Bug 1461548 - Only load the RefreshBlocker frame script when necessary. r=mconley draft
authorFelipe Gomes <felipc@gmail.com>
Mon, 14 May 2018 23:10:04 -0300
changeset 795131 0b09bcad8e2555278ab75e0ffed5275f15220d0d
parent 795130 0ea7e8c4e3cbbaeb5c503a32ee479018e1397650
push id109865
push userfelipc@gmail.com
push dateTue, 15 May 2018 02:10:44 +0000
reviewersmconley
bugs1461548
milestone62.0a1
Bug 1461548 - Only load the RefreshBlocker frame script when necessary. r=mconley MozReview-Commit-ID: LZWOzll6PAg
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();
@@ -5265,16 +5268,51 @@ 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() {
+    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
@@ -173,8 +173,12 @@ var RefreshBlocker = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIWebProgressListener2, Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]),
 };
 
 RefreshBlocker.init();
 
 addEventListener("unload", () => {
   RefreshBlocker.uninit();
 });
+
+addEventListener("unload", () => {
+  RefreshBlocker.uninit();
+});