From 0b73b92f31611bdd1cb8d0ba81326c3fde4ef726 Mon Sep 17 00:00:00 2001 From: yulia Date: Tue, 18 Dec 2018 08:31:43 +0000 Subject: [PATCH] Bug 1508660 - migrate getHighlighterByType to inspector front; r=ochameau Differential Revision: https://phabricator.services.mozilla.com/D12438 --HG-- extra : moz-landing-system : lando --- .../framework/toolbox-highlighter-utils.js | 16 ---------------- devtools/client/inspector/fonts/fonts.js | 2 +- devtools/client/inspector/rules/rules.js | 4 ++-- .../inspector/shared/highlighters-overlay.js | 8 ++++---- devtools/client/styleeditor/StyleEditorUI.jsm | 4 +--- devtools/shared/fronts/inspector.js | 11 +++++++++++ 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/devtools/client/framework/toolbox-highlighter-utils.js b/devtools/client/framework/toolbox-highlighter-utils.js index c546c3bcb3d1..c2a5441ae51b 100644 --- a/devtools/client/framework/toolbox-highlighter-utils.js +++ b/devtools/client/framework/toolbox-highlighter-utils.js @@ -173,22 +173,6 @@ exports.getHighlighterUtils = function(toolbox) { toolbox.win.focus(); } - /** - * If the main, box-model, highlighter isn't enough, or if multiple highlighters - * are needed in parallel, this method can be used to return a new instance of a - * highlighter actor, given a type. - * The type of the highlighter passed must be known by the server. - * The highlighter actor returned will have the show(nodeFront) and hide() - * methods and needs to be released by the consumer when not needed anymore. - * @return Promise a promise that resolves to the highlighter - */ - exported.getHighlighterByType = requireInspector(async function(typeName) { - const highlighter = await toolbox.inspector.getHighlighterByType(typeName); - - return highlighter || promise.reject("The target doesn't support " + - `creating highlighters by types or ${typeName} is unknown`); - }); - /** * Similar to getHighlighterByType, however it automatically memoizes and * destroys highlighters with the inspector, instead of having to be manually diff --git a/devtools/client/inspector/fonts/fonts.js b/devtools/client/inspector/fonts/fonts.js index 307fca5c740e..39265b6c5564 100644 --- a/devtools/client/inspector/fonts/fonts.js +++ b/devtools/client/inspector/fonts/fonts.js @@ -752,7 +752,7 @@ class FontInspector { async onToggleFontHighlight(font, show, isForCurrentElement = true) { if (!this.fontsHighlighter) { try { - this.fontsHighlighter = await this.inspector.toolbox.highlighterUtils + this.fontsHighlighter = await this.inspector.inspector .getHighlighterByType("FontsHighlighter"); } catch (e) { // When connecting to an older server or when debugging a XUL document, the diff --git a/devtools/client/inspector/rules/rules.js b/devtools/client/inspector/rules/rules.js index 9dfde3d85e25..45d233a0ac9c 100644 --- a/devtools/client/inspector/rules/rules.js +++ b/devtools/client/inspector/rules/rules.js @@ -262,8 +262,8 @@ CssRuleView.prototype = { } try { - const utils = this.inspector.toolbox.highlighterUtils; - const h = await utils.getHighlighterByType("SelectorHighlighter"); + const front = this.inspector.inspector; + const h = await front.getHighlighterByType("SelectorHighlighter"); this.selectorHighlighter = h; return h; } catch (e) { diff --git a/devtools/client/inspector/shared/highlighters-overlay.js b/devtools/client/inspector/shared/highlighters-overlay.js index bbf72b8287ca..5b5d0f3f2904 100644 --- a/devtools/client/inspector/shared/highlighters-overlay.js +++ b/devtools/client/inspector/shared/highlighters-overlay.js @@ -28,7 +28,7 @@ class HighlightersOverlay { */ constructor(inspector) { this.inspector = inspector; - this.highlighterUtils = this.inspector.toolbox.highlighterUtils; + this.inspectorFront = this.inspector.inspector; this.store = this.inspector.store; this.telemetry = inspector.telemetry; this.maxGridHighlighters = @@ -779,7 +779,7 @@ class HighlightersOverlay { let highlighter; try { - highlighter = await this.highlighterUtils.getHighlighterByType(type); + highlighter = await this.inspectorFront.getHighlighterByType(type); } catch (e) { this._handleRejection(e); } @@ -812,7 +812,7 @@ class HighlightersOverlay { highlighter = this.extraGridHighlighterPool.pop(); } else { try { - highlighter = await this.highlighterUtils.getHighlighterByType( + highlighter = await this.inspectorFront.getHighlighterByType( "CssGridHighlighter"); } catch (e) { this._handleRejection(e); @@ -1240,7 +1240,7 @@ class HighlightersOverlay { this._lastHovered = null; this.inspector = null; - this.highlighterUtils = null; + this.inspectorFront = null; this.state = null; this.store = null; diff --git a/devtools/client/styleeditor/StyleEditorUI.jsm b/devtools/client/styleeditor/StyleEditorUI.jsm index 67ba90a6db4c..adba40fdb359 100644 --- a/devtools/client/styleeditor/StyleEditorUI.jsm +++ b/devtools/client/styleeditor/StyleEditorUI.jsm @@ -129,11 +129,9 @@ StyleEditorUI.prototype = { await toolbox.initInspector(); this._walker = toolbox.walker; - const hUtils = toolbox.highlighterUtils; - try { this._highlighter = - await hUtils.getHighlighterByType(SELECTOR_HIGHLIGHTER_TYPE); + await toolbox.inspector.getHighlighterByType(SELECTOR_HIGHLIGHTER_TYPE); } catch (e) { // The selectorHighlighter can't always be instantiated, for example // it doesn't work with XUL windows (until bug 1094959 gets fixed); diff --git a/devtools/shared/fronts/inspector.js b/devtools/shared/fronts/inspector.js index 4b302ba091d9..49893160fcda 100644 --- a/devtools/shared/fronts/inspector.js +++ b/devtools/shared/fronts/inspector.js @@ -499,6 +499,17 @@ class InspectorFront extends FrontClassWithSpec(inspectorSpec) { } } + async getHighlighterByType(typeName) { + let highlighter = null; + try { + highlighter = await super.getHighlighterByType(typeName); + } catch (_) { + throw new Error("The target doesn't support " + + `creating highlighters by types or ${typeName} is unknown`); + } + return highlighter; + } + getKnownHighlighter(type) { return this._highlighters.get(type); }