diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 3b130e2ffb6..d84be96f710 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -114,8 +114,8 @@ typedef CallbackObjectHolder NodeFilterHolder; } // namespace mozilla #define NS_IDOCUMENT_IID \ -{ 0x308f8444, 0x7679, 0x445a, \ - { 0xa6, 0xcc, 0xb9, 0x5c, 0x61, 0xff, 0xe2, 0x66 } } +{ 0x62cca591, 0xa030, 0x4117, \ + { 0x9b, 0x80, 0xdc, 0xd3, 0x66, 0xbb, 0xb5, 0x9 } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -770,13 +770,6 @@ public: return mStyleAttrStyleSheet; } - /** - * Get/set the object from which a document can get a script context - * and scope. This is the context within which all scripts (during - * document creation and during event handling) will run. Note that - * this is the *inner* window object. - */ - virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0; virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0; /** @@ -1475,8 +1468,7 @@ public: { NS_PRECONDITION(!GetShell() && !nsCOMPtr(GetContainer()) && - !GetWindow() && - !GetScriptGlobalObject(), + !GetWindow(), "Shouldn't set mDisplayDocument on documents that already " "have a presentation or a docshell or a window"); NS_PRECONDITION(aDisplayDocument != this, "Should be different document"); diff --git a/content/base/src/nsContentSink.cpp b/content/base/src/nsContentSink.cpp index 1977e83f65d..c75ec979624 100644 --- a/content/base/src/nsContentSink.cpp +++ b/content/base/src/nsContentSink.cpp @@ -308,7 +308,7 @@ nsContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue, NS_ENSURE_TRUE(codebaseURI, rv); nsCOMPtr prompt; - nsCOMPtr window = do_QueryInterface(mDocument->GetScriptGlobalObject()); + nsCOMPtr window = do_QueryInterface(mDocument->GetWindow()); if (window) { window->GetPrompter(getter_AddRefs(prompt)); } diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index a03d15ebb5a..c7c8f47c272 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -6100,10 +6100,10 @@ nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern, nsIDocument* aDocument) { NS_ASSERTION(aDocument, "aDocument should be a valid pointer (not null)"); - NS_ENSURE_TRUE(aDocument->GetScriptGlobalObject(), true); + nsCOMPtr sgo = do_QueryInterface(aDocument->GetWindow()); + NS_ENSURE_TRUE(sgo, true); - AutoPushJSContext cx(aDocument->GetScriptGlobalObject()-> - GetContext()->GetNativeContext()); + AutoPushJSContext cx(sgo->GetContext()->GetNativeContext()); NS_ENSURE_TRUE(cx, true); // The pattern has to match the entire value. diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index f89f1e46022..df40c4b787d 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -4078,28 +4078,6 @@ nsDocument::FirstAdditionalAuthorSheet() return mAdditionalSheets[eAuthorSheet].SafeObjectAt(0); } -nsIScriptGlobalObject* -nsDocument::GetScriptGlobalObject() const -{ - // If we're going away, we've already released the reference to our - // ScriptGlobalObject. We can, however, try to obtain it for the - // caller through our docshell. - - // We actually need to start returning the docshell's script global - // object as soon as nsDocumentViewer::Close has called - // RemovedFromDocShell on us. - if (mRemovedFromDocShell) { - nsCOMPtr requestor = - do_QueryReferent(mDocumentContainer); - if (requestor) { - nsCOMPtr globalObject = do_GetInterface(requestor); - return globalObject; - } - } - - return mScriptGlobalObject; -} - nsIGlobalObject* nsDocument::GetScopeObject() const { @@ -4270,14 +4248,25 @@ nsPIDOMWindow * nsDocument::GetWindowInternal() const { MOZ_ASSERT(!mWindow, "This should not be called when mWindow is not null!"); - - nsCOMPtr win(do_QueryInterface(GetScriptGlobalObject())); - - if (!win) { - return nullptr; + // Let's use mScriptGlobalObject. Even if the document is already removed from + // the docshell, the outer window might be still obtainable from the it. + nsCOMPtr win; + if (mRemovedFromDocShell) { + nsCOMPtr requestor = + do_QueryReferent(mDocumentContainer); + if (requestor) { + // The docshell returns the outer window we are done. + win = do_GetInterface(requestor); + } + } else { + win = do_QueryInterface(mScriptGlobalObject); + if (win) { + // mScriptGlobalObject is always the inner window, let's get the outer. + win = win->GetOuterWindow(); + } } - return win->GetOuterWindow(); + return win; } nsScriptLoader* @@ -7111,7 +7100,7 @@ nsDocument::IsScriptEnabled() nsCOMPtr sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID)); NS_ENSURE_TRUE(sm, false); - nsIScriptGlobalObject* globalObject = GetScriptGlobalObject(); + nsCOMPtr globalObject = do_QueryInterface(GetWindow()); NS_ENSURE_TRUE(globalObject, false); nsIScriptContext *scriptContext = globalObject->GetContext(); @@ -8123,7 +8112,7 @@ nsDocument::MutationEventDispatched(nsINode* aTarget) } nsCOMPtr window; - window = do_QueryInterface(GetScriptGlobalObject()); + window = do_QueryInterface(GetWindow()); if (window && !window->HasMutationListeners(NS_EVENT_BITS_MUTATION_SUBTREEMODIFIED)) { mSubtreeModifiedTargets.Clear(); @@ -11275,7 +11264,7 @@ nsIDocument::WrapObject(JSContext *aCx, JS::Handle aScope) return nullptr; } - nsCOMPtr win = do_QueryInterface(GetScriptGlobalObject()); + nsCOMPtr win = do_QueryInterface(GetInnerWindow()); if (!win) { // No window, nothing else to do here return obj; diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 7848dd61e53..507a0710b66 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -640,12 +640,6 @@ public: return mChannel; } - /** - * Set the object from which a document can get a script context. - * This is the context within which all scripts (during document - * creation and during event handling) will run. - */ - virtual nsIScriptGlobalObject* GetScriptGlobalObject() const MOZ_OVERRIDE; virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) MOZ_OVERRIDE; virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) MOZ_OVERRIDE; diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index c4735ed3aaa..22eb14caa05 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -1797,7 +1797,7 @@ nsFrameLoader::GetWindowDimensions(nsRect& aRect) } nsCOMPtr parentAsWebNav = - do_GetInterface(doc->GetScriptGlobalObject()); + do_GetInterface(doc->GetWindow()); if (!parentAsWebNav) { return NS_ERROR_FAILURE; @@ -1973,7 +1973,7 @@ nsFrameLoader::TryRemoteBrowser() } nsCOMPtr parentAsWebNav = - do_GetInterface(doc->GetScriptGlobalObject()); + do_GetInterface(doc->GetWindow()); if (!parentAsWebNav) { return false; diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index aeb660afb29..74057aa67b0 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -603,9 +603,9 @@ nsObjectLoadingContent::IsSupportedDocument(const nsCString& aMimeType) nsCOMPtr webNav; nsIDocument* currentDoc = thisContent->GetCurrentDoc(); if (currentDoc) { - webNav = do_GetInterface(currentDoc->GetScriptGlobalObject()); + webNav = do_GetInterface(currentDoc->GetWindow()); } - + uint32_t supported; nsresult rv = info->IsTypeSupported(aMimeType, webNav, &supported); diff --git a/content/base/src/nsScriptLoader.cpp b/content/base/src/nsScriptLoader.cpp index 040650b1447..fdd7fb13674 100644 --- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -273,7 +273,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, nsCOMPtr loadGroup = mDocument->GetDocumentLoadGroup(); - nsCOMPtr window(do_QueryInterface(mDocument->GetScriptGlobalObject())); + nsCOMPtr window(do_QueryInterface(mDocument->GetWindow())); if (!window) { return NS_ERROR_NULL_POINTER; } @@ -430,7 +430,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) // For now though, if JS is disabled we assume every language is // disabled. // XXX is this different from the mDocument->IsScriptEnabled() call? - nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); + nsCOMPtr globalObject = + do_QueryInterface(mDocument->GetWindow()); if (!globalObject) { return false; } diff --git a/content/html/content/src/HTMLCanvasElement.cpp b/content/html/content/src/HTMLCanvasElement.cpp index 97b76279804..2b343d6d763 100644 --- a/content/html/content/src/HTMLCanvasElement.cpp +++ b/content/html/content/src/HTMLCanvasElement.cpp @@ -889,10 +889,11 @@ HTMLCanvasElement::InvalidateCanvasContent(const gfx::Rect* damageRect) * invalidating a canvas will feed into heuristics and cause JIT code to be * kept around longer, for smoother animations. */ - nsIScriptGlobalObject *scope = OwnerDoc()->GetScriptGlobalObject(); - if (scope) { - JSObject *obj = scope->GetGlobalJSObject(); - if (obj) { + nsCOMPtr global = + do_QueryInterface(OwnerDoc()->GetInnerWindow()); + + if (global) { + if (JSObject *obj = global->GetGlobalJSObject()) { js::NotifyAnimationActivity(obj); } } diff --git a/content/html/document/src/ImageDocument.cpp b/content/html/document/src/ImageDocument.cpp index 76cff5ec794..1d01a3fbcd7 100644 --- a/content/html/document/src/ImageDocument.cpp +++ b/content/html/document/src/ImageDocument.cpp @@ -81,8 +81,7 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt) return NS_ERROR_FAILURE; } - nsCOMPtr domWindow = - do_QueryInterface(imgDoc->GetScriptGlobalObject()); + nsCOMPtr domWindow = imgDoc->GetWindow(); NS_ENSURE_TRUE(domWindow, NS_ERROR_UNEXPECTED); // Do a ShouldProcess check to see whether to keep loading the image. diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index cfea9986c32..861d4aea932 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -1321,7 +1321,8 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer) { NS_ENSURE_TRUE(aDoc && aContainer, true); - nsCOMPtr globalObject = aDoc->GetScriptGlobalObject(); + nsCOMPtr globalObject = + do_QueryInterface(aDoc->GetWindow()); // Getting context is tricky if the document hasn't had its // GlobalObject set yet diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index c53939b815e..b62c5508d4f 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -1172,7 +1172,8 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, nsIDocument* doc = aContent->OwnerDoc(); - nsIScriptGlobalObject *global = doc->GetScriptGlobalObject(); + nsCOMPtr global = + do_QueryInterface(doc->GetWindow()); if (!global) return NS_NOINTERFACE; diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 3fe617fecb1..358c291ae26 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -1254,7 +1254,7 @@ nsXBLBinding::AllowScripts() return false; } - nsIScriptGlobalObject* global = doc->GetScriptGlobalObject(); + nsCOMPtr global = do_QueryInterface(doc->GetWindow()); if (!global) { return false; } diff --git a/content/xbl/src/nsXBLProtoImplField.cpp b/content/xbl/src/nsXBLProtoImplField.cpp index 1739cadc982..0c95f0ed90d 100644 --- a/content/xbl/src/nsXBLProtoImplField.cpp +++ b/content/xbl/src/nsXBLProtoImplField.cpp @@ -195,7 +195,8 @@ InstallXBLField(JSContext* cx, MOZ_ASSERT(field); // This mirrors code in nsXBLProtoImpl::InstallImplementation - nsIScriptGlobalObject* global = xblNode->OwnerDoc()->GetScriptGlobalObject(); + nsCOMPtr global = + do_QueryInterface(xblNode->OwnerDoc()->GetWindow()); if (!global) { return true; } diff --git a/content/xbl/src/nsXBLProtoImplMethod.cpp b/content/xbl/src/nsXBLProtoImplMethod.cpp index e9008ee3d66..6a96f8b8cd9 100644 --- a/content/xbl/src/nsXBLProtoImplMethod.cpp +++ b/content/xbl/src/nsXBLProtoImplMethod.cpp @@ -281,7 +281,8 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement) // nsXBLProtoImpl::InstallImplementation does. nsIDocument* document = aBoundElement->OwnerDoc(); - nsIScriptGlobalObject* global = document->GetScriptGlobalObject(); + nsCOMPtr global = + do_QueryInterface(document->GetWindow()); if (!global) { return NS_OK; } diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index 360367ad6cf..494d897cd99 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -454,7 +454,7 @@ nsXBLPrototypeHandler::DispatchXBLCommand(EventTarget* aTarget, nsIDOMEvent* aEv if (!doc) return NS_ERROR_FAILURE; - privateWindow = do_QueryInterface(doc->GetScriptGlobalObject()); + privateWindow = doc->GetWindow(); if (!privateWindow) return NS_ERROR_FAILURE; } diff --git a/content/xul/document/src/nsXULCommandDispatcher.cpp b/content/xul/document/src/nsXULCommandDispatcher.cpp index c8ede4504e9..ae9c246b018 100644 --- a/content/xul/document/src/nsXULCommandDispatcher.cpp +++ b/content/xul/document/src/nsXULCommandDispatcher.cpp @@ -97,7 +97,7 @@ already_AddRefed nsXULCommandDispatcher::GetWindowRoot() { if (mDocument) { - nsCOMPtr window(do_QueryInterface(mDocument->GetScriptGlobalObject())); + nsCOMPtr window(mDocument->GetWindow()); if (window) { return window->GetTopWindowRoot(); } diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index f8e809caebe..6e0cc1b1651 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -945,9 +945,9 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes, // Don't process scripts that aren't known if (langID != nsIProgrammingLanguage::UNKNOWN) { - nsIScriptGlobalObject* globalObject = nullptr; // borrowed reference + nsCOMPtr globalObject; if (doc) - globalObject = doc->GetScriptGlobalObject(); + globalObject = do_QueryInterface(doc->GetWindow()); nsRefPtr script = new nsXULPrototypeScript(aLineNumber, version); if (! script) diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 6946514d2ab..2f7c8198851 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1371,7 +1371,8 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot() if (! doc) return NS_ERROR_UNEXPECTED; - nsIScriptGlobalObject *global = doc->GetScriptGlobalObject(); + nsCOMPtr global = + do_QueryInterface(doc->GetWindow()); if (! global) return NS_ERROR_UNEXPECTED; diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 0d9369ce952..134b5492205 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8074,11 +8074,7 @@ nsGlobalWindow::GetPrivateParent() if (!doc) return nullptr; // This is ok, just means a null parent. - nsIScriptGlobalObject *globalObject = doc->GetScriptGlobalObject(); - if (!globalObject) - return nullptr; // This is ok, just means a null parent. - - parent = do_QueryInterface(globalObject); + return doc->GetWindow(); } if (parent) { diff --git a/dom/plugins/base/nsNPAPIPlugin.cpp b/dom/plugins/base/nsNPAPIPlugin.cpp index 6a6b3b674c5..99e8e4e9030 100644 --- a/dom/plugins/base/nsNPAPIPlugin.cpp +++ b/dom/plugins/base/nsNPAPIPlugin.cpp @@ -644,7 +644,7 @@ GetDocumentFromNPP(NPP npp) static JSContext * GetJSContextFromDoc(nsIDocument *doc) { - nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); + nsCOMPtr sgo = do_QueryInterface(doc->GetWindow()); NS_ENSURE_TRUE(sgo, nullptr); nsIScriptContext *scx = sgo->GetContext(); diff --git a/dom/plugins/base/nsNPAPIPluginInstance.cpp b/dom/plugins/base/nsNPAPIPluginInstance.cpp index 0c4cf05d2f3..abd2e143eb1 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.cpp +++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp @@ -1618,7 +1618,8 @@ nsNPAPIPluginInstance::GetJSContext(JSContext* *outContext) nsresult rv = mOwner->GetDocument(getter_AddRefs(document)); if (NS_SUCCEEDED(rv) && document) { - nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); + nsCOMPtr global = + do_QueryInterface(document->GetWindow()); if (global) { nsIScriptContext *context = global->GetContext(); diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index 7ec1a62721f..e5cc98d33a0 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -3518,12 +3518,8 @@ nsPrintEngine::TurnScriptingOn(bool aDoTurnOn) continue; } - // get the script global object - nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject(); - - if (scriptGlobalObj) { - nsCOMPtr window = do_QueryInterface(scriptGlobalObj); - NS_ASSERTION(window, "Can't get nsPIDOMWindow"); + if (nsCOMPtr window = doc->GetWindow()) { + nsCOMPtr scriptGlobalObj = do_QueryInterface(window); nsIScriptContext *scx = scriptGlobalObj->GetContext(); NS_WARN_IF_FALSE(scx, "Can't get nsIScriptContext"); nsresult propThere = NS_PROPTABLE_PROP_NOT_THERE; diff --git a/layout/xul/tree/nsTreeBodyFrame.cpp b/layout/xul/tree/nsTreeBodyFrame.cpp index ce4c3c7997f..34dd5400f54 100644 --- a/layout/xul/tree/nsTreeBodyFrame.cpp +++ b/layout/xul/tree/nsTreeBodyFrame.cpp @@ -2776,7 +2776,7 @@ nsTreeBodyFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, // Bail out now if there's no view or we can't run script because the // document is a zombie - if (!mView || !GetContent()->GetCurrentDoc()->GetScriptGlobalObject()) + if (!mView || !GetContent()->GetCurrentDoc()->GetWindow()) return; aLists.Content()->AppendNewToTop(new (aBuilder) diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index a9a4fa54d61..4a9a0e3e7e1 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -101,7 +101,7 @@ nsHtml5TreeOpExecutor::WillParse() NS_IMETHODIMP nsHtml5TreeOpExecutor::WillBuildModel(nsDTDMode aDTDMode) { - if (mDocShell && !GetDocument()->GetScriptGlobalObject() && + if (mDocShell && !GetDocument()->GetWindow() && !IsExternalViewSource()) { // Not loading as data but script global object not ready return MarkAsBroken(NS_ERROR_DOM_INVALID_STATE_ERR); @@ -682,13 +682,13 @@ nsHtml5TreeOpExecutor::IsScriptEnabled() { if (!mDocument || !mDocShell) return true; - nsCOMPtr globalObject = mDocument->GetScriptGlobalObject(); + nsCOMPtr globalObject = do_QueryInterface(mDocument->GetWindow()); // Getting context is tricky if the document hasn't had its // GlobalObject set yet if (!globalObject) { nsCOMPtr owner = do_GetInterface(mDocShell); NS_ENSURE_TRUE(owner, true); - globalObject = owner->GetScriptGlobalObject(); + globalObject = do_QueryInterface(mDocument->GetWindow()); NS_ENSURE_TRUE(globalObject, true); } nsIScriptContext *scriptContext = globalObject->GetContext(); diff --git a/widget/cocoa/nsMenuX.mm b/widget/cocoa/nsMenuX.mm index 791457e01e2..106b86e7b2a 100644 --- a/widget/cocoa/nsMenuX.mm +++ b/widget/cocoa/nsMenuX.mm @@ -412,8 +412,8 @@ void nsMenuX::MenuConstruct() do_GetService(nsIXPConnect::GetCID(), &rv); if (NS_SUCCEEDED(rv)) { nsIDocument* ownerDoc = menuPopup->OwnerDoc(); - nsIScriptGlobalObject* sgo; - if (ownerDoc && (sgo = ownerDoc->GetScriptGlobalObject())) { + nsCOMPtr sgo; + if (ownerDoc && (sgo = do_QueryInterface(ownerDoc->GetWindow()))) { nsCOMPtr scriptContext = sgo->GetContext(); JSObject* global = sgo->GetGlobalJSObject(); if (scriptContext && global) {