Bug 1081677 - Fixing multiple DOMContentLoaded issue for imports. r=smaug
--- 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));