Bug 1508660 - migrate getHighlighterByType to inspector front; r=ochameau

Differential Revision: https://phabricator.services.mozilla.com/D12438

--HG--
extra : moz-landing-system : lando
This commit is contained in:
yulia 2018-12-18 08:31:43 +00:00
Родитель 64e1d8a0f5
Коммит 0b73b92f31
6 изменённых файлов: 19 добавлений и 26 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);
}