Bug 1081677 - Fixing multiple DOMContentLoaded issue for imports. r=smaug
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Tue, 14 Oct 2014 14:02:15 +0200
changeset 210348 c7e87e4946870ed81a2a5e4c276af0c9090564d0
parent 210347 a73e2cda0ec6ce0b93c20424a7d7fbbefc37f30c
child 210349 f8bb9368beb1f0e7d4d50efccf69beee0af5d372
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs1081677
milestone36.0a1
Bug 1081677 - Fixing multiple DOMContentLoaded issue for imports. r=smaug
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/base/src/nsScriptLoader.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -2356,18 +2356,18 @@ public:
 
   // ParentNode
   nsIHTMLCollection* Children();
   uint32_t ChildElementCount();
 
   virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; }
   virtual mozilla::dom::SVGDocument* AsSVGDocument() { return nullptr; }
 
-  // Each import tree has exactly one master document which is
-  // the root of the tree, and owns the browser context.
+  // The root document of the import tree. If this document is not an import
+  // this will return the document itself.
   virtual nsIDocument* MasterDocument() = 0;
   virtual void SetMasterDocument(nsIDocument* master) = 0;
   virtual bool IsMasterDocument() = 0;
   virtual mozilla::dom::ImportManager* ImportManager() = 0;
   // We keep track of the order of sub imports were added to the document.
   virtual bool HasSubImportLink(nsINode* aLink) = 0;
   virtual uint32_t IndexOfSubImportLink(nsINode* aLink) = 0;
   virtual void AddSubImportLink(nsINode* aLink) = 0;
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -4698,20 +4698,16 @@ nsDocument::GetWindowInternal() const
     if (mDocumentContainer) {
       win = mDocumentContainer->GetWindow();
     }
   } else {
     win = do_QueryInterface(mScriptGlobalObject);
     if (win) {
       // mScriptGlobalObject is always the inner window, let's get the outer.
       win = win->GetOuterWindow();
-    } else if (mMasterDocument) {
-      // For script execution in the imported document we need the window of
-      // the master document.
-      win = mMasterDocument->GetWindow();
     }
   }
 
   return win;
 }
 
 nsScriptLoader*
 nsDocument::ScriptLoader()
--- a/content/base/src/nsScriptLoader.cpp
+++ b/content/base/src/nsScriptLoader.cpp
@@ -287,17 +287,18 @@ nsScriptLoader::StartLoad(nsScriptLoadRe
                          : static_cast<nsISupports *>(mDocument);
   nsresult rv = ShouldLoadScript(mDocument, context, aRequest->mURI, aType);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
 
-  nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mDocument->GetWindow()));
+  nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mDocument->MasterDocument()->GetWindow()));
+
   if (!window) {
     return NS_ERROR_NULL_POINTER;
   }
 
   nsIDocShell *docshell = window->GetDocShell();
 
   nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));