Bug 1697171 - Clear various states referring to the old BrowserParent when it enters bfcache, r=peterv
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 11 Mar 2021 19:36:20 +0000
changeset 638079 2823dcb7e5321861005f72d4caa011ddd4fc3ea6
parent 638078 5ebb11d146cdf1b04a5239a359b962d37b351c72
child 638080 f7c3a7daf52271c4bc80b11ba32979f8b08b9957
push id15212
push userffxbld-merge
push dateMon, 22 Mar 2021 14:40:41 +0000
treeherdermozilla-beta@ad9bae9bb10c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1697171
milestone88.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 1697171 - Clear various states referring to the old BrowserParent when it enters bfcache, r=peterv Differential Revision: https://phabricator.services.mozilla.com/D107644
docshell/shistory/SessionHistoryEntry.cpp
dom/ipc/BrowserParent.cpp
dom/ipc/BrowserParent.h
--- a/docshell/shistory/SessionHistoryEntry.cpp
+++ b/docshell/shistory/SessionHistoryEntry.cpp
@@ -13,16 +13,17 @@
 #include "nsIXULRuntime.h"
 #include "nsSHEntryShared.h"
 #include "nsSHistory.h"
 #include "nsStructuredCloneContainer.h"
 #include "nsXULAppAPI.h"
 #include "mozilla/PresState.h"
 #include "mozilla/StaticPrefs_fission.h"
 #include "mozilla/Tuple.h"
+#include "mozilla/dom/BrowserParent.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/CSPMessageUtils.h"
 #include "mozilla/dom/DOMTypes.h"
 #include "mozilla/dom/nsCSPContext.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
 #include "mozilla/dom/ReferrerInfoUtils.h"
 #include "mozilla/ipc/IPDLParamTraits.h"
@@ -1352,16 +1353,20 @@ SHEntrySharedParentState* SessionHistory
 }
 
 void SessionHistoryEntry::SetFrameLoader(nsFrameLoader* aFrameLoader) {
   MOZ_ASSERT_IF(aFrameLoader, !SharedInfo()->mFrameLoader);
   // If the pref is disabled, we still allow evicting the existing entries.
   MOZ_RELEASE_ASSERT(!aFrameLoader || mozilla::BFCacheInParent());
   SharedInfo()->mFrameLoader = aFrameLoader;
   if (aFrameLoader) {
+    if (BrowserParent* bp = aFrameLoader->GetBrowserParent()) {
+      bp->Deactivated();
+    }
+
     // When a new frameloader is stored, try to evict some older
     // frameloaders. Non-SHIP session history has a similar call in
     // nsDocumentViewer::Show.
     nsCOMPtr<nsISHistory> shistory;
     GetShistory(getter_AddRefs(shistory));
     if (shistory) {
       int32_t index = 0;
       shistory->GetIndex(&index);
--- a/dom/ipc/BrowserParent.cpp
+++ b/dom/ipc/BrowserParent.cpp
@@ -595,22 +595,26 @@ void BrowserParent::RemoveWindowListener
     nsCOMPtr<EventTarget> eventTarget = window->GetTopWindowRoot();
     if (eventTarget) {
       eventTarget->RemoveEventListener(u"MozUpdateWindowPos"_ns, this, false);
       eventTarget->RemoveEventListener(u"fullscreenchange"_ns, this, false);
     }
   }
 }
 
-void BrowserParent::DestroyInternal() {
+void BrowserParent::Deactivated() {
   UnsetTopLevelWebFocus(this);
   UnsetLastMouseRemoteTarget(this);
   PointerLockManager::ReleaseLockedRemoteTarget(this);
   PointerEventHandler::ReleasePointerCaptureRemoteTarget(this);
   PresShell::ReleaseCapturingRemoteTarget(this);
+}
+
+void BrowserParent::DestroyInternal() {
+  Deactivated();
 
   RemoveWindowListeners();
 
 #ifdef ACCESSIBILITY
   if (a11y::DocAccessibleParent* tabDoc = GetTopLevelDocAccessible()) {
     tabDoc->Destroy();
   }
 #endif
@@ -680,21 +684,17 @@ void BrowserParent::ActorDestroy(ActorDe
     // destroyed, otherwise it may still send messages to the compositor which
     // will reject them, causing assertions.
     RemoveBrowserParentFromTable(mRemoteLayerTreeOwner.GetLayersId());
     mRemoteLayerTreeOwner.Destroy();
   }
 
   // Even though BrowserParent::Destroy calls this, we need to do it here too in
   // case of a crash.
-  BrowserParent::UnsetTopLevelWebFocus(this);
-  BrowserParent::UnsetLastMouseRemoteTarget(this);
-  PointerLockManager::ReleaseLockedRemoteTarget(this);
-  PointerEventHandler::ReleasePointerCaptureRemoteTarget(this);
-  PresShell::ReleaseCapturingRemoteTarget(this);
+  Deactivated();
 
   if (why == AbnormalShutdown) {
     // dom_reporting_header must also be enabled for the report to be sent.
     if (StaticPrefs::dom_reporting_crash_enabled()) {
       nsCOMPtr<nsIPrincipal> principal = GetContentPrincipal();
 
       if (principal) {
         nsAutoCString crash_reason;
--- a/dom/ipc/BrowserParent.h
+++ b/dom/ipc/BrowserParent.h
@@ -705,16 +705,19 @@ class BrowserParent final : public PBrow
   bool StartApzAutoscroll(float aAnchorX, float aAnchorY, nsViewID aScrollId,
                           uint32_t aPresShellId);
   void StopApzAutoscroll(nsViewID aScrollId, uint32_t aPresShellId);
 
   bool CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType,
                           int32_t aNavigationIndex,
                           nsIURI* aNavigationURI) const;
 
+  // Called when the BrowserParent is being destroyed or entering bfcache.
+  void Deactivated();
+
  protected:
   friend BrowserBridgeParent;
   friend BrowserHost;
 
   void SetBrowserBridgeParent(BrowserBridgeParent* aBrowser);
   void SetBrowserHost(BrowserHost* aBrowser);
 
   bool ReceiveMessage(