Bug 820170 - nsIGlobalObject. r=bholley

This commit is contained in:
Gabor Krizsanits 2013-04-04 11:27:06 +02:00
parent 670b243606
commit 23e12dce05
9 changed files with 64 additions and 14 deletions

View File

@ -167,6 +167,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsInProcessTabChildGlobal)
NS_INTERFACE_MAP_ENTRY(nsIInProcessContentFrameMessageManager)
NS_INTERFACE_MAP_ENTRY(nsIScriptContextPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ContentFrameMessageManager)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)

View File

@ -19,12 +19,13 @@
#include "nsIDOMElement.h"
#include "nsCOMArray.h"
#include "nsThreadUtils.h"
#include "nsIGlobalObject.h"
class nsInProcessTabChildGlobal : public nsDOMEventTargetHelper,
public nsFrameScriptExecutor,
public nsIInProcessContentFrameMessageManager,
public nsIScriptObjectPrincipal,
public nsIScriptContextPrincipal,
public nsIGlobalObject,
public mozilla::dom::ipc::MessageManagerCallback
{
public:
@ -113,6 +114,17 @@ public:
}
void DelayedDisconnect();
virtual JSObject* GetGlobalJSObject() {
if (!mGlobal) {
return nullptr;
}
JSObject* global;
mGlobal->GetJSObject(&global);
return global;
}
protected:
nsresult Init();
nsresult InitTabChildGlobal();

View File

@ -41,14 +41,16 @@ static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CI
// An XBLDocumentInfo object has a special context associated with it which we can use to pre-compile
// properties and methods of XBL bindings against.
class nsXBLDocGlobalObject : public nsIScriptGlobalObject,
public nsIScriptObjectPrincipal
class nsXBLDocGlobalObject : public nsIScriptGlobalObject
{
public:
nsXBLDocGlobalObject(nsXBLDocumentInfo *aGlobalObjectOwner);
// nsISupports interface
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
// nsIGlobalObject methods
virtual JSObject *GetGlobalJSObject();
// nsIScriptGlobalObject methods
virtual nsresult EnsureScriptEnvironment();
@ -58,7 +60,6 @@ public:
}
virtual nsIScriptContext *GetContext();
virtual JSObject *GetGlobalJSObject();
virtual void OnFinalize(JSObject* aObject);
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
@ -199,6 +200,7 @@ NS_IMPL_CYCLE_COLLECTION_1(nsXBLDocGlobalObject, mScriptContext)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXBLDocGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject)
NS_INTERFACE_MAP_END

View File

@ -40,8 +40,7 @@ static NS_DEFINE_CID(kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
class nsXULPDGlobalObject : public nsIScriptGlobalObject,
public nsIScriptObjectPrincipal
class nsXULPDGlobalObject : public nsIScriptGlobalObject
{
public:
nsXULPDGlobalObject(nsXULPrototypeDocument* owner);
@ -49,11 +48,13 @@ public:
// nsISupports interface
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
// nsIGlobalJSObjectHolder methods
virtual JSObject* GetGlobalJSObject();
// nsIScriptGlobalObject methods
virtual void OnFinalize(JSObject* aObject);
virtual void SetScriptsEnabled(bool aEnabled, bool aFireTimeouts);
virtual JSObject* GetGlobalJSObject();
virtual nsresult EnsureScriptEnvironment();
virtual nsIScriptContext *GetScriptContext();
@ -729,6 +730,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULPDGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject)
NS_INTERFACE_MAP_END

View File

@ -40,6 +40,7 @@ EXPORTS = \
nsDOMString.h \
nsIDOMClassInfo.h \
nsIDOMScriptObjectFactory.h \
nsIGlobalObject.h \
nsIJSEventListener.h \
nsIJSNativeInitializer.h \
nsIScriptContext.h \

View File

@ -1506,6 +1506,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindow)
"nsIDOMWindowInternalWarning");
}
} else
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)

View File

@ -260,7 +260,6 @@ class nsGlobalWindow : public mozilla::dom::EventTarget,
public nsPIDOMWindow,
public nsIScriptGlobalObject,
public nsIDOMJSWindow,
public nsIScriptObjectPrincipal,
public nsIDOMStorageIndexedDB,
public nsSupportsWeakReference,
public nsIInterfaceRequestor,
@ -297,9 +296,11 @@ public:
return EnsureInnerWindow() ? GetWrapper() : nullptr;
}
// nsIGlobalJSObjectHolder
virtual JSObject *GetGlobalJSObject();
// nsIScriptGlobalObject
virtual nsIScriptContext *GetContext();
virtual JSObject *GetGlobalJSObject();
JSObject *FastGetGlobalJSObject()
{
return mJSObject;

View File

@ -0,0 +1,29 @@
/* -*- 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 nsIGlobalObject_h__
#define nsIGlobalObject_h__
#include "nsISupports.h"
#include "nsIScriptObjectPrincipal.h"
class JSObject;
#define NS_IGLOBALOBJECT_IID \
{ 0x8503e9a9, 0x530, 0x4b26, \
{ 0xae, 0x24, 0x18, 0xca, 0x38, 0xe5, 0xed, 0x17 } }
class nsIGlobalObject : public nsIScriptObjectPrincipal
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IGLOBALOBJECT_IID)
virtual JSObject* GetGlobalJSObject() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsIGlobalObject,
NS_IGLOBALOBJECT_IID)
#endif // nsIGlobalObject_h__

View File

@ -10,6 +10,7 @@
#include "nsISupports.h"
#include "nsEvent.h"
#include "nsIProgrammingLanguage.h"
#include "nsIGlobalObject.h"
class nsIScriptContext;
class nsIDOMEvent;
@ -60,15 +61,17 @@ NS_HandleScriptError(nsIScriptGlobalObject *aScriptGlobal,
#define NS_ISCRIPTGLOBALOBJECT_IID \
{ 0x92569431, 0x6e6e, 0x408a, \
{ 0xa8, 0x8c, 0x45, 0x28, 0x5c, 0x1c, 0x85, 0x73 } }
{ 0xde24b30a, 0x12c6, 0x4e5f, \
{ 0xa8, 0x5e, 0x90, 0xcd, 0xfb, 0x6c, 0x54, 0x51 } }
/**
* The global object which keeps a script context for each supported script
* language. This often used to store per-window global state.
* This is a heavyweight interface implemented only by DOM globals, and
* it might go away some time in the future.
*/
class nsIScriptGlobalObject : public nsISupports
class nsIScriptGlobalObject : public nsIGlobalObject
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
@ -87,8 +90,6 @@ public:
* Get a script context (WITHOUT added reference) for the specified language.
*/
virtual nsIScriptContext *GetScriptContext() = 0;
virtual JSObject* GetGlobalJSObject() = 0;
nsIScriptContext* GetContext() {
return GetScriptContext();