Bug 1381853 - Remove browser-refreshblocker.js and move its code to tabbrowser.xml, avoiding the RefreshBlocked event completely, r=mconley.
authorFlorian Quèze <florian@queze.net>
Sun, 23 Jul 2017 00:17:58 +0200
changeset 419148 85e90150f820f2136c8767d367bcc00aa449107b
parent 419147 664bdf1753338d72c65a78942058b4a0d8e77bea
child 419149 8f3349552837ebd18085885fae54bacab88680e7
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1381853
milestone56.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 1381853 - Remove browser-refreshblocker.js and move its code to tabbrowser.xml, avoiding the RefreshBlocked event completely, r=mconley.
browser/base/content/browser-refreshblocker.js
browser/base/content/browser.js
browser/base/content/global-scripts.inc
browser/base/content/moz.build
browser/base/content/tabbrowser.xml
browser/base/jar.mn
deleted file mode 100644
--- a/browser/base/content/browser-refreshblocker.js
+++ /dev/null
@@ -1,84 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
- * 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/. */
-
-/**
- * If the user has opted into blocking refresh and redirect attempts by
- * default, this handles showing the notification to the user which
- * gives them the option to let the refresh or redirect proceed.
- */
-var RefreshBlocker = {
-  init() {
-    gBrowser.addEventListener("RefreshBlocked", this);
-  },
-
-  uninit() {
-    gBrowser.removeEventListener("RefreshBlocked", this);
-  },
-
-  handleEvent(event) {
-    if (event.type == "RefreshBlocked") {
-      this.block(event.originalTarget, event.detail);
-    }
-  },
-
-  /**
-   * Shows the blocked refresh / redirect notification for some browser.
-   *
-   * @param browser (<xul:browser>)
-   *        The browser that had the refresh blocked. This will be the browser
-   *        for which we'll show the notification on.
-   * @param data (object)
-   *        An object with the following properties:
-   *
-   *        URI (string)
-   *          The URI that a page is attempting to refresh or redirect to.
-   *
-   *        delay (int)
-   *          The delay (in milliseconds) before the page was going to reload
-   *          or redirect.
-   *
-   *        sameURI (bool)
-   *          true if we're refreshing the page. false if we're redirecting.
-   *
-   *        outerWindowID (int)
-   *          The outerWindowID of the frame that requested the refresh or
-   *          redirect.
-   */
-  block(browser, data) {
-    let brandBundle = document.getElementById("bundle_brand");
-    let brandShortName = brandBundle.getString("brandShortName");
-    let message =
-      gNavigatorBundle.getFormattedString(data.sameURI ? "refreshBlocked.refreshLabel"
-                                                       : "refreshBlocked.redirectLabel",
-                                          [brandShortName]);
-
-    let notificationBox = gBrowser.getNotificationBox(browser);
-    let notification = notificationBox.getNotificationWithValue("refresh-blocked");
-
-    if (notification) {
-      notification.label = message;
-    } else {
-      let refreshButtonText =
-        gNavigatorBundle.getString("refreshBlocked.goButton");
-      let refreshButtonAccesskey =
-        gNavigatorBundle.getString("refreshBlocked.goButton.accesskey");
-
-      let buttons = [{
-        label: refreshButtonText,
-        accessKey: refreshButtonAccesskey,
-        callback() {
-          if (browser.messageManager) {
-            browser.messageManager.sendAsyncMessage("RefreshBlocker:Refresh", data);
-          }
-        }
-      }];
-
-      notificationBox.appendNotification(message, "refresh-blocked",
-                                         "chrome://browser/skin/Info.png",
-                                         notificationBox.PRIORITY_INFO_MEDIUM,
-                                         buttons);
-    }
-  }
-};
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1291,17 +1291,16 @@ var gBrowserInit = {
     DOMLinkHandler.init();
     gPageStyleMenu.init();
     LanguageDetectionListener.init();
     BrowserOnClick.init();
     FeedHandler.init();
     CompactTheme.init();
     AboutPrivateBrowsingListener.init();
     TrackingProtection.init();
-    RefreshBlocker.init();
     CaptivePortalWatcher.init();
     ZoomUI.init(window);
 
     let mm = window.getGroupMessageManager("browsers");
     mm.loadFrameScript("chrome://browser/content/tab-content.js", true);
     mm.loadFrameScript("chrome://browser/content/content.js", true);
     mm.loadFrameScript("chrome://browser/content/content-UITour.js", true);
     mm.loadFrameScript("chrome://global/content/manifestMessages.js", true);
@@ -1823,18 +1822,16 @@ var gBrowserInit = {
     BrowserOnClick.uninit();
 
     FeedHandler.uninit();
 
     CompactTheme.uninit();
 
     TrackingProtection.uninit();
 
-    RefreshBlocker.uninit();
-
     CaptivePortalWatcher.uninit();
 
     SidebarUI.uninit();
 
     // Now either cancel delayedStartup, or clean up the services initialized from
     // it.
     if (this._boundDelayedStartup) {
       this._cancelDelayedStartup();
--- a/browser/base/content/global-scripts.inc
+++ b/browser/base/content/global-scripts.inc
@@ -10,17 +10,16 @@
 <script type="application/javascript" src="chrome://browser/content/browser.js"/>
 
 <script type="application/javascript" src="chrome://browser/content/browser-captivePortal.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-compacttheme.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-feeds.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-media.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-places.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-plugins.js"/>
-<script type="application/javascript" src="chrome://browser/content/browser-refreshblocker.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-safebrowsing.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-sidebar.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-social.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-sync.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-tabsintitlebar.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-thumbnails.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-trackingprotection.js"/>
 
--- a/browser/base/content/moz.build
+++ b/browser/base/content/moz.build
@@ -125,19 +125,16 @@ with Files("browser-media.js"):
     BUG_COMPONENT = ("Core", "Audio/Video: Playback")
 
 with Files("browser-places.js"):
     BUG_COMPONENT = ("Firefox", "Bookmarks & History")
 
 with Files("browser-plugins.js"):
     BUG_COMPONENT = ("Core", "Plug-ins")
 
-with Files("browser-refreshblocker.js"):
-    BUG_COMPONENT = ("Firefox", "Disability Access")
-
 with Files("browser-safebrowsing.js"):
     BUG_COMPONENT = ("Toolkit", "Safe Browsing")
 
 with Files("*social*"):
     BUG_COMPONENT = ("Firefox", "SocialAPI")
 
 with Files("browser-sync.js"):
     BUG_COMPONENT = ("Firefox", "Sync")
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -5271,24 +5271,62 @@
                 if (shouldFastFind) {
                   // Make sure we return the result.
                   return this.getFindBar(tab).receiveMessage(aMessage);
                 }
               }
               break;
             }
             case "RefreshBlocker:Blocked": {
-              let event = new CustomEvent("RefreshBlocked", {
-                bubbles: true,
-                cancelable: false,
-                detail: data,
-              });
-
-              browser.dispatchEvent(event);
-
+              // The data object is expected to contain the following properties:
+              //  - URI (string)
+              //     The URI that a page is attempting to refresh or redirect to.
+              //  - delay (int)
+              //     The delay (in milliseconds) before the page was going to
+              //     reload or redirect.
+              //  - sameURI (bool)
+              //     true if we're refreshing the page. false if we're redirecting.
+              //  - outerWindowID (int)
+              //     The outerWindowID of the frame that requested the refresh or
+              //     redirect.
+
+              let brandBundle = document.getElementById("bundle_brand");
+              let brandShortName = brandBundle.getString("brandShortName");
+              let message =
+                gNavigatorBundle.getFormattedString("refreshBlocked." +
+                                                    (data.sameURI ? "refreshLabel"
+                                                                  : "redirectLabel"),
+                                                    [brandShortName]);
+
+              let notificationBox = this.getNotificationBox(browser);
+              let notification = notificationBox.getNotificationWithValue("refresh-blocked");
+
+              if (notification) {
+                notification.label = message;
+              } else {
+                let refreshButtonText =
+                  gNavigatorBundle.getString("refreshBlocked.goButton");
+                let refreshButtonAccesskey =
+                  gNavigatorBundle.getString("refreshBlocked.goButton.accesskey");
+
+                let buttons = [{
+                  label: refreshButtonText,
+                  accessKey: refreshButtonAccesskey,
+                  callback() {
+                    if (browser.messageManager) {
+                      browser.messageManager.sendAsyncMessage("RefreshBlocker:Refresh", data);
+                    }
+                  }
+                }];
+
+                notificationBox.appendNotification(message, "refresh-blocked",
+                                                   "chrome://browser/skin/Info.png",
+                                                   notificationBox.PRIORITY_INFO_MEDIUM,
+                                                   buttons);
+              }
               break;
             }
 
             case "Prerender:Request": {
               let sendCancelPrerendering = () => {
                 browser.frameloader.messageManager.
                   sendAsyncMessage("Prerender:Canceled", { id: data.id });
               };
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -71,17 +71,16 @@ browser.jar:
         content/browser/browser-compacttheme.js       (content/browser-compacttheme.js)
         content/browser/browser-feeds.js              (content/browser-feeds.js)
         content/browser/browser-fullScreenAndPointerLock.js  (content/browser-fullScreenAndPointerLock.js)
         content/browser/browser-fullZoom.js           (content/browser-fullZoom.js)
         content/browser/browser-gestureSupport.js     (content/browser-gestureSupport.js)
         content/browser/browser-media.js              (content/browser-media.js)
         content/browser/browser-places.js             (content/browser-places.js)
         content/browser/browser-plugins.js            (content/browser-plugins.js)
-        content/browser/browser-refreshblocker.js     (content/browser-refreshblocker.js)
         content/browser/browser-safebrowsing.js       (content/browser-safebrowsing.js)
         content/browser/browser-sidebar.js            (content/browser-sidebar.js)
         content/browser/browser-social.js             (content/browser-social.js)
         content/browser/browser-sync.js               (content/browser-sync.js)
 *       content/browser/browser-tabPreviews.xml       (content/browser-tabPreviews.xml)
 #ifdef CAN_DRAW_IN_TITLEBAR
         content/browser/browser-tabsintitlebar.js       (content/browser-tabsintitlebar.js)
 #else