Bug 1094409 - Explain in the preferences UI the reason when e10s is disabled. r=felipe
authorGavin Sharp <gavin@gavinsharp.com>
Wed, 05 Nov 2014 17:01:25 -0800
changeset 214409 789381d7270b143e0dac7cb0dc879532c190107b
parent 214408 9eceae016a7564af2d4827a3425843bea1308e63
child 214410 a75897e664ddd36cb0e538aab1a01a84f23fef75
push id27780
push userkwierso@gmail.com
push dateFri, 07 Nov 2014 02:25:05 +0000
treeherdermozilla-central@e6d47abb6a7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs1094409
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1094409 - Explain in the preferences UI the reason when e10s is disabled. r=felipe
browser/components/preferences/in-content/main.js
toolkit/xre/nsAppRunner.cpp
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -87,19 +87,42 @@ var gMainPane = {
                      gMainPane.restoreDefaultHomePage);
     setEventListener("chooseFolder", "command",
                      gMainPane.chooseFolder);
 
 #ifdef E10S_TESTING_ONLY
     setEventListener("e10sAutoStart", "command",
                      gMainPane.enableE10SChange);
     let e10sCheckbox = document.getElementById("e10sAutoStart");
-    let e10sPref = document.getElementById("browser.tabs.remote.autostart");
-    let e10sTempPref = document.getElementById("e10sTempPref");
-    e10sCheckbox.checked = e10sPref.value || e10sTempPref.value;
+    e10sCheckbox.checked = Services.appinfo.browserTabsRemoteAutostart;
+
+    // If e10s is blocked for some reason unrelated to prefs, we want to disable
+    // the checkbox.
+    if (!Services.appinfo.browserTabsRemoteAutostart) {
+      let e10sBlockedReason = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
+      let appinfo = Services.appinfo.QueryInterface(Ci.nsIObserver);
+      appinfo.observe(e10sBlockedReason, "getE10SBlocked", "")
+      if (e10sBlockedReason.data) {
+        if (e10sBlockedReason.data == "Safe mode") {
+          // If the only reason we're disabled is because of safe mode, then
+          // we want to allow the user to un-toggle the pref.
+          // We're relying on the nsAppRunner code only specifying "Safe mode"
+          // as the reason if the pref is otherwise enabled, and there are no
+          // other reasons to block e10s.
+          // Update the checkbox to reflect the pref state.
+          e10sCheckbox.checked = true;
+        } else {
+          e10sCheckbox.disabled = true;
+          e10sCheckbox.label += " (disabled: " + e10sBlockedReason.data + ")";
+        }
+      }
+    }
+
+    // If E10S is blocked because of safe mode, we want the checkbox to be
+    // enabled
 #endif
 
 #ifdef MOZ_DEV_EDITION
     Cu.import("resource://gre/modules/osfile.jsm");
     let uAppData = OS.Constants.Path.userApplicationDataDir;
     let ignoreSeparateProfile = OS.Path.join(uAppData, "ignore-dev-edition-profile");
 
     setEventListener("separateProfileMode", "command", gMainPane.separateProfileModeChange);
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -610,43 +610,52 @@ KeyboardMayHaveIME()
 
 bool gSafeMode = false;
 
 /**
  * The nsXULAppInfo object implements nsIFactory so that it can be its own
  * singleton.
  */
 class nsXULAppInfo : public nsIXULAppInfo,
+#ifdef NIGHTLY_BUILD
+                     public nsIObserver,
+#endif
 #ifdef XP_WIN
                      public nsIWinAppHelper,
 #endif
 #ifdef MOZ_CRASHREPORTER
                      public nsICrashReporter,
                      public nsIFinishDumpingCallback,
 #endif
                      public nsIXULRuntime
 
 {
 public:
   MOZ_CONSTEXPR nsXULAppInfo() {}
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIXULAPPINFO
   NS_DECL_NSIXULRUNTIME
+#ifdef NIGHTLY_BUILD
+  NS_DECL_NSIOBSERVER
+#endif
 #ifdef MOZ_CRASHREPORTER
   NS_DECL_NSICRASHREPORTER
   NS_DECL_NSIFINISHDUMPINGCALLBACK
 #endif
 #ifdef XP_WIN
   NS_DECL_NSIWINAPPHELPER
 #endif
 };
 
 NS_INTERFACE_MAP_BEGIN(nsXULAppInfo)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULRuntime)
   NS_INTERFACE_MAP_ENTRY(nsIXULRuntime)
+#ifdef NIGHTLY_BUILD
+  NS_INTERFACE_MAP_ENTRY(nsIObserver)
+#endif
 #ifdef XP_WIN
   NS_INTERFACE_MAP_ENTRY(nsIWinAppHelper)
 #endif
 #ifdef MOZ_CRASHREPORTER
   NS_INTERFACE_MAP_ENTRY(nsICrashReporter)
   NS_INTERFACE_MAP_ENTRY(nsIFinishDumpingCallback)
 #endif
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData || 
@@ -837,18 +846,35 @@ nsXULAppInfo::GetProcessID(uint32_t* aRe
   *aResult = GetCurrentProcessId();
 #else
   *aResult = getpid();
 #endif
   return NS_OK;
 }
 
 static bool gBrowserTabsRemoteAutostart = false;
+static nsString gBrowserTabsRemoteDisabledReason;
 static bool gBrowserTabsRemoteAutostartInitialized = false;
 
+#ifdef NIGHTLY_BUILD
+NS_IMETHODIMP
+nsXULAppInfo::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *aData) {
+  if (!nsCRT::strcmp(aTopic, "getE10SBlocked")) {
+    nsCOMPtr<nsISupportsString> ret = do_QueryInterface(aSubject);
+    if (!ret)
+      return NS_ERROR_FAILURE;
+
+    ret->SetData(gBrowserTabsRemoteDisabledReason);
+
+    return NS_OK;
+  }
+  return NS_ERROR_FAILURE;
+}
+#endif
+
 NS_IMETHODIMP
 nsXULAppInfo::GetBrowserTabsRemoteAutostart(bool* aResult)
 {
   *aResult = BrowserTabsRemoteAutostart();
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -4533,18 +4559,20 @@ XRE_DeinitCommandLine()
 GeckoProcessType
 XRE_GetProcessType()
 {
   return mozilla::startup::sChildProcessType;
 }
 
 static void
 LogE10sBlockedReason(const char *reason) {
+  gBrowserTabsRemoteDisabledReason.Assign(NS_ConvertASCIItoUTF16(reason));
+
   nsAutoString msg(NS_LITERAL_STRING("==================\nE10s has been blocked from running because:\n"));
-  msg.Append(NS_ConvertASCIItoUTF16(reason));
+  msg.Append(gBrowserTabsRemoteDisabledReason);
   msg.AppendLiteral("\n==================\n");
   nsCOMPtr<nsIConsoleService> console(do_GetService("@mozilla.org/consoleservice;1"));
   if (console) {
     console->LogStringMessage(msg.get());
   }
 }
 
 bool
@@ -4569,21 +4597,21 @@ mozilla::BrowserTabsRemoteAutostart()
   // Nightly builds, update gBrowserTabsRemoteAutostart based on all the
   // e10s remote relayed prefs we watch.
   bool disabledForA11y = Preferences::GetBool("browser.tabs.remote.autostart.disabled-because-using-a11y", false);
   // Only disable for IME for the automatic pref, not the opt-in one.
   bool disabledForIME = trialPref && KeyboardMayHaveIME();
 
   if (prefEnabled) {
     if (gSafeMode) {
-      LogE10sBlockedReason("Firefox is in safe mode.");
+      LogE10sBlockedReason("Safe mode");
     } else if (disabledForA11y) {
-      LogE10sBlockedReason("An accessibility tool is active.");
+      LogE10sBlockedReason("An accessibility tool is active");
     } else if (disabledForIME) {
-      LogE10sBlockedReason("The keyboard being used has activated IME.");
+      LogE10sBlockedReason("The keyboard being used has activated IME");
     } else {
       gBrowserTabsRemoteAutostart = true;
     }
   }
 #endif
 
 #if defined(XP_WIN) || defined(XP_MACOSX)
   // If for any reason we suspect acceleration will be disabled, disabled
@@ -4630,17 +4658,17 @@ mozilla::BrowserTabsRemoteAutostart()
       const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
       if (acceleratedEnv && (*acceleratedEnv != '0')) {
         accelDisabled = false;
       }
     }
 
     if (accelDisabled) {
       gBrowserTabsRemoteAutostart = false;
-      LogE10sBlockedReason("Hardware acceleration is disabled.");
+      LogE10sBlockedReason("Hardware acceleration is disabled");
     }
   }
 #endif
 
   bool tpEnabled = Preferences::GetBool("privacy.trackingprotection.enabled",
                                         false);
   if (tpEnabled) {
     gBrowserTabsRemoteAutostart = false;