Bug 961165 - Remove inline scripts from scratchpad.xul. r=bbenvie
authorMark Goodwin <mgoodwin@mozilla.com>
Mon, 10 Mar 2014 09:00:31 -0400
changeset 172806 80ea77dd1eac3ee9d4118e104630d0a2c6156a02
parent 172805 c6a1cc77c943be2c08dfbbdaf89cc42b6838e131
child 172807 170b1052afc5bcb8a02cdc9fc3f49aaa671866e1
push id26382
push userryanvm@gmail.com
push dateMon, 10 Mar 2014 21:09:54 +0000
treeherdermozilla-central@41d962d23e81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbenvie
bugs961165
milestone30.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 961165 - Remove inline scripts from scratchpad.xul. r=bbenvie
browser/devtools/scratchpad/scratchpad.js
browser/devtools/scratchpad/scratchpad.xul
--- a/browser/devtools/scratchpad/scratchpad.js
+++ b/browser/devtools/scratchpad/scratchpad.js
@@ -126,16 +126,109 @@ var Scratchpad = {
         obj[key.trim()] = val.trim();
       }
     });
 
     return obj;
   },
 
   /**
+   * Add the event listeners for popupshowing events.
+   */
+  _setupPopupShowingListeners: function SP_setupPopupShowing() {
+    let elementIDs = ['sp-menu_editpopup', 'scratchpad-text-popup'];
+
+    for (let elementID of elementIDs) {
+      let elem = document.getElementById(elementID);
+      if (elem) {
+        elem.addEventListener("popupshowing", function () {
+          goUpdateGlobalEditMenuItems();
+          let commands = ['cmd_undo', 'cmd_redo', 'cmd_delete', 'cmd_findAgain'];
+          commands.forEach(goUpdateCommand);
+        });
+      }
+    }
+  },
+
+  /**
+   * Add the event event listeners for command events.
+   */
+  _setupCommandListeners: function SP_setupCommands() {
+    let commands = {
+      "cmd_gotoLine": () => {
+        goDoCommand('cmd_gotoLine');
+      },
+      "sp-cmd-newWindow": () => {
+        Scratchpad.openScratchpad();
+      },
+      "sp-cmd-openFile": () => {
+        Scratchpad.openFile();
+      },
+      "sp-cmd-clearRecentFiles": () => {
+        Scratchpad.clearRecentFiles();
+      },
+      "sp-cmd-save": () => {
+        Scratchpad.saveFile();
+      },
+      "sp-cmd-saveas": () => {
+        Scratchpad.saveFileAs();
+      },
+      "sp-cmd-revert": () => {
+        Scratchpad.promptRevert();
+      },
+      "sp-cmd-close": () => {
+        Scratchpad.close();
+      },
+      "sp-cmd-run": () => {
+        Scratchpad.run();
+      },
+      "sp-cmd-inspect": () => {
+        Scratchpad.inspect();
+      },
+      "sp-cmd-display": () => {
+        Scratchpad.display();
+      },
+      "sp-cmd-pprint": () => {
+        Scratchpad.prettyPrint();
+      },
+      "sp-cmd-contentContext": () => {
+        Scratchpad.setContentContext();
+      },
+      "sp-cmd-browserContext": () => {
+        Scratchpad.setBrowserContext();
+      },
+      "sp-cmd-reloadAndRun": () => {
+        Scratchpad.reloadAndRun();
+      },
+      "sp-cmd-evalFunction": () => {
+        Scratchpad.evalTopLevelFunction();
+      },
+      "sp-cmd-errorConsole": () => {
+        Scratchpad.openErrorConsole();
+      },
+      "sp-cmd-webConsole": () => {
+        Scratchpad.openWebConsole();
+      },
+      "sp-cmd-documentationLink": () => {
+        Scratchpad.openDocumentationPage();
+      },
+      "sp-cmd-hideSidebar": () => {
+        Scratchpad.sidebar.hide();
+      }
+    }
+
+    for (let command in commands) {
+      let elem = document.getElementById(command);
+      if (elem) {
+        elem.addEventListener("command", commands[command]);
+      }
+    }
+  },
+
+  /**
    * The script execution context. This tells Scratchpad in which context the
    * script shall execute.
    *
    * Possible values:
    *   - SCRATCHPAD_CONTEXT_CONTENT to execute code in the context of the current
    *   tab content window object.
    *   - SCRATCHPAD_CONTEXT_BROWSER to execute code in the context of the
    *   currently active chrome window object.
@@ -1163,17 +1256,17 @@ var Scratchpad = {
         menuitem.setAttribute("type", "radio");
         menuitem.setAttribute("label", filePaths[i]);
 
         if (filePaths[i] === filename) {
           menuitem.setAttribute("checked", true);
           menuitem.setAttribute("disabled", true);
         }
 
-        menuitem.setAttribute("oncommand", "Scratchpad.openFile(" + i + ");");
+        menuitem.addEventListener("command", Scratchpad.openFile.bind(Scratchpad, i));
         recentFilesPopup.appendChild(menuitem);
       }
 
       recentFilesPopup.appendChild(document.createElement("menuseparator"));
       let clearItems = document.createElement("menuitem");
       clearItems.setAttribute("id", "sp-menu-clear_recent");
       clearItems.setAttribute("label",
                               this.strings.
@@ -1508,16 +1601,18 @@ var Scratchpad = {
         this.dirty = !state.saved;
 
       this.initialized = true;
       this._triggerObservers("Ready");
       this.populateRecentFilesMenu();
       PreferenceObserver.init();
       CloseObserver.init();
     }).then(null, (err) => console.log(err.message));
+    this._setupCommandListeners();
+    this._setupPopupShowingListeners();
   },
 
   /**
    * The Source Editor "change" event handler. This function updates the
    * Scratchpad window title to show an asterisk when there are unsaved changes.
    *
    * @private
    */
--- a/browser/devtools/scratchpad/scratchpad.xul
+++ b/browser/devtools/scratchpad/scratchpad.xul
@@ -28,51 +28,42 @@
         width="640" height="480"
         persist="screenX screenY width height sizemode">
 
 <script type="application/javascript;version=1.8"
         src="chrome://browser/content/devtools/theme-switching.js"/>
 <script type="application/javascript" src="chrome://global/content/globalOverlay.js"/>
 <script type="application/javascript" src="chrome://browser/content/devtools/scratchpad.js"/>
 
-
-<script type="application/javascript">
-  function goUpdateSourceEditorMenuItems() {
-    goUpdateGlobalEditMenuItems();
-    let commands = ['cmd_undo', 'cmd_redo', 'cmd_delete', 'cmd_findAgain'];
-    commands.forEach(goUpdateCommand);
-  }
-</script>
-
 <commandset id="editMenuCommands"/>
 
 <commandset id="sourceEditorCommands">
-  <command id="cmd_gotoLine" oncommand="goDoCommand('cmd_gotoLine')"/>
+  <command id="cmd_gotoLine" oncommand=";"/>
 </commandset>
 
 <commandset id="sp-commandset">
-  <command id="sp-cmd-newWindow" oncommand="Scratchpad.openScratchpad();"/>
-  <command id="sp-cmd-openFile" oncommand="Scratchpad.openFile();"/>
-  <command id="sp-cmd-clearRecentFiles" oncommand="Scratchpad.clearRecentFiles();"/>
-  <command id="sp-cmd-save" oncommand="Scratchpad.saveFile();"/>
-  <command id="sp-cmd-saveas" oncommand="Scratchpad.saveFileAs();"/>
-  <command id="sp-cmd-revert" oncommand="Scratchpad.promptRevert();" disabled="true"/>
-  <command id="sp-cmd-close" oncommand="Scratchpad.close();"/>
-  <command id="sp-cmd-run" oncommand="Scratchpad.run();"/>
-  <command id="sp-cmd-inspect" oncommand="Scratchpad.inspect();"/>
-  <command id="sp-cmd-display" oncommand="Scratchpad.display();"/>
-  <command id="sp-cmd-pprint" oncommand="Scratchpad.prettyPrint();"/>
-  <command id="sp-cmd-contentContext" oncommand="Scratchpad.setContentContext();"/>
-  <command id="sp-cmd-browserContext" oncommand="Scratchpad.setBrowserContext();" disabled="true"/>
-  <command id="sp-cmd-reloadAndRun" oncommand="Scratchpad.reloadAndRun();"/>
-  <command id="sp-cmd-evalFunction" oncommand="Scratchpad.evalTopLevelFunction();"/>
-  <command id="sp-cmd-errorConsole" oncommand="Scratchpad.openErrorConsole();" disabled="true"/>
-  <command id="sp-cmd-webConsole" oncommand="Scratchpad.openWebConsole();"/>
-  <command id="sp-cmd-documentationLink" oncommand="Scratchpad.openDocumentationPage();"/>
-  <command id="sp-cmd-hideSidebar" oncommand="Scratchpad.sidebar.hide();"/>
+  <command id="sp-cmd-newWindow" oncommand=";"/>
+  <command id="sp-cmd-openFile" oncommand=";"/>
+  <command id="sp-cmd-clearRecentFiles" oncommand=";"/>
+  <command id="sp-cmd-save" oncommand=";"/>
+  <command id="sp-cmd-saveas" oncommand=";"/>
+  <command id="sp-cmd-revert" oncommand=";" disabled="true"/>
+  <command id="sp-cmd-close" oncommand=";"/>
+  <command id="sp-cmd-run" oncommand=";"/>
+  <command id="sp-cmd-inspect" oncommand=";"/>
+  <command id="sp-cmd-display" oncommand=";"/>
+  <command id="sp-cmd-pprint" oncommand=";"/>
+  <command id="sp-cmd-contentContext" oncommand=";"/>
+  <command id="sp-cmd-browserContext" oncommand=";" disabled="true"/>
+  <command id="sp-cmd-reloadAndRun" oncommand=";"/>
+  <command id="sp-cmd-evalFunction" oncommand=";"/>
+  <command id="sp-cmd-errorConsole" oncommand=";" disabled="true"/>
+  <command id="sp-cmd-webConsole" oncommand=";"/>
+  <command id="sp-cmd-documentationLink" oncommand=";"/>
+  <command id="sp-cmd-hideSidebar" oncommand=";"/>
 </commandset>
 
 <keyset id="editMenuKeys"/>
 
 <keyset id="sp-keyset">
   <key id="sp-key-window"
        key="&newWindowCmd.commandkey;"
        command="sp-cmd-newWindow"
@@ -167,18 +158,17 @@
                 key="sp-key-close"
                 accesskey="&closeCmd.accesskey;"
                 command="sp-cmd-close"/>
     </menupopup>
   </menu>
 
   <menu id="sp-edit-menu" label="&editMenu.label;"
         accesskey="&editMenu.accesskey;">
-    <menupopup id="sp-menu_editpopup"
-               onpopupshowing="goUpdateSourceEditorMenuItems()">
+    <menupopup id="sp-menu_editpopup">
       <menuitem id="menu_undo"/>
       <menuitem id="menu_redo"/>
       <menuseparator/>
       <menuitem id="menu_cut"/>
       <menuitem id="menu_copy"/>
       <menuitem id="menu_paste"/>
       <menuseparator/>
       <menuitem id="menu_selectAll"/>
@@ -300,18 +290,17 @@
   <toolbarbutton id="sp-toolbar-pprint"
                  class="devtools-toolbarbutton"
                  label="&pprint.label;"
                  command="sp-cmd-pprint"/>
 </toolbar>
 
 
 <popupset id="scratchpad-popups">
-  <menupopup id="scratchpad-text-popup"
-             onpopupshowing="goUpdateSourceEditorMenuItems()">
+  <menupopup id="scratchpad-text-popup">
     <menuitem id="cMenu_cut"/>
     <menuitem id="cMenu_copy"/>
     <menuitem id="cMenu_paste"/>
     <menuitem id="cMenu_delete"/>
     <menuseparator/>
     <menuitem id="cMenu_selectAll"/>
     <menuseparator/>
     <menuitem id="sp-text-run"