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/. */
7 #ifndef mozilla_dom_ContentProcessManager_h
8 #define mozilla_dom_ContentProcessManager_h
10 #include "mozilla/StaticPtr.h"
11 #include "mozilla/dom/TabContext.h"
12 #include "mozilla/dom/ipc/IdType.h"
14 #include "nsTHashMap.h"
16 namespace mozilla::dom
{
19 class ContentProcessManager final
{
21 static ContentProcessManager
* GetSingleton();
22 MOZ_COUNTED_DTOR(ContentProcessManager
);
25 * Add a new content process into the map.
27 void AddContentProcess(ContentParent
* aChildCp
);
30 * Remove the content process by id.
32 void RemoveContentProcess(const ContentParentId
& aChildCpId
);
35 * Return the ContentParent pointer by id.
37 ContentParent
* GetContentProcessById(const ContentParentId
& aChildCpId
);
40 * Add a new browser parent into the map.
42 bool RegisterRemoteFrame(BrowserParent
* aChildBp
);
45 * Remove the browser parent by the given tab id.
47 void UnregisterRemoteFrame(const TabId
& aChildTabId
);
50 * Get the ContentParentId of the parent of the given tab id.
52 ContentParentId
GetTabProcessId(const TabId
& aChildTabId
);
55 * Get the number of BrowserParents managed by the givent content process.
56 * Return 0 when ContentParent couldn't be found via aChildCpId.
58 uint32_t GetBrowserParentCountByProcessId(const ContentParentId
& aChildCpId
);
61 * Get the BrowserParent by the given content process and tab id.
62 * Return nullptr when BrowserParent couldn't be found via aChildCpId
65 already_AddRefed
<BrowserParent
> GetBrowserParentByProcessAndTabId(
66 const ContentParentId
& aChildCpId
, const TabId
& aChildTabId
);
69 * Get the BrowserParent on top level by the given content process and tab id.
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.
76 already_AddRefed
<BrowserParent
> GetTopLevelBrowserParentByProcessAndTabId(
77 const ContentParentId
& aChildCpId
, const TabId
& aChildTabId
);
80 static StaticAutoPtr
<ContentProcessManager
> sSingleton
;
82 nsTHashMap
<nsUint64HashKey
, ContentParent
*> mContentParentMap
;
83 nsTHashMap
<nsUint64HashKey
, BrowserParent
*> mBrowserParentMap
;
85 MOZ_COUNTED_DEFAULT_CTOR(ContentProcessManager
);
88 } // namespace mozilla::dom
90 #endif // mozilla_dom_ContentProcessManager_h