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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_dom_ContentParent_h
8 #define mozilla_dom_ContentParent_h
9
10 #include "mozilla/dom/PContentParent.h"
11 #include "mozilla/dom/ipc/IdType.h"
12 #include "mozilla/dom/MessageManagerCallback.h"
13 #include "mozilla/dom/MediaSessionBinding.h"
14 #include "mozilla/dom/RemoteBrowser.h"
15 #include "mozilla/dom/RemoteType.h"
16 #include "mozilla/dom/JSProcessActorParent.h"
17 #include "mozilla/dom/ProcessActor.h"
18 #include "mozilla/gfx/gfxVarReceiver.h"
19 #include "mozilla/gfx/GPUProcessListener.h"
20 #include "mozilla/ipc/BackgroundUtils.h"
21 #include "mozilla/ipc/GeckoChildProcessHost.h"
22 #include "mozilla/ipc/InputStreamUtils.h"
23 #include "mozilla/ipc/PParentToChildStreamParent.h"
24 #include "mozilla/ipc/PChildToParentStreamParent.h"
25 #include "mozilla/Attributes.h"
26 #include "mozilla/DataMutex.h"
27 #include "mozilla/FileUtils.h"
28 #include "mozilla/HalTypes.h"
29 #include "mozilla/LinkedList.h"
30 #include "mozilla/Maybe.h"
31 #include "mozilla/MemoryReportingProcess.h"
32 #include "mozilla/MozPromise.h"
33 #include "mozilla/TimeStamp.h"
34 #include "mozilla/UniquePtr.h"
35
36 #include "nsClassHashtable.h"
37 #include "nsTHashMap.h"
38 #include "nsTHashSet.h"
39 #include "nsPluginTags.h"
40 #include "nsHashKeys.h"
41 #include "nsIAsyncShutdown.h"
42 #include "nsIDOMProcessParent.h"
43 #include "nsIInterfaceRequestor.h"
44 #include "nsIObserver.h"
45 #include "nsIRemoteTab.h"
46 #include "nsIDOMGeoPositionCallback.h"
47 #include "nsIDOMGeoPositionErrorCallback.h"
48 #include "nsRefPtrHashtable.h"
49 #include "PermissionMessageUtils.h"
50 #include "DriverCrashGuard.h"
51 #include "nsIReferrerInfo.h"
52
53 #define CHILD_PROCESS_SHUTDOWN_MESSAGE u"child-process-shutdown"_ns
54
55 class nsConsoleService;
56 class nsIContentProcessInfo;
57 class nsICycleCollectorLogSink;
58 class nsIDumpGCAndCCLogsCallback;
59 class nsIRemoteTab;
60 class nsITimer;
61 class ParentIdleListener;
62 class nsIWidget;
63
64 namespace mozilla {
65 class PRemoteSpellcheckEngineParent;
66
67 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
68 class SandboxBroker;
69 class SandboxBrokerPolicyFactory;
70 #endif
71
72 class PreallocatedProcessManagerImpl;
73 class BenchmarkStorageParent;
74
75 using mozilla::loader::PScriptCacheParent;
76
77 namespace embedding {
78 class PrintingParent;
79 }
80
81 namespace ipc {
82 class CrashReporterHost;
83 class PFileDescriptorSetParent;
84 class TestShellParent;
85 #ifdef FUZZING
86 class ProtocolFuzzerHelper;
87 #endif
88 class SharedPreferenceSerializer;
89 } // namespace ipc
90
91 namespace layers {
92 struct TextureFactoryIdentifier;
93 } // namespace layers
94
95 namespace dom {
96
97 class BrowsingContextGroup;
98 class Element;
99 class BrowserParent;
100 class ClonedMessageData;
101 class MemoryReport;
102 class TabContext;
103 class GetFilesHelper;
104 class MemoryReportRequestHost;
105 class RemoteWorkerManager;
106 struct CancelContentJSOptions;
107
108 #define NS_CONTENTPARENT_IID \
109 { \
110 0xeeec9ebf, 0x8ecf, 0x4e38, { \
111 0x81, 0xda, 0xb7, 0x34, 0x13, 0x7e, 0xac, 0xf3 \
112 } \
113 }
114
115 class ContentParent final
116 : public PContentParent,
117 public nsIDOMProcessParent,
118 public nsIObserver,
119 public nsIDOMGeoPositionCallback,
120 public nsIDOMGeoPositionErrorCallback,
121 public nsIAsyncShutdownBlocker,
122 public nsIInterfaceRequestor,
123 public gfx::gfxVarReceiver,
124 public mozilla::LinkedListElement<ContentParent>,
125 public gfx::GPUProcessListener,
126 public mozilla::MemoryReportingProcess,
127 public mozilla::dom::ipc::MessageManagerCallback,
128 public mozilla::ipc::IShmemAllocator,
129 public mozilla::ipc::ParentToChildStreamActorManager,
130 public ProcessActor {
131 typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
132 typedef mozilla::ipc::PFileDescriptorSetParent PFileDescriptorSetParent;
133 typedef mozilla::ipc::TestShellParent TestShellParent;
134 typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
135 typedef mozilla::dom::ClonedMessageData ClonedMessageData;
136 typedef mozilla::dom::BrowsingContextGroup BrowsingContextGroup;
137
138 friend class mozilla::PreallocatedProcessManagerImpl;
139 friend class PContentParent;
140 friend class mozilla::dom::RemoteWorkerManager;
141 #ifdef FUZZING
142 friend class mozilla::ipc::ProtocolFuzzerHelper;
143 #endif
144
145 public:
146 using LaunchError = mozilla::ipc::LaunchError;
147 using LaunchPromise =
148 mozilla::MozPromise<RefPtr<ContentParent>, LaunchError, false>;
149
150 NS_DECLARE_STATIC_IID_ACCESSOR(NS_CONTENTPARENT_IID)
151
152 static LogModule* GetLog();
153
154 /**
155 * Create a subprocess suitable for use later as a content process.
156 */
157 static RefPtr<LaunchPromise> PreallocateProcess();
158
159 /**
160 * Start up the content-process machinery. This might include
161 * scheduling pre-launch tasks.
162 */
163 static void StartUp();
164
165 /** Shut down the content-process machinery. */
166 static void ShutDown();
167
168 static uint32_t GetPoolSize(const nsACString& aContentProcessType);
169
170 static uint32_t GetMaxProcessCount(const nsACString& aContentProcessType);
171
172 static bool IsMaxProcessCountReached(const nsACString& aContentProcessType);
173
174 static void ReleaseCachedProcesses();
175
176 static void LogAndAssertFailedPrincipalValidationInfo(
177 nsIPrincipal* aPrincipal, const char* aMethod);
178
179 /**
180 * Picks a random content parent from |aContentParents| respecting the index
181 * limit set by |aMaxContentParents|.
182 * Returns null if non available.
183 */
184 static already_AddRefed<ContentParent> MinTabSelect(
185 const nsTArray<ContentParent*>& aContentParents,
186 int32_t maxContentParents);
187
188 /**
189 * Get or create a content process for:
190 * 1. browser iframe
191 * 2. remote xul <browser>
192 * 3. normal iframe
193 */
194 static RefPtr<ContentParent::LaunchPromise> GetNewOrUsedBrowserProcessAsync(
195 const nsACString& aRemoteType, BrowsingContextGroup* aGroup = nullptr,
196 hal::ProcessPriority aPriority =
197 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
198 bool aPreferUsed = false);
199 static already_AddRefed<ContentParent> GetNewOrUsedBrowserProcess(
200 const nsACString& aRemoteType, BrowsingContextGroup* aGroup = nullptr,
201 hal::ProcessPriority aPriority =
202 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
203 bool aPreferUsed = false);
204
205 /**
206 * Get or create a content process, but without waiting for the process
207 * launch to have completed. The returned `ContentParent` may still be in the
208 * "Launching" state.
209 *
210 * Can return `nullptr` in the case of an error.
211 *
212 * Use the `WaitForLaunchAsync` or `WaitForLaunchSync` methods to wait for
213 * the process to be fully launched.
214 */
215 static already_AddRefed<ContentParent> GetNewOrUsedLaunchingBrowserProcess(
216 const nsACString& aRemoteType, BrowsingContextGroup* aGroup = nullptr,
217 hal::ProcessPriority aPriority =
218 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
219 bool aPreferUsed = false);
220
221 RefPtr<ContentParent::LaunchPromise> WaitForLaunchAsync(
222 hal::ProcessPriority aPriority =
223 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND);
224 bool WaitForLaunchSync(hal::ProcessPriority aPriority =
225 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND);
226
227 /**
228 * Get or create a content process for a JS plugin. aPluginID is the id of the
229 * JS plugin
230 * (@see nsFakePlugin::mId). There is a maximum of one process per JS plugin.
231 */
232 static already_AddRefed<ContentParent> GetNewOrUsedJSPluginProcess(
233 uint32_t aPluginID, const hal::ProcessPriority& aPriority);
234
235 /**
236 * Get or create a content process for the given TabContext. aFrameElement
237 * should be the frame/iframe element with which this process will
238 * associated.
239 */
240 static already_AddRefed<RemoteBrowser> CreateBrowser(
241 const TabContext& aContext, Element* aFrameElement,
242 const nsACString& aRemoteType, BrowsingContext* aBrowsingContext,
243 ContentParent* aOpenerContentParent);
244
245 /**
246 * Get all content parents.
247 *
248 * # Lifetime
249 *
250 * These pointers are ONLY valid for synchronous use from the main thread.
251 *
252 * Do NOT attempt to use them after the main thread has had a chance to handle
253 * messages or you could end up with dangling pointers.
254 */
255 static void GetAll(nsTArray<ContentParent*>& aArray);
256
257 static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
258
259 static void BroadcastStringBundle(const StringBundleDescriptor&);
260
261 static void BroadcastFontListChanged();
262 static void BroadcastShmBlockAdded(uint32_t aGeneration, uint32_t aIndex);
263
264 static void BroadcastThemeUpdate(widget::ThemeChangeKind);
265
266 static void BroadcastMediaCodecsSupportedUpdate(
267 RemoteDecodeIn aLocation,
268 const PDMFactory::MediaCodecsSupported& aSupported);
269
270 const nsACString& GetRemoteType() const override;
271
DoGetRemoteType(nsACString & aRemoteType,ErrorResult & aError)272 virtual void DoGetRemoteType(nsACString& aRemoteType,
273 ErrorResult& aError) const override {
274 aRemoteType = GetRemoteType();
275 }
276
277 enum CPIteratorPolicy { eLive, eAll };
278
279 class ContentParentIterator {
280 private:
281 ContentParent* mCurrent;
282 CPIteratorPolicy mPolicy;
283
284 public:
ContentParentIterator(CPIteratorPolicy aPolicy,ContentParent * aCurrent)285 ContentParentIterator(CPIteratorPolicy aPolicy, ContentParent* aCurrent)
286 : mCurrent(aCurrent), mPolicy(aPolicy) {}
287
begin()288 ContentParentIterator begin() {
289 // Move the cursor to the first element that matches the policy.
290 while (mPolicy != eAll && mCurrent && !mCurrent->IsAlive()) {
291 mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
292 }
293
294 return *this;
295 }
end()296 ContentParentIterator end() {
297 return ContentParentIterator(mPolicy, nullptr);
298 }
299
300 const ContentParentIterator& operator++() {
301 MOZ_ASSERT(mCurrent);
302 do {
303 mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
304 } while (mPolicy != eAll && mCurrent && !mCurrent->IsAlive());
305
306 return *this;
307 }
308
309 bool operator!=(const ContentParentIterator& aOther) {
310 MOZ_ASSERT(mPolicy == aOther.mPolicy);
311 return mCurrent != aOther.mCurrent;
312 }
313
314 ContentParent* operator*() { return mCurrent; }
315 };
316
AllProcesses(CPIteratorPolicy aPolicy)317 static ContentParentIterator AllProcesses(CPIteratorPolicy aPolicy) {
318 ContentParent* first =
319 sContentParents ? sContentParents->getFirst() : nullptr;
320 return ContentParentIterator(aPolicy, first);
321 }
322
323 static void NotifyUpdatedDictionaries();
324
325 // Tell content processes the font list has changed. If aFullRebuild is true,
326 // the shared list has been rebuilt and must be freshly mapped by child
327 // processes; if false, existing mappings are still valid but the data has
328 // been updated and so full reflows are in order.
329 static void NotifyUpdatedFonts(bool aFullRebuild);
330
331 #if defined(XP_WIN)
332 /**
333 * Windows helper for firing off an update window request to a plugin
334 * instance.
335 *
336 * aWidget - the eWindowType_plugin_ipc_chrome widget associated with
337 * this plugin window.
338 */
339 static void SendAsyncUpdate(nsIWidget* aWidget);
340 #endif
341
342 mozilla::ipc::IPCResult RecvCreateGMPService();
343
344 mozilla::ipc::IPCResult RecvUngrabPointer(const uint32_t& aTime);
345
346 mozilla::ipc::IPCResult RecvRemovePermission(const IPC::Principal& aPrincipal,
347 const nsCString& aPermissionType,
348 nsresult* aRv);
349
350 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver)
351
352 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
353 NS_DECL_NSIDOMPROCESSPARENT
354 NS_DECL_NSIOBSERVER
355 NS_DECL_NSIDOMGEOPOSITIONCALLBACK
356 NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
357 NS_DECL_NSIASYNCSHUTDOWNBLOCKER
358 NS_DECL_NSIINTERFACEREQUESTOR
359
360 /**
361 * MessageManagerCallback methods that we override.
362 */
363 virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
364 bool aRunInGlobalScope) override;
365
366 virtual nsresult DoSendAsyncMessage(const nsAString& aMessage,
367 StructuredCloneData& aData) override;
368
369 /** Notify that a tab is beginning its destruction sequence. */
370 void NotifyTabDestroying();
371
372 /** Notify that a tab was destroyed during normal operation. */
373 void NotifyTabDestroyed(const TabId& aTabId, bool aNotifiedDestroying);
374
375 // Manage the set of `KeepAlive`s on this ContentParent which are preventing
376 // it from being destroyed.
377 void AddKeepAlive();
378 void RemoveKeepAlive();
379
380 TestShellParent* CreateTestShell();
381
382 bool DestroyTestShell(TestShellParent* aTestShell);
383
384 TestShellParent* GetTestShellSingleton();
385
386 // This method can be called on any thread.
387 void RegisterRemoteWorkerActor();
388
389 // This method _must_ be called on main-thread because it can start the
390 // shutting down of the content process.
391 void UnregisterRemoveWorkerActor();
392
393 void ReportChildAlreadyBlocked();
394
395 bool RequestRunToCompletion();
396
397 void UpdateCookieStatus(nsIChannel* aChannel);
398
IsLaunching()399 bool IsLaunching() const {
400 return mLifecycleState == LifecycleState::LAUNCHING;
401 }
402 bool IsAlive() const override;
403 bool IsInitialized() const;
IsDead()404 bool IsDead() const { return mLifecycleState == LifecycleState::DEAD; }
405
IsForBrowser()406 bool IsForBrowser() const { return mIsForBrowser; }
IsForJSPlugin()407 bool IsForJSPlugin() const {
408 return mJSPluginID != nsFakePluginTag::NOT_JSPLUGIN;
409 }
410
Process()411 GeckoChildProcessHost* Process() const { return mSubprocess; }
412
ScriptableHelper()413 nsIContentProcessInfo* ScriptableHelper() const { return mScriptableHelper; }
414
GetMessageManager()415 mozilla::dom::ProcessMessageManager* GetMessageManager() const {
416 return mMessageManager;
417 }
418
419 bool NeedsPermissionsUpdate(const nsACString& aPermissionKey) const;
420
421 /**
422 * Kill our subprocess and make sure it dies. Should only be used
423 * in emergency situations since it bypasses the normal shutdown
424 * process.
425 *
426 * WARNING: aReason appears in telemetry, so any new value passed in requires
427 * data review.
428 */
429 void KillHard(const char* aWhy);
430
ChildID()431 ContentParentId ChildID() const { return mChildID; }
432
433 /**
434 * Get a user-friendly name for this ContentParent. We make no guarantees
435 * about this name: It might not be unique, apps can spoof special names,
436 * etc. So please don't use this name to make any decisions about the
437 * ContentParent based on the value returned here.
438 */
439 void FriendlyName(nsAString& aName, bool aAnonymize = false);
440
441 virtual void OnChannelError() override;
442
443 mozilla::ipc::IPCResult RecvInitCrashReporter(
444 const NativeThreadId& aThreadId);
445
446 PNeckoParent* AllocPNeckoParent();
447
RecvPNeckoConstructor(PNeckoParent * aActor)448 virtual mozilla::ipc::IPCResult RecvPNeckoConstructor(
449 PNeckoParent* aActor) override {
450 return PContentParent::RecvPNeckoConstructor(aActor);
451 }
452
453 PPrintingParent* AllocPPrintingParent();
454
455 bool DeallocPPrintingParent(PPrintingParent* aActor);
456
457 #if defined(NS_PRINTING)
458 /**
459 * @return the PrintingParent for this ContentParent.
460 */
461 already_AddRefed<embedding::PrintingParent> GetPrintingParent();
462 #endif
463
464 mozilla::ipc::IPCResult RecvInitStreamFilter(
465 const uint64_t& aChannelId, const nsString& aAddonId,
466 InitStreamFilterResolver&& aResolver);
467
468 PChildToParentStreamParent* AllocPChildToParentStreamParent();
469 bool DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor);
470
471 PParentToChildStreamParent* AllocPParentToChildStreamParent();
472 bool DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor);
473
474 PHalParent* AllocPHalParent();
475
RecvPHalConstructor(PHalParent * aActor)476 virtual mozilla::ipc::IPCResult RecvPHalConstructor(
477 PHalParent* aActor) override {
478 return PContentParent::RecvPHalConstructor(aActor);
479 }
480
481 PHeapSnapshotTempFileHelperParent* AllocPHeapSnapshotTempFileHelperParent();
482
483 PRemoteSpellcheckEngineParent* AllocPRemoteSpellcheckEngineParent();
484
485 mozilla::ipc::IPCResult RecvRecordingDeviceEvents(
486 const nsString& aRecordingStatus, const nsString& aPageURL,
487 const bool& aIsAudio, const bool& aIsVideo);
488
489 bool CycleCollectWithLogs(bool aDumpAllTraces,
490 nsICycleCollectorLogSink* aSink,
491 nsIDumpGCAndCCLogsCallback* aCallback);
492
493 mozilla::ipc::IPCResult RecvNotifyTabDestroying(const TabId& aTabId,
494 const ContentParentId& aCpId);
495
496 mozilla::ipc::IPCResult RecvSetOfflinePermission(
497 const IPC::Principal& principal);
498
499 mozilla::ipc::IPCResult RecvFinishShutdown();
500
501 void MaybeInvokeDragSession(BrowserParent* aParent);
502
503 PContentPermissionRequestParent* AllocPContentPermissionRequestParent(
504 const nsTArray<PermissionRequest>& aRequests,
505 const IPC::Principal& aPrincipal,
506 const IPC::Principal& aTopLevelPrincipal,
507 const bool& aIsHandlingUserInput,
508 const bool& aMaybeUnsafePermissionDelegate, const TabId& aTabId);
509
510 bool DeallocPContentPermissionRequestParent(
511 PContentPermissionRequestParent* actor);
512
513 virtual bool HandleWindowsMessages(const Message& aMsg) const override;
514
515 void ForkNewProcess(bool aBlocking);
516
517 mozilla::ipc::IPCResult RecvCreateWindow(
518 PBrowserParent* aThisBrowserParent,
519 const MaybeDiscarded<BrowsingContext>& aParent, PBrowserParent* aNewTab,
520 const uint32_t& aChromeFlags, const bool& aCalledFromJS,
521 const bool& aWidthSpecified, const bool& aForPrinting,
522 const bool& aForWindowDotPrint, nsIURI* aURIToLoad,
523 const nsCString& aFeatures, const float& aFullZoom,
524 const IPC::Principal& aTriggeringPrincipal,
525 nsIContentSecurityPolicy* aCsp, nsIReferrerInfo* aReferrerInfo,
526 const OriginAttributes& aOriginAttributes,
527 CreateWindowResolver&& aResolve);
528
529 mozilla::ipc::IPCResult RecvCreateWindowInDifferentProcess(
530 PBrowserParent* aThisTab, const MaybeDiscarded<BrowsingContext>& aParent,
531 const uint32_t& aChromeFlags, const bool& aCalledFromJS,
532 const bool& aWidthSpecified, nsIURI* aURIToLoad,
533 const nsCString& aFeatures, const float& aFullZoom, const nsString& aName,
534 nsIPrincipal* aTriggeringPrincipal, nsIContentSecurityPolicy* aCsp,
535 nsIReferrerInfo* aReferrerInfo,
536 const OriginAttributes& aOriginAttributes);
537
538 static void BroadcastBlobURLRegistration(
539 const nsACString& aURI, BlobImpl* aBlobImpl, nsIPrincipal* aPrincipal,
540 const Maybe<nsID>& aAgentClusterId,
541 ContentParent* aIgnoreThisCP = nullptr);
542
543 static void BroadcastBlobURLUnregistration(
544 const nsACString& aURI, nsIPrincipal* aPrincipal,
545 ContentParent* aIgnoreThisCP = nullptr);
546
547 mozilla::ipc::IPCResult RecvStoreAndBroadcastBlobURLRegistration(
548 const nsCString& aURI, const IPCBlob& aBlob, const Principal& aPrincipal,
549 const Maybe<nsID>& aAgentCluster);
550
551 mozilla::ipc::IPCResult RecvUnstoreAndBroadcastBlobURLUnregistration(
552 const nsCString& aURI, const Principal& aPrincipal);
553
554 mozilla::ipc::IPCResult RecvGetA11yContentId(uint32_t* aContentId);
555
556 mozilla::ipc::IPCResult RecvA11yHandlerControl(
557 const uint32_t& aPid, const IHandlerControlHolder& aHandlerControl);
558
559 virtual int32_t Pid() const override;
560
561 // PURLClassifierParent.
562 PURLClassifierParent* AllocPURLClassifierParent(const Principal& aPrincipal,
563 bool* aSuccess);
564 virtual mozilla::ipc::IPCResult RecvPURLClassifierConstructor(
565 PURLClassifierParent* aActor, const Principal& aPrincipal,
566 bool* aSuccess) override;
567
568 // PURLClassifierLocalParent.
569 PURLClassifierLocalParent* AllocPURLClassifierLocalParent(
570 nsIURI* aURI, const nsTArray<IPCURLClassifierFeature>& aFeatures);
571
572 virtual mozilla::ipc::IPCResult RecvPURLClassifierLocalConstructor(
573 PURLClassifierLocalParent* aActor, nsIURI* aURI,
574 nsTArray<IPCURLClassifierFeature>&& aFeatures) override;
575
576 PLoginReputationParent* AllocPLoginReputationParent(nsIURI* aURI);
577
578 virtual mozilla::ipc::IPCResult RecvPLoginReputationConstructor(
579 PLoginReputationParent* aActor, nsIURI* aURI) override;
580
581 bool DeallocPLoginReputationParent(PLoginReputationParent* aActor);
582
583 PSessionStorageObserverParent* AllocPSessionStorageObserverParent();
584
585 virtual mozilla::ipc::IPCResult RecvPSessionStorageObserverConstructor(
586 PSessionStorageObserverParent* aActor) override;
587
588 bool DeallocPSessionStorageObserverParent(
589 PSessionStorageObserverParent* aActor);
590
591 bool DeallocPURLClassifierLocalParent(PURLClassifierLocalParent* aActor);
592
593 bool DeallocPURLClassifierParent(PURLClassifierParent* aActor);
594
595 // Use the PHangMonitor channel to ask the child to repaint a tab.
596 void PaintTabWhileInterruptingJS(BrowserParent* aBrowserParent,
597 const layers::LayersObserverEpoch& aEpoch);
598
599 void CancelContentJSExecutionIfRunning(
600 BrowserParent* aBrowserParent,
601 nsIRemoteTab::NavigationType aNavigationType,
602 const CancelContentJSOptions& aCancelContentJSOptions);
603
604 // This function is called when we are about to load a document from an
605 // HTTP(S) or FTP channel for a content process. It is a useful place
606 // to start to kick off work as early as possible in response to such
607 // document loads.
608 // aShouldWaitForPermissionCookieUpdate is set to true if main thread IPCs for
609 // updating permissions/cookies are sent.
610 nsresult AboutToLoadHttpFtpDocumentForChild(
611 nsIChannel* aChannel,
612 bool* aShouldWaitForPermissionCookieUpdate = nullptr);
613
614 // Send Blob URLs for this aPrincipal if they are not already known to this
615 // content process and mark the process to receive any new/revoked Blob URLs
616 // to this content process forever.
617 void TransmitBlobURLsForPrincipal(nsIPrincipal* aPrincipal);
618
619 nsresult TransmitPermissionsForPrincipal(nsIPrincipal* aPrincipal);
620
621 // Whenever receiving a Principal we need to validate that Principal case
622 // by case, where we grant individual callsites to customize the checks!
623 enum class ValidatePrincipalOptions {
624 AllowNullPtr, // Not a NullPrincipal but a nullptr as Principal.
625 AllowSystem,
626 AllowExpanded,
627 };
628 bool ValidatePrincipal(
629 nsIPrincipal* aPrincipal,
630 const EnumSet<ValidatePrincipalOptions>& aOptions = {});
631
632 // This function is called in BrowsingContext immediately before IPC call to
633 // load a URI. If aURI is a BlobURL, this method transmits all BlobURLs for
634 // aPrincipal that were previously not transmitted. This allows for opening a
635 // locally created BlobURL in a new tab.
636 //
637 // The reason all previously untransmitted Blobs are transmitted is that the
638 // current BlobURL could contain html code, referring to another untransmitted
639 // BlobURL.
640 //
641 // Should eventually be made obsolete by broader design changes that only
642 // store BlobURLs in the parent process.
643 void TransmitBlobDataIfBlobURL(nsIURI* aURI, nsIPrincipal* aPrincipal);
644
645 void OnCompositorDeviceReset() override;
646
647 // Control the priority of the IPC messages for input events.
648 void SetInputPriorityEventEnabled(bool aEnabled);
IsInputPriorityEventEnabled()649 bool IsInputPriorityEventEnabled() { return mIsInputPriorityEventEnabled; }
650
651 static bool IsInputEventQueueSupported();
652
653 mozilla::ipc::IPCResult RecvCreateBrowsingContext(
654 uint64_t aGroupId, BrowsingContext::IPCInitializer&& aInit);
655
656 mozilla::ipc::IPCResult RecvDiscardBrowsingContext(
657 const MaybeDiscarded<BrowsingContext>& aContext,
658 DiscardBrowsingContextResolver&& aResolve);
659
660 mozilla::ipc::IPCResult RecvWindowClose(
661 const MaybeDiscarded<BrowsingContext>& aContext, bool aTrustedCaller);
662 mozilla::ipc::IPCResult RecvWindowFocus(
663 const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType,
664 uint64_t aActionId);
665 mozilla::ipc::IPCResult RecvWindowBlur(
666 const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType);
667 mozilla::ipc::IPCResult RecvRaiseWindow(
668 const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType,
669 uint64_t aActionId);
670 mozilla::ipc::IPCResult RecvAdjustWindowFocus(
671 const MaybeDiscarded<BrowsingContext>& aContext, bool aIsVisible,
672 uint64_t aActionId);
673 mozilla::ipc::IPCResult RecvClearFocus(
674 const MaybeDiscarded<BrowsingContext>& aContext);
675 mozilla::ipc::IPCResult RecvSetFocusedBrowsingContext(
676 const MaybeDiscarded<BrowsingContext>& aContext, uint64_t aActionId);
677 mozilla::ipc::IPCResult RecvSetActiveBrowsingContext(
678 const MaybeDiscarded<BrowsingContext>& aContext, uint64_t aActionId);
679 mozilla::ipc::IPCResult RecvUnsetActiveBrowsingContext(
680 const MaybeDiscarded<BrowsingContext>& aContext, uint64_t aActionId);
681 mozilla::ipc::IPCResult RecvSetFocusedElement(
682 const MaybeDiscarded<BrowsingContext>& aContext, bool aNeedsFocus);
683 mozilla::ipc::IPCResult RecvFinalizeFocusOuter(
684 const MaybeDiscarded<BrowsingContext>& aContext, bool aCanFocus,
685 CallerType aCallerType);
686 mozilla::ipc::IPCResult RecvInsertNewFocusActionId(uint64_t aActionId);
687 mozilla::ipc::IPCResult RecvBlurToParent(
688 const MaybeDiscarded<BrowsingContext>& aFocusedBrowsingContext,
689 const MaybeDiscarded<BrowsingContext>& aBrowsingContextToClear,
690 const MaybeDiscarded<BrowsingContext>& aAncestorBrowsingContextToFocus,
691 bool aIsLeavingDocument, bool aAdjustWidget,
692 bool aBrowsingContextToClearHandled,
693 bool aAncestorBrowsingContextToFocusHandled, uint64_t aActionId);
694 mozilla::ipc::IPCResult RecvMaybeExitFullscreen(
695 const MaybeDiscarded<BrowsingContext>& aContext);
696
697 mozilla::ipc::IPCResult RecvWindowPostMessage(
698 const MaybeDiscarded<BrowsingContext>& aContext,
699 const ClonedOrErrorMessageData& aMessage, const PostMessageData& aData);
700
701 FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
702
703 PParentToChildStreamParent* SendPParentToChildStreamConstructor(
704 PParentToChildStreamParent* aActor) override;
705 PFileDescriptorSetParent* SendPFileDescriptorSetConstructor(
706 const FileDescriptor& aFD) override;
707
708 mozilla::ipc::IPCResult RecvBlobURLDataRequest(
709 const nsCString& aBlobURL, nsIPrincipal* pTriggeringPrincipal,
710 nsIPrincipal* pLoadingPrincipal,
711 const OriginAttributes& aOriginAttributes, uint64_t aInnerWindowId,
712 const Maybe<nsID>& aAgentClusterId,
713 BlobURLDataRequestResolver&& aResolver);
714
715 protected:
716 bool CheckBrowsingContextEmbedder(CanonicalBrowsingContext* aBC,
717 const char* aOperation) const;
718
719 void ActorDestroy(ActorDestroyReason why) override;
720 void ActorDealloc() override;
721
722 bool ShouldContinueFromReplyTimeout() override;
723
724 void OnVarChanged(const GfxVarUpdate& aVar) override;
725 void OnCompositorUnexpectedShutdown() override;
726
727 private:
728 /**
729 * A map of the remote content process type to a list of content parents
730 * currently available to host *new* tabs/frames of that type.
731 *
732 * If a content process is identified as troubled or dead, it will be
733 * removed from this list, but will still be in the sContentParents list for
734 * the GetAll/GetAllEvenIfDead APIs.
735 */
736 static nsClassHashtable<nsCStringHashKey, nsTArray<ContentParent*>>*
737 sBrowserContentParents;
738 static UniquePtr<nsTArray<ContentParent*>> sPrivateContent;
739 static UniquePtr<nsTHashMap<nsUint32HashKey, ContentParent*>>
740 sJSPluginContentParents;
741 static UniquePtr<LinkedList<ContentParent>> sContentParents;
742
743 /**
744 * In order to avoid rapidly creating and destroying content processes when
745 * running under e10s, we may keep alive a single unused "web" content
746 * process if it previously had a very short lifetime.
747 *
748 * This process will be re-used during process selection, avoiding spawning a
749 * new process, if the "web" remote type is being requested.
750 */
751 static StaticRefPtr<ContentParent> sRecycledE10SProcess;
752
753 void AddShutdownBlockers();
754 void RemoveShutdownBlockers();
755
756 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
757 // Cached Mac sandbox params used when launching content processes.
758 static UniquePtr<std::vector<std::string>> sMacSandboxParams;
759 #endif
760
761 // Set aLoadUri to true to load aURIToLoad and to false to only create the
762 // window. aURIToLoad should always be provided, if available, to ensure
763 // compatibility with GeckoView.
764 mozilla::ipc::IPCResult CommonCreateWindow(
765 PBrowserParent* aThisTab, BrowsingContext* aParent, bool aSetOpener,
766 const uint32_t& aChromeFlags, const bool& aCalledFromJS,
767 const bool& aWidthSpecified, const bool& aForPrinting,
768 const bool& aForWindowDotPrint, nsIURI* aURIToLoad,
769 const nsCString& aFeatures, const float& aFullZoom,
770 BrowserParent* aNextRemoteBrowser, const nsString& aName,
771 nsresult& aResult, nsCOMPtr<nsIRemoteTab>& aNewRemoteTab,
772 bool* aWindowIsNew, int32_t& aOpenLocation,
773 nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo,
774 bool aLoadUri, nsIContentSecurityPolicy* aCsp,
775 const OriginAttributes& aOriginAttributes);
776
ContentParent(int32_t aPluginID)777 explicit ContentParent(int32_t aPluginID) : ContentParent(""_ns, aPluginID) {}
ContentParent(const nsACString & aRemoteType)778 explicit ContentParent(const nsACString& aRemoteType)
779 : ContentParent(aRemoteType, nsFakePluginTag::NOT_JSPLUGIN) {}
780
781 ContentParent(const nsACString& aRemoteType, int32_t aPluginID);
782
783 // Launch the subprocess and associated initialization.
784 // Returns false if the process fails to start.
785 // Deprecated in favor of LaunchSubprocessAsync.
786 bool LaunchSubprocessSync(hal::ProcessPriority aInitialPriority);
787
788 // Launch the subprocess and associated initialization;
789 // returns a promise and signals failure by rejecting.
790 // OS-level launching work is dispatched to another thread, but some
791 // initialization (creating IPDL actors, etc.; see Init()) is run on
792 // the main thread.
793 RefPtr<LaunchPromise> LaunchSubprocessAsync(
794 hal::ProcessPriority aInitialPriority);
795
796 // Common implementation of LaunchSubprocess{Sync,Async}.
797 // Return `true` in case of success, `false` if launch was
798 // aborted because of shutdown.
799 bool BeginSubprocessLaunch(ProcessPriority aPriority);
800 void LaunchSubprocessReject();
801 bool LaunchSubprocessResolve(bool aIsSync, ProcessPriority aPriority);
802
803 // Common initialization after sub process launch.
804 bool InitInternal(ProcessPriority aPriority);
805
806 // Generate a minidump for the child process and one for the main process
807 void GeneratePairedMinidump(const char* aReason);
808 void HandleOrphanedMinidump(nsString* aDumpId);
809
810 virtual ~ContentParent();
811
812 void Init();
813
814 // Some information could be sent to content very early, it
815 // should be send from this function. This function should only be
816 // called after the process has been transformed to browser.
817 void ForwardKnownInfo();
818
819 /**
820 * We might want to reuse barely used content processes if certain criteria
821 * are met.
822 */
823 bool TryToRecycle();
824
825 /**
826 * If this process is currently being recycled, unmark it as the recycled
827 * content process.
828 * If `aForeground` is true, will also restore the process' foreground
829 * priority if it was previously the recycled content process.
830 */
831 void StopRecycling(bool aForeground = true);
832
833 /**
834 * Removing it from the static array so it won't be returned for new tabs in
835 * GetNewOrUsedBrowserProcess.
836 */
837 void RemoveFromList();
838
839 /**
840 * Return if the process has an active worker or JSPlugin
841 */
842 bool HasActiveWorkerOrJSPlugin();
843
844 /**
845 * Decide whether the process should be kept alive even when it would normally
846 * be shut down, for example when all its tabs are closed.
847 */
848 bool ShouldKeepProcessAlive();
849
850 /**
851 * Mark this ContentParent as dead for the purposes of Get*().
852 * This method is idempotent.
853 */
854 void MarkAsDead();
855
856 /**
857 * Check if this process is ready to be shut down, and if it is, begin the
858 * shutdown process. Should be called whenever a change occurs which could
859 * cause the decisions made by `ShouldKeepProcessAlive` to change.
860 *
861 * @param aExpectedBrowserCount The number of PBrowser actors which should
862 * not block shutdown. This should usually be 0.
863 * @param aSendShutDown If true, will send the shutdown message in addition
864 * to marking the process as dead and starting the force
865 * kill timer.
866 */
867 void MaybeBeginShutDown(uint32_t aExpectedBrowserCount = 0,
868 bool aSendShutDown = true);
869
870 /**
871 * How we will shut down this ContentParent and its subprocess.
872 */
873 enum ShutDownMethod {
874 // Send a shutdown message and wait for FinishShutdown call back.
875 SEND_SHUTDOWN_MESSAGE,
876 // Close the channel ourselves and let the subprocess clean up itself.
877 CLOSE_CHANNEL,
878 // Close the channel with error and let the subprocess clean up itself.
879 CLOSE_CHANNEL_WITH_ERROR,
880 };
881
882 void MaybeAsyncSendShutDownMessage();
883
884 /**
885 * Exit the subprocess and vamoose. After this call IsAlive()
886 * will return false and this ContentParent will not be returned
887 * by the Get*() funtions. However, the shutdown sequence itself
888 * may be asynchronous.
889 *
890 * If aMethod is CLOSE_CHANNEL_WITH_ERROR and this is the first call
891 * to ShutDownProcess, then we'll close our channel using CloseWithError()
892 * rather than vanilla Close(). CloseWithError() indicates to IPC that this
893 * is an abnormal shutdown (e.g. a crash).
894 */
895 void ShutDownProcess(ShutDownMethod aMethod);
896
897 // Perform any steps necesssary to gracefully shtudown the message
898 // manager and null out mMessageManager.
899 void ShutDownMessageManager();
900
901 // Start the force-kill timer on shutdown.
902 void StartForceKillTimer();
903
904 // Ensure that the permissions for the giben Permission key are set in the
905 // content process.
906 //
907 // See nsIPermissionManager::GetPermissionsForKey for more information on
908 // these keys.
909 void EnsurePermissionsByKey(const nsCString& aKey, const nsCString& aOrigin);
910
911 static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
912
913 bool CanOpenBrowser(const IPCTabContext& aContext);
914
915 /**
916 * Get or create the corresponding content parent array to
917 * |aContentProcessType|.
918 */
919 static nsTArray<ContentParent*>& GetOrCreatePool(
920 const nsACString& aContentProcessType);
921
922 mozilla::ipc::IPCResult RecvInitBackground(
923 Endpoint<mozilla::ipc::PBackgroundParent>&& aEndpoint);
924
925 mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport);
926 mozilla::ipc::IPCResult RecvAddPerformanceMetrics(
927 const nsID& aID, nsTArray<PerformanceInfo>&& aMetrics);
928
929 bool DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent*);
930
931 mozilla::ipc::IPCResult RecvCloneDocumentTreeInto(
932 const MaybeDiscarded<BrowsingContext>& aSource,
933 const MaybeDiscarded<BrowsingContext>& aTarget, PrintData&& aPrintData);
934
935 mozilla::ipc::IPCResult RecvUpdateRemotePrintSettings(
936 const MaybeDiscarded<BrowsingContext>& aTarget, PrintData&& aPrintData);
937
938 mozilla::ipc::IPCResult RecvConstructPopupBrowser(
939 ManagedEndpoint<PBrowserParent>&& actor,
940 ManagedEndpoint<PWindowGlobalParent>&& windowEp, const TabId& tabId,
941 const IPCTabContext& context, const WindowGlobalInit& initialWindowInit,
942 const uint32_t& chromeFlags);
943
944 mozilla::ipc::IPCResult RecvIsSecureURI(
945 nsIURI* aURI, const uint32_t& aFlags,
946 const OriginAttributes& aOriginAttributes, bool* aIsSecureURI);
947
948 mozilla::ipc::IPCResult RecvAccumulateMixedContentHSTS(
949 nsIURI* aURI, const bool& aActive,
950 const OriginAttributes& aOriginAttributes);
951
952 bool DeallocPHalParent(PHalParent*);
953
954 bool DeallocPHeapSnapshotTempFileHelperParent(
955 PHeapSnapshotTempFileHelperParent*);
956
957 PCycleCollectWithLogsParent* AllocPCycleCollectWithLogsParent(
958 const bool& aDumpAllTraces, const FileDescriptor& aGCLog,
959 const FileDescriptor& aCCLog);
960
961 bool DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent* aActor);
962
963 PTestShellParent* AllocPTestShellParent();
964
965 bool DeallocPTestShellParent(PTestShellParent* shell);
966
967 PScriptCacheParent* AllocPScriptCacheParent(const FileDescOrError& cacheFile,
968 const bool& wantCacheData);
969
970 bool DeallocPScriptCacheParent(PScriptCacheParent* shell);
971
972 bool DeallocPNeckoParent(PNeckoParent* necko);
973
974 already_AddRefed<PExternalHelperAppParent> AllocPExternalHelperAppParent(
975 nsIURI* aUri, const Maybe<mozilla::net::LoadInfoArgs>& aLoadInfoArgs,
976 const nsCString& aMimeContentType, const nsCString& aContentDisposition,
977 const uint32_t& aContentDispositionHint,
978 const nsString& aContentDispositionFilename, const bool& aForceSave,
979 const int64_t& aContentLength, const bool& aWasFileChannel,
980 nsIURI* aReferrer, const MaybeDiscarded<BrowsingContext>& aContext,
981 const bool& aShouldCloseWindow);
982
983 mozilla::ipc::IPCResult RecvPExternalHelperAppConstructor(
984 PExternalHelperAppParent* actor, nsIURI* uri,
985 const Maybe<LoadInfoArgs>& loadInfoArgs,
986 const nsCString& aMimeContentType, const nsCString& aContentDisposition,
987 const uint32_t& aContentDispositionHint,
988 const nsString& aContentDispositionFilename, const bool& aForceSave,
989 const int64_t& aContentLength, const bool& aWasFileChannel,
990 nsIURI* aReferrer, const MaybeDiscarded<BrowsingContext>& aContext,
991 const bool& aShouldCloseWindow) override;
992
993 already_AddRefed<PHandlerServiceParent> AllocPHandlerServiceParent();
994
995 PMediaParent* AllocPMediaParent();
996
997 bool DeallocPMediaParent(PMediaParent* aActor);
998
999 PBenchmarkStorageParent* AllocPBenchmarkStorageParent();
1000
1001 bool DeallocPBenchmarkStorageParent(PBenchmarkStorageParent* aActor);
1002
1003 #ifdef MOZ_WEBSPEECH
1004 PSpeechSynthesisParent* AllocPSpeechSynthesisParent();
1005 bool DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor);
1006
1007 virtual mozilla::ipc::IPCResult RecvPSpeechSynthesisConstructor(
1008 PSpeechSynthesisParent* aActor) override;
1009 #endif
1010
1011 PWebBrowserPersistDocumentParent* AllocPWebBrowserPersistDocumentParent(
1012 PBrowserParent* aBrowser,
1013 const MaybeDiscarded<BrowsingContext>& aContext);
1014
1015 bool DeallocPWebBrowserPersistDocumentParent(
1016 PWebBrowserPersistDocumentParent* aActor);
1017
1018 mozilla::ipc::IPCResult RecvGetGfxVars(nsTArray<GfxVarUpdate>* aVars);
1019
1020 mozilla::ipc::IPCResult RecvSetClipboard(
1021 const IPCDataTransfer& aDataTransfer, const bool& aIsPrivateData,
1022 const IPC::Principal& aRequestingPrincipal,
1023 const nsContentPolicyType& aContentPolicyType,
1024 const int32_t& aWhichClipboard);
1025
1026 mozilla::ipc::IPCResult RecvGetClipboard(nsTArray<nsCString>&& aTypes,
1027 const int32_t& aWhichClipboard,
1028 IPCDataTransfer* aDataTransfer);
1029
1030 mozilla::ipc::IPCResult RecvEmptyClipboard(const int32_t& aWhichClipboard);
1031
1032 mozilla::ipc::IPCResult RecvClipboardHasType(nsTArray<nsCString>&& aTypes,
1033 const int32_t& aWhichClipboard,
1034 bool* aHasType);
1035
1036 mozilla::ipc::IPCResult RecvGetExternalClipboardFormats(
1037 const int32_t& aWhichClipboard, const bool& aPlainTextOnly,
1038 nsTArray<nsCString>* aTypes);
1039
1040 mozilla::ipc::IPCResult RecvPlaySound(nsIURI* aURI);
1041 mozilla::ipc::IPCResult RecvBeep();
1042 mozilla::ipc::IPCResult RecvPlayEventSound(const uint32_t& aEventId);
1043
1044 mozilla::ipc::IPCResult RecvGetIconForExtension(const nsCString& aFileExt,
1045 const uint32_t& aIconSize,
1046 nsTArray<uint8_t>* bits);
1047
1048 mozilla::ipc::IPCResult RecvStartVisitedQueries(
1049 const nsTArray<RefPtr<nsIURI>>&);
1050
1051 mozilla::ipc::IPCResult RecvSetURITitle(nsIURI* uri, const nsString& title);
1052
1053 mozilla::ipc::IPCResult RecvShowAlert(nsIAlertNotification* aAlert);
1054
1055 mozilla::ipc::IPCResult RecvCloseAlert(const nsString& aName);
1056
1057 mozilla::ipc::IPCResult RecvDisableNotifications(
1058 const IPC::Principal& aPrincipal);
1059
1060 mozilla::ipc::IPCResult RecvOpenNotificationSettings(
1061 const IPC::Principal& aPrincipal);
1062
1063 mozilla::ipc::IPCResult RecvNotificationEvent(
1064 const nsString& aType, const NotificationEventData& aData);
1065
1066 mozilla::ipc::IPCResult RecvLoadURIExternal(
1067 nsIURI* uri, nsIPrincipal* triggeringPrincipal,
1068 nsIPrincipal* redirectPrincipal,
1069 const MaybeDiscarded<BrowsingContext>& aContext,
1070 bool aWasExternallyTriggered);
1071 mozilla::ipc::IPCResult RecvExtProtocolChannelConnectParent(
1072 const uint64_t& registrarId);
1073
1074 mozilla::ipc::IPCResult RecvSyncMessage(
1075 const nsString& aMsg, const ClonedMessageData& aData,
1076 nsTArray<StructuredCloneData>* aRetvals);
1077
1078 mozilla::ipc::IPCResult RecvAsyncMessage(const nsString& aMsg,
1079 const ClonedMessageData& aData);
1080
1081 // MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
1082 // in IPC code yet.
1083 MOZ_CAN_RUN_SCRIPT_BOUNDARY
1084 mozilla::ipc::IPCResult RecvAddGeolocationListener(const bool& aHighAccuracy);
1085 mozilla::ipc::IPCResult RecvRemoveGeolocationListener();
1086
1087 // MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
1088 // in IPC code yet.
1089 MOZ_CAN_RUN_SCRIPT_BOUNDARY
1090 mozilla::ipc::IPCResult RecvSetGeolocationHigherAccuracy(const bool& aEnable);
1091
1092 mozilla::ipc::IPCResult RecvConsoleMessage(const nsString& aMessage);
1093
1094 mozilla::ipc::IPCResult RecvScriptError(
1095 const nsString& aMessage, const nsString& aSourceName,
1096 const nsString& aSourceLine, const uint32_t& aLineNumber,
1097 const uint32_t& aColNumber, const uint32_t& aFlags,
1098 const nsCString& aCategory, const bool& aIsFromPrivateWindow,
1099 const uint64_t& aInnerWindowId, const bool& aIsFromChromeContext);
1100
1101 mozilla::ipc::IPCResult RecvReportFrameTimingData(
1102 uint64_t innerWindowId, const nsString& entryName,
1103 const nsString& initiatorType, UniquePtr<PerformanceTimingData>&& aData);
1104
1105 mozilla::ipc::IPCResult RecvScriptErrorWithStack(
1106 const nsString& aMessage, const nsString& aSourceName,
1107 const nsString& aSourceLine, const uint32_t& aLineNumber,
1108 const uint32_t& aColNumber, const uint32_t& aFlags,
1109 const nsCString& aCategory, const bool& aIsFromPrivateWindow,
1110 const bool& aIsFromChromeContext, const ClonedMessageData& aStack);
1111
1112 private:
1113 mozilla::ipc::IPCResult RecvScriptErrorInternal(
1114 const nsString& aMessage, const nsString& aSourceName,
1115 const nsString& aSourceLine, const uint32_t& aLineNumber,
1116 const uint32_t& aColNumber, const uint32_t& aFlags,
1117 const nsCString& aCategory, const bool& aIsFromPrivateWindow,
1118 const bool& aIsFromChromeContext,
1119 const ClonedMessageData* aStack = nullptr);
1120
1121 public:
1122 mozilla::ipc::IPCResult RecvCommitBrowsingContextTransaction(
1123 const MaybeDiscarded<BrowsingContext>& aContext,
1124 BrowsingContext::BaseTransaction&& aTransaction, uint64_t aEpoch);
1125
1126 mozilla::ipc::IPCResult RecvCommitWindowContextTransaction(
1127 const MaybeDiscarded<WindowContext>& aContext,
1128 WindowContext::BaseTransaction&& aTransaction, uint64_t aEpoch);
1129
1130 mozilla::ipc::IPCResult RecvAddSecurityState(
1131 const MaybeDiscarded<WindowContext>& aContext, uint32_t aStateFlags);
1132
1133 mozilla::ipc::IPCResult RecvFirstIdle();
1134
1135 mozilla::ipc::IPCResult RecvDeviceReset();
1136
1137 mozilla::ipc::IPCResult RecvCopyFavicon(nsIURI* aOldURI, nsIURI* aNewURI,
1138 const bool& aInPrivateBrowsing);
1139
1140 virtual void ProcessingError(Result aCode, const char* aMsgName) override;
1141
1142 mozilla::ipc::IPCResult RecvGraphicsError(const nsCString& aError);
1143
1144 mozilla::ipc::IPCResult RecvBeginDriverCrashGuard(const uint32_t& aGuardType,
1145 bool* aOutCrashed);
1146
1147 mozilla::ipc::IPCResult RecvEndDriverCrashGuard(const uint32_t& aGuardType);
1148
1149 mozilla::ipc::IPCResult RecvAddIdleObserver(const uint64_t& observerId,
1150 const uint32_t& aIdleTimeInS);
1151
1152 mozilla::ipc::IPCResult RecvRemoveIdleObserver(const uint64_t& observerId,
1153 const uint32_t& aIdleTimeInS);
1154
1155 mozilla::ipc::IPCResult RecvBackUpXResources(
1156 const FileDescriptor& aXSocketFd);
1157
1158 mozilla::ipc::IPCResult RecvRequestAnonymousTemporaryFile(
1159 const uint64_t& aID);
1160
1161 mozilla::ipc::IPCResult RecvCreateAudioIPCConnection(
1162 CreateAudioIPCConnectionResolver&& aResolver);
1163
1164 already_AddRefed<extensions::PExtensionsParent> AllocPExtensionsParent();
1165
1166 PFileDescriptorSetParent* AllocPFileDescriptorSetParent(
1167 const mozilla::ipc::FileDescriptor&);
1168
1169 bool DeallocPFileDescriptorSetParent(PFileDescriptorSetParent*);
1170
1171 PWebrtcGlobalParent* AllocPWebrtcGlobalParent();
1172 bool DeallocPWebrtcGlobalParent(PWebrtcGlobalParent* aActor);
1173
1174 mozilla::ipc::IPCResult RecvUpdateDropEffect(const uint32_t& aDragAction,
1175 const uint32_t& aDropEffect);
1176
1177 mozilla::ipc::IPCResult RecvShutdownProfile(const nsCString& aProfile);
1178
1179 mozilla::ipc::IPCResult RecvGetGraphicsDeviceInitData(
1180 ContentDeviceData* aOut);
1181
1182 mozilla::ipc::IPCResult RecvGetOutputColorProfileData(
1183 nsTArray<uint8_t>* aOutputColorProfileData);
1184
1185 mozilla::ipc::IPCResult RecvGetFontListShmBlock(
1186 const uint32_t& aGeneration, const uint32_t& aIndex,
1187 base::SharedMemoryHandle* aOut);
1188
1189 mozilla::ipc::IPCResult RecvInitializeFamily(const uint32_t& aGeneration,
1190 const uint32_t& aFamilyIndex,
1191 const bool& aLoadCmaps);
1192
1193 mozilla::ipc::IPCResult RecvSetCharacterMap(
1194 const uint32_t& aGeneration, const mozilla::fontlist::Pointer& aFacePtr,
1195 const gfxSparseBitSet& aMap);
1196
1197 mozilla::ipc::IPCResult RecvInitOtherFamilyNames(const uint32_t& aGeneration,
1198 const bool& aDefer,
1199 bool* aLoaded);
1200
1201 mozilla::ipc::IPCResult RecvSetupFamilyCharMap(
1202 const uint32_t& aGeneration,
1203 const mozilla::fontlist::Pointer& aFamilyPtr);
1204
1205 mozilla::ipc::IPCResult RecvStartCmapLoading(const uint32_t& aGeneration,
1206 const uint32_t& aStartIndex);
1207
1208 mozilla::ipc::IPCResult RecvGetHyphDict(nsIURI* aURIParams,
1209 base::SharedMemoryHandle* aOutHandle,
1210 uint32_t* aOutSize);
1211
1212 mozilla::ipc::IPCResult RecvNotifyBenchmarkResult(const nsString& aCodecName,
1213 const uint32_t& aDecodeFPS);
1214
1215 mozilla::ipc::IPCResult RecvNotifyPushObservers(
1216 const nsCString& aScope, const IPC::Principal& aPrincipal,
1217 const nsString& aMessageId);
1218
1219 mozilla::ipc::IPCResult RecvNotifyPushObserversWithData(
1220 const nsCString& aScope, const IPC::Principal& aPrincipal,
1221 const nsString& aMessageId, nsTArray<uint8_t>&& aData);
1222
1223 mozilla::ipc::IPCResult RecvNotifyPushSubscriptionChangeObservers(
1224 const nsCString& aScope, const IPC::Principal& aPrincipal);
1225
1226 mozilla::ipc::IPCResult RecvPushError(const nsCString& aScope,
1227 const IPC::Principal& aPrincipal,
1228 const nsString& aMessage,
1229 const uint32_t& aFlags);
1230
1231 mozilla::ipc::IPCResult RecvNotifyPushSubscriptionModifiedObservers(
1232 const nsCString& aScope, const IPC::Principal& aPrincipal);
1233
1234 mozilla::ipc::IPCResult RecvGetFilesRequest(const nsID& aID,
1235 const nsString& aDirectoryPath,
1236 const bool& aRecursiveFlag);
1237
1238 mozilla::ipc::IPCResult RecvDeleteGetFilesRequest(const nsID& aID);
1239
1240 mozilla::ipc::IPCResult RecvAccumulateChildHistograms(
1241 nsTArray<HistogramAccumulation>&& aAccumulations);
1242 mozilla::ipc::IPCResult RecvAccumulateChildKeyedHistograms(
1243 nsTArray<KeyedHistogramAccumulation>&& aAccumulations);
1244 mozilla::ipc::IPCResult RecvUpdateChildScalars(
1245 nsTArray<ScalarAction>&& aScalarActions);
1246 mozilla::ipc::IPCResult RecvUpdateChildKeyedScalars(
1247 nsTArray<KeyedScalarAction>&& aScalarActions);
1248 mozilla::ipc::IPCResult RecvRecordChildEvents(
1249 nsTArray<ChildEventData>&& events);
1250 mozilla::ipc::IPCResult RecvRecordDiscardedData(
1251 const DiscardedData& aDiscardedData);
1252 mozilla::ipc::IPCResult RecvRecordOrigin(const uint32_t& aMetricId,
1253 const nsCString& aOrigin);
1254 mozilla::ipc::IPCResult RecvReportContentBlockingLog(
1255 const IPCStream& aIPCStream);
1256
1257 mozilla::ipc::IPCResult RecvBHRThreadHang(const HangDetails& aHangDetails);
1258
1259 mozilla::ipc::IPCResult RecvAddCertException(
1260 const nsACString& aSerializedCert, uint32_t aFlags,
1261 const nsACString& aHostName, int32_t aPort,
1262 const OriginAttributes& aOriginAttributes, bool aIsTemporary,
1263 AddCertExceptionResolver&& aResolver);
1264
1265 mozilla::ipc::IPCResult RecvAutomaticStorageAccessPermissionCanBeGranted(
1266 const Principal& aPrincipal,
1267 AutomaticStorageAccessPermissionCanBeGrantedResolver&& aResolver);
1268
1269 mozilla::ipc::IPCResult RecvStorageAccessPermissionGrantedForOrigin(
1270 uint64_t aTopLevelWindowId,
1271 const MaybeDiscarded<BrowsingContext>& aParentContext,
1272 const Principal& aTrackingPrincipal, const nsCString& aTrackingOrigin,
1273 const int& aAllowMode,
1274 const Maybe<
1275 ContentBlockingNotifier::StorageAccessPermissionGrantedReason>&
1276 aReason,
1277 StorageAccessPermissionGrantedForOriginResolver&& aResolver);
1278
1279 mozilla::ipc::IPCResult RecvCompleteAllowAccessFor(
1280 const MaybeDiscarded<BrowsingContext>& aParentContext,
1281 uint64_t aTopLevelWindowId, const Principal& aTrackingPrincipal,
1282 const nsCString& aTrackingOrigin, uint32_t aCookieBehavior,
1283 const ContentBlockingNotifier::StorageAccessPermissionGrantedReason&
1284 aReason,
1285 CompleteAllowAccessForResolver&& aResolver);
1286
1287 mozilla::ipc::IPCResult RecvStoreUserInteractionAsPermission(
1288 const Principal& aPrincipal);
1289
1290 mozilla::ipc::IPCResult RecvNotifyMediaPlaybackChanged(
1291 const MaybeDiscarded<BrowsingContext>& aContext,
1292 MediaPlaybackState aState);
1293
1294 mozilla::ipc::IPCResult RecvNotifyMediaAudibleChanged(
1295 const MaybeDiscarded<BrowsingContext>& aContext,
1296 MediaAudibleState aState);
1297
1298 mozilla::ipc::IPCResult RecvNotifyPictureInPictureModeChanged(
1299 const MaybeDiscarded<BrowsingContext>& aContext, bool aEnabled);
1300
1301 mozilla::ipc::IPCResult RecvNotifyMediaSessionUpdated(
1302 const MaybeDiscarded<BrowsingContext>& aContext, bool aIsCreated);
1303
1304 mozilla::ipc::IPCResult RecvNotifyUpdateMediaMetadata(
1305 const MaybeDiscarded<BrowsingContext>& aContext,
1306 const Maybe<MediaMetadataBase>& aMetadata);
1307
1308 mozilla::ipc::IPCResult RecvNotifyMediaSessionPlaybackStateChanged(
1309 const MaybeDiscarded<BrowsingContext>& aContext,
1310 MediaSessionPlaybackState aPlaybackState);
1311
1312 mozilla::ipc::IPCResult RecvNotifyMediaSessionSupportedActionChanged(
1313 const MaybeDiscarded<BrowsingContext>& aContext,
1314 MediaSessionAction aAction, bool aEnabled);
1315
1316 mozilla::ipc::IPCResult RecvNotifyMediaFullScreenState(
1317 const MaybeDiscarded<BrowsingContext>& aContext, bool aIsInFullScreen);
1318
1319 mozilla::ipc::IPCResult RecvNotifyPositionStateChanged(
1320 const MaybeDiscarded<BrowsingContext>& aContext,
1321 const PositionState& aState);
1322
1323 mozilla::ipc::IPCResult RecvGetModulesTrust(
1324 ModulePaths&& aModPaths, bool aRunAtNormalPriority,
1325 GetModulesTrustResolver&& aResolver);
1326
1327 mozilla::ipc::IPCResult RecvReportServiceWorkerShutdownProgress(
1328 uint32_t aShutdownStateId,
1329 ServiceWorkerShutdownState::Progress aProgress);
1330
1331 mozilla::ipc::IPCResult RecvRawMessage(
1332 const JSActorMessageMeta& aMeta, const Maybe<ClonedMessageData>& aData,
1333 const Maybe<ClonedMessageData>& aStack);
1334
1335 mozilla::ipc::IPCResult RecvAbortOtherOrientationPendingPromises(
1336 const MaybeDiscarded<BrowsingContext>& aContext);
1337
1338 mozilla::ipc::IPCResult RecvNotifyOnHistoryReload(
1339 const MaybeDiscarded<BrowsingContext>& aContext, const bool& aForceReload,
1340 NotifyOnHistoryReloadResolver&& aResolver);
1341
1342 mozilla::ipc::IPCResult RecvHistoryCommit(
1343 const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID,
1344 const nsID& aChangeID, const uint32_t& aLoadType, const bool& aPersist,
1345 const bool& aCloneEntryChildren);
1346
1347 mozilla::ipc::IPCResult RecvHistoryGo(
1348 const MaybeDiscarded<BrowsingContext>& aContext, int32_t aOffset,
1349 uint64_t aHistoryEpoch, bool aRequireUserInteraction,
1350 bool aUserActivation, HistoryGoResolver&& aResolveRequestedIndex);
1351
1352 mozilla::ipc::IPCResult RecvSynchronizeLayoutHistoryState(
1353 const MaybeDiscarded<BrowsingContext>& aContext,
1354 nsILayoutHistoryState* aState);
1355
1356 mozilla::ipc::IPCResult RecvSessionHistoryEntryTitle(
1357 const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aTitle);
1358
1359 mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollRestorationIsManual(
1360 const MaybeDiscarded<BrowsingContext>& aContext, const bool& aIsManual);
1361
1362 mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollPosition(
1363 const MaybeDiscarded<BrowsingContext>& aContext, const int32_t& aX,
1364 const int32_t& aY);
1365
1366 mozilla::ipc::IPCResult RecvSessionHistoryEntryCacheKey(
1367 const MaybeDiscarded<BrowsingContext>& aContext,
1368 const uint32_t& aCacheKey);
1369
1370 mozilla::ipc::IPCResult
1371 RecvSessionHistoryEntryStoreWindowNameInContiguousEntries(
1372 const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aName);
1373
1374 mozilla::ipc::IPCResult RecvGetLoadingSessionHistoryInfoFromParent(
1375 const MaybeDiscarded<BrowsingContext>& aContext,
1376 GetLoadingSessionHistoryInfoFromParentResolver&& aResolver);
1377
1378 mozilla::ipc::IPCResult RecvRemoveFromBFCache(
1379 const MaybeDiscarded<BrowsingContext>& aContext);
1380
1381 mozilla::ipc::IPCResult RecvSetActiveSessionHistoryEntry(
1382 const MaybeDiscarded<BrowsingContext>& aContext,
1383 const Maybe<nsPoint>& aPreviousScrollPos, SessionHistoryInfo&& aInfo,
1384 uint32_t aLoadType, uint32_t aUpdatedCacheKey, const nsID& aChangeID);
1385
1386 mozilla::ipc::IPCResult RecvReplaceActiveSessionHistoryEntry(
1387 const MaybeDiscarded<BrowsingContext>& aContext,
1388 SessionHistoryInfo&& aInfo);
1389
1390 mozilla::ipc::IPCResult RecvRemoveDynEntriesFromActiveSessionHistoryEntry(
1391 const MaybeDiscarded<BrowsingContext>& aContext);
1392
1393 mozilla::ipc::IPCResult RecvRemoveFromSessionHistory(
1394 const MaybeDiscarded<BrowsingContext>& aContext, const nsID& aChangeID);
1395
1396 mozilla::ipc::IPCResult RecvHistoryReload(
1397 const MaybeDiscarded<BrowsingContext>& aContext,
1398 const uint32_t aReloadFlags);
1399
1400 // Notify the ContentChild to enable the input event prioritization when
1401 // initializing.
1402 void MaybeEnableRemoteInputEventQueue();
1403
1404 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
1405 void AppendSandboxParams(std::vector<std::string>& aArgs);
1406 void AppendDynamicSandboxParams(std::vector<std::string>& aArgs);
1407 #endif
1408
1409 mozilla::ipc::IPCResult RecvFOGData(ByteBuf&& buf);
1410
1411 mozilla::ipc::IPCResult RecvSetContainerFeaturePolicy(
1412 const MaybeDiscardedBrowsingContext& aContainerContext,
1413 FeaturePolicy* aContainerFeaturePolicy);
1414
1415 mozilla::ipc::IPCResult RecvGetSystemIcon(nsIURI* aURI,
1416 GetSystemIconResolver&& aResolver);
1417
1418 public:
1419 void SendGetFilesResponseAndForget(const nsID& aID,
1420 const GetFilesResponseResult& aResult);
1421
1422 bool SendRequestMemoryReport(const uint32_t& aGeneration,
1423 const bool& aAnonymize,
1424 const bool& aMinimizeMemoryUsage,
1425 const Maybe<FileDescriptor>& aDMDFile) override;
1426
1427 void AddBrowsingContextGroup(BrowsingContextGroup* aGroup);
1428 void RemoveBrowsingContextGroup(BrowsingContextGroup* aGroup);
1429
1430 // See `BrowsingContext::mEpochs` for an explanation of this field.
GetBrowsingContextFieldEpoch()1431 uint64_t GetBrowsingContextFieldEpoch() const {
1432 return mBrowsingContextFieldEpoch;
1433 }
1434
1435 void UpdateNetworkLinkType();
1436
1437 static bool ShouldSyncPreference(const char16_t* aData);
1438
1439 already_AddRefed<JSActor> InitJSActor(JS::HandleObject aMaybeActor,
1440 const nsACString& aName,
1441 ErrorResult& aRv) override;
AsNativeActor()1442 mozilla::ipc::IProtocol* AsNativeActor() override { return this; }
1443
1444 private:
1445 // Return an existing ContentParent if possible. Otherwise, `nullptr`.
1446 static already_AddRefed<ContentParent> GetUsedBrowserProcess(
1447 const nsACString& aRemoteType, nsTArray<ContentParent*>& aContentParents,
1448 uint32_t aMaxContentParents, bool aPreferUsed);
1449
1450 void AddToPool(nsTArray<ContentParent*>&);
1451 void RemoveFromPool(nsTArray<ContentParent*>&);
1452 void AssertNotInPool();
1453
1454 void AssertAlive();
1455
1456 /**
1457 * Called when a subprocess succesfully launches.
1458 *
1459 * May submit telemetry if the new number of content processes is greater
1460 * than the previous maximum.
1461 *
1462 * This will submit telemetry about the time delta between this content
1463 * process launch and the last content process launch.
1464 */
1465 static void DidLaunchSubprocess();
1466
1467 private:
1468 // Released in ActorDealloc; deliberately not exposed to the CC.
1469 RefPtr<ContentParent> mSelfRef;
1470
1471 // If you add strong pointers to cycle collected objects here, be sure to
1472 // release these objects in ShutDownProcess. See the comment there for more
1473 // details.
1474
1475 GeckoChildProcessHost* mSubprocess;
1476 const TimeStamp mLaunchTS; // used to calculate time to start content process
1477 TimeStamp mLaunchYieldTS; // used to calculate async launch main thread time
1478 TimeStamp mActivateTS;
1479
1480 bool mIsAPreallocBlocker; // We called AddBlocker for this ContentParent
1481
1482 nsCString mRemoteType;
1483 nsCOMPtr<nsIPrincipal> mRemoteTypeIsolationPrincipal;
1484
1485 ContentParentId mChildID;
1486 int32_t mGeolocationWatchID;
1487
1488 // This contains the id for the JS plugin (@see nsFakePluginTag) if this is
1489 // the ContentParent for a process containing iframes for that JS plugin. If
1490 // this is not a ContentParent for a JS plugin then it contains the value
1491 // nsFakePluginTag::NOT_JSPLUGIN.
1492 int32_t mJSPluginID;
1493
1494 // After we initiate shutdown, we also start a timer to ensure
1495 // that even content processes that are 100% blocked (say from
1496 // SIGSTOP), are still killed eventually. This task enforces that
1497 // timer.
1498 nsCOMPtr<nsITimer> mForceKillTimer;
1499
1500 // `mCount` is increased when a RemoteWorkerParent actor is created for this
1501 // ContentProcess and it is decreased when the actor is destroyed.
1502 //
1503 // `mShutdownStarted` is flipped to `true` when a runnable that calls
1504 // `ShutDownProcess` is dispatched; it's needed because the corresponding
1505 // Content Process may be shutdown if there's no remote worker actors, and
1506 // decrementing `mCount` and the call to `ShutDownProcess` are async. So,
1507 // when a worker is going to be spawned and we see that `mCount` is 0,
1508 // we can decide whether or not to use that process based on the value of
1509 // `mShutdownStarted.`
1510 //
1511 // It's touched on PBackground thread and on main-thread.
1512 struct RemoteWorkerActorData {
1513 uint32_t mCount = 0;
1514 bool mShutdownStarted = false;
1515 };
1516
1517 DataMutex<RemoteWorkerActorData> mRemoteWorkerActorData;
1518
1519 // How many tabs we're waiting to finish their destruction
1520 // sequence. Precisely, how many BrowserParents have called
1521 // NotifyTabDestroying() but not called NotifyTabDestroyed().
1522 int32_t mNumDestroyingTabs;
1523
1524 uint32_t mNumKeepaliveCalls;
1525
1526 // The process starts in the LAUNCHING state, and transitions to
1527 // ALIVE once it can accept IPC messages. It remains ALIVE only
1528 // while remote content is being actively used from this process.
1529 // After the state becaomes DEAD, some previously scheduled IPC
1530 // traffic may still pass through.
1531 enum class LifecycleState : uint8_t {
1532 LAUNCHING,
1533 ALIVE,
1534 INITIALIZED,
1535 DEAD,
1536 };
1537
1538 LifecycleState mLifecycleState;
1539
1540 uint8_t mIsForBrowser : 1;
1541
1542 // These variables track whether we've called Close() and KillHard() on our
1543 // channel.
1544 uint8_t mCalledClose : 1;
1545 uint8_t mCalledKillHard : 1;
1546 uint8_t mCreatedPairedMinidumps : 1;
1547 uint8_t mShutdownPending : 1;
1548 uint8_t mLaunchResolved : 1;
1549
1550 // True if the input event queue on the main thread of the content process is
1551 // enabled.
1552 uint8_t mIsRemoteInputEventQueueEnabled : 1;
1553
1554 // True if we send input events with input priority. Otherwise, we send input
1555 // events with normal priority.
1556 uint8_t mIsInputPriorityEventEnabled : 1;
1557
1558 uint8_t mIsInPool : 1;
1559
1560 RefPtr<nsConsoleService> mConsoleService;
1561 nsConsoleService* GetConsoleService();
1562 nsCOMPtr<nsIContentProcessInfo> mScriptableHelper;
1563
1564 nsTArray<nsCOMPtr<nsIObserver>> mIdleListeners;
1565
1566 #ifdef MOZ_X11
1567 // Dup of child's X socket, used to scope its resources to this
1568 // object instead of the child process's lifetime.
1569 ScopedClose mChildXSocketFdDup;
1570 #endif
1571
1572 PProcessHangMonitorParent* mHangMonitorActor;
1573
1574 UniquePtr<gfx::DriverCrashGuard> mDriverCrashGuard;
1575 UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
1576
1577 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
1578 mozilla::UniquePtr<SandboxBroker> mSandboxBroker;
1579 static mozilla::UniquePtr<SandboxBrokerPolicyFactory>
1580 sSandboxBrokerPolicyFactory;
1581 #endif
1582
1583 #ifdef NS_PRINTING
1584 RefPtr<embedding::PrintingParent> mPrintingParent;
1585 #endif
1586
1587 // This hashtable is used to run GetFilesHelper objects in the parent process.
1588 // GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest.
1589 nsRefPtrHashtable<nsIDHashKey, GetFilesHelper> mGetFilesPendingRequests;
1590
1591 nsTHashSet<nsCString> mActivePermissionKeys;
1592
1593 nsTArray<nsCString> mBlobURLs;
1594
1595 // This is intended to be a memory and time efficient means of determining
1596 // whether an origin has ever existed in a process so that Blob URL broadcast
1597 // doesn't need to transmit every Blob URL to every content process. False
1598 // positives are acceptable because receiving a Blob URL does not grant access
1599 // to its contents, and the act of creating/revoking a Blob is currently
1600 // viewed as an acceptable side-channel leak. In the future bug 1491018 will
1601 // moot the need for this structure.
1602 nsTArray<uint64_t> mLoadedOriginHashes;
1603
1604 UniquePtr<mozilla::ipc::CrashReporterHost> mCrashReporter;
1605
1606 // Collects any pref changes that occur during process launch (after
1607 // the initial map is passed in command-line arguments) to be sent
1608 // when the process can receive IPC messages.
1609 nsTArray<Pref> mQueuedPrefs;
1610
1611 RefPtr<mozilla::dom::ProcessMessageManager> mMessageManager;
1612
1613 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
1614 // When set to true, indicates that content processes should
1615 // initialize their sandbox during startup instead of waiting
1616 // for the SetProcessSandbox IPDL message.
1617 static bool sEarlySandboxInit;
1618 #endif
1619
1620 nsTHashSet<RefPtr<BrowsingContextGroup>> mGroups;
1621
1622 // See `BrowsingContext::mEpochs` for an explanation of this field.
1623 uint64_t mBrowsingContextFieldEpoch = 0;
1624
1625 // A preference serializer used to share preferences with the process.
1626 // Cleared once startup is complete.
1627 UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
1628
1629 static uint32_t sMaxContentProcesses;
1630 static Maybe<TimeStamp> sLastContentProcessLaunch;
1631 };
1632
1633 NS_DEFINE_STATIC_IID_ACCESSOR(ContentParent, NS_CONTENTPARENT_IID)
1634
1635 // This is the C++ version of remoteTypePrefix in E10SUtils.jsm.
1636 const nsDependentCSubstring RemoteTypePrefix(
1637 const nsACString& aContentProcessType);
1638
1639 // This is based on isWebRemoteType in E10SUtils.jsm.
1640 bool IsWebRemoteType(const nsACString& aContentProcessType);
1641
1642 bool IsWebCoopCoepRemoteType(const nsACString& aContentProcessType);
1643
1644 bool IsPrivilegedMozillaRemoteType(const nsACString& aContentProcessType);
1645
1646 bool IsExtensionRemoteType(const nsACString& aContentProcessType);
1647
ToSupports(mozilla::dom::ContentParent * aContentParent)1648 inline nsISupports* ToSupports(mozilla::dom::ContentParent* aContentParent) {
1649 return static_cast<nsIDOMProcessParent*>(aContentParent);
1650 }
1651
1652 } // namespace dom
1653 } // namespace mozilla
1654
1655 class ParentIdleListener : public nsIObserver {
1656 friend class mozilla::dom::ContentParent;
1657
1658 public:
1659 NS_DECL_ISUPPORTS
1660 NS_DECL_NSIOBSERVER
1661
ParentIdleListener(mozilla::dom::ContentParent * aParent,uint64_t aObserver,uint32_t aTime)1662 ParentIdleListener(mozilla::dom::ContentParent* aParent, uint64_t aObserver,
1663 uint32_t aTime)
1664 : mParent(aParent), mObserver(aObserver), mTime(aTime) {}
1665
1666 private:
1667 virtual ~ParentIdleListener() = default;
1668
1669 RefPtr<mozilla::dom::ContentParent> mParent;
1670 uint64_t mObserver;
1671 uint32_t mTime;
1672 };
1673
1674 #endif // mozilla_dom_ContentParent_h
1675