tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ContentParent.h (71168B)


      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 "DriverCrashGuard.h"
     11 #include "MainThreadUtils.h"
     12 #include "PermissionMessageUtils.h"
     13 #include "mozilla/Attributes.h"
     14 #include "mozilla/DataMutex.h"
     15 #include "mozilla/HalTypes.h"
     16 #include "mozilla/IdleTaskRunner.h"
     17 #include "mozilla/LinkedList.h"
     18 #include "mozilla/Maybe.h"
     19 #include "mozilla/MemoryReportingProcess.h"
     20 #include "mozilla/MozPromise.h"
     21 #include "mozilla/RecursiveMutex.h"
     22 #include "mozilla/Result.h"
     23 #include "mozilla/StaticPtr.h"
     24 #include "mozilla/TimeStamp.h"
     25 #include "mozilla/UniquePtr.h"
     26 #include "mozilla/dom/JSProcessActorParent.h"
     27 #include "mozilla/dom/MediaSessionBinding.h"
     28 #include "mozilla/dom/MessageManagerCallback.h"
     29 #include "mozilla/dom/PContentParent.h"
     30 #include "mozilla/dom/ProcessActor.h"
     31 #include "mozilla/dom/ProcessIsolation.h"
     32 #include "mozilla/dom/RemoteBrowser.h"
     33 #include "mozilla/dom/RemoteType.h"
     34 #include "mozilla/dom/UniqueContentParentKeepAlive.h"
     35 #include "mozilla/dom/UserActivation.h"
     36 #include "mozilla/dom/ipc/IdType.h"
     37 #include "mozilla/gfx/GPUProcessListener.h"
     38 #include "mozilla/gfx/gfxVarReceiver.h"
     39 #include "mozilla/ipc/BackgroundUtils.h"
     40 #include "mozilla/ipc/GeckoChildProcessHost.h"
     41 #include "mozilla/ipc/InputStreamUtils.h"
     42 #include "mozilla/ipc/SharedMemoryHandle.h"
     43 #include "nsClassHashtable.h"
     44 #include "nsHashKeys.h"
     45 #include "nsIAsyncShutdown.h"
     46 #include "nsIDOMGeoPositionCallback.h"
     47 #include "nsIDOMGeoPositionErrorCallback.h"
     48 #include "nsIDOMProcessParent.h"
     49 #include "nsIInterfaceRequestor.h"
     50 #include "nsIObserver.h"
     51 #include "nsIReferrerInfo.h"
     52 #include "nsIRemoteTab.h"
     53 #include "nsITransferable.h"
     54 #include "nsIUrlClassifierFeature.h"
     55 #include "nsRefPtrHashtable.h"
     56 #include "nsTHashMap.h"
     57 #include "nsTHashSet.h"
     58 
     59 class nsConsoleService;
     60 class nsICycleCollectorLogSink;
     61 class nsIDumpGCAndCCLogsCallback;
     62 class nsIRemoteTab;
     63 class nsITimer;
     64 class ParentIdleListener;
     65 class nsIOriginsListLoadCallback;
     66 class nsIWidget;
     67 class nsIX509Cert;
     68 
     69 namespace CrashReporter {
     70 class CrashReporterInitArgs;
     71 }
     72 
     73 namespace mozilla {
     74 class PClipboardWriteRequestParent;
     75 class PRemoteSpellcheckEngineParent;
     76 
     77 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
     78 class SandboxBroker;
     79 class SandboxBrokerPolicyFactory;
     80 #endif
     81 
     82 class PreallocatedProcessManagerImpl;
     83 
     84 using mozilla::loader::PScriptCacheParent;
     85 
     86 namespace performance::pageload_event {
     87 class PageloadEventData;
     88 }  // namespace performance::pageload_event
     89 
     90 namespace ipc {
     91 class CrashReporterHost;
     92 class TestShellParent;
     93 class SharedPreferenceSerializer;
     94 }  // namespace ipc
     95 
     96 namespace layers {
     97 struct TextureFactoryIdentifier;
     98 }  // namespace layers
     99 
    100 namespace dom {
    101 
    102 class BrowsingContextGroup;
    103 class Element;
    104 class BrowserParent;
    105 class ClonedMessageData;
    106 class MemoryReport;
    107 class TabContext;
    108 class GetFilesHelper;
    109 class MemoryReportRequestHost;
    110 class RemoteWorkerDebuggerManagerParent;
    111 class RemoteWorkerManager;
    112 class RemoteWorkerServiceParent;
    113 class ThreadsafeContentParentHandle;
    114 struct CancelContentJSOptions;
    115 
    116 #define NS_CONTENTPARENT_IID \
    117  {0xeeec9ebf, 0x8ecf, 0x4e38, {0x81, 0xda, 0xb7, 0x34, 0x13, 0x7e, 0xac, 0xf3}}
    118 
    119 class ContentParent final : public PContentParent,
    120                            public nsIDOMProcessParent,
    121                            public nsIObserver,
    122                            public nsIDOMGeoPositionCallback,
    123                            public nsIDOMGeoPositionErrorCallback,
    124                            public nsIAsyncShutdownBlocker,
    125                            public nsIInterfaceRequestor,
    126                            public gfx::gfxVarReceiver,
    127                            public mozilla::LinkedListElement<ContentParent>,
    128                            public gfx::GPUProcessListener,
    129                            public mozilla::MemoryReportingProcess,
    130                            public mozilla::dom::ipc::MessageManagerCallback,
    131                            public mozilla::ipc::IShmemAllocator,
    132                            public ProcessActor {
    133  typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
    134  typedef mozilla::ipc::TestShellParent TestShellParent;
    135  typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
    136  typedef mozilla::dom::ClonedMessageData ClonedMessageData;
    137  typedef mozilla::dom::BrowsingContextGroup BrowsingContextGroup;
    138 
    139  friend class mozilla::PreallocatedProcessManagerImpl;
    140  friend class PContentParent;
    141  friend class mozilla::dom::RemoteWorkerManager;
    142  friend struct mozilla::dom::ContentParentKeepAliveDeleter;
    143 
    144 public:
    145  using LaunchPromise =
    146      mozilla::MozPromise<UniqueContentParentKeepAlive, nsresult, true>;
    147 
    148  NS_INLINE_DECL_STATIC_IID(NS_CONTENTPARENT_IID)
    149 
    150  static LogModule* GetLog();
    151 
    152  static ContentParent* Cast(PContentParent* aActor) {
    153    return static_cast<ContentParent*>(aActor);
    154  }
    155 
    156  /**
    157   * Create a ContentParent suitable for use later as a content process.
    158   */
    159  static UniqueContentParentKeepAlive MakePreallocProcess();
    160 
    161  /**
    162   * Start up the content-process machinery.  This might include
    163   * scheduling pre-launch tasks.
    164   */
    165  static void StartUp();
    166 
    167  /** Shut down the content-process machinery. */
    168  static void ShutDown();
    169 
    170  static uint32_t GetPoolSize(const nsACString& aContentProcessType);
    171 
    172  static uint32_t GetMaxProcessCount(const nsACString& aContentProcessType);
    173 
    174  static bool IsMaxProcessCountReached(const nsACString& aContentProcessType);
    175 
    176  static void ReleaseCachedProcesses();
    177 
    178  static void LogAndAssertFailedPrincipalValidationInfo(
    179      nsIPrincipal* aPrincipal, const char* aMethod);
    180 
    181  /**
    182   * Picks a random content parent from |aContentParents| respecting the index
    183   * limit set by |aMaxContentParents|. If |aBrowserId| is non-zero, that tab
    184   * will be ignored when counting tabs in this process.
    185   * Returns null if non available.
    186   */
    187  static already_AddRefed<ContentParent> MinTabSelect(
    188      const nsTArray<ContentParent*>& aContentParents,
    189      int32_t maxContentParents, uint64_t aBrowserId);
    190 
    191  /**
    192   * Get or create a content process which can be used for hosting web content
    193   * or workers.
    194   *
    195   * This method returns a |UniqueContentParentKeepAlive|, which manages the
    196   * lifecycle of the process. See the documentation on |AddKeepAlive| for more
    197   * information about managing content process lifecycles.
    198   *
    199   * The returned ContentParent which may still be in the process of launching.
    200   * Use the |WaitForLaunchAsync| or |WaitForLaunchSync| methods to wait for
    201   * this process to finish launching.
    202   *
    203   * @param aRemoteType Required remote type for new & used processes.
    204   * @param aGroup If specified, the |BrowsingContextGroup| requesting process
    205   *               selection. Used to ensure that only a single process per
    206   *               remoteType is used for each |BrowsingContextGroup|.
    207   * @param aPriority Initial process priority for a new content process.
    208   * @param aPreferUsed If true, process selection will prefer re-using an
    209   *                    existing ContentProcess over launching a new one.
    210   * @param aBrowserId The |BrowserId| requesting process selection. This
    211   *                   information is used to reduce unnecessary process churn
    212   *                   when navigating (see |MinTabSelect|).
    213   *                   The returned KeepAlive will be for this BrowserId.
    214   */
    215  static UniqueContentParentKeepAlive GetNewOrUsedLaunchingBrowserProcess(
    216      const nsACString& aRemoteType, BrowsingContextGroup* aGroup = nullptr,
    217      hal::ProcessPriority aPriority =
    218          hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
    219      bool aPreferUsed = false, uint64_t aBrowserId = 0);
    220 
    221  /**
    222   * Like |GetNewOrUsedLaunchingBrowserProcess|, but returns a promise which
    223   * resolves when the process is finished launching.
    224   */
    225  static RefPtr<ContentParent::LaunchPromise> GetNewOrUsedBrowserProcessAsync(
    226      const nsACString& aRemoteType, BrowsingContextGroup* aGroup = nullptr,
    227      hal::ProcessPriority aPriority =
    228          hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
    229      bool aPreferUsed = false, uint64_t aBrowserId = 0);
    230 
    231  /**
    232   * Like |GetNewOrUsedLaunchingBrowserProcess|, but blocks the main thread
    233   * until the process process is finished launching before returning.
    234   */
    235  static UniqueContentParentKeepAlive GetNewOrUsedBrowserProcess(
    236      const nsACString& aRemoteType, BrowsingContextGroup* aGroup = nullptr,
    237      hal::ProcessPriority aPriority =
    238          hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
    239      bool aPreferUsed = false, uint64_t aBrowserId = 0);
    240 
    241  /**
    242   * Create an nsITransferable with the specified data flavor types.
    243   */
    244  static mozilla::Result<nsCOMPtr<nsITransferable>, nsresult>
    245  CreateClipboardTransferable(const nsTArray<nsCString>& aTypes);
    246 
    247  /**
    248   * Asynchronously wait for this content process to finish launching, such that
    249   * the ContentParent actor is ready for IPC.
    250   *
    251   * @param aPriority The initial priority for the process after launching.
    252   * @param aBrowserId The BrowserId to hold a KeepAlive for during the async
    253   *                   launch which will be used to resolve the LaunchPromise.
    254   */
    255  RefPtr<ContentParent::LaunchPromise> WaitForLaunchAsync(
    256      hal::ProcessPriority aPriority =
    257          hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND,
    258      uint64_t aBrowserId = 0);
    259 
    260  /**
    261   * Like `WaitForLaunchAsync`, but synchronously blocks the main thread until
    262   * the content process has finished launching.
    263   */
    264  bool WaitForLaunchSync(hal::ProcessPriority aPriority =
    265                             hal::ProcessPriority::PROCESS_PRIORITY_FOREGROUND);
    266 
    267  /**
    268   * Get or create a content process for the given TabContext.  aFrameElement
    269   * should be the frame/iframe element with which this process will
    270   * associated.
    271   */
    272  static already_AddRefed<RemoteBrowser> CreateBrowser(
    273      const TabContext& aContext, Element* aFrameElement,
    274      const nsACString& aRemoteType, BrowsingContext* aBrowsingContext,
    275      ContentParent* aOpenerContentParent);
    276 
    277  /**
    278   * Get all content parents.
    279   *
    280   * # Lifetime
    281   *
    282   * These pointers are ONLY valid for synchronous use from the main thread.
    283   *
    284   * Do NOT attempt to use them after the main thread has had a chance to handle
    285   * messages or you could end up with dangling pointers.
    286   */
    287  static void GetAll(nsTArray<ContentParent*>& aArray);
    288 
    289  static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
    290 
    291  static void BroadcastStringBundle(const StringBundleDescriptor&);
    292 
    293  static void BroadcastShmBlockAdded(uint32_t aGeneration, uint32_t aIndex);
    294 
    295  static void BroadcastThemeUpdate(widget::ThemeChangeKind);
    296 
    297  static void BroadcastMediaCodecsSupportedUpdate(
    298      RemoteMediaIn aLocation, const media::MediaCodecsSupported& aSupported);
    299 
    300  const nsACString& GetRemoteType() const override;
    301 
    302  virtual void DoGetRemoteType(nsACString& aRemoteType,
    303                               ErrorResult& aError) const override {
    304    aRemoteType = GetRemoteType();
    305  }
    306 
    307  enum CPIteratorPolicy { eLive, eAll };
    308 
    309  class ContentParentIterator {
    310   private:
    311    ContentParent* mCurrent;
    312    CPIteratorPolicy mPolicy;
    313 
    314   public:
    315    ContentParentIterator(CPIteratorPolicy aPolicy, ContentParent* aCurrent)
    316        : mCurrent(aCurrent), mPolicy(aPolicy) {}
    317 
    318    ContentParentIterator begin() {
    319      // Move the cursor to the first element that matches the policy.
    320      while (mPolicy != eAll && mCurrent && !mCurrent->IsAlive()) {
    321        mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
    322      }
    323 
    324      return *this;
    325    }
    326    ContentParentIterator end() {
    327      return ContentParentIterator(mPolicy, nullptr);
    328    }
    329 
    330    const ContentParentIterator& operator++() {
    331      MOZ_ASSERT(mCurrent);
    332      do {
    333        mCurrent = mCurrent->LinkedListElement<ContentParent>::getNext();
    334      } while (mPolicy != eAll && mCurrent && !mCurrent->IsAlive());
    335 
    336      return *this;
    337    }
    338 
    339    bool operator!=(const ContentParentIterator& aOther) const {
    340      MOZ_ASSERT(mPolicy == aOther.mPolicy);
    341      return mCurrent != aOther.mCurrent;
    342    }
    343 
    344    ContentParent* operator*() { return mCurrent; }
    345  };
    346 
    347  static ContentParentIterator AllProcesses(CPIteratorPolicy aPolicy) {
    348    ContentParent* first =
    349        sContentParents ? sContentParents->getFirst() : nullptr;
    350    return ContentParentIterator(aPolicy, first);
    351  }
    352 
    353  static void NotifyUpdatedDictionaries();
    354 
    355  // Tell content processes the font list has changed. If aFullRebuild is true,
    356  // the shared list has been rebuilt and must be freshly mapped by child
    357  // processes; if false, existing mappings are still valid but the data has
    358  // been updated and so full reflows are in order.
    359  static void NotifyUpdatedFonts(bool aFullRebuild);
    360 
    361  mozilla::ipc::IPCResult RecvCreateClipboardContentAnalysis(
    362      Endpoint<PClipboardContentAnalysisParent>&& aParentEndpoint);
    363  mozilla::ipc::IPCResult RecvCreateGMPService();
    364 
    365  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver)
    366 
    367  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    368  NS_DECL_NSIDOMPROCESSPARENT
    369  NS_DECL_NSIOBSERVER
    370  NS_DECL_NSIDOMGEOPOSITIONCALLBACK
    371  NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
    372  NS_DECL_NSIASYNCSHUTDOWNBLOCKER
    373  NS_DECL_NSIINTERFACEREQUESTOR
    374 
    375  /**
    376   * MessageManagerCallback methods that we override.
    377   */
    378  virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
    379                                          bool aRunInGlobalScope) override;
    380 
    381  virtual nsresult DoSendAsyncMessage(const nsAString& aMessage,
    382                                      StructuredCloneData& aData) override;
    383 
    384  /*
    385   * Attempt to add a KeepAlive for the given BrowserId. A KeepAlive will try to
    386   * keep the process alive, though it may still die (e.g. due to a crash,
    387   * explicit shutdown request, or similar).
    388   *
    389   * The returned `UniqueContentParentKeepAlive` will clear this KeepAlive when
    390   * destroyed, and acts as a strong pointer to this `ContentParent`.
    391   *
    392   * Returns nullptr if the process is already being shut down.
    393   */
    394  [[nodiscard]] UniqueContentParentKeepAlive TryAddKeepAlive(
    395      uint64_t aBrowserId);
    396 
    397  /*
    398   * Like `TryAddKeepAlive`, but never returns `nullptr`, instead asserting if
    399   * the ContentParent is already shutting down.
    400   */
    401  [[nodiscard]] UniqueContentParentKeepAlive AddKeepAlive(uint64_t aBrowserId);
    402 
    403  /**
    404   * Check if this process is ready to be shut down, and if it is, begin the
    405   * shutdown process.  Automatically called whenever a KeepAlive is removed, or
    406   * a BrowserParent is removed.
    407   *
    408   * By default when a process becomes unused, it will be kept alive for a short
    409   * time, potentially allowing the process to be re-used.
    410   *
    411   * @param aImmediate If true, immediately begins shutdown if the process is
    412   *                   eligible, without any grace period for process re-use.
    413   * @param aIgnoreKeepAlivePref If true, the dom.ipc.keepProcessesAlive.*
    414   *                             preferences will be ignored, for clean-up of
    415   *                             cached processes. Requires aImmediate.
    416   */
    417  void MaybeBeginShutDown(bool aImmediate = false,
    418                          bool aIgnoreKeepAlivePref = false);
    419 
    420  TestShellParent* CreateTestShell();
    421 
    422  bool DestroyTestShell(TestShellParent* aTestShell);
    423 
    424  TestShellParent* GetTestShellSingleton();
    425 
    426  void ReportChildAlreadyBlocked();
    427 
    428  bool RequestRunToCompletion();
    429 
    430  void UpdateCookieStatus(nsIChannel* aChannel);
    431 
    432  bool IsLaunching() const {
    433    return mLifecycleState == LifecycleState::LAUNCHING;
    434  }
    435  bool IsAlive() const override;
    436  bool IsInitialized() const;
    437  bool IsSignaledImpendingShutdown() const {
    438    return mIsSignaledImpendingShutdown;
    439  }
    440  bool IsShuttingDown() const {
    441    return IsDead() || IsSignaledImpendingShutdown();
    442  }
    443  bool IsDead() const { return mLifecycleState == LifecycleState::DEAD; }
    444 
    445  bool IsForBrowser() const { return mIsForBrowser; }
    446 
    447  GeckoChildProcessHost* Process() const { return mSubprocess; }
    448 
    449  mozilla::dom::ProcessMessageManager* GetMessageManager() const {
    450    return mMessageManager;
    451  }
    452 
    453  bool NeedsPermissionsUpdate(const nsACString& aPermissionKey) const;
    454 
    455  // Getter for which permission keys should signal that a content
    456  // process needs to know about the change of a permission with this as the
    457  // secondary key, like for 3rdPartyFrameStorage^https://secondary.com
    458  bool NeedsSecondaryKeyPermissionsUpdate(
    459      const nsACString& aPermissionKey) const;
    460 
    461  // Manage pending load states which have been sent to this process, and are
    462  // expected to be used to start a load imminently.
    463  already_AddRefed<nsDocShellLoadState> TakePendingLoadStateForId(
    464      uint64_t aLoadIdentifier);
    465  void StorePendingLoadState(nsDocShellLoadState* aLoadState);
    466 
    467  /**
    468   * Kill our subprocess and make sure it dies.  Should only be used
    469   * in emergency situations since it bypasses the normal shutdown
    470   * process.
    471   *
    472   * WARNING: aReason appears in telemetry, so any new value passed in requires
    473   * data review.
    474   */
    475  void KillHard(const char* aReason);
    476 
    477  /**
    478   * Get a unique identifier for this child process. This ID is unique across
    479   * all types of child processes.
    480   *
    481   * NOTE: The `ContentParentId` wrapper type is a historical artifact from when
    482   * the ID was only specific to content processes.
    483   */
    484  ContentParentId ChildID() const { return mChildID; }
    485 
    486  /**
    487   * Get a user-friendly name for this ContentParent.  We make no guarantees
    488   * about this name: It might not be unique, apps can spoof special names,
    489   * etc.  So please don't use this name to make any decisions about the
    490   * ContentParent based on the value returned here.
    491   */
    492  void FriendlyName(nsAString& aName, bool aAnonymize = false);
    493 
    494  mozilla::ipc::IPCResult RecvInitCrashReporter(
    495      const CrashReporter::CrashReporterInitArgs& aInitArgs);
    496 
    497  already_AddRefed<PNeckoParent> AllocPNeckoParent();
    498 
    499  virtual mozilla::ipc::IPCResult RecvPNeckoConstructor(
    500      PNeckoParent* aActor) override {
    501    return PContentParent::RecvPNeckoConstructor(aActor);
    502  }
    503 
    504  mozilla::ipc::IPCResult RecvInitStreamFilter(
    505      const uint64_t& aChannelId, const nsAString& aAddonId,
    506      InitStreamFilterResolver&& aResolver);
    507 
    508  PHalParent* AllocPHalParent();
    509 
    510  virtual mozilla::ipc::IPCResult RecvPHalConstructor(
    511      PHalParent* aActor) override {
    512    return PContentParent::RecvPHalConstructor(aActor);
    513  }
    514 
    515  mozilla::ipc::IPCResult RecvAttributionEvent(
    516      const nsACString& aHost, PrivateAttributionImpressionType aType,
    517      uint32_t aIndex, const nsAString& aAd, const nsACString& aTargetHost);
    518  mozilla::ipc::IPCResult RecvAttributionConversion(
    519      const nsACString& aHost, const nsAString& aTask, uint32_t aHistogramSize,
    520      const Maybe<uint32_t>& aLookbackDays,
    521      const Maybe<PrivateAttributionImpressionType>& aImpressionType,
    522      const nsTArray<nsString>& aAds, const nsTArray<nsCString>& aSourceHosts);
    523 
    524  PHeapSnapshotTempFileHelperParent* AllocPHeapSnapshotTempFileHelperParent();
    525 
    526  PRemoteSpellcheckEngineParent* AllocPRemoteSpellcheckEngineParent();
    527 
    528  bool CycleCollectWithLogs(bool aDumpAllTraces,
    529                            nsICycleCollectorLogSink* aSink,
    530                            nsIDumpGCAndCCLogsCallback* aCallback);
    531 
    532  mozilla::ipc::IPCResult RecvNotifyTabDestroying(const TabId& aTabId,
    533                                                  const ContentParentId& aCpId);
    534 
    535  mozilla::ipc::IPCResult RecvFinishShutdown();
    536 
    537  mozilla::ipc::IPCResult RecvNotifyShutdownSuccess();
    538 
    539  PContentPermissionRequestParent* AllocPContentPermissionRequestParent(
    540      const nsTArray<PermissionRequest>& aRequests, nsIPrincipal* aPrincipal,
    541      nsIPrincipal* aTopLevelPrincipal, const bool& aIsHandlingUserInput,
    542      const bool& aMaybeUnsafePermissionDelegate, const TabId& aTabId);
    543 
    544  bool DeallocPContentPermissionRequestParent(
    545      PContentPermissionRequestParent* actor);
    546 
    547  void ForkNewProcess(bool aBlocking);
    548 
    549  mozilla::ipc::IPCResult RecvCreateWindow(
    550      PBrowserParent* aThisTab, const MaybeDiscarded<BrowsingContext>& aParent,
    551      PBrowserParent* aNewTab, const uint32_t& aChromeFlags,
    552      const bool& aCalledFromJS, const bool& aForPrinting,
    553      const bool& aForWindowDotPrint, const bool& aTopLevelCreatedByWebContent,
    554      nsIURI* aURIToLoad, const nsACString& aFeatures,
    555      const UserActivation::Modifiers& aModifiers,
    556      nsIPrincipal* aTriggeringPrincipal, nsIPolicyContainer* aPolicyContainer,
    557      nsIReferrerInfo* aReferrerInfo, const OriginAttributes& aOriginAttributes,
    558      bool aUserActivation, bool aTextDirectiveUserActivation,
    559      CreateWindowResolver&& aResolve);
    560 
    561  mozilla::ipc::IPCResult RecvCreateWindowInDifferentProcess(
    562      PBrowserParent* aThisTab, const MaybeDiscarded<BrowsingContext>& aParent,
    563      const uint32_t& aChromeFlags, const bool& aCalledFromJS,
    564      const bool& aTopLevelCreatedByWebContent, nsIURI* aURIToLoad,
    565      const nsACString& aFeatures, const UserActivation::Modifiers& aModifiers,
    566      const nsAString& aName, nsIPrincipal* aTriggeringPrincipal,
    567      nsIPolicyContainer* aPolicyContainer, nsIReferrerInfo* aReferrerInfo,
    568      const OriginAttributes& aOriginAttributes, bool aUserActivation,
    569      bool aTextDirectiveUserActivation);
    570 
    571  static void BroadcastBlobURLRegistration(
    572      const nsACString& aURI, BlobImpl* aBlobImpl, nsIPrincipal* aPrincipal,
    573      const nsCString& aPartitionKey, ContentParent* aIgnoreThisCP = nullptr);
    574 
    575  static void BroadcastBlobURLUnregistration(
    576      const nsTArray<BroadcastBlobURLUnregistrationRequest>& aRequests,
    577      ContentParent* aIgnoreThisCP = nullptr);
    578 
    579  mozilla::ipc::IPCResult RecvStoreAndBroadcastBlobURLRegistration(
    580      const nsACString& aURI, const IPCBlob& aBlob, nsIPrincipal* aPrincipal,
    581      const nsCString& aPartitionKey);
    582 
    583  mozilla::ipc::IPCResult RecvUnstoreAndBroadcastBlobURLUnregistration(
    584      const nsTArray<BroadcastBlobURLUnregistrationRequest>& aRequests);
    585 
    586  virtual int32_t Pid() const override;
    587 
    588  // PURLClassifierParent.
    589  PURLClassifierParent* AllocPURLClassifierParent(nsIPrincipal* aPrincipal,
    590                                                  bool* aSuccess);
    591  virtual mozilla::ipc::IPCResult RecvPURLClassifierConstructor(
    592      PURLClassifierParent* aActor, nsIPrincipal* aPrincipal,
    593      bool* aSuccess) override;
    594 
    595  // PURLClassifierLocalParent.
    596  PURLClassifierLocalParent* AllocPURLClassifierLocalParent(
    597      nsIURI* aURI, const nsTArray<IPCURLClassifierFeature>& aFeatures);
    598 
    599  virtual mozilla::ipc::IPCResult RecvPURLClassifierLocalConstructor(
    600      PURLClassifierLocalParent* aActor, nsIURI* aURI,
    601      nsTArray<IPCURLClassifierFeature>&& aFeatures) override;
    602 
    603  // PURLClassifierLocalByNameParent.
    604  PURLClassifierLocalByNameParent* AllocPURLClassifierLocalByNameParent(
    605      nsIURI* aURI, const nsTArray<nsCString>& aFeatures,
    606      const nsIUrlClassifierFeature::listType& aListType);
    607 
    608  virtual mozilla::ipc::IPCResult RecvPURLClassifierLocalByNameConstructor(
    609      PURLClassifierLocalByNameParent* aActor, nsIURI* aURI,
    610      nsTArray<nsCString>&& aFeatureNames,
    611      const nsIUrlClassifierFeature::listType& aListType) override;
    612 
    613  PSessionStorageObserverParent* AllocPSessionStorageObserverParent();
    614 
    615  virtual mozilla::ipc::IPCResult RecvPSessionStorageObserverConstructor(
    616      PSessionStorageObserverParent* aActor) override;
    617 
    618  bool DeallocPSessionStorageObserverParent(
    619      PSessionStorageObserverParent* aActor);
    620 
    621  bool DeallocPURLClassifierLocalByNameParent(
    622      PURLClassifierLocalByNameParent* aActor);
    623 
    624  bool DeallocPURLClassifierLocalParent(PURLClassifierLocalParent* aActor);
    625 
    626  bool DeallocPURLClassifierParent(PURLClassifierParent* aActor);
    627 
    628  // Use the PHangMonitor channel to ask the child to repaint a tab.
    629  void PaintTabWhileInterruptingJS(BrowserParent*);
    630 
    631  void UnloadLayersWhileInterruptingJS(BrowserParent*);
    632 
    633  void CancelContentJSExecutionIfRunning(
    634      BrowserParent* aBrowserParent,
    635      nsIRemoteTab::NavigationType aNavigationType,
    636      const CancelContentJSOptions& aCancelContentJSOptions);
    637 
    638  void SetMainThreadQoSPriority(nsIThread::QoSPriority aQoSPriority);
    639 
    640  // This function is called when we are about to load a document from an
    641  // HTTP(S) channel for a content process.  It is a useful place
    642  // to start to kick off work as early as possible in response to such
    643  // document loads.
    644  // aShouldWaitForPermissionCookieUpdate is set to true if main thread IPCs for
    645  // updating permissions/cookies are sent.
    646  nsresult AboutToLoadHttpDocumentForChild(
    647      nsIChannel* aChannel,
    648      bool* aShouldWaitForPermissionCookieUpdate = nullptr);
    649 
    650  // Send Blob URLs for this aPrincipal if they are not already known to this
    651  // content process and mark the process to receive any new/revoked Blob URLs
    652  // to this content process forever.
    653  void TransmitBlobURLsForPrincipal(nsIPrincipal* aPrincipal);
    654 
    655  // Update a cache list of allowed domains to store cookies for the current
    656  // process. This method is called when PCookieServiceParent actor is not
    657  // available yet.
    658  void AddPrincipalToCookieInProcessCache(nsIPrincipal* aPrincipal);
    659  void TakeCookieInProcessCache(nsTArray<nsCOMPtr<nsIPrincipal>>& aList);
    660 
    661  nsresult TransmitPermissionsForPrincipal(nsIPrincipal* aPrincipal);
    662 
    663  // Whenever receiving a Principal we need to validate that Principal case
    664  // by case, where we grant individual callsites to customize the checks!
    665  bool ValidatePrincipal(
    666      nsIPrincipal* aPrincipal,
    667      const EnumSet<ValidatePrincipalOptions>& aOptions = {});
    668 
    669  // This function is called in BrowsingContext immediately before IPC call to
    670  // load a URI. If aURI is a BlobURL, this method transmits all BlobURLs for
    671  // aURI's principal that were previously not transmitted. This allows for
    672  // opening a locally created BlobURL in a new tab.
    673  //
    674  // The reason all previously untransmitted Blobs are transmitted is that the
    675  // current BlobURL could contain html code, referring to another untransmitted
    676  // BlobURL.
    677  //
    678  // Should eventually be made obsolete by broader design changes that only
    679  // store BlobURLs in the parent process.
    680  void TransmitBlobDataIfBlobURL(nsIURI* aURI);
    681 
    682  void OnCompositorDeviceReset() override;
    683 
    684  // Control the priority of the IPC messages for input events.
    685  void SetInputPriorityEventEnabled(bool aEnabled);
    686  bool IsInputPriorityEventEnabled() { return mIsInputPriorityEventEnabled; }
    687 
    688  mozilla::ipc::IPCResult RecvCreateBrowsingContext(
    689      uint64_t aGroupId, BrowsingContext::IPCInitializer&& aInit);
    690 
    691  mozilla::ipc::IPCResult RecvDiscardBrowsingContext(
    692      const MaybeDiscarded<BrowsingContext>& aContext, bool aDoDiscard,
    693      DiscardBrowsingContextResolver&& aResolve);
    694 
    695  mozilla::ipc::IPCResult RecvWindowClose(
    696      const MaybeDiscarded<BrowsingContext>& aContext, bool aTrustedCaller);
    697  mozilla::ipc::IPCResult RecvWindowFocus(
    698      const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType,
    699      uint64_t aActionId);
    700  mozilla::ipc::IPCResult RecvWindowBlur(
    701      const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType);
    702  mozilla::ipc::IPCResult RecvRaiseWindow(
    703      const MaybeDiscarded<BrowsingContext>& aContext, CallerType aCallerType,
    704      uint64_t aActionId);
    705  mozilla::ipc::IPCResult RecvAdjustWindowFocus(
    706      const MaybeDiscarded<BrowsingContext>& aContext, bool aIsVisible,
    707      uint64_t aActionId, bool aShouldClearFocus,
    708      const MaybeDiscarded<BrowsingContext>& aAncestorBrowsingContextToFocus);
    709  mozilla::ipc::IPCResult RecvClearFocus(
    710      const MaybeDiscarded<BrowsingContext>& aContext);
    711  mozilla::ipc::IPCResult RecvSetFocusedBrowsingContext(
    712      const MaybeDiscarded<BrowsingContext>& aContext, uint64_t aActionId);
    713  mozilla::ipc::IPCResult RecvSetActiveBrowsingContext(
    714      const MaybeDiscarded<BrowsingContext>& aContext, uint64_t aActionId);
    715  mozilla::ipc::IPCResult RecvUnsetActiveBrowsingContext(
    716      const MaybeDiscarded<BrowsingContext>& aContext, uint64_t aActionId);
    717  mozilla::ipc::IPCResult RecvSetFocusedElement(
    718      const MaybeDiscarded<BrowsingContext>& aContext, bool aNeedsFocus);
    719  mozilla::ipc::IPCResult RecvFinalizeFocusOuter(
    720      const MaybeDiscarded<BrowsingContext>& aContext, bool aCanFocus,
    721      CallerType aCallerType);
    722  mozilla::ipc::IPCResult RecvInsertNewFocusActionId(uint64_t aActionId);
    723  mozilla::ipc::IPCResult RecvBlurToParent(
    724      const MaybeDiscarded<BrowsingContext>& aFocusedBrowsingContext,
    725      const MaybeDiscarded<BrowsingContext>& aBrowsingContextToClear,
    726      const MaybeDiscarded<BrowsingContext>& aAncestorBrowsingContextToFocus,
    727      bool aIsLeavingDocument, bool aAdjustWidget,
    728      bool aBrowsingContextToClearHandled,
    729      bool aAncestorBrowsingContextToFocusHandled, uint64_t aActionId);
    730  mozilla::ipc::IPCResult RecvMaybeExitFullscreen(
    731      const MaybeDiscarded<BrowsingContext>& aContext);
    732 
    733  mozilla::ipc::IPCResult RecvWindowPostMessage(
    734      const MaybeDiscarded<BrowsingContext>& aContext,
    735      const ClonedOrErrorMessageData& aMessage, const PostMessageData& aData);
    736 
    737  FORWARD_SHMEM_ALLOCATOR_TO(PContentParent)
    738 
    739  mozilla::ipc::IPCResult RecvBlobURLDataRequest(
    740      const nsACString& aBlobURL, nsIPrincipal* pTriggeringPrincipal,
    741      nsIPrincipal* pLoadingPrincipal,
    742      const OriginAttributes& aOriginAttributes, uint64_t aInnerWindowId,
    743      const nsCString& aPartitionKey, BlobURLDataRequestResolver&& aResolver);
    744 
    745 protected:
    746  bool CheckBrowsingContextEmbedder(CanonicalBrowsingContext* aBC,
    747                                    const char* aOperation) const;
    748 
    749  void ActorDestroy(ActorDestroyReason why) override;
    750 
    751  bool ShouldContinueFromReplyTimeout() override;
    752 
    753  void OnVarChanged(const nsTArray<GfxVarUpdate>& aVar) override;
    754  void OnCompositorUnexpectedShutdown() override;
    755 
    756 private:
    757  /**
    758   * A map of the remote content process type to a list of content parents
    759   * currently available to host *new* tabs/frames of that type.
    760   *
    761   * If a content process is identified as troubled or dead, it will be
    762   * removed from this list, but will still be in the sContentParents list for
    763   * the GetAll/GetAllEvenIfDead APIs.
    764   */
    765  static nsClassHashtable<nsCStringHashKey, nsTArray<ContentParent*>>*
    766      sBrowserContentParents;
    767  static mozilla::StaticAutoPtr<LinkedList<ContentParent>> sContentParents;
    768 
    769  void AddShutdownBlockers();
    770  void RemoveShutdownBlockers();
    771 
    772 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
    773  // Cached Mac sandbox params used when launching content processes.
    774  static mozilla::StaticAutoPtr<std::vector<std::string>> sMacSandboxParams;
    775 #endif
    776 
    777  // Set aLoadUri to true to load aURIToLoad and to false to only create the
    778  // window. aURIToLoad should always be provided, if available, to ensure
    779  // compatibility with GeckoView.
    780  mozilla::ipc::IPCResult CommonCreateWindow(
    781      PBrowserParent* aThisTab, BrowsingContext& aParent, bool aSetOpener,
    782      const uint32_t& aChromeFlags, const bool& aCalledFromJS,
    783      const bool& aForPrinting, const bool& aForWindowDotPrint,
    784      const bool& aIsTopLevelCreatedByWebContent, nsIURI* aURIToLoad,
    785      const nsACString& aFeatures, const UserActivation::Modifiers& aModifiers,
    786      BrowserParent* aNextRemoteBrowser, const nsAString& aName,
    787      nsresult& aResult, nsCOMPtr<nsIRemoteTab>& aNewRemoteTab,
    788      bool* aWindowIsNew, int32_t& aOpenLocation,
    789      nsIPrincipal* aTriggeringPrincipal, nsIReferrerInfo* aReferrerInfo,
    790      bool aLoadUri, nsIPolicyContainer* aPolicyContainer,
    791      const OriginAttributes& aOriginAttributes, bool aUserActivation,
    792      bool aTextDirectiveUserActivation);
    793 
    794  explicit ContentParent(const nsACString& aRemoteType);
    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   * Removing it from the static array so it won't be returned for new tabs in
    821   * GetNewOrUsedBrowserProcess.
    822   */
    823  void RemoveFromList();
    824 
    825  /**
    826   * Mark this ContentParent as dead for the purposes of Get*().
    827   * This method is idempotent.
    828   */
    829  void MarkAsDead();
    830 
    831  /**
    832   * Let the process know we are about to send a shutdown through a
    833   * non-mainthread side channel in order to bypass mainthread congestion.
    834   * This potentially cancels mainthread content JS execution.
    835   */
    836  void SignalImpendingShutdownToContentJS();
    837 
    838  /**
    839   * How we will shut down this ContentParent and its subprocess.
    840   */
    841  enum ShutDownMethod {
    842    // Send a shutdown message and wait for FinishShutdown call back.
    843    SEND_SHUTDOWN_MESSAGE,
    844    // Close the channel ourselves and let the subprocess clean up itself.
    845    CLOSE_CHANNEL,
    846  };
    847 
    848  void AsyncSendShutDownMessage();
    849 
    850  /**
    851   * Exit the subprocess and vamoose.  After this call IsAlive()
    852   * will return false and this ContentParent will not be returned
    853   * by the Get*() funtions.  However, the shutdown sequence itself
    854   * may be asynchronous.
    855   */
    856  bool ShutDownProcess(ShutDownMethod aMethod);
    857 
    858  // Perform any steps necesssary to gracefully shtudown the message
    859  // manager and null out mMessageManager.
    860  void ShutDownMessageManager();
    861 
    862  // Start the send shutdown timer on shutdown.
    863  void StartSendShutdownTimer();
    864 
    865  // Start the force-kill timer on shutdown.
    866  void StartForceKillTimer();
    867 
    868  // Ensure that the permissions for the giben Permission key are set in the
    869  // content process.
    870  //
    871  // See nsIPermissionManager::GetPermissionsForKey for more information on
    872  // these keys.
    873  void EnsurePermissionsByKey(const nsACString& aKey,
    874                              const nsACString& aOrigin);
    875 
    876  static void SendShutdownTimerCallback(nsITimer* aTimer, void* aClosure);
    877  static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
    878 
    879  bool CanOpenBrowser(const IPCTabContext& aContext);
    880 
    881  /**
    882   * Get or create the corresponding content parent array to
    883   * |aContentProcessType|.
    884   */
    885  static nsTArray<ContentParent*>& GetOrCreatePool(
    886      const nsACString& aContentProcessType);
    887 
    888  mozilla::ipc::IPCResult RecvInitBackground(
    889      Endpoint<mozilla::ipc::PBackgroundStarterParent>&& aEndpoint);
    890 
    891  mozilla::ipc::IPCResult RecvAddMemoryReport(const MemoryReport& aReport);
    892 
    893  bool DeallocPRemoteSpellcheckEngineParent(PRemoteSpellcheckEngineParent*);
    894 
    895  MOZ_CAN_RUN_SCRIPT_BOUNDARY
    896  mozilla::ipc::IPCResult RecvCloneDocumentTreeInto(
    897      const MaybeDiscarded<BrowsingContext>& aSource,
    898      const MaybeDiscarded<BrowsingContext>& aTarget, PrintData&& aPrintData);
    899 
    900  mozilla::ipc::IPCResult RecvUpdateRemotePrintSettings(
    901      const MaybeDiscarded<BrowsingContext>& aTarget, PrintData&& aPrintData);
    902 
    903  mozilla::ipc::IPCResult RecvConstructPopupBrowser(
    904      ManagedEndpoint<PBrowserParent>&& aBrowserEp,
    905      ManagedEndpoint<PWindowGlobalParent>&& windowEp, const TabId& tabId,
    906      const IPCTabContext& context, const WindowGlobalInit& initialWindowInit,
    907      const uint32_t& chromeFlags);
    908 
    909  mozilla::ipc::IPCResult RecvIsSecureURI(
    910      nsIURI* aURI, const OriginAttributes& aOriginAttributes,
    911      bool* aIsSecureURI);
    912 
    913  mozilla::ipc::IPCResult RecvAccumulateMixedContentHSTS(
    914      nsIURI* aURI, const bool& aActive,
    915      const OriginAttributes& aOriginAttributes);
    916 
    917  bool DeallocPHalParent(PHalParent*);
    918 
    919  bool DeallocPHeapSnapshotTempFileHelperParent(
    920      PHeapSnapshotTempFileHelperParent*);
    921 
    922  PCycleCollectWithLogsParent* AllocPCycleCollectWithLogsParent(
    923      const bool& aDumpAllTraces, const FileDescriptor& aGCLog,
    924      const FileDescriptor& aCCLog);
    925 
    926  bool DeallocPCycleCollectWithLogsParent(PCycleCollectWithLogsParent* aActor);
    927 
    928  PScriptCacheParent* AllocPScriptCacheParent(const FileDescOrError& cacheFile,
    929                                              const bool& wantCacheData);
    930 
    931  bool DeallocPScriptCacheParent(PScriptCacheParent* shell);
    932 
    933  already_AddRefed<PExternalHelperAppParent> AllocPExternalHelperAppParent(
    934      nsIURI* aUri, const mozilla::net::LoadInfoArgs& aLoadInfoArgs,
    935      const nsACString& aMimeContentType, const nsACString& aContentDisposition,
    936      const uint32_t& aContentDispositionHint,
    937      const nsAString& aContentDispositionFilename, const bool& aForceSave,
    938      const int64_t& aContentLength, const bool& aWasFileChannel,
    939      nsIURI* aReferrer, const MaybeDiscarded<BrowsingContext>& aContext);
    940 
    941  mozilla::ipc::IPCResult RecvPExternalHelperAppConstructor(
    942      PExternalHelperAppParent* actor, nsIURI* uri,
    943      const LoadInfoArgs& loadInfoArgs, const nsACString& aMimeContentType,
    944      const nsACString& aContentDisposition,
    945      const uint32_t& aContentDispositionHint,
    946      const nsAString& aContentDispositionFilename, const bool& aForceSave,
    947      const int64_t& aContentLength, const bool& aWasFileChannel,
    948      nsIURI* aReferrer,
    949      const MaybeDiscarded<BrowsingContext>& aContext) override;
    950 
    951  already_AddRefed<PHandlerServiceParent> AllocPHandlerServiceParent();
    952 
    953  PMediaParent* AllocPMediaParent();
    954 
    955  bool DeallocPMediaParent(PMediaParent* aActor);
    956 
    957 #ifdef MOZ_WEBSPEECH
    958  already_AddRefed<PSpeechSynthesisParent> AllocPSpeechSynthesisParent();
    959 
    960  virtual mozilla::ipc::IPCResult RecvPSpeechSynthesisConstructor(
    961      PSpeechSynthesisParent* aActor) override;
    962 #endif
    963 
    964  already_AddRefed<PWebBrowserPersistDocumentParent>
    965  AllocPWebBrowserPersistDocumentParent(
    966      PBrowserParent* aBrowser,
    967      const MaybeDiscarded<BrowsingContext>& aContext);
    968 
    969  mozilla::ipc::IPCResult RecvSetClipboard(
    970      const IPCTransferable& aTransferable,
    971      const nsIClipboard::ClipboardType& aWhichClipboard,
    972      const MaybeDiscarded<WindowContext>& aRequestingWindowContext);
    973 
    974  mozilla::ipc::IPCResult RecvGetClipboard(
    975      nsTArray<nsCString>&& aTypes,
    976      const nsIClipboard::ClipboardType& aWhichClipboard,
    977      const MaybeDiscarded<WindowContext>& aRequestingWindowContext,
    978      IPCTransferableDataOrError* aTransferableDataOrError);
    979 
    980  mozilla::ipc::IPCResult RecvEmptyClipboard(
    981      const nsIClipboard::ClipboardType& aWhichClipboard);
    982 
    983  mozilla::ipc::IPCResult RecvClipboardHasType(
    984      nsTArray<nsCString>&& aTypes,
    985      const nsIClipboard::ClipboardType& aWhichClipboard, bool* aHasType);
    986 
    987  mozilla::ipc::IPCResult RecvGetClipboardDataSnapshot(
    988      nsTArray<nsCString>&& aTypes,
    989      const nsIClipboard::ClipboardType& aWhichClipboard,
    990      const MaybeDiscarded<WindowContext>& aRequestingWindowContext,
    991      mozilla::NotNull<nsIPrincipal*> aRequestingPrincipal,
    992      GetClipboardDataSnapshotResolver&& aResolver);
    993 
    994  mozilla::ipc::IPCResult RecvGetClipboardDataSnapshotSync(
    995      nsTArray<nsCString>&& aTypes,
    996      const nsIClipboard::ClipboardType& aWhichClipboard,
    997      const MaybeDiscarded<WindowContext>& aRequestingWindowContext,
    998      ClipboardReadRequestOrError* aRequestOrError);
    999 
   1000  already_AddRefed<PClipboardWriteRequestParent>
   1001  AllocPClipboardWriteRequestParent(
   1002      const nsIClipboard::ClipboardType& aClipboardType,
   1003      const MaybeDiscarded<WindowContext>& aSettingWindowContext);
   1004 
   1005  mozilla::ipc::IPCResult RecvGetIconForExtension(const nsACString& aFileExt,
   1006                                                  const uint32_t& aIconSize,
   1007                                                  nsTArray<uint8_t>* bits);
   1008 
   1009  mozilla::ipc::IPCResult RecvStartVisitedQueries(
   1010      const nsTArray<RefPtr<nsIURI>>&);
   1011 
   1012  mozilla::ipc::IPCResult RecvSetURITitle(nsIURI* uri, const nsAString& title);
   1013 
   1014  mozilla::ipc::IPCResult RecvLoadURIExternal(
   1015      nsIURI* uri, nsIPrincipal* triggeringPrincipal,
   1016      nsIPrincipal* redirectPrincipal,
   1017      const MaybeDiscarded<BrowsingContext>& aContext,
   1018      bool aWasExternallyTriggered, bool aHasValidUserGestureActivation,
   1019      bool aNewWindowTarget);
   1020  mozilla::ipc::IPCResult RecvExtProtocolChannelConnectParent(
   1021      const uint64_t& registrarId);
   1022 
   1023  mozilla::ipc::IPCResult RecvSyncMessage(
   1024      const nsAString& aMsg, const ClonedMessageData& aData,
   1025      nsTArray<UniquePtr<StructuredCloneData>>* aRetvals);
   1026 
   1027  mozilla::ipc::IPCResult RecvAsyncMessage(const nsAString& aMsg,
   1028                                           const ClonedMessageData& aData);
   1029 
   1030  // MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
   1031  // in IPC code yet.
   1032  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   1033  mozilla::ipc::IPCResult RecvAddGeolocationListener(const bool& aHighAccuracy);
   1034  mozilla::ipc::IPCResult RecvRemoveGeolocationListener();
   1035 
   1036  // MOZ_CAN_RUN_SCRIPT_BOUNDARY because we don't have MOZ_CAN_RUN_SCRIPT bits
   1037  // in IPC code yet.
   1038  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   1039  mozilla::ipc::IPCResult RecvSetGeolocationHigherAccuracy(const bool& aEnable);
   1040 
   1041  mozilla::ipc::IPCResult RecvConsoleMessage(const nsAString& aMessage);
   1042 
   1043  mozilla::ipc::IPCResult RecvScriptError(
   1044      const nsAString& aMessage, const nsACString& aSourceName,
   1045      const uint32_t& aLineNumber, const uint32_t& aColNumber,
   1046      const uint32_t& aFlags, const nsACString& aCategory,
   1047      const bool& aIsFromPrivateWindow, const uint64_t& aInnerWindowId,
   1048      const bool& aIsFromChromeContext);
   1049 
   1050  mozilla::ipc::IPCResult RecvReportFrameTimingData(
   1051      const LoadInfoArgs& loadInfoArgs, const nsAString& entryName,
   1052      const nsAString& initiatorType, UniquePtr<PerformanceTimingData>&& aData);
   1053 
   1054  mozilla::ipc::IPCResult RecvScriptErrorWithStack(
   1055      const nsAString& aMessage, const nsACString& aSourceName,
   1056      const uint32_t& aLineNumber, const uint32_t& aColNumber,
   1057      const uint32_t& aFlags, const nsACString& aCategory,
   1058      const bool& aIsFromPrivateWindow, const bool& aIsFromChromeContext,
   1059      const ClonedMessageData& aStack);
   1060 
   1061 private:
   1062  mozilla::ipc::IPCResult RecvScriptErrorInternal(
   1063      const nsAString& aMessage, const nsACString& aSourceName,
   1064      const uint32_t& aLineNumber, const uint32_t& aColNumber,
   1065      const uint32_t& aFlags, const nsACString& aCategory,
   1066      const bool& aIsFromPrivateWindow, const bool& aIsFromChromeContext,
   1067      const ClonedMessageData* aStack = nullptr);
   1068 
   1069 public:
   1070  mozilla::ipc::IPCResult RecvCommitBrowsingContextTransaction(
   1071      const MaybeDiscarded<BrowsingContext>& aContext,
   1072      BrowsingContext::BaseTransaction&& aTransaction, uint64_t aEpoch);
   1073 
   1074  mozilla::ipc::IPCResult RecvCommitWindowContextTransaction(
   1075      const MaybeDiscarded<WindowContext>& aContext,
   1076      WindowContext::BaseTransaction&& aTransaction, uint64_t aEpoch);
   1077 
   1078  mozilla::ipc::IPCResult RecvAddSecurityState(
   1079      const MaybeDiscarded<WindowContext>& aContext, uint32_t aStateFlags);
   1080 
   1081  mozilla::ipc::IPCResult RecvFirstIdle();
   1082 
   1083  mozilla::ipc::IPCResult RecvDeviceReset();
   1084 
   1085  mozilla::ipc::IPCResult RecvCopyFavicon(nsIURI* aOldURI, nsIURI* aNewURI,
   1086                                          const bool& aInPrivateBrowsing);
   1087 
   1088  mozilla::ipc::IPCResult RecvFindImageText(IPCImage&&, nsTArray<nsCString>&&,
   1089                                            FindImageTextResolver&&);
   1090 
   1091  virtual void ProcessingError(Result aCode, const char* aMsgName) override;
   1092 
   1093  mozilla::ipc::IPCResult RecvGraphicsError(const nsACString& aError);
   1094 
   1095  mozilla::ipc::IPCResult RecvBeginDriverCrashGuard(const uint32_t& aGuardType,
   1096                                                    bool* aOutCrashed);
   1097 
   1098  mozilla::ipc::IPCResult RecvEndDriverCrashGuard(const uint32_t& aGuardType);
   1099 
   1100  mozilla::ipc::IPCResult RecvAddIdleObserver(const uint64_t& aObserverId,
   1101                                              const uint32_t& aIdleTimeInS);
   1102 
   1103  mozilla::ipc::IPCResult RecvRemoveIdleObserver(const uint64_t& aObserverId,
   1104                                                 const uint32_t& aIdleTimeInS);
   1105 
   1106  mozilla::ipc::IPCResult RecvBackUpXResources(
   1107      const FileDescriptor& aXSocketFd);
   1108 
   1109  mozilla::ipc::IPCResult RecvRequestAnonymousTemporaryFile(
   1110      const uint64_t& aID);
   1111 
   1112  mozilla::ipc::IPCResult RecvCreateAudioIPCConnection(
   1113      CreateAudioIPCConnectionResolver&& aResolver);
   1114 
   1115  already_AddRefed<extensions::PExtensionsParent> AllocPExtensionsParent();
   1116 
   1117 #ifdef MOZ_WEBRTC
   1118  PWebrtcGlobalParent* AllocPWebrtcGlobalParent();
   1119  bool DeallocPWebrtcGlobalParent(PWebrtcGlobalParent* aActor);
   1120 #endif
   1121 
   1122  mozilla::ipc::IPCResult RecvShutdownProfile(const nsACString& aProfile);
   1123 
   1124  mozilla::ipc::IPCResult RecvShutdownPerfStats(const nsACString& aPerfStats);
   1125 
   1126  mozilla::ipc::IPCResult RecvGetFontListShmBlock(
   1127      const uint32_t& aGeneration, const uint32_t& aIndex,
   1128      mozilla::ipc::ReadOnlySharedMemoryHandle* aOut);
   1129 
   1130  mozilla::ipc::IPCResult RecvInitializeFamily(const uint32_t& aGeneration,
   1131                                               const uint32_t& aFamilyIndex,
   1132                                               const bool& aLoadCmaps);
   1133 
   1134  mozilla::ipc::IPCResult RecvSetCharacterMap(const uint32_t& aGeneration,
   1135                                              const uint32_t& aFamilyIndex,
   1136                                              const bool& aAlias,
   1137                                              const uint32_t& aFaceIndex,
   1138                                              const gfxSparseBitSet& aMap);
   1139 
   1140  mozilla::ipc::IPCResult RecvInitOtherFamilyNames(const uint32_t& aGeneration,
   1141                                                   const bool& aDefer,
   1142                                                   bool* aLoaded);
   1143 
   1144  mozilla::ipc::IPCResult RecvSetupFamilyCharMap(const uint32_t& aGeneration,
   1145                                                 const uint32_t& aIndex,
   1146                                                 const bool& aAlias);
   1147 
   1148  mozilla::ipc::IPCResult RecvStartCmapLoading(const uint32_t& aGeneration,
   1149                                               const uint32_t& aStartIndex);
   1150 
   1151  mozilla::ipc::IPCResult RecvGetHyphDict(
   1152      nsIURI* aURIParams, mozilla::ipc::ReadOnlySharedMemoryHandle* aOutHandle);
   1153 
   1154  mozilla::ipc::IPCResult RecvNotifyPushObservers(const nsACString& aScope,
   1155                                                  nsIPrincipal* aPrincipal,
   1156                                                  const nsAString& aMessageId);
   1157 
   1158  mozilla::ipc::IPCResult RecvNotifyPushObserversWithData(
   1159      const nsACString& aScope, nsIPrincipal* aPrincipal,
   1160      const nsAString& aMessageId, nsTArray<uint8_t>&& aData);
   1161 
   1162  mozilla::ipc::IPCResult RecvPushError(const nsACString& aScope,
   1163                                        nsIPrincipal* aPrincipal,
   1164                                        const nsAString& aMessage,
   1165                                        const uint32_t& aFlags);
   1166 
   1167  mozilla::ipc::IPCResult RecvNotifyPushSubscriptionModifiedObservers(
   1168      const nsACString& aScope, nsIPrincipal* aPrincipal);
   1169 
   1170  mozilla::ipc::IPCResult RecvGetFilesRequest(
   1171      const nsID& aID, nsTArray<nsString>&& aDirectoryPaths,
   1172      const bool& aRecursiveFlag);
   1173 
   1174  mozilla::ipc::IPCResult RecvDeleteGetFilesRequest(const nsID& aID);
   1175 
   1176  mozilla::ipc::IPCResult RecvAccumulateChildHistograms(
   1177      nsTArray<HistogramAccumulation>&& aAccumulations);
   1178  mozilla::ipc::IPCResult RecvAccumulateChildKeyedHistograms(
   1179      nsTArray<KeyedHistogramAccumulation>&& aAccumulations);
   1180  mozilla::ipc::IPCResult RecvUpdateChildScalars(
   1181      nsTArray<ScalarAction>&& aScalarActions);
   1182  mozilla::ipc::IPCResult RecvUpdateChildKeyedScalars(
   1183      nsTArray<KeyedScalarAction>&& aScalarActions);
   1184  mozilla::ipc::IPCResult RecvRecordChildEvents(
   1185      nsTArray<ChildEventData>&& events);
   1186  mozilla::ipc::IPCResult RecvRecordDiscardedData(
   1187      const DiscardedData& aDiscardedData);
   1188  mozilla::ipc::IPCResult RecvRecordPageLoadEvent(
   1189      mozilla::performance::pageload_event::PageloadEventData&&
   1190          aPageLoadEventData,
   1191      const TimeStamp& aNavigationStartTime,
   1192      uint64_t aAndroidAppLinkLoadIdentifier);
   1193  mozilla::ipc::IPCResult RecvRecordOrigin(const uint32_t& aMetricId,
   1194                                           const nsACString& aOrigin);
   1195  mozilla::ipc::IPCResult RecvReportContentBlockingLog(
   1196      const IPCStream& aIPCStream);
   1197 
   1198  mozilla::ipc::IPCResult RecvBHRThreadHang(const HangDetails& aHangDetails);
   1199 
   1200  mozilla::ipc::IPCResult RecvAddCertException(
   1201      nsIX509Cert* aCert, const nsACString& aHostName, int32_t aPort,
   1202      const OriginAttributes& aOriginAttributes, bool aIsTemporary,
   1203      AddCertExceptionResolver&& aResolver);
   1204 
   1205  mozilla::ipc::IPCResult RecvAutomaticStorageAccessPermissionCanBeGranted(
   1206      nsIPrincipal* aPrincipal,
   1207      AutomaticStorageAccessPermissionCanBeGrantedResolver&& aResolver);
   1208 
   1209  mozilla::ipc::IPCResult RecvStorageAccessPermissionGrantedForOrigin(
   1210      uint64_t aTopLevelWindowId,
   1211      const MaybeDiscarded<BrowsingContext>& aParentContext,
   1212      nsIPrincipal* aTrackingPrincipal, const nsACString& aTrackingOrigin,
   1213      const int& aAllowMode,
   1214      const Maybe<
   1215          ContentBlockingNotifier::StorageAccessPermissionGrantedReason>&
   1216          aReason,
   1217      const bool& aFrameOnly,
   1218      StorageAccessPermissionGrantedForOriginResolver&& aResolver);
   1219 
   1220  mozilla::ipc::IPCResult RecvCompleteAllowAccessFor(
   1221      const MaybeDiscarded<BrowsingContext>& aParentContext,
   1222      uint64_t aTopLevelWindowId, nsIPrincipal* aTrackingPrincipal,
   1223      const nsACString& aTrackingOrigin, uint32_t aCookieBehavior,
   1224      const ContentBlockingNotifier::StorageAccessPermissionGrantedReason&
   1225          aReason,
   1226      CompleteAllowAccessForResolver&& aResolver);
   1227 
   1228  mozilla::ipc::IPCResult RecvSetAllowStorageAccessRequestFlag(
   1229      nsIPrincipal* aEmbeddedPrincipal, nsIURI* aEmbeddingOrigin,
   1230      SetAllowStorageAccessRequestFlagResolver&& aResolver);
   1231 
   1232  mozilla::ipc::IPCResult RecvTestAllowStorageAccessRequestFlag(
   1233      nsIPrincipal* aEmbeddingPrincipal, nsIURI* aEmbeddedOrigin,
   1234      TestAllowStorageAccessRequestFlagResolver&& aResolver);
   1235 
   1236  mozilla::ipc::IPCResult RecvStoreUserInteractionAsPermission(
   1237      nsIPrincipal* aPrincipal);
   1238 
   1239  mozilla::ipc::IPCResult RecvTestCookiePermissionDecided(
   1240      const MaybeDiscarded<BrowsingContext>& aContext, nsIPrincipal* aPrincipal,
   1241      const TestCookiePermissionDecidedResolver&& aResolver);
   1242 
   1243  mozilla::ipc::IPCResult RecvTestStorageAccessPermission(
   1244      nsIPrincipal* aEmbeddingPrincipal, const nsCString& aEmbeddedOrigin,
   1245      const TestStorageAccessPermissionResolver&& aResolver);
   1246 
   1247  mozilla::ipc::IPCResult RecvNotifyMediaPlaybackChanged(
   1248      const MaybeDiscarded<BrowsingContext>& aContext,
   1249      MediaPlaybackState aState);
   1250 
   1251  mozilla::ipc::IPCResult RecvNotifyMediaAudibleChanged(
   1252      const MaybeDiscarded<BrowsingContext>& aContext,
   1253      MediaAudibleState aState);
   1254 
   1255  mozilla::ipc::IPCResult RecvNotifyPictureInPictureModeChanged(
   1256      const MaybeDiscarded<BrowsingContext>& aContext, bool aEnabled);
   1257 
   1258  mozilla::ipc::IPCResult RecvNotifyMediaSessionUpdated(
   1259      const MaybeDiscarded<BrowsingContext>& aContext, bool aIsCreated);
   1260 
   1261  mozilla::ipc::IPCResult RecvNotifyUpdateMediaMetadata(
   1262      const MaybeDiscarded<BrowsingContext>& aContext,
   1263      const Maybe<MediaMetadataBase>& aMetadata);
   1264 
   1265  mozilla::ipc::IPCResult RecvNotifyMediaSessionPlaybackStateChanged(
   1266      const MaybeDiscarded<BrowsingContext>& aContext,
   1267      MediaSessionPlaybackState aPlaybackState);
   1268 
   1269  mozilla::ipc::IPCResult RecvNotifyMediaSessionSupportedActionChanged(
   1270      const MaybeDiscarded<BrowsingContext>& aContext,
   1271      MediaSessionAction aAction, bool aEnabled);
   1272 
   1273  mozilla::ipc::IPCResult RecvNotifyMediaFullScreenState(
   1274      const MaybeDiscarded<BrowsingContext>& aContext, bool aIsInFullScreen);
   1275 
   1276  mozilla::ipc::IPCResult RecvNotifyPositionStateChanged(
   1277      const MaybeDiscarded<BrowsingContext>& aContext,
   1278      const Maybe<PositionState>& aState);
   1279 
   1280  mozilla::ipc::IPCResult RecvNotifyGuessedPositionStateChanged(
   1281      const MaybeDiscarded<BrowsingContext>& aContext, const nsID& aMediaId,
   1282      const Maybe<PositionState>& aState);
   1283 
   1284  mozilla::ipc::IPCResult RecvAddOrRemovePageAwakeRequest(
   1285      const MaybeDiscarded<BrowsingContext>& aContext,
   1286      const bool& aShouldAddCount);
   1287 
   1288 #if defined(XP_WIN)
   1289  mozilla::ipc::IPCResult RecvGetModulesTrust(
   1290      ModulePaths&& aModPaths, bool aRunAtNormalPriority,
   1291      GetModulesTrustResolver&& aResolver);
   1292 #endif  // defined(XP_WIN)
   1293 
   1294  mozilla::ipc::IPCResult RecvReportServiceWorkerShutdownProgress(
   1295      uint32_t aShutdownStateId,
   1296      ServiceWorkerShutdownState::Progress aProgress);
   1297 
   1298  mozilla::ipc::IPCResult RecvRawMessage(
   1299      const JSActorMessageMeta& aMeta, JSIPCValue&& aData,
   1300      const UniquePtr<ClonedMessageData>& aStack);
   1301 
   1302  mozilla::ipc::IPCResult RecvAbortOtherOrientationPendingPromises(
   1303      const MaybeDiscarded<BrowsingContext>& aContext);
   1304 
   1305  mozilla::ipc::IPCResult RecvNotifyOnHistoryReload(
   1306      const MaybeDiscarded<BrowsingContext>& aContext, const bool& aForceReload,
   1307      NotifyOnHistoryReloadResolver&& aResolver);
   1308 
   1309  mozilla::ipc::IPCResult RecvHistoryCommit(
   1310      const MaybeDiscarded<BrowsingContext>& aContext, const uint64_t& aLoadID,
   1311      const nsID& aChangeID, const uint32_t& aLoadType,
   1312      const bool& aCloneEntryChildren, const bool& aChannelExpired,
   1313      const uint32_t& aCacheKey);
   1314 
   1315  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   1316  mozilla::ipc::IPCResult RecvHistoryGo(
   1317      const MaybeDiscarded<BrowsingContext>& aContext, int32_t aOffset,
   1318      uint64_t aHistoryEpoch, bool aRequireUserInteraction,
   1319      bool aUserActivation, bool aCheckForCancelation,
   1320      HistoryGoResolver&& aResolveRequestedIndex);
   1321 
   1322  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   1323  mozilla::ipc::IPCResult RecvNavigationTraverse(
   1324      const MaybeDiscarded<BrowsingContext>& aContext, const nsID& aKey,
   1325      uint64_t aHistoryEpoch, bool aUserActivation, bool aCheckForCancelation,
   1326      NavigationTraverseResolver&& aResolveRequestedIndex);
   1327 
   1328  mozilla::ipc::IPCResult RecvSynchronizeLayoutHistoryState(
   1329      const MaybeDiscarded<BrowsingContext>& aContext,
   1330      nsILayoutHistoryState* aState);
   1331 
   1332  mozilla::ipc::IPCResult RecvSessionHistoryEntryTitle(
   1333      const MaybeDiscarded<BrowsingContext>& aContext, const nsAString& aTitle);
   1334 
   1335  mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollRestorationIsManual(
   1336      const MaybeDiscarded<BrowsingContext>& aContext, const bool& aIsManual);
   1337 
   1338  mozilla::ipc::IPCResult RecvSessionHistoryEntryScrollPosition(
   1339      const MaybeDiscarded<BrowsingContext>& aContext, const int32_t& aX,
   1340      const int32_t& aY);
   1341 
   1342  mozilla::ipc::IPCResult RecvSessionHistoryEntryCacheKey(
   1343      const MaybeDiscarded<BrowsingContext>& aContext,
   1344      const uint32_t& aCacheKey);
   1345 
   1346  mozilla::ipc::IPCResult RecvSessionHistoryEntryWireframe(
   1347      const MaybeDiscarded<BrowsingContext>& aContext,
   1348      const Wireframe& aWireframe);
   1349 
   1350  mozilla::ipc::IPCResult
   1351  RecvSessionHistoryEntryStoreWindowNameInContiguousEntries(
   1352      const MaybeDiscarded<BrowsingContext>& aContext, const nsAString& aName);
   1353 
   1354  mozilla::ipc::IPCResult RecvGetLoadingSessionHistoryInfoFromParent(
   1355      const MaybeDiscarded<BrowsingContext>& aContext,
   1356      GetLoadingSessionHistoryInfoFromParentResolver&& aResolver);
   1357 
   1358  mozilla::ipc::IPCResult RecvSynchronizeNavigationAPIState(
   1359      const MaybeDiscarded<BrowsingContext>& aContext,
   1360      const ClonedMessageData& aState);
   1361 
   1362  mozilla::ipc::IPCResult RecvRemoveFromBFCache(
   1363      const MaybeDiscarded<BrowsingContext>& aContext);
   1364 
   1365  mozilla::ipc::IPCResult RecvSetActiveSessionHistoryEntry(
   1366      const MaybeDiscarded<BrowsingContext>& aContext,
   1367      const Maybe<nsPoint>& aPreviousScrollPos, SessionHistoryInfo&& aInfo,
   1368      uint32_t aLoadType, uint32_t aUpdatedCacheKey, const nsID& aChangeID);
   1369 
   1370  mozilla::ipc::IPCResult RecvReplaceActiveSessionHistoryEntry(
   1371      const MaybeDiscarded<BrowsingContext>& aContext,
   1372      SessionHistoryInfo&& aInfo);
   1373 
   1374  mozilla::ipc::IPCResult RecvRemoveDynEntriesFromActiveSessionHistoryEntry(
   1375      const MaybeDiscarded<BrowsingContext>& aContext);
   1376 
   1377  mozilla::ipc::IPCResult RecvRemoveFromSessionHistory(
   1378      const MaybeDiscarded<BrowsingContext>& aContext, const nsID& aChangeID);
   1379 
   1380  MOZ_CAN_RUN_SCRIPT_BOUNDARY
   1381  mozilla::ipc::IPCResult RecvHistoryReload(
   1382      const MaybeDiscarded<BrowsingContext>& aContext,
   1383      const uint32_t aReloadFlags);
   1384 
   1385  mozilla::ipc::IPCResult RecvConsumeHistoryActivation(
   1386      const MaybeDiscarded<BrowsingContext>& aTop);
   1387 
   1388  mozilla::ipc::IPCResult RecvCleanupPendingLoadState(uint64_t aLoadIdentifier);
   1389 
   1390  // Notify the ContentChild to enable the input event prioritization when
   1391  // initializing.
   1392  void MaybeEnableRemoteInputEventQueue();
   1393 
   1394 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
   1395  void AppendSandboxParams(std::vector<std::string>& aArgs);
   1396  void AppendDynamicSandboxParams(std::vector<std::string>& aArgs);
   1397 #endif
   1398 
   1399  mozilla::ipc::IPCResult RecvFOGData(ByteBuf&& buf);
   1400 
   1401  mozilla::ipc::IPCResult RecvGeckoTraceExport(ByteBuf&& aBuf);
   1402 
   1403  mozilla::ipc::IPCResult RecvSetContainerFeaturePolicy(
   1404      const MaybeDiscardedBrowsingContext& aContainerContext,
   1405      MaybeFeaturePolicyInfo&& aContainerFeaturePolicyInfo);
   1406 
   1407  mozilla::ipc::IPCResult RecvUpdateAncestorOriginsList(
   1408      const MaybeDiscardedBrowsingContext& aContext);
   1409 
   1410  mozilla::ipc::IPCResult RecvSetReferrerPolicyForEmbedderFrame(
   1411      const MaybeDiscardedBrowsingContext& aContext,
   1412      const ReferrerPolicy& aPolicy);
   1413 
   1414  mozilla::ipc::IPCResult RecvGetSystemIcon(nsIURI* aURI,
   1415                                            GetSystemIconResolver&& aResolver);
   1416 
   1417  mozilla::ipc::IPCResult RecvGetSystemGeolocationPermissionBehavior(
   1418      GetSystemGeolocationPermissionBehaviorResolver&& aResolver);
   1419 
   1420  MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult
   1421  RecvRequestGeolocationPermissionFromUser(
   1422      const MaybeDiscardedBrowsingContext& aBrowsingContext,
   1423      RequestGeolocationPermissionFromUserResolver&& aResolver);
   1424 
   1425 #ifdef FUZZING_SNAPSHOT
   1426  mozilla::ipc::IPCResult RecvSignalFuzzingReady();
   1427 #endif
   1428 
   1429 #ifdef FUZZING
   1430  mozilla::ipc::IPCResult RecvKillGPUProcess();
   1431 #endif
   1432 
   1433 public:
   1434  void SendGetFilesResponseAndForget(const nsID& aID,
   1435                                     const GetFilesResponseResult& aResult);
   1436 
   1437  bool SendRequestMemoryReport(const uint32_t& aGeneration,
   1438                               const bool& aAnonymize,
   1439                               const bool& aMinimizeMemoryUsage,
   1440                               const Maybe<FileDescriptor>& aDMDFile) override;
   1441 
   1442  void AddBrowsingContextGroup(BrowsingContextGroup* aGroup);
   1443  void RemoveBrowsingContextGroup(BrowsingContextGroup* aGroup);
   1444 
   1445  // See `BrowsingContext::mEpochs` for an explanation of this field.
   1446  uint64_t GetBrowsingContextFieldEpoch() const {
   1447    return mBrowsingContextFieldEpoch;
   1448  }
   1449 
   1450  uint32_t UpdateNetworkLinkType();
   1451 
   1452  already_AddRefed<JSActor> InitJSActor(JS::Handle<JSObject*> aMaybeActor,
   1453                                        const nsACString& aName,
   1454                                        ErrorResult& aRv) override;
   1455  mozilla::ipc::IProtocol* AsNativeActor() override { return this; }
   1456 
   1457  static already_AddRefed<nsIPrincipal> CreateRemoteTypeIsolationPrincipal(
   1458      const nsACString& aRemoteType);
   1459 
   1460 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   1461  bool IsBlockingShutdown() { return mBlockShutdownCalled; }
   1462 #endif
   1463 
   1464  ThreadsafeContentParentHandle* ThreadsafeHandle() const {
   1465    return mThreadsafeHandle;
   1466  }
   1467 
   1468  RemoteWorkerServiceParent* GetRemoteWorkerServiceParent() const {
   1469    return mRemoteWorkerServiceActor;
   1470  }
   1471 
   1472  void SetAndroidAppLinkLaunchType(uint64_t aLoadIdentifier,
   1473                                   int32_t aAppLinkLaunchType);
   1474  int32_t GetAndroidAppLinkLaunchType(uint64_t aLoadIdentifier);
   1475  void ClearAndroidAppLinkLaunchType(uint64_t aLoadIdentifier);
   1476 
   1477 private:
   1478  // Return an existing ContentParent if possible. Otherwise, `nullptr`.
   1479  static UniqueContentParentKeepAlive GetUsedBrowserProcess(
   1480      const nsACString& aRemoteType, nsTArray<ContentParent*>& aContentParents,
   1481      uint32_t aMaxContentParents, bool aPreferUsed, ProcessPriority aPriority,
   1482      uint64_t aBrowserId);
   1483 
   1484  void AddToPool(nsTArray<ContentParent*>&);
   1485  void RemoveFromPool(nsTArray<ContentParent*>&);
   1486  void AssertNotInPool();
   1487 
   1488  void RemoveKeepAlive(uint64_t aBrowserId);
   1489 
   1490  void AssertAlive();
   1491 
   1492  void StartRemoteWorkerService();
   1493 
   1494  void RecordAndroidAppLinkTelemetry(
   1495      mozilla::performance::pageload_event::PageloadEventData*
   1496          aPageLoadEventData,
   1497      const TimeStamp& aNavStartTime, uint64_t aAppLinkLaunchTypeIdentifier);
   1498 
   1499 private:
   1500  // If you add strong pointers to cycle collected objects here, be sure to
   1501  // release these objects in ShutDownProcess.  See the comment there for more
   1502  // details.
   1503 
   1504  GeckoChildProcessHost* mSubprocess;
   1505  const TimeStamp mLaunchTS;  // used to calculate time to start content process
   1506  TimeStamp mLaunchYieldTS;   // used to calculate async launch main thread time
   1507 
   1508  bool mIsAPreallocBlocker;  // We called AddBlocker for this ContentParent
   1509 
   1510  nsCString mRemoteType;
   1511  nsCString mProfile;
   1512  nsCOMPtr<nsIPrincipal> mRemoteTypeIsolationPrincipal;
   1513 
   1514  ContentParentId mChildID;
   1515  int32_t mGeolocationWatchID;
   1516 
   1517  // After we destroy the last Browser, we also start a timer to ensure
   1518  // that even content processes that are not responding will get a
   1519  // second chance and a shutdown message.
   1520  nsCOMPtr<nsITimer> mSendShutdownTimer;
   1521  bool mSentShutdownMessage = false;
   1522 
   1523  // After we initiate shutdown, we also start a timer to ensure
   1524  // that even content processes that are 100% blocked (say from
   1525  // SIGSTOP), are still killed eventually.  This task enforces that
   1526  // timer.
   1527  nsCOMPtr<nsITimer> mForceKillTimer;
   1528 
   1529  // Threadsafe handle object which can be used by actors like PBackground to
   1530  // track the identity and other relevant information about the content process
   1531  // they're attached to.
   1532  const RefPtr<ThreadsafeContentParentHandle> mThreadsafeHandle;
   1533 
   1534  // The process starts in the LAUNCHING state, and transitions to
   1535  // ALIVE once it can accept IPC messages.  It remains ALIVE only
   1536  // while remote content is being actively used from this process.
   1537  // After the state becaomes DEAD, some previously scheduled IPC
   1538  // traffic may still pass through.
   1539  enum class LifecycleState : uint8_t {
   1540    LAUNCHING,
   1541    ALIVE,
   1542    INITIALIZED,
   1543    DEAD,
   1544  };
   1545 
   1546  LifecycleState mLifecycleState;
   1547 
   1548  uint8_t mIsForBrowser : 1;
   1549 
   1550  // These variables track whether we've called Close() and KillHard() on our
   1551  // channel.
   1552  uint8_t mCalledClose : 1;
   1553  uint8_t mCalledKillHard : 1;
   1554  uint8_t mCreatedPairedMinidumps : 1;
   1555  uint8_t mShutdownPending : 1;
   1556 
   1557  // Whether or not `LaunchSubprocessResolve` has been called, and whether or
   1558  // not it returned `true` when called.
   1559  uint8_t mLaunchResolved : 1;
   1560  uint8_t mLaunchResolvedOk : 1;
   1561 
   1562  // True if the input event queue on the main thread of the content process is
   1563  // enabled.
   1564  uint8_t mIsRemoteInputEventQueueEnabled : 1;
   1565 
   1566  // True if we send input events with input priority. Otherwise, we send input
   1567  // events with normal priority.
   1568  uint8_t mIsInputPriorityEventEnabled : 1;
   1569 
   1570  uint8_t mIsInPool : 1;
   1571 
   1572  // True if we already created a GMP service.
   1573  uint8_t mGMPCreated : 1;
   1574  // True if we already created the
   1575  // ClipboardContentAnalysis actor
   1576  uint8_t mClipboardContentAnalysisCreated : 1;
   1577 
   1578 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
   1579  bool mBlockShutdownCalled;
   1580 #endif
   1581 
   1582  nsTArray<nsCOMPtr<nsIObserver>> mIdleListeners;
   1583 
   1584 #ifdef MOZ_X11
   1585  // Dup of child's X socket, used to scope its resources to this
   1586  // object instead of the child process's lifetime.
   1587  UniqueFileHandle mChildXSocketFdDup;
   1588 #endif
   1589 
   1590  RefPtr<PProcessHangMonitorParent> mHangMonitorActor;
   1591 
   1592  RefPtr<RemoteWorkerServiceParent> mRemoteWorkerServiceActor;
   1593 
   1594  RefPtr<RemoteWorkerDebuggerManagerParent> mRemoteWorkerDebuggerManagerActor;
   1595 
   1596  UniquePtr<gfx::DriverCrashGuard> mDriverCrashGuard;
   1597  UniquePtr<MemoryReportRequestHost> mMemoryReportRequest;
   1598 
   1599 #if defined(XP_LINUX) && defined(MOZ_SANDBOX)
   1600  RefPtr<SandboxBroker> mSandboxBroker;
   1601  static mozilla::StaticAutoPtr<SandboxBrokerPolicyFactory>
   1602      sSandboxBrokerPolicyFactory;
   1603 #endif
   1604 
   1605  // This hashtable is used to run GetFilesHelper objects in the parent process.
   1606  // GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest.
   1607  nsRefPtrHashtable<nsIDHashKey, GetFilesHelper> mGetFilesPendingRequests;
   1608 
   1609  nsTHashSet<nsCString> mActivePermissionKeys;
   1610  nsTHashSet<nsCString> mActiveSecondaryPermissionKeys;
   1611 
   1612  nsTArray<nsCOMPtr<nsIPrincipal>> mCookieInContentListCache;
   1613 
   1614  // This is intended to be a memory and time efficient means of determining
   1615  // whether an origin has ever existed in a process so that Blob URL broadcast
   1616  // doesn't need to transmit every Blob URL to every content process. False
   1617  // positives are acceptable because receiving a Blob URL does not grant access
   1618  // to its contents, and the act of creating/revoking a Blob is currently
   1619  // viewed as an acceptable side-channel leak. In the future bug 1491018 will
   1620  // moot the need for this structure.
   1621  nsTArray<uint64_t> mLoadedOriginHashes;
   1622 
   1623  // Map from android load identifier to app link launch type
   1624  // We do this to avoid sending the app link launch type to the content process
   1625  nsTHashMap<uint64_t, int32_t> mAndroidLoadIdentifierToAppLinkLaunchType;
   1626 
   1627  UniquePtr<mozilla::ipc::CrashReporterHost> mCrashReporter;
   1628 
   1629  // Collects any pref changes that occur during process launch (after
   1630  // the initial map is passed in command-line arguments) to be sent
   1631  // when the process can receive IPC messages.
   1632  nsTArray<Pref> mQueuedPrefs;
   1633 
   1634  RefPtr<mozilla::dom::ProcessMessageManager> mMessageManager;
   1635 
   1636 #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
   1637  // When set to true, indicates that content processes should
   1638  // initialize their sandbox during startup instead of waiting
   1639  // for the SetProcessSandbox IPDL message.
   1640  static bool sEarlySandboxInit;
   1641 #endif
   1642 
   1643  nsTHashSet<RefPtr<BrowsingContextGroup>> mGroups;
   1644 
   1645  // When we request a content process to load a document on our behalf, we'll
   1646  // record the nsDocShellLoadState we sent to the content process mapped by the
   1647  // load ID. If the load is then requested from the content process, we can
   1648  // compare the load state and ensure it matches.
   1649  nsTHashMap<uint64_t, RefPtr<nsDocShellLoadState>> mPendingLoadStates;
   1650 
   1651  // See `BrowsingContext::mEpochs` for an explanation of this field.
   1652  uint64_t mBrowsingContextFieldEpoch = 0;
   1653 
   1654  // A preference serializer used to share preferences with the process.
   1655  // Cleared once startup is complete.
   1656  UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
   1657 
   1658  RefPtr<IdleTaskRunner> mMaybeBeginShutdownRunner;
   1659 
   1660  static uint32_t sMaxContentProcesses;
   1661 
   1662  bool mIsSignaledImpendingShutdown = false;
   1663  bool mIsNotifiedShutdownSuccess = false;
   1664 
   1665  nsCOMPtr<nsIThread> mClipboardContentAnalysisThread;
   1666 
   1667 #ifdef MOZ_WMF_CDM
   1668  RefPtr<nsIOriginsListLoadCallback> mOriginsListCallback;
   1669 #endif
   1670 };
   1671 
   1672 // Threadsafe handle object allowing off-main-thread code to get some
   1673 // information and maintain a weak reference to a ContentParent.
   1674 class ThreadsafeContentParentHandle final {
   1675  friend class ContentParent;
   1676 
   1677 public:
   1678  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ThreadsafeContentParentHandle);
   1679 
   1680  // Get the ChildID of this process. Safe to call from any thread.
   1681  ContentParentId ChildID() const { return mChildID; }
   1682 
   1683  // Get the current RemoteType of this ContentParent. Safe to call from any
   1684  // thread. If the returned RemoteType is PREALLOC_REMOTE_TYPE, it may change
   1685  // again in the future.
   1686  nsCString GetRemoteType() MOZ_EXCLUDES(mMutex);
   1687 
   1688  // Try to get a reference to the real `ContentParent` object from this weak
   1689  // reference. This may only be called on the main thread.
   1690  already_AddRefed<ContentParent> GetContentParent()
   1691      MOZ_REQUIRES(sMainThreadCapability) {
   1692    return do_AddRef(mWeakActor);
   1693  }
   1694 
   1695  // Attempt to add a KeepAlive for the given BrowserId. A KeepAlive will try to
   1696  // keep the process alive, though it may still die (e.g. due to a crash,
   1697  // explicit shutdown request, or similar).
   1698  //
   1699  // Returns nullptr if the process is already being shut down.
   1700  //
   1701  // May be called from any thread.
   1702  [[nodiscard]] UniqueThreadsafeContentParentKeepAlive TryAddKeepAlive(
   1703      uint64_t aBrowserId = 0) MOZ_EXCLUDES(mMutex);
   1704 
   1705 private:
   1706  ThreadsafeContentParentHandle(ContentParent* aActor, ContentParentId aChildID,
   1707                                const nsACString& aRemoteType)
   1708      : mChildID(aChildID), mRemoteType(aRemoteType), mWeakActor(aActor) {}
   1709  ~ThreadsafeContentParentHandle() { MOZ_ASSERT(!mWeakActor); }
   1710 
   1711  mozilla::RecursiveMutex mMutex{"ContentParentIdentity"};
   1712 
   1713  const ContentParentId mChildID;
   1714 
   1715  nsCString mRemoteType MOZ_GUARDED_BY(mMutex);
   1716 
   1717  // Keepalives for this browser, keyed by BrowserId. A BrowserId of `0` is used
   1718  // for non-tab code keeping the process alive (such as for workers).
   1719  // Each KeepAlive increments the corresponding BrowserId's counter, and the
   1720  // process will begin shutdown when the last KeepAlive is removed.
   1721  // FIXME: These sets are probably quite small, so it might make sense to avoid
   1722  // hashtable storage.
   1723  nsTHashMap<uint64_t, uint32_t> mKeepAlivesPerBrowserId MOZ_GUARDED_BY(mMutex);
   1724 
   1725  // If set, the browser is shutting down, and new workers or tabs should not be
   1726  // created in this process.
   1727  bool mShutdownStarted MOZ_GUARDED_BY(mMutex) = false;
   1728 
   1729  // Weak reference to the actual ContentParent actor. Only touched on the main
   1730  // thread to read or clear.
   1731  ContentParent* mWeakActor MOZ_GUARDED_BY(sMainThreadCapability);
   1732 };
   1733 
   1734 // This is the C++ version of remoteTypePrefix in E10SUtils.sys.mjs.
   1735 nsDependentCSubstring RemoteTypePrefix(const nsACString& aContentProcessType);
   1736 
   1737 // This is based on isWebRemoteType in E10SUtils.sys.mjs.
   1738 bool IsWebRemoteType(const nsACString& aContentProcessType);
   1739 
   1740 bool IsWebCoopCoepRemoteType(const nsACString& aContentProcessType);
   1741 
   1742 bool IsExtensionRemoteType(const nsACString& aContentProcessType);
   1743 
   1744 inline nsISupports* ToSupports(mozilla::dom::ContentParent* aContentParent) {
   1745  return static_cast<nsIDOMProcessParent*>(aContentParent);
   1746 }
   1747 
   1748 }  // namespace dom
   1749 }  // namespace mozilla
   1750 
   1751 class ParentIdleListener : public nsIObserver {
   1752  friend class mozilla::dom::ContentParent;
   1753 
   1754 public:
   1755  NS_DECL_ISUPPORTS
   1756  NS_DECL_NSIOBSERVER
   1757 
   1758  ParentIdleListener(mozilla::dom::ContentParent* aParent, uint64_t aObserver,
   1759                     uint32_t aTime)
   1760      : mParent(aParent), mObserver(aObserver), mTime(aTime) {}
   1761 
   1762 private:
   1763  virtual ~ParentIdleListener() = default;
   1764 
   1765  RefPtr<mozilla::dom::ContentParent> mParent;
   1766  uint64_t mObserver;
   1767  uint32_t mTime;
   1768 };
   1769 
   1770 #endif  // mozilla_dom_ContentParent_h