Bug 1540839 - Add pref for preserving browsing contexts; r=nika
authorKyle Machulis <kyle@nonpolynomial.com>
Thu, 09 May 2019 12:24:10 -0700
changeset 532671 1dca842b1dd83a06703ef0b9d5ed8d3ad52e4662
parent 532670 8069a95120e0660496da92f8edb6c8fd89180b66
child 532672 6f732caaed60783f57944a66f7ea494f5fd78d6c
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnika
bugs1540839, 1550571
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540839 - Add pref for preserving browsing contexts; r=nika Still having lots of issues with tests failing, but need to get this landed for various reasons. Followup to pref on at Bug 1550571. Differential Revision: https://phabricator.services.mozilla.com/D30563
docshell/base/BrowsingContext.cpp
docshell/base/BrowsingContext.h
dom/base/nsFrameLoaderOwner.cpp
modules/libpref/init/all.js
toolkit/components/remotebrowserutils/tests/browser/browser_oopProcessSwap.js
--- a/docshell/base/BrowsingContext.cpp
+++ b/docshell/base/BrowsingContext.cpp
@@ -808,16 +808,31 @@ void BrowsingContext::Transaction::Apply
     aBrowsingContext->WillSet##name(*m##name, aSource); \
     aBrowsingContext->m##name = std::move(*m##name);    \
     aBrowsingContext->DidSet##name(aSource);            \
     m##name.reset();                                    \
   }
 #include "mozilla/dom/BrowsingContextFieldList.h"
 }
 
+BrowsingContext::IPCInitializer BrowsingContext::GetIPCInitializer() {
+  MOZ_ASSERT(
+      !mozilla::Preferences::GetBool("fission.preserve_browsing_contexts", false) ||
+      IsContent());
+
+  IPCInitializer init;
+  init.mId = Id();
+  init.mParentId = mParent ? mParent->Id() : 0;
+  init.mCached = IsCached();
+
+#define MOZ_BC_FIELD(name, type) init.m##name = m##name;
+#include "mozilla/dom/BrowsingContextFieldList.h"
+  return init;
+}
+
 already_AddRefed<BrowsingContext> BrowsingContext::IPCInitializer::GetParent() {
   RefPtr<BrowsingContext> parent;
   if (mParentId != 0) {
     parent = BrowsingContext::Get(mParentId);
     MOZ_RELEASE_ASSERT(parent);
   }
   return parent.forget();
 }
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -342,27 +342,17 @@ class BrowsingContext : public nsWrapper
     bool mCached;
     // Include each field, skipping mOpener, as we want to handle it
     // separately.
 #define MOZ_BC_FIELD(name, type) type m##name;
 #include "mozilla/dom/BrowsingContextFieldList.h"
   };
 
   // Create an IPCInitializer object for this BrowsingContext.
-  IPCInitializer GetIPCInitializer() {
-    MOZ_ASSERT(IsContent());
-    IPCInitializer init;
-    init.mId = Id();
-    init.mParentId = mParent ? mParent->Id() : 0;
-    init.mCached = IsCached();
-
-#define MOZ_BC_FIELD(name, type) init.m##name = m##name;
-#include "mozilla/dom/BrowsingContextFieldList.h"
-    return init;
-  }
+  IPCInitializer GetIPCInitializer();
 
   // Create a BrowsingContext object from over IPC.
   static already_AddRefed<BrowsingContext> CreateFromIPC(
       IPCInitializer&& aInitializer, BrowsingContextGroup* aGroup,
       ContentParent* aOriginProcess);
 
  protected:
   virtual ~BrowsingContext();
--- a/dom/base/nsFrameLoaderOwner.cpp
+++ b/dom/base/nsFrameLoaderOwner.cpp
@@ -41,18 +41,18 @@ void nsFrameLoaderOwner::ChangeRemotenes
     // is changing from remote to local.
     bool isChromeRemoteToLocal =
         XRE_IsParentProcess() && (!aOptions.mRemoteType.WasPassed() ||
                                   aOptions.mRemoteType.Value().IsVoid());
 
     // If this is a process switch due to a difference in Cross Origin Opener
     // Policy, do not preserve the browsing context. Otherwise, save off the
     // browsing context and use it when creating our new FrameLoader.
-    if (!aOptions.mReplaceBrowsingContext &&
-        !isChromeRemoteToLocal) {
+    if (!aOptions.mReplaceBrowsingContext && !isChromeRemoteToLocal &&
+        mozilla::Preferences::GetBool("fission.preserve_browsing_contexts", false)) {
       bc = mFrameLoader->GetBrowsingContext();
       mFrameLoader->SkipBrowsingContextDetach();
     }
 
     mFrameLoader->Destroy();
     mFrameLoader = nullptr;
   }
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -6038,14 +6038,18 @@ pref("dom.datatransfer.mozAtAPIs", true)
 
 // External.AddSearchProvider is deprecated and it will be removed in the next
 // cycles.
 pref("dom.sidebar.enabled", true);
 
 // Turn on fission frameloader swapping
 pref("fission.rebuild_frameloaders_on_remoteness_change", true);
 
+// If true, preserve browsing contexts between process swaps. Should be set to
+// true in bug 1550571.
+pref("fission.preserve_browsing_contexts", false);
+
 // Support for legacy customizations that rely on checking the
 // user profile directory for these stylesheets:
 //  * userContent.css
 //  * userChrome.css
 pref("toolkit.legacyUserProfileCustomizations.stylesheets", false);
 
--- a/toolkit/components/remotebrowserutils/tests/browser/browser_oopProcessSwap.js
+++ b/toolkit/components/remotebrowserutils/tests/browser/browser_oopProcessSwap.js
@@ -40,17 +40,20 @@ add_task(async function oopProcessSwap()
 
       return {
         location: data.location,
         browsingContextId: iframe.browsingContext.id,
       };
     });
 
     is(browser.browsingContext.getChildren().length, 1);
-    is(frameId, oopinfo.browsingContextId, `BrowsingContext should not have changed (${frameId} != ${oopinfo.browsingContextId})`);
+
+    if (Services.prefs.getBoolPref("fission.preserve_browsing_contexts")) {
+      is(frameId, oopinfo.browsingContextId, `BrowsingContext should not have changed (${frameId} != ${oopinfo.browsingContextId})`);
+    }
     is(oopinfo.location, WEB, "correct location");
   });
 
   await BrowserTestUtils.closeWindow(win);
 });
 
 add_task(async function oopOriginProcessSwap() {
   const COM_DUMMY = httpURL("dummy_page.html", "https://example.com/");
@@ -94,15 +97,17 @@ add_task(async function oopOriginProcess
 
       return {
         location: data.location,
         browsingContextId: iframe.browsingContext.id,
       };
     });
 
     is(browser.browsingContext.getChildren().length, 1);
-    is(frameId, oopinfo.browsingContextId, `BrowsingContext should not have changed (${frameId} != ${oopinfo.browsingContextId})`);
+    if (Services.prefs.getBoolPref("fission.preserve_browsing_contexts")) {
+      is(frameId, oopinfo.browsingContextId, `BrowsingContext should not have changed (${frameId} != ${oopinfo.browsingContextId})`);
+    }
     is(oopinfo.location, ORG_POSTMSG, "correct location");
   });
 
   await BrowserTestUtils.closeWindow(win);
 });