Bug 1357348 - Add the performance section to set the hardware acceleration and content process count prefs, r=jaws draft
authorEvan Tseng <evan@tseng.io>
Wed, 19 Apr 2017 12:02:34 +0800
changeset 569263 8cb38edc572825debfb88a4e9b425462a3ebc099
parent 565752 27311156637f9b5d4504373967e01c4241902ae7
child 626152 15208e4efa4d47b218a27ea09fc5eaaf2cebcf86
push id56112
push userbmo:evan@tseng.io
push dateThu, 27 Apr 2017 07:43:50 +0000
reviewersjaws
bugs1357348
milestone55.0a1
Bug 1357348 - Add the performance section to set the hardware acceleration and content process count prefs, r=jaws MozReview-Commit-ID: IendRIuWP85
browser/app/profile/firefox.js
browser/components/preferences/in-content/main.js
browser/components/preferences/in-content/main.xul
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_performance.js
browser/components/preferences/in-content/tests/browser_search_within_preferences.js
browser/locales/en-US/chrome/browser/preferences/advanced.dtd
browser/locales/en-US/chrome/browser/preferences/preferences.properties
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -683,16 +683,18 @@ pref("browser.preferences.search", false
 // The Offline(Appcache) Group section in about:preferences will be hidden.
 // And the task to clear appcache will be done by Storage Management.
 #if defined(NIGHTLY_BUILD)
 pref("browser.preferences.offlineGroup.enabled", false);
 #else
 pref("browser.preferences.offlineGroup.enabled", true);
 #endif
 
+pref("browser.preferences.defaultPerformanceSettings.enabled", true);
+
 pref("browser.download.show_plugins_in_list", true);
 pref("browser.download.hide_plugins_without_extensions", true);
 
 // Backspace and Shift+Backspace behavior
 // 0 goes Back/Forward
 // 1 act like PgUp/PgDown
 // 2 and other values, nothing
 #ifdef UNIX_BUT_NOT_MAC
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -60,16 +60,18 @@ var gMainPane = {
         window.setInterval(this.updateSetDefaultBrowser.bind(this), 1000);
       }
     }
 
     gEngineView = new EngineView(new EngineStore());
     document.getElementById("engineList").view = gEngineView;
     this.buildDefaultEngineDropDown();
 
+    this.buildContentProcessCountMenuList();
+
     let addEnginesLink = document.getElementById("addEngines");
     let searchEnginesURL = Services.wm.getMostRecentWindow("navigator:browser")
                                       .BrowserSearch.searchEnginesURL;
     addEnginesLink.setAttribute("href", searchEnginesURL);
 
     window.addEventListener("click", this);
     window.addEventListener("command", this);
     window.addEventListener("dragstart", this);
@@ -86,16 +88,35 @@ var gMainPane = {
 
     let suggestsPref =
       document.getElementById("browser.search.suggest.enabled");
     suggestsPref.addEventListener("change", () => {
       this.updateSuggestsCheckbox();
     });
     this.updateSuggestsCheckbox();
 
+    let processCountPref =
+      document.getElementById("dom.ipc.processCount");
+    processCountPref.addEventListener("change", () => {
+      this.updateDefaultPerformanceSettingsPref();
+    });
+    let accelerationPref =
+      document.getElementById("layers.acceleration.disabled");
+    accelerationPref.addEventListener("change", () => {
+      this.updateDefaultPerformanceSettingsPref();
+    });
+    this.updateDefaultPerformanceSettingsPref();
+
+    let defaultPerformancePref =
+      document.getElementById("browser.preferences.defaultPerformanceSettings.enabled");
+    defaultPerformancePref.addEventListener("change", () => {
+      this.updatePerformanceSettingsBox();
+    });
+    this.updatePerformanceSettingsBox();
+
     // set up the "use current page" label-changing listener
     this._updateUseCurrentButton();
     window.addEventListener("focus", this._updateUseCurrentButton.bind(this));
 
     this.updateBrowserStartupLastSession();
 
     if (AppConstants.platform == "win") {
       // Functionality for "Show tabs in taskbar" on Windows 7 and up.
@@ -787,16 +808,53 @@ var gMainPane = {
       urlbarSuggests.checked = false;
     }
 
     let permanentPBLabel =
       document.getElementById("urlBarSuggestionPermanentPBLabel");
     permanentPBLabel.hidden = urlbarSuggests.hidden || !permanentPB;
   },
 
+  updateDefaultPerformanceSettingsPref() {
+    let defaultPerformancePref =
+      document.getElementById("browser.preferences.defaultPerformanceSettings.enabled");
+    let processCountPref = document.getElementById("dom.ipc.processCount");
+    let accelerationPref = document.getElementById("layers.acceleration.disabled");
+    if (processCountPref.value != processCountPref.defaultValue ||
+        accelerationPref.value != accelerationPref.defaultValue) {
+      defaultPerformancePref.value = false;
+    }
+  },
+
+  updatePerformanceSettingsBox() {
+    let defaultPerformancePref =
+      document.getElementById("browser.preferences.defaultPerformanceSettings.enabled");
+    let performanceSettings = document.getElementById("performanceSettings");
+    if (defaultPerformancePref.value) {
+      let processCountPref = document.getElementById("dom.ipc.processCount");
+      let accelerationPref = document.getElementById("layers.acceleration.disabled");
+      processCountPref.value = processCountPref.defaultValue;
+      accelerationPref.value = accelerationPref.defaultValue;
+      performanceSettings.hidden = true;
+    } else {
+      performanceSettings.hidden = false;
+    }
+  },
+
+  buildContentProcessCountMenuList() {
+    let processCountPref = document.getElementById("dom.ipc.processCount");
+    let bundlePreferences = document.getElementById("bundlePreferences");
+    let label = bundlePreferences.getFormattedString("defaultContentProcessCount",
+      [processCountPref.defaultValue]);
+    let contentProcessCount =
+      document.querySelector(`#contentProcessCount > menupopup >
+                              menuitem[value="${processCountPref.defaultValue}"]`);
+    contentProcessCount.label = label;
+  },
+
   buildDefaultEngineDropDown() {
     // This is called each time something affects the list of engines.
     let list = document.getElementById("defaultEngine");
     // Set selection to the current default engine.
     let currentEngine = Services.search.currentEngine.name;
 
     // If the current engine isn't in the list any more, select the first item.
     let engines = gEngineView._engineStore._engines;
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -7,16 +7,18 @@
 <script type="application/javascript"
         src="chrome://browser/content/preferences/in-content/main.js"/>
 
 <script type="application/javascript"
         src="chrome://mozapps/content/preferences/fontbuilder.js"/>
 
 <stringbundle id="engineManagerBundle" src="chrome://browser/locale/engineManager.properties"/>
 
+<stringbundle id="bundlePreferences" src="chrome://browser/locale/preferences.properties"/>
+
 <preferences id="mainPreferences" hidden="true" data-category="paneGeneral">
 
 #ifdef E10S_TESTING_ONLY
     <preference id="browser.tabs.remote.autostart"
                 name="browser.tabs.remote.autostart"
                 type="bool"/>
     <preference id="e10sTempPref"
                 name="browser.tabs.remote.autostart.2"
@@ -172,35 +174,44 @@
      - set to true to enable finer page scrolling than line-by-line on page-up,
        page-down, and other such page movements -->
   <preference id="general.autoScroll"
               name="general.autoScroll"
               type="bool"/>
   <preference id="general.smoothScroll"
               name="general.smoothScroll"
               type="bool"/>
-  <preference id="layers.acceleration.disabled"
-              name="layers.acceleration.disabled"
-              type="bool"
-              inverted="true"/>
 #ifdef XP_WIN
   <preference id="gfx.direct2d.disabled"
               name="gfx.direct2d.disabled"
               type="bool"
               inverted="true"/>
 #endif
   <preference id="layout.spellcheckDefault"
               name="layout.spellcheckDefault"
               type="int"/>
 
 #ifdef MOZ_TELEMETRY_REPORTING
   <preference id="toolkit.telemetry.enabled"
               name="toolkit.telemetry.enabled"
               type="bool"/>
 #endif
+
+  <preference id="browser.preferences.defaultPerformanceSettings.enabled"
+              name="browser.preferences.defaultPerformanceSettings.enabled"
+              type="bool"/>
+
+  <preference id="dom.ipc.processCount"
+              name="dom.ipc.processCount"
+              type="int"/>
+
+  <preference id="layers.acceleration.disabled"
+              name="layers.acceleration.disabled"
+              type="bool"
+              inverted="true"/>
 </preferences>
 
 <hbox id="header-general"
       class="header"
       hidden="true"
       data-category="paneGeneral">
   <label class="header-name" flex="1">&paneGeneral.title;</label>
 </hbox>
@@ -545,13 +556,42 @@
   <checkbox id="useAutoScroll"
             label="&useAutoScroll.label;"
             accesskey="&useAutoScroll.accesskey;"
             preference="general.autoScroll"/>
   <checkbox id="useSmoothScrolling"
             label="&useSmoothScrolling.label;"
             accesskey="&useSmoothScrolling.accesskey;"
             preference="general.smoothScroll"/>
-  <checkbox id="allowHWAccel"
-            label="&allowHWAccel.label;"
-            accesskey="&allowHWAccel.accesskey;"
-            preference="layers.acceleration.disabled"/>
 </groupbox>
+
+<!-- Performance -->
+<groupbox id="performanceGroup" data-category="paneGeneral" hidden="true">
+  <caption><label>&performance.label;</label></caption>
+
+  <checkbox id="useRecommendedPerformanceSettings"
+            label="&useRecommendedPerformanceSettings.label;"
+            accesskey="&useRecommendedPerformanceSettings.accesskey;"
+            preference="browser.preferences.defaultPerformanceSettings.enabled"/>
+  <description class="indent">&useRecommendedPerformanceSettings.description;</description>
+
+  <vbox id="performanceSettings" class="indent" hidden="true">
+    <checkbox id="allowHWAccel"
+              label="&allowHWAccel.label;"
+              accesskey="&allowHWAccel.accesskey;"
+              preference="layers.acceleration.disabled"/>
+    <hbox align="center">
+      <label id="limitContentProcess" accesskey="&limitContentProcess.accesskey;" control="contentProcessCount">&limitContentProcess.label;</label>
+      <menulist id="contentProcessCount" preference="dom.ipc.processCount">
+        <menupopup>
+          <menuitem label="1" value="1"/>
+          <menuitem label="2" value="2"/>
+          <menuitem label="3" value="3"/>
+          <menuitem label="4" value="4"/>
+          <menuitem label="5" value="5"/>
+          <menuitem label="6" value="6"/>
+          <menuitem label="7" value="7"/>
+        </menupopup>
+      </menulist>
+    </hbox>
+    <description>&limitContentProcess.description;</description>
+  </vbox>
+</groupbox>
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -26,16 +26,17 @@ skip-if = os != "win" # This test tests 
 [browser_cookies_exceptions.js]
 [browser_defaultbrowser_alwayscheck.js]
 [browser_healthreport.js]
 skip-if = true || !healthreport # Bug 1185403 for the "true"
 [browser_homepages_filter_aboutpreferences.js]
 [browser_layersacceleration.js]
 [browser_masterpassword.js]
 [browser_notifications_do_not_disturb.js]
+[browser_performance.js]
 [browser_permissions_urlFieldHidden.js]
 [browser_proxy_backup.js]
 [browser_privacypane_1.js]
 [browser_privacypane_3.js]
 [browser_privacypane_4.js]
 [browser_privacypane_5.js]
 [browser_privacypane_8.js]
 [browser_sanitizeOnShutdown_prefLocked.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_performance.js
@@ -0,0 +1,116 @@
+SpecialPowers.pushPrefEnv({set: [
+  ["browser.preferences.defaultPerformanceSettings.enabled", true],
+  ["dom.ipc.processCount", 4],
+  ["layers.acceleration.disabled", false],
+]});
+
+add_task(function*() {
+  let prefs = yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
+
+  let doc = gBrowser.contentDocument;
+  let useRecommendedPerformanceSettings = doc.querySelector("#useRecommendedPerformanceSettings");
+
+  is(Services.prefs.getBoolPref("browser.preferences.defaultPerformanceSettings.enabled"), true,
+    "pref value should be true before clicking on checkbox");
+  ok(useRecommendedPerformanceSettings.checked, "checkbox should be checked before clicking on checkbox");
+
+  useRecommendedPerformanceSettings.click();
+
+  let performanceSettings = doc.querySelector("#performanceSettings");
+  is(performanceSettings.hidden, false, "performance settings section is shown");
+
+  is(Services.prefs.getBoolPref("browser.preferences.defaultPerformanceSettings.enabled"), false,
+     "pref value should be false after clicking on checkbox");
+  ok(!useRecommendedPerformanceSettings.checked, "checkbox should not be checked after clicking on checkbox");
+
+  let allowHWAccel = doc.querySelector("#allowHWAccel");
+  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), false,
+    "pref value should be false before clicking on checkbox");
+  ok(allowHWAccel.checked, "checkbox should be checked");
+
+  let contentProcessCount = doc.querySelector("#contentProcessCount");
+  is(Services.prefs.getIntPref("dom.ipc.processCount"), 4, "default pref value should be default value");
+  is(contentProcessCount.selectedItem.value, 4, "selected item should be the default one");
+
+  allowHWAccel.click();
+  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), true,
+    "pref value should be true after clicking on checkbox");
+  ok(!allowHWAccel.checked, "checkbox should not be checked");
+
+  contentProcessCount.value = 7;
+  contentProcessCount.doCommand();
+  is(Services.prefs.getIntPref("dom.ipc.processCount"), 7, "pref value should be 7");
+  is(contentProcessCount.selectedItem.value, 7, "selected item should be 7");
+
+  allowHWAccel.click();
+  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), false,
+    "pref value should be false after clicking on checkbox");
+  ok(allowHWAccel.checked, "checkbox should not be checked");
+
+  contentProcessCount.value = 4;
+  contentProcessCount.doCommand();
+  is(Services.prefs.getIntPref("dom.ipc.processCount"), 4, "pref value should be default value");
+  is(contentProcessCount.selectedItem.value, 4, "selected item should be default one");
+
+  is(performanceSettings.hidden, false, "performance settings section should be still shown");
+
+  Services.prefs.setBoolPref("browser.preferences.defaultPerformanceSettings.enabled", true);
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+add_task(function*() {
+  let prefs = yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
+
+  let doc = gBrowser.contentDocument;
+  let performanceSettings = doc.querySelector("#performanceSettings");
+
+  is(performanceSettings.hidden, true, "performance settings section should not be shown");
+
+  Services.prefs.setBoolPref("browser.preferences.defaultPerformanceSettings.enabled", false);
+
+  is(performanceSettings.hidden, false, "performance settings section should be shown");
+
+  Services.prefs.setBoolPref("browser.preferences.defaultPerformanceSettings.enabled", true);
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+add_task(function*() {
+  Services.prefs.setIntPref("dom.ipc.processCount", 7);
+
+  let prefs = yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
+
+  let doc = gBrowser.contentDocument;
+
+  let performanceSettings = doc.querySelector("#performanceSettings");
+  is(performanceSettings.hidden, false, "performance settings section should be shown");
+
+  let contentProcessCount = doc.querySelector("#contentProcessCount");
+  is(Services.prefs.getIntPref("dom.ipc.processCount"), 7, "pref value should be 7");
+  is(contentProcessCount.selectedItem.value, 7, "selected item should be 7");
+
+  Services.prefs.setBoolPref("browser.preferences.defaultPerformanceSettings.enabled", true);
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+add_task(function*() {
+  Services.prefs.setBoolPref("layers.acceleration.disabled", true);
+
+  let prefs = yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+  is(prefs.selectedPane, "paneGeneral", "General pane was selected");
+
+  let doc = gBrowser.contentDocument;
+
+  let performanceSettings = doc.querySelector("#performanceSettings");
+  is(performanceSettings.hidden, false, "performance settings section should be shown");
+
+  let allowHWAccel = doc.querySelector("#allowHWAccel");
+  is(Services.prefs.getBoolPref("layers.acceleration.disabled"), true,
+    "pref value is false");
+  ok(!allowHWAccel.checked, "checkbox should not be checked");
+
+  Services.prefs.setBoolPref("browser.preferences.defaultPerformanceSettings.enabled", true);
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
--- a/browser/components/preferences/in-content/tests/browser_search_within_preferences.js
+++ b/browser/components/preferences/in-content/tests/browser_search_within_preferences.js
@@ -104,16 +104,17 @@ add_task(function*() {
     if (child.id == "startupGroup"
     || child.id == "defaultEngineGroup"
     || child.id == "oneClickSearchProvidersGroup"
     || child.id == "paneGeneral"
     || child.id == "accessibilityGroup"
     || child.id == "languagesGroup"
     || child.id == "fontsGroup"
     || child.id == "browsingGroup"
+    || child.id == "performanceGroup"
     || child.id == "header-general") {
       is_element_visible(child, "Should be in general tab");
     } else if (child.id) {
       is_element_hidden(child, "Should not be in general tab");
     }
   }
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
--- a/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
+++ b/browser/locales/en-US/chrome/browser/preferences/advanced.dtd
@@ -18,18 +18,16 @@
 <!ENTITY useOnScreenKeyboard.accesskey   "k">
 
 <!ENTITY browsing.label                  "Browsing">
 
 <!ENTITY useAutoScroll.label             "Use autoscrolling">
 <!ENTITY useAutoScroll.accesskey         "a">
 <!ENTITY useSmoothScrolling.label        "Use smooth scrolling">
 <!ENTITY useSmoothScrolling.accesskey    "m">
-<!ENTITY allowHWAccel.label              "Use hardware acceleration when available">
-<!ENTITY allowHWAccel.accesskey          "r">
 <!ENTITY checkUserSpelling.label         "Check your spelling as you type">
 <!ENTITY checkUserSpelling.accesskey     "t">
 
 <!ENTITY dataChoicesTab.label            "Data Choices">
 
 <!ENTITY healthReportDesc.label          "Helps you understand your browser performance and shares data with &vendorShortName; about your browser health">
 <!ENTITY enableHealthReport.label        "Enable &brandShortName; Health Report">
 <!ENTITY enableHealthReport.accesskey    "R">
@@ -121,8 +119,22 @@
 <!ENTITY selectCerts.ask                 "Ask you every time">
 <!ENTITY selectCerts.ask.accesskey       "A">
 <!ENTITY enableOCSP.label                "Query OCSP responder servers to confirm the current validity of certificates">
 <!ENTITY enableOCSP.accesskey            "Q">
 <!ENTITY viewCerts.label                 "View Certificates">
 <!ENTITY viewCerts.accesskey             "C">
 <!ENTITY viewSecurityDevices.label       "Security Devices">
 <!ENTITY viewSecurityDevices.accesskey   "D">
+
+<!ENTITY performance.label               "Performance">
+<!ENTITY useRecommendedPerformanceSettings.label
+                                         "Use recommended performance settings">
+<!ENTITY useRecommendedPerformanceSettings.description
+                                         "Recommended performance settings are tailored to your computer.">
+<!ENTITY useRecommendedPerformanceSettings.accesskey
+                                         "U">
+<!ENTITY limitContentProcess.label       "Content process limit">
+<!ENTITY limitContentProcess.description
+                                         "More content processes can make &brandShortName; more responsive when using multiple tabs, but will also consume more memory.">
+<!ENTITY limitContentProcess.accesskey   "L">
+<!ENTITY allowHWAccel.label              "Use hardware acceleration when available">
+<!ENTITY allowHWAccel.accesskey          "r">
--- a/browser/locales/en-US/chrome/browser/preferences/preferences.properties
+++ b/browser/locales/en-US/chrome/browser/preferences/preferences.properties
@@ -255,8 +255,11 @@ removeContainerMsg=If you remove this Co
 removeContainerOkButton=Remove this Container
 removeContainerButton2=Don’t remove this Container
 
 # Search Results Pane
 # LOCALIZATION NOTE %S will be replaced by the word being searched
 searchResults.sorryMessage=Sorry! No results were found for “%S”
 # LOCALIZATION NOTE %S gets replaced with the browser name
 searchResults.needHelp=Need help? Visit <html:a id="need-help-link">%S Support</html:a>
+
+# LOCALIZATION NOTE %S is the default value of the `dom.ipc.processCount` pref.
+defaultContentProcessCount=%S (default)