tor-browser

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

ContentProcessManager.h (2861B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_ContentProcessManager_h
      8 #define mozilla_dom_ContentProcessManager_h
      9 
     10 #include "mozilla/StaticPtr.h"
     11 #include "mozilla/dom/TabContext.h"
     12 #include "mozilla/dom/ipc/IdType.h"
     13 #include "nsTArray.h"
     14 #include "nsTHashMap.h"
     15 
     16 namespace mozilla::dom {
     17 class ContentParent;
     18 
     19 class ContentProcessManager final {
     20 public:
     21  static ContentProcessManager* GetSingleton();
     22  MOZ_COUNTED_DTOR(ContentProcessManager);
     23 
     24  /**
     25   * Add a new content process into the map.
     26   */
     27  void AddContentProcess(ContentParent* aChildCp);
     28 
     29  /**
     30   * Remove the content process by id.
     31   */
     32  void RemoveContentProcess(const ContentParentId& aChildCpId);
     33 
     34  /**
     35   * Return the ContentParent pointer by id.
     36   */
     37  ContentParent* GetContentProcessById(const ContentParentId& aChildCpId);
     38 
     39  /**
     40   * Add a new browser parent into the map.
     41   */
     42  bool RegisterRemoteFrame(BrowserParent* aChildBp);
     43 
     44  /**
     45   * Remove the browser parent by the given tab id.
     46   */
     47  void UnregisterRemoteFrame(const TabId& aChildTabId);
     48 
     49  /**
     50   * Get the ContentParentId of the parent of the given tab id.
     51   */
     52  ContentParentId GetTabProcessId(const TabId& aChildTabId);
     53 
     54  /**
     55   * Get the number of BrowserParents managed by the givent content process.
     56   * Return 0 when ContentParent couldn't be found via aChildCpId.
     57   */
     58  uint32_t GetBrowserParentCountByProcessId(const ContentParentId& aChildCpId);
     59 
     60  /**
     61   * Get the BrowserParent by the given content process and tab id.
     62   * Return nullptr when BrowserParent couldn't be found via aChildCpId
     63   * and aChildTabId.
     64   */
     65  already_AddRefed<BrowserParent> GetBrowserParentByProcessAndTabId(
     66      const ContentParentId& aChildCpId, const TabId& aChildTabId);
     67 
     68  /**
     69   * Get the BrowserParent on top level by the given content process and tab id.
     70   *
     71   * This function returns the BrowserParent directly within a BrowserHost,
     72   * called top-level BrowserParent here, by given aChildCpId and aChildTabId.
     73   * The given aChildCpId and aChildTabId are related to a content process
     74   * and a tab respectively.
     75   */
     76  already_AddRefed<BrowserParent> GetTopLevelBrowserParentByProcessAndTabId(
     77      const ContentParentId& aChildCpId, const TabId& aChildTabId);
     78 
     79 private:
     80  static StaticAutoPtr<ContentProcessManager> sSingleton;
     81 
     82  nsTHashMap<nsUint64HashKey, ContentParent*> mContentParentMap;
     83  nsTHashMap<nsUint64HashKey, BrowserParent*> mBrowserParentMap;
     84 
     85  MOZ_COUNTED_DEFAULT_CTOR(ContentProcessManager);
     86 };
     87 
     88 }  // namespace mozilla::dom
     89 
     90 #endif  // mozilla_dom_ContentProcessManager_h