Bug 1037715 - Implement .searchParams on Location, r=bz, r=ehsan

This commit is contained in:
Andrea Marchesini
2014-08-07 17:45:21 -07:00
parent 39e838131c
commit ffe9ef5b47
18 changed files with 327 additions and 23 deletions

View File

@@ -192,6 +192,7 @@
#include "nsIWidget.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/URLSearchParams.h"
static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
@@ -1932,6 +1933,24 @@ nsDocShell::SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
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) {
/*
* We don't want to send OnLocationChange notifications when
@@ -5348,6 +5367,11 @@ nsDocShell::Destroy()
mParentWidget = nullptr;
mCurrentURI = nullptr;
if (mURLSearchParams) {
mURLSearchParams->RemoveObservers();
mURLSearchParams = nullptr;
}
if (mScriptGlobal) {
mScriptGlobal->DetachFromDocShell();
mScriptGlobal = nullptr;
@@ -13187,3 +13211,9 @@ nsDocShell::GetOpenedRemote()
nsCOMPtr<nsITabParent> openedRemote(do_QueryReferent(mOpenedRemote));
return openedRemote;
}
URLSearchParams*
nsDocShell::GetURLSearchParams()
{
return mURLSearchParams;
}