|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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 mozilla_dom_ContentChild_h |
|
8 #define mozilla_dom_ContentChild_h |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "mozilla/dom/PContentChild.h" |
|
12 #include "mozilla/dom/ipc/Blob.h" |
|
13 #include "nsHashKeys.h" |
|
14 #include "nsIObserver.h" |
|
15 #include "nsTHashtable.h" |
|
16 |
|
17 #include "nsWeakPtr.h" |
|
18 |
|
19 |
|
20 struct ChromePackage; |
|
21 class nsIDOMBlob; |
|
22 class nsIObserver; |
|
23 struct ResourceMapping; |
|
24 struct OverrideMapping; |
|
25 |
|
26 namespace mozilla { |
|
27 |
|
28 namespace ipc { |
|
29 class OptionalURIParams; |
|
30 class URIParams; |
|
31 }// namespace ipc |
|
32 |
|
33 namespace jsipc { |
|
34 class JavaScriptChild; |
|
35 } |
|
36 |
|
37 namespace layers { |
|
38 class PCompositorChild; |
|
39 } // namespace layers |
|
40 |
|
41 namespace dom { |
|
42 |
|
43 class AlertObserver; |
|
44 class PrefObserver; |
|
45 class ConsoleListener; |
|
46 class PStorageChild; |
|
47 class ClonedMessageData; |
|
48 class PFileDescriptorSetChild; |
|
49 |
|
50 class ContentChild : public PContentChild |
|
51 { |
|
52 typedef mozilla::dom::ClonedMessageData ClonedMessageData; |
|
53 typedef mozilla::ipc::OptionalURIParams OptionalURIParams; |
|
54 typedef mozilla::ipc::URIParams URIParams; |
|
55 |
|
56 public: |
|
57 ContentChild(); |
|
58 virtual ~ContentChild(); |
|
59 nsrefcnt AddRef() { return 1; } |
|
60 nsrefcnt Release() { return 1; } |
|
61 |
|
62 struct AppInfo |
|
63 { |
|
64 nsCString version; |
|
65 nsCString buildID; |
|
66 nsCString name; |
|
67 nsCString UAName; |
|
68 }; |
|
69 |
|
70 bool Init(MessageLoop* aIOLoop, |
|
71 base::ProcessHandle aParentHandle, |
|
72 IPC::Channel* aChannel); |
|
73 void InitProcessAttributes(); |
|
74 void InitXPCOM(); |
|
75 |
|
76 static ContentChild* GetSingleton() { |
|
77 return sSingleton; |
|
78 } |
|
79 |
|
80 const AppInfo& GetAppInfo() { |
|
81 return mAppInfo; |
|
82 } |
|
83 |
|
84 void SetProcessName(const nsAString& aName, bool aDontOverride = false); |
|
85 void GetProcessName(nsAString& aName); |
|
86 void GetProcessName(nsACString& aName); |
|
87 static void AppendProcessId(nsACString& aName); |
|
88 |
|
89 PCompositorChild* |
|
90 AllocPCompositorChild(mozilla::ipc::Transport* aTransport, |
|
91 base::ProcessId aOtherProcess) MOZ_OVERRIDE; |
|
92 PImageBridgeChild* |
|
93 AllocPImageBridgeChild(mozilla::ipc::Transport* aTransport, |
|
94 base::ProcessId aOtherProcess) MOZ_OVERRIDE; |
|
95 |
|
96 virtual bool RecvSetProcessSandbox() MOZ_OVERRIDE; |
|
97 |
|
98 PBackgroundChild* |
|
99 AllocPBackgroundChild(Transport* aTransport, ProcessId aOtherProcess) |
|
100 MOZ_OVERRIDE; |
|
101 |
|
102 virtual PBrowserChild* AllocPBrowserChild(const IPCTabContext &aContext, |
|
103 const uint32_t &chromeFlags); |
|
104 virtual bool DeallocPBrowserChild(PBrowserChild*); |
|
105 |
|
106 virtual PDeviceStorageRequestChild* AllocPDeviceStorageRequestChild(const DeviceStorageParams&); |
|
107 virtual bool DeallocPDeviceStorageRequestChild(PDeviceStorageRequestChild*); |
|
108 |
|
109 virtual PFileSystemRequestChild* AllocPFileSystemRequestChild(const FileSystemParams&); |
|
110 virtual bool DeallocPFileSystemRequestChild(PFileSystemRequestChild*); |
|
111 |
|
112 virtual PBlobChild* AllocPBlobChild(const BlobConstructorParams& aParams); |
|
113 virtual bool DeallocPBlobChild(PBlobChild*); |
|
114 |
|
115 virtual PCrashReporterChild* |
|
116 AllocPCrashReporterChild(const mozilla::dom::NativeThreadId& id, |
|
117 const uint32_t& processType) MOZ_OVERRIDE; |
|
118 virtual bool |
|
119 DeallocPCrashReporterChild(PCrashReporterChild*) MOZ_OVERRIDE; |
|
120 |
|
121 virtual PHalChild* AllocPHalChild() MOZ_OVERRIDE; |
|
122 virtual bool DeallocPHalChild(PHalChild*) MOZ_OVERRIDE; |
|
123 |
|
124 virtual PIndexedDBChild* AllocPIndexedDBChild() MOZ_OVERRIDE; |
|
125 virtual bool DeallocPIndexedDBChild(PIndexedDBChild* aActor) MOZ_OVERRIDE; |
|
126 |
|
127 virtual PMemoryReportRequestChild* |
|
128 AllocPMemoryReportRequestChild(const uint32_t& generation, |
|
129 const bool &minimizeMemoryUsage, |
|
130 const nsString &aDMDDumpIdent) MOZ_OVERRIDE; |
|
131 virtual bool |
|
132 DeallocPMemoryReportRequestChild(PMemoryReportRequestChild* actor) MOZ_OVERRIDE; |
|
133 |
|
134 virtual bool |
|
135 RecvPMemoryReportRequestConstructor(PMemoryReportRequestChild* child, |
|
136 const uint32_t& generation, |
|
137 const bool &minimizeMemoryUsage, |
|
138 const nsString &aDMDDumpIdent) MOZ_OVERRIDE; |
|
139 |
|
140 virtual bool |
|
141 RecvAudioChannelNotify() MOZ_OVERRIDE; |
|
142 |
|
143 virtual bool |
|
144 RecvDumpGCAndCCLogsToFile(const nsString& aIdentifier, |
|
145 const bool& aDumpAllTraces, |
|
146 const bool& aDumpChildProcesses) MOZ_OVERRIDE; |
|
147 |
|
148 virtual PTestShellChild* AllocPTestShellChild() MOZ_OVERRIDE; |
|
149 virtual bool DeallocPTestShellChild(PTestShellChild*) MOZ_OVERRIDE; |
|
150 virtual bool RecvPTestShellConstructor(PTestShellChild*) MOZ_OVERRIDE; |
|
151 jsipc::JavaScriptChild *GetCPOWManager(); |
|
152 |
|
153 virtual PNeckoChild* AllocPNeckoChild() MOZ_OVERRIDE; |
|
154 virtual bool DeallocPNeckoChild(PNeckoChild*) MOZ_OVERRIDE; |
|
155 |
|
156 virtual PExternalHelperAppChild *AllocPExternalHelperAppChild( |
|
157 const OptionalURIParams& uri, |
|
158 const nsCString& aMimeContentType, |
|
159 const nsCString& aContentDisposition, |
|
160 const uint32_t& aContentDispositionHint, |
|
161 const nsString& aContentDispositionFilename, |
|
162 const bool& aForceSave, |
|
163 const int64_t& aContentLength, |
|
164 const OptionalURIParams& aReferrer, |
|
165 PBrowserChild* aBrowser) MOZ_OVERRIDE; |
|
166 virtual bool DeallocPExternalHelperAppChild(PExternalHelperAppChild *aService) MOZ_OVERRIDE; |
|
167 |
|
168 virtual PSmsChild* AllocPSmsChild() MOZ_OVERRIDE; |
|
169 virtual bool DeallocPSmsChild(PSmsChild*) MOZ_OVERRIDE; |
|
170 |
|
171 virtual PTelephonyChild* AllocPTelephonyChild() MOZ_OVERRIDE; |
|
172 virtual bool DeallocPTelephonyChild(PTelephonyChild*) MOZ_OVERRIDE; |
|
173 |
|
174 virtual PStorageChild* AllocPStorageChild() MOZ_OVERRIDE; |
|
175 virtual bool DeallocPStorageChild(PStorageChild* aActor) MOZ_OVERRIDE; |
|
176 |
|
177 virtual PBluetoothChild* AllocPBluetoothChild() MOZ_OVERRIDE; |
|
178 virtual bool DeallocPBluetoothChild(PBluetoothChild* aActor) MOZ_OVERRIDE; |
|
179 |
|
180 virtual PFMRadioChild* AllocPFMRadioChild() MOZ_OVERRIDE; |
|
181 virtual bool DeallocPFMRadioChild(PFMRadioChild* aActor) MOZ_OVERRIDE; |
|
182 |
|
183 virtual PAsmJSCacheEntryChild* AllocPAsmJSCacheEntryChild( |
|
184 const asmjscache::OpenMode& aOpenMode, |
|
185 const asmjscache::WriteParams& aWriteParams, |
|
186 const IPC::Principal& aPrincipal) MOZ_OVERRIDE; |
|
187 virtual bool DeallocPAsmJSCacheEntryChild( |
|
188 PAsmJSCacheEntryChild* aActor) MOZ_OVERRIDE; |
|
189 |
|
190 virtual PSpeechSynthesisChild* AllocPSpeechSynthesisChild() MOZ_OVERRIDE; |
|
191 virtual bool DeallocPSpeechSynthesisChild(PSpeechSynthesisChild* aActor) MOZ_OVERRIDE; |
|
192 |
|
193 virtual bool RecvRegisterChrome(const InfallibleTArray<ChromePackage>& packages, |
|
194 const InfallibleTArray<ResourceMapping>& resources, |
|
195 const InfallibleTArray<OverrideMapping>& overrides, |
|
196 const nsCString& locale) MOZ_OVERRIDE; |
|
197 |
|
198 virtual mozilla::jsipc::PJavaScriptChild* AllocPJavaScriptChild() MOZ_OVERRIDE; |
|
199 virtual bool DeallocPJavaScriptChild(mozilla::jsipc::PJavaScriptChild*) MOZ_OVERRIDE; |
|
200 |
|
201 virtual bool RecvSetOffline(const bool& offline) MOZ_OVERRIDE; |
|
202 |
|
203 virtual bool RecvSpeakerManagerNotify() MOZ_OVERRIDE; |
|
204 |
|
205 virtual bool RecvNotifyVisited(const URIParams& aURI) MOZ_OVERRIDE; |
|
206 // auto remove when alertfinished is received. |
|
207 nsresult AddRemoteAlertObserver(const nsString& aData, nsIObserver* aObserver); |
|
208 |
|
209 virtual bool RecvPreferenceUpdate(const PrefSetting& aPref) MOZ_OVERRIDE; |
|
210 |
|
211 virtual bool RecvNotifyAlertsObserver(const nsCString& aType, |
|
212 const nsString& aData) MOZ_OVERRIDE; |
|
213 |
|
214 virtual bool RecvAsyncMessage(const nsString& aMsg, |
|
215 const ClonedMessageData& aData, |
|
216 const InfallibleTArray<CpowEntry>& aCpows, |
|
217 const IPC::Principal& aPrincipal) MOZ_OVERRIDE; |
|
218 |
|
219 virtual bool RecvGeolocationUpdate(const GeoPosition& somewhere) MOZ_OVERRIDE; |
|
220 |
|
221 virtual bool RecvAddPermission(const IPC::Permission& permission) MOZ_OVERRIDE; |
|
222 |
|
223 virtual bool RecvScreenSizeChanged(const gfxIntSize &size) MOZ_OVERRIDE; |
|
224 |
|
225 virtual bool RecvFlushMemory(const nsString& reason) MOZ_OVERRIDE; |
|
226 |
|
227 virtual bool RecvActivateA11y() MOZ_OVERRIDE; |
|
228 |
|
229 virtual bool RecvGarbageCollect() MOZ_OVERRIDE; |
|
230 virtual bool RecvCycleCollect() MOZ_OVERRIDE; |
|
231 |
|
232 virtual bool RecvAppInfo(const nsCString& version, const nsCString& buildID, |
|
233 const nsCString& name, const nsCString& UAName) MOZ_OVERRIDE; |
|
234 |
|
235 virtual bool RecvLastPrivateDocShellDestroyed() MOZ_OVERRIDE; |
|
236 |
|
237 virtual bool RecvFilePathUpdate(const nsString& aStorageType, |
|
238 const nsString& aStorageName, |
|
239 const nsString& aPath, |
|
240 const nsCString& aReason) MOZ_OVERRIDE; |
|
241 virtual bool RecvFileSystemUpdate(const nsString& aFsName, |
|
242 const nsString& aVolumeName, |
|
243 const int32_t& aState, |
|
244 const int32_t& aMountGeneration, |
|
245 const bool& aIsMediaPresent, |
|
246 const bool& aIsSharing, |
|
247 const bool& aIsFormatting) MOZ_OVERRIDE; |
|
248 |
|
249 virtual bool RecvNuwaFork() MOZ_OVERRIDE; |
|
250 |
|
251 virtual bool |
|
252 RecvNotifyProcessPriorityChanged(const hal::ProcessPriority& aPriority) MOZ_OVERRIDE; |
|
253 virtual bool RecvMinimizeMemoryUsage() MOZ_OVERRIDE; |
|
254 |
|
255 virtual bool RecvLoadAndRegisterSheet(const URIParams& aURI, |
|
256 const uint32_t& aType) MOZ_OVERRIDE; |
|
257 virtual bool RecvUnregisterSheet(const URIParams& aURI, const uint32_t& aType) MOZ_OVERRIDE; |
|
258 |
|
259 virtual bool RecvNotifyPhoneStateChange(const nsString& state) MOZ_OVERRIDE; |
|
260 |
|
261 void AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS); |
|
262 void RemoveIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS); |
|
263 virtual bool RecvNotifyIdleObserver(const uint64_t& aObserver, |
|
264 const nsCString& aTopic, |
|
265 const nsString& aData) MOZ_OVERRIDE; |
|
266 #ifdef ANDROID |
|
267 gfxIntSize GetScreenSize() { return mScreenSize; } |
|
268 #endif |
|
269 |
|
270 // Get the directory for IndexedDB files. We query the parent for this and |
|
271 // cache the value |
|
272 nsString &GetIndexedDBPath(); |
|
273 |
|
274 uint64_t GetID() { return mID; } |
|
275 |
|
276 bool IsForApp() { return mIsForApp; } |
|
277 bool IsForBrowser() { return mIsForBrowser; } |
|
278 |
|
279 BlobChild* GetOrCreateActorForBlob(nsIDOMBlob* aBlob); |
|
280 |
|
281 virtual PFileDescriptorSetChild* |
|
282 AllocPFileDescriptorSetChild(const FileDescriptor&) MOZ_OVERRIDE; |
|
283 |
|
284 virtual bool |
|
285 DeallocPFileDescriptorSetChild(PFileDescriptorSetChild*) MOZ_OVERRIDE; |
|
286 |
|
287 protected: |
|
288 virtual bool RecvPBrowserConstructor(PBrowserChild* actor, |
|
289 const IPCTabContext& context, |
|
290 const uint32_t& chromeFlags) MOZ_OVERRIDE; |
|
291 |
|
292 private: |
|
293 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; |
|
294 |
|
295 virtual void ProcessingError(Result what) MOZ_OVERRIDE; |
|
296 |
|
297 /** |
|
298 * Exit *now*. Do not shut down XPCOM, do not pass Go, do not run |
|
299 * static destructors, do not collect $200. |
|
300 */ |
|
301 MOZ_NORETURN void QuickExit(); |
|
302 |
|
303 InfallibleTArray<nsAutoPtr<AlertObserver> > mAlertObservers; |
|
304 nsRefPtr<ConsoleListener> mConsoleListener; |
|
305 |
|
306 nsTHashtable<nsPtrHashKey<nsIObserver>> mIdleObservers; |
|
307 |
|
308 /** |
|
309 * An ID unique to the process containing our corresponding |
|
310 * content parent. |
|
311 * |
|
312 * We expect our content parent to set this ID immediately after opening a |
|
313 * channel to us. |
|
314 */ |
|
315 uint64_t mID; |
|
316 |
|
317 AppInfo mAppInfo; |
|
318 |
|
319 #ifdef ANDROID |
|
320 gfxIntSize mScreenSize; |
|
321 #endif |
|
322 |
|
323 bool mIsForApp; |
|
324 bool mIsForBrowser; |
|
325 bool mCanOverrideProcessName; |
|
326 nsString mProcessName; |
|
327 |
|
328 static ContentChild* sSingleton; |
|
329 |
|
330 DISALLOW_EVIL_CONSTRUCTORS(ContentChild); |
|
331 }; |
|
332 |
|
333 } // namespace dom |
|
334 } // namespace mozilla |
|
335 |
|
336 #endif |