Bug 1353013 - Make about:newtab idle preloading pref-able. r?florian draft
authorMike Conley <mconley@mozilla.com>
Wed, 20 Sep 2017 17:31:40 -0400
changeset 668403 f1a908dead8619a665d135baf4d91750ff25035b
parent 667848 88a74b30e5a11b6aad57596cd59352b938523ce4
child 668404 ccee362f5c48f17553e71cc323c8a75ca7e73396
push id81028
push usermconley@mozilla.com
push dateThu, 21 Sep 2017 15:51:23 +0000
reviewersflorian
bugs1353013
milestone57.0a1
Bug 1353013 - Make about:newtab idle preloading pref-able. r?florian MozReview-Commit-ID: 55R1BjlyqkL
browser/app/profile/firefox.js
browser/base/content/tabbrowser.xml
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1231,16 +1231,18 @@ sticky_pref("lightweightThemes.selectedT
 // preference is a string so that localizers can alter it.
 pref("browser.menu.showCharacterEncoding", "chrome://browser/locale/browser.properties");
 
 // Allow using tab-modal prompts when possible.
 pref("prompts.tab_modal.enabled", true);
 
 // Activates preloading of the new tab url.
 pref("browser.newtab.preload", true);
+// If preloading is enabled, preloads during an appropriate idle period.
+pref("browser.newtab.preload.on-idle", false);
 
 // Remembers if the about:newtab intro has been shown
 // NOTE: This preference is unused but was not removed in case
 //       this information will be valuable in the future.
 pref("browser.newtabpage.introShown", false);
 
 // Toggles the content of 'about:newtab'. Shows the grid when enabled.
 pref("browser.newtabpage.enabled", true);
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -2109,25 +2109,38 @@
             // and the URL is "about:newtab". We do not support preloading for
             // custom newtab URLs.
             return Services.prefs.getBoolPref("browser.newtab.preload") &&
                    !aboutNewTabService.overridden;
           ]]>
         </body>
       </method>
 
+      <method name="_useOnIdlePreloading">
+        <body>
+          <![CDATA[
+            // Preloading for the newtab page is enabled when the pref is true
+            // and the URL is "about:newtab". We do not support preloading for
+            // custom newtab URLs.
+            return Services.prefs.getBoolPref("browser.newtab.preload.on-idle");
+          ]]>
+        </body>
+      </method>
+
       <field name="_preloadBrowserMinUserIdleSeconds">1</field>
       <field name="_preloadBrowserMinIdlePeriodMs">40</field>
       <method name="requestPreloadBrowser">
         <body><![CDATA[
           // Do nothing if we have a preloaded browser already or we're about
-          // to create one or preloading is disabled.
+          // to create one, preloading is disabled, or idle preloading is
+          // disabled.
           if (this._preloadedBrowser ||
               this._preloadBrowserIdleObserver ||
-              !this._isPreloadingEnabled()) {
+              !this._isPreloadingEnabled() ||
+              !this._useOnIdlePreloading) {
             return;
           }
 
           this._preloadBrowserIdleObserver = (aSubject, aTopic) => {
             if (aTopic != "idle") {
               return;
             }
 
@@ -7062,18 +7075,23 @@
 
           // XXXmano: this is a temporary workaround for bug 345399
           // We need to manually update the scroll buttons disabled state
           // if a tab was inserted to the overflow area or removed from it
           // without any scrolling and when the tabbar has already
           // overflowed.
           this.mTabstrip._updateScrollButtonsDisabledState();
 
-          // Preload the next about:newtab if there isn't one already.
-          this.tabbrowser.requestPreloadBrowser();
+          if (this._useOnIdlePreloading) {
+            // Preload the next about:newtab during an appropriate idle period.
+            this.tabbrowser.requestPreloadBrowser();
+          } else {
+            // Preload the next about:newtab immediately
+            this.tabbrowser._createPreloadBrowser();
+          }
         ]]></body>
       </method>
 
       <method name="_canAdvanceToTab">
         <parameter name="aTab"/>
         <body>
         <![CDATA[
           return !aTab.closing;