From d163204665999b2aa127b2af229c6acca45e0a91 Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Tue, 22 Dec 2015 10:14:23 -0500 Subject: [PATCH] Bug 1226200: Don't assume a TCPSocket has only one managee (and rename LoneManagedOrNull) r=jdm --- dom/ipc/ContentBridgeChild.cpp | 2 +- dom/ipc/ContentBridgeParent.cpp | 2 +- dom/ipc/ContentChild.cpp | 4 ++-- dom/ipc/ContentParent.cpp | 8 ++++---- dom/ipc/CrashReporterChild.cpp | 2 +- dom/ipc/TabParent.cpp | 2 +- dom/media/gmp/GMPParent.cpp | 2 +- dom/network/TCPServerSocketParent.cpp | 4 ++-- dom/network/TCPSocketParent.cpp | 8 +++++--- dom/plugins/ipc/PluginModuleParent.cpp | 2 +- ipc/glue/ProtocolUtils.h | 15 ++++++++++++++- ipc/ipdl/test/cxx/TestMultiMgrs.cpp | 4 ++-- 12 files changed, 35 insertions(+), 20 deletions(-) diff --git a/dom/ipc/ContentBridgeChild.cpp b/dom/ipc/ContentBridgeChild.cpp index 3684e88e961..67d583d8263 100644 --- a/dom/ipc/ContentBridgeChild.cpp +++ b/dom/ipc/ContentBridgeChild.cpp @@ -98,7 +98,7 @@ ContentBridgeChild::SendPBrowserConstructor(PBrowserChild* aActor, jsipc::CPOWManager* ContentBridgeChild::GetCPOWManager() { - if (PJavaScriptChild* c = LoneManagedOrNull(ManagedPJavaScriptChild())) { + if (PJavaScriptChild* c = LoneManagedOrNullAsserts(ManagedPJavaScriptChild())) { return CPOWManagerFor(c); } return CPOWManagerFor(SendPJavaScriptConstructor()); diff --git a/dom/ipc/ContentBridgeParent.cpp b/dom/ipc/ContentBridgeParent.cpp index 2b5de0629ad..b4672f02e3e 100644 --- a/dom/ipc/ContentBridgeParent.cpp +++ b/dom/ipc/ContentBridgeParent.cpp @@ -180,7 +180,7 @@ ContentBridgeParent::NotifyTabDestroyed() jsipc::CPOWManager* ContentBridgeParent::GetCPOWManager() { - if (PJavaScriptParent* p = LoneManagedOrNull(ManagedPJavaScriptParent())) { + if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) { return CPOWManagerFor(p); } return nullptr; diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 5f504dfd967..14a7302dfdd 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -1723,7 +1723,7 @@ ContentChild::DeallocPTestShellChild(PTestShellChild* shell) jsipc::CPOWManager* ContentChild::GetCPOWManager() { - if (PJavaScriptChild* c = LoneManagedOrNull(ManagedPJavaScriptChild())) { + if (PJavaScriptChild* c = LoneManagedOrNullAsserts(ManagedPJavaScriptChild())) { return CPOWManagerFor(c); } return CPOWManagerFor(SendPJavaScriptConstructor()); @@ -2226,7 +2226,7 @@ ContentChild::ProcessingError(Result aCode, const char* aReason) } #if defined(MOZ_CRASHREPORTER) && !defined(MOZ_B2G) - if (PCrashReporterChild* c = LoneManagedOrNull(ManagedPCrashReporterChild())) { + if (PCrashReporterChild* c = LoneManagedOrNullAsserts(ManagedPCrashReporterChild())) { CrashReporterChild* crashReporter = static_cast(c); nsDependentCString reason(aReason); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index dd786914737..7e401b6852f 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2169,7 +2169,7 @@ ContentParent::ActorDestroy(ActorDestroyReason why) // There's a window in which child processes can crash // after IPC is established, but before a crash reporter // is created. - if (PCrashReporterParent* p = LoneManagedOrNull(ManagedPCrashReporterParent())) { + if (PCrashReporterParent* p = LoneManagedOrNullAsserts(ManagedPCrashReporterParent())) { CrashReporterParent* crashReporter = static_cast(p); @@ -2350,7 +2350,7 @@ ContentParent::NotifyTabDestroyed(const TabId& aTabId, jsipc::CPOWManager* ContentParent::GetCPOWManager() { - if (PJavaScriptParent* p = LoneManagedOrNull(ManagedPJavaScriptParent())) { + if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) { return CPOWManagerFor(p); } return nullptr; @@ -2371,7 +2371,7 @@ ContentParent::DestroyTestShell(TestShellParent* aTestShell) TestShellParent* ContentParent::GetTestShellSingleton() { - PTestShellParent* p = LoneManagedOrNull(ManagedPTestShellParent()); + PTestShellParent* p = LoneManagedOrNullAsserts(ManagedPTestShellParent()); return static_cast(p); } @@ -3656,7 +3656,7 @@ ContentParent::KillHard(const char* aReason) // We're about to kill the child process associated with this content. // Something has gone wrong to get us here, so we generate a minidump // of the parent and child for submission to the crash server. - if (PCrashReporterParent* p = LoneManagedOrNull(ManagedPCrashReporterParent())) { + if (PCrashReporterParent* p = LoneManagedOrNullAsserts(ManagedPCrashReporterParent())) { CrashReporterParent* crashReporter = static_cast(p); // GeneratePairedMinidump creates two minidumps for us - the main diff --git a/dom/ipc/CrashReporterChild.cpp b/dom/ipc/CrashReporterChild.cpp index 27d3dee2ddd..8174452e706 100644 --- a/dom/ipc/CrashReporterChild.cpp +++ b/dom/ipc/CrashReporterChild.cpp @@ -35,7 +35,7 @@ CrashReporterChild::GetCrashReporter() if (!reporters) { return nullptr; } - return LoneManagedOrNull(*reporters); + return LoneManagedOrNullAsserts(*reporters); } } // namespace dom diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index 5a72924fc6e..e05afeb186a 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -2348,7 +2348,7 @@ TabParent::GetTabIdFrom(nsIDocShell *docShell) RenderFrameParent* TabParent::GetRenderFrame() { - PRenderFrameParent* p = LoneManagedOrNull(ManagedPRenderFrameParent()); + PRenderFrameParent* p = LoneManagedOrNullAsserts(ManagedPRenderFrameParent()); return static_cast(p); } diff --git a/dom/media/gmp/GMPParent.cpp b/dom/media/gmp/GMPParent.cpp index 9154ca090af..c32b9eea82e 100644 --- a/dom/media/gmp/GMPParent.cpp +++ b/dom/media/gmp/GMPParent.cpp @@ -582,7 +582,7 @@ void GMPParent::GetCrashID(nsString& aResult) { CrashReporterParent* cr = - static_cast(LoneManagedOrNull(ManagedPCrashReporterParent())); + static_cast(LoneManagedOrNullAsserts(ManagedPCrashReporterParent())); if (NS_WARN_IF(!cr)) { return; } diff --git a/dom/network/TCPServerSocketParent.cpp b/dom/network/TCPServerSocketParent.cpp index b2b873a2167..39d689ae4ff 100644 --- a/dom/network/TCPServerSocketParent.cpp +++ b/dom/network/TCPServerSocketParent.cpp @@ -66,7 +66,7 @@ uint32_t TCPServerSocketParent::GetAppId() { const PContentParent *content = Manager()->Manager(); - if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) { + if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) { TabParent *tab = TabParent::GetFrom(browser); return tab->OwnAppId(); } else { @@ -78,7 +78,7 @@ bool TCPServerSocketParent::GetInBrowser() { const PContentParent *content = Manager()->Manager(); - if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) { + if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) { TabParent *tab = TabParent::GetFrom(browser); return tab->IsBrowserElement(); } else { diff --git a/dom/network/TCPSocketParent.cpp b/dom/network/TCPSocketParent.cpp index 08cd0dfef51..eca8b03b20c 100644 --- a/dom/network/TCPSocketParent.cpp +++ b/dom/network/TCPSocketParent.cpp @@ -68,7 +68,7 @@ uint32_t TCPSocketParent::GetAppId() { const PContentParent *content = Manager()->Manager(); - if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) { + if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) { TabParent *tab = TabParent::GetFrom(browser); return tab->OwnAppId(); } else { @@ -80,7 +80,7 @@ bool TCPSocketParent::GetInBrowser() { const PContentParent *content = Manager()->Manager(); - if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) { + if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) { TabParent *tab = TabParent::GetFrom(browser); return tab->IsBrowserElement(); } else { @@ -223,7 +223,9 @@ TCPSocketParent::RecvOpenBind(const nsCString& aRemoteHost, uint32_t appId = nsIScriptSecurityManager::NO_APP_ID; bool inBrowser = false; const PContentParent *content = Manager()->Manager(); - if (PBrowserParent* browser = LoneManagedOrNull(content->ManagedPBrowserParent())) { + if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) { + // appId's are for B2G only currently, where managees.Count() == 1 + // This is not guaranteed currently in Desktop, so skip this there. TabParent *tab = TabParent::GetFrom(browser); appId = tab->OwnAppId(); inBrowser = tab->IsBrowserElement(); diff --git a/dom/plugins/ipc/PluginModuleParent.cpp b/dom/plugins/ipc/PluginModuleParent.cpp index f1e13ea5025..ea0039529ad 100755 --- a/dom/plugins/ipc/PluginModuleParent.cpp +++ b/dom/plugins/ipc/PluginModuleParent.cpp @@ -1504,7 +1504,7 @@ PluginModuleChromeParent::OnHangUIContinue() CrashReporterParent* PluginModuleChromeParent::CrashReporter() { - return static_cast(LoneManagedOrNull(ManagedPCrashReporterParent())); + return static_cast(LoneManagedOrNullAsserts(ManagedPCrashReporterParent())); } #ifdef MOZ_CRASHREPORTER_INJECTOR diff --git a/ipc/glue/ProtocolUtils.h b/ipc/glue/ProtocolUtils.h index 50b2d4ca3bc..1a30d03ab70 100644 --- a/ipc/glue/ProtocolUtils.h +++ b/ipc/glue/ProtocolUtils.h @@ -336,7 +336,7 @@ using ManagedContainer = nsTHashtable>; template Protocol* -LoneManagedOrNull(const ManagedContainer& aManagees) +LoneManagedOrNullAsserts(const ManagedContainer& aManagees) { if (aManagees.IsEmpty()) { return nullptr; @@ -345,6 +345,19 @@ LoneManagedOrNull(const ManagedContainer& aManagees) return aManagees.ConstIter().Get()->GetKey(); } +// appId's are for B2G only currently, where managees.Count() == 1. This is +// not guaranteed currently in Desktop, so for paths used for desktop, +// don't assert there's one managee. +template +Protocol* +SingleManagedOrNull(const ManagedContainer& aManagees) +{ + if (aManagees.Count() != 1) { + return nullptr; + } + return aManagees.ConstIter().Get()->GetKey(); +} + } // namespace mozilla diff --git a/ipc/ipdl/test/cxx/TestMultiMgrs.cpp b/ipc/ipdl/test/cxx/TestMultiMgrs.cpp index ab9daac173d..422b3fea338 100644 --- a/ipc/ipdl/test/cxx/TestMultiMgrs.cpp +++ b/ipc/ipdl/test/cxx/TestMultiMgrs.cpp @@ -78,10 +78,10 @@ TestMultiMgrsChild::RecvCheck() TestMultiMgrsLeftChild* leftie = static_cast( - LoneManagedOrNull(ManagedPTestMultiMgrsLeftChild())); + LoneManagedOrNullAsserts(ManagedPTestMultiMgrsLeftChild())); TestMultiMgrsRightChild* rightie = static_cast( - LoneManagedOrNull(ManagedPTestMultiMgrsRightChild())); + LoneManagedOrNullAsserts(ManagedPTestMultiMgrsRightChild())); if (!leftie->HasChild(mBottomL)) fail("leftie didn't have a child it was supposed to!");