bool GMPProcessChild::Init() { nsAutoString pluginFilename; nsAutoString voucherFilename; #if defined(OS_POSIX) // NB: need to be very careful in ensuring that the first arg // (after the binary name) here is indeed the plugin module path. // Keep in sync with dom/plugins/PluginModuleParent. std::vector<std::string> values = CommandLine::ForCurrentProcess()->argv(); MOZ_ASSERT(values.size() >= 3, "not enough args"); pluginFilename = NS_ConvertUTF8toUTF16(nsDependentCString(values[1].c_str())); voucherFilename = NS_ConvertUTF8toUTF16(nsDependentCString(values[2].c_str())); #elif defined(OS_WIN) std::vector<std::wstring> values = CommandLine::ForCurrentProcess()->GetLooseValues(); MOZ_ASSERT(values.size() >= 2, "not enough loose args"); pluginFilename = nsDependentString(values[0].c_str()); voucherFilename = nsDependentString(values[1].c_str()); #else #error Not implemented #endif BackgroundHangMonitor::Startup(); return mPlugin.Init(pluginFilename, voucherFilename, ParentPid(), IOThreadChild::message_loop(), IOThreadChild::channel()); }
bool IPDLUnitTestProcessChild::Init() { IPDLUnitTestChildInit(IOThreadChild::channel(), ParentPid(), IOThreadChild::message_loop()); if (NS_FAILED(nsRegion::InitStatic())) return false; return true; }
bool ContentProcess::Init() { mContent.Init(IOThreadChild::message_loop(), ParentPid(), IOThreadChild::channel()); mXREEmbed.Start(); mContent.InitXPCOM(); mContent.InitGraphicsDeviceData(); #if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX) SetUpSandboxEnvironment(); #endif return true; }
bool PluginProcessChild::Init() { nsDebugImpl::SetMultiprocessMode("NPAPI"); #if defined(XP_MACOSX) // Remove the trigger for "dyld interposing" that we added in // GeckoChildProcessHost::PerformAsyncLaunchInternal(), in the host // process just before we were launched. Dyld interposing will still // happen in our process (the plugin child process). But we don't want // it to happen in any processes that the plugin might launch from our // process. nsCString interpose(PR_GetEnv("DYLD_INSERT_LIBRARIES")); if (!interpose.IsEmpty()) { // If we added the path to libplugin_child_interpose.dylib to an // existing DYLD_INSERT_LIBRARIES, we appended it to the end, after a // ":" path seperator. int32_t lastSeparatorPos = interpose.RFind(":"); int32_t lastTriggerPos = interpose.RFind("libplugin_child_interpose.dylib"); bool needsReset = false; if (lastTriggerPos != -1) { if (lastSeparatorPos == -1) { interpose.Truncate(); needsReset = true; } else if (lastTriggerPos > lastSeparatorPos) { interpose.SetLength(lastSeparatorPos); needsReset = true; } } if (needsReset) { nsCString setInterpose("DYLD_INSERT_LIBRARIES="); if (!interpose.IsEmpty()) { setInterpose.Append(interpose); } // Values passed to PR_SetEnv() must be seperately allocated. char* setInterposePtr = strdup(setInterpose.get()); PR_SetEnv(setInterposePtr); } } #endif #ifdef XP_WIN // Drag-and-drop needs OleInitialize to be called, and Silverlight depends // on the host calling CoInitialize (which is called by OleInitialize). ::OleInitialize(nullptr); #endif // Certain plugins, such as flash, steal the unhandled exception filter // thus we never get crash reports when they fault. This call fixes it. message_loop()->set_exception_restoration(true); std::string pluginFilename; #if defined(OS_POSIX) // NB: need to be very careful in ensuring that the first arg // (after the binary name) here is indeed the plugin module path. // Keep in sync with dom/plugins/PluginModuleParent. std::vector<std::string> values = CommandLine::ForCurrentProcess()->argv(); MOZ_ASSERT(values.size() >= 2, "not enough args"); pluginFilename = UnmungePluginDsoPath(values[1]); #elif defined(OS_WIN) std::vector<std::wstring> values = CommandLine::ForCurrentProcess()->GetLooseValues(); MOZ_ASSERT(values.size() >= 1, "not enough loose args"); if (ShouldProtectPluginCurrentDirectory(values[0].c_str())) { SanitizeEnvironmentVariables(); SetDllDirectory(L""); } pluginFilename = WideToUTF8(values[0]); #if defined(MOZ_SANDBOX) // This is probably the earliest we would want to start the sandbox. // As we attempt to tighten the sandbox, we may need to consider moving this // to later in the plugin initialization. mozilla::SandboxTarget::Instance()->StartSandbox(); #endif #else # error Sorry #endif if (NS_FAILED(nsRegion::InitStatic())) { NS_ERROR("Could not initialize nsRegion"); return false; } bool retval = mPlugin.InitForChrome(pluginFilename, ParentPid(), IOThreadChild::message_loop(), IOThreadChild::channel()); #if defined(XP_MACOSX) if (nsCocoaFeatures::OnYosemiteOrLater()) { // Explicitly turn off CGEvent logging. This works around bug 1092855. // If there are already CGEvents in the log, turning off logging also // causes those events to be written to disk. But at this point no // CGEvents have yet been processed. CGEvents are events (usually // input events) pulled from the WindowServer. An option of 0x80000008 // turns on CGEvent logging. CGSSetDebugOptions(0x80000007); } #endif return retval; }
bool ContentProcess::Init(int aArgc, char* aArgv[]) { // If passed in grab the application path for xpcom init bool foundAppdir = false; bool foundChildID = false; bool foundIsForBrowser = false; bool foundIntPrefs = false; bool foundBoolPrefs = false; bool foundStringPrefs = false; uint64_t childID; bool isForBrowser; #if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX) // If passed in grab the profile path for sandboxing bool foundProfile = false; nsCOMPtr<nsIFile> profileDir; #endif InfallibleTArray<PrefSetting> prefsArray; for (int idx = aArgc; idx > 0; idx--) { if (!aArgv[idx]) { continue; } if (!strcmp(aArgv[idx], "-appdir")) { MOZ_ASSERT(!foundAppdir); if (foundAppdir) { continue; } nsCString appDir; appDir.Assign(nsDependentCString(aArgv[idx+1])); mXREEmbed.SetAppDir(appDir); foundAppdir = true; } else if (!strcmp(aArgv[idx], "-childID")) { MOZ_ASSERT(!foundChildID); if (foundChildID) { continue; } if (idx + 1 < aArgc) { childID = strtoull(aArgv[idx + 1], nullptr, 10); foundChildID = true; } } else if (!strcmp(aArgv[idx], "-isForBrowser") || !strcmp(aArgv[idx], "-notForBrowser")) { MOZ_ASSERT(!foundIsForBrowser); if (foundIsForBrowser) { continue; } isForBrowser = strcmp(aArgv[idx], "-notForBrowser"); foundIsForBrowser = true; } else if (!strcmp(aArgv[idx], "-intPrefs")) { SET_PREF_PHASE(BEGIN_INIT_PREFS); char* str = aArgv[idx + 1]; while (*str) { int32_t index = strtol(str, &str, 10); MOZ_ASSERT(str[0] == ':'); str++; MaybePrefValue value(PrefValue(static_cast<int32_t>(strtol(str, &str, 10)))); MOZ_ASSERT(str[0] == '|'); str++; PrefSetting pref(nsCString(ContentPrefs::GetContentPref(index)), value, MaybePrefValue()); prefsArray.AppendElement(pref); } SET_PREF_PHASE(END_INIT_PREFS); foundIntPrefs = true; } else if (!strcmp(aArgv[idx], "-boolPrefs")) { SET_PREF_PHASE(BEGIN_INIT_PREFS); char* str = aArgv[idx + 1]; while (*str) { int32_t index = strtol(str, &str, 10); MOZ_ASSERT(str[0] == ':'); str++; MaybePrefValue value(PrefValue(!!strtol(str, &str, 10))); MOZ_ASSERT(str[0] == '|'); str++; PrefSetting pref(nsCString(ContentPrefs::GetContentPref(index)), value, MaybePrefValue()); prefsArray.AppendElement(pref); } SET_PREF_PHASE(END_INIT_PREFS); foundBoolPrefs = true; } else if (!strcmp(aArgv[idx], "-stringPrefs")) { SET_PREF_PHASE(BEGIN_INIT_PREFS); char* str = aArgv[idx + 1]; while (*str) { int32_t index = strtol(str, &str, 10); MOZ_ASSERT(str[0] == ':'); str++; int32_t length = strtol(str, &str, 10); MOZ_ASSERT(str[0] == ';'); str++; MaybePrefValue value(PrefValue(nsCString(str, length))); PrefSetting pref(nsCString(ContentPrefs::GetContentPref(index)), value, MaybePrefValue()); prefsArray.AppendElement(pref); str += length + 1; MOZ_ASSERT(*(str - 1) == '|'); } SET_PREF_PHASE(END_INIT_PREFS); foundStringPrefs = true; } else if (!strcmp(aArgv[idx], "-safeMode")) { gSafeMode = true; } #if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX) else if (!strcmp(aArgv[idx], "-profile")) { MOZ_ASSERT(!foundProfile); if (foundProfile) { continue; } bool flag; nsresult rv = XRE_GetFileFromPath(aArgv[idx+1], getter_AddRefs(profileDir)); if (NS_FAILED(rv) || NS_FAILED(profileDir->Exists(&flag)) || !flag) { NS_WARNING("Invalid profile directory passed to content process."); profileDir = nullptr; } foundProfile = true; } #endif /* XP_MACOSX && MOZ_CONTENT_SANDBOX */ bool allFound = foundAppdir && foundChildID && foundIsForBrowser && foundIntPrefs && foundBoolPrefs && foundStringPrefs; #if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX) allFound &= foundProfile; #endif if (allFound) { break; } } Preferences::SetInitPreferences(&prefsArray); mContent.Init(IOThreadChild::message_loop(), ParentPid(), IOThreadChild::channel(), childID, isForBrowser); mXREEmbed.Start(); #if (defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX) mContent.SetProfileDir(profileDir); #endif #if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX) SetUpSandboxEnvironment(); #endif return true; }