/* 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 { fetch } = require("resource://devtools/shared/DevToolsUtils.js"); /** * For imported stylesheets, `ownerNode` is null. * * To resolve the ownerNode for an imported stylesheet, loop on `parentStylesheet` * until we reach the topmost stylesheet, which should have a valid ownerNode. * * Constructable stylesheets do not have an owner node and this method will * return null. * * @param {StyleSheet} * The stylesheet for which we want to retrieve the ownerNode. * @return {DOMNode|null} The ownerNode or null for constructable stylesheets. */ function getStyleSheetOwnerNode(sheet) { // If this is not an imported stylesheet and we have an ownerNode available // bail out immediately. if (sheet.ownerNode) { return sheet.ownerNode; } let parentStyleSheet = sheet; while ( parentStyleSheet.parentStyleSheet && parentStyleSheet !== parentStyleSheet.parentStyleSheet ) { parentStyleSheet = parentStyleSheet.parentStyleSheet; } return parentStyleSheet.ownerNode; } exports.getStyleSheetOwnerNode = getStyleSheetOwnerNode; /** * Get the text of a stylesheet. * * TODO: A call site in window-global.js expects this method to return a promise * so it is mandatory to keep it as an async function even if we are not using * await explicitly. Bug 1810572. * * @param {StyleSheet} * The stylesheet for which we want to retrieve the text. * @returns {Promise} */ async function getStyleSheetText(styleSheet) { if (!styleSheet.href) { if (styleSheet.ownerNode) { // this is an inline