Bug 1369801 - dt-addon: only unload devtools resources if previous install found draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 06 Jul 2017 21:29:05 +0200
changeset 606675 e5deb4554cdc112a3bc6b091b10ce983c510acaa
parent 606674 86a1cb2e9b724750218e7b7e03adf2346838956f
child 636825 9b4afabe438f28f10eda419d475f906683da29af
push id67765
push userjdescottes@mozilla.com
push dateTue, 11 Jul 2017 08:07:43 +0000
bugs1369801
milestone56.0a1
Bug 1369801 - dt-addon: only unload devtools resources if previous install found MozReview-Commit-ID: 7jKY0IjUUj2
devtools/bootstrap.js
devtools/shim/DevToolsShim.jsm
--- a/devtools/bootstrap.js
+++ b/devtools/bootstrap.js
@@ -12,16 +12,19 @@ const Cu = Components.utils;
 const Ci = Components.interfaces;
 const Cm = Components.manager;
 
 Cm.QueryInterface(Ci.nsIComponentRegistrar);
 
 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
 const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
+XPCOMUtils.defineLazyGetter(this, "DevToolsShim", function () {
+  return Cu.import("chrome://devtools-shim/content/DevToolsShim.jsm", {}).DevToolsShim;
+});
 XPCOMUtils.defineLazyGetter(this, "DevToolsStartup", function () {
   return Cu.import("resource://devtools/client/devtools-startup.js", {}).DevToolsStartup;
 });
 XPCOMUtils.defineLazyGetter(this, "webideCli", function () {
   return Cu.import("resource://devtools/client/webide/components/webideCli.js", {}).webideCli;
 });
 XPCOMUtils.defineLazyGetter(this, "DevToolsPreferences", function () {
   return Cu.import("chrome://devtools/content/preferences/DevToolsPreferences.jsm", {}).DevToolsPreferences;
@@ -155,20 +158,24 @@ function reload(event) {
   let reopenBrowserConsole = false;
   if (browserConsole) {
     browserConsole.close();
     reopenBrowserConsole = true;
   }
 
   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");
+  // Only unload DevTools related resources if a previous devtools installation was
+  // detected.
+  if (DevToolsShim.alreadyHadRegistration) {
+    // Invalidate xul cache in order to see changes made to chrome:// files
+    Services.obs.notifyObservers(null, "startupcache-invalidate");
 
-  unload("reload");
+    unload("reload");
+  }
 
   const {devtools} = Cu.import("resource://devtools/shared/Loader.jsm", {});
   devtools.require("devtools/client/framework/devtools-browser");
 
   // Go over all top level windows to reload all devtools related things
   let windowsEnum = Services.wm.getEnumerator(null);
   while (windowsEnum.hasMoreElements()) {
     let window = windowsEnum.getNext();
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -30,16 +30,19 @@ function removeItem(array, callback) {
  * DevToolsShim.isInstalled() can also be used to know if DevTools are currently
  * installed.
  */
 this.DevToolsShim = {
   gDevTools: null,
   listeners: [],
   tools: [],
   themes: [],
+  // This property can be checked by the DevTools addon bootstrap in order to know if
+  // DevTools were already loaded and should be cleaned up.
+  alreadyHadRegistration: false,
 
   /**
    * Check if DevTools are currently installed and available.
    *
    * @return {Boolean} true if DevTools are installed.
    */
   isInstalled: function () {
     return !!this.gDevTools;
@@ -47,16 +50,17 @@ this.DevToolsShim = {
 
   /**
    * Register an instance of gDevTools. Should be called by DevTools during startup.
    *
    * @param {DevTools} a devtools instance (from client/framework/devtools)
    */
   register: function (gDevTools) {
     this.gDevTools = gDevTools;
+    this.alreadyHadRegistration = true;
     this._onDevToolsRegistered();
     this.gDevTools.emit("devtools-registered");
   },
 
   /**
    * Unregister the current instance of gDevTools. Should be called by DevTools during
    * shutdown.
    */