mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 887836 - URLSearchParams and URL, r=ehsan, r=bz, r=smaug
--HG-- rename : dom/workers/test/urlSearchparams_worker.js => dom/workers/test/urlSearchParams_worker.js
This commit is contained in:
parent
1e4cd05d99
commit
cd35fe13b6
@ -214,7 +214,16 @@ Link::SetPathname(const nsAString &aPathname)
|
||||
}
|
||||
|
||||
void
|
||||
Link::SetSearch(const nsAString &aSearch)
|
||||
Link::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Link::SetSearchInternal(const nsAString& aSearch)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri(GetURIToMutate());
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
||||
@ -478,6 +487,9 @@ Link::ResetLinkState(bool aNotify, bool aHasHref)
|
||||
|
||||
// If we've cached the URI, reset always invalidates it.
|
||||
mCachedURI = nullptr;
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
|
||||
// Update our state back to the default.
|
||||
mLinkState = defaultState;
|
||||
@ -563,5 +575,85 @@ Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
return n;
|
||||
}
|
||||
|
||||
URLSearchParams*
|
||||
Link::GetSearchParams()
|
||||
{
|
||||
CreateSearchParamsIfNeeded();
|
||||
return mSearchParams;
|
||||
}
|
||||
|
||||
void
|
||||
Link::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
{
|
||||
if (!aSearchParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
}
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
}
|
||||
|
||||
void
|
||||
Link::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
}
|
||||
|
||||
void
|
||||
Link::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsAutoCString search;
|
||||
nsCOMPtr<nsIURI> uri(GetURI());
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
||||
if (url) {
|
||||
nsresult rv = url->GetQuery(search);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to get the query from a nsIURL.");
|
||||
}
|
||||
}
|
||||
|
||||
mSearchParams->ParseInput(search);
|
||||
}
|
||||
|
||||
void
|
||||
Link::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Link::Unlink()
|
||||
{
|
||||
mSearchParams = nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
Link::Traverse(nsCycleCollectionTraversalCallback &cb)
|
||||
{
|
||||
Link* tmp = this;
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSearchParams);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "mozilla/IHistory.h"
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
#include "nsEventStates.h"
|
||||
#include "nsIContent.h"
|
||||
|
||||
@ -25,7 +26,7 @@ class Element;
|
||||
{ 0xb25edee6, 0xdd35, 0x4f8b, \
|
||||
{ 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
|
||||
|
||||
class Link : public nsISupports
|
||||
class Link : public URLSearchParamsObserver
|
||||
{
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
||||
@ -61,6 +62,7 @@ public:
|
||||
void SetHostname(const nsAString &aHostname);
|
||||
void SetPathname(const nsAString &aPathname);
|
||||
void SetSearch(const nsAString &aSearch);
|
||||
void SetSearchParams(mozilla::dom::URLSearchParams* aSearchParams);
|
||||
void SetPort(const nsAString &aPort);
|
||||
void SetHash(const nsAString &aHash);
|
||||
void GetOrigin(nsAString &aOrigin);
|
||||
@ -71,6 +73,7 @@ public:
|
||||
void GetHostname(nsAString &_hostname);
|
||||
void GetPathname(nsAString &_pathname);
|
||||
void GetSearch(nsAString &_search);
|
||||
URLSearchParams* GetSearchParams();
|
||||
void GetPort(nsAString &_port);
|
||||
void GetHash(nsAString &_hash);
|
||||
|
||||
@ -109,6 +112,10 @@ public:
|
||||
|
||||
bool ElementHasHref() const;
|
||||
|
||||
// URLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual ~Link();
|
||||
|
||||
@ -127,6 +134,10 @@ protected:
|
||||
nsIURI* GetCachedURI() const { return mCachedURI; }
|
||||
bool HasCachedURI() const { return !!mCachedURI; }
|
||||
|
||||
// CC methods
|
||||
void Unlink();
|
||||
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Unregisters from History so this node no longer gets notifications about
|
||||
@ -137,6 +148,10 @@ private:
|
||||
already_AddRefed<nsIURI> GetURIToMutate();
|
||||
void SetHrefAttribute(nsIURI *aURI);
|
||||
|
||||
void CreateSearchParamsIfNeeded();
|
||||
|
||||
void SetSearchInternal(const nsAString& aSearch);
|
||||
|
||||
mutable nsCOMPtr<nsIURI> mCachedURI;
|
||||
|
||||
Element * const mElement;
|
||||
@ -150,6 +165,9 @@ private:
|
||||
bool mNeedsRegistration;
|
||||
|
||||
bool mRegistered;
|
||||
|
||||
protected:
|
||||
nsRefPtr<URLSearchParams> mSearchParams;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
|
||||
|
@ -41,8 +41,26 @@ HTMLAnchorElement::~HTMLAnchorElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED2(HTMLAnchorElement, nsGenericHTMLElement,
|
||||
nsIDOMHTMLAnchorElement, Link)
|
||||
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLAnchorElement)
|
||||
NS_INTERFACE_TABLE_INHERITED2(HTMLAnchorElement,
|
||||
nsIDOMHTMLAnchorElement,
|
||||
Link)
|
||||
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(HTMLAnchorElement, Element)
|
||||
NS_IMPL_RELEASE_INHERITED(HTMLAnchorElement, Element)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLAnchorElement)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLAnchorElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->Link::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLAnchorElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->Link::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLAnchorElement)
|
||||
|
||||
|
@ -33,6 +33,10 @@ public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// CC
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLAnchorElement,
|
||||
nsGenericHTMLElement)
|
||||
|
||||
virtual int32_t TabIndexDefault() MOZ_OVERRIDE;
|
||||
virtual bool Draggable() const MOZ_OVERRIDE;
|
||||
|
||||
@ -135,30 +139,14 @@ public:
|
||||
rv = SetText(aValue);
|
||||
}
|
||||
|
||||
void GetOrigin(nsAString& aOrigin)
|
||||
{
|
||||
Link::GetOrigin(aOrigin);
|
||||
}
|
||||
// Link::GetOrigin is OK for us
|
||||
|
||||
void GetUsername(nsAString& aUsername)
|
||||
{
|
||||
Link::GetUsername(aUsername);
|
||||
}
|
||||
// Link::GetUsername is OK for us
|
||||
// Link::SetUsername is OK for us
|
||||
|
||||
void SetUsername(const nsAString& aUsername)
|
||||
{
|
||||
Link::SetUsername(aUsername);
|
||||
}
|
||||
// Link::Getpassword is OK for us
|
||||
// Link::Setpassword is OK for us
|
||||
|
||||
void GetPassword(nsAString& aPassword)
|
||||
{
|
||||
Link::GetPassword(aPassword);
|
||||
}
|
||||
|
||||
void SetPassword(const nsAString& aPassword)
|
||||
{
|
||||
Link::SetPassword(aPassword);
|
||||
}
|
||||
// The XPCOM URI decomposition attributes are fine for us
|
||||
void GetCoords(nsString& aValue)
|
||||
{
|
||||
|
@ -25,8 +25,26 @@ HTMLAreaElement::~HTMLAreaElement()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED2(HTMLAreaElement, nsGenericHTMLElement,
|
||||
nsIDOMHTMLAreaElement, Link)
|
||||
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLAreaElement)
|
||||
NS_INTERFACE_TABLE_INHERITED2(HTMLAreaElement,
|
||||
nsIDOMHTMLAreaElement,
|
||||
Link)
|
||||
NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(HTMLAreaElement, Element)
|
||||
NS_IMPL_RELEASE_INHERITED(HTMLAreaElement, Element)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLAreaElement)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLAreaElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->Link::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLAreaElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->Link::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_ELEMENT_CLONE(HTMLAreaElement)
|
||||
|
||||
|
@ -30,6 +30,10 @@ public:
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// CC
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLAreaElement,
|
||||
nsGenericHTMLElement)
|
||||
|
||||
// DOM memory reporter participant
|
||||
NS_DECL_SIZEOF_EXCLUDING_THIS
|
||||
|
||||
@ -108,33 +112,16 @@ public:
|
||||
SetHTMLAttr(nsGkAtoms::ping, aPing, aError);
|
||||
}
|
||||
|
||||
void GetOrigin(nsAString &aOrigin)
|
||||
{
|
||||
Link::GetOrigin(aOrigin);
|
||||
}
|
||||
// The Link::GetOrigin is OK for us
|
||||
|
||||
// The XPCOM GetProtocol is OK for us
|
||||
// The XPCOM SetProtocol is OK for us
|
||||
|
||||
void GetUsername(nsAString& aUsername)
|
||||
{
|
||||
Link::GetUsername(aUsername);
|
||||
}
|
||||
// The Link::GetUsername is OK for us
|
||||
// The Link::SetUsername is OK for us
|
||||
|
||||
void SetUsername(const nsAString& aUsername)
|
||||
{
|
||||
Link::SetUsername(aUsername);
|
||||
}
|
||||
|
||||
void GetPassword(nsAString& aPassword)
|
||||
{
|
||||
Link::GetPassword(aPassword);
|
||||
}
|
||||
|
||||
void SetPassword(const nsAString& aPassword)
|
||||
{
|
||||
Link::SetPassword(aPassword);
|
||||
}
|
||||
// The Link::GetPassword is OK for us
|
||||
// The Link::SetPassword is OK for us
|
||||
|
||||
// The XPCOM GetHost is OK for us
|
||||
// The XPCOM SetHost is OK for us
|
||||
@ -154,6 +141,9 @@ public:
|
||||
// The XPCOM GetHash is OK for us
|
||||
// The XPCOM SetHash is OK for us
|
||||
|
||||
// The Link::GetSearchParams is OK for us
|
||||
// The Link::SetSearchParams is OK for us
|
||||
|
||||
bool NoHref() const
|
||||
{
|
||||
return GetBoolAttr(nsGkAtoms::nohref);
|
||||
|
@ -44,11 +44,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLLinkElement)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLLinkElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->nsStyleLinkElement::Traverse(cb);
|
||||
tmp->Link::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLLinkElement,
|
||||
nsGenericHTMLElement)
|
||||
tmp->nsStyleLinkElement::Unlink();
|
||||
tmp->Link::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(HTMLLinkElement, Element)
|
||||
|
@ -34,12 +34,28 @@ nsSVGElement::StringInfo SVGAElement::sStringInfo[2] =
|
||||
//----------------------------------------------------------------------
|
||||
// nsISupports methods
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED4(SVGAElement, SVGAElementBase,
|
||||
nsIDOMNode,
|
||||
nsIDOMElement,
|
||||
nsIDOMSVGElement,
|
||||
Link)
|
||||
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(SVGAElement)
|
||||
NS_INTERFACE_TABLE_INHERITED4(SVGAElement,
|
||||
nsIDOMNode,
|
||||
nsIDOMElement,
|
||||
nsIDOMSVGElement,
|
||||
Link)
|
||||
NS_INTERFACE_TABLE_TAIL_INHERITING(SVGAElementBase)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(SVGAElement)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SVGAElement,
|
||||
SVGAElementBase)
|
||||
tmp->Link::Traverse(cb);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SVGAElement,
|
||||
SVGAElementBase)
|
||||
tmp->Link::Unlink();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(SVGAElement, SVGAElementBase)
|
||||
NS_IMPL_RELEASE_INHERITED(SVGAElement, SVGAElementBase)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Implementation
|
||||
|
@ -30,6 +30,7 @@ protected:
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGAElement, SVGAElementBase)
|
||||
|
||||
// nsINode interface methods
|
||||
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
|
||||
|
@ -20,6 +20,15 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_1(URL, mSearchParams)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(URL)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(URL)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URL)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
URL::URL(nsIURI* aURI)
|
||||
: mURI(aURI)
|
||||
{
|
||||
@ -212,6 +221,10 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
}
|
||||
|
||||
aRv = mURI->SetSpec(href);
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -288,6 +301,33 @@ URL::SetHost(const nsAString& aHost)
|
||||
mURI->SetHostPort(NS_ConvertUTF16toUTF8(aHost));
|
||||
}
|
||||
|
||||
void
|
||||
URL::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
}
|
||||
|
||||
void
|
||||
URL::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsAutoCString search;
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(mURI));
|
||||
if (url) {
|
||||
nsresult rv = url->GetQuery(search);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to get the query from a nsIURL.");
|
||||
}
|
||||
}
|
||||
|
||||
mSearchParams->ParseInput(search);
|
||||
}
|
||||
|
||||
void
|
||||
URL::GetHostname(nsString& aHostname) const
|
||||
{
|
||||
@ -384,6 +424,16 @@ URL::GetSearch(nsString& aSearch) const
|
||||
|
||||
void
|
||||
URL::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URL::SetSearchInternal(const nsAString& aSearch)
|
||||
{
|
||||
nsCOMPtr<nsIURL> url(do_QueryInterface(mURI));
|
||||
if (!url) {
|
||||
@ -394,6 +444,35 @@ URL::SetSearch(const nsAString& aSearch)
|
||||
url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
|
||||
}
|
||||
|
||||
URLSearchParams*
|
||||
URL::GetSearchParams()
|
||||
{
|
||||
CreateSearchParamsIfNeeded();
|
||||
return mSearchParams;
|
||||
}
|
||||
|
||||
void
|
||||
URL::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
{
|
||||
if (!aSearchParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
}
|
||||
|
||||
nsAutoString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
}
|
||||
|
||||
void
|
||||
URL::GetHash(nsString& aHash) const
|
||||
{
|
||||
@ -422,5 +501,15 @@ bool IsChromeURI(nsIURI* aURI)
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
URL::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define URL_h___
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsString.h"
|
||||
@ -29,10 +30,11 @@ namespace workers {
|
||||
class URLProxy;
|
||||
}
|
||||
|
||||
class URL MOZ_FINAL
|
||||
class URL MOZ_FINAL : public URLSearchParamsObserver
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(URL)
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(URL)
|
||||
|
||||
URL(nsIURI* aURI);
|
||||
|
||||
@ -108,16 +110,28 @@ public:
|
||||
|
||||
void SetSearch(const nsAString& aArg);
|
||||
|
||||
URLSearchParams* GetSearchParams();
|
||||
|
||||
void SetSearchParams(URLSearchParams* aSearchParams);
|
||||
|
||||
void GetHash(nsString& aRetval) const;
|
||||
|
||||
void SetHash(const nsAString& aArg);
|
||||
|
||||
// URLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
nsIURI* GetURI() const
|
||||
{
|
||||
return mURI;
|
||||
}
|
||||
|
||||
void CreateSearchParamsIfNeeded();
|
||||
|
||||
void SetSearchInternal(const nsAString& aSearch);
|
||||
|
||||
static void CreateObjectURLInternal(const GlobalObject& aGlobal,
|
||||
nsISupports* aObject,
|
||||
const nsACString& aScheme,
|
||||
@ -126,6 +140,7 @@ private:
|
||||
ErrorResult& aError);
|
||||
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsRefPtr<URLSearchParams> mSearchParams;
|
||||
|
||||
friend class mozilla::dom::workers::URLProxy;
|
||||
};
|
||||
|
@ -9,8 +9,19 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(URLSearchParams, mObserver)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
URLSearchParams::URLSearchParams()
|
||||
: mValid(false)
|
||||
{
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
URLSearchParams::~URLSearchParams()
|
||||
@ -30,7 +41,7 @@ URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsRefPtr<URLSearchParams> sp = new URLSearchParams();
|
||||
sp->ParseInput(aInit);
|
||||
sp->ParseInput(NS_ConvertUTF16toUTF8(aInit));
|
||||
return sp.forget();
|
||||
}
|
||||
|
||||
@ -41,19 +52,23 @@ URLSearchParams::Constructor(const GlobalObject& aGlobal,
|
||||
{
|
||||
nsRefPtr<URLSearchParams> sp = new URLSearchParams();
|
||||
aInit.mSearchParams.EnumerateRead(CopyEnumerator, sp);
|
||||
sp->mValid = true;
|
||||
return sp.forget();
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::ParseInput(const nsAString& aInput)
|
||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
{
|
||||
nsAString::const_iterator start, end;
|
||||
// Remove all the existing data before parsing a new input.
|
||||
DeleteAll();
|
||||
|
||||
nsACString::const_iterator start, end;
|
||||
aInput.BeginReading(start);
|
||||
aInput.EndReading(end);
|
||||
nsAString::const_iterator iter(start);
|
||||
nsACString::const_iterator iter(start);
|
||||
|
||||
while (start != end) {
|
||||
nsAutoString string;
|
||||
nsAutoCString string;
|
||||
|
||||
if (FindCharInReadable('&', iter, end)) {
|
||||
string.Assign(Substring(start, iter));
|
||||
@ -67,13 +82,13 @@ URLSearchParams::ParseInput(const nsAString& aInput)
|
||||
continue;
|
||||
}
|
||||
|
||||
nsAString::const_iterator eqStart, eqEnd;
|
||||
nsACString::const_iterator eqStart, eqEnd;
|
||||
string.BeginReading(eqStart);
|
||||
string.EndReading(eqEnd);
|
||||
nsAString::const_iterator eqIter(eqStart);
|
||||
nsACString::const_iterator eqIter(eqStart);
|
||||
|
||||
nsAutoString name;
|
||||
nsAutoString value;
|
||||
nsAutoCString name;
|
||||
nsAutoCString value;
|
||||
|
||||
if (FindCharInReadable('=', eqIter, eqEnd)) {
|
||||
name.Assign(Substring(eqStart, eqIter));
|
||||
@ -84,20 +99,23 @@ URLSearchParams::ParseInput(const nsAString& aInput)
|
||||
name.Assign(string);
|
||||
}
|
||||
|
||||
nsAutoString decodedName;
|
||||
nsAutoCString decodedName;
|
||||
DecodeString(name, decodedName);
|
||||
|
||||
nsAutoString decodedValue;
|
||||
nsAutoCString decodedValue;
|
||||
DecodeString(value, decodedValue);
|
||||
|
||||
Append(decodedName, decodedValue);
|
||||
AppendInternal(NS_ConvertUTF8toUTF16(decodedName),
|
||||
NS_ConvertUTF8toUTF16(decodedValue));
|
||||
}
|
||||
|
||||
mValid = true;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::DecodeString(const nsAString& aInput, nsAString& aOutput)
|
||||
URLSearchParams::DecodeString(const nsACString& aInput, nsACString& aOutput)
|
||||
{
|
||||
nsAString::const_iterator start, end;
|
||||
nsACString::const_iterator start, end;
|
||||
aInput.BeginReading(start);
|
||||
aInput.EndReading(end);
|
||||
|
||||
@ -111,10 +129,10 @@ URLSearchParams::DecodeString(const nsAString& aInput, nsAString& aOutput)
|
||||
|
||||
// Percent decode algorithm
|
||||
if (*start == '%') {
|
||||
nsAString::const_iterator first(start);
|
||||
nsACString::const_iterator first(start);
|
||||
++first;
|
||||
|
||||
nsAString::const_iterator second(first);
|
||||
nsACString::const_iterator second(first);
|
||||
++second;
|
||||
|
||||
#define ASCII_HEX_DIGIT( x ) \
|
||||
@ -147,6 +165,18 @@ URLSearchParams::DecodeString(const nsAString& aInput, nsAString& aOutput)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::CopyFromURLSearchParams(URLSearchParams& aSearchParams)
|
||||
{
|
||||
// The other SearchParams must be valid before copying its data.
|
||||
aSearchParams.Validate();
|
||||
|
||||
// Remove all the existing data before parsing a new input.
|
||||
DeleteAll();
|
||||
aSearchParams.mSearchParams.EnumerateRead(CopyEnumerator, this);
|
||||
mValid = true;
|
||||
}
|
||||
|
||||
/* static */ PLDHashOperator
|
||||
URLSearchParams::CopyEnumerator(const nsAString& aName,
|
||||
nsTArray<nsString>* aArray,
|
||||
@ -161,9 +191,28 @@ URLSearchParams::CopyEnumerator(const nsAString& aName,
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
MOZ_ASSERT(!mObserver);
|
||||
mObserver = aObserver;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Validate()
|
||||
{
|
||||
MOZ_ASSERT(mValid || mObserver);
|
||||
if (!mValid) {
|
||||
mObserver->URLSearchParamsNeedsUpdates();
|
||||
MOZ_ASSERT(mValid);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||
{
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
aRetval.Truncate();
|
||||
@ -176,6 +225,8 @@ URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||
void
|
||||
URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString>& aRetval)
|
||||
{
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
return;
|
||||
@ -187,6 +238,10 @@ URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString>& aRetval)
|
||||
void
|
||||
URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
// Before setting any new value we have to be sure to have all the previous
|
||||
// values in place.
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
array = new nsTArray<nsString>();
|
||||
@ -195,10 +250,23 @@ URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
|
||||
} else {
|
||||
array->ElementAt(0) = aValue;
|
||||
}
|
||||
|
||||
NotifyObserver();
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
// Before setting any new value we have to be sure to have all the previous
|
||||
// values in place.
|
||||
Validate();
|
||||
|
||||
AppendInternal(aName, aValue);
|
||||
NotifyObserver();
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
@ -212,18 +280,32 @@ URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
|
||||
bool
|
||||
URLSearchParams::Has(const nsAString& aName)
|
||||
{
|
||||
Validate();
|
||||
return mSearchParams.Get(aName, nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Delete(const nsAString& aName)
|
||||
{
|
||||
// Before deleting any value we have to be sure to have all the previous
|
||||
// values in place.
|
||||
Validate();
|
||||
|
||||
nsTArray<nsString>* array;
|
||||
if (!mSearchParams.Get(aName, &array)) {
|
||||
return;
|
||||
}
|
||||
|
||||
mSearchParams.Remove(aName);
|
||||
|
||||
NotifyObserver();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
URLSearchParams::Size()
|
||||
{
|
||||
Validate();
|
||||
return mSearchParams.Count();
|
||||
}
|
||||
|
||||
void
|
||||
@ -232,5 +314,84 @@ URLSearchParams::DeleteAll()
|
||||
mSearchParams.Clear();
|
||||
}
|
||||
|
||||
class MOZ_STACK_CLASS SerializeData
|
||||
{
|
||||
public:
|
||||
SerializeData()
|
||||
: mFirst(true)
|
||||
{}
|
||||
|
||||
nsAutoString mValue;
|
||||
bool mFirst;
|
||||
|
||||
void Serialize(const nsCString& aInput)
|
||||
{
|
||||
const unsigned char* p = (const unsigned char*) aInput.get();
|
||||
|
||||
while (p && *p) {
|
||||
// ' ' to '+'
|
||||
if (*p == 0x20) {
|
||||
mValue.Append(0x2B);
|
||||
// Percent Encode algorithm
|
||||
} else if (*p == 0x2A || *p == 0x2D || *p == 0x2E ||
|
||||
(*p >= 0x30 && *p <= 0x39) ||
|
||||
(*p >= 0x41 && *p <= 0x5A) || *p == 0x5F ||
|
||||
(*p >= 0x61 && *p <= 0x7A)) {
|
||||
mValue.Append(*p);
|
||||
} else {
|
||||
mValue.AppendPrintf("%%%X", *p);
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
URLSearchParams::Serialize(nsAString& aValue)
|
||||
{
|
||||
MOZ_ASSERT(mValid);
|
||||
|
||||
SerializeData data;
|
||||
mSearchParams.EnumerateRead(SerializeEnumerator, &data);
|
||||
aValue.Assign(data.mValue);
|
||||
}
|
||||
|
||||
/* static */ PLDHashOperator
|
||||
URLSearchParams::SerializeEnumerator(const nsAString& aName,
|
||||
nsTArray<nsString>* aArray,
|
||||
void *userData)
|
||||
{
|
||||
SerializeData* data = static_cast<SerializeData*>(userData);
|
||||
|
||||
for (uint32_t i = 0, len = aArray->Length(); i < len; ++i) {
|
||||
if (data->mFirst) {
|
||||
data->mFirst = false;
|
||||
} else {
|
||||
data->mValue.Append(NS_LITERAL_STRING("&"));
|
||||
}
|
||||
|
||||
data->Serialize(NS_ConvertUTF16toUTF8(aName));
|
||||
data->mValue.Append(NS_LITERAL_STRING("="));
|
||||
data->Serialize(NS_ConvertUTF16toUTF8(aArray->ElementAt(i)));
|
||||
}
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::NotifyObserver()
|
||||
{
|
||||
if (mObserver) {
|
||||
mObserver->URLSearchParamsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Invalidate()
|
||||
{
|
||||
mValid = false;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -8,28 +8,47 @@
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsHashKeys.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class URLSearchParams MOZ_FINAL
|
||||
class URLSearchParamsObserver : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_INLINE_DECL_REFCOUNTING(URL)
|
||||
virtual ~URLSearchParamsObserver() {}
|
||||
|
||||
virtual void URLSearchParamsUpdated() = 0;
|
||||
virtual void URLSearchParamsNeedsUpdates() = 0;
|
||||
};
|
||||
|
||||
class URLSearchParams MOZ_FINAL : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(URLSearchParams)
|
||||
|
||||
URLSearchParams();
|
||||
~URLSearchParams();
|
||||
|
||||
bool HasURLAssociated() const
|
||||
{
|
||||
return !!mObserver;
|
||||
}
|
||||
|
||||
// WebIDL methods
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope);
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
||||
|
||||
static already_AddRefed<URLSearchParams>
|
||||
Constructor(const GlobalObject& aGlobal, const nsAString& aInit,
|
||||
@ -39,6 +58,21 @@ public:
|
||||
Constructor(const GlobalObject& aGlobal, URLSearchParams& aInit,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void ParseInput(const nsACString& aInput);
|
||||
|
||||
void CopyFromURLSearchParams(URLSearchParams& aSearchParams);
|
||||
|
||||
void SetObserver(URLSearchParamsObserver* aObserver);
|
||||
|
||||
void Invalidate();
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return mValid;
|
||||
}
|
||||
|
||||
void Serialize(nsAString& aValue);
|
||||
|
||||
void Get(const nsAString& aName, nsString& aRetval);
|
||||
|
||||
void GetAll(const nsAString& aName, nsTArray<nsString >& aRetval);
|
||||
@ -51,23 +85,33 @@ public:
|
||||
|
||||
void Delete(const nsAString& aName);
|
||||
|
||||
uint32_t Size() const
|
||||
{
|
||||
return mSearchParams.Count();
|
||||
}
|
||||
uint32_t Size();
|
||||
|
||||
private:
|
||||
void ParseInput(const nsAString& aInput);
|
||||
void AppendInternal(const nsAString& aName, const nsAString& aValue);
|
||||
|
||||
void DeleteAll();
|
||||
|
||||
void DecodeString(const nsAString& aInput, nsAString& aOutput);
|
||||
void DecodeString(const nsACString& aInput, nsACString& aOutput);
|
||||
|
||||
void NotifyObserver();
|
||||
|
||||
static PLDHashOperator
|
||||
CopyEnumerator(const nsAString& aName, nsTArray<nsString>* aArray,
|
||||
void *userData);
|
||||
|
||||
static PLDHashOperator
|
||||
SerializeEnumerator(const nsAString& aName, nsTArray<nsString>* aArray,
|
||||
void *userData);
|
||||
|
||||
void
|
||||
Validate();
|
||||
|
||||
nsClassHashtable<nsStringHashKey, nsTArray<nsString>> mSearchParams;
|
||||
|
||||
nsRefPtr<URLSearchParamsObserver> mObserver;
|
||||
|
||||
bool mValid;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -19,7 +19,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
<script type="application/javascript">
|
||||
<a href="http://www.example.net?a=b&c=d" id="anchor">foobar</a>
|
||||
<area href="http://www.example.net?a=b&c=d" id="area">foobar</area>
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 887836 **/
|
||||
ok("URLSearchParams" in window, "window.URLSearchParams exists");
|
||||
@ -117,10 +119,104 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testURL() {
|
||||
var url = new URL('http://www.example.net?a=b&c=d');
|
||||
ok(url.searchParams, "URL searchParams exists!");
|
||||
ok(url.searchParams.has('a'), "URL.searchParams.has('a')");
|
||||
is(url.searchParams.get('a'), 'b', "URL.searchParams.get('a')");
|
||||
ok(url.searchParams.has('c'), "URL.searchParams.has('c')");
|
||||
is(url.searchParams.get('c'), 'd', "URL.searchParams.get('c')");
|
||||
|
||||
url.searchParams.set('e', 'f');
|
||||
ok(url.href.indexOf('e=f') != 1, 'URL right');
|
||||
|
||||
var u = new URLSearchParams();
|
||||
u.append('foo', 'bar');
|
||||
url.searchParams = u;
|
||||
is(url.searchParams, u, "URL.searchParams is the same object");
|
||||
is(url.searchParams.get('foo'), 'bar', "URL.searchParams.get('foo')");
|
||||
is(url.href, 'http://www.example.net/?foo=bar', 'URL right');
|
||||
|
||||
url.searchParams = null;
|
||||
is(url.searchParams.get('foo'), 'bar', "URL.searchParams.get('foo')");
|
||||
is(url.href, 'http://www.example.net/?foo=bar', 'URL right');
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
url.searchParams = url2.searchParams;
|
||||
isnot(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
is(url.searchParams.get('e'), 'f', "URL.searchParams.get('e')");
|
||||
|
||||
url.href = "http://www.example.net?bar=foo";
|
||||
is(url.searchParams.get('bar'), 'foo', "URL.searchParams.get('bar')");
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testElement(e) {
|
||||
ok(e, 'element exists');
|
||||
ok(e.searchParams, "e.searchParams exists!");
|
||||
ok(e.searchParams.has('a'), "e.searchParams.has('a')");
|
||||
is(e.searchParams.get('a'), 'b', "e.searchParams.get('a')");
|
||||
ok(e.searchParams.has('c'), "e.searchParams.has('c')");
|
||||
is(e.searchParams.get('c'), 'd', "e.searchParams.get('c')");
|
||||
|
||||
e.searchParams.set('e', 'f');
|
||||
ok(e.href.indexOf('e=f') != 1, 'e is right');
|
||||
|
||||
var u = new URLSearchParams();
|
||||
u.append('foo', 'bar');
|
||||
e.searchParams = u;
|
||||
is(e.searchParams, u, "e.searchParams is the same object");
|
||||
is(e.searchParams.get('foo'), 'bar', "e.searchParams.get('foo')");
|
||||
is(e.href, 'http://www.example.net/?foo=bar', 'e is right');
|
||||
|
||||
e.searchParams = null;
|
||||
is(e.searchParams.get('foo'), 'bar', "e.searchParams.get('foo')");
|
||||
is(e.href, 'http://www.example.net/?foo=bar', 'e is right');
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
e.searchParams = url2.searchParams;
|
||||
isnot(e.searchParams, url2.searchParams, "e.searchParams is not the same object");
|
||||
is(e.searchParams.get('e'), 'f', "e.searchParams.get('e')");
|
||||
|
||||
e.href = "http://www.example.net?bar=foo";
|
||||
is(e.searchParams.get('bar'), 'foo', "e.searchParams.get('bar')");
|
||||
|
||||
e.setAttribute('href', "http://www.example.net?bar2=foo2");
|
||||
is(e.searchParams.get('bar2'), 'foo2', "e.searchParams.get('bar2')");
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testEncoding() {
|
||||
var encoding = [ [ '1', '1' ],
|
||||
[ 'a b', 'a+b' ],
|
||||
[ '<>', '%3C%3E' ],
|
||||
[ '\u0541', '%D5%81'] ];
|
||||
|
||||
for (var i = 0; i < encoding.length; ++i) {
|
||||
var a = new URLSearchParams();
|
||||
a.set('a', encoding[i][0]);
|
||||
|
||||
var url = new URL('http://www.example.net');
|
||||
url.searchParams = a;
|
||||
is(url.href, 'http://www.example.net/?a=' + encoding[i][1]);
|
||||
|
||||
var url2 = new URL(url.href);
|
||||
is(url2.searchParams.get('a'), encoding[i][0], 'a is still there');
|
||||
}
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
var tests = [
|
||||
testSimpleURLSearchParams,
|
||||
testCopyURLSearchParams,
|
||||
testParserURLSearchParams
|
||||
testParserURLSearchParams,
|
||||
testURL,
|
||||
function() { testElement(document.getElementById('anchor')) },
|
||||
function() { testElement(document.getElementById('area')) },
|
||||
testEncoding
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
@ -136,6 +232,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=887836
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
runTest();
|
||||
|
||||
</script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1287,14 +1287,8 @@ DOMInterfaces = {
|
||||
{
|
||||
'workers': True,
|
||||
'wrapperCache': False,
|
||||
'nativeOwnership': 'owned',
|
||||
}],
|
||||
|
||||
'URLSearchParams' : {
|
||||
'wrapperCache' : False,
|
||||
'nativeOwnership': 'refcounted',
|
||||
},
|
||||
|
||||
'VTTCue': {
|
||||
'nativeType': 'mozilla::dom::TextTrackCue'
|
||||
},
|
||||
|
@ -614,6 +614,7 @@ var interfaceNamesInGlobalScope =
|
||||
"UIEvent",
|
||||
"UndoManager",
|
||||
"URL",
|
||||
"URLSearchParams",
|
||||
{name: "UserDataHandler", xbl: true},
|
||||
"UserProximityEvent",
|
||||
{name: "USSDReceivedEvent", b2g: true, pref: "dom.mobileconnection.enabled"},
|
||||
|
@ -27,7 +27,7 @@ interface URLUtils {
|
||||
attribute DOMString port;
|
||||
attribute DOMString pathname;
|
||||
attribute DOMString search;
|
||||
// attribute URLSearchParams? searchParams;
|
||||
attribute URLSearchParams? searchParams;
|
||||
attribute DOMString hash;
|
||||
};
|
||||
|
||||
|
@ -71,7 +71,7 @@ WorkerPrivate::RegisterBindings(JSContext* aCx, JS::Handle<JSObject*> aGlobal)
|
||||
!XMLHttpRequestBinding_workers::GetConstructorObject(aCx, aGlobal) ||
|
||||
!XMLHttpRequestUploadBinding_workers::GetConstructorObject(aCx, aGlobal) ||
|
||||
!URLBinding_workers::GetConstructorObject(aCx, aGlobal) ||
|
||||
!URLSearchParamsBinding::GetConstructorObject(aCx, global) ||
|
||||
!URLSearchParamsBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!WorkerBinding::GetConstructorObject(aCx, aGlobal) ||
|
||||
!WorkerLocationBinding_workers::GetConstructorObject(aCx, aGlobal) ||
|
||||
!WorkerNavigatorBinding_workers::GetConstructorObject(aCx, aGlobal)) {
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "mozilla/dom/URL.h"
|
||||
#include "mozilla/dom/URLBinding.h"
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
@ -536,6 +537,17 @@ private:
|
||||
mozilla::ErrorResult& mRv;
|
||||
};
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_1(URL, mSearchParams)
|
||||
|
||||
// The reason for using worker::URL is to have different refcnt logging than
|
||||
// for main thread URL.
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(workers::URL)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(workers::URL)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URL)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
// static
|
||||
URL*
|
||||
URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
|
||||
@ -606,10 +618,9 @@ URL::~URL()
|
||||
}
|
||||
|
||||
JSObject*
|
||||
URL::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope,
|
||||
bool* aTookOwnership)
|
||||
URL::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return URLBinding_workers::Wrap(aCx, aScope, this, aTookOwnership);
|
||||
return URLBinding_workers::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
||||
void
|
||||
@ -634,6 +645,10 @@ URL::SetHref(const nsAString& aHref, ErrorResult& aRv)
|
||||
if (!runnable->Dispatch(mWorkerPrivate->GetJSContext())) {
|
||||
JS_ReportPendingException(mWorkerPrivate->GetJSContext());
|
||||
}
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -837,6 +852,16 @@ URL::GetSearch(nsString& aSearch) const
|
||||
|
||||
void
|
||||
URL::SetSearch(const nsAString& aSearch)
|
||||
{
|
||||
SetSearchInternal(aSearch);
|
||||
|
||||
if (mSearchParams) {
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URL::SetSearchInternal(const nsAString& aSearch)
|
||||
{
|
||||
ErrorResult rv;
|
||||
nsRefPtr<SetterRunnable> runnable =
|
||||
@ -848,6 +873,36 @@ URL::SetSearch(const nsAString& aSearch)
|
||||
}
|
||||
}
|
||||
|
||||
mozilla::dom::URLSearchParams*
|
||||
URL::GetSearchParams()
|
||||
{
|
||||
CreateSearchParamsIfNeeded();
|
||||
return mSearchParams;
|
||||
}
|
||||
|
||||
void
|
||||
URL::SetSearchParams(URLSearchParams* aSearchParams)
|
||||
{
|
||||
if (!aSearchParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!aSearchParams->HasURLAssociated()) {
|
||||
MOZ_ASSERT(aSearchParams->IsValid());
|
||||
|
||||
mSearchParams = aSearchParams;
|
||||
mSearchParams->SetObserver(this);
|
||||
} else {
|
||||
CreateSearchParamsIfNeeded();
|
||||
mSearchParams->CopyFromURLSearchParams(*aSearchParams);
|
||||
}
|
||||
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
}
|
||||
|
||||
void
|
||||
URL::GetHash(nsString& aHash) const
|
||||
{
|
||||
@ -924,4 +979,34 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
URL::URLSearchParamsUpdated()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams && mSearchParams->IsValid());
|
||||
|
||||
nsString search;
|
||||
mSearchParams->Serialize(search);
|
||||
SetSearchInternal(search);
|
||||
}
|
||||
|
||||
void
|
||||
URL::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
MOZ_ASSERT(mSearchParams);
|
||||
|
||||
nsString search;
|
||||
GetSearch(search);
|
||||
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(Substring(search, 1)));
|
||||
}
|
||||
|
||||
void
|
||||
URL::CreateSearchParamsIfNeeded()
|
||||
{
|
||||
if (!mSearchParams) {
|
||||
mSearchParams = new URLSearchParams();
|
||||
mSearchParams->SetObserver(this);
|
||||
mSearchParams->Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/NonRefcountedDOMObject.h"
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -23,9 +23,13 @@ BEGIN_WORKERS_NAMESPACE
|
||||
|
||||
class URLProxy;
|
||||
|
||||
class URL MOZ_FINAL : public NonRefcountedDOMObject
|
||||
class URL MOZ_FINAL : public mozilla::dom::URLSearchParamsObserver
|
||||
{
|
||||
typedef mozilla::dom::URLSearchParams URLSearchParams;
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(URL)
|
||||
|
||||
URL(WorkerPrivate* aWorkerPrivate, URLProxy* aURLProxy);
|
||||
~URL();
|
||||
@ -38,8 +42,7 @@ public:
|
||||
}
|
||||
|
||||
JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope,
|
||||
bool* aTookOwnership);
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope);
|
||||
|
||||
// Methods for WebIDL
|
||||
|
||||
@ -101,18 +104,31 @@ public:
|
||||
|
||||
void SetSearch(const nsAString& aSearch);
|
||||
|
||||
URLSearchParams* GetSearchParams();
|
||||
|
||||
void SetSearchParams(URLSearchParams* aSearchParams);
|
||||
|
||||
void GetHash(nsString& aHost) const;
|
||||
|
||||
void SetHash(const nsAString& aHash);
|
||||
|
||||
// IURLSearchParamsObserver
|
||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
||||
void URLSearchParamsNeedsUpdates() MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
URLProxy* GetURLProxy() const
|
||||
{
|
||||
return mURLProxy;
|
||||
}
|
||||
|
||||
void CreateSearchParamsIfNeeded();
|
||||
|
||||
void SetSearchInternal(const nsAString& aSearch);
|
||||
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
nsRefPtr<URLProxy> mURLProxy;
|
||||
nsRefPtr<URLSearchParams> mSearchParams;
|
||||
};
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
|
@ -8,6 +8,11 @@ function is(a, b, msg) {
|
||||
postMessage({type: 'status', status: a === b, msg: a + " === " + b + ": " + msg });
|
||||
}
|
||||
|
||||
function isnot(a, b, msg) {
|
||||
dump("ISNOT: " + (a!==b) + " => " + a + " | " + b + " " + msg + "\n");
|
||||
postMessage({type: 'status', status: a !== b, msg: a + " !== " + b + ": " + msg });
|
||||
}
|
||||
|
||||
onmessage = function() {
|
||||
status = false;
|
||||
try {
|
||||
@ -111,10 +116,66 @@ onmessage = function() {
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testURL() {
|
||||
var url = new URL('http://www.example.net?a=b&c=d');
|
||||
ok(url.searchParams, "URL searchParams exists!");
|
||||
ok(url.searchParams.has('a'), "URL.searchParams.has('a')");
|
||||
is(url.searchParams.get('a'), 'b', "URL.searchParams.get('a')");
|
||||
ok(url.searchParams.has('c'), "URL.searchParams.has('c')");
|
||||
is(url.searchParams.get('c'), 'd', "URL.searchParams.get('c')");
|
||||
|
||||
url.searchParams.set('e', 'f');
|
||||
ok(url.href.indexOf('e=f') != 1, 'URL right');
|
||||
|
||||
var u = new URLSearchParams();
|
||||
u.append('foo', 'bar');
|
||||
url.searchParams = u;
|
||||
is(url.searchParams, u, "URL.searchParams is the same object");
|
||||
is(url.searchParams.get('foo'), 'bar', "URL.searchParams.get('foo')");
|
||||
is(url.href, 'http://www.example.net/?foo=bar', 'URL right');
|
||||
|
||||
url.searchParams = null;
|
||||
is(url.searchParams.get('foo'), 'bar', "URL.searchParams.get('foo')");
|
||||
is(url.href, 'http://www.example.net/?foo=bar', 'URL right');
|
||||
|
||||
var url2 = new URL('http://www.example.net?e=f');
|
||||
url.searchParams = url2.searchParams;
|
||||
isnot(url.searchParams, url2.searchParams, "URL.searchParams is not the same object");
|
||||
is(url.searchParams.get('e'), 'f', "URL.searchParams.get('e')");
|
||||
|
||||
url.href = "http://www.example.net?bar=foo";
|
||||
is(url.searchParams.get('bar'), 'foo', "URL.searchParams.get('bar')");
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
function testEncoding() {
|
||||
var encoding = [ [ '1', '1' ],
|
||||
[ 'a b', 'a+b' ],
|
||||
[ '<>', '%3C%3E' ],
|
||||
[ '\u0541', '%D5%81'] ];
|
||||
|
||||
for (var i = 0; i < encoding.length; ++i) {
|
||||
var a = new URLSearchParams();
|
||||
a.set('a', encoding[i][0]);
|
||||
|
||||
var url = new URL('http://www.example.net');
|
||||
url.searchParams = a;
|
||||
is(url.href, 'http://www.example.net/?a=' + encoding[i][1]);
|
||||
|
||||
var url2 = new URL(url.href);
|
||||
is(url2.searchParams.get('a'), encoding[i][0], 'a is still there');
|
||||
}
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
var tests = [
|
||||
testSimpleURLSearchParams,
|
||||
testCopyURLSearchParams,
|
||||
testParserURLSearchParams
|
||||
testParserURLSearchParams,
|
||||
testURL,
|
||||
testEncoding
|
||||
];
|
||||
|
||||
function runTest() {
|
||||
@ -129,5 +190,3 @@ onmessage = function() {
|
||||
|
||||
runTest();
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/dom/Link.h"
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
|
||||
class mock_Link : public mozilla::dom::Link
|
||||
{
|
||||
@ -115,6 +116,134 @@ Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Link::URLSearchParamsUpdated()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated");
|
||||
}
|
||||
|
||||
void
|
||||
Link::URLSearchParamsNeedsUpdates()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to Link::URLSearchParamsNeedsUpdates");
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(URLSearchParams)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(URLSearchParams)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(URLSearchParams)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(URLSearchParams)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
URLSearchParams::URLSearchParams()
|
||||
{
|
||||
}
|
||||
|
||||
URLSearchParams::~URLSearchParams()
|
||||
{
|
||||
}
|
||||
|
||||
JSObject*
|
||||
URLSearchParams::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::ParseInput(const nsACString& aInput)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::ParseInput");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::CopyFromURLSearchParams(URLSearchParams& aSearchParams)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::CopyFromURLSearchParams");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::SetObserver(URLSearchParamsObserver* aObserver)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::SetObserver");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Serialize(nsAString& aValue)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Serialize");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Get");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::GetAll(const nsAString& aName, nsTArray<nsString >& aRetval)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::GetAll");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Set(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Set");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Append(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Append");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::AppendInternal(const nsAString& aName, const nsAString& aValue)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::AppendInternal");
|
||||
}
|
||||
|
||||
bool
|
||||
URLSearchParams::Has(const nsAString& aName)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Has");
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Delete(const nsAString& aName)
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Delete");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::DeleteAll()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::DeleteAll");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::NotifyObserver()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::NotifyObserver");
|
||||
}
|
||||
|
||||
void
|
||||
URLSearchParams::Invalidate()
|
||||
{
|
||||
NS_NOTREACHED("Unexpected call to URLSearchParams::Invalidate");
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user