Bug 1222047 - Manage StyleSheets fronts via target.getFront. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 13 Aug 2018 09:42:19 -0700
changeset 433052 b1efefe78cb691ed1ece51a12185eb417a783c02
parent 433051 b47fe9721bd87ec9d1f075d5ab4de41ca15963bf
child 433053 d8a1ea339162aa89ba0c852685126a394ebb0e3a
push id34499
push usercsabou@mozilla.com
push dateThu, 23 Aug 2018 21:40:51 +0000
treeherdermozilla-central@49b70f7e6817 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1222047
milestone63.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 1222047 - Manage StyleSheets fronts via target.getFront. r=yulia Summary: Depends On D3316 Tags: #secure-revision Bug #: 1222047 Differential Revision: https://phabricator.services.mozilla.com/D3317 MozReview-Commit-ID: KMVHXrGlncU
devtools/client/framework/source-map-url-service.js
devtools/client/framework/toolbox.js
devtools/client/styleeditor/panel.js
--- a/devtools/client/framework/source-map-url-service.js
+++ b/devtools/client/framework/source-map-url-service.js
@@ -48,40 +48,43 @@ function SourceMapURLService(toolbox, so
 }
 
 /**
  * Lazy initialization.  Returns a promise that will resolve when all
  * the relevant URLs have been registered.
  */
 SourceMapURLService.prototype._getLoadingPromise = function() {
   if (!this._loadingPromise) {
-    let styleSheetsLoadingPromise = null;
-    this._stylesheetsFront = this._toolbox.initStyleSheetsFront();
-    if (this._stylesheetsFront) {
+    this._loadingPromise = (async () => {
+      if (this._target.isWorkerTarget) {
+        return;
+      }
+      this._stylesheetsFront = await this._target.getFront("stylesheets");
       this._stylesheetsFront.on("stylesheet-added", this._onNewStyleSheet);
-      styleSheetsLoadingPromise =
+      const styleSheetsLoadingPromise =
           this._stylesheetsFront.getStyleSheets().then(sheets => {
             sheets.forEach(this._onNewStyleSheet);
           }, () => {
             // Ignore any protocol-based errors.
           });
-    }
 
-    // Start fetching the sources now.
-    const loadingPromise = this._toolbox.threadClient.getSources().then(({sources}) => {
-      // Ignore errors.  Register the sources we got; we can't rely on
-      // an event to arrive if the source actor already existed.
-      for (const source of sources) {
-        this._onSourceUpdated({source});
-      }
-    }, e => {
-      // Also ignore any protocol-based errors.
-    });
+      // Start fetching the sources now.
+      const loadingPromise = this._toolbox.threadClient.getSources().then(({sources}) => {
+        // Ignore errors.  Register the sources we got; we can't rely on
+        // an event to arrive if the source actor already existed.
+        for (const source of sources) {
+          this._onSourceUpdated({source});
+        }
+      }, e => {
+        // Also ignore any protocol-based errors.
+      });
 
-    this._loadingPromise = Promise.all([styleSheetsLoadingPromise, loadingPromise]);
+      await styleSheetsLoadingPromise;
+      await loadingPromise;
+    })();
   }
   return this._loadingPromise;
 };
 
 /**
  * Reset the service.  This flushes the internal cache.
  */
 SourceMapURLService.prototype.reset = function() {
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -58,18 +58,16 @@ loader.lazyRequireGetter(this, "settleAl
 loader.lazyRequireGetter(this, "ToolboxButtons",
   "devtools/client/definitions", true);
 loader.lazyRequireGetter(this, "SourceMapURLService",
   "devtools/client/framework/source-map-url-service", true);
 loader.lazyRequireGetter(this, "HUDService",
   "devtools/client/webconsole/hudservice", true);
 loader.lazyRequireGetter(this, "viewSource",
   "devtools/client/shared/view-source");
-loader.lazyRequireGetter(this, "StyleSheetsFront",
-  "devtools/shared/fronts/stylesheets", true);
 loader.lazyRequireGetter(this, "buildHarLog",
   "devtools/client/netmonitor/src/har/har-builder-utils", true);
 loader.lazyRequireGetter(this, "getKnownDeviceFront",
   "devtools/shared/fronts/device", true);
 loader.lazyRequireGetter(this, "NetMonitorAPI",
   "devtools/client/netmonitor/src/api", true);
 loader.lazyRequireGetter(this, "sortPanelDefinitions",
   "devtools/client/framework/toolbox-tabs-order-manager", true);
@@ -120,17 +118,16 @@ function Toolbox(target, selectedTool, h
 
   this._toolPanels = new Map();
   // Map of tool startup components for given tool id.
   this._toolStartups = new Map();
   this._inspectorExtensionSidebars = new Map();
 
   this._initInspector = null;
   this._inspector = null;
-  this._styleSheets = null;
   this._netMonitorAPI = null;
 
   // Map of frames (id => frame-info) and currently selected frame id.
   this.frameMap = new Map();
   this.selectedFrameId = null;
 
   this._toolRegistered = this._toolRegistered.bind(this);
   this._toolUnregistered = this._toolUnregistered.bind(this);
@@ -2933,22 +2930,16 @@ Toolbox.prototype = {
     outstanding.push(this.destroyInspector());
 
     // Destroy the profiler connection
     outstanding.push(this.destroyPerformance());
 
     // Destroy the preference front
     outstanding.push(this.destroyPreference());
 
-    // Destroy the style sheet front.
-    if (this._styleSheets) {
-      this._styleSheets.destroy();
-      this._styleSheets = null;
-    }
-
     // Destroy the device front for the current client if any.
     // A given DeviceFront instance can cached and shared between different panels, so
     // destroying it is the responsibility of the toolbox.
     const deviceFront = getKnownDeviceFront(this.target.client);
     if (deviceFront) {
       deviceFront.destroy();
     }
 
@@ -3130,27 +3121,16 @@ Toolbox.prototype = {
       await this._performanceFrontConnection;
     }
     this.performance.off("*", this._onPerformanceFrontEvent);
     await this.performance.destroy();
     this._performance = null;
   },
 
   /**
-   * Return the style sheets front, creating it if necessary.  If the
-   * style sheets front is not supported by the target, returns null.
-   */
-  initStyleSheetsFront: function() {
-    if (!this._styleSheets && this.target.hasActor("styleSheets")) {
-      this._styleSheets = StyleSheetsFront(this.target.client, this.target.form);
-    }
-    return this._styleSheets;
-  },
-
-  /**
    * Destroy the preferences actor when the toolbox is unloaded.
    */
   async destroyPreference() {
     if (!this._preferenceFront) {
       return;
     }
 
     // Only reset the autohide pref in the Browser Toolbox if it's been toggled
--- a/devtools/client/styleeditor/panel.js
+++ b/devtools/client/styleeditor/panel.js
@@ -42,17 +42,17 @@ StyleEditorPanel.prototype = {
   async open() {
     // We always interact with the target as if it were remote
     if (!this.target.isRemote) {
       await this.target.makeRemote();
     }
 
     this.target.on("close", this.destroy);
 
-    this._debuggee = this._toolbox.initStyleSheetsFront();
+    this._debuggee = await this._target.getFront("stylesheets");
 
     // Initialize the CSS properties database.
     const {cssProperties} = await initCssProperties(this._toolbox);
 
     // Initialize the UI
     this.UI = new StyleEditorUI(this._debuggee, this.target, this._panelDoc,
                                 cssProperties);
     this.UI.on("error", this._showError);