Bug 1696771: Always null check the ContentProcessManager singleton before use. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D143180
This commit is contained in:
Jens Stutte 2022-04-08 06:20:19 +00:00
Родитель 8abdcc7d3e
Коммит 3c00871162
7 изменённых файлов: 104 добавлений и 52 удалений

Просмотреть файл

@ -184,6 +184,9 @@ ContentParent* CanonicalBrowsingContext::GetContentParent() const {
}
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (!cpm) {
return nullptr;
}
return cpm->GetContentProcessById(ContentParentId(mProcessId));
}

Просмотреть файл

@ -2750,6 +2750,9 @@ bool nsFrameLoader::TryRemoteBrowserInternal() {
RefPtr<ContentParent> contentParent;
if (mChildID != 0) {
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (cpm) {
return false;
}
contentParent = cpm->GetContentProcessById(ContentParentId(mChildID));
}
mRemoteBrowser =

Просмотреть файл

@ -83,6 +83,9 @@ nsresult BrowserBridgeParent::InitWithProcess(
}
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (!cpm) {
return NS_ERROR_UNEXPECTED;
}
cpm->RegisterRemoteFrame(browserParent);
RefPtr<WindowGlobalParent> windowParent =

Просмотреть файл

@ -675,7 +675,10 @@ mozilla::ipc::IPCResult BrowserParent::RecvEnsureLayersConnected(
void BrowserParent::ActorDestroy(ActorDestroyReason why) {
Manager()->NotifyTabDestroyed(mTabId, mMarkedDestroying);
ContentProcessManager::GetSingleton()->UnregisterRemoteFrame(mTabId);
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (cpm) {
cpm->UnregisterRemoteFrame(mTabId);
}
if (mRemoteLayerTreeOwner.IsInitialized()) {
auto layersId = mRemoteLayerTreeOwner.GetLayersId();

Просмотреть файл

@ -1530,6 +1530,9 @@ already_AddRefed<RemoteBrowser> ContentParent::CreateBrowser(
}
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (NS_WARN_IF(!cpm)) {
return nullptr;
}
cpm->RegisterRemoteFrame(browserParent);
nsCOMPtr<nsIPrincipal> initialPrincipal =
@ -2090,7 +2093,9 @@ void ContentParent::ActorDestroy(ActorDestroyReason why) {
mSubprocess = nullptr;
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
cpm->RemoveContentProcess(this->ChildID());
if (cpm) {
cpm->RemoveContentProcess(this->ChildID());
}
if (mDriverCrashGuard) {
mDriverCrashGuard->NotifyCrashed();
@ -2481,6 +2486,8 @@ void ContentParent::AppendSandboxParams(std::vector<std::string>& aArgs) {
bool ContentParent::BeginSubprocessLaunch(ProcessPriority aPriority) {
AUTO_PROFILER_LABEL("ContentParent::LaunchSubprocess", OTHER);
// XXX: This check works only late, as GetSingleton will return nullptr
// only after ClearOnShutdown happened. See bug 1632740.
if (!ContentProcessManager::GetSingleton()) {
NS_WARNING(
"Shutdown has begun, we shouldn't spawn any more child processes");
@ -2613,7 +2620,13 @@ bool ContentParent::LaunchSubprocessResolve(bool aIsSync,
base::GetProcId(mSubprocess->GetChildProcessHandle());
Open(mSubprocess->TakeInitialPort(), procId);
ContentProcessManager::GetSingleton()->AddContentProcess(this);
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (!cpm) {
NS_WARNING("immediately shutting-down caused by our shutdown");
ShutDownProcess(SEND_SHUTDOWN_MESSAGE);
return false;
}
cpm->AddContentProcess(this);
#ifdef MOZ_CODE_COVERAGE
Unused << SendShareCodeCoverageMutex(
@ -4026,7 +4039,7 @@ mozilla::ipc::IPCResult ContentParent::RecvConstructPopupBrowser(
// window.open().
// We need to register remote frame with the child generated tab id.
auto* cpm = ContentProcessManager::GetSingleton();
if (!cpm->RegisterRemoteFrame(parent)) {
if (!cpm || !cpm->RegisterRemoteFrame(parent)) {
return IPC_FAIL(this, "RegisterRemoteFrame Failed");
}
}
@ -5156,9 +5169,12 @@ ContentParent::AllocPContentPermissionRequestParent(
const IPC::Principal& aPrincipal, const IPC::Principal& aTopLevelPrincipal,
const bool& aIsHandlingUserInput,
const bool& aMaybeUnsafePermissionDelegate, const TabId& aTabId) {
RefPtr<BrowserParent> tp;
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
RefPtr<BrowserParent> tp =
cpm->GetTopLevelBrowserParentByProcessAndTabId(this->ChildID(), aTabId);
if (cpm) {
tp =
cpm->GetTopLevelBrowserParentByProcessAndTabId(this->ChildID(), aTabId);
}
if (!tp) {
return nullptr;
}
@ -6812,9 +6828,11 @@ mozilla::ipc::IPCResult ContentParent::RecvWindowClose(
// browsing contexts of bc.
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendWindowClose(context, aTrustedCaller);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendWindowClose(context, aTrustedCaller);
}
return IPC_OK();
}
@ -6831,9 +6849,11 @@ mozilla::ipc::IPCResult ContentParent::RecvWindowFocus(
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendWindowFocus(context, aCallerType, aActionId);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendWindowFocus(context, aCallerType, aActionId);
}
return IPC_OK();
}
@ -6848,9 +6868,11 @@ mozilla::ipc::IPCResult ContentParent::RecvWindowBlur(
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendWindowBlur(context, aCallerType);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendWindowBlur(context, aCallerType);
}
return IPC_OK();
}
@ -6868,9 +6890,11 @@ mozilla::ipc::IPCResult ContentParent::RecvRaiseWindow(
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendRaiseWindow(context, aCallerType, aActionId);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendRaiseWindow(context, aCallerType, aActionId);
}
return IPC_OK();
}
@ -6891,21 +6915,23 @@ mozilla::ipc::IPCResult ContentParent::RecvAdjustWindowFocus(
processes.InsertOrUpdate(this, true);
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
CanonicalBrowsingContext* context = aContext.get_canonical();
while (context) {
BrowsingContext* parent = context->GetParent();
if (!parent) {
break;
}
if (cpm) {
CanonicalBrowsingContext* context = aContext.get_canonical();
while (context) {
BrowsingContext* parent = context->GetParent();
if (!parent) {
break;
}
CanonicalBrowsingContext* canonicalParent = parent->Canonical();
ContentParent* cp = cpm->GetContentProcessById(
ContentParentId(canonicalParent->OwnerProcessId()));
if (cp && !processes.Get(cp)) {
Unused << cp->SendAdjustWindowFocus(context, aIsVisible, aActionId);
processes.InsertOrUpdate(cp, true);
CanonicalBrowsingContext* canonicalParent = parent->Canonical();
ContentParent* cp = cpm->GetContentProcessById(
ContentParentId(canonicalParent->OwnerProcessId()));
if (cp && !processes.Get(cp)) {
Unused << cp->SendAdjustWindowFocus(context, aIsVisible, aActionId);
processes.InsertOrUpdate(cp, true);
}
context = canonicalParent;
}
context = canonicalParent;
}
return IPC_OK();
}
@ -6921,9 +6947,11 @@ mozilla::ipc::IPCResult ContentParent::RecvClearFocus(
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendClearFocus(context);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendClearFocus(context);
}
return IPC_OK();
}
@ -7046,11 +7074,11 @@ mozilla::ipc::IPCResult ContentParent::RecvSetFocusedElement(
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendSetFocusedElement(context, aNeedsFocus);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendSetFocusedElement(context, aNeedsFocus);
}
return IPC_OK();
}
@ -7066,11 +7094,12 @@ mozilla::ipc::IPCResult ContentParent::RecvFinalizeFocusOuter(
LOGFOCUS(("ContentParent::RecvFinalizeFocusOuter"));
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->EmbedderProcessId()));
if (cp) {
Unused << cp->SendFinalizeFocusOuter(context, aCanFocus, aCallerType);
if (cpm) {
ContentParent* cp = cpm->GetContentProcessById(
ContentParentId(context->EmbedderProcessId()));
if (cp) {
Unused << cp->SendFinalizeFocusOuter(context, aCanFocus, aCallerType);
}
}
return IPC_OK();
}
@ -7111,6 +7140,9 @@ mozilla::ipc::IPCResult ContentParent::RecvBlurToParent(
aFocusedBrowsingContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
if (!cpm) {
return IPC_OK();
}
// If aBrowsingContextToClear and aAncestorBrowsingContextToFocusHandled
// didn't get handled in the process that sent this IPC message and they
@ -7158,10 +7190,11 @@ mozilla::ipc::IPCResult ContentParent::RecvMaybeExitFullscreen(
CanonicalBrowsingContext* context = aContext.get_canonical();
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendMaybeExitFullscreen(context);
if (cpm) {
ContentParent* cp =
cpm->GetContentProcessById(ContentParentId(context->OwnerProcessId()));
Unused << cp->SendMaybeExitFullscreen(context);
}
return IPC_OK();
}

Просмотреть файл

@ -73,8 +73,10 @@ WebrtcTCPSocket::~WebrtcTCPSocket() {
void WebrtcTCPSocket::SetTabId(dom::TabId aTabId) {
MOZ_ASSERT(NS_IsMainThread());
dom::ContentProcessManager* cpm = dom::ContentProcessManager::GetSingleton();
dom::ContentParentId cpId = cpm->GetTabProcessId(aTabId);
mAuthProvider = cpm->GetBrowserParentByProcessAndTabId(cpId, aTabId);
if (cpm) {
dom::ContentParentId cpId = cpm->GetTabProcessId(aTabId);
mAuthProvider = cpm->GetBrowserParentByProcessAndTabId(cpId, aTabId);
}
}
nsresult WebrtcTCPSocket::Write(nsTArray<uint8_t>&& aWriteData) {

Просмотреть файл

@ -367,13 +367,18 @@ void CrossProcessPaint::LostFragment(dom::WindowGlobalParent* aWGP) {
void CrossProcessPaint::QueueDependencies(
const nsTHashSet<uint64_t>& aDependencies) {
dom::ContentProcessManager* cpm = dom::ContentProcessManager::GetSingleton();
if (!cpm) {
CPP_LOG(
"Skipping QueueDependencies with no"
" current ContentProcessManager.\n");
return;
}
for (const auto& key : aDependencies) {
auto dependency = dom::TabId(key);
// Get the current BrowserParent of the remote browser that was marked
// as a dependency
dom::ContentProcessManager* cpm =
dom::ContentProcessManager::GetSingleton();
dom::ContentParentId cpId = cpm->GetTabProcessId(dependency);
RefPtr<dom::BrowserParent> browser =
cpm->GetBrowserParentByProcessAndTabId(cpId, dependency);