Bug 1461548 - Only load the RefreshBlocker frame script when necessary. r=mconley
authorFelipe Gomes <felipc@gmail.com>
Fri, 25 May 2018 14:22:14 -0300
changeset 419905 2a22b2c857678a615d3dc178698bc8f9aea388c0
parent 419904 6ed202b3c4356ed5f46d9d633088dc0d1084c88c
child 419906 2d4d8797e848866b3de007da25eb5020293d331f
push id103655
push userfelipc@gmail.com
push dateFri, 25 May 2018 17:22:32 +0000
treeherdermozilla-inbound@abb1759701b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1461548
milestone62.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 1461548 - Only load the RefreshBlocker frame script when necessary. r=mconley
browser/base/content/browser.js
browser/base/content/content-refreshblocker.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1326,16 +1326,17 @@ var gBrowserInit = {
 
     // Misc. inits.
     TabletModeUpdater.init();
     CombinedStopReload.ensureInitialized();
     gPrivateBrowsingUI.init();
     BrowserSearch.init();
     BrowserPageActions.init();
     gAccessibilityServiceIndicator.init();
+    AccessibilityRefreshBlocker.init();
 
     gRemoteControl.updateVisualCue(Marionette.running);
 
     // If we are given a tab to swap in, take care of it before first paint to
     // avoid an about:blank flash.
     let tabToOpen = window.arguments && window.arguments[0];
     if (tabToOpen instanceof XULElement) {
       // Clear the reference to the tab from the arguments array.
@@ -1850,16 +1851,18 @@ var gBrowserInit = {
     CaptivePortalWatcher.uninit();
 
     SidebarUI.uninit();
 
     DownloadsButton.uninit();
 
     gAccessibilityServiceIndicator.uninit();
 
+    AccessibilityRefreshBlocker.uninit();
+
     LanguagePrompt.uninit();
 
     BrowserSearch.uninit();
 
     // Now either cancel delayedStartup, or clean up the services initialized from
     // it.
     if (this._boundDelayedStartup) {
       this._cancelDelayedStartup();
@@ -5270,16 +5273,54 @@ var CombinedStopReload = {
   _cancelTransition() {
     if (this._timer) {
       clearTimeout(this._timer);
       this._timer = 0;
     }
   }
 };
 
+// This helper only cares about loading the frame
+// script if the pref is seen as true.
+// After the frame script is loaded, it takes over
+// the responsibility of watching the pref and
+// enabling/disabling itself.
+const AccessibilityRefreshBlocker = {
+  PREF: "accessibility.blockautorefresh",
+
+  init() {
+    if (Services.prefs.getBoolPref(this.PREF)) {
+      this.loadFrameScript();
+    } else {
+      Services.prefs.addObserver(this.PREF, this);
+    }
+  },
+
+  uninit() {
+    Services.prefs.removeObserver(this.PREF, this);
+  },
+
+  observe(aSubject, aTopic, aPrefName) {
+    if (aTopic == "nsPref:changed" &&
+        aPrefName == this.PREF &&
+        Services.prefs.getBoolPref(this.PREF)) {
+      this.loadFrameScript();
+      Services.prefs.removeObserver(this.PREF, this);
+    }
+  },
+
+  loadFrameScript() {
+    if (!this._loaded) {
+      this._loaded = true;
+      let mm = window.getGroupMessageManager("browsers");
+      mm.loadFrameScript("chrome://browser/content/content-refreshblocker.js", true);
+    }
+  }
+};
+
 var TabsProgressListener = {
   onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
     // Collect telemetry data about tab load times.
     if (aWebProgress.isTopLevel && (!aRequest.originalURI || aRequest.originalURI.spec.scheme != "about")) {
       let stopwatchRunning = TelemetryStopwatch.running("FX_PAGE_LOAD_MS", aBrowser);
 
       if (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) {
         if (aStateFlags & Ci.nsIWebProgressListener.STATE_START) {
--- a/browser/base/content/content-refreshblocker.js
+++ b/browser/base/content/content-refreshblocker.js
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* eslint-env mozilla/frame-script */
 
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 var RefreshBlocker = {
   PREF: "accessibility.blockautorefresh",
 
   // Bug 1247100 - When a refresh is caused by an HTTP header,
   // onRefreshAttempted will be fired before onLocationChange.
   // When a refresh is caused by a <meta> tag in the document,
   // onRefreshAttempted will be fired after onLocationChange.
   //