Bug 1510178 - remove broadcasters from common/. r=darktrojan
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Wed, 28 Nov 2018 12:40:22 +0200
changeset 33795 2a56bbf3704832de7085764738e0d32c354208e7
parent 33794 997316def2a1f266e97df8bc9a2ab0b824e3c1f8
child 33796 214b702ef3435adcc6ad826646af44861b0e83a8
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersdarktrojan
bugs1510178
Bug 1510178 - remove broadcasters from common/. r=darktrojan
common/src/viewSource.js
common/src/viewSource.xul
--- a/common/src/viewSource.js
+++ b/common/src/viewSource.js
@@ -288,21 +288,20 @@ ViewSourceChrome.prototype = {
     gContextMenu.addEventListener("popupshowing", this);
     gContextMenu.addEventListener("popuphidden", this);
 
     Services.els.addSystemEventListener(this.browser, "dragover", this, true);
     Services.els.addSystemEventListener(this.browser, "drop", this, true);
 
     if (!this.historyEnabled) {
       // Disable the BACK and FORWARD commands and hide the related menu items.
-      let viewSourceNavigation = document.getElementById("viewSourceNavigation");
-      if (viewSourceNavigation) {
-        viewSourceNavigation.setAttribute("disabled", "true");
-        viewSourceNavigation.setAttribute("hidden", "true");
-      }
+      document.querySelectorAll(".viewSourceNavigation").forEach(e => {
+        e.setAttribute("disabled", "true");
+        e.setAttribute("hidden", "true");
+      });
     }
 
     // We require the first argument to do any loading of source.
     // otherwise, we're done.
     if (!window.arguments[0]) {
       return undefined;
     }
 
@@ -565,31 +564,31 @@ ViewSourceChrome.prototype = {
    * @param URL
    *        A URL string to be opened in the view source browser.
    */
   loadURL(URL) {
     this.sendAsyncMessage("ViewSource:LoadSource", { URL });
   },
 
   /**
-   * Updates any commands that are dependant on command broadcasters.
+   * Updates any applicable commands.
    */
   updateCommands() {
-    let backBroadcaster = document.getElementById("Browser:Back");
-    let forwardBroadcaster = document.getElementById("Browser:Forward");
+    let backCommand = document.getElementById("Browser:Back");
+    let forwardCommand = document.getElementById("Browser:Forward");
 
     if (this.webNav.canGoBack) {
-      backBroadcaster.removeAttribute("disabled");
+      backCommand.removeAttribute("disabled");
     } else {
-      backBroadcaster.setAttribute("disabled", "true");
+      backCommand.setAttribute("disabled", "true");
     }
     if (this.webNav.canGoForward) {
-      forwardBroadcaster.removeAttribute("disabled");
+      forwardCommand.removeAttribute("disabled");
     } else {
-      forwardBroadcaster.setAttribute("disabled", "true");
+      forwardCommand.setAttribute("disabled", "true");
     }
   },
 
   /**
    * Reloads the browser, bypassing the network cache.
    */
   reload() {
     this.browser.reloadWithFlags(Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY |
--- a/common/src/viewSource.xul
+++ b/common/src/viewSource.xul
@@ -61,26 +61,23 @@
   <command id="cmd_findSelection"
            oncommand="document.getElementById('FindToolbar').onFindSelectionCommand();"/>
 #endif
   <command id="cmd_reload" oncommand="viewSourceChrome.reload();"/>
   <command id="cmd_goToLine" oncommand="viewSourceChrome.promptAndGoToLine();" disabled="true"/>
 #ifdef MOZ_SUITE
   <command id="cmd_highlightSyntax" oncommand="viewSourceChrome.toggleSyntaxHighlighting();"/>
   <command id="cmd_wrapLongLines" oncommand="viewSourceChrome.toggleWrapping();"/>
+  <command id="Browser:Back" oncommand="viewSourceChrome.goBack()" class="viewSourceNavigation"/>
+  <command id="Browser:Forward" oncommand="viewSourceChrome.goForward()" class="viewSourceNavigation"/>
 #endif
   <command id="cmd_textZoomReduce" oncommand="ZoomManager.reduce();"/>
   <command id="cmd_textZoomEnlarge" oncommand="ZoomManager.enlarge();"/>
   <command id="cmd_textZoomReset" oncommand="ZoomManager.reset();"/>
 
-  <command id="Browser:Back" oncommand="viewSourceChrome.goBack()" observes="viewSourceNavigation"/>
-  <command id="Browser:Forward" oncommand="viewSourceChrome.goForward()" observes="viewSourceNavigation"/>
-
-  <broadcaster id="viewSourceNavigation"/>
-
 #includesubst @TOOLKIT_DIR@/content/editMenuKeys.inc.xul
   <keyset id="viewSourceKeys">
     <key id="key_savePage" key="&savePageCmd.commandkey;" modifiers="accel" command="cmd_savePage"/>
     <key id="key_print" key="&printCmd.commandkey;" modifiers="accel" command="cmd_print"/>
     <key id="key_close" key="&closeCmd.commandkey;" modifiers="accel" command="cmd_close"/>
     <key id="key_goToLine"     key="&goToLineCmd.commandkey;"  command="cmd_goToLine"  modifiers="accel"/>
 
     <key id="key_textZoomEnlarge" key="&textEnlarge.commandkey;" command="cmd_textZoomEnlarge" modifiers="accel"/>
@@ -128,27 +125,29 @@
 #endif
 #endif
 
   </keyset>
 
   <tooltip id="aHTMLTooltip" page="true"/>
 
   <menupopup id="viewSourceContextMenu">
+#ifdef MOZ_SUITE
     <menuitem id="context-back"
               label="&backCmd.label;"
               accesskey="&backCmd.accesskey;"
               command="Browser:Back"
               observes="viewSourceNavigation"/>
     <menuitem id="context-forward"
               label="&forwardCmd.label;"
               accesskey="&forwardCmd.accesskey;"
               command="Browser:Forward"
               observes="viewSourceNavigation"/>
     <menuseparator observes="viewSourceNavigation"/>
+#endif
     <menuitem id="cMenu_findAgain"
               label="&findAgainCmd.label;"
               accesskey="&findAgainCmd.accesskey;"
               command="cmd_findAgain"/>
     <menuseparator/>
     <menuitem id="cMenu_copy"
               label="&copyCmd.label;"
               accesskey="&copyCmd.accesskey;"