From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- devtools/server/actors/style-sheets.js | 105 +++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 devtools/server/actors/style-sheets.js (limited to 'devtools/server/actors/style-sheets.js') diff --git a/devtools/server/actors/style-sheets.js b/devtools/server/actors/style-sheets.js new file mode 100644 index 0000000000..64f16badc0 --- /dev/null +++ b/devtools/server/actors/style-sheets.js @@ -0,0 +1,105 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const { Actor } = require("resource://devtools/shared/protocol.js"); +const { + styleSheetsSpec, +} = require("resource://devtools/shared/specs/style-sheets.js"); + +const { + LongStringActor, +} = require("resource://devtools/server/actors/string.js"); + +loader.lazyRequireGetter( + this, + "UPDATE_GENERAL", + "resource://devtools/server/actors/utils/stylesheets-manager.js", + true +); + +/** + * Creates a StyleSheetsActor. StyleSheetsActor provides remote access to the + * stylesheets of a document. + */ +class StyleSheetsActor extends Actor { + constructor(conn, targetActor) { + super(conn, styleSheetsSpec); + + this.parentActor = targetActor; + } + + /** + * The window we work with, taken from the parent actor. + */ + get window() { + return this.parentActor.window; + } + + /** + * The current content document of the window we work with. + */ + get document() { + return this.window.document; + } + + getTraits() { + return { + traits: {}, + }; + } + + destroy() { + for (const win of this.parentActor.windows) { + // This flag only exists for devtools, so we are free to clear + // it when we're done. + win.document.styleSheetChangeEventsEnabled = false; + } + + super.destroy(); + } + + /** + * Create a new style sheet in the document with the given text. + * Return an actor for it. + * + * @param {object} request + * Debugging protocol request object, with 'text property' + * @param {string} fileName + * If the stylesheet adding is from file, `fileName` indicates the path. + * @return {object} + * Object with 'styelSheet' property for form on new actor. + */ + async addStyleSheet(text, fileName = null) { + const styleSheetsManager = this._getStyleSheetsManager(); + await styleSheetsManager.addStyleSheet(this.document, text, fileName); + } + + _getStyleSheetsManager() { + return this.parentActor.getStyleSheetsManager(); + } + + toggleDisabled(resourceId) { + const styleSheetsManager = this._getStyleSheetsManager(); + return styleSheetsManager.toggleDisabled(resourceId); + } + + async getText(resourceId) { + const styleSheetsManager = this._getStyleSheetsManager(); + const text = await styleSheetsManager.getText(resourceId); + return new LongStringActor(this.conn, text || ""); + } + + update(resourceId, text, transition, cause = "") { + const styleSheetsManager = this._getStyleSheetsManager(); + return styleSheetsManager.setStyleSheetText(resourceId, text, { + transition, + kind: UPDATE_GENERAL, + cause, + }); + } +} + +exports.StyleSheetsActor = StyleSheetsActor; -- cgit v1.2.3