1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
2 /* vim: set sw=4 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsInProcessTabChildGlobal_h
8 #define nsInProcessTabChildGlobal_h
10 #include "mozilla/Attributes.h"
12 #include "nsFrameMessageManager.h"
13 #include "nsIScriptContext.h"
14 #include "nsDOMEventTargetHelper.h"
15 #include "nsIScriptObjectPrincipal.h"
16 #include "nsIScriptContext.h"
17 #include "nsIClassInfo.h"
18 #include "nsIDocShell.h"
19 #include "nsIDOMElement.h"
20 #include "nsCOMArray.h"
21 #include "nsIRunnable.h"
22 #include "nsIGlobalObject.h"
23 #include "nsIScriptObjectPrincipal.h"
24 #include "nsWeakReference.h"
26 class nsInProcessTabChildGlobal
: public nsDOMEventTargetHelper
,
27 public nsFrameScriptExecutor
,
28 public nsIInProcessContentFrameMessageManager
,
29 public nsIGlobalObject
,
30 public nsIScriptObjectPrincipal
,
31 public nsSupportsWeakReference
,
32 public mozilla::dom::ipc::MessageManagerCallback
35 nsInProcessTabChildGlobal(nsIDocShell
* aShell
, nsIContent
* aOwner
,
36 nsFrameMessageManager
* aChrome
);
37 virtual ~nsInProcessTabChildGlobal();
38 NS_DECL_ISUPPORTS_INHERITED
39 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal
,
40 nsDOMEventTargetHelper
)
41 NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager
)
42 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager
)
43 NS_IMETHOD
SendSyncMessage(const nsAString
& aMessageName
,
44 const JS::Value
& aObject
,
45 const JS::Value
& aRemote
,
46 nsIPrincipal
* aPrincipal
,
51 return mMessageManager
52 ? mMessageManager
->SendSyncMessage(aMessageName
, aObject
, aRemote
,
53 aPrincipal
, aCx
, aArgc
, aRetval
)
54 : NS_ERROR_NULL_POINTER
;
56 NS_IMETHOD
SendRpcMessage(const nsAString
& aMessageName
,
57 const JS::Value
& aObject
,
58 const JS::Value
& aRemote
,
59 nsIPrincipal
* aPrincipal
,
64 return mMessageManager
65 ? mMessageManager
->SendRpcMessage(aMessageName
, aObject
, aRemote
,
66 aPrincipal
, aCx
, aArgc
, aRetval
)
67 : NS_ERROR_NULL_POINTER
;
69 NS_IMETHOD
GetContent(nsIDOMWindow
** aContent
) MOZ_OVERRIDE
;
70 NS_IMETHOD
GetDocShell(nsIDocShell
** aDocShell
) MOZ_OVERRIDE
;
71 NS_IMETHOD
Dump(const nsAString
& aStr
) MOZ_OVERRIDE
73 return mMessageManager
? mMessageManager
->Dump(aStr
) : NS_OK
;
75 NS_IMETHOD
PrivateNoteIntentionalCrash() MOZ_OVERRIDE
;
76 NS_IMETHOD
Btoa(const nsAString
& aBinaryData
,
77 nsAString
& aAsciiBase64String
) MOZ_OVERRIDE
;
78 NS_IMETHOD
Atob(const nsAString
& aAsciiString
,
79 nsAString
& aBinaryData
) MOZ_OVERRIDE
;
81 NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
84 * MessageManagerCallback methods that we override.
86 virtual bool DoSendBlockingMessage(JSContext
* aCx
,
87 const nsAString
& aMessage
,
88 const mozilla::dom::StructuredCloneData
& aData
,
89 JS::Handle
<JSObject
*> aCpows
,
90 nsIPrincipal
* aPrincipal
,
91 InfallibleTArray
<nsString
>* aJSONRetVal
,
92 bool aIsSync
) MOZ_OVERRIDE
;
93 virtual bool DoSendAsyncMessage(JSContext
* aCx
,
94 const nsAString
& aMessage
,
95 const mozilla::dom::StructuredCloneData
& aData
,
96 JS::Handle
<JSObject
*> aCpows
,
97 nsIPrincipal
* aPrincipal
) MOZ_OVERRIDE
;
99 virtual nsresult
PreHandleEvent(nsEventChainPreVisitor
& aVisitor
) MOZ_OVERRIDE
;
100 NS_IMETHOD
AddEventListener(const nsAString
& aType
,
101 nsIDOMEventListener
* aListener
,
104 // By default add listeners only for trusted events!
105 return nsDOMEventTargetHelper::AddEventListener(aType
, aListener
,
106 aUseCapture
, false, 2);
108 NS_IMETHOD
AddEventListener(const nsAString
& aType
,
109 nsIDOMEventListener
* aListener
,
110 bool aUseCapture
, bool aWantsUntrusted
,
111 uint8_t optional_argc
) MOZ_OVERRIDE
113 return nsDOMEventTargetHelper::AddEventListener(aType
, aListener
,
118 using nsDOMEventTargetHelper::AddEventListener
;
120 virtual JSContext
* GetJSContextForEventHandlers() MOZ_OVERRIDE
{ return nsContentUtils::GetSafeJSContext(); }
121 virtual nsIPrincipal
* GetPrincipal() MOZ_OVERRIDE
{ return mPrincipal
; }
122 void LoadFrameScript(const nsAString
& aURL
);
124 void SendMessageToParent(const nsString
& aMessage
, bool aSync
,
125 const nsString
& aJSON
,
126 nsTArray
<nsString
>* aJSONRetVal
);
127 nsFrameMessageManager
* GetInnerManager()
129 return static_cast<nsFrameMessageManager
*>(mMessageManager
.get());
132 void SetOwner(nsIContent
* aOwner
) { mOwner
= aOwner
; }
133 nsFrameMessageManager
* GetChromeMessageManager()
135 return mChromeMessageManager
;
137 void SetChromeMessageManager(nsFrameMessageManager
* aParent
)
139 mChromeMessageManager
= aParent
;
142 void DelayedDisconnect();
144 virtual JSObject
* GetGlobalJSObject() MOZ_OVERRIDE
{
149 return mGlobal
->GetJSObject();
153 nsresult
InitTabChildGlobal();
154 nsCOMPtr
<nsIContentFrameMessageManager
> mMessageManager
;
155 nsCOMPtr
<nsIDocShell
> mDocShell
;
158 bool mDelayedDisconnect
;
160 // Is this the message manager for an in-process <iframe mozbrowser> or
161 // <iframe mozapp>? This affects where events get sent, so it affects
163 bool mIsBrowserOrAppFrame
;
166 nsFrameMessageManager
* mChromeMessageManager
;
167 nsTArray
<nsCOMPtr
<nsIRunnable
> > mASyncMessages
;