Bug 1037715 - Implement .searchParams on Location, r=bz, r=ehsan
This commit is contained in:
@@ -596,9 +596,10 @@ Link::SetSearchParams(URLSearchParams& aSearchParams)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Link::URLSearchParamsUpdated()
|
Link::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mSearchParams);
|
MOZ_ASSERT(mSearchParams);
|
||||||
|
MOZ_ASSERT(mSearchParams == aSearchParams);
|
||||||
|
|
||||||
nsString search;
|
nsString search;
|
||||||
mSearchParams->Serialize(search);
|
mSearchParams->Serialize(search);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public:
|
|||||||
bool ElementHasHref() const;
|
bool ElementHasHref() const;
|
||||||
|
|
||||||
// URLSearchParamsObserver
|
// URLSearchParamsObserver
|
||||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
void URLSearchParamsUpdated(URLSearchParams* aSearchParams) MOZ_OVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~Link();
|
virtual ~Link();
|
||||||
|
|||||||
@@ -192,6 +192,7 @@
|
|||||||
#include "nsIWidget.h"
|
#include "nsIWidget.h"
|
||||||
#include "mozilla/dom/EncodingUtils.h"
|
#include "mozilla/dom/EncodingUtils.h"
|
||||||
#include "mozilla/dom/ScriptSettings.h"
|
#include "mozilla/dom/ScriptSettings.h"
|
||||||
|
#include "mozilla/dom/URLSearchParams.h"
|
||||||
|
|
||||||
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
||||||
|
|
||||||
@@ -1932,6 +1933,24 @@ nsDocShell::SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
|
|||||||
mLSHE->GetIsSubFrame(&isSubFrame);
|
mLSHE->GetIsSubFrame(&isSubFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nsDocShell owns a URLSearchParams that is used by
|
||||||
|
// window.location.searchParams to be in sync with the current location.
|
||||||
|
if (!mURLSearchParams) {
|
||||||
|
mURLSearchParams = new URLSearchParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoCString search;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURL> url(do_QueryInterface(mCurrentURI));
|
||||||
|
if (url) {
|
||||||
|
nsresult rv = url->GetQuery(search);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
NS_WARNING("Failed to get the query from a nsIURL.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mURLSearchParams->ParseInput(search, nullptr);
|
||||||
|
|
||||||
if (!isSubFrame && !isRoot) {
|
if (!isSubFrame && !isRoot) {
|
||||||
/*
|
/*
|
||||||
* We don't want to send OnLocationChange notifications when
|
* We don't want to send OnLocationChange notifications when
|
||||||
@@ -5348,6 +5367,11 @@ nsDocShell::Destroy()
|
|||||||
mParentWidget = nullptr;
|
mParentWidget = nullptr;
|
||||||
mCurrentURI = nullptr;
|
mCurrentURI = nullptr;
|
||||||
|
|
||||||
|
if (mURLSearchParams) {
|
||||||
|
mURLSearchParams->RemoveObservers();
|
||||||
|
mURLSearchParams = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (mScriptGlobal) {
|
if (mScriptGlobal) {
|
||||||
mScriptGlobal->DetachFromDocShell();
|
mScriptGlobal->DetachFromDocShell();
|
||||||
mScriptGlobal = nullptr;
|
mScriptGlobal = nullptr;
|
||||||
@@ -13187,3 +13211,9 @@ nsDocShell::GetOpenedRemote()
|
|||||||
nsCOMPtr<nsITabParent> openedRemote(do_QueryReferent(mOpenedRemote));
|
nsCOMPtr<nsITabParent> openedRemote(do_QueryReferent(mOpenedRemote));
|
||||||
return openedRemote;
|
return openedRemote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URLSearchParams*
|
||||||
|
nsDocShell::GetURLSearchParams()
|
||||||
|
{
|
||||||
|
return mURLSearchParams;
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
class EventTarget;
|
class EventTarget;
|
||||||
|
class URLSearchParams;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,6 +764,9 @@ protected:
|
|||||||
nsCOMPtr<nsIChannel> mFailedChannel;
|
nsCOMPtr<nsIChannel> mFailedChannel;
|
||||||
uint32_t mFailedLoadType;
|
uint32_t mFailedLoadType;
|
||||||
|
|
||||||
|
// window.location.searchParams is updated in sync with this object.
|
||||||
|
nsRefPtr<mozilla::dom::URLSearchParams> mURLSearchParams;
|
||||||
|
|
||||||
// Set in DoURILoad when either the LOAD_RELOAD_ALLOW_MIXED_CONTENT flag or
|
// Set in DoURILoad when either the LOAD_RELOAD_ALLOW_MIXED_CONTENT flag or
|
||||||
// the LOAD_NORMAL_ALLOW_MIXED_CONTENT flag is set.
|
// the LOAD_NORMAL_ALLOW_MIXED_CONTENT flag is set.
|
||||||
// Checked in nsMixedContentBlocker, to see if the channels match.
|
// Checked in nsMixedContentBlocker, to see if the channels match.
|
||||||
|
|||||||
@@ -11,6 +11,13 @@
|
|||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
class nsPresContext;
|
class nsPresContext;
|
||||||
class nsIPresShell;
|
class nsIPresShell;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace dom {
|
||||||
|
class URLSearchParams;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +26,7 @@ class nsIPresShell;
|
|||||||
|
|
||||||
[ptr] native nsPresContext(nsPresContext);
|
[ptr] native nsPresContext(nsPresContext);
|
||||||
[ptr] native nsIPresShell(nsIPresShell);
|
[ptr] native nsIPresShell(nsIPresShell);
|
||||||
|
[ptr] native URLSearchParams(mozilla::dom::URLSearchParams);
|
||||||
|
|
||||||
interface nsIURI;
|
interface nsIURI;
|
||||||
interface nsIChannel;
|
interface nsIChannel;
|
||||||
@@ -46,7 +54,7 @@ interface nsITabParent;
|
|||||||
|
|
||||||
typedef unsigned long nsLoadFlags;
|
typedef unsigned long nsLoadFlags;
|
||||||
|
|
||||||
[scriptable, builtinclass, uuid(e5fe5c76-e511-4da3-9709-f8294b8dc5ce)]
|
[scriptable, builtinclass, uuid(8ccc5a61-e053-4851-ab00-dadab0dffd7f)]
|
||||||
interface nsIDocShell : nsIDocShellTreeItem
|
interface nsIDocShell : nsIDocShellTreeItem
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -982,4 +990,7 @@ interface nsIDocShell : nsIDocShellTreeItem
|
|||||||
*/
|
*/
|
||||||
[noscript,notxpcom,nostdcall] void setOpenedRemote(in nsITabParent aOpenedRemote);
|
[noscript,notxpcom,nostdcall] void setOpenedRemote(in nsITabParent aOpenedRemote);
|
||||||
[noscript,notxpcom,nostdcall] nsITabParent getOpenedRemote();
|
[noscript,notxpcom,nostdcall] nsITabParent getOpenedRemote();
|
||||||
|
|
||||||
|
// URLSearchParams for the window.location is owned by the docShell.
|
||||||
|
[noscript,notxpcom] URLSearchParams getURLSearchParams();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -341,9 +341,10 @@ URL::SetHost(const nsAString& aHost, ErrorResult& aRv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
URL::URLSearchParamsUpdated()
|
URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mSearchParams);
|
MOZ_ASSERT(mSearchParams);
|
||||||
|
MOZ_ASSERT(mSearchParams == aSearchParams);
|
||||||
|
|
||||||
nsAutoString search;
|
nsAutoString search;
|
||||||
mSearchParams->Serialize(search);
|
mSearchParams->Serialize(search);
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// URLSearchParamsObserver
|
// URLSearchParamsObserver
|
||||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
void URLSearchParamsUpdated(URLSearchParams* aSearchParams) MOZ_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsIURI* GetURI() const
|
nsIURI* GetURI() const
|
||||||
|
|||||||
@@ -237,6 +237,12 @@ URLSearchParams::RemoveObserver(URLSearchParamsObserver* aObserver)
|
|||||||
mObservers.RemoveElement(aObserver);
|
mObservers.RemoveElement(aObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
URLSearchParams::RemoveObservers()
|
||||||
|
{
|
||||||
|
mObservers.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
URLSearchParams::Get(const nsAString& aName, nsString& aRetval)
|
||||||
{
|
{
|
||||||
@@ -387,7 +393,7 @@ URLSearchParams::NotifyObservers(URLSearchParamsObserver* aExceptObserver)
|
|||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
|
for (uint32_t i = 0; i < mObservers.Length(); ++i) {
|
||||||
if (mObservers[i] != aExceptObserver) {
|
if (mObservers[i] != aExceptObserver) {
|
||||||
mObservers[i]->URLSearchParamsUpdated();
|
mObservers[i]->URLSearchParamsUpdated(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,14 @@
|
|||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
|
class URLSearchParams;
|
||||||
|
|
||||||
class URLSearchParamsObserver : public nsISupports
|
class URLSearchParamsObserver : public nsISupports
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~URLSearchParamsObserver() {}
|
virtual ~URLSearchParamsObserver() {}
|
||||||
|
|
||||||
virtual void URLSearchParamsUpdated() = 0;
|
virtual void URLSearchParamsUpdated(URLSearchParams* aFromThis) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class URLSearchParams MOZ_FINAL : public nsISupports,
|
class URLSearchParams MOZ_FINAL : public nsISupports,
|
||||||
@@ -59,6 +61,7 @@ public:
|
|||||||
|
|
||||||
void AddObserver(URLSearchParamsObserver* aObserver);
|
void AddObserver(URLSearchParamsObserver* aObserver);
|
||||||
void RemoveObserver(URLSearchParamsObserver* aObserver);
|
void RemoveObserver(URLSearchParamsObserver* aObserver);
|
||||||
|
void RemoveObservers();
|
||||||
|
|
||||||
void Serialize(nsAString& aValue) const;
|
void Serialize(nsAString& aValue) const;
|
||||||
|
|
||||||
|
|||||||
@@ -68,16 +68,33 @@ nsLocation::nsLocation(nsPIDOMWindow* aWindow, nsIDocShell *aDocShell)
|
|||||||
|
|
||||||
nsLocation::~nsLocation()
|
nsLocation::~nsLocation()
|
||||||
{
|
{
|
||||||
|
RemoveURLSearchParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryInterface implementation for nsLocation
|
// QueryInterface implementation for nsLocation
|
||||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsLocation)
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsLocation)
|
||||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIDOMLocation)
|
NS_INTERFACE_MAP_ENTRY(nsIDOMLocation)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMLocation)
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsLocation, mInnerWindow)
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsLocation)
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsLocation)
|
||||||
|
tmp->RemoveURLSearchParams();
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInnerWindow);
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsLocation)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSearchParams)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInnerWindow)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsLocation)
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsLocation)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsLocation)
|
||||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsLocation)
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsLocation)
|
||||||
|
|
||||||
@@ -858,6 +875,17 @@ nsLocation::GetSearch(nsAString& aSearch)
|
|||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsLocation::SetSearch(const nsAString& aSearch)
|
nsLocation::SetSearch(const nsAString& aSearch)
|
||||||
|
{
|
||||||
|
nsresult rv = SetSearchInternal(aSearch);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsLocation::SetSearchInternal(const nsAString& aSearch)
|
||||||
{
|
{
|
||||||
if (!CallerSubsumes())
|
if (!CallerSubsumes())
|
||||||
return NS_ERROR_DOM_SECURITY_ERR;
|
return NS_ERROR_DOM_SECURITY_ERR;
|
||||||
@@ -1036,3 +1064,119 @@ nsLocation::WrapObject(JSContext* aCx)
|
|||||||
{
|
{
|
||||||
return LocationBinding::Wrap(aCx, this);
|
return LocationBinding::Wrap(aCx, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URLSearchParams*
|
||||||
|
nsLocation::GetDocShellSearchParams()
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
|
||||||
|
if (!docShell) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return docShell->GetURLSearchParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
URLSearchParams*
|
||||||
|
nsLocation::SearchParams()
|
||||||
|
{
|
||||||
|
if (!mSearchParams) {
|
||||||
|
// We must register this object to the URLSearchParams of the docshell in
|
||||||
|
// order to receive updates.
|
||||||
|
nsRefPtr<URLSearchParams> searchParams = GetDocShellSearchParams();
|
||||||
|
if (searchParams) {
|
||||||
|
searchParams->AddObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
mSearchParams = new URLSearchParams();
|
||||||
|
mSearchParams->AddObserver(this);
|
||||||
|
UpdateURLSearchParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
return mSearchParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsLocation::SetSearchParams(URLSearchParams& aSearchParams)
|
||||||
|
{
|
||||||
|
if (mSearchParams) {
|
||||||
|
mSearchParams->RemoveObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the observer will be cleared using the cycle collector.
|
||||||
|
mSearchParams = &aSearchParams;
|
||||||
|
mSearchParams->AddObserver(this);
|
||||||
|
|
||||||
|
nsAutoString search;
|
||||||
|
mSearchParams->Serialize(search);
|
||||||
|
SetSearchInternal(search);
|
||||||
|
|
||||||
|
// We don't need to inform the docShell about this new SearchParams because
|
||||||
|
// setting the new value the docShell will refresh its value automatically.
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsLocation::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(mSearchParams);
|
||||||
|
|
||||||
|
// This change comes from content.
|
||||||
|
if (aSearchParams == mSearchParams) {
|
||||||
|
nsAutoString search;
|
||||||
|
mSearchParams->Serialize(search);
|
||||||
|
SetSearchInternal(search);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This change comes from the docShell.
|
||||||
|
#ifdef DEBUG
|
||||||
|
{
|
||||||
|
nsRefPtr<URLSearchParams> searchParams = GetDocShellSearchParams();
|
||||||
|
MOZ_ASSERT(searchParams);
|
||||||
|
MOZ_ASSERT(aSearchParams == searchParams);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
nsAutoString search;
|
||||||
|
aSearchParams->Serialize(search);
|
||||||
|
mSearchParams->ParseInput(NS_ConvertUTF16toUTF8(search), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsLocation::UpdateURLSearchParams()
|
||||||
|
{
|
||||||
|
if (!mSearchParams) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoCString search;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
nsresult rv = GetURI(getter_AddRefs(uri));
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv)) || NS_WARN_IF(!uri)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsLocation::RemoveURLSearchParams()
|
||||||
|
{
|
||||||
|
if (mSearchParams) {
|
||||||
|
mSearchParams->RemoveObserver(this);
|
||||||
|
mSearchParams = nullptr;
|
||||||
|
|
||||||
|
nsRefPtr<URLSearchParams> docShellSearchParams = GetDocShellSearchParams();
|
||||||
|
if (docShellSearchParams) {
|
||||||
|
docShellSearchParams->RemoveObserver(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "nsCycleCollectionParticipant.h"
|
#include "nsCycleCollectionParticipant.h"
|
||||||
#include "js/TypeDecls.h"
|
#include "js/TypeDecls.h"
|
||||||
#include "mozilla/ErrorResult.h"
|
#include "mozilla/ErrorResult.h"
|
||||||
|
#include "mozilla/dom/URLSearchParams.h"
|
||||||
#include "nsPIDOMWindow.h"
|
#include "nsPIDOMWindow.h"
|
||||||
|
|
||||||
class nsIURI;
|
class nsIURI;
|
||||||
@@ -26,6 +27,7 @@ class nsIDocShellLoadInfo;
|
|||||||
|
|
||||||
class nsLocation MOZ_FINAL : public nsIDOMLocation
|
class nsLocation MOZ_FINAL : public nsIDOMLocation
|
||||||
, public nsWrapperCache
|
, public nsWrapperCache
|
||||||
|
, public mozilla::dom::URLSearchParamsObserver
|
||||||
{
|
{
|
||||||
typedef mozilla::ErrorResult ErrorResult;
|
typedef mozilla::ErrorResult ErrorResult;
|
||||||
|
|
||||||
@@ -33,7 +35,8 @@ public:
|
|||||||
nsLocation(nsPIDOMWindow* aWindow, nsIDocShell *aDocShell);
|
nsLocation(nsPIDOMWindow* aWindow, nsIDocShell *aDocShell);
|
||||||
|
|
||||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsLocation)
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsLocation,
|
||||||
|
nsIDOMLocation)
|
||||||
|
|
||||||
void SetDocShell(nsIDocShell *aDocShell);
|
void SetDocShell(nsIDocShell *aDocShell);
|
||||||
nsIDocShell *GetDocShell();
|
nsIDocShell *GetDocShell();
|
||||||
@@ -118,6 +121,11 @@ public:
|
|||||||
{
|
{
|
||||||
aError = SetSearch(aSeach);
|
aError = SetSearch(aSeach);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mozilla::dom::URLSearchParams* SearchParams();
|
||||||
|
|
||||||
|
void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams);
|
||||||
|
|
||||||
void GetHash(nsAString& aHash, ErrorResult& aError)
|
void GetHash(nsAString& aHash, ErrorResult& aError)
|
||||||
{
|
{
|
||||||
aError = GetHash(aHash);
|
aError = GetHash(aHash);
|
||||||
@@ -136,9 +144,18 @@ public:
|
|||||||
}
|
}
|
||||||
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
||||||
|
|
||||||
|
// URLSearchParamsObserver
|
||||||
|
void URLSearchParamsUpdated(mozilla::dom::URLSearchParams* aSearchParams) MOZ_OVERRIDE;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~nsLocation();
|
virtual ~nsLocation();
|
||||||
|
|
||||||
|
nsresult SetSearchInternal(const nsAString& aSearch);
|
||||||
|
void UpdateURLSearchParams();
|
||||||
|
void RemoveURLSearchParams();
|
||||||
|
|
||||||
|
mozilla::dom::URLSearchParams* GetDocShellSearchParams();
|
||||||
|
|
||||||
// In the case of jar: uris, we sometimes want the place the jar was
|
// In the case of jar: uris, we sometimes want the place the jar was
|
||||||
// fetched from as the URI instead of the jar: uri itself. Pass in
|
// fetched from as the URI instead of the jar: uri itself. Pass in
|
||||||
// true for aGetInnermostURI when that's the case.
|
// true for aGetInnermostURI when that's the case.
|
||||||
@@ -156,6 +173,7 @@ protected:
|
|||||||
|
|
||||||
nsString mCachedHash;
|
nsString mCachedHash;
|
||||||
nsCOMPtr<nsPIDOMWindow> mInnerWindow;
|
nsCOMPtr<nsPIDOMWindow> mInnerWindow;
|
||||||
|
nsRefPtr<mozilla::dom::URLSearchParams> mSearchParams;
|
||||||
nsWeakPtr mDocShell;
|
nsWeakPtr mDocShell;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e1
|
|||||||
[test_history_state_null.html]
|
[test_history_state_null.html]
|
||||||
[test_Image_constructor.html]
|
[test_Image_constructor.html]
|
||||||
[test_innersize_scrollport.html]
|
[test_innersize_scrollport.html]
|
||||||
|
[test_location_searchParams.html]
|
||||||
[test_messageChannel.html]
|
[test_messageChannel.html]
|
||||||
[test_messageChannel_cloning.html]
|
[test_messageChannel_cloning.html]
|
||||||
[test_messageChannel_pingpong.html]
|
[test_messageChannel_pingpong.html]
|
||||||
|
|||||||
89
dom/base/test/test_location_searchParams.html
Normal file
89
dom/base/test/test_location_searchParams.html
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=1037715
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test for Bug 1037715</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1037715">Mozilla Bug 1037715</a>
|
||||||
|
<iframe id="a"></iframe>
|
||||||
|
<script type="application/javascript">
|
||||||
|
|
||||||
|
var l;
|
||||||
|
|
||||||
|
var iframe = document.getElementById('a');
|
||||||
|
function onload0() {
|
||||||
|
iframe.removeEventListener('load', onload0);
|
||||||
|
|
||||||
|
l = iframe.contentWindow.location;
|
||||||
|
is(l.searchParams.get('a'), 'test0', 'l.searchParams value is ok');
|
||||||
|
|
||||||
|
info('changing location from JS...');
|
||||||
|
iframe.addEventListener('load', onload1);
|
||||||
|
iframe.contentWindow.location.href = 'file_empty.html?a=test1';
|
||||||
|
}
|
||||||
|
|
||||||
|
function onload1() {
|
||||||
|
iframe.removeEventListener('load', onload1);
|
||||||
|
|
||||||
|
var ll = iframe.contentWindow.location;
|
||||||
|
is(ll.searchParams.get('a'), 'test1', 'location.searchParams value is ok');
|
||||||
|
is(l.searchParams.get('a'), 'test1', 'l.searchParams value is ok');
|
||||||
|
isnot(ll.searchParams, l.searchParams, '2 different objects.');
|
||||||
|
|
||||||
|
info('changing location using l.searchParams...');
|
||||||
|
iframe.addEventListener('load', onload2);
|
||||||
|
l.searchParams.set('a', 'test2');
|
||||||
|
}
|
||||||
|
|
||||||
|
function onload2() {
|
||||||
|
iframe.removeEventListener('load', onload2);
|
||||||
|
|
||||||
|
var ll = iframe.contentWindow.location;
|
||||||
|
is(ll.searchParams.get('a'), 'test2', 'location.searchParams value is ok');
|
||||||
|
is(l.searchParams.get('a'), 'test2', 'l.searchParams value is ok');
|
||||||
|
isnot(ll.searchParams, l.searchParams, '2 different objects.');
|
||||||
|
|
||||||
|
info('changing iframe.src...');
|
||||||
|
iframe.addEventListener('load', onload3);
|
||||||
|
l.search = 'a=test3';
|
||||||
|
}
|
||||||
|
|
||||||
|
function onload3() {
|
||||||
|
iframe.removeEventListener('load', onload3);
|
||||||
|
|
||||||
|
var ll = iframe.contentWindow.location;
|
||||||
|
is(ll.searchParams.get('a'), 'test3', 'location.searchParams value is ok');
|
||||||
|
is(l.searchParams.get('a'), 'test3', 'l.searchParams value is ok');
|
||||||
|
isnot(ll.searchParams, l.searchParams, '2 different objects.');
|
||||||
|
|
||||||
|
info('changing iframe.src...');
|
||||||
|
iframe.addEventListener('load', onload4);
|
||||||
|
iframe.src = 'file_empty.html?a=test4';
|
||||||
|
}
|
||||||
|
|
||||||
|
function onload4() {
|
||||||
|
iframe.removeEventListener('load', onload4);
|
||||||
|
|
||||||
|
var ll = iframe.contentWindow.location;
|
||||||
|
is(ll.searchParams.get('a'), 'test4', 'location.searchParams value is ok');
|
||||||
|
is(l.searchParams.get('a'), 'test4', 'l.searchParams value is ok');
|
||||||
|
isnot(ll.searchParams, l.searchParams, '2 different objects.');
|
||||||
|
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
iframe.addEventListener('load', onload0);
|
||||||
|
iframe.src = "file_empty.html?a=test0";
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -22,4 +22,4 @@ interface Location {
|
|||||||
void reload(optional boolean forceget = false);
|
void reload(optional boolean forceget = false);
|
||||||
};
|
};
|
||||||
// No support for .searchParams on Location yet. See bug 1037715.
|
// No support for .searchParams on Location yet. See bug 1037715.
|
||||||
Location implements URLUtilsNoSearchParams;
|
Location implements URLUtils;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
[NoInterfaceObject,
|
[NoInterfaceObject,
|
||||||
Exposed=(Window, Worker)]
|
Exposed=(Window, Worker)]
|
||||||
interface URLUtilsNoSearchParams {
|
interface URLUtils {
|
||||||
// Bug 824857: no support for stringifier attributes yet.
|
// Bug 824857: no support for stringifier attributes yet.
|
||||||
// stringifier attribute DOMString href;
|
// stringifier attribute DOMString href;
|
||||||
[Throws, CrossOriginWritable=Location]
|
[Throws, CrossOriginWritable=Location]
|
||||||
@@ -39,7 +39,9 @@ interface URLUtilsNoSearchParams {
|
|||||||
attribute DOMString pathname;
|
attribute DOMString pathname;
|
||||||
[Throws]
|
[Throws]
|
||||||
attribute DOMString search;
|
attribute DOMString search;
|
||||||
// searchParams should go here once Location implements it. See bug 1037715.
|
|
||||||
|
attribute URLSearchParams searchParams;
|
||||||
|
|
||||||
[Throws]
|
[Throws]
|
||||||
attribute DOMString hash;
|
attribute DOMString hash;
|
||||||
|
|
||||||
@@ -47,10 +49,3 @@ interface URLUtilsNoSearchParams {
|
|||||||
[Throws]
|
[Throws]
|
||||||
stringifier;
|
stringifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
[NoInterfaceObject,
|
|
||||||
Exposed=(Window, Worker)]
|
|
||||||
interface URLUtils : URLUtilsNoSearchParams
|
|
||||||
{
|
|
||||||
attribute URLSearchParams searchParams;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -894,9 +894,10 @@ URL::RevokeObjectURL(const GlobalObject& aGlobal, const nsAString& aUrl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
URL::URLSearchParamsUpdated()
|
URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(mSearchParams);
|
MOZ_ASSERT(mSearchParams);
|
||||||
|
MOZ_ASSERT(mSearchParams == aSearchParams);
|
||||||
|
|
||||||
nsString search;
|
nsString search;
|
||||||
mSearchParams->Serialize(search);
|
mSearchParams->Serialize(search);
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IURLSearchParamsObserver
|
// IURLSearchParamsObserver
|
||||||
void URLSearchParamsUpdated() MOZ_OVERRIDE;
|
void URLSearchParamsUpdated(URLSearchParams* aSearchParams) MOZ_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
URLProxy* GetURLProxy() const
|
URLProxy* GetURLProxy() const
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ Link::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Link::URLSearchParamsUpdated()
|
Link::URLSearchParamsUpdated(URLSearchParams* aSearchParams)
|
||||||
{
|
{
|
||||||
NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated");
|
NS_NOTREACHED("Unexpected call to Link::URLSearchParamsUpdated");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user