2014-10-29 21:11:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-10-29 21:11:00 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ContentProcessManager_h
|
|
|
|
#define mozilla_dom_ContentProcessManager_h
|
|
|
|
|
|
|
|
#include "mozilla/StaticPtr.h"
|
|
|
|
#include "mozilla/dom/TabContext.h"
|
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
|
|
|
#include "nsTArray.h"
|
2021-03-10 13:47:47 +03:00
|
|
|
#include "nsTHashMap.h"
|
2014-10-29 21:11:00 +03:00
|
|
|
|
2022-05-18 13:17:08 +03:00
|
|
|
namespace mozilla::dom {
|
2014-10-29 21:11:00 +03:00
|
|
|
class ContentParent;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ContentProcessManager final {
|
2014-10-29 21:11:00 +03:00
|
|
|
public:
|
|
|
|
static ContentProcessManager* GetSingleton();
|
2020-02-20 14:40:14 +03:00
|
|
|
MOZ_COUNTED_DTOR(ContentProcessManager);
|
2014-10-29 21:11:00 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new content process into the map.
|
|
|
|
*/
|
2019-08-08 19:07:24 +03:00
|
|
|
void AddContentProcess(ContentParent* aChildCp);
|
|
|
|
|
2014-10-29 21:11:00 +03:00
|
|
|
/**
|
|
|
|
* Remove the content process by id.
|
|
|
|
*/
|
|
|
|
void RemoveContentProcess(const ContentParentId& aChildCpId);
|
2019-08-08 19:07:24 +03:00
|
|
|
|
2014-10-29 21:11:00 +03:00
|
|
|
/**
|
|
|
|
* Return the ContentParent pointer by id.
|
|
|
|
*/
|
|
|
|
ContentParent* GetContentProcessById(const ContentParentId& aChildCpId);
|
|
|
|
|
|
|
|
/**
|
2019-08-08 19:07:26 +03:00
|
|
|
* Add a new browser parent into the map.
|
2014-10-29 21:11:00 +03:00
|
|
|
*/
|
2019-08-08 19:07:26 +03:00
|
|
|
bool RegisterRemoteFrame(BrowserParent* aChildBp);
|
2017-04-05 13:42:00 +03:00
|
|
|
|
2014-10-29 21:11:00 +03:00
|
|
|
/**
|
2019-08-08 19:07:26 +03:00
|
|
|
* Remove the browser parent by the given tab id.
|
2014-10-29 21:11:00 +03:00
|
|
|
*/
|
2019-08-08 19:07:32 +03:00
|
|
|
void UnregisterRemoteFrame(const TabId& aChildTabId);
|
2014-10-29 21:11:00 +03:00
|
|
|
|
2018-09-25 05:25:29 +03:00
|
|
|
/**
|
|
|
|
* Get the ContentParentId of the parent of the given tab id.
|
|
|
|
*/
|
2019-08-08 19:07:26 +03:00
|
|
|
ContentParentId GetTabProcessId(const TabId& aChildTabId);
|
2018-09-25 05:25:29 +03:00
|
|
|
|
2017-03-07 22:00:28 +03:00
|
|
|
/**
|
2019-04-10 00:38:15 +03:00
|
|
|
* Get the number of BrowserParents managed by the givent content process.
|
2019-08-08 19:07:26 +03:00
|
|
|
* Return 0 when ContentParent couldn't be found via aChildCpId.
|
2017-03-07 22:00:28 +03:00
|
|
|
*/
|
2019-04-10 00:38:15 +03:00
|
|
|
uint32_t GetBrowserParentCountByProcessId(const ContentParentId& aChildCpId);
|
2017-03-07 22:00:28 +03:00
|
|
|
|
2015-02-03 11:03:29 +03:00
|
|
|
/**
|
2019-04-10 00:38:15 +03:00
|
|
|
* Get the BrowserParent by the given content process and tab id.
|
|
|
|
* Return nullptr when BrowserParent couldn't be found via aChildCpId
|
2015-02-03 11:03:29 +03:00
|
|
|
* and aChildTabId.
|
|
|
|
*/
|
2019-04-10 00:38:15 +03:00
|
|
|
already_AddRefed<BrowserParent> GetBrowserParentByProcessAndTabId(
|
2015-02-03 11:03:29 +03:00
|
|
|
const ContentParentId& aChildCpId, const TabId& aChildTabId);
|
|
|
|
|
|
|
|
/**
|
2019-04-10 00:38:15 +03:00
|
|
|
* Get the BrowserParent on top level by the given content process and tab id.
|
2015-02-03 11:03:29 +03:00
|
|
|
*
|
2019-08-08 19:07:26 +03:00
|
|
|
* This function returns the BrowserParent directly within a BrowserHost,
|
|
|
|
* called top-level BrowserParent here, by given aChildCpId and aChildTabId.
|
|
|
|
* The given aChildCpId and aChildTabId are related to a content process
|
|
|
|
* and a tab respectively.
|
2015-02-03 11:03:29 +03:00
|
|
|
*/
|
2019-04-10 00:38:15 +03:00
|
|
|
already_AddRefed<BrowserParent> GetTopLevelBrowserParentByProcessAndTabId(
|
2015-02-03 11:03:29 +03:00
|
|
|
const ContentParentId& aChildCpId, const TabId& aChildTabId);
|
|
|
|
|
2014-10-29 21:11:00 +03:00
|
|
|
private:
|
|
|
|
static StaticAutoPtr<ContentProcessManager> sSingleton;
|
2019-08-08 19:07:26 +03:00
|
|
|
|
2021-03-10 13:47:47 +03:00
|
|
|
nsTHashMap<nsUint64HashKey, ContentParent*> mContentParentMap;
|
|
|
|
nsTHashMap<nsUint64HashKey, BrowserParent*> mBrowserParentMap;
|
2014-10-29 21:11:00 +03:00
|
|
|
|
2020-02-20 14:40:14 +03:00
|
|
|
MOZ_COUNTED_DEFAULT_CTOR(ContentProcessManager);
|
2014-10-29 21:11:00 +03:00
|
|
|
};
|
|
|
|
|
2022-05-18 13:17:08 +03:00
|
|
|
} // namespace mozilla::dom
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2016-01-05 12:59:30 +03:00
|
|
|
#endif // mozilla_dom_ContentProcessManager_h
|