Bug 1329403 - Ensure onload blocker is added once mScriptGlobalObject is set. r=smaug
authorJW Wang <jwwang@mozilla.com>
Mon, 16 Jan 2017 17:12:33 +0800
changeset 377242 17542663b5648395038161ac86f3ef91267e73d3
parent 377241 3eb75c153034bda2340ff22e7ca7efa93d3dcdf4
child 377243 aba1bf821277c995fbae47f5a898eef62ba10a14
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1329403
milestone53.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 1329403 - Ensure onload blocker is added once mScriptGlobalObject is set. r=smaug MozReview-Commit-ID: KREnly28m0v
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4575,18 +4575,26 @@ nsDocument::SetScriptGlobalObject(nsIScr
     // clients.  We only do this for content principal documents
     // since we can never observe system or null principals.
     nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
       os->AddObserver(this, "service-worker-get-client", /* ownsWeak */ false);
     }
   }
 
+  // BlockOnload() might be called before mScriptGlobalObject is set.
+  // We may need to add the blocker once mScriptGlobalObject is set.
+  bool needOnloadBlocker = !mScriptGlobalObject && aScriptGlobalObject;
+
   mScriptGlobalObject = aScriptGlobalObject;
 
+  if (needOnloadBlocker) {
+    EnsureOnloadBlocker();
+  }
+
   if (aScriptGlobalObject) {
     // Go back to using the docshell for the layout history state
     mLayoutHistoryState = nullptr;
     SetScopeObject(aScriptGlobalObject);
     mHasHadDefaultView = true;
 #ifdef DEBUG
     if (!mWillReparent) {
       // We really shouldn't have a wrapper here but if we do we need to make sure