From a371672f3d8f3773adac648fb738443724dc21bf Mon Sep 17 00:00:00 2001 From: Fedor Date: Sun, 17 Jan 2021 16:10:47 +0200 Subject: [PATCH] Restore browser.history.allow... and more. --- dom/base/nsGlobalWindow.cpp | 9 ++++++- dom/base/nsHistory.cpp | 48 +++++++++++++++++++++++++++++++++++++ modules/libpref/init/all.js | 4 ++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 4e80568f6..ddbb26487 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -470,6 +470,8 @@ static uint32_t gThrottledIdlePeriodLength; // CIDs static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID); +static const char sPopStatePrefStr[] = "browser.history.allowPopState"; + #define NETWORK_UPLOAD_EVENT_NAME NS_LITERAL_STRING("moznetworkupload") #define NETWORK_DOWNLOAD_EVENT_NAME NS_LITERAL_STRING("moznetworkdownload") @@ -10637,9 +10639,14 @@ nsGlobalWindow::DispatchSyncPopState() nsresult rv = NS_OK; + // Check that PopState hasn't been pref'ed off. + if (!Preferences::GetBool(sPopStatePrefStr, false)) { + return rv; + } + // Bail if the window is frozen. if (IsFrozen()) { - return NS_OK; + return rv; } // Get the document's pending state object -- it contains the data we're diff --git a/dom/base/nsHistory.cpp b/dom/base/nsHistory.cpp index 2e989676b..497b962d9 100644 --- a/dom/base/nsHistory.cpp +++ b/dom/base/nsHistory.cpp @@ -24,6 +24,12 @@ using namespace mozilla; using namespace mozilla::dom; +static const char* sAllowPushStatePrefStr = + "browser.history.allowPushState"; +static const char* sAllowReplaceStatePrefStr = + "browser.history.allowReplaceState"; +static const char* sAllowOtherStuffPrefStr = + "browser.history.allowOtherStuff"; // // History class implementation // @@ -62,6 +68,11 @@ nsHistory::WrapObject(JSContext* aCx, JS::Handle aGivenProto) uint32_t nsHistory::GetLength(ErrorResult& aRv) const { + + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + return 0; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win || !win->HasActiveDocument()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); @@ -92,6 +103,10 @@ nsHistory::GetLength(ErrorResult& aRv) const ScrollRestoration nsHistory::GetScrollRestoration(mozilla::ErrorResult& aRv) { + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + return mozilla::dom::ScrollRestoration::Auto; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win || !win->HasActiveDocument() || !win->GetDocShell()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); @@ -110,6 +125,11 @@ void nsHistory::SetScrollRestoration(mozilla::dom::ScrollRestoration aMode, mozilla::ErrorResult& aRv) { + + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + return; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win || !win->HasActiveDocument() || !win->GetDocShell()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); @@ -125,6 +145,12 @@ void nsHistory::GetState(JSContext* aCx, JS::MutableHandle aResult, ErrorResult& aRv) const { + + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + aResult.setNull(); + return; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); @@ -166,6 +192,11 @@ nsHistory::GetState(JSContext* aCx, JS::MutableHandle aResult, void nsHistory::Go(int32_t aDelta, ErrorResult& aRv) { + + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + return; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win || !win->HasActiveDocument()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); @@ -225,6 +256,11 @@ nsHistory::Go(int32_t aDelta, ErrorResult& aRv) void nsHistory::Back(ErrorResult& aRv) { + + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + return; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win || !win->HasActiveDocument()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); @@ -246,6 +282,11 @@ nsHistory::Back(ErrorResult& aRv) void nsHistory::Forward(ErrorResult& aRv) { + + if (!Preferences::GetBool(sAllowOtherStuffPrefStr, false)) { + return; + } + nsCOMPtr win(do_QueryReferent(mInnerWindow)); if (!win || !win->HasActiveDocument()) { aRv.Throw(NS_ERROR_DOM_SECURITY_ERR); @@ -298,6 +339,13 @@ nsHistory::PushOrReplaceState(JSContext* aCx, JS::Handle aData, return; } + // Check that PushState hasn't been pref'ed off. + if (!Preferences::GetBool(aReplace ? sAllowReplaceStatePrefStr : + sAllowPushStatePrefStr, false)) { + aRv = NS_OK; + return; + } + // AddState might run scripts, so we need to hold a strong reference to the // docShell here to keep it from going away. nsCOMPtr docShell = win->GetDocShell(); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 68623418d..ac7271f01 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4680,6 +4680,10 @@ pref("html5.flushtimer.initialdelay", 120); pref("html5.flushtimer.subsequentdelay", 120); // Push/Pop/Replace State prefs +pref("browser.history.allowPushState", true); +pref("browser.history.allowReplaceState", true); +pref("browser.history.allowPopState", true); +pref("browser.history.allowOtherStuff", true); pref("browser.history.maxStateObjectSize", 655360); pref("browser.meta_refresh_when_inactive.disabled", false);