mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
3909bb5fb8
- Bug 1110446 P2 Cleanup stale caches/bodies if last session didn't shutdown cleanly. r=ehsan (7925cf5fa) - Bug 1110446 P3 Add a test that forces a Cache object to be orphaned and reclaimed. r=ehsan (c61409240) - Bug 1110446 P4 Add a test that orphanes Cache API body files. r=ehsan (97e0a6f73) - Bug 1157670 - Fixing an incorrect assertion in QuotaManager.cpp leads to an assertion failure; r=bent (0a19eac66) - Bug 1165119 Remove corrupt morgue directories polluting nightly profiles. r=janv (d148170d8) - Bug 1165119 - Follow-up to address review feedback accidentally left out of last push. r=me (f7ef96873) - Fixup to make bug 1165119 ride the trains properly. r=trivial,DONTBUILD (87d186da4) - Bug 1162624 - Add support for restoring corrupted or missing metadata files; r=bent (57e4341e6) - Bug 1174113 - QuotaManager: Origin initialization fails on moz-safe-about+++home; r=bent (b7673128c) - Bug 1142694 - QuotaManager default/temporary initialization fails on some profiles; r=bent (29a286137) - Bug 1166871 - Always force a repaint before handling a wheel event so that we don't untransform it into some other scrollframe. r=botond (28e56646d) - Don't vertically scroll APZCs that have less than one pixel of vertical scroll range. (bug 1154134, r=kats) (1bac9c054) - Bug 1166871 - Add a test. r=botond (45d398bb6) - Bug 1164557 - Do not start an overscroll animation if one is already running. r=kats (287a27910) - Bug 1163832 - Add an API to flush pending APZ repaint requests and dispatch a notification upon completion. r=botond (8b3f9e06f) - Bug 858680 - Part 1: Perform incremental_vacuum on open databases while idle, r=janv. (715f77ad6) - Bug 858680 - Part 2: Add idle notifications to QuotaClient, r=janv. (9f245b1bb) - Bug 1135166 - Initialize Telemetry histogram id cache early to avoid races. r=froydnj,vladan (f0bd8278c) - Bug 1162176, Part 1. r=mak. (f92ba4061) - Bug 1162176, Part 2. r=janv. (f313e1cf3) - Bug 1155634 - Move ConnectionPool creation closer to where we actually use it and at a point guaranteed to be after QuotaManager has been started. r=khuey relanding CLOSED TREE (ce489e8f4) - Bug 1155652 - Fix two incorrect assertions r=janv (2417d91ed) - Bug 1156063 - Intermittent application crashed [@ mozilla::dom::indexedDB::::ConnectionPool::Start] in various tests. r=janv (b1126ac71) - Bug 1157029 - More changes to bulletproof shutdown of failed connections, r=janv. (93a425abb) - Bug 858680 - Part 4: Perform maintenance on databases while idle, r=janv. (017d536fe) - Bug 1130775 - Convert synchronized ops and storage registration into unified directory locks; r=bent (300f635f7) - Bug 1130775 followup: Add missing 'override' keyword to SendResults() methods in QuotaManager.cpp. rs=ehsan (397338f5b) - Bug 1170021 - Part 1: Merge QuotaManager with QuotaObject; r=bent (168264350) - Bug 1170021 - Part 2: Move DirectoryLock out of QuotaManager class; r=bent (278964f88) - pointer style (99453953c) - Bug 1171931 - Refactor duplicated code using XRE_IsParent/ContentProcess. r=froydnj (6d1ddbff1)
339 lines
9.9 KiB
C++
339 lines
9.9 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "ContentProcessManager.h"
|
|
#include "ContentParent.h"
|
|
#include "mozilla/dom/TabParent.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
// XXX need another bug to move this to a common header.
|
|
#ifdef DISABLE_ASSERTS_FOR_FUZZING
|
|
#define ASSERT_UNLESS_FUZZING(...) do { } while (0)
|
|
#else
|
|
#define ASSERT_UNLESS_FUZZING(...) MOZ_ASSERT(false, __VA_ARGS__)
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
static uint64_t gTabId = 0;
|
|
|
|
/* static */
|
|
StaticAutoPtr<ContentProcessManager>
|
|
ContentProcessManager::sSingleton;
|
|
|
|
/* static */ ContentProcessManager*
|
|
ContentProcessManager::GetSingleton()
|
|
{
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
if (!sSingleton) {
|
|
sSingleton = new ContentProcessManager();
|
|
ClearOnShutdown(&sSingleton);
|
|
}
|
|
return sSingleton;
|
|
}
|
|
|
|
void
|
|
ContentProcessManager::AddContentProcess(ContentParent* aChildCp,
|
|
const ContentParentId& aParentCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aChildCp);
|
|
|
|
ContentProcessInfo info;
|
|
info.mCp = aChildCp;
|
|
info.mParentCpId = aParentCpId;
|
|
mContentParentMap[aChildCp->ChildID()] = info;
|
|
}
|
|
|
|
void
|
|
ContentProcessManager::RemoveContentProcess(const ContentParentId& aChildCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(mContentParentMap.find(aChildCpId) != mContentParentMap.end());
|
|
|
|
mContentParentMap.erase(aChildCpId);
|
|
for (auto iter = mContentParentMap.begin();
|
|
iter != mContentParentMap.end();
|
|
++iter) {
|
|
if (!iter->second.mChildrenCpId.empty()) {
|
|
iter->second.mChildrenCpId.erase(aChildCpId);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool
|
|
ContentProcessManager::AddGrandchildProcess(const ContentParentId& aParentCpId,
|
|
const ContentParentId& aChildCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto iter = mContentParentMap.find(aParentCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING("Parent process should be already in map!");
|
|
return false;
|
|
}
|
|
iter->second.mChildrenCpId.insert(aChildCpId);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ContentProcessManager::GetParentProcessId(const ContentParentId& aChildCpId,
|
|
/*out*/ ContentParentId* aParentCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return false;
|
|
}
|
|
*aParentCpId = iter->second.mParentCpId;
|
|
return true;
|
|
}
|
|
|
|
ContentParent*
|
|
ContentProcessManager::GetContentProcessById(const ContentParentId& aChildCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return nullptr;
|
|
}
|
|
return iter->second.mCp;
|
|
}
|
|
|
|
nsTArray<ContentParentId>
|
|
ContentProcessManager::GetAllChildProcessById(const ContentParentId& aParentCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsTArray<ContentParentId> cpIdArray;
|
|
auto iter = mContentParentMap.find(aParentCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return Move(cpIdArray);
|
|
}
|
|
|
|
for (auto cpIter = iter->second.mChildrenCpId.begin();
|
|
cpIter != iter->second.mChildrenCpId.end();
|
|
++cpIter) {
|
|
cpIdArray.AppendElement(*cpIter);
|
|
}
|
|
|
|
return Move(cpIdArray);
|
|
}
|
|
|
|
TabId
|
|
ContentProcessManager::AllocateTabId(const TabId& aOpenerTabId,
|
|
const IPCTabContext& aContext,
|
|
const ContentParentId& aChildCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return TabId(0);
|
|
}
|
|
|
|
struct RemoteFrameInfo info;
|
|
|
|
const IPCTabAppBrowserContext& appBrowser = aContext.appBrowserContext();
|
|
// If it's a PopupIPCTabContext, it's the case that a TabChild want to
|
|
// open a new tab. aOpenerTabId has to be it's parent frame's opener id.
|
|
if (appBrowser.type() == IPCTabAppBrowserContext::TPopupIPCTabContext) {
|
|
auto remoteFrameIter = iter->second.mRemoteFrames.find(aOpenerTabId);
|
|
if (remoteFrameIter == iter->second.mRemoteFrames.end()) {
|
|
ASSERT_UNLESS_FUZZING("Failed to find parent frame's opener id.");
|
|
return TabId(0);
|
|
}
|
|
|
|
info.mOpenerTabId = remoteFrameIter->second.mOpenerTabId;
|
|
|
|
const PopupIPCTabContext &ipcContext = appBrowser.get_PopupIPCTabContext();
|
|
MOZ_ASSERT(ipcContext.opener().type() == PBrowserOrId::TTabId);
|
|
|
|
remoteFrameIter = iter->second.mRemoteFrames.find(ipcContext.opener().get_TabId());
|
|
if (remoteFrameIter == iter->second.mRemoteFrames.end()) {
|
|
ASSERT_UNLESS_FUZZING("Failed to find tab id.");
|
|
return TabId(0);
|
|
}
|
|
|
|
info.mContext = remoteFrameIter->second.mContext;
|
|
}
|
|
else {
|
|
MaybeInvalidTabContext tc(aContext);
|
|
if (!tc.IsValid()) {
|
|
NS_ERROR(nsPrintfCString("Received an invalid TabContext from "
|
|
"the child process. (%s)",
|
|
tc.GetInvalidReason()).get());
|
|
return TabId(0);
|
|
}
|
|
info.mOpenerTabId = aOpenerTabId;
|
|
info.mContext = tc.GetTabContext();
|
|
}
|
|
|
|
mUniqueId = ++gTabId;
|
|
iter->second.mRemoteFrames[mUniqueId] = info;
|
|
|
|
return mUniqueId;
|
|
}
|
|
|
|
void
|
|
ContentProcessManager::DeallocateTabId(const ContentParentId& aChildCpId,
|
|
const TabId& aChildTabId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return;
|
|
}
|
|
|
|
auto remoteFrameIter = iter->second.mRemoteFrames.find(aChildTabId);
|
|
if (remoteFrameIter != iter->second.mRemoteFrames.end()) {
|
|
iter->second.mRemoteFrames.erase(aChildTabId);
|
|
}
|
|
}
|
|
|
|
bool
|
|
ContentProcessManager::GetTabContextByProcessAndTabId(const ContentParentId& aChildCpId,
|
|
const TabId& aChildTabId,
|
|
/*out*/ TabContext* aTabContext)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aTabContext);
|
|
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return false;
|
|
}
|
|
|
|
auto remoteFrameIter = iter->second.mRemoteFrames.find(aChildTabId);
|
|
if (NS_WARN_IF(remoteFrameIter == iter->second.mRemoteFrames.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return false;
|
|
}
|
|
|
|
*aTabContext = remoteFrameIter->second.mContext;
|
|
|
|
return true;
|
|
}
|
|
|
|
nsTArray<TabContext>
|
|
ContentProcessManager::GetTabContextByContentProcess(const ContentParentId& aChildCpId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsTArray<TabContext> tabContextArray;
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return Move(tabContextArray);
|
|
}
|
|
|
|
for (auto remoteFrameIter = iter->second.mRemoteFrames.begin();
|
|
remoteFrameIter != iter->second.mRemoteFrames.end();
|
|
++remoteFrameIter) {
|
|
tabContextArray.AppendElement(remoteFrameIter->second.mContext);
|
|
}
|
|
|
|
return Move(tabContextArray);
|
|
}
|
|
|
|
bool
|
|
ContentProcessManager::GetRemoteFrameOpenerTabId(const ContentParentId& aChildCpId,
|
|
const TabId& aChildTabId,
|
|
/*out*/TabId* aOpenerTabId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return false;
|
|
}
|
|
|
|
auto remoteFrameIter = iter->second.mRemoteFrames.find(aChildTabId);
|
|
if (NS_WARN_IF(remoteFrameIter == iter->second.mRemoteFrames.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return false;
|
|
}
|
|
|
|
*aOpenerTabId = remoteFrameIter->second.mOpenerTabId;
|
|
|
|
return true;
|
|
}
|
|
|
|
already_AddRefed<TabParent>
|
|
ContentProcessManager::GetTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
|
|
const TabId& aChildTabId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
auto iter = mContentParentMap.find(aChildCpId);
|
|
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
|
ASSERT_UNLESS_FUZZING();
|
|
return nullptr;
|
|
}
|
|
|
|
const InfallibleTArray<PBrowserParent*>& browsers =
|
|
iter->second.mCp->ManagedPBrowserParent();
|
|
for (uint32_t i = 0; i < browsers.Length(); i++) {
|
|
nsRefPtr<TabParent> tab = TabParent::GetFrom(browsers[i]);
|
|
if (tab->GetTabId() == aChildTabId) {
|
|
return tab.forget();
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
already_AddRefed<TabParent>
|
|
ContentProcessManager::GetTopLevelTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
|
|
const TabId& aChildTabId)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Used to keep the current ContentParentId and the current TabId
|
|
// in the iteration(do-while loop below)
|
|
ContentParentId currentCpId;
|
|
TabId currentTabId;
|
|
|
|
// To get the ContentParentId and the TabParentId on upper level
|
|
ContentParentId parentCpId = aChildCpId;
|
|
TabId openerTabId = aChildTabId;
|
|
|
|
// Stop this loop when the upper ContentParentId of
|
|
// the current ContentParentId is chrome(ContentParentId = 0).
|
|
do {
|
|
// Update the current ContentParentId and TabId in iteration
|
|
currentCpId = parentCpId;
|
|
currentTabId = openerTabId;
|
|
|
|
// Get the ContentParentId and TabId on upper level
|
|
if (!GetParentProcessId(currentCpId, &parentCpId) ||
|
|
!GetRemoteFrameOpenerTabId(currentCpId, currentTabId, &openerTabId)) {
|
|
return nullptr;
|
|
}
|
|
} while (parentCpId);
|
|
|
|
// Get the top level TabParent by the current ContentParentId and TabId
|
|
return GetTabParentByProcessAndTabId(currentCpId, currentTabId);
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|