Bug 1247203 - Register tools and themes in the sorted order. r=jryans
authorAlexandre Poirot <poirot.alex@gmail.com>
Fri, 04 Mar 2016 07:51:12 -0800
changeset 323251 36f76c141709a89c42718b8efa9c8e272ef549c7
parent 323250 bfd61742bd5952153c5fc97c6ff9ae22e6594f3e
child 323252 b479a3b0fde9a3dfc67dfb6dbf35d3c958fd1a9c
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1247203
milestone47.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 1247203 - Register tools and themes in the sorted order. r=jryans
devtools/client/framework/devtools.js
devtools/client/main.js
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -37,16 +37,32 @@ this.DevTools = function DevTools() {
 
   EventEmitter.decorate(this);
 
   Services.obs.addObserver(this._teardown, "devtools-unloaded", false);
   Services.obs.addObserver(this.destroy, "quit-application", false);
 };
 
 DevTools.prototype = {
+  registerDefaults() {
+    // Ensure registering items in the sorted order (getDefault* functions
+    // return sorted lists)
+    this.getDefaultTools().forEach(definition => this.registerTool(definition));
+    this.getDefaultThemes().forEach(definition => this.registerTheme(definition));
+  },
+
+  unregisterDefaults() {
+    for (let definition of this.getToolDefinitionArray()) {
+      this.unregisterTool(definition.id);
+    }
+    for (let definition of this.getThemeDefinitionArray()) {
+      this.unregisterTheme(definition.id);
+    }
+  },
+
   /**
    * Register a new developer tool.
    *
    * A definition is a light object that holds different information about a
    * developer tool. This object is not supposed to have any operational code.
    * See it as a "manifest".
    * The only actual code lives in the build() function, which will be used to
    * start an instance of this tool.
@@ -78,17 +94,17 @@ DevTools.prototype = {
 
     if (!toolId || FORBIDDEN_IDS.has(toolId)) {
       throw new Error("Invalid definition.id");
     }
 
     // Make sure that additional tools will always be able to be hidden.
     // When being called from main.js, defaultTools has not yet been exported.
     // But, we can assume that in this case, it is a default tool.
-    if (DefaultTools && DefaultTools.indexOf(toolDefinition) == -1) {
+    if (DefaultTools.indexOf(toolDefinition) == -1) {
       toolDefinition.visibilityswitch = "devtools." + toolId + ".enabled";
     }
 
     this._tools.set(toolId, toolDefinition);
 
     this.emit("tool-registered", toolId);
   },
 
@@ -137,16 +153,20 @@ DevTools.prototype = {
     for (let [key, value] of this._tools) {
       if (DefaultTools.indexOf(value) == -1) {
         tools.push(value);
       }
     }
     return tools.sort(this.ordinalSort);
   },
 
+  getDefaultThemes() {
+    return DefaultThemes.sort(this.ordinalSort);
+  },
+
   /**
    * Get a tool definition if it exists and is enabled.
    *
    * @param {string} toolId
    *        The id of the tool to show
    *
    * @return {ToolDefinition|null} tool
    *         The ToolDefinition for the id or null.
--- a/devtools/client/main.js
+++ b/devtools/client/main.js
@@ -2,35 +2,29 @@
  * 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 Services = require("Services");
 const { gDevTools } = require("devtools/client/framework/devtools");
 
-const { defaultTools, defaultThemes } = require("devtools/client/definitions");
-
-defaultTools.forEach(definition => gDevTools.registerTool(definition));
-defaultThemes.forEach(definition => gDevTools.registerTheme(definition));
-
+// This is important step in initialization codepath where we are going to
+// start registering all default tools and themes: create menuitems, keys, emit
+// related events.
+gDevTools.registerDefaults();
 
 Object.defineProperty(exports, "Toolbox", {
   get: () => require("devtools/client/framework/toolbox").Toolbox
 });
 Object.defineProperty(exports, "TargetFactory", {
   get: () => require("devtools/client/framework/target").TargetFactory
 });
 
 const unloadObserver = {
   observe: function(subject) {
     if (subject.wrappedJSObject === require("@loader/unload")) {
       Services.obs.removeObserver(unloadObserver, "sdk:loader:destroy");
-      for (let definition of gDevTools.getToolDefinitionArray()) {
-        gDevTools.unregisterTool(definition.id);
-      }
-      for (let definition of gDevTools.getThemeDefinitionArray()) {
-        gDevTools.unregisterTheme(definition.id);
-      }
+      gDevTools.unregisterDefaults();
     }
   }
 };
 Services.obs.addObserver(unloadObserver, "sdk:loader:destroy", false);