/src/mozilla-central/dom/ipc/ContentBridgeParent.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 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 file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "mozilla/dom/ContentBridgeParent.h" |
8 | | #include "mozilla/dom/ProcessMessageManager.h" |
9 | | #include "mozilla/dom/TabParent.h" |
10 | | #include "mozilla/jsipc/CrossProcessObjectWrappers.h" |
11 | | #include "nsXULAppAPI.h" |
12 | | #include "nsIObserverService.h" |
13 | | #include "base/task.h" |
14 | | |
15 | | using namespace mozilla::ipc; |
16 | | using namespace mozilla::jsipc; |
17 | | |
18 | | namespace mozilla { |
19 | | namespace dom { |
20 | | |
21 | | NS_IMPL_ISUPPORTS(ContentBridgeParent, |
22 | | nsIContentParent, |
23 | | nsIObserver) |
24 | | |
25 | | ContentBridgeParent::ContentBridgeParent() |
26 | | : mIsForBrowser(false) |
27 | | , mIsForJSPlugin(false) |
28 | 0 | {} |
29 | | |
30 | | ContentBridgeParent::~ContentBridgeParent() |
31 | 0 | { |
32 | 0 | } |
33 | | |
34 | | void |
35 | | ContentBridgeParent::ActorDestroy(ActorDestroyReason aWhy) |
36 | 0 | { |
37 | 0 | nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); |
38 | 0 | if (os) { |
39 | 0 | os->RemoveObserver(this, "content-child-shutdown"); |
40 | 0 | } |
41 | 0 | MessageLoop::current()->PostTask( |
42 | 0 | NewRunnableMethod("dom::ContentBridgeParent::DeferredDestroy", |
43 | 0 | this, |
44 | 0 | &ContentBridgeParent::DeferredDestroy)); |
45 | 0 | } |
46 | | |
47 | | /*static*/ ContentBridgeParent* |
48 | | ContentBridgeParent::Create(Endpoint<PContentBridgeParent>&& aEndpoint) |
49 | 0 | { |
50 | 0 | RefPtr<ContentBridgeParent> bridge = new ContentBridgeParent(); |
51 | 0 | bridge->mSelfRef = bridge; |
52 | 0 |
|
53 | 0 | DebugOnly<bool> ok = aEndpoint.Bind(bridge); |
54 | 0 | MOZ_ASSERT(ok); |
55 | 0 |
|
56 | 0 | nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); |
57 | 0 | if (os) { |
58 | 0 | os->AddObserver(bridge, "content-child-shutdown", false); |
59 | 0 | } |
60 | 0 |
|
61 | 0 | // Initialize the message manager (and load delayed scripts) now that we |
62 | 0 | // have established communications with the child. |
63 | 0 | bridge->mMessageManager->InitWithCallback(bridge); |
64 | 0 |
|
65 | 0 | return bridge.get(); |
66 | 0 | } |
67 | | |
68 | | void |
69 | | ContentBridgeParent::DeferredDestroy() |
70 | 0 | { |
71 | 0 | mSelfRef = nullptr; |
72 | 0 | // |this| was just destroyed, hands off |
73 | 0 | } |
74 | | |
75 | | mozilla::ipc::IPCResult |
76 | | ContentBridgeParent::RecvSyncMessage(const nsString& aMsg, |
77 | | const ClonedMessageData& aData, |
78 | | InfallibleTArray<jsipc::CpowEntry>&& aCpows, |
79 | | const IPC::Principal& aPrincipal, |
80 | | nsTArray<StructuredCloneData>* aRetvals) |
81 | 0 | { |
82 | 0 | return nsIContentParent::RecvSyncMessage(aMsg, aData, std::move(aCpows), |
83 | 0 | aPrincipal, aRetvals); |
84 | 0 | } |
85 | | |
86 | | mozilla::ipc::IPCResult |
87 | | ContentBridgeParent::RecvAsyncMessage(const nsString& aMsg, |
88 | | InfallibleTArray<jsipc::CpowEntry>&& aCpows, |
89 | | const IPC::Principal& aPrincipal, |
90 | | const ClonedMessageData& aData) |
91 | 0 | { |
92 | 0 | return nsIContentParent::RecvAsyncMessage(aMsg, std::move(aCpows), |
93 | 0 | aPrincipal, aData); |
94 | 0 | } |
95 | | |
96 | | PBrowserParent* |
97 | | ContentBridgeParent::SendPBrowserConstructor(PBrowserParent* aActor, |
98 | | const TabId& aTabId, |
99 | | const TabId& aSameTabGroupAs, |
100 | | const IPCTabContext& aContext, |
101 | | const uint32_t& aChromeFlags, |
102 | | const ContentParentId& aCpID, |
103 | | const bool& aIsForBrowser) |
104 | 0 | { |
105 | 0 | return PContentBridgeParent::SendPBrowserConstructor(aActor, |
106 | 0 | aTabId, |
107 | 0 | aSameTabGroupAs, |
108 | 0 | aContext, |
109 | 0 | aChromeFlags, |
110 | 0 | aCpID, |
111 | 0 | aIsForBrowser); |
112 | 0 | } |
113 | | |
114 | | PParentToChildStreamParent* |
115 | | ContentBridgeParent::SendPParentToChildStreamConstructor(PParentToChildStreamParent* aActor) |
116 | 0 | { |
117 | 0 | return PContentBridgeParent::SendPParentToChildStreamConstructor(aActor); |
118 | 0 | } |
119 | | |
120 | | PIPCBlobInputStreamParent* |
121 | | ContentBridgeParent::SendPIPCBlobInputStreamConstructor(PIPCBlobInputStreamParent* aActor, |
122 | | const nsID& aID, |
123 | | const uint64_t& aSize) |
124 | 0 | { |
125 | 0 | return |
126 | 0 | PContentBridgeParent::SendPIPCBlobInputStreamConstructor(aActor, aID, aSize); |
127 | 0 | } |
128 | | |
129 | | PIPCBlobInputStreamParent* |
130 | | ContentBridgeParent::AllocPIPCBlobInputStreamParent(const nsID& aID, |
131 | | const uint64_t& aSize) |
132 | 0 | { |
133 | 0 | return nsIContentParent::AllocPIPCBlobInputStreamParent(aID, aSize); |
134 | 0 | } |
135 | | |
136 | | bool |
137 | | ContentBridgeParent::DeallocPIPCBlobInputStreamParent(PIPCBlobInputStreamParent* aActor) |
138 | 0 | { |
139 | 0 | return nsIContentParent::DeallocPIPCBlobInputStreamParent(aActor); |
140 | 0 | } |
141 | | |
142 | | mozilla::jsipc::PJavaScriptParent * |
143 | | ContentBridgeParent::AllocPJavaScriptParent() |
144 | 0 | { |
145 | 0 | return nsIContentParent::AllocPJavaScriptParent(); |
146 | 0 | } |
147 | | |
148 | | bool |
149 | | ContentBridgeParent::DeallocPJavaScriptParent(PJavaScriptParent *parent) |
150 | 0 | { |
151 | 0 | return nsIContentParent::DeallocPJavaScriptParent(parent); |
152 | 0 | } |
153 | | |
154 | | PBrowserParent* |
155 | | ContentBridgeParent::AllocPBrowserParent(const TabId& aTabId, |
156 | | const TabId& aSameTabGroupAs, |
157 | | const IPCTabContext &aContext, |
158 | | const uint32_t& aChromeFlags, |
159 | | const ContentParentId& aCpID, |
160 | | const bool& aIsForBrowser) |
161 | 0 | { |
162 | 0 | return nsIContentParent::AllocPBrowserParent(aTabId, |
163 | 0 | aSameTabGroupAs, |
164 | 0 | aContext, |
165 | 0 | aChromeFlags, |
166 | 0 | aCpID, |
167 | 0 | aIsForBrowser); |
168 | 0 | } |
169 | | |
170 | | bool |
171 | | ContentBridgeParent::DeallocPBrowserParent(PBrowserParent* aParent) |
172 | 0 | { |
173 | 0 | return nsIContentParent::DeallocPBrowserParent(aParent); |
174 | 0 | } |
175 | | |
176 | | mozilla::ipc::IPCResult |
177 | | ContentBridgeParent::RecvPBrowserConstructor(PBrowserParent* actor, |
178 | | const TabId& tabId, |
179 | | const TabId& sameTabGroupAs, |
180 | | const IPCTabContext& context, |
181 | | const uint32_t& chromeFlags, |
182 | | const ContentParentId& cpId, |
183 | | const bool& isForBrowser) |
184 | 0 | { |
185 | 0 | return nsIContentParent::RecvPBrowserConstructor(actor, |
186 | 0 | tabId, |
187 | 0 | sameTabGroupAs, |
188 | 0 | context, |
189 | 0 | chromeFlags, |
190 | 0 | cpId, |
191 | 0 | isForBrowser); |
192 | 0 | } |
193 | | |
194 | | void |
195 | | ContentBridgeParent::NotifyTabDestroyed() |
196 | 0 | { |
197 | 0 | int32_t numLiveTabs = ManagedPBrowserParent().Count(); |
198 | 0 | if (numLiveTabs == 1) { |
199 | 0 | MessageLoop::current()->PostTask(NewRunnableMethod( |
200 | 0 | "dom::ContentBridgeParent::Close", this, &ContentBridgeParent::Close)); |
201 | 0 | } |
202 | 0 | } |
203 | | |
204 | | // This implementation is identical to ContentParent::GetCPOWManager but we can't |
205 | | // move it to nsIContentParent because it calls ManagedPJavaScriptParent() which |
206 | | // only exists in PContentParent and PContentBridgeParent. |
207 | | jsipc::CPOWManager* |
208 | | ContentBridgeParent::GetCPOWManager() |
209 | 0 | { |
210 | 0 | if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) { |
211 | 0 | return CPOWManagerFor(p); |
212 | 0 | } |
213 | 0 | return nullptr; |
214 | 0 | } |
215 | | |
216 | | NS_IMETHODIMP |
217 | | ContentBridgeParent::Observe(nsISupports* aSubject, |
218 | | const char* aTopic, |
219 | | const char16_t* aData) |
220 | 0 | { |
221 | 0 | if (!strcmp(aTopic, "content-child-shutdown")) { |
222 | 0 | Close(); |
223 | 0 | } |
224 | 0 | return NS_OK; |
225 | 0 | } |
226 | | |
227 | | PFileDescriptorSetParent* |
228 | | ContentBridgeParent::SendPFileDescriptorSetConstructor(const FileDescriptor& aFD) |
229 | 0 | { |
230 | 0 | return PContentBridgeParent::SendPFileDescriptorSetConstructor(aFD); |
231 | 0 | } |
232 | | |
233 | | PFileDescriptorSetParent* |
234 | | ContentBridgeParent::AllocPFileDescriptorSetParent(const FileDescriptor& aFD) |
235 | 0 | { |
236 | 0 | return nsIContentParent::AllocPFileDescriptorSetParent(aFD); |
237 | 0 | } |
238 | | |
239 | | bool |
240 | | ContentBridgeParent::DeallocPFileDescriptorSetParent(PFileDescriptorSetParent* aActor) |
241 | 0 | { |
242 | 0 | return nsIContentParent::DeallocPFileDescriptorSetParent(aActor); |
243 | 0 | } |
244 | | |
245 | | PChildToParentStreamParent* |
246 | | ContentBridgeParent::AllocPChildToParentStreamParent() |
247 | 0 | { |
248 | 0 | return nsIContentParent::AllocPChildToParentStreamParent(); |
249 | 0 | } |
250 | | |
251 | | bool |
252 | | ContentBridgeParent::DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor) |
253 | 0 | { |
254 | 0 | return nsIContentParent::DeallocPChildToParentStreamParent(aActor); |
255 | 0 | } |
256 | | |
257 | | PParentToChildStreamParent* |
258 | | ContentBridgeParent::AllocPParentToChildStreamParent() |
259 | 0 | { |
260 | 0 | return nsIContentParent::AllocPParentToChildStreamParent(); |
261 | 0 | } |
262 | | |
263 | | bool |
264 | | ContentBridgeParent::DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor) |
265 | 0 | { |
266 | 0 | return nsIContentParent::DeallocPParentToChildStreamParent(aActor); |
267 | 0 | } |
268 | | |
269 | | } // namespace dom |
270 | | } // namespace mozilla |