Bug 1257242 - Split the ::BrowserTabsRemoteAutostart() function into two parts, to allow for the blocking policies to be checked independently from the prefs checks. r=jimm a=lizzard IGNORE IDL

MozReview-Commit-ID: qlfYBvHfLI
This commit is contained in:
Felipe Gomes 2016-03-16 17:31:14 -03:00
parent dd269151bd
commit 42f4042d38
3 changed files with 112 additions and 58 deletions

View File

@ -989,6 +989,9 @@ static bool gBrowserTabsRemoteAutostart = false;
static uint64_t gBrowserTabsRemoteStatus = 0;
static bool gBrowserTabsRemoteAutostartInitialized = false;
static bool gMultiprocessBlockPolicyInitialized = false;
static uint32_t gMultiprocessBlockPolicy = 0;
NS_IMETHODIMP
nsXULAppInfo::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) {
if (!nsCRT::strcmp(aTopic, "getE10SBlocked")) {
@ -1010,6 +1013,13 @@ nsXULAppInfo::GetBrowserTabsRemoteAutostart(bool* aResult)
return NS_OK;
}
NS_IMETHODIMP
nsXULAppInfo::GetMultiprocessBlockPolicy(uint32_t* aResult)
{
*aResult = MultiprocessBlockPolicy();
return NS_OK;
}
NS_IMETHODIMP
nsXULAppInfo::GetAccessibilityEnabled(bool* aResult)
{
@ -4660,13 +4670,29 @@ PRTimeToSeconds(PRTime t_usec)
}
#endif // XP_WIN
bool
mozilla::BrowserTabsRemoteAutostart()
{
if (gBrowserTabsRemoteAutostartInitialized) {
return gBrowserTabsRemoteAutostart;
uint32_t
MultiprocessBlockPolicy() {
if (gMultiprocessBlockPolicyInitialized) {
return gMultiprocessBlockPolicy;
}
gMultiprocessBlockPolicyInitialized = true;
/**
* Avoids enabling e10s if there are add-ons installed.
*/
bool addonsCanDisable = Preferences::GetBool("extensions.e10sBlocksEnabling", false);
bool disabledByAddons = Preferences::GetBool("extensions.e10sBlockedByAddons", false);
#ifdef MOZ_CRASHREPORTER
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AddonsShouldHaveBlockedE10s"),
disabledByAddons ? NS_LITERAL_CSTRING("1")
: NS_LITERAL_CSTRING("0"));
#endif
if (addonsCanDisable && disabledByAddons) {
gMultiprocessBlockPolicy = kE10sDisabledForAddons;
return gMultiprocessBlockPolicy;
}
gBrowserTabsRemoteAutostartInitialized = true;
bool disabledForA11y = false;
#ifdef XP_WIN
@ -4698,6 +4724,11 @@ mozilla::BrowserTabsRemoteAutostart()
}
#endif // XP_WIN
if (disabledForA11y) {
gMultiprocessBlockPolicy = kE10sDisabledForAccessibility;
return gMultiprocessBlockPolicy;
}
/**
* Avoids enabling e10s for certain locales that require bidi selection,
* which currently doesn't work well with e10s.
@ -4723,6 +4754,64 @@ mozilla::BrowserTabsRemoteAutostart()
disabledForBidi = true;
}
if (disabledForBidi) {
gMultiprocessBlockPolicy = kE10sDisabledForBidi;
return gMultiprocessBlockPolicy;
}
#if defined(XP_MACOSX)
// If for any reason we suspect acceleration will be disabled, disable
// e10s auto start on mac.
// Check prefs
bool accelDisabled = gfxPrefs::GetSingleton().LayersAccelerationDisabled() &&
!gfxPrefs::LayersAccelerationForceEnabled();
accelDisabled = accelDisabled || !nsCocoaFeatures::AccelerateByDefault();
// Check for blocked drivers
if (!accelDisabled) {
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
if (gfxInfo) {
int32_t status;
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &status)) &&
status != nsIGfxInfo::FEATURE_STATUS_OK) {
accelDisabled = true;
}
}
}
// Check env flags
if (accelDisabled) {
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
if (acceleratedEnv && (*acceleratedEnv != '0')) {
accelDisabled = false;
}
}
if (accelDisabled) {
gMultiprocessBlockPolicy = kE10sDisabledForMacGfx;
return gMultiprocessBlockPolicy;
}
#endif // defined(XP_MACOSX)
/*
* None of the blocking policies matched, so e10s is allowed to run.
* Cache the information and return 0, indicating success.
*/
gMultiprocessBlockPolicy = 0;
return 0;
}
bool
mozilla::BrowserTabsRemoteAutostart()
{
if (gBrowserTabsRemoteAutostartInitialized) {
return gBrowserTabsRemoteAutostart;
}
gBrowserTabsRemoteAutostartInitialized = true;
bool optInPref = Preferences::GetBool("browser.tabs.remote.autostart", false);
bool trialPref = Preferences::GetBool("browser.tabs.remote.autostart.2", false);
bool prefEnabled = optInPref || trialPref;
@ -4735,64 +4824,15 @@ mozilla::BrowserTabsRemoteAutostart()
status = kE10sDisabledByUser;
}
bool addonsCanDisable = Preferences::GetBool("extensions.e10sBlocksEnabling", false);
bool disabledByAddons = Preferences::GetBool("extensions.e10sBlockedByAddons", false);
#ifdef MOZ_CRASHREPORTER
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AddonsShouldHaveBlockedE10s"),
disabledByAddons ? NS_LITERAL_CSTRING("1")
: NS_LITERAL_CSTRING("0"));
#endif
if (prefEnabled) {
if (disabledForA11y) {
status = kE10sDisabledForAccessibility;
} else if (disabledForBidi) {
status = kE10sDisabledForBidi;
} else if (addonsCanDisable && disabledByAddons) {
status = kE10sDisabledForAddons;
uint32_t blockPolicy = MultiprocessBlockPolicy();
if (blockPolicy != 0) {
status = blockPolicy;
} else {
gBrowserTabsRemoteAutostart = true;
}
}
#if defined(XP_MACOSX)
// If for any reason we suspect acceleration will be disabled, disabled
// e10s auto start on mac.
if (gBrowserTabsRemoteAutostart) {
// Check prefs
bool accelDisabled = gfxPrefs::GetSingleton().LayersAccelerationDisabled() &&
!gfxPrefs::LayersAccelerationForceEnabled();
accelDisabled = accelDisabled || !nsCocoaFeatures::AccelerateByDefault();
// Check for blocked drivers
if (!accelDisabled) {
nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
if (gfxInfo) {
int32_t status;
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &status)) &&
status != nsIGfxInfo::FEATURE_STATUS_OK) {
accelDisabled = true;
}
}
}
// Check env flags
if (accelDisabled) {
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
if (acceleratedEnv && (*acceleratedEnv != '0')) {
accelDisabled = false;
}
}
if (accelDisabled) {
gBrowserTabsRemoteAutostart = false;
status = kE10sDisabledForMacGfx;
}
}
#endif // defined(XP_MACOSX)
// Uber override pref for manual testing purposes
if (Preferences::GetBool(kForceEnableE10sPref, false)) {
gBrowserTabsRemoteAutostart = true;

View File

@ -120,4 +120,11 @@ extern GeckoProcessType sChildProcessType;
*/
void SetupErrorHandling(const char* progname);
/**
* A numeric value indicating whether multiprocess might be blocked.
* Possible values can be found at nsAppRunner.cpp. A value of 0
* represents not blocking.
*/
uint32_t MultiprocessBlockPolicy();
#endif // nsAppRunner_h__

View File

@ -91,6 +91,13 @@ interface nsIXULRuntime : nsISupports
*/
readonly attribute boolean browserTabsRemoteAutostart;
/**
* A numeric value indicating whether multiprocess might be blocked.
* Possible values can be found at nsAppRunner.cpp. A value of 0
* represents not blocking.
*/
readonly attribute unsigned long multiprocessBlockPolicy;
/**
* If true, the accessibility service is running.
*/