Bug 1632338 - Allow remote window proxies before SetNewDocument. r=peterv
authorAndrew McCreight <continuation@gmail.com>
Mon, 27 Apr 2020 15:22:53 +0000
changeset 526267 d1cdf76164822ead2ad82be4a4090b0f8c88fc80
parent 526266 af13eadc637026cc8316eb7d83aec79347a5dc12
child 526268 c1a36d34c2cc3b8d42e615a4891335123af48007
push id114159
push useramccreight@mozilla.com
push dateMon, 27 Apr 2020 15:23:38 +0000
treeherderautoland@d1cdf7616482 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1632338
milestone77.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 1632338 - Allow remote window proxies before SetNewDocument. r=peterv In BrowsingContext::SetDocShell(), we indicate that any remote outer window proxies need to be cleaned up, if we've transitioned from a remote window proxy to a local one. However, we don't actually do the cleanup until nsGlobalWindowOuter::SetNewDocument(), so don't assert if we find remote window proxies when we're in between these two periods. Also includes a formatting fix by clang-format. Differential Revision: https://phabricator.services.mozilla.com/D72251
docshell/base/BrowsingContext.h
js/xpconnect/wrappers/WrapperFactory.cpp
--- a/docshell/base/BrowsingContext.h
+++ b/docshell/base/BrowsingContext.h
@@ -199,16 +199,20 @@ class BrowsingContext : public nsILoadCo
   // Cast this object to a canonical browsing context, and return it.
   CanonicalBrowsingContext* Canonical();
 
   // Is the most recent Document in this BrowsingContext loaded within this
   // process? This may be true with a null mDocShell after the Window has been
   // closed.
   bool IsInProcess() const { return mIsInProcess; }
 
+  bool CanHaveRemoteOuterProxies() const {
+    return !mIsInProcess || mDanglingRemoteOuterProxies;
+  }
+
   // Has this BrowsingContext been discarded. A discarded browsing context has
   // been destroyed, and may not be available on the other side of an IPC
   // message.
   bool IsDiscarded() const { return mIsDiscarded; }
 
   bool Windowless() const { return mWindowless; }
   void SetWindowless();
 
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -173,22 +173,22 @@ static bool MaybeWrapWindowProxy(JSConte
       retObj.set(obj);
       return true;
     }
   } else {
     bc = dom::GetBrowsingContext(obj);
     MOZ_ASSERT(bc);
   }
 
+  // We should only have a remote window proxy if bc is in a state where we
+  // expect remote window proxies. Otherwise, they should have been cleaned up
+  // by a call to CleanUpDanglingRemoteOuterWindowProxies().
+  MOZ_RELEASE_ASSERT(isWindowProxy || bc->CanHaveRemoteOuterProxies());
+
   if (bc->IsInProcess()) {
-    // Any remote window proxies for bc should have been cleaned up by a call to
-    // CleanUpDanglingRemoteOuterWindowProxies() before now, so obj must be a
-    // local outer window proxy.
-    MOZ_RELEASE_ASSERT(isWindowProxy);
-
     retObj.set(obj);
   } else {
     // If bc is not in process, then use a remote window proxy, whether or not
     // obj is one already.
     if (!dom::GetRemoteOuterWindowProxy(cx, bc, origObj, retObj)) {
       MOZ_CRASH("GetRemoteOuterWindowProxy failed");
     }
   }