diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 8e21165c8157..3530938b25b1 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -1249,93 +1249,13 @@ ContentParent::ContentParent(mozIApplication* aApp, Open(mSubprocess->GetChannel(), mSubprocess->GetOwnedChildProcessHandle()); - // Set the subprocess's priority. We do this early on because we're likely - // /lowering/ the process's CPU and memory priority, which it has inherited - // from this process. - // - // This call can cause us to send IPC messages to the child process, so it - // must come after the Open() call above. - ProcessPriorityManager::SetProcessPriority(this, aInitialPriority); - - // NB: internally, this will send an IPC message to the child - // process to get it to create the CompositorChild. This - // message goes through the regular IPC queue for this - // channel, so delivery will happen-before any other messages - // we send. The CompositorChild must be created before any - // PBrowsers are created, because they rely on the Compositor - // already being around. (Creation is async, so can't happen - // on demand.) - bool useOffMainThreadCompositing = !!CompositorParent::CompositorLoop(); - if (useOffMainThreadCompositing) { - DebugOnly opened = PCompositor::Open(this); - MOZ_ASSERT(opened); - - if (Preferences::GetBool("layers.async-video.enabled",false)) { - opened = PImageBridge::Open(this); - MOZ_ASSERT(opened); - } - } - - nsCOMPtr registrySvc = nsChromeRegistry::GetService(); - nsChromeRegistryChrome* chromeRegistry = - static_cast(registrySvc.get()); - chromeRegistry->SendRegisteredChrome(this); - mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this); - - if (gAppData) { - nsCString version(gAppData->version); - nsCString buildID(gAppData->buildID); - nsCString name(gAppData->name); - nsCString UAName(gAppData->UAName); - - // Sending all information to content process. - unused << SendAppInfo(version, buildID, name, UAName); - } - - nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); - if (sheetService) { - // This looks like a lot of work, but in a normal browser session we just - // send two loads. - - nsCOMArray& agentSheets = *sheetService->AgentStyleSheets(); - for (uint32_t i = 0; i < agentSheets.Length(); i++) { - URIParams uri; - SerializeURI(agentSheets[i]->GetSheetURI(), uri); - unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET); - } - - nsCOMArray& userSheets = *sheetService->UserStyleSheets(); - for (uint32_t i = 0; i < userSheets.Length(); i++) { - URIParams uri; - SerializeURI(userSheets[i]->GetSheetURI(), uri); - unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET); - } - - nsCOMArray& authorSheets = *sheetService->AuthorStyleSheets(); - for (uint32_t i = 0; i < authorSheets.Length(); i++) { - URIParams uri; - SerializeURI(authorSheets[i]->GetSheetURI(), uri); - unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET); - } - } - -#ifdef MOZ_CONTENT_SANDBOX - // Bug 921817. We enable the sandbox in RecvSetProcessPrivileges, - // which is where a preallocated process drops unnecessary privileges, - // but a non-preallocated process will already have changed its - // uid/gid/etc immediately after forking. Thus, we send this message, - // which is otherwise a no-op, to sandbox it at an appropriate point - // during startup. - if (aOSPrivileges != base::PRIVILEGES_INHERIT) { - if (!SendSetProcessPrivileges(base::PRIVILEGES_INHERIT)) { - KillHard(); - } - } -#endif + InitInternal(aInitialPriority, + true, /* Setup off-main thread compositing */ + true /* Send registered chrome */); } #ifdef MOZ_NUWA_PROCESS -static const FileDescriptor* +static const mozilla::ipc::FileDescriptor* FindFdProtocolFdMapping(const nsTArray& aFds, ProtocolId aProtoId) { @@ -1401,8 +1321,9 @@ ContentParent::ContentParent(ContentParent* aTemplate, priority = PROCESS_PRIORITY_FOREGROUND; } - ProcessPriorityManager::SetProcessPriority(this, priority); - mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this); + InitInternal(priority, + false, /* Setup Off-main thread compositing */ + false /* Send registered chrome */); } #endif // MOZ_NUWA_PROCESS @@ -1432,6 +1353,101 @@ ContentParent::~ContentParent() } } +void +ContentParent::InitInternal(ProcessPriority aInitialPriority, + bool aSetupOffMainThreadCompositing, + bool aSendRegisteredChrome) +{ + // Set the subprocess's priority. We do this early on because we're likely + // /lowering/ the process's CPU and memory priority, which it has inherited + // from this process. + // + // This call can cause us to send IPC messages to the child process, so it + // must come after the Open() call above. + ProcessPriorityManager::SetProcessPriority(this, aInitialPriority); + + if (aSetupOffMainThreadCompositing) { + // NB: internally, this will send an IPC message to the child + // process to get it to create the CompositorChild. This + // message goes through the regular IPC queue for this + // channel, so delivery will happen-before any other messages + // we send. The CompositorChild must be created before any + // PBrowsers are created, because they rely on the Compositor + // already being around. (Creation is async, so can't happen + // on demand.) + bool useOffMainThreadCompositing = !!CompositorParent::CompositorLoop(); + if (useOffMainThreadCompositing) { + DebugOnly opened = PCompositor::Open(this); + MOZ_ASSERT(opened); + + if (Preferences::GetBool("layers.async-video.enabled",false)) { + opened = PImageBridge::Open(this); + MOZ_ASSERT(opened); + } + } + } + + if (aSendRegisteredChrome) { + nsCOMPtr registrySvc = nsChromeRegistry::GetService(); + nsChromeRegistryChrome* chromeRegistry = + static_cast(registrySvc.get()); + chromeRegistry->SendRegisteredChrome(this); + } + + mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this); + + if (gAppData) { + nsCString version(gAppData->version); + nsCString buildID(gAppData->buildID); + nsCString name(gAppData->name); + nsCString UAName(gAppData->UAName); + + // Sending all information to content process. + unused << SendAppInfo(version, buildID, name, UAName); + } + + nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance(); + if (sheetService) { + // This looks like a lot of work, but in a normal browser session we just + // send two loads. + + nsCOMArray& agentSheets = *sheetService->AgentStyleSheets(); + for (uint32_t i = 0; i < agentSheets.Length(); i++) { + URIParams uri; + SerializeURI(agentSheets[i]->GetSheetURI(), uri); + unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET); + } + + nsCOMArray& userSheets = *sheetService->UserStyleSheets(); + for (uint32_t i = 0; i < userSheets.Length(); i++) { + URIParams uri; + SerializeURI(userSheets[i]->GetSheetURI(), uri); + unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET); + } + + nsCOMArray& authorSheets = *sheetService->AuthorStyleSheets(); + for (uint32_t i = 0; i < authorSheets.Length(); i++) { + URIParams uri; + SerializeURI(authorSheets[i]->GetSheetURI(), uri); + unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET); + } + } + +#ifdef MOZ_CONTENT_SANDBOX + // Bug 921817. We enable the sandbox in RecvSetProcessPrivileges, + // which is where a preallocated process drops unnecessary privileges, + // but a non-preallocated process will already have changed its + // uid/gid/etc immediately after forking. Thus, we send this message, + // which is otherwise a no-op, to sandbox it at an appropriate point + // during startup. + if (mOSPrivileges != base::PRIVILEGES_INHERIT) { + if (!SendSetProcessPrivileges(base::PRIVILEGES_INHERIT)) { + KillHard(); + } + } +#endif +} + bool ContentParent::IsAlive() { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index b70b5616165e..5e64ed2b5561 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -265,6 +265,11 @@ private: // The common initialization for the constructors. void InitializeMembers(); + // The common initialization logic shared by all constuctors. + void InitInternal(ProcessPriority aPriority, + bool aSetupOffMainThreadCompositing, + bool aSendRegisteredChrome); + virtual ~ContentParent(); void Init();