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/. */
7 #ifndef mozilla_dom_ContentParent_h
8 #define mozilla_dom_ContentParent_h
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/dom/UserActivation.h"
19 #include "mozilla/gfx/gfxVarReceiver.h"
20 #include "mozilla/gfx/GPUProcessListener.h"
21 #include "mozilla/ipc/BackgroundUtils.h"
22 #include "mozilla/ipc/GeckoChildProcessHost.h"
23 #include "mozilla/ipc/InputStreamUtils.h"
24 #include "mozilla/Attributes.h"
25 #include "mozilla/DataMutex.h"
26 #include "mozilla/HalTypes.h"
27 #include "mozilla/LinkedList.h"
28 #include "mozilla/Maybe.h"
29 #include "mozilla/MemoryReportingProcess.h"
30 #include "mozilla/MozPromise.h"
31 #include "mozilla/RecursiveMutex.h"
32 #include "mozilla/StaticPtr.h"
33 #include "mozilla/TimeStamp.h"
34 #include "mozilla/UniquePtr.h"
36 #include "MainThreadUtils.h"
37 #include "nsClassHashtable.h"
38 #include "nsTHashMap.h"
39 #include "nsTHashSet.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"
53 class nsConsoleService
;
54 class nsIContentProcessInfo
;
55 class nsICycleCollectorLogSink
;
56 class nsIDumpGCAndCCLogsCallback
;
59 class ParentIdleListener
;
64 class PClipboardWriteRequestParent
;
65 class PRemoteSpellcheckEngineParent
;
67 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
69 class SandboxBrokerPolicyFactory
;
72 class PreallocatedProcessManagerImpl
;
73 class BenchmarkStorageParent
;
75 using mozilla::loader::PScriptCacheParent
;
78 class CrashReporterHost
;
79 class TestShellParent
;
80 class SharedPreferenceSerializer
;
84 struct TextureFactoryIdentifier
;
89 class BrowsingContextGroup
;
92 class ClonedMessageData
;
96 class MemoryReportRequestHost
;
97 class RemoteWorkerManager
;
98 class ThreadsafeContentParentHandle
;
99 struct CancelContentJSOptions
;
101 #define NS_CONTENTPARENT_IID \
103 0xeeec9ebf, 0x8ecf, 0x4e38, { \
104 0x81, 0xda, 0xb7, 0x34, 0x13, 0x7e, 0xac, 0xf3 \
108 class ContentParent final
: public PContentParent
,
109 public nsIDOMProcessParent
,
111 public nsIDOMGeoPositionCallback
,
112 public nsIDOMGeoPositionErrorCallback
,
113 public nsIAsyncShutdownBlocker
,
114 public nsIInterfaceRequestor
,
115 public gfx::gfxVarReceiver
,
116 public mozilla::LinkedListElement
<ContentParent
>,
117 public gfx::GPUProcessListener
,
118 public mozilla::MemoryReportingProcess
,
119 public mozilla::dom::ipc::MessageManagerCallback
,
120 public mozilla::ipc::IShmemAllocator
,
121 public ProcessActor
{
122 typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost
;
123 typedef mozilla::ipc::TestShellParent TestShellParent
;
124 typedef mozilla::ipc::PrincipalInfo PrincipalInfo
;
125 typedef mozilla::dom::ClonedMessageData ClonedMessageData
;
126 typedef mozilla::dom::BrowsingContextGroup BrowsingContextGroup
;
128 friend class mozilla::PreallocatedProcessManagerImpl
;
129 friend class PContentParent
;
130 friend class mozilla::dom::RemoteWorkerManager
;
133 using LaunchPromise
=
134 mozilla::MozPromise
<RefPtr
<ContentParent
>, nsresult
, false>;
136 NS_DECLARE_STATIC_IID_ACCESSOR(NS_CONTENTPARENT_IID
)
138 static LogModule
* GetLog();
140 static ContentParent
* Cast(PContentParent
* aActor
) {
141 return static_cast<ContentParent
*>(aActor
);
145 * Create a ContentParent suitable for use later as a content process.
147 static already_AddRefed
<ContentParent
> MakePreallocProcess();
150 * Start up the content-process machinery. This might include
151 * scheduling pre-launch tasks.
153 static void StartUp();
155 /** Shut down the content-process machinery. */
156 static void ShutDown();
158 static uint32_t GetPoolSize(const nsACString
& aContentProcessType
);
160 static uint32_t GetMaxProcessCount(const nsACString
& aContentProcessType
);
162 static bool IsMaxProcessCountReached(const nsACString
& aContentProcessType
);
164 static void ReleaseCachedProcesses();
166 static void LogAndAssertFailedPrincipalValidationInfo(
167 nsIPrincipal
* aPrincipal
, const char* aMethod
);
170 * Picks a random content parent from |aContentParents| respecting the index
171 * limit set by |aMaxContentParents|.
172 * Returns null if non available.
174 static already_AddRefed
<ContentParent
> MinTabSelect(
175 const nsTArray
<ContentParent
*>& aContentParents
,
176 int32_t maxContentParents
);
179 * Get or create a content process for:
181 * 2. remote xul <browser>
184 static RefPtr
<ContentParent::LaunchPromise
> GetNewOrUsedBrowserProcessAsync(
185 const nsACString
& aRemoteType
, BrowsingContextGroup
* aGroup
= nullptr,
186 hal::ProcessPriority aPriority
=
187 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND
,
188 bool aPreferUsed
= false);
189 static already_AddRefed
<ContentParent
> GetNewOrUsedBrowserProcess(
190 const nsACString
& aRemoteType
, BrowsingContextGroup
* aGroup
= nullptr,
191 hal::ProcessPriority aPriority
=
192 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND
,
193 bool aPreferUsed
= false);
196 * Get or create a content process, but without waiting for the process
197 * launch to have completed. The returned `ContentParent` may still be in the
200 * Can return `nullptr` in the case of an error.
202 * Use the `WaitForLaunchAsync` or `WaitForLaunchSync` methods to wait for
203 * the process to be fully launched.
205 static already_AddRefed
<ContentParent
> GetNewOrUsedLaunchingBrowserProcess(
206 const nsACString
& aRemoteType
, BrowsingContextGroup
* aGroup
= nullptr,
207 hal::ProcessPriority aPriority
=
208 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND
,
209 bool aPreferUsed
= false);
211 RefPtr
<ContentParent::LaunchPromise
> WaitForLaunchAsync(
212 hal::ProcessPriority aPriority
=
213 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND
);
214 bool WaitForLaunchSync(hal::ProcessPriority aPriority
=
215 hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND
);
218 * Get or create a content process for the given TabContext. aFrameElement
219 * should be the frame/iframe element with which this process will
222 static already_AddRefed
<RemoteBrowser
> CreateBrowser(
223 const TabContext
& aContext
, Element
* aFrameElement
,
224 const nsACString
& aRemoteType
, BrowsingContext
* aBrowsingContext
,
225 ContentParent
* aOpenerContentParent
);
228 * Get all content parents.
232 * These pointers are ONLY valid for synchronous use from the main thread.
234 * Do NOT attempt to use them after the main thread has had a chance to handle
235 * messages or you could end up with dangling pointers.
237 static void GetAll(nsTArray
<ContentParent
*>& aArray
);
239 static void GetAllEvenIfDead(nsTArray
<ContentParent
*>& aArray
);
241 static void BroadcastStringBundle(const StringBundleDescriptor
&);
243 static void BroadcastFontListChanged();
244 static void BroadcastShmBlockAdded(uint32_t aGeneration
, uint32_t aIndex
);
246 static void BroadcastThemeUpdate(widget::ThemeChangeKind
);
248 static void BroadcastMediaCodecsSupportedUpdate(
249 RemoteDecodeIn aLocation
, const media::MediaCodecsSupported
& aSupported
);
251 const nsACString
& GetRemoteType() const override
;
253 virtual void DoGetRemoteType(nsACString
& aRemoteType
,
254 ErrorResult
& aError
) const override
{
255 aRemoteType
= GetRemoteType();
258 enum CPIteratorPolicy
{ eLive
, eAll
};
260 class ContentParentIterator
{
262 ContentParent
* mCurrent
;
263 CPIteratorPolicy mPolicy
;
266 ContentParentIterator(CPIteratorPolicy aPolicy
, ContentParent
* aCurrent
)
267 : mCurrent(aCurrent
), mPolicy(aPolicy
) {}
269 ContentParentIterator
begin() {
270 // Move the cursor to the first element that matches the policy.
271 while (mPolicy
!= eAll
&& mCurrent
&& !mCurrent
->IsAlive()) {
272 mCurrent
= mCurrent
->LinkedListElement
<ContentParent
>::getNext();
277 ContentParentIterator
end() {
278 return ContentParentIterator(mPolicy
, nullptr);
281 const ContentParentIterator
& operator++() {
282 MOZ_ASSERT(mCurrent
);
284 mCurrent
= mCurrent
->LinkedListElement
<ContentParent
>::getNext();
285 } while (mPolicy
!= eAll
&& mCurrent
&& !mCurrent
->IsAlive());
290 bool operator!=(const ContentParentIterator
& aOther
) const {
291 MOZ_ASSERT(mPolicy
== aOther
.mPolicy
);
292 return mCurrent
!= aOther
.mCurrent
;
295 ContentParent
* operator*() { return mCurrent
; }
298 static ContentParentIterator
AllProcesses(CPIteratorPolicy aPolicy
) {
299 ContentParent
* first
=
300 sContentParents
? sContentParents
->getFirst() : nullptr;
301 return ContentParentIterator(aPolicy
, first
);
304 static void NotifyUpdatedDictionaries();
306 // Tell content processes the font list has changed. If aFullRebuild is true,
307 // the shared list has been rebuilt and must be freshly mapped by child
308 // processes; if false, existing mappings are still valid but the data has
309 // been updated and so full reflows are in order.
310 static void NotifyUpdatedFonts(bool aFullRebuild
);
312 mozilla::ipc::IPCResult
RecvCreateGMPService();
314 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent
, nsIObserver
)
316 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
317 NS_DECL_NSIDOMPROCESSPARENT
319 NS_DECL_NSIDOMGEOPOSITIONCALLBACK
320 NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
321 NS_DECL_NSIASYNCSHUTDOWNBLOCKER
322 NS_DECL_NSIINTERFACEREQUESTOR
325 * MessageManagerCallback methods that we override.
327 virtual bool DoLoadMessageManagerScript(const nsAString
& aURL
,
328 bool aRunInGlobalScope
) override
;
330 virtual nsresult
DoSendAsyncMessage(const nsAString
& aMessage
,
331 StructuredCloneData
& aData
) override
;
333 RecursiveMutex
& ThreadsafeHandleMutex();
335 /** Notify that a tab is about to send Destroy to its child. */
336 void NotifyTabWillDestroy();
338 /** Notify that a tab is beginning its destruction sequence. */
339 void NotifyTabDestroying();
341 /** Notify that a tab was destroyed during normal operation. */
342 void NotifyTabDestroyed(const TabId
& aTabId
, bool aNotifiedDestroying
);
344 // Manage the set of `KeepAlive`s on this ContentParent which are preventing
345 // it from being destroyed.
347 void RemoveKeepAlive();
349 TestShellParent
* CreateTestShell();
351 bool DestroyTestShell(TestShellParent
* aTestShell
);
353 TestShellParent
* GetTestShellSingleton();
355 // This method can be called on any thread.
356 void RegisterRemoteWorkerActor();
358 // This method _must_ be called on main-thread because it can start the
359 // shutting down of the content process.
360 void UnregisterRemoveWorkerActor();
362 void ReportChildAlreadyBlocked();
364 bool RequestRunToCompletion();
366 void UpdateCookieStatus(nsIChannel
* aChannel
);
368 bool IsLaunching() const {
369 return mLifecycleState
== LifecycleState::LAUNCHING
;
371 bool IsAlive() const override
;
372 bool IsInitialized() const;
373 bool IsSignaledImpendingShutdown() const {
374 return mIsSignaledImpendingShutdown
;
376 bool IsShuttingDown() const {
377 return IsDead() || IsSignaledImpendingShutdown();
379 bool IsDead() const { return mLifecycleState
== LifecycleState::DEAD
; }
381 bool IsForBrowser() const { return mIsForBrowser
; }
383 GeckoChildProcessHost
* Process() const { return mSubprocess
; }
385 nsIContentProcessInfo
* ScriptableHelper() const { return mScriptableHelper
; }
387 mozilla::dom::ProcessMessageManager
* GetMessageManager() const {
388 return mMessageManager
;
391 bool NeedsPermissionsUpdate(const nsACString
& aPermissionKey
) const;
393 // Getter for which permission keys should signal that a content
394 // process needs to know about the change of a permission with this as the
395 // secondary key, like for 3rdPartyFrameStorage^https://secondary.com
396 bool NeedsSecondaryKeyPermissionsUpdate(
397 const nsACString
& aPermissionKey
) const;
399 // Manage pending load states which have been sent to this process, and are
400 // expected to be used to start a load imminently.
401 already_AddRefed
<nsDocShellLoadState
> TakePendingLoadStateForId(
402 uint64_t aLoadIdentifier
);
403 void StorePendingLoadState(nsDocShellLoadState
* aLoadState
);
406 * Kill our subprocess and make sure it dies. Should only be used
407 * in emergency situations since it bypasses the normal shutdown
410 * WARNING: aReason appears in telemetry, so any new value passed in requires
413 void KillHard(const char* aWhy
);
415 ContentParentId
ChildID() const { return mChildID
; }
418 * Get a user-friendly name for this ContentParent. We make no guarantees
419 * about this name: It might not be unique, apps can spoof special names,
420 * etc. So please don't use this name to make any decisions about the
421 * ContentParent based on the value returned here.
423 void FriendlyName(nsAString
& aName
, bool aAnonymize
= false);
425 virtual void OnChannelError() override
;
427 mozilla::ipc::IPCResult
RecvInitCrashReporter(
428 const NativeThreadId
& aThreadId
);
430 already_AddRefed
<PNeckoParent
> AllocPNeckoParent();
432 virtual mozilla::ipc::IPCResult
RecvPNeckoConstructor(
433 PNeckoParent
* aActor
) override
{
434 return PContentParent::RecvPNeckoConstructor(aActor
);
437 mozilla::ipc::IPCResult
RecvInitStreamFilter(
438 const uint64_t& aChannelId
, const nsAString
& aAddonId
,
439 InitStreamFilterResolver
&& aResolver
);
441 PHalParent
* AllocPHalParent();
443 virtual mozilla::ipc::IPCResult
RecvPHalConstructor(
444 PHalParent
* aActor
) override
{
445 return PContentParent::RecvPHalConstructor(aActor
);
448 PHeapSnapshotTempFileHelperParent
* AllocPHeapSnapshotTempFileHelperParent();
450 PRemoteSpellcheckEngineParent
* AllocPRemoteSpellcheckEngineParent();
452 bool CycleCollectWithLogs(bool aDumpAllTraces
,
453 nsICycleCollectorLogSink
* aSink
,
454 nsIDumpGCAndCCLogsCallback
* aCallback
);
456 mozilla::ipc::IPCResult
RecvNotifyTabDestroying(const TabId
& aTabId
,
457 const ContentParentId
& aCpId
);
459 mozilla::ipc::IPCResult
RecvFinishShutdown();
461 mozilla::ipc::IPCResult
RecvNotifyShutdownSuccess();
463 void MaybeInvokeDragSession(BrowserParent
* aParent
, EventMessage aMessage
);
465 PContentPermissionRequestParent
* AllocPContentPermissionRequestParent(
466 const nsTArray
<PermissionRequest
>& aRequests
, nsIPrincipal
* aPrincipal
,
467 nsIPrincipal
* aTopLevelPrincipal
, const bool& aIsHandlingUserInput
,
468 const bool& aMaybeUnsafePermissionDelegate
, const TabId
& aTabId
);
470 bool DeallocPContentPermissionRequestParent(
471 PContentPermissionRequestParent
* actor
);
473 void ForkNewProcess(bool aBlocking
);
475 mozilla::ipc::IPCResult
RecvCreateWindow(
476 PBrowserParent
* aThisBrowserParent
,
477 const MaybeDiscarded
<BrowsingContext
>& aParent
, PBrowserParent
* aNewTab
,
478 const uint32_t& aChromeFlags
, const bool& aCalledFromJS
,
479 const bool& aForPrinting
, const bool& aForWindowDotPrint
,
480 nsIURI
* aURIToLoad
, const nsACString
& aFeatures
,
481 const UserActivation::Modifiers
& aModifiers
,
482 nsIPrincipal
* aTriggeringPrincipal
, nsIContentSecurityPolicy
* aCsp
,
483 nsIReferrerInfo
* aReferrerInfo
, const OriginAttributes
& aOriginAttributes
,
484 CreateWindowResolver
&& aResolve
);
486 mozilla::ipc::IPCResult
RecvCreateWindowInDifferentProcess(
487 PBrowserParent
* aThisTab
, const MaybeDiscarded
<BrowsingContext
>& aParent
,
488 const uint32_t& aChromeFlags
, const bool& aCalledFromJS
,
489 nsIURI
* aURIToLoad
, const nsACString
& aFeatures
,
490 const UserActivation::Modifiers
& aModifiers
, const nsAString
& aName
,
491 nsIPrincipal
* aTriggeringPrincipal
, nsIContentSecurityPolicy
* aCsp
,
492 nsIReferrerInfo
* aReferrerInfo
,
493 const OriginAttributes
& aOriginAttributes
);
495 static void BroadcastBlobURLRegistration(
496 const nsACString
& aURI
, BlobImpl
* aBlobImpl
, nsIPrincipal
* aPrincipal
,
497 const nsCString
& aPartitionKey
, ContentParent
* aIgnoreThisCP
= nullptr);
499 static void BroadcastBlobURLUnregistration(
500 const nsACString
& aURI
, nsIPrincipal
* aPrincipal
,
501 ContentParent
* aIgnoreThisCP
= nullptr);
503 mozilla::ipc::IPCResult
RecvStoreAndBroadcastBlobURLRegistration(
504 const nsACString
& aURI
, const IPCBlob
& aBlob
, nsIPrincipal
* aPrincipal
,
505 const nsCString
& aPartitionKey
);
507 mozilla::ipc::IPCResult
RecvUnstoreAndBroadcastBlobURLUnregistration(
508 const nsACString
& aURI
, nsIPrincipal
* aPrincipal
);
510 virtual int32_t Pid() const override
;
512 // PURLClassifierParent.
513 PURLClassifierParent
* AllocPURLClassifierParent(nsIPrincipal
* aPrincipal
,
515 virtual mozilla::ipc::IPCResult
RecvPURLClassifierConstructor(
516 PURLClassifierParent
* aActor
, nsIPrincipal
* aPrincipal
,
517 bool* aSuccess
) override
;
519 // PURLClassifierLocalParent.
520 PURLClassifierLocalParent
* AllocPURLClassifierLocalParent(
521 nsIURI
* aURI
, const nsTArray
<IPCURLClassifierFeature
>& aFeatures
);
523 virtual mozilla::ipc::IPCResult
RecvPURLClassifierLocalConstructor(
524 PURLClassifierLocalParent
* aActor
, nsIURI
* aURI
,
525 nsTArray
<IPCURLClassifierFeature
>&& aFeatures
) override
;
527 PSessionStorageObserverParent
* AllocPSessionStorageObserverParent();
529 virtual mozilla::ipc::IPCResult
RecvPSessionStorageObserverConstructor(
530 PSessionStorageObserverParent
* aActor
) override
;
532 bool DeallocPSessionStorageObserverParent(
533 PSessionStorageObserverParent
* aActor
);
535 bool DeallocPURLClassifierLocalParent(PURLClassifierLocalParent
* aActor
);
537 bool DeallocPURLClassifierParent(PURLClassifierParent
* aActor
);
539 // Use the PHangMonitor channel to ask the child to repaint a tab.
540 void PaintTabWhileInterruptingJS(BrowserParent
*);
542 void UnloadLayersWhileInterruptingJS(BrowserParent
*);
544 void CancelContentJSExecutionIfRunning(
545 BrowserParent
* aBrowserParent
,
546 nsIRemoteTab::NavigationType aNavigationType
,
547 const CancelContentJSOptions
& aCancelContentJSOptions
);
549 void SetMainThreadQoSPriority(nsIThread::QoSPriority aQoSPriority
);
551 // This function is called when we are about to load a document from an
552 // HTTP(S) channel for a content process. It is a useful place
553 // to start to kick off work as early as possible in response to such
555 // aShouldWaitForPermissionCookieUpdate is set to true if main thread IPCs for
556 // updating permissions/cookies are sent.
557 nsresult
AboutToLoadHttpDocumentForChild(
558 nsIChannel
* aChannel
,
559 bool* aShouldWaitForPermissionCookieUpdate
= nullptr);
561 // Send Blob URLs for this aPrincipal if they are not already known to this
562 // content process and mark the process to receive any new/revoked Blob URLs
563 // to this content process forever.
564 void TransmitBlobURLsForPrincipal(nsIPrincipal
* aPrincipal
);
566 nsresult
TransmitPermissionsForPrincipal(nsIPrincipal
* aPrincipal
);
568 // Whenever receiving a Principal we need to validate that Principal case
569 // by case, where we grant individual callsites to customize the checks!
570 enum class ValidatePrincipalOptions
{
571 AllowNullPtr
, // Not a NullPrincipal but a nullptr as Principal.
575 bool ValidatePrincipal(
576 nsIPrincipal
* aPrincipal
,
577 const EnumSet
<ValidatePrincipalOptions
>& aOptions
= {});
579 // This function is called in BrowsingContext immediately before IPC call to
580 // load a URI. If aURI is a BlobURL, this method transmits all BlobURLs for
581 // aURI's principal that were previously not transmitted. This allows for
582 // opening a locally created BlobURL in a new tab.
584 // The reason all previously untransmitted Blobs are transmitted is that the
585 // current BlobURL could contain html code, referring to another untransmitted
588 // Should eventually be made obsolete by broader design changes that only
589 // store BlobURLs in the parent process.
590 void TransmitBlobDataIfBlobURL(nsIURI
* aURI
);
592 void OnCompositorDeviceReset() override
;
594 // Control the priority of the IPC messages for input events.
595 void SetInputPriorityEventEnabled(bool aEnabled
);
596 bool IsInputPriorityEventEnabled() { return mIsInputPriorityEventEnabled
; }
598 static bool IsInputEventQueueSupported();
600 mozilla::ipc::IPCResult
RecvCreateBrowsingContext(
601 uint64_t aGroupId
, BrowsingContext::IPCInitializer
&& aInit
);
603 mozilla::ipc::IPCResult
RecvDiscardBrowsingContext(
604 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aDoDiscard
,
605 DiscardBrowsingContextResolver
&& aResolve
);
607 mozilla::ipc::IPCResult
RecvWindowClose(
608 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aTrustedCaller
);
609 mozilla::ipc::IPCResult
RecvWindowFocus(
610 const MaybeDiscarded
<BrowsingContext
>& aContext
, CallerType aCallerType
,
612 mozilla::ipc::IPCResult
RecvWindowBlur(
613 const MaybeDiscarded
<BrowsingContext
>& aContext
, CallerType aCallerType
);
614 mozilla::ipc::IPCResult
RecvRaiseWindow(
615 const MaybeDiscarded
<BrowsingContext
>& aContext
, CallerType aCallerType
,
617 mozilla::ipc::IPCResult
RecvAdjustWindowFocus(
618 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aIsVisible
,
619 uint64_t aActionId
, bool aShouldClearFocus
,
620 const MaybeDiscarded
<BrowsingContext
>& aAncestorBrowsingContextToFocus
);
621 mozilla::ipc::IPCResult
RecvClearFocus(
622 const MaybeDiscarded
<BrowsingContext
>& aContext
);
623 mozilla::ipc::IPCResult
RecvSetFocusedBrowsingContext(
624 const MaybeDiscarded
<BrowsingContext
>& aContext
, uint64_t aActionId
);
625 mozilla::ipc::IPCResult
RecvSetActiveBrowsingContext(
626 const MaybeDiscarded
<BrowsingContext
>& aContext
, uint64_t aActionId
);
627 mozilla::ipc::IPCResult
RecvUnsetActiveBrowsingContext(
628 const MaybeDiscarded
<BrowsingContext
>& aContext
, uint64_t aActionId
);
629 mozilla::ipc::IPCResult
RecvSetFocusedElement(
630 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aNeedsFocus
);
631 mozilla::ipc::IPCResult
RecvFinalizeFocusOuter(
632 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aCanFocus
,
633 CallerType aCallerType
);
634 mozilla::ipc::IPCResult
RecvInsertNewFocusActionId(uint64_t aActionId
);
635 mozilla::ipc::IPCResult
RecvBlurToParent(
636 const MaybeDiscarded
<BrowsingContext
>& aFocusedBrowsingContext
,
637 const MaybeDiscarded
<BrowsingContext
>& aBrowsingContextToClear
,
638 const MaybeDiscarded
<BrowsingContext
>& aAncestorBrowsingContextToFocus
,
639 bool aIsLeavingDocument
, bool aAdjustWidget
,
640 bool aBrowsingContextToClearHandled
,
641 bool aAncestorBrowsingContextToFocusHandled
, uint64_t aActionId
);
642 mozilla::ipc::IPCResult
RecvMaybeExitFullscreen(
643 const MaybeDiscarded
<BrowsingContext
>& aContext
);
645 mozilla::ipc::IPCResult
RecvWindowPostMessage(
646 const MaybeDiscarded
<BrowsingContext
>& aContext
,
647 const ClonedOrErrorMessageData
& aMessage
, const PostMessageData
& aData
);
649 FORWARD_SHMEM_ALLOCATOR_TO(PContentParent
)
651 mozilla::ipc::IPCResult
RecvBlobURLDataRequest(
652 const nsACString
& aBlobURL
, nsIPrincipal
* pTriggeringPrincipal
,
653 nsIPrincipal
* pLoadingPrincipal
,
654 const OriginAttributes
& aOriginAttributes
, uint64_t aInnerWindowId
,
655 const nsCString
& aPartitionKey
, BlobURLDataRequestResolver
&& aResolver
);
658 bool CheckBrowsingContextEmbedder(CanonicalBrowsingContext
* aBC
,
659 const char* aOperation
) const;
661 void ActorDestroy(ActorDestroyReason why
) override
;
663 bool ShouldContinueFromReplyTimeout() override
;
665 void OnVarChanged(const GfxVarUpdate
& aVar
) override
;
666 void OnCompositorUnexpectedShutdown() override
;
670 * A map of the remote content process type to a list of content parents
671 * currently available to host *new* tabs/frames of that type.
673 * If a content process is identified as troubled or dead, it will be
674 * removed from this list, but will still be in the sContentParents list for
675 * the GetAll/GetAllEvenIfDead APIs.
677 static nsClassHashtable
<nsCStringHashKey
, nsTArray
<ContentParent
*>>*
678 sBrowserContentParents
;
679 static mozilla::StaticAutoPtr
<LinkedList
<ContentParent
>> sContentParents
;
682 * In order to avoid rapidly creating and destroying content processes when
683 * running under e10s, we may keep alive a single unused "web" content
684 * process if it previously had a very short lifetime.
686 * This process will be re-used during process selection, avoiding spawning a
687 * new process, if the "web" remote type is being requested.
689 static StaticRefPtr
<ContentParent
> sRecycledE10SProcess
;
691 void AddShutdownBlockers();
692 void RemoveShutdownBlockers();
694 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
695 // Cached Mac sandbox params used when launching content processes.
696 static mozilla::StaticAutoPtr
<std::vector
<std::string
>> sMacSandboxParams
;
699 // Set aLoadUri to true to load aURIToLoad and to false to only create the
700 // window. aURIToLoad should always be provided, if available, to ensure
701 // compatibility with GeckoView.
702 mozilla::ipc::IPCResult
CommonCreateWindow(
703 PBrowserParent
* aThisTab
, BrowsingContext
& aParent
, bool aSetOpener
,
704 const uint32_t& aChromeFlags
, const bool& aCalledFromJS
,
705 const bool& aForPrinting
, const bool& aForWindowDotPrint
,
706 nsIURI
* aURIToLoad
, const nsACString
& aFeatures
,
707 const UserActivation::Modifiers
& aModifiers
,
708 BrowserParent
* aNextRemoteBrowser
, const nsAString
& aName
,
709 nsresult
& aResult
, nsCOMPtr
<nsIRemoteTab
>& aNewRemoteTab
,
710 bool* aWindowIsNew
, int32_t& aOpenLocation
,
711 nsIPrincipal
* aTriggeringPrincipal
, nsIReferrerInfo
* aReferrerInfo
,
712 bool aLoadUri
, nsIContentSecurityPolicy
* aCsp
,
713 const OriginAttributes
& aOriginAttributes
);
715 explicit ContentParent(const nsACString
& aRemoteType
);
717 // Launch the subprocess and associated initialization.
718 // Returns false if the process fails to start.
719 // Deprecated in favor of LaunchSubprocessAsync.
720 bool LaunchSubprocessSync(hal::ProcessPriority aInitialPriority
);
722 // Launch the subprocess and associated initialization;
723 // returns a promise and signals failure by rejecting.
724 // OS-level launching work is dispatched to another thread, but some
725 // initialization (creating IPDL actors, etc.; see Init()) is run on
727 RefPtr
<LaunchPromise
> LaunchSubprocessAsync(
728 hal::ProcessPriority aInitialPriority
);
730 // Common implementation of LaunchSubprocess{Sync,Async}.
731 // Return `true` in case of success, `false` if launch was
732 // aborted because of shutdown.
733 bool BeginSubprocessLaunch(ProcessPriority aPriority
);
734 void LaunchSubprocessReject();
735 bool LaunchSubprocessResolve(bool aIsSync
, ProcessPriority aPriority
);
737 // Common initialization after sub process launch.
738 bool InitInternal(ProcessPriority aPriority
);
740 // Generate a minidump for the child process and one for the main process
741 void GeneratePairedMinidump(const char* aReason
);
742 void HandleOrphanedMinidump(nsString
* aDumpId
);
744 virtual ~ContentParent();
748 // Some information could be sent to content very early, it
749 // should be send from this function. This function should only be
750 // called after the process has been transformed to browser.
751 void ForwardKnownInfo();
754 * We might want to reuse barely used content processes if certain criteria
757 * With Fission this is a no-op.
759 bool TryToRecycleE10SOnly();
762 * If this process is currently being recycled, unmark it as the recycled
764 * If `aForeground` is true, will also restore the process' foreground
765 * priority if it was previously the recycled content process.
767 * With Fission this is a no-op.
769 void StopRecyclingE10SOnly(bool aForeground
);
772 * Removing it from the static array so it won't be returned for new tabs in
773 * GetNewOrUsedBrowserProcess.
775 void RemoveFromList();
778 * Return if the process has an active worker.
780 bool HasActiveWorker();
783 * Decide whether the process should be kept alive even when it would normally
784 * be shut down, for example when all its tabs are closed.
786 bool ShouldKeepProcessAlive();
789 * Mark this ContentParent as dead for the purposes of Get*().
790 * This method is idempotent.
795 * Let the process know we are about to send a shutdown through a
796 * non-mainthread side channel in order to bypass mainthread congestion.
797 * This potentially cancels mainthread content JS execution.
799 void SignalImpendingShutdownToContentJS();
801 bool CheckTabDestroyWillKeepAlive(uint32_t aExpectedBrowserCount
);
804 * Check if this process is ready to be shut down, and if it is, begin the
805 * shutdown process. Should be called whenever a change occurs which could
806 * cause the decisions made by `ShouldKeepProcessAlive` to change.
808 * @param aExpectedBrowserCount The number of PBrowser actors which should
809 * not block shutdown. This should usually be 0.
810 * @param aSendShutDown If true, will send the shutdown message in addition
811 * to marking the process as dead and starting the force
814 void MaybeBeginShutDown(uint32_t aExpectedBrowserCount
= 0,
815 bool aSendShutDown
= true);
818 * How we will shut down this ContentParent and its subprocess.
820 enum ShutDownMethod
{
821 // Send a shutdown message and wait for FinishShutdown call back.
822 SEND_SHUTDOWN_MESSAGE
,
823 // Close the channel ourselves and let the subprocess clean up itself.
827 void AsyncSendShutDownMessage();
830 * Exit the subprocess and vamoose. After this call IsAlive()
831 * will return false and this ContentParent will not be returned
832 * by the Get*() funtions. However, the shutdown sequence itself
833 * may be asynchronous.
835 bool ShutDownProcess(ShutDownMethod aMethod
);
837 // Perform any steps necesssary to gracefully shtudown the message
838 // manager and null out mMessageManager.
839 void ShutDownMessageManager();
841 // Start the send shutdown timer on shutdown.
842 void StartSendShutdownTimer();
844 // Start the force-kill timer on shutdown.
845 void StartForceKillTimer();
847 // Ensure that the permissions for the giben Permission key are set in the
850 // See nsIPermissionManager::GetPermissionsForKey for more information on
852 void EnsurePermissionsByKey(const nsACString
& aKey
,
853 const nsACString
& aOrigin
);
855 static void SendShutdownTimerCallback(nsITimer
* aTimer
, void* aClosure
);
856 static void ForceKillTimerCallback(nsITimer
* aTimer
, void* aClosure
);
858 bool CanOpenBrowser(const IPCTabContext
& aContext
);
861 * Get or create the corresponding content parent array to
862 * |aContentProcessType|.
864 static nsTArray
<ContentParent
*>& GetOrCreatePool(
865 const nsACString
& aContentProcessType
);
867 mozilla::ipc::IPCResult
RecvInitBackground(
868 Endpoint
<mozilla::ipc::PBackgroundStarterParent
>&& aEndpoint
);
870 mozilla::ipc::IPCResult
RecvAddMemoryReport(const MemoryReport
& aReport
);
872 bool DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent
*);
874 mozilla::ipc::IPCResult
RecvCloneDocumentTreeInto(
875 const MaybeDiscarded
<BrowsingContext
>& aSource
,
876 const MaybeDiscarded
<BrowsingContext
>& aTarget
, PrintData
&& aPrintData
);
878 mozilla::ipc::IPCResult
RecvUpdateRemotePrintSettings(
879 const MaybeDiscarded
<BrowsingContext
>& aTarget
, PrintData
&& aPrintData
);
881 mozilla::ipc::IPCResult
RecvConstructPopupBrowser(
882 ManagedEndpoint
<PBrowserParent
>&& actor
,
883 ManagedEndpoint
<PWindowGlobalParent
>&& windowEp
, const TabId
& tabId
,
884 const IPCTabContext
& context
, const WindowGlobalInit
& initialWindowInit
,
885 const uint32_t& chromeFlags
);
887 mozilla::ipc::IPCResult
RecvIsSecureURI(
888 nsIURI
* aURI
, const OriginAttributes
& aOriginAttributes
,
891 mozilla::ipc::IPCResult
RecvAccumulateMixedContentHSTS(
892 nsIURI
* aURI
, const bool& aActive
,
893 const OriginAttributes
& aOriginAttributes
);
895 bool DeallocPHalParent(PHalParent
*);
897 bool DeallocPHeapSnapshotTempFileHelperParent(
898 PHeapSnapshotTempFileHelperParent
*);
900 PCycleCollectWithLogsParent
* AllocPCycleCollectWithLogsParent(
901 const bool& aDumpAllTraces
, const FileDescriptor
& aGCLog
,
902 const FileDescriptor
& aCCLog
);
904 bool DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent
* aActor
);
906 PScriptCacheParent
* AllocPScriptCacheParent(const FileDescOrError
& cacheFile
,
907 const bool& wantCacheData
);
909 bool DeallocPScriptCacheParent(PScriptCacheParent
* shell
);
911 already_AddRefed
<PExternalHelperAppParent
> AllocPExternalHelperAppParent(
912 nsIURI
* aUri
, const mozilla::net::LoadInfoArgs
& aLoadInfoArgs
,
913 const nsACString
& aMimeContentType
, const nsACString
& aContentDisposition
,
914 const uint32_t& aContentDispositionHint
,
915 const nsAString
& aContentDispositionFilename
, const bool& aForceSave
,
916 const int64_t& aContentLength
, const bool& aWasFileChannel
,
917 nsIURI
* aReferrer
, const MaybeDiscarded
<BrowsingContext
>& aContext
,
918 const bool& aShouldCloseWindow
);
920 mozilla::ipc::IPCResult
RecvPExternalHelperAppConstructor(
921 PExternalHelperAppParent
* actor
, nsIURI
* uri
,
922 const LoadInfoArgs
& loadInfoArgs
, const nsACString
& aMimeContentType
,
923 const nsACString
& aContentDisposition
,
924 const uint32_t& aContentDispositionHint
,
925 const nsAString
& aContentDispositionFilename
, const bool& aForceSave
,
926 const int64_t& aContentLength
, const bool& aWasFileChannel
,
927 nsIURI
* aReferrer
, const MaybeDiscarded
<BrowsingContext
>& aContext
,
928 const bool& aShouldCloseWindow
) override
;
930 already_AddRefed
<PHandlerServiceParent
> AllocPHandlerServiceParent();
932 PMediaParent
* AllocPMediaParent();
934 bool DeallocPMediaParent(PMediaParent
* aActor
);
936 PBenchmarkStorageParent
* AllocPBenchmarkStorageParent();
938 bool DeallocPBenchmarkStorageParent(PBenchmarkStorageParent
* aActor
);
941 already_AddRefed
<PSpeechSynthesisParent
> AllocPSpeechSynthesisParent();
943 virtual mozilla::ipc::IPCResult
RecvPSpeechSynthesisConstructor(
944 PSpeechSynthesisParent
* aActor
) override
;
947 already_AddRefed
<PWebBrowserPersistDocumentParent
>
948 AllocPWebBrowserPersistDocumentParent(
949 PBrowserParent
* aBrowser
,
950 const MaybeDiscarded
<BrowsingContext
>& aContext
);
952 mozilla::ipc::IPCResult
RecvSetClipboard(const IPCTransferable
& aTransferable
,
953 const int32_t& aWhichClipboard
);
955 mozilla::ipc::IPCResult
RecvGetClipboard(
956 nsTArray
<nsCString
>&& aTypes
, const int32_t& aWhichClipboard
,
957 const MaybeDiscarded
<WindowContext
>& aRequestingWindowContext
,
958 IPCTransferableData
* aTransferableData
);
960 mozilla::ipc::IPCResult
RecvEmptyClipboard(const int32_t& aWhichClipboard
);
962 mozilla::ipc::IPCResult
RecvClipboardHasType(nsTArray
<nsCString
>&& aTypes
,
963 const int32_t& aWhichClipboard
,
966 mozilla::ipc::IPCResult
RecvGetClipboardAsync(
967 nsTArray
<nsCString
>&& aTypes
, const int32_t& aWhichClipboard
,
968 const MaybeDiscarded
<WindowContext
>& aRequestingWindowContext
,
969 mozilla::NotNull
<nsIPrincipal
*> aRequestingPrincipal
,
970 GetClipboardAsyncResolver
&& aResolver
);
972 mozilla::ipc::IPCResult
RecvGetClipboardDataSnapshotSync(
973 nsTArray
<nsCString
>&& aTypes
, const int32_t& aWhichClipboard
,
974 const MaybeDiscarded
<WindowContext
>& aRequestingWindowContext
,
975 ClipboardReadRequestOrError
* aRequestOrError
);
977 already_AddRefed
<PClipboardWriteRequestParent
>
978 AllocPClipboardWriteRequestParent(const int32_t& aClipboardType
);
980 mozilla::ipc::IPCResult
RecvGetIconForExtension(const nsACString
& aFileExt
,
981 const uint32_t& aIconSize
,
982 nsTArray
<uint8_t>* bits
);
984 mozilla::ipc::IPCResult
RecvStartVisitedQueries(
985 const nsTArray
<RefPtr
<nsIURI
>>&);
987 mozilla::ipc::IPCResult
RecvSetURITitle(nsIURI
* uri
, const nsAString
& title
);
989 mozilla::ipc::IPCResult
RecvShowAlert(nsIAlertNotification
* aAlert
);
991 mozilla::ipc::IPCResult
RecvCloseAlert(const nsAString
& aName
,
992 bool aContextClosed
);
994 mozilla::ipc::IPCResult
RecvDisableNotifications(nsIPrincipal
* aPrincipal
);
996 mozilla::ipc::IPCResult
RecvOpenNotificationSettings(
997 nsIPrincipal
* aPrincipal
);
999 mozilla::ipc::IPCResult
RecvNotificationEvent(
1000 const nsAString
& aType
, const NotificationEventData
& aData
);
1002 mozilla::ipc::IPCResult
RecvLoadURIExternal(
1003 nsIURI
* uri
, nsIPrincipal
* triggeringPrincipal
,
1004 nsIPrincipal
* redirectPrincipal
,
1005 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1006 bool aWasExternallyTriggered
, bool aHasValidUserGestureActivation
);
1007 mozilla::ipc::IPCResult
RecvExtProtocolChannelConnectParent(
1008 const uint64_t& registrarId
);
1010 mozilla::ipc::IPCResult
RecvSyncMessage(
1011 const nsAString
& aMsg
, const ClonedMessageData
& aData
,
1012 nsTArray
<StructuredCloneData
>* aRetvals
);
1014 mozilla::ipc::IPCResult
RecvAsyncMessage(const nsAString
& aMsg
,
1015 const ClonedMessageData
& aData
);
1017 // MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
1019 MOZ_CAN_RUN_SCRIPT_BOUNDARY
1020 mozilla::ipc::IPCResult
RecvAddGeolocationListener(const bool& aHighAccuracy
);
1021 mozilla::ipc::IPCResult
RecvRemoveGeolocationListener();
1023 // MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
1025 MOZ_CAN_RUN_SCRIPT_BOUNDARY
1026 mozilla::ipc::IPCResult
RecvSetGeolocationHigherAccuracy(const bool& aEnable
);
1028 mozilla::ipc::IPCResult
RecvConsoleMessage(const nsAString
& aMessage
);
1030 mozilla::ipc::IPCResult
RecvScriptError(
1031 const nsAString
& aMessage
, const nsAString
& aSourceName
,
1032 const nsAString
& aSourceLine
, const uint32_t& aLineNumber
,
1033 const uint32_t& aColNumber
, const uint32_t& aFlags
,
1034 const nsACString
& aCategory
, const bool& aIsFromPrivateWindow
,
1035 const uint64_t& aInnerWindowId
, const bool& aIsFromChromeContext
);
1037 mozilla::ipc::IPCResult
RecvReportFrameTimingData(
1038 const LoadInfoArgs
& loadInfoArgs
, const nsAString
& entryName
,
1039 const nsAString
& initiatorType
, UniquePtr
<PerformanceTimingData
>&& aData
);
1041 mozilla::ipc::IPCResult
RecvScriptErrorWithStack(
1042 const nsAString
& aMessage
, const nsAString
& aSourceName
,
1043 const nsAString
& aSourceLine
, const uint32_t& aLineNumber
,
1044 const uint32_t& aColNumber
, const uint32_t& aFlags
,
1045 const nsACString
& aCategory
, const bool& aIsFromPrivateWindow
,
1046 const bool& aIsFromChromeContext
, const ClonedMessageData
& aStack
);
1049 mozilla::ipc::IPCResult
RecvScriptErrorInternal(
1050 const nsAString
& aMessage
, const nsAString
& aSourceName
,
1051 const nsAString
& aSourceLine
, const uint32_t& aLineNumber
,
1052 const uint32_t& aColNumber
, const uint32_t& aFlags
,
1053 const nsACString
& aCategory
, const bool& aIsFromPrivateWindow
,
1054 const bool& aIsFromChromeContext
,
1055 const ClonedMessageData
* aStack
= nullptr);
1058 mozilla::ipc::IPCResult
RecvCommitBrowsingContextTransaction(
1059 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1060 BrowsingContext::BaseTransaction
&& aTransaction
, uint64_t aEpoch
);
1062 mozilla::ipc::IPCResult
RecvCommitWindowContextTransaction(
1063 const MaybeDiscarded
<WindowContext
>& aContext
,
1064 WindowContext::BaseTransaction
&& aTransaction
, uint64_t aEpoch
);
1066 mozilla::ipc::IPCResult
RecvAddSecurityState(
1067 const MaybeDiscarded
<WindowContext
>& aContext
, uint32_t aStateFlags
);
1069 mozilla::ipc::IPCResult
RecvFirstIdle();
1071 mozilla::ipc::IPCResult
RecvDeviceReset();
1073 mozilla::ipc::IPCResult
RecvCopyFavicon(nsIURI
* aOldURI
, nsIURI
* aNewURI
,
1074 const bool& aInPrivateBrowsing
);
1076 mozilla::ipc::IPCResult
RecvFindImageText(IPCImage
&&, nsTArray
<nsCString
>&&,
1077 FindImageTextResolver
&&);
1079 virtual void ProcessingError(Result aCode
, const char* aMsgName
) override
;
1081 mozilla::ipc::IPCResult
RecvGraphicsError(const nsACString
& aError
);
1083 mozilla::ipc::IPCResult
RecvBeginDriverCrashGuard(const uint32_t& aGuardType
,
1086 mozilla::ipc::IPCResult
RecvEndDriverCrashGuard(const uint32_t& aGuardType
);
1088 mozilla::ipc::IPCResult
RecvAddIdleObserver(const uint64_t& observerId
,
1089 const uint32_t& aIdleTimeInS
);
1091 mozilla::ipc::IPCResult
RecvRemoveIdleObserver(const uint64_t& observerId
,
1092 const uint32_t& aIdleTimeInS
);
1094 mozilla::ipc::IPCResult
RecvBackUpXResources(
1095 const FileDescriptor
& aXSocketFd
);
1097 mozilla::ipc::IPCResult
RecvRequestAnonymousTemporaryFile(
1098 const uint64_t& aID
);
1100 mozilla::ipc::IPCResult
RecvCreateAudioIPCConnection(
1101 CreateAudioIPCConnectionResolver
&& aResolver
);
1103 already_AddRefed
<extensions::PExtensionsParent
> AllocPExtensionsParent();
1106 PWebrtcGlobalParent
* AllocPWebrtcGlobalParent();
1107 bool DeallocPWebrtcGlobalParent(PWebrtcGlobalParent
* aActor
);
1110 mozilla::ipc::IPCResult
RecvUpdateDropEffect(const uint32_t& aDragAction
,
1111 const uint32_t& aDropEffect
);
1113 mozilla::ipc::IPCResult
RecvShutdownProfile(const nsACString
& aProfile
);
1115 mozilla::ipc::IPCResult
RecvShutdownPerfStats(const nsACString
& aPerfStats
);
1117 mozilla::ipc::IPCResult
RecvGetFontListShmBlock(
1118 const uint32_t& aGeneration
, const uint32_t& aIndex
,
1119 base::SharedMemoryHandle
* aOut
);
1121 mozilla::ipc::IPCResult
RecvInitializeFamily(const uint32_t& aGeneration
,
1122 const uint32_t& aFamilyIndex
,
1123 const bool& aLoadCmaps
);
1125 mozilla::ipc::IPCResult
RecvSetCharacterMap(const uint32_t& aGeneration
,
1126 const uint32_t& aFamilyIndex
,
1128 const uint32_t& aFaceIndex
,
1129 const gfxSparseBitSet
& aMap
);
1131 mozilla::ipc::IPCResult
RecvInitOtherFamilyNames(const uint32_t& aGeneration
,
1135 mozilla::ipc::IPCResult
RecvSetupFamilyCharMap(const uint32_t& aGeneration
,
1136 const uint32_t& aIndex
,
1137 const bool& aAlias
);
1139 mozilla::ipc::IPCResult
RecvStartCmapLoading(const uint32_t& aGeneration
,
1140 const uint32_t& aStartIndex
);
1142 mozilla::ipc::IPCResult
RecvGetHyphDict(nsIURI
* aURIParams
,
1143 base::SharedMemoryHandle
* aOutHandle
,
1144 uint32_t* aOutSize
);
1146 mozilla::ipc::IPCResult
RecvNotifyBenchmarkResult(const nsAString
& aCodecName
,
1147 const uint32_t& aDecodeFPS
);
1149 mozilla::ipc::IPCResult
RecvNotifyPushObservers(const nsACString
& aScope
,
1150 nsIPrincipal
* aPrincipal
,
1151 const nsAString
& aMessageId
);
1153 mozilla::ipc::IPCResult
RecvNotifyPushObserversWithData(
1154 const nsACString
& aScope
, nsIPrincipal
* aPrincipal
,
1155 const nsAString
& aMessageId
, nsTArray
<uint8_t>&& aData
);
1157 mozilla::ipc::IPCResult
RecvNotifyPushSubscriptionChangeObservers(
1158 const nsACString
& aScope
, nsIPrincipal
* aPrincipal
);
1160 mozilla::ipc::IPCResult
RecvPushError(const nsACString
& aScope
,
1161 nsIPrincipal
* aPrincipal
,
1162 const nsAString
& aMessage
,
1163 const uint32_t& aFlags
);
1165 mozilla::ipc::IPCResult
RecvNotifyPushSubscriptionModifiedObservers(
1166 const nsACString
& aScope
, nsIPrincipal
* aPrincipal
);
1168 mozilla::ipc::IPCResult
RecvGetFilesRequest(const nsID
& aID
,
1169 const nsAString
& aDirectoryPath
,
1170 const bool& aRecursiveFlag
);
1172 mozilla::ipc::IPCResult
RecvDeleteGetFilesRequest(const nsID
& aID
);
1174 mozilla::ipc::IPCResult
RecvAccumulateChildHistograms(
1175 nsTArray
<HistogramAccumulation
>&& aAccumulations
);
1176 mozilla::ipc::IPCResult
RecvAccumulateChildKeyedHistograms(
1177 nsTArray
<KeyedHistogramAccumulation
>&& aAccumulations
);
1178 mozilla::ipc::IPCResult
RecvUpdateChildScalars(
1179 nsTArray
<ScalarAction
>&& aScalarActions
);
1180 mozilla::ipc::IPCResult
RecvUpdateChildKeyedScalars(
1181 nsTArray
<KeyedScalarAction
>&& aScalarActions
);
1182 mozilla::ipc::IPCResult
RecvRecordChildEvents(
1183 nsTArray
<ChildEventData
>&& events
);
1184 mozilla::ipc::IPCResult
RecvRecordDiscardedData(
1185 const DiscardedData
& aDiscardedData
);
1186 mozilla::ipc::IPCResult
RecvRecordPageLoadEvent(
1187 const mozilla::glean::perf::PageLoadExtra
& aPageLoadEventExtra
);
1188 mozilla::ipc::IPCResult
RecvRecordOrigin(const uint32_t& aMetricId
,
1189 const nsACString
& aOrigin
);
1190 mozilla::ipc::IPCResult
RecvReportContentBlockingLog(
1191 const IPCStream
& aIPCStream
);
1193 mozilla::ipc::IPCResult
RecvBHRThreadHang(const HangDetails
& aHangDetails
);
1195 mozilla::ipc::IPCResult
RecvAddCertException(
1196 nsIX509Cert
* aCert
, const nsACString
& aHostName
, int32_t aPort
,
1197 const OriginAttributes
& aOriginAttributes
, bool aIsTemporary
,
1198 AddCertExceptionResolver
&& aResolver
);
1200 mozilla::ipc::IPCResult
RecvAutomaticStorageAccessPermissionCanBeGranted(
1201 nsIPrincipal
* aPrincipal
,
1202 AutomaticStorageAccessPermissionCanBeGrantedResolver
&& aResolver
);
1204 mozilla::ipc::IPCResult
RecvStorageAccessPermissionGrantedForOrigin(
1205 uint64_t aTopLevelWindowId
,
1206 const MaybeDiscarded
<BrowsingContext
>& aParentContext
,
1207 nsIPrincipal
* aTrackingPrincipal
, const nsACString
& aTrackingOrigin
,
1208 const int& aAllowMode
,
1210 ContentBlockingNotifier::StorageAccessPermissionGrantedReason
>&
1212 const bool& aFrameOnly
,
1213 StorageAccessPermissionGrantedForOriginResolver
&& aResolver
);
1215 mozilla::ipc::IPCResult
RecvCompleteAllowAccessFor(
1216 const MaybeDiscarded
<BrowsingContext
>& aParentContext
,
1217 uint64_t aTopLevelWindowId
, nsIPrincipal
* aTrackingPrincipal
,
1218 const nsACString
& aTrackingOrigin
, uint32_t aCookieBehavior
,
1219 const ContentBlockingNotifier::StorageAccessPermissionGrantedReason
&
1221 CompleteAllowAccessForResolver
&& aResolver
);
1223 mozilla::ipc::IPCResult
RecvSetAllowStorageAccessRequestFlag(
1224 nsIPrincipal
* aEmbeddedPrincipal
, nsIURI
* aEmbeddingOrigin
,
1225 SetAllowStorageAccessRequestFlagResolver
&& aResolver
);
1227 mozilla::ipc::IPCResult
RecvTestAllowStorageAccessRequestFlag(
1228 nsIPrincipal
* aEmbeddingPrincipal
, nsIURI
* aEmbeddedOrigin
,
1229 TestAllowStorageAccessRequestFlagResolver
&& aResolver
);
1231 mozilla::ipc::IPCResult
RecvStoreUserInteractionAsPermission(
1232 nsIPrincipal
* aPrincipal
);
1234 mozilla::ipc::IPCResult
RecvTestCookiePermissionDecided(
1235 const MaybeDiscarded
<BrowsingContext
>& aContext
, nsIPrincipal
* aPrincipal
,
1236 const TestCookiePermissionDecidedResolver
&& aResolver
);
1238 mozilla::ipc::IPCResult
RecvTestStorageAccessPermission(
1239 nsIPrincipal
* aEmbeddingPrincipal
, const nsCString
& aEmbeddedOrigin
,
1240 const TestStorageAccessPermissionResolver
&& aResolver
);
1242 mozilla::ipc::IPCResult
RecvNotifyMediaPlaybackChanged(
1243 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1244 MediaPlaybackState aState
);
1246 mozilla::ipc::IPCResult
RecvNotifyMediaAudibleChanged(
1247 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1248 MediaAudibleState aState
);
1250 mozilla::ipc::IPCResult
RecvNotifyPictureInPictureModeChanged(
1251 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aEnabled
);
1253 mozilla::ipc::IPCResult
RecvNotifyMediaSessionUpdated(
1254 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aIsCreated
);
1256 mozilla::ipc::IPCResult
RecvNotifyUpdateMediaMetadata(
1257 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1258 const Maybe
<MediaMetadataBase
>& aMetadata
);
1260 mozilla::ipc::IPCResult
RecvNotifyMediaSessionPlaybackStateChanged(
1261 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1262 MediaSessionPlaybackState aPlaybackState
);
1264 mozilla::ipc::IPCResult
RecvNotifyMediaSessionSupportedActionChanged(
1265 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1266 MediaSessionAction aAction
, bool aEnabled
);
1268 mozilla::ipc::IPCResult
RecvNotifyMediaFullScreenState(
1269 const MaybeDiscarded
<BrowsingContext
>& aContext
, bool aIsInFullScreen
);
1271 mozilla::ipc::IPCResult
RecvNotifyPositionStateChanged(
1272 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1273 const Maybe
<PositionState
>& aState
);
1275 mozilla::ipc::IPCResult
RecvAddOrRemovePageAwakeRequest(
1276 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1277 const bool& aShouldAddCount
);
1280 mozilla::ipc::IPCResult
RecvGetModulesTrust(
1281 ModulePaths
&& aModPaths
, bool aRunAtNormalPriority
,
1282 GetModulesTrustResolver
&& aResolver
);
1283 #endif // defined(XP_WIN)
1285 mozilla::ipc::IPCResult
RecvReportServiceWorkerShutdownProgress(
1286 uint32_t aShutdownStateId
,
1287 ServiceWorkerShutdownState::Progress aProgress
);
1289 mozilla::ipc::IPCResult
RecvRawMessage(
1290 const JSActorMessageMeta
& aMeta
, const Maybe
<ClonedMessageData
>& aData
,
1291 const Maybe
<ClonedMessageData
>& aStack
);
1293 mozilla::ipc::IPCResult
RecvAbortOtherOrientationPendingPromises(
1294 const MaybeDiscarded
<BrowsingContext
>& aContext
);
1296 mozilla::ipc::IPCResult
RecvNotifyOnHistoryReload(
1297 const MaybeDiscarded
<BrowsingContext
>& aContext
, const bool& aForceReload
,
1298 NotifyOnHistoryReloadResolver
&& aResolver
);
1300 mozilla::ipc::IPCResult
RecvHistoryCommit(
1301 const MaybeDiscarded
<BrowsingContext
>& aContext
, const uint64_t& aLoadID
,
1302 const nsID
& aChangeID
, const uint32_t& aLoadType
, const bool& aPersist
,
1303 const bool& aCloneEntryChildren
, const bool& aChannelExpired
,
1304 const uint32_t& aCacheKey
);
1306 mozilla::ipc::IPCResult
RecvHistoryGo(
1307 const MaybeDiscarded
<BrowsingContext
>& aContext
, int32_t aOffset
,
1308 uint64_t aHistoryEpoch
, bool aRequireUserInteraction
,
1309 bool aUserActivation
, HistoryGoResolver
&& aResolveRequestedIndex
);
1311 mozilla::ipc::IPCResult
RecvSynchronizeLayoutHistoryState(
1312 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1313 nsILayoutHistoryState
* aState
);
1315 mozilla::ipc::IPCResult
RecvSessionHistoryEntryTitle(
1316 const MaybeDiscarded
<BrowsingContext
>& aContext
, const nsAString
& aTitle
);
1318 mozilla::ipc::IPCResult
RecvSessionHistoryEntryScrollRestorationIsManual(
1319 const MaybeDiscarded
<BrowsingContext
>& aContext
, const bool& aIsManual
);
1321 mozilla::ipc::IPCResult
RecvSessionHistoryEntryScrollPosition(
1322 const MaybeDiscarded
<BrowsingContext
>& aContext
, const int32_t& aX
,
1325 mozilla::ipc::IPCResult
RecvSessionHistoryEntryCacheKey(
1326 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1327 const uint32_t& aCacheKey
);
1329 mozilla::ipc::IPCResult
RecvSessionHistoryEntryWireframe(
1330 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1331 const Wireframe
& aWireframe
);
1333 mozilla::ipc::IPCResult
1334 RecvSessionHistoryEntryStoreWindowNameInContiguousEntries(
1335 const MaybeDiscarded
<BrowsingContext
>& aContext
, const nsAString
& aName
);
1337 mozilla::ipc::IPCResult
RecvGetLoadingSessionHistoryInfoFromParent(
1338 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1339 GetLoadingSessionHistoryInfoFromParentResolver
&& aResolver
);
1341 mozilla::ipc::IPCResult
RecvRemoveFromBFCache(
1342 const MaybeDiscarded
<BrowsingContext
>& aContext
);
1344 mozilla::ipc::IPCResult
RecvSetActiveSessionHistoryEntry(
1345 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1346 const Maybe
<nsPoint
>& aPreviousScrollPos
, SessionHistoryInfo
&& aInfo
,
1347 uint32_t aLoadType
, uint32_t aUpdatedCacheKey
, const nsID
& aChangeID
);
1349 mozilla::ipc::IPCResult
RecvReplaceActiveSessionHistoryEntry(
1350 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1351 SessionHistoryInfo
&& aInfo
);
1353 mozilla::ipc::IPCResult
RecvRemoveDynEntriesFromActiveSessionHistoryEntry(
1354 const MaybeDiscarded
<BrowsingContext
>& aContext
);
1356 mozilla::ipc::IPCResult
RecvRemoveFromSessionHistory(
1357 const MaybeDiscarded
<BrowsingContext
>& aContext
, const nsID
& aChangeID
);
1359 mozilla::ipc::IPCResult
RecvHistoryReload(
1360 const MaybeDiscarded
<BrowsingContext
>& aContext
,
1361 const uint32_t aReloadFlags
);
1363 mozilla::ipc::IPCResult
RecvCleanupPendingLoadState(uint64_t aLoadIdentifier
);
1365 // Notify the ContentChild to enable the input event prioritization when
1367 void MaybeEnableRemoteInputEventQueue();
1369 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
1370 void AppendSandboxParams(std::vector
<std::string
>& aArgs
);
1371 void AppendDynamicSandboxParams(std::vector
<std::string
>& aArgs
);
1374 mozilla::ipc::IPCResult
RecvFOGData(ByteBuf
&& buf
);
1376 mozilla::ipc::IPCResult
RecvSetContainerFeaturePolicy(
1377 const MaybeDiscardedBrowsingContext
& aContainerContext
,
1378 FeaturePolicy
* aContainerFeaturePolicy
);
1380 mozilla::ipc::IPCResult
RecvGetSystemIcon(nsIURI
* aURI
,
1381 GetSystemIconResolver
&& aResolver
);
1383 #ifdef FUZZING_SNAPSHOT
1384 mozilla::ipc::IPCResult
RecvSignalFuzzingReady();
1388 void SendGetFilesResponseAndForget(const nsID
& aID
,
1389 const GetFilesResponseResult
& aResult
);
1391 bool SendRequestMemoryReport(const uint32_t& aGeneration
,
1392 const bool& aAnonymize
,
1393 const bool& aMinimizeMemoryUsage
,
1394 const Maybe
<FileDescriptor
>& aDMDFile
) override
;
1396 void AddBrowsingContextGroup(BrowsingContextGroup
* aGroup
);
1397 void RemoveBrowsingContextGroup(BrowsingContextGroup
* aGroup
);
1399 // See `BrowsingContext::mEpochs` for an explanation of this field.
1400 uint64_t GetBrowsingContextFieldEpoch() const {
1401 return mBrowsingContextFieldEpoch
;
1404 void UpdateNetworkLinkType();
1406 already_AddRefed
<JSActor
> InitJSActor(JS::Handle
<JSObject
*> aMaybeActor
,
1407 const nsACString
& aName
,
1408 ErrorResult
& aRv
) override
;
1409 mozilla::ipc::IProtocol
* AsNativeActor() override
{ return this; }
1411 static already_AddRefed
<nsIPrincipal
> CreateRemoteTypeIsolationPrincipal(
1412 const nsACString
& aRemoteType
);
1414 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
1415 bool IsBlockingShutdown() { return mBlockShutdownCalled
; }
1418 ThreadsafeContentParentHandle
* ThreadsafeHandle() const {
1419 return mThreadsafeHandle
;
1422 void GetIPCTransferableData(nsIDragSession
* aSession
, BrowserParent
* aParent
,
1423 nsTArray
<IPCTransferableData
>& aIPCTransferables
);
1426 // Return an existing ContentParent if possible. Otherwise, `nullptr`.
1427 static already_AddRefed
<ContentParent
> GetUsedBrowserProcess(
1428 const nsACString
& aRemoteType
, nsTArray
<ContentParent
*>& aContentParents
,
1429 uint32_t aMaxContentParents
, bool aPreferUsed
, ProcessPriority aPriority
);
1431 void AddToPool(nsTArray
<ContentParent
*>&);
1432 void RemoveFromPool(nsTArray
<ContentParent
*>&);
1433 void AssertNotInPool();
1438 // If you add strong pointers to cycle collected objects here, be sure to
1439 // release these objects in ShutDownProcess. See the comment there for more
1442 GeckoChildProcessHost
* mSubprocess
;
1443 const TimeStamp mLaunchTS
; // used to calculate time to start content process
1444 TimeStamp mLaunchYieldTS
; // used to calculate async launch main thread time
1445 TimeStamp mActivateTS
;
1447 bool mIsAPreallocBlocker
; // We called AddBlocker for this ContentParent
1449 nsCString mRemoteType
;
1451 nsCOMPtr
<nsIPrincipal
> mRemoteTypeIsolationPrincipal
;
1453 ContentParentId mChildID
;
1454 int32_t mGeolocationWatchID
;
1456 // After we destroy the last Browser, we also start a timer to ensure
1457 // that even content processes that are not responding will get a
1458 // second chance and a shutdown message.
1459 nsCOMPtr
<nsITimer
> mSendShutdownTimer
;
1460 bool mSentShutdownMessage
= false;
1462 // After we initiate shutdown, we also start a timer to ensure
1463 // that even content processes that are 100% blocked (say from
1464 // SIGSTOP), are still killed eventually. This task enforces that
1466 nsCOMPtr
<nsITimer
> mForceKillTimer
;
1468 // Threadsafe handle object which can be used by actors like PBackground to
1469 // track the identity and other relevant information about the content process
1470 // they're attached to.
1471 const RefPtr
<ThreadsafeContentParentHandle
> mThreadsafeHandle
;
1473 // How many tabs we're waiting to finish their destruction
1474 // sequence. Precisely, how many BrowserParents have called
1475 // NotifyTabDestroying() but not called NotifyTabDestroyed().
1476 int32_t mNumDestroyingTabs
;
1478 uint32_t mNumKeepaliveCalls
;
1480 // The process starts in the LAUNCHING state, and transitions to
1481 // ALIVE once it can accept IPC messages. It remains ALIVE only
1482 // while remote content is being actively used from this process.
1483 // After the state becaomes DEAD, some previously scheduled IPC
1484 // traffic may still pass through.
1485 enum class LifecycleState
: uint8_t {
1492 LifecycleState mLifecycleState
;
1494 uint8_t mIsForBrowser
: 1;
1496 // These variables track whether we've called Close() and KillHard() on our
1498 uint8_t mCalledClose
: 1;
1499 uint8_t mCalledKillHard
: 1;
1500 uint8_t mCreatedPairedMinidumps
: 1;
1501 uint8_t mShutdownPending
: 1;
1503 // Whether or not `LaunchSubprocessResolve` has been called, and whether or
1504 // not it returned `true` when called.
1505 uint8_t mLaunchResolved
: 1;
1506 uint8_t mLaunchResolvedOk
: 1;
1508 // True if the input event queue on the main thread of the content process is
1510 uint8_t mIsRemoteInputEventQueueEnabled
: 1;
1512 // True if we send input events with input priority. Otherwise, we send input
1513 // events with normal priority.
1514 uint8_t mIsInputPriorityEventEnabled
: 1;
1516 uint8_t mIsInPool
: 1;
1518 // True if we already created a GMP service.
1519 uint8_t mGMPCreated
: 1;
1521 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
1522 bool mNotifiedImpendingShutdownOnTabWillDestroy
= false;
1523 bool mBlockShutdownCalled
;
1526 nsCOMPtr
<nsIContentProcessInfo
> mScriptableHelper
;
1528 nsTArray
<nsCOMPtr
<nsIObserver
>> mIdleListeners
;
1531 // Dup of child's X socket, used to scope its resources to this
1532 // object instead of the child process's lifetime.
1533 UniqueFileHandle mChildXSocketFdDup
;
1536 RefPtr
<PProcessHangMonitorParent
> mHangMonitorActor
;
1538 UniquePtr
<gfx::DriverCrashGuard
> mDriverCrashGuard
;
1539 UniquePtr
<MemoryReportRequestHost
> mMemoryReportRequest
;
1541 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
1542 mozilla::UniquePtr
<SandboxBroker
> mSandboxBroker
;
1543 static mozilla::StaticAutoPtr
<SandboxBrokerPolicyFactory
>
1544 sSandboxBrokerPolicyFactory
;
1547 // This hashtable is used to run GetFilesHelper objects in the parent process.
1548 // GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest.
1549 nsRefPtrHashtable
<nsIDHashKey
, GetFilesHelper
> mGetFilesPendingRequests
;
1551 nsTHashSet
<nsCString
> mActivePermissionKeys
;
1552 nsTHashSet
<nsCString
> mActiveSecondaryPermissionKeys
;
1554 nsTArray
<nsCString
> mBlobURLs
;
1556 // This is intended to be a memory and time efficient means of determining
1557 // whether an origin has ever existed in a process so that Blob URL broadcast
1558 // doesn't need to transmit every Blob URL to every content process. False
1559 // positives are acceptable because receiving a Blob URL does not grant access
1560 // to its contents, and the act of creating/revoking a Blob is currently
1561 // viewed as an acceptable side-channel leak. In the future bug 1491018 will
1562 // moot the need for this structure.
1563 nsTArray
<uint64_t> mLoadedOriginHashes
;
1565 UniquePtr
<mozilla::ipc::CrashReporterHost
> mCrashReporter
;
1567 // Collects any pref changes that occur during process launch (after
1568 // the initial map is passed in command-line arguments) to be sent
1569 // when the process can receive IPC messages.
1570 nsTArray
<Pref
> mQueuedPrefs
;
1572 RefPtr
<mozilla::dom::ProcessMessageManager
> mMessageManager
;
1574 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
1575 // When set to true, indicates that content processes should
1576 // initialize their sandbox during startup instead of waiting
1577 // for the SetProcessSandbox IPDL message.
1578 static bool sEarlySandboxInit
;
1581 nsTHashSet
<RefPtr
<BrowsingContextGroup
>> mGroups
;
1583 // When we request a content process to load a document on our behalf, we'll
1584 // record the nsDocShellLoadState we sent to the content process mapped by the
1585 // load ID. If the load is then requested from the content process, we can
1586 // compare the load state and ensure it matches.
1587 nsTHashMap
<uint64_t, RefPtr
<nsDocShellLoadState
>> mPendingLoadStates
;
1589 // See `BrowsingContext::mEpochs` for an explanation of this field.
1590 uint64_t mBrowsingContextFieldEpoch
= 0;
1592 // A preference serializer used to share preferences with the process.
1593 // Cleared once startup is complete.
1594 UniquePtr
<mozilla::ipc::SharedPreferenceSerializer
> mPrefSerializer
;
1596 static uint32_t sMaxContentProcesses
;
1597 static uint32_t sPageLoadEventCounter
;
1599 bool mIsSignaledImpendingShutdown
= false;
1600 bool mIsNotifiedShutdownSuccess
= false;
1603 NS_DEFINE_STATIC_IID_ACCESSOR(ContentParent
, NS_CONTENTPARENT_IID
)
1605 // Threadsafe handle object allowing off-main-thread code to get some
1606 // information and maintain a weak reference to a ContentParent.
1607 class ThreadsafeContentParentHandle final
{
1608 friend class ContentParent
;
1611 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ThreadsafeContentParentHandle
);
1613 // Get the ChildID of this process. Safe to call from any thread.
1614 ContentParentId
ChildID() const { return mChildID
; }
1616 // Get the current RemoteType of this ContentParent. Safe to call from any
1617 // thread. If the returned RemoteType is PREALLOC_REMOTE_TYPE, it may change
1618 // again in the future.
1619 nsCString
GetRemoteType() MOZ_EXCLUDES(mMutex
);
1621 // Try to get a reference to the real `ContentParent` object from this weak
1622 // reference. This may only be called on the main thread.
1623 already_AddRefed
<ContentParent
> GetContentParent()
1624 MOZ_REQUIRES(sMainThreadCapability
) {
1625 return do_AddRef(mWeakActor
);
1628 // Calls `aCallback` with the current remote worker count and whether or not
1629 // shutdown has been started. If the callback returns `true`, registers a new
1630 // actor, and returns `true`, otherwise returns `false`.
1632 // NOTE: The internal mutex is held while evaluating `aCallback`.
1633 bool MaybeRegisterRemoteWorkerActor(
1634 MoveOnlyFunction
<bool(uint32_t, bool)> aCallback
) MOZ_EXCLUDES(mMutex
);
1636 // Like `MaybeRegisterRemoteWorkerActor`, but unconditional.
1637 void RegisterRemoteWorkerActor() MOZ_EXCLUDES(mMutex
) {
1638 MaybeRegisterRemoteWorkerActor([](uint32_t, bool) { return true; });
1641 RecursiveMutex
& Mutex() { return mMutex
; }
1644 ThreadsafeContentParentHandle(ContentParent
* aActor
, ContentParentId aChildID
,
1645 const nsACString
& aRemoteType
)
1646 : mChildID(aChildID
), mRemoteType(aRemoteType
), mWeakActor(aActor
) {}
1647 ~ThreadsafeContentParentHandle() { MOZ_ASSERT(!mWeakActor
); }
1649 mozilla::RecursiveMutex mMutex
{"ContentParentIdentity"};
1651 const ContentParentId mChildID
;
1653 nsCString mRemoteType
MOZ_GUARDED_BY(mMutex
);
1654 uint32_t mRemoteWorkerActorCount
MOZ_GUARDED_BY(mMutex
) = 0;
1655 bool mShutdownStarted
MOZ_GUARDED_BY(mMutex
) = false;
1657 // Weak reference to the actual ContentParent actor. Only touched on the main
1658 // thread to read or clear.
1659 ContentParent
* mWeakActor
MOZ_GUARDED_BY(sMainThreadCapability
);
1662 // This is the C++ version of remoteTypePrefix in E10SUtils.sys.mjs.
1663 const nsDependentCSubstring
RemoteTypePrefix(
1664 const nsACString
& aContentProcessType
);
1666 // This is based on isWebRemoteType in E10SUtils.sys.mjs.
1667 bool IsWebRemoteType(const nsACString
& aContentProcessType
);
1669 bool IsWebCoopCoepRemoteType(const nsACString
& aContentProcessType
);
1671 bool IsExtensionRemoteType(const nsACString
& aContentProcessType
);
1673 inline nsISupports
* ToSupports(mozilla::dom::ContentParent
* aContentParent
) {
1674 return static_cast<nsIDOMProcessParent
*>(aContentParent
);
1678 } // namespace mozilla
1680 class ParentIdleListener
: public nsIObserver
{
1681 friend class mozilla::dom::ContentParent
;
1687 ParentIdleListener(mozilla::dom::ContentParent
* aParent
, uint64_t aObserver
,
1689 : mParent(aParent
), mObserver(aObserver
), mTime(aTime
) {}
1692 virtual ~ParentIdleListener() = default;
1694 RefPtr
<mozilla::dom::ContentParent
> mParent
;
1699 #endif // mozilla_dom_ContentParent_h