Bug 1225108 - Introduce an addon to easily work on devtools codebase. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 05 Jan 2016 02:41:49 -0800
changeset 315546 1850e2691a107ed4cd99cae0950fe8af0ce48433
parent 315545 0bea3bcf7946270ce90bf34cb78827fbdfee2e56
child 315547 fee7f4242ab1e9fd026f2f3d12c4d358b6f88100
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1225108
milestone46.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 1225108 - Introduce an addon to easily work on devtools codebase. r=jryans
devtools/bootstrap.js
devtools/chrome.manifest
devtools/client/framework/gDevTools.jsm
devtools/install.rdf
new file mode 100644
--- /dev/null
+++ b/devtools/bootstrap.js
@@ -0,0 +1,99 @@
+/* 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/. */
+
+"use strict";
+
+const Cu = Components.utils;
+const Ci = Components.interfaces;
+const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
+
+// Helper to listen to a key on all windows
+function MultiWindowKeyListener({ keyCode, ctrlKey, altKey, callback }) {
+  let keyListener = function (event) {
+    if (event.ctrlKey == !!ctrlKey &&
+        event.altKey == !!altKey &&
+        event.keyCode === keyCode) {
+      callback(event);
+
+      // Call preventDefault to avoid duplicated events when
+      // doing the key stroke within a tab.
+      event.preventDefault();
+    }
+  };
+
+  let observer = function (window, topic, data) {
+    // Listen on keyup to call keyListener only once per stroke
+    if (topic === "domwindowopened") {
+      window.addEventListener("keyup", keyListener);
+    } else {
+      window.removeEventListener("keyup", keyListener);
+    }
+  };
+
+  return {
+    start: function () {
+      // Automatically process already opened windows
+      let e = Services.ww.getWindowEnumerator();
+      while (e.hasMoreElements()) {
+        let window = e.getNext();
+        observer(window, "domwindowopened", null);
+      }
+      // And listen for new ones to come
+      Services.ww.registerNotification(observer);
+    },
+
+    stop: function () {
+      Services.ww.unregisterNotification(observer);
+      let e = Services.ww.getWindowEnumerator();
+      while (e.hasMoreElements()) {
+        let window = e.getNext();
+        observer(window, "domwindowclosed", null);
+      }
+    }
+  };
+};
+
+let getTopLevelWindow = function (window) {
+  return window.QueryInterface(Ci.nsIInterfaceRequestor)
+               .getInterface(Ci.nsIWebNavigation)
+               .QueryInterface(Ci.nsIDocShellTreeItem)
+               .rootTreeItem
+               .QueryInterface(Ci.nsIInterfaceRequestor)
+               .getInterface(Ci.nsIDOMWindow);
+};
+
+function reload(event) {
+  // We automatically reload the toolbox if we are on a browser tab
+  // with a toolbox already opened
+  let top = getTopLevelWindow(event.view)
+  let isBrowser = top.location.href.includes("/browser.xul") && top.gDevToolsBrowser;
+  let reloadToolbox = false;
+  if (isBrowser && top.gDevToolsBrowser.hasToolboxOpened) {
+    reloadToolbox = top.gDevToolsBrowser.hasToolboxOpened(top);
+  }
+  dump("Reload DevTools.  (reload-toolbox:"+reloadToolbox+")\n");
+
+  // Invalidate xul cache in order to see changes made to chrome:// files
+  Services.obs.notifyObservers(null, "startupcache-invalidate", null);
+
+  // Ask the loader to update itself and reopen the toolbox if needed
+  const {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
+  devtools.reload(reloadToolbox);
+}
+
+let listener;
+function startup() {
+  dump("DevTools addon started.\n");
+  listener = new MultiWindowKeyListener({
+    keyCode: Ci.nsIDOMKeyEvent.DOM_VK_R, ctrlKey: true, altKey: true,
+    callback: reload
+  });
+  listener.start();
+}
+function shutdown() {
+  listener.stop();
+  listener = null;
+}
+function install() {}
+function uninstall() {}
new file mode 100644
--- /dev/null
+++ b/devtools/chrome.manifest
@@ -0,0 +1,6 @@
+content devtools client/
+skin devtools classic/1.0 client/themes/
+resource devtools .
+
+content webide client/webide/content/
+skin webide classic/1.0 client/webide/themes/
--- a/devtools/client/framework/gDevTools.jsm
+++ b/devtools/client/framework/gDevTools.jsm
@@ -1156,30 +1156,34 @@ var gDevToolsBrowser = {
       cmd: cmd,
       key: key,
       bc: bc,
       appmenuitem: appmenuitem,
       menuitem: menuitem
     };
   },
 
+  hasToolboxOpened: function(win) {
+    let tab = win.gBrowser.selectedTab;
+    for (let [target, toolbox] of gDevTools._toolboxes) {
+      if (target.tab == tab) {
+        return true;
+      }
+    }
+    return false;
+  },
+
   /**
    * Update the "Toggle Tools" checkbox in the developer tools menu. This is
    * called when a toolbox is created or destroyed.
    */
   _updateMenuCheckbox: function DT_updateMenuCheckbox() {
     for (let win of gDevToolsBrowser._trackedBrowserWindows) {
 
-      let hasToolbox = false;
-      if (TargetFactory.isKnownTab(win.gBrowser.selectedTab)) {
-        let target = TargetFactory.forTab(win.gBrowser.selectedTab);
-        if (gDevTools._toolboxes.has(target)) {
-          hasToolbox = true;
-        }
-      }
+      let hasToolbox = gDevToolsBrowser.hasToolboxOpened(win);
 
       let broadcaster = win.document.getElementById("devtoolsMenuBroadcaster_DevToolbox");
       if (hasToolbox) {
         broadcaster.setAttribute("checked", "true");
       } else {
         broadcaster.removeAttribute("checked");
       }
     }
new file mode 100644
--- /dev/null
+++ b/devtools/install.rdf
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+# 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/.
+-->
+
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+  <Description about="urn:mozilla:install-manifest"
+               em:id="devtools@mozilla.org"
+               em:name="Developer Tools (local version)"
+               em:description="Add-on to load DevTools from local sources and easily reload them with Ctrl+Alt+r shortcut"
+               em:version="44.0a1"
+               em:type="2"
+               em:creator="Mozilla">
+
+    <em:bootstrap>true</em:bootstrap>
+    <em:targetApplication>
+      <Description>
+        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
+        <em:minVersion>44.0a1</em:minVersion>
+        <em:maxVersion>*</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+  </Description>
+</RDF>