зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1808870 - [devtools] Remove unused code branches behind hasStyleSheetWatcherSupport r=devtools-reviewers,devtools-backward-compat-reviewers,nchevobbe
Depends on D166142 Differential Revision: https://phabricator.services.mozilla.com/D166143
This commit is contained in:
Родитель
32445baa46
Коммит
45015576d9
|
@ -98,12 +98,6 @@ loader.lazyRequireGetter(
|
|||
"resource://devtools/server/actors/utils/walker-search.js",
|
||||
true
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
"hasStyleSheetWatcherSupportForTarget",
|
||||
"resource://devtools/server/actors/utils/stylesheets-manager.js",
|
||||
true
|
||||
);
|
||||
|
||||
// ContentDOMReference requires ChromeUtils, which isn't available in worker context.
|
||||
const lazy = {};
|
||||
|
@ -2666,23 +2660,14 @@ var WalkerActor = protocol.ActorClassWithSpec(walkerSpec, {
|
|||
},
|
||||
|
||||
/**
|
||||
* Given a StyleSheetActor (identified by its ID), commonly used in the
|
||||
* style-editor, get its ownerNode and return the corresponding walker's
|
||||
* NodeActor.
|
||||
* Given a StyleSheet resource ID, commonly used in the style-editor, get its
|
||||
* ownerNode and return the corresponding walker's NodeActor.
|
||||
* Note that getNodeFromActor was added later and can now be used instead.
|
||||
*/
|
||||
getStyleSheetOwnerNode(resourceId) {
|
||||
if (hasStyleSheetWatcherSupportForTarget(this.targetActor)) {
|
||||
const manager = this.targetActor.getStyleSheetManager();
|
||||
const ownerNode = manager.getOwnerNode(resourceId);
|
||||
return this.attachElement(ownerNode);
|
||||
}
|
||||
|
||||
// Following code can be removed once we enable STYLESHEET resource on the watcher/server
|
||||
// side by default. For now it is being preffed off and we have to support the two
|
||||
// codepaths. Once enabled we will only support the stylesheet watcher codepath.
|
||||
const actorBasedNode = this.getNodeFromActor(resourceId, ["ownerNode"]);
|
||||
return actorBasedNode;
|
||||
const manager = this.targetActor.getStyleSheetManager();
|
||||
const ownerNode = manager.getOwnerNode(resourceId);
|
||||
return this.attachElement(ownerNode);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,10 +19,6 @@ const {
|
|||
style: { ELEMENT_STYLE },
|
||||
} = require("resource://devtools/shared/constants.js");
|
||||
|
||||
const {
|
||||
hasStyleSheetWatcherSupportForTarget,
|
||||
} = require("resource://devtools/server/actors/utils/stylesheets-manager.js");
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
"StyleRuleActor",
|
||||
|
@ -66,7 +62,6 @@ loader.lazyGetter(this, "FONT_VARIATIONS_ENABLED", () => {
|
|||
return Services.prefs.getBoolPref("layout.css.font-variations.enabled");
|
||||
});
|
||||
|
||||
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
const NORMAL_FONT_WEIGHT = 400;
|
||||
const BOLD_FONT_WEIGHT = 700;
|
||||
|
||||
|
@ -115,17 +110,9 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
|
|||
this._watchedSheets = new Set();
|
||||
|
||||
this.styleSheetsManager = this.inspector.targetActor.getStyleSheetManager();
|
||||
this.hasStyleSheetWatcherSupport = hasStyleSheetWatcherSupportForTarget(
|
||||
this.inspector.targetActor
|
||||
);
|
||||
|
||||
if (this.hasStyleSheetWatcherSupport) {
|
||||
this._onStylesheetUpdated = this._onStylesheetUpdated.bind(this);
|
||||
this.styleSheetsManager.on(
|
||||
"stylesheet-updated",
|
||||
this._onStylesheetUpdated
|
||||
);
|
||||
}
|
||||
this._onStylesheetUpdated = this._onStylesheetUpdated.bind(this);
|
||||
this.styleSheetsManager.on("stylesheet-updated", this._onStylesheetUpdated);
|
||||
},
|
||||
|
||||
destroy() {
|
||||
|
@ -225,27 +212,6 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
|
|||
this.refMap.set(item, actor);
|
||||
},
|
||||
|
||||
/**
|
||||
* Return or create a StyleSheetActor for the given CSSStyleSheet.
|
||||
* @param {CSSStyleSheet} sheet
|
||||
* The style sheet to create an actor for.
|
||||
* @return {StyleSheetActor}
|
||||
* The actor for this style sheet
|
||||
*/
|
||||
_sheetRef(sheet) {
|
||||
if (this.hasStyleSheetWatcherSupport) {
|
||||
// We need to clean up this function in bug 1672090 when server-side stylesheet
|
||||
// watcher is enabled.
|
||||
console.warn(
|
||||
"This function should not be called when server-side stylesheet watcher is enabled"
|
||||
);
|
||||
}
|
||||
|
||||
const targetActor = this.inspector.targetActor;
|
||||
const actor = targetActor.createStyleSheetActor(sheet);
|
||||
return actor;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the StyleRuleActor matching the given rule id or null if no match is found.
|
||||
*
|
||||
|
@ -963,30 +929,6 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We need to clean up the following codes when server-side stylesheet
|
||||
// watcher is enabled in bug 1672090.
|
||||
if (this.hasStyleSheetWatcherSupport) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const rule of ruleSet) {
|
||||
if (rule.rawRule.parentStyleSheet) {
|
||||
const parent = this._sheetRef(rule.rawRule.parentStyleSheet);
|
||||
if (!sheetSet.has(parent)) {
|
||||
sheetSet.add(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const sheet of sheetSet) {
|
||||
if (sheet.rawSheet.parentStyleSheet) {
|
||||
const parent = this._sheetRef(sheet.rawSheet.parentStyleSheet);
|
||||
if (!sheetSet.has(parent)) {
|
||||
sheetSet.add(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1108,35 +1050,12 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
|
|||
styleActor._parentSheet
|
||||
);
|
||||
if (resId === resourceId) {
|
||||
styleActor._onStyleApplied(kind);
|
||||
styleActor.onStyleApplied(kind);
|
||||
}
|
||||
}
|
||||
this._styleApplied(kind);
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to addNewRule to get or create a style tag in the provided
|
||||
* document.
|
||||
*
|
||||
* @param {Document} document
|
||||
* The document in which the style element should be appended.
|
||||
* @returns DOMElement of the style tag
|
||||
*/
|
||||
getStyleElement(document) {
|
||||
if (
|
||||
!this.styleElements.has(document) ||
|
||||
!this.styleElements.get(document).isConnected
|
||||
) {
|
||||
const style = document.createElementNS(XHTML_NS, "style");
|
||||
style.setAttribute("type", "text/css");
|
||||
style.setDevtoolsAsTriggeringPrincipal();
|
||||
document.documentElement.appendChild(style);
|
||||
this.styleElements.set(document, style);
|
||||
}
|
||||
|
||||
return this.styleElements.get(document);
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function for adding a new rule and getting its applied style
|
||||
* properties
|
||||
|
@ -1160,20 +1079,15 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
|
|||
*/
|
||||
async addNewRule(node, pseudoClasses) {
|
||||
let sheet = null;
|
||||
if (this.hasStyleSheetWatcherSupport) {
|
||||
const doc = node.rawNode.ownerDocument;
|
||||
if (
|
||||
this.styleElements.has(doc) &&
|
||||
this.styleElements.get(doc).ownerNode?.isConnected
|
||||
) {
|
||||
sheet = this.styleElements.get(doc);
|
||||
} else {
|
||||
sheet = await this.styleSheetsManager.addStyleSheet(doc);
|
||||
this.styleElements.set(doc, sheet);
|
||||
}
|
||||
const doc = node.rawNode.ownerDocument;
|
||||
if (
|
||||
this.styleElements.has(doc) &&
|
||||
this.styleElements.get(doc).ownerNode?.isConnected
|
||||
) {
|
||||
sheet = this.styleElements.get(doc);
|
||||
} else {
|
||||
const style = this.getStyleElement(node.rawNode.ownerDocument);
|
||||
sheet = style.sheet;
|
||||
sheet = await this.styleSheetsManager.addStyleSheet(doc);
|
||||
this.styleElements.set(doc, sheet);
|
||||
}
|
||||
|
||||
const cssRules = sheet.cssRules;
|
||||
|
@ -1195,19 +1109,10 @@ var PageStyleActor = protocol.ActorClassWithSpec(pageStyleSpec, {
|
|||
|
||||
const index = sheet.insertRule(selector + " {}", cssRules.length);
|
||||
|
||||
if (this.hasStyleSheetWatcherSupport) {
|
||||
const resourceId = this.styleSheetsManager.getStyleSheetResourceId(sheet);
|
||||
let authoredText = await this.styleSheetsManager.getText(resourceId);
|
||||
authoredText += "\n" + selector + " {\n" + "}";
|
||||
await this.styleSheetsManager.setStyleSheetText(resourceId, authoredText);
|
||||
} else {
|
||||
// If inserting the rule succeeded, go ahead and edit the source
|
||||
// text if requested.
|
||||
const sheetActor = this._sheetRef(sheet);
|
||||
let { str: authoredText } = await sheetActor.getText();
|
||||
authoredText += "\n" + selector + " {\n" + "}";
|
||||
await sheetActor.update(authoredText, false);
|
||||
}
|
||||
const resourceId = this.styleSheetsManager.getStyleSheetResourceId(sheet);
|
||||
let authoredText = await this.styleSheetsManager.getText(resourceId);
|
||||
authoredText += "\n" + selector + " {\n" + "}";
|
||||
await this.styleSheetsManager.setStyleSheetText(resourceId, authoredText);
|
||||
|
||||
const cssRule = sheet.cssRules.item(index);
|
||||
const ruleActor = this._styleRef(cssRule);
|
||||
|
|
|
@ -86,7 +86,6 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
this.pageStyle = pageStyle;
|
||||
this.rawStyle = item.style;
|
||||
this._parentSheet = null;
|
||||
this._onStyleApplied = this._onStyleApplied.bind(this);
|
||||
// Parsed CSS declarations from this.form().declarations used to check CSS property
|
||||
// names and values before tracking changes. Using cached values instead of accessing
|
||||
// this.form().declarations on demand because that would cause needless re-parsing.
|
||||
|
@ -105,10 +104,6 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
this.line = InspectorUtils.getRelativeRuleLine(this.rawRule);
|
||||
this.column = InspectorUtils.getRuleColumn(this.rawRule);
|
||||
this._parentSheet = this.rawRule.parentStyleSheet;
|
||||
if (!this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
this.sheetActor = this.pageStyle._sheetRef(this._parentSheet);
|
||||
this.sheetActor.on("style-applied", this._onStyleApplied);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fake a rule
|
||||
|
@ -137,9 +132,6 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
this.rawNode = null;
|
||||
this.rawRule = null;
|
||||
this._declarations = null;
|
||||
if (this.sheetActor) {
|
||||
this.sheetActor.off("style-applied", this._onStyleApplied);
|
||||
}
|
||||
},
|
||||
|
||||
// Objects returned by this actor are owned by the PageStyleActor
|
||||
|
@ -252,36 +244,23 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
// Used to differentiate between changes to rules with identical selectors.
|
||||
data.ruleIndex = this._ruleIndex;
|
||||
|
||||
if (this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
const sheet = this._parentSheet;
|
||||
const inspectorActor = this.pageStyle.inspector;
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
sheet
|
||||
);
|
||||
const styleSheetIndex = this.pageStyle.styleSheetsManager.getStyleSheetIndex(
|
||||
resourceId
|
||||
);
|
||||
data.source = {
|
||||
// Inline stylesheets have a null href; Use window URL instead.
|
||||
type: sheet.href ? "stylesheet" : "inline",
|
||||
href: sheet.href || inspectorActor.window.location.toString(),
|
||||
id: resourceId,
|
||||
index: styleSheetIndex,
|
||||
// Whether the stylesheet lives in a different frame than the host document.
|
||||
isFramed: inspectorActor.window !== inspectorActor.window.top,
|
||||
};
|
||||
} else {
|
||||
data.source = {
|
||||
// Inline stylesheets have a null href; Use window URL instead.
|
||||
type: this.sheetActor.href ? "stylesheet" : "inline",
|
||||
href:
|
||||
this.sheetActor.href || this.sheetActor.window.location.toString(),
|
||||
id: this.sheetActor.actorID,
|
||||
index: this.sheetActor.styleSheetIndex,
|
||||
// Whether the stylesheet lives in a different frame than the host document.
|
||||
isFramed: this.sheetActor.ownerWindow !== this.sheetActor.window,
|
||||
};
|
||||
}
|
||||
const sheet = this._parentSheet;
|
||||
const inspectorActor = this.pageStyle.inspector;
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
sheet
|
||||
);
|
||||
const styleSheetIndex = this.pageStyle.styleSheetsManager.getStyleSheetIndex(
|
||||
resourceId
|
||||
);
|
||||
data.source = {
|
||||
// Inline stylesheets have a null href; Use window URL instead.
|
||||
type: sheet.href ? "stylesheet" : "inline",
|
||||
href: sheet.href || inspectorActor.window.location.toString(),
|
||||
id: resourceId,
|
||||
index: styleSheetIndex,
|
||||
// Whether the stylesheet lives in a different frame than the host document.
|
||||
isFramed: inspectorActor.window !== inspectorActor.window.top,
|
||||
};
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -349,15 +328,9 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
}
|
||||
|
||||
if (this._parentSheet) {
|
||||
if (this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
form.parentStyleSheet = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
} else {
|
||||
form.parentStyleSheet = this.pageStyle._sheetRef(
|
||||
this._parentSheet
|
||||
).actorID;
|
||||
}
|
||||
form.parentStyleSheet = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
|
||||
// If the rule is in a imported stylesheet with a specified layer, put it at the top
|
||||
// of the ancestor data array.
|
||||
|
@ -561,17 +534,16 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
},
|
||||
|
||||
/**
|
||||
* This is attached to the parent style sheet actor's
|
||||
* "style-applied" event.
|
||||
* Called from PageStyle actor _onStylesheetUpdated.
|
||||
*/
|
||||
_onStyleApplied(kind) {
|
||||
onStyleApplied(kind) {
|
||||
if (kind === UPDATE_GENERAL) {
|
||||
// A general change means that the rule actors are invalidated,
|
||||
// so stop listening to events now.
|
||||
if (this.sheetActor) {
|
||||
this.sheetActor.off("style-applied", this._onStyleApplied);
|
||||
}
|
||||
} else if (this._ruleIndex) {
|
||||
// A general change means that the rule actors are invalidated, nothing
|
||||
// to do here.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._ruleIndex) {
|
||||
// The sheet was updated by this actor, in a way that preserves
|
||||
// the rules. Now, recompute our new rule from the style sheet,
|
||||
// so that we aren't left with a reference to a dangling rule.
|
||||
|
@ -615,28 +587,15 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
return Promise.resolve(this.authoredText);
|
||||
}
|
||||
|
||||
if (this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
const cssText = await this.pageStyle.styleSheetsManager.getText(
|
||||
resourceId
|
||||
);
|
||||
const { text } = getRuleText(cssText, this.line, this.column);
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
const cssText = await this.pageStyle.styleSheetsManager.getText(resourceId);
|
||||
const { text } = getRuleText(cssText, this.line, this.column);
|
||||
|
||||
// Cache the result on the rule actor to avoid parsing again next time
|
||||
this.authoredText = text;
|
||||
return this.authoredText;
|
||||
}
|
||||
|
||||
return this.sheetActor.getText().then(longStr => {
|
||||
const cssText = longStr.str;
|
||||
const { text } = getRuleText(cssText, this.line, this.column);
|
||||
|
||||
// Cache the result on the rule actor to avoid parsing again next time
|
||||
this.authoredText = text;
|
||||
return this.authoredText;
|
||||
});
|
||||
// Cache the result on the rule actor to avoid parsing again next time
|
||||
this.authoredText = text;
|
||||
return this.authoredText;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -670,18 +629,12 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
// Get the rule's authored text and skip any cached value.
|
||||
ruleBodyText = await this.getAuthoredCssText(true);
|
||||
|
||||
let stylesheetText = null;
|
||||
if (this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
stylesheetText = await this.pageStyle.styleSheetsManager.getText(
|
||||
resourceId
|
||||
);
|
||||
} else {
|
||||
const { str } = await this.sheetActor.getText();
|
||||
stylesheetText = str;
|
||||
}
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
const stylesheetText = await this.pageStyle.styleSheetsManager.getText(
|
||||
resourceId
|
||||
);
|
||||
|
||||
const [start, end] = getSelectorOffsets(
|
||||
stylesheetText,
|
||||
|
@ -737,7 +690,7 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
if (this.type === ELEMENT_STYLE) {
|
||||
// For element style rules, set the node's style attribute.
|
||||
this.rawNode.setAttributeDevtools("style", newText);
|
||||
} else if (this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
} else {
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
|
@ -754,18 +707,6 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
cssText,
|
||||
{ kind: UPDATE_PRESERVING_RULES }
|
||||
);
|
||||
} else {
|
||||
// For stylesheet rules, set the text in the stylesheet.
|
||||
const parentStyleSheet = this.pageStyle._sheetRef(this._parentSheet);
|
||||
let { str: cssText } = await parentStyleSheet.getText();
|
||||
|
||||
const { offset, text } = getRuleText(cssText, this.line, this.column);
|
||||
cssText =
|
||||
cssText.substring(0, offset) +
|
||||
newText +
|
||||
cssText.substring(offset + text.length);
|
||||
|
||||
await parentStyleSheet.update(cssText, false, UPDATE_PRESERVING_RULES);
|
||||
}
|
||||
|
||||
this.authoredText = newText;
|
||||
|
@ -871,45 +812,28 @@ const StyleRuleActor = protocol.ActorClassWithSpec(styleRuleSpec, {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (this.pageStyle.hasStyleSheetWatcherSupport) {
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
let authoredText = await this.pageStyle.styleSheetsManager.getText(
|
||||
resourceId
|
||||
);
|
||||
const resourceId = this.pageStyle.styleSheetsManager.getStyleSheetResourceId(
|
||||
this._parentSheet
|
||||
);
|
||||
let authoredText = await this.pageStyle.styleSheetsManager.getText(
|
||||
resourceId
|
||||
);
|
||||
|
||||
const [startOffset, endOffset] = getSelectorOffsets(
|
||||
authoredText,
|
||||
this.line,
|
||||
this.column
|
||||
);
|
||||
authoredText =
|
||||
authoredText.substring(0, startOffset) +
|
||||
value +
|
||||
authoredText.substring(endOffset);
|
||||
const [startOffset, endOffset] = getSelectorOffsets(
|
||||
authoredText,
|
||||
this.line,
|
||||
this.column
|
||||
);
|
||||
authoredText =
|
||||
authoredText.substring(0, startOffset) +
|
||||
value +
|
||||
authoredText.substring(endOffset);
|
||||
|
||||
await this.pageStyle.styleSheetsManager.setStyleSheetText(
|
||||
resourceId,
|
||||
authoredText,
|
||||
{ kind: UPDATE_PRESERVING_RULES }
|
||||
);
|
||||
} else {
|
||||
const sheetActor = this.pageStyle._sheetRef(parentStyleSheet);
|
||||
let { str: authoredText } = await sheetActor.getText();
|
||||
|
||||
const [startOffset, endOffset] = getSelectorOffsets(
|
||||
authoredText,
|
||||
this.line,
|
||||
this.column
|
||||
);
|
||||
authoredText =
|
||||
authoredText.substring(0, startOffset) +
|
||||
value +
|
||||
authoredText.substring(endOffset);
|
||||
|
||||
await sheetActor.update(authoredText, false, UPDATE_PRESERVING_RULES);
|
||||
}
|
||||
await this.pageStyle.styleSheetsManager.setStyleSheetText(
|
||||
resourceId,
|
||||
authoredText,
|
||||
{ kind: UPDATE_PRESERVING_RULES }
|
||||
);
|
||||
} else {
|
||||
const cssRules = parentStyleSheet.cssRules;
|
||||
const cssText = rule.cssText;
|
||||
|
|
|
@ -19,12 +19,6 @@ loader.lazyRequireGetter(
|
|||
"resource://devtools/server/actors/style-sheet.js",
|
||||
true
|
||||
);
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
"hasStyleSheetWatcherSupportForTarget",
|
||||
"resource://devtools/server/actors/utils/stylesheets-manager.js",
|
||||
true
|
||||
);
|
||||
|
||||
/**
|
||||
* Creates a StyleSheetsActor. StyleSheetsActor provides remote access to the
|
||||
|
@ -298,96 +292,36 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, {
|
|||
* Object with 'styelSheet' property for form on new actor.
|
||||
*/
|
||||
async addStyleSheet(text, fileName = null) {
|
||||
if (this._hasStyleSheetWatcherSupport()) {
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
await styleSheetsManager.addStyleSheet(this.document, text, fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
// Following code can be removed once we enable STYLESHEET resource on the watcher/server
|
||||
// side by default. For now it is being preffed off and we have to support the two
|
||||
// codepaths. Once enabled we will only support the stylesheet watcher codepath.
|
||||
const parent = this.document.documentElement;
|
||||
const style = this.document.createElementNS(
|
||||
"http://www.w3.org/1999/xhtml",
|
||||
"style"
|
||||
);
|
||||
style.setAttribute("type", "text/css");
|
||||
|
||||
if (text) {
|
||||
style.appendChild(this.document.createTextNode(text));
|
||||
}
|
||||
parent.appendChild(style);
|
||||
|
||||
// This is a bit convoluted. The style sheet actor may be created
|
||||
// by a notification from platform. In this case, we can't easily
|
||||
// pass the "new" flag through to createStyleSheetActor, so we set
|
||||
// a flag locally and check it before sending an event to the
|
||||
// client. See |_onNewStyleSheetActor|.
|
||||
if (!this._addingStyleSheetInfo) {
|
||||
this._addingStyleSheetInfo = new WeakMap();
|
||||
}
|
||||
this._addingStyleSheetInfo.set(style.sheet, { isNew: true, fileName });
|
||||
|
||||
const actor = this.parentActor.createStyleSheetActor(style.sheet);
|
||||
// eslint-disable-next-line consistent-return
|
||||
return actor;
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
await styleSheetsManager.addStyleSheet(this.document, text, fileName);
|
||||
},
|
||||
|
||||
_getStyleSheetActor(resourceId) {
|
||||
return this.parentActor._targetScopedActorPool.getActorByID(resourceId);
|
||||
},
|
||||
|
||||
_hasStyleSheetWatcherSupport() {
|
||||
return hasStyleSheetWatcherSupportForTarget(this.parentActor);
|
||||
},
|
||||
|
||||
_getStyleSheetsManager() {
|
||||
return this.parentActor.getStyleSheetManager();
|
||||
},
|
||||
|
||||
toggleDisabled(resourceId) {
|
||||
if (this._hasStyleSheetWatcherSupport()) {
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
return styleSheetsManager.toggleDisabled(resourceId);
|
||||
}
|
||||
|
||||
// Following code can be removed once we enable STYLESHEET resource on the watcher/server
|
||||
// side by default. For now it is being preffed off and we have to support the two
|
||||
// codepaths. Once enabled we will only support the stylesheet watcher codepath.
|
||||
const actor = this._getStyleSheetActor(resourceId);
|
||||
return actor.toggleDisabled();
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
return styleSheetsManager.toggleDisabled(resourceId);
|
||||
},
|
||||
|
||||
async getText(resourceId) {
|
||||
if (this._hasStyleSheetWatcherSupport()) {
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
const text = await styleSheetsManager.getText(resourceId);
|
||||
return new LongStringActor(this.conn, text || "");
|
||||
}
|
||||
|
||||
// Following code can be removed once we enable STYLESHEET resource on the watcher/server
|
||||
// side by default. For now it is being preffed off and we have to support the two
|
||||
// codepaths. Once enabled we will only support the stylesheet watcher codepath.
|
||||
const actor = this._getStyleSheetActor(resourceId);
|
||||
return actor.getText();
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
const text = await styleSheetsManager.getText(resourceId);
|
||||
return new LongStringActor(this.conn, text || "");
|
||||
},
|
||||
|
||||
update(resourceId, text, transition, cause = "") {
|
||||
if (this._hasStyleSheetWatcherSupport()) {
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
return styleSheetsManager.setStyleSheetText(resourceId, text, {
|
||||
transition,
|
||||
kind: UPDATE_GENERAL,
|
||||
cause,
|
||||
});
|
||||
}
|
||||
|
||||
// Following code can be removed once we enable STYLESHEET resource on the watcher/server
|
||||
// side by default. For now it is being preffed off and we have to support the two
|
||||
// codepaths. Once enabled we will only support the stylesheet watcher codepath.
|
||||
const actor = this._getStyleSheetActor(resourceId);
|
||||
return actor.update(text, transition, UPDATE_GENERAL, cause);
|
||||
const styleSheetsManager = this._getStyleSheetsManager();
|
||||
return styleSheetsManager.setStyleSheetText(resourceId, text, {
|
||||
transition,
|
||||
kind: UPDATE_GENERAL,
|
||||
cause,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@ const InspectorUtils = require("InspectorUtils");
|
|||
const {
|
||||
getSourcemapBaseURL,
|
||||
} = require("resource://devtools/server/actors/utils/source-map-utils.js");
|
||||
const {
|
||||
TYPES,
|
||||
} = require("resource://devtools/server/actors/resources/index.js");
|
||||
|
||||
loader.lazyRequireGetter(
|
||||
this,
|
||||
|
@ -936,13 +933,6 @@ class StyleSheetsManager extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
function hasStyleSheetWatcherSupportForTarget(targetActor) {
|
||||
return (
|
||||
targetActor.sessionContext.supportedResources?.[TYPES.STYLESHEET] || false
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
StyleSheetsManager,
|
||||
hasStyleSheetWatcherSupportForTarget,
|
||||
};
|
||||
|
|
|
@ -38,7 +38,7 @@ const styleSheetsSpec = generateActorSpec({
|
|||
text: Arg(0, "string"),
|
||||
fileName: Arg(1, "nullable:string"),
|
||||
},
|
||||
response: { styleSheet: RetVal("nullable:stylesheet") },
|
||||
response: {},
|
||||
},
|
||||
toggleDisabled: {
|
||||
request: { resourceId: Arg(0, "string") },
|
||||
|
|
Загрузка…
Ссылка в новой задаче