|
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/. */ |
|
6 |
|
7 #ifndef nsInProcessTabChildGlobal_h |
|
8 #define nsInProcessTabChildGlobal_h |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "mozilla/DOMEventTargetHelper.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsFrameMessageManager.h" |
|
14 #include "nsIScriptContext.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" |
|
25 |
|
26 namespace mozilla { |
|
27 class EventChainPreVisitor; |
|
28 } // namespace mozilla |
|
29 |
|
30 class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper, |
|
31 public nsFrameScriptExecutor, |
|
32 public nsIInProcessContentFrameMessageManager, |
|
33 public nsIGlobalObject, |
|
34 public nsIScriptObjectPrincipal, |
|
35 public nsSupportsWeakReference, |
|
36 public mozilla::dom::ipc::MessageManagerCallback |
|
37 { |
|
38 public: |
|
39 nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner, |
|
40 nsFrameMessageManager* aChrome); |
|
41 virtual ~nsInProcessTabChildGlobal(); |
|
42 NS_DECL_ISUPPORTS_INHERITED |
|
43 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsInProcessTabChildGlobal, |
|
44 mozilla::DOMEventTargetHelper) |
|
45 NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager) |
|
46 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) |
|
47 NS_IMETHOD SendSyncMessage(const nsAString& aMessageName, |
|
48 JS::Handle<JS::Value> aObject, |
|
49 JS::Handle<JS::Value> aRemote, |
|
50 nsIPrincipal* aPrincipal, |
|
51 JSContext* aCx, |
|
52 uint8_t aArgc, |
|
53 JS::MutableHandle<JS::Value> aRetval) |
|
54 { |
|
55 return mMessageManager |
|
56 ? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote, |
|
57 aPrincipal, aCx, aArgc, aRetval) |
|
58 : NS_ERROR_NULL_POINTER; |
|
59 } |
|
60 NS_IMETHOD SendRpcMessage(const nsAString& aMessageName, |
|
61 JS::Handle<JS::Value> aObject, |
|
62 JS::Handle<JS::Value> aRemote, |
|
63 nsIPrincipal* aPrincipal, |
|
64 JSContext* aCx, |
|
65 uint8_t aArgc, |
|
66 JS::MutableHandle<JS::Value> aRetval) |
|
67 { |
|
68 return mMessageManager |
|
69 ? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote, |
|
70 aPrincipal, aCx, aArgc, aRetval) |
|
71 : NS_ERROR_NULL_POINTER; |
|
72 } |
|
73 NS_IMETHOD GetContent(nsIDOMWindow** aContent) MOZ_OVERRIDE; |
|
74 NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) MOZ_OVERRIDE; |
|
75 NS_IMETHOD Dump(const nsAString& aStr) MOZ_OVERRIDE |
|
76 { |
|
77 return mMessageManager ? mMessageManager->Dump(aStr) : NS_OK; |
|
78 } |
|
79 NS_IMETHOD PrivateNoteIntentionalCrash() MOZ_OVERRIDE; |
|
80 NS_IMETHOD Btoa(const nsAString& aBinaryData, |
|
81 nsAString& aAsciiBase64String) MOZ_OVERRIDE; |
|
82 NS_IMETHOD Atob(const nsAString& aAsciiString, |
|
83 nsAString& aBinaryData) MOZ_OVERRIDE; |
|
84 |
|
85 NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER |
|
86 |
|
87 /** |
|
88 * MessageManagerCallback methods that we override. |
|
89 */ |
|
90 virtual bool DoSendBlockingMessage(JSContext* aCx, |
|
91 const nsAString& aMessage, |
|
92 const mozilla::dom::StructuredCloneData& aData, |
|
93 JS::Handle<JSObject *> aCpows, |
|
94 nsIPrincipal* aPrincipal, |
|
95 InfallibleTArray<nsString>* aJSONRetVal, |
|
96 bool aIsSync) MOZ_OVERRIDE; |
|
97 virtual bool DoSendAsyncMessage(JSContext* aCx, |
|
98 const nsAString& aMessage, |
|
99 const mozilla::dom::StructuredCloneData& aData, |
|
100 JS::Handle<JSObject *> aCpows, |
|
101 nsIPrincipal* aPrincipal) MOZ_OVERRIDE; |
|
102 |
|
103 virtual nsresult PreHandleEvent( |
|
104 mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; |
|
105 NS_IMETHOD AddEventListener(const nsAString& aType, |
|
106 nsIDOMEventListener* aListener, |
|
107 bool aUseCapture) |
|
108 { |
|
109 // By default add listeners only for trusted events! |
|
110 return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener, |
|
111 aUseCapture, false, |
|
112 2); |
|
113 } |
|
114 NS_IMETHOD AddEventListener(const nsAString& aType, |
|
115 nsIDOMEventListener* aListener, |
|
116 bool aUseCapture, bool aWantsUntrusted, |
|
117 uint8_t optional_argc) MOZ_OVERRIDE |
|
118 { |
|
119 return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener, |
|
120 aUseCapture, |
|
121 aWantsUntrusted, |
|
122 optional_argc); |
|
123 } |
|
124 using mozilla::DOMEventTargetHelper::AddEventListener; |
|
125 |
|
126 virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return nsContentUtils::GetSafeJSContext(); } |
|
127 virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; } |
|
128 void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope); |
|
129 void Disconnect(); |
|
130 void SendMessageToParent(const nsString& aMessage, bool aSync, |
|
131 const nsString& aJSON, |
|
132 nsTArray<nsString>* aJSONRetVal); |
|
133 nsFrameMessageManager* GetInnerManager() |
|
134 { |
|
135 return static_cast<nsFrameMessageManager*>(mMessageManager.get()); |
|
136 } |
|
137 |
|
138 void SetOwner(nsIContent* aOwner) { mOwner = aOwner; } |
|
139 nsFrameMessageManager* GetChromeMessageManager() |
|
140 { |
|
141 return mChromeMessageManager; |
|
142 } |
|
143 void SetChromeMessageManager(nsFrameMessageManager* aParent) |
|
144 { |
|
145 mChromeMessageManager = aParent; |
|
146 } |
|
147 |
|
148 void DelayedDisconnect(); |
|
149 |
|
150 virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE { |
|
151 if (!mGlobal) { |
|
152 return nullptr; |
|
153 } |
|
154 |
|
155 return mGlobal->GetJSObject(); |
|
156 } |
|
157 protected: |
|
158 nsresult Init(); |
|
159 nsresult InitTabChildGlobal(); |
|
160 nsCOMPtr<nsIContentFrameMessageManager> mMessageManager; |
|
161 nsCOMPtr<nsIDocShell> mDocShell; |
|
162 bool mInitialized; |
|
163 bool mLoadingScript; |
|
164 |
|
165 // Is this the message manager for an in-process <iframe mozbrowser> or |
|
166 // <iframe mozapp>? This affects where events get sent, so it affects |
|
167 // PreHandleEvent. |
|
168 bool mIsBrowserOrAppFrame; |
|
169 public: |
|
170 nsIContent* mOwner; |
|
171 nsFrameMessageManager* mChromeMessageManager; |
|
172 nsTArray<nsCOMPtr<nsIRunnable> > mASyncMessages; |
|
173 }; |
|
174 |
|
175 #endif |