Skip to content

Commit

Permalink
Bug 1384336 - Stop using OS-level event loop in content process (r=ms…
Browse files Browse the repository at this point in the history
…tange)

MozReview-Commit-ID: 1ouSlgGchWl
  • Loading branch information
bill-mccloskey committed Aug 10, 2017
1 parent c11382c commit fea9857
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 6 deletions.
14 changes: 14 additions & 0 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,11 @@ GetDirectoryPath(const char *aPath) {
}
#endif // DEBUG

extern "C" {
void CGSSetDenyWindowServerConnections(bool);
void CGSShutdownServerConnections();
};

static bool
StartMacOSContentSandbox()
{
Expand All @@ -1460,6 +1465,15 @@ StartMacOSContentSandbox()
return false;
}

if (!XRE_UseNativeEventProcessing()) {
// If we've opened a connection to the window server, shut it down now. Forbid
// future connections as well. We do this for sandboxing, but it also ensures
// that the Activity Monitor will not label the content process as "Not
// responding" because it's not running a native event loop. See bug 1384336.
CGSSetDenyWindowServerConnections(true);
CGSShutdownServerConnections();
}

nsAutoCString appPath, appBinaryPath, appDir;
if (!GetAppPaths(appPath, appBinaryPath, appDir)) {
MOZ_CRASH("Error resolving child process path");
Expand Down
1 change: 1 addition & 0 deletions dom/ipc/ContentPrefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const char* mozilla::dom::ContentPrefs::gInitPrefs[] = {
"dom.forms.autocomplete.formautofill",
"dom.ipc.processPriorityManager.backgroundGracePeriodMS",
"dom.ipc.processPriorityManager.backgroundPerceivableGracePeriodMS",
"dom.ipc.useNativeEventProcessing.content",
"dom.max_chrome_script_run_time",
"dom.max_script_run_time",
"dom.mozBrowserFramesEnabled",
Expand Down
3 changes: 3 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,9 @@ pref("dom.ipc.processCount.file", 1);
// WebExtensions only support a single extension process.
pref("dom.ipc.processCount.extension", 1);

// Don't use a native event loop in the content process.
pref("dom.ipc.useNativeEventProcessing.content", false);

// Disable support for SVG
pref("svg.disabled", false);

Expand Down
18 changes: 18 additions & 0 deletions toolkit/xre/nsAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5012,6 +5012,24 @@ XRE_IsContentProcess()
return XRE_GetProcessType() == GeckoProcessType_Content;
}

bool
XRE_UseNativeEventProcessing()
{
if (XRE_IsContentProcess()) {
static bool sInited = false;
static bool sUseNativeEventProcessing = false;
if (!sInited) {
Preferences::AddBoolVarCache(&sUseNativeEventProcessing,
"dom.ipc.useNativeEventProcessing.content");
sInited = true;
}

return sUseNativeEventProcessing;
}

return true;
}

// If you add anything to this enum, please update about:support to reflect it
enum {
kE10sEnabledByUser = 0,
Expand Down
2 changes: 1 addition & 1 deletion toolkit/xre/nsEmbedFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ XRE_RunAppShell()
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));
NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE);
#if defined(XP_MACOSX)
{
if (XRE_UseNativeEventProcessing()) {
// In content processes that want XPCOM (and hence want
// AppShell), we usually run our hybrid event loop through
// MessagePump::Run(), by way of nsBaseAppShell::Run(). The
Expand Down
10 changes: 8 additions & 2 deletions widget/cocoa/nsAppShell.mm
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,19 @@ - (void)beginMenuTracking:(NSNotification*)aNotification;
AddScreenWakeLockListener();
}

NS_OBJC_TRY_ABORT([NSApp run]);
// We use the native Gecko event loop in content processes.
nsresult rv = NS_OK;
if (XRE_UseNativeEventProcessing()) {
NS_OBJC_TRY_ABORT([NSApp run]);
} else {
rv = nsBaseAppShell::Run();
}

if (XRE_IsParentProcess()) {
RemoveScreenWakeLockListener();
}

return NS_OK;
return rv;
}

NS_IMETHODIMP
Expand Down
8 changes: 5 additions & 3 deletions widget/nsBaseAppShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ nsBaseAppShell::Init()
{
// Configure ourselves as an observer for the current thread:

nsCOMPtr<nsIThreadInternal> threadInt =
if (XRE_UseNativeEventProcessing()) {
nsCOMPtr<nsIThreadInternal> threadInt =
do_QueryInterface(NS_GetCurrentThread());
NS_ENSURE_STATE(threadInt);
NS_ENSURE_STATE(threadInt);

threadInt->SetObserver(this);
threadInt->SetObserver(this);
}

nsCOMPtr<nsIObserverService> obsSvc =
mozilla::services::GetObserverService();
Expand Down
7 changes: 7 additions & 0 deletions xpcom/build/nsXULAppAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ XRE_API(bool,
XRE_API(bool,
XRE_IsGPUProcess, ())

/**
* Returns true if the appshell should run its own native event loop. Returns
* false if we should rely solely on the Gecko event loop.
*/
XRE_API(bool,
XRE_UseNativeEventProcessing, ())

typedef void (*MainFunction)(void* aData);

XRE_API(nsresult,
Expand Down

0 comments on commit fea9857

Please sign in to comment.