From 012fdba09b91cf09f13e117673efbc5b0e2d72f0 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Mon, 27 May 2013 06:07:01 -0400 Subject: [PATCH] bug 935325 - merge nsIScriptGlobalObjectOwner into nsIDocShell r=smaug --- .../html/document/src/nsHTMLContentSink.cpp | 6 +--- content/xml/document/src/XMLDocument.cpp | 1 - docshell/base/nsDocShell.cpp | 19 ++++------ docshell/base/nsDocShell.h | 5 --- docshell/base/nsIDocShell.idl | 8 ++++- dom/base/moz.build | 1 - dom/base/nsIScriptGlobalObjectOwner.h | 36 ------------------- dom/src/jsurl/nsJSProtocolHandler.cpp | 18 ++++------ parser/html/nsHtml5TreeOpExecutor.cpp | 5 +-- 9 files changed, 23 insertions(+), 76 deletions(-) delete mode 100644 dom/base/nsIScriptGlobalObjectOwner.h diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 855a4cd32a2..10f90a4b0ab 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -60,7 +60,6 @@ #include "nsIPrincipal.h" #include "nsTextFragment.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectOwner.h" #include "nsIParserService.h" @@ -712,10 +711,7 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer) // Getting context is tricky if the document hasn't had its // GlobalObject set yet if (!globalObject) { - nsCOMPtr owner = do_GetInterface(aContainer); - NS_ENSURE_TRUE(owner, true); - - globalObject = owner->GetScriptGlobalObject(); + globalObject = aContainer->GetScriptGlobalObject(); NS_ENSURE_TRUE(globalObject, true); } diff --git a/content/xml/document/src/XMLDocument.cpp b/content/xml/document/src/XMLDocument.cpp index ff562012c00..e57af605676 100644 --- a/content/xml/document/src/XMLDocument.cpp +++ b/content/xml/document/src/XMLDocument.cpp @@ -40,7 +40,6 @@ #include "nsJSUtils.h" #include "nsCRT.h" #include "nsIAuthPrompt.h" -#include "nsIScriptGlobalObjectOwner.h" #include "nsContentCreatorFunctions.h" #include "nsContentPolicyUtils.h" #include "nsIDOMUserDataHandler.h" diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index b7f782de70a..d3b32459c21 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -897,7 +897,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY(nsIScrollable) NS_INTERFACE_MAP_ENTRY(nsITextScroll) NS_INTERFACE_MAP_ENTRY(nsIDocCharset) - NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) NS_INTERFACE_MAP_ENTRY(nsIRefreshURI) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) @@ -3920,6 +3919,13 @@ nsDocShell::GetCurrentSHEntry(nsISHEntry** aEntry, bool* aOSHE) return NS_OK; } +nsIScriptGlobalObject* +nsDocShell::GetScriptGlobalObject() +{ + NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), nullptr); + return mScriptGlobal; +} + void nsDocShell::ClearFrameHistory(nsISHEntry* aEntry) { @@ -5818,17 +5824,6 @@ nsDocShell::ScrollByPages(int32_t numPages) return NS_OK; } -//***************************************************************************** -// nsDocShell::nsIScriptGlobalObjectOwner -//***************************************************************************** - -nsIScriptGlobalObject* -nsDocShell::GetScriptGlobalObject() -{ - NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), nullptr); - return mScriptGlobal; -} - //***************************************************************************** // nsDocShell::nsIRefreshURI //***************************************************************************** diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 56e292cce7d..a474b606093 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -33,7 +33,6 @@ #include "nsIDocCharset.h" #include "nsIInterfaceRequestor.h" #include "nsIRefreshURI.h" -#include "nsIScriptGlobalObjectOwner.h" #include "nsIWebNavigation.h" #include "nsIWebPageDescriptor.h" #include "nsIWebProgressListener.h" @@ -130,7 +129,6 @@ class nsDocShell : public nsDocLoader, public nsITextScroll, public nsIDocCharset, public nsIContentViewerContainer, - public nsIScriptGlobalObjectOwner, public nsIRefreshURI, public nsIWebProgressListener, public nsIWebPageDescriptor, @@ -205,9 +203,6 @@ public: nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType); uint32_t ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType); - // nsIScriptGlobalObjectOwner methods - virtual nsIScriptGlobalObject* GetScriptGlobalObject(); - // Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods // are shared with nsIDocShell (appID, etc.) and can't be declared twice. NS_IMETHOD GetAssociatedWindow(nsIDOMWindow**); diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 919f9174433..5782c4f4c63 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -34,6 +34,7 @@ interface nsIRequest; interface nsISHEntry; interface nsILayoutHistoryState; interface nsISecureBrowserUI; +interface nsIScriptGlobalObject; interface nsIDOMStorage; interface nsIPrincipal; interface nsIWebBrowserPrint; @@ -43,7 +44,7 @@ interface nsIReflowObserver; typedef unsigned long nsLoadFlags; -[scriptable, builtinclass, uuid(1470A132-99B2-44C3-B37D-D8093B2E29BF)] +[scriptable, builtinclass, uuid(5c9adf31-8e4a-4d8d-8daf-9999e6002697)] interface nsIDocShell : nsIDocShellTreeItem { /** @@ -907,4 +908,9 @@ interface nsIDocShell : nsIDocShellTreeItem */ [noscript, notxpcom] bool IsInvisible(); [noscript, notxpcom] void SetInvisible(in bool aIsInvisibleDochsell); + +/** + * Get the script global for the document in this docshell. +*/ + [noscript,notxpcom,nostdcall] nsIScriptGlobalObject GetScriptGlobalObject(); }; diff --git a/dom/base/moz.build b/dom/base/moz.build index 7855232543e..adca8e0ec43 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -34,7 +34,6 @@ EXPORTS += [ 'nsIScriptContext.h', 'nsIScriptExternalNameSet.h', 'nsIScriptGlobalObject.h', - 'nsIScriptGlobalObjectOwner.h', 'nsIScriptNameSpaceManager.h', 'nsIScriptObjectPrincipal.h', 'nsIScriptTimeoutHandler.h', diff --git a/dom/base/nsIScriptGlobalObjectOwner.h b/dom/base/nsIScriptGlobalObjectOwner.h deleted file mode 100644 index f1ee9b1eff3..00000000000 --- a/dom/base/nsIScriptGlobalObjectOwner.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef nsIScriptGlobalObjectOwner_h__ -#define nsIScriptGlobalObjectOwner_h__ - -#include "nsISupports.h" - -class nsIScriptGlobalObject; - -#define NS_ISCRIPTGLOBALOBJECTOWNER_IID \ - {0xfd25ca8e, 0x6b63, 0x435f, \ - { 0xb8, 0xc6, 0xb8, 0x07, 0x68, 0xa4, 0x0a, 0xdc }} - -/** - * Implemented by any object capable of supplying a nsIScriptGlobalObject. - * The implentor may create the script global object on demand. - */ - -class nsIScriptGlobalObjectOwner : public nsISupports -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECTOWNER_IID) - - /** - * Returns the script global object - */ - virtual nsIScriptGlobalObject* GetScriptGlobalObject() = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIScriptGlobalObjectOwner, - NS_ISCRIPTGLOBALOBJECTOWNER_IID) - -#endif /* nsIScriptGlobalObjectOwner_h__ */ diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index 4592d7338f0..453b37511b5 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -21,7 +21,6 @@ #include "nsIURI.h" #include "nsIScriptContext.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectOwner.h" #include "nsIPrincipal.h" #include "nsIScriptSecurityManager.h" #include "nsIInterfaceRequestor.h" @@ -119,22 +118,19 @@ static nsIScriptGlobalObject* GetGlobalObject(nsIChannel* aChannel) { // Get the global object owner from the channel - nsCOMPtr globalOwner; - NS_QueryNotificationCallbacks(aChannel, globalOwner); - if (!globalOwner) { - NS_WARNING("Unable to get an nsIScriptGlobalObjectOwner from the " - "channel!"); - } - if (!globalOwner) { + nsCOMPtr docShell; + NS_QueryNotificationCallbacks(aChannel, docShell); + if (!docShell) { + NS_WARNING("Unable to get a docShell from the channel!"); return nullptr; } - // So far so good: get the script context from its owner. - nsIScriptGlobalObject* global = globalOwner->GetScriptGlobalObject(); + // So far so good: get the script global from its docshell + nsIScriptGlobalObject* global = docShell->GetScriptGlobalObject(); NS_ASSERTION(global, "Unable to get an nsIScriptGlobalObject from the " - "ScriptGlobalObjectOwner!"); + "docShell!"); return global; } diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 79bb706889d..e824b7de133 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -17,7 +17,6 @@ #include "nsStyleLinkElement.h" #include "nsIDocShell.h" #include "nsIScriptGlobalObject.h" -#include "nsIScriptGlobalObjectOwner.h" #include "nsIScriptSecurityManager.h" #include "nsIWebShellServices.h" #include "nsContentUtils.h" @@ -653,9 +652,7 @@ nsHtml5TreeOpExecutor::IsScriptEnabled() // 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 = do_QueryInterface(mDocument->GetWindow()); + globalObject = mDocShell->GetScriptGlobalObject(); NS_ENSURE_TRUE(globalObject, true); } nsIScriptContext *scriptContext = globalObject->GetContext();