From b9e65b07d6e78694ed53cbfb1a5904869a0322c2 Mon Sep 17 00:00:00 2001 From: Daisuke Akatsuka Date: Fri, 28 Aug 2020 06:27:53 +0000 Subject: [PATCH] Bug 1659589: Implement update method in stylesheets actor. r=ochameau,devtools-backward-compat-reviewers Depends on D87046 Differential Revision: https://phabricator.services.mozilla.com/D87047 --- .../client/styleeditor/StyleSheetEditor.jsm | 46 +++++++++++++------ devtools/server/actors/stylesheets.js | 5 ++ devtools/shared/specs/stylesheets.js | 9 ++++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/devtools/client/styleeditor/StyleSheetEditor.jsm b/devtools/client/styleeditor/StyleSheetEditor.jsm index f007fb5e7602..97fd79205793 100644 --- a/devtools/client/styleeditor/StyleSheetEditor.jsm +++ b/devtools/client/styleeditor/StyleSheetEditor.jsm @@ -490,7 +490,7 @@ StyleSheetEditor.prototype = { return sourceEditor.appendTo(inputElement).then(() => { sourceEditor.on("saveRequested", this.saveToFile); - if (this.styleSheet.update) { + if (!this.styleSheet.isOriginalSource) { sourceEditor.on("change", this.updateStyleSheet); } @@ -598,7 +598,7 @@ StyleSheetEditor.prototype = { /** * Update live style sheet according to modifications. */ - _updateStyleSheet: function() { + async _updateStyleSheet() { if (this.styleSheet.disabled) { // TODO: do we want to do this? return; @@ -620,14 +620,24 @@ StyleSheetEditor.prototype = { } this._isUpdating = true; - this.styleSheet - .update(this._state.text, this.transitionsEnabled) - .then(() => { - // Clear any existing mappings from automatic CSS prettification - // because they were likely invalided by manually editing the stylesheet. - this._mappings = null; - }) - .catch(console.error); + + try { + const styleSheetsFront = await this._getStyleSheetsFront(); + if (styleSheetsFront.traits.supportResourceRequests) { + await styleSheetsFront.update( + this.resourceId, + this._state.text, + this.transitionsEnabled + ); + } else { + await this.styleSheet.update(this._state.text, this.transitionsEnabled); + } + // Clear any existing mappings from automatic CSS prettification + // because they were likely invalided by manually editing the stylesheet. + this._mappings = null; + } catch (e) { + console.error(e); + } }, /** @@ -819,15 +829,25 @@ StyleSheetEditor.prototype = { * file from disk and live update the stylesheet object with the contents. */ updateLinkedStyleSheet: function() { - OS.File.read(this.linkedCSSFile).then(array => { + OS.File.read(this.linkedCSSFile).then(async array => { const decoder = new TextDecoder(); const text = decoder.decode(array); // Ensure we don't re-fetch the text from the original source // actor when we're notified that the style sheet changed. this._isUpdating = true; - const relatedSheet = this.styleSheet.relatedStyleSheet; - relatedSheet.update(text, this.transitionsEnabled); + + const styleSheetsFront = await this._getStyleSheetsFront(); + if (styleSheetsFront.traits.supportResourceRequests) { + await styleSheetsFront.update( + this.resourceId, + text, + this.transitionsEnabled + ); + } else { + const relatedSheet = this.styleSheet.relatedStyleSheet; + await relatedSheet.update(text, this.transitionsEnabled); + } }, this.markLinkedFileBroken); }, diff --git a/devtools/server/actors/stylesheets.js b/devtools/server/actors/stylesheets.js index f9335d5b0745..ce892a6c675f 100644 --- a/devtools/server/actors/stylesheets.js +++ b/devtools/server/actors/stylesheets.js @@ -914,6 +914,11 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, { const actor = this._getStyleSheetActor(resourceId); return actor.getText(); }, + + update(resourceId, text, transition) { + const actor = this._getStyleSheetActor(resourceId); + return actor.update(text, transition); + }, }); exports.StyleSheetsActor = StyleSheetsActor; diff --git a/devtools/shared/specs/stylesheets.js b/devtools/shared/specs/stylesheets.js index 01426d35df6d..1dd8e2d47454 100644 --- a/devtools/shared/specs/stylesheets.js +++ b/devtools/shared/specs/stylesheets.js @@ -62,6 +62,7 @@ const styleSheetSpec = generateActorSpec({ mediaRules: RetVal("nullable:array:mediarule"), }, }, + // Backward-compatibility: remove when FF81 hits release. update: { request: { text: Arg(0, "string"), @@ -109,6 +110,14 @@ const styleSheetsSpec = generateActorSpec({ request: { resourceId: Arg(0, "string") }, response: { text: RetVal("longstring") }, }, + update: { + request: { + resourceId: Arg(0, "string"), + text: Arg(1, "string"), + transition: Arg(2, "boolean"), + }, + response: {}, + }, }, });