Bug 1406778 - Lazily load the font inspector. r=ochameau draft
authorGabriel Luong <gabriel.luong@gmail.com>
Thu, 12 Oct 2017 15:18:49 -0400
changeset 679503 25b9a106d58b72fe71c5802979f91d8b9a105e79
parent 679502 809626d33d7438458ead8017127161ddd3ebd54d
child 735617 2f65e8475efc98752e44a43f1b5d5a4d21bef30a
push id84241
push userbmo:gl@mozilla.com
push dateThu, 12 Oct 2017 19:19:19 +0000
reviewersochameau
bugs1406778
milestone58.0a1
Bug 1406778 - Lazily load the font inspector. r=ochameau MozReview-Commit-ID: IWns3WTM3dx
devtools/client/inspector/fonts/fonts.js
devtools/client/inspector/inspector.js
--- a/devtools/client/inspector/fonts/fonts.js
+++ b/devtools/client/inspector/fonts/fonts.js
@@ -31,44 +31,40 @@ function FontInspector(inspector, window
   this.store = inspector.store;
 
   this.update = this.update.bind(this);
 
   this.onNewNode = this.onNewNode.bind(this);
   this.onPreviewFonts = this.onPreviewFonts.bind(this);
   this.onShowAllFont = this.onShowAllFont.bind(this);
   this.onThemeChanged = this.onThemeChanged.bind(this);
+
+  this.init();
 }
 
 FontInspector.prototype = {
   init() {
     if (!this.inspector) {
       return;
     }
 
     let app = App({
       onPreviewFonts: this.onPreviewFonts,
       onShowAllFont: this.onShowAllFont,
     });
 
     let provider = createElement(Provider, {
+      id: "fontinspector",
+      key: "fontinspector",
       store: this.store,
-      id: "fontinspector",
       title: INSPECTOR_L10N.getStr("inspector.sidebar.fontInspectorTitle"),
-      key: "fontinspector",
     }, app);
 
-    let defaultTab = Services.prefs.getCharPref("devtools.inspector.activeSidebar");
-
-    this.inspector.addSidebarTab(
-      "fontinspector",
-      INSPECTOR_L10N.getStr("inspector.sidebar.fontInspectorTitle"),
-      provider,
-      defaultTab == "fontinspector"
-    );
+    // Expose the provider to let inspector.js use it in setupSidebar.
+    this.provider = provider;
 
     this.inspector.selection.on("new-node-front", this.onNewNode);
     this.inspector.sidebar.on("fontinspector-selected", this.onNewNode);
 
     // Listen for theme changes as the color of the previews depend on the theme
     gDevTools.on("theme-switched", this.onThemeChanged);
 
     this.store.dispatch(updatePreviewText(""));
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -663,23 +663,37 @@ Inspector.prototype = {
     if (this.target.form.animationsActor) {
       this.sidebar.addFrameTab(
         "animationinspector",
         INSPECTOR_L10N.getStr("inspector.sidebar.animationInspectorTitle"),
         "chrome://devtools/content/animationinspector/animation-inspector.xhtml",
         defaultTab == "animationinspector");
     }
 
-    if (Services.prefs.getBoolPref("devtools.fontinspector.enabled") &&
-        this.canGetUsedFontFaces) {
-      const FontInspector = this.browserRequire("devtools/client/inspector/fonts/fonts");
-      this.fontinspector = new FontInspector(this, this.panelWin);
-      this.fontinspector.init();
-
-      this.sidebar.toggleTab(true, "fontinspector");
+    if (this.canGetUsedFontFaces) {
+      let fontId = "fontinspector";
+      let fontTitle = INSPECTOR_L10N.getStr("inspector.sidebar.fontInspectorTitle");
+      this.sidebar.addTab(
+        fontId,
+        fontTitle,
+        {
+          props: {
+            id: fontId,
+            title: fontTitle
+          },
+          panel: () => {
+            if (!this.fontinspector) {
+              const FontInspector =
+                this.browserRequire("devtools/client/inspector/fonts/fonts");
+              this.fontinspector = new FontInspector(this, this.panelWin);
+            }
+            return this.fontinspector.provider;
+          }
+        },
+        defaultTab == fontId);
     }
 
     // Persist splitter state in preferences.
     this.sidebar.on("show", this.onSidebarShown);
     this.sidebar.on("hide", this.onSidebarHidden);
     this.sidebar.on("destroy", this.onSidebarHidden);
 
     this.sidebar.show(defaultTab);