diff --git a/devtools/client/framework/source-map-url-service.js b/devtools/client/framework/source-map-url-service.js index b2e552fbd589..9c74e3cbfb58 100644 --- a/devtools/client/framework/source-map-url-service.js +++ b/devtools/client/framework/source-map-url-service.js @@ -27,6 +27,7 @@ class SourceMapURLService { this._pendingURLSubscriptions = new Map(); this._urlToIDMap = new Map(); this._mapsById = new Map(); + this._listeningStylesheetFront = null; this._sourcesLoading = null; this._runningCallback = false; @@ -204,16 +205,13 @@ class SourceMapURLService { this._pendingURLSubscriptions.clear(); this._urlToIDMap.clear(); - try { - this._toolbox.resourceWatcher.unwatchResources( - [this._toolbox.resourceWatcher.TYPES.STYLESHEET], - { onAvailable: this._onResourceAvailable } + if (this._listeningStylesheetFront) { + this._listeningStylesheetFront.off( + "stylesheet-added", + this._onNewStyleSheet ); - } catch (e) { - // If unwatchResources is called before finishing process of watchResources, - // it throws an error during stopping listener. + this._listeningStylesheetFront = null; } - this._sourcesLoading = null; } @@ -428,17 +426,39 @@ class SourceMapURLService { return; } - this._onResourceAvailable = async ({ resource }) => { - if (this._sourcesLoading === sourcesLoading) { - this._onNewStyleSheet(resource.styleSheet); - } - }; - await Promise.all([ - this._toolbox.resourceWatcher.watchResources( - [this._toolbox.resourceWatcher.TYPES.STYLESHEET], - { onAvailable: this._onResourceAvailable } - ), + (async () => { + if (!this._target.hasActor("styleSheets")) { + return; + } + + try { + const front = await this._target.getFront("stylesheets"); + + if (this._listeningStylesheetFront) { + this._listeningStylesheetFront.off( + "stylesheet-added", + this._onNewStyleSheet + ); + } + this._listeningStylesheetFront = front; + this._listeningStylesheetFront.on( + "stylesheet-added", + this._onNewStyleSheet + ); + + const sheets = await front.getStyleSheets(); + if (this._sourcesLoading === sourcesLoading) { + // If we've cleared the state since starting this request, + // we don't want to populate these. + for (const sheet of sheets) { + this._onNewStyleSheet(sheet); + } + } + } catch (err) { + // Ignore any protocol-based errors. + } + })(), (async () => { const { threadFront } = this._toolbox; if (!threadFront) { diff --git a/devtools/client/styleeditor/StyleEditorUI.jsm b/devtools/client/styleeditor/StyleEditorUI.jsm index 89aecafc5309..c2e0c765f999 100644 --- a/devtools/client/styleeditor/StyleEditorUI.jsm +++ b/devtools/client/styleeditor/StyleEditorUI.jsm @@ -89,8 +89,16 @@ function StyleEditorUI(toolbox, panelDoc, cssProperties) { this.savedLocations = {}; this._seenSheets = new Map(); + // Don't add any style sheets that might arrive via events, until + // the call to initialize. Style sheets can arrive from the server + // at any time, for example if a new style sheet was added, or if + // the style sheet actor was just created and is walking the style + // sheets for the first time. In any case, in |initialize| we're + // going to fetch the list of sheets anyway. + this._suppressAdd = true; + this._onOptionsButtonClick = this._onOptionsButtonClick.bind(this); - this._onOrigSourcesPrefChanged = this._onOrigSourcesPrefChanged.bind(this); + this._onNewDocument = this._onNewDocument.bind(this); this._onMediaPrefChanged = this._onMediaPrefChanged.bind(this); this._updateMediaList = this._updateMediaList.bind(this); this._clear = this._clear.bind(this); @@ -98,18 +106,16 @@ function StyleEditorUI(toolbox, panelDoc, cssProperties) { this._updateContextMenuItems = this._updateContextMenuItems.bind(this); this._openLinkNewTab = this._openLinkNewTab.bind(this); this._copyUrl = this._copyUrl.bind(this); + this._addStyleSheet = this._addStyleSheet.bind(this); this._onTargetAvailable = this._onTargetAvailable.bind(this); - this._onResourceAvailable = this._onResourceAvailable.bind(this); + this._onTargetDestroyed = this._onTargetDestroyed.bind(this); this._prefObserver = new PrefObserver("devtools.styleeditor."); this._prefObserver.on(PREF_MEDIA_SIDEBAR, this._onMediaPrefChanged); this._sourceMapPrefObserver = new PrefObserver( "devtools.source-map.client-service." ); - this._sourceMapPrefObserver.on( - PREF_ORIG_SOURCES, - this._onOrigSourcesPrefChanged - ); + this._sourceMapPrefObserver.on(PREF_ORIG_SOURCES, this._onNewDocument); } StyleEditorUI.prototype = { @@ -138,20 +144,9 @@ StyleEditorUI.prototype = { await this._toolbox.targetList.watchTargets( [this._toolbox.targetList.TYPES.FRAME], - this._onTargetAvailable + this._onTargetAvailable, + this._onTargetDestroyed ); - - await this._toolbox.resourceWatcher.watchResources( - [this._toolbox.resourceWatcher.TYPES.DOCUMENT_EVENT], - { onAvailable: this._onResourceAvailable } - ); - - this._startLoadingStyleSheets(); - await this._toolbox.resourceWatcher.watchResources( - [this._toolbox.resourceWatcher.TYPES.STYLESHEET], - { onAvailable: this._onResourceAvailable } - ); - await this._waitForLoadingStyleSheets(); }, async initializeHighlighter(targetFront) { @@ -244,22 +239,41 @@ StyleEditorUI.prototype = { }, /** - * Be called when changing the original sources pref. + * Refresh editors to reflect the stylesheets in the document. */ - async _onOrigSourcesPrefChanged() { - this._clear(); - // When we toggle the source-map preference, we clear the panel and re-fetch the exact - // same stylesheet resources from ResourceWatcher, but `_addStyleSheet` will trigger - // or ignore the additional source-map mapping. - this._root.classList.add("loading"); - for (const resource of this._toolbox.resourceWatcher.getAllResources( - this._toolbox.resourceWatcher.TYPES.STYLESHEET - )) { - await this._handleStyleSheetResource(resource); + async _onNewDocument() { + this._suppressAdd = true; + try { + const stylesheetsFront = await this.currentTarget.getFront("stylesheets"); + const styleSheets = await stylesheetsFront.getStyleSheets(); + await this._resetStyleSheetList(styleSheets); + } catch (e) { + console.error(e); } + }, + + /** + * Add editors for all the given stylesheets to the UI. + * + * @param {array} styleSheets + * Array of StyleSheetFront + */ + async _resetStyleSheetList(styleSheets) { + this._clear(); + this._suppressAdd = false; + + for (const sheet of styleSheets) { + try { + await this._addStyleSheet(sheet); + } catch (e) { + console.error(e); + this.emit("error", { key: LOAD_ERROR, level: "warning" }); + } + } + this._root.classList.remove("loading"); - this.emit("stylesheets-refreshed"); + this.emit("stylesheets-reset"); }, /** @@ -293,8 +307,9 @@ StyleEditorUI.prototype = { // Here the keys are style sheet actors, and the values are // promises that resolve to the sheet's editor. See |_addStyleSheet|. this._seenSheets = new Map(); + this._suppressAdd = true; - this.emit("stylesheets-clear"); + this._root.classList.add("loading"); }, /** @@ -312,6 +327,10 @@ StyleEditorUI.prototype = { * is enabled, then the promise resolves to null. */ _addStyleSheet: function(styleSheet, isNew) { + if (this._suppressAdd) { + return null; + } + if (!this._seenSheets.has(styleSheet)) { const promise = (async () => { let editor = await this._addStyleSheetEditor(styleSheet, isNew); @@ -474,10 +493,12 @@ StyleEditorUI.prototype = { ); stream.close(); + this._suppressAdd = true; const stylesheetsFront = await this.currentTarget.getFront( "stylesheets" ); const styleSheet = await stylesheetsFront.addStyleSheet(source); + this._suppressAdd = false; const editor = await this._addStyleSheet(styleSheet, true); if (editor) { editor.savedFile = selectedFile; @@ -1154,96 +1175,50 @@ StyleEditorUI.prototype = { this.selectStyleSheet(source, location.line - 1, location.column - 1); }, - _startLoadingStyleSheets() { - this._root.classList.add("loading"); - this._loadingStyleSheets = []; - }, - - async _waitForLoadingStyleSheets() { - while (this._loadingStyleSheets?.length > 0) { - const pending = this._loadingStyleSheets; - this._loadingStyleSheets = []; - await Promise.all(pending); - } - - this._loadingStyleSheets = null; - this._root.classList.remove("loading"); - }, - - async _handleStyleSheetResource({ styleSheet, isNew }) { - try { - await this._addStyleSheet(styleSheet, isNew); - } catch (e) { - console.error(e); - this.emit("error", { key: LOAD_ERROR, level: "warning" }); - } - }, - - async _onResourceAvailable({ targetFront, resource }) { - if ( - resource.resourceType === this._toolbox.resourceWatcher.TYPES.STYLESHEET - ) { - const onStyleSheetHandled = this._handleStyleSheetResource(resource); - - if (this._loadingStyleSheets) { - // In case of reloading/navigating and panel's opening - this._loadingStyleSheets.push(onStyleSheetHandled); - } - - await onStyleSheetHandled; - return; - } - - if (!resource.targetFront.isTopLevel) { - return; - } - - if (resource.name === "dom-loading") { - // will-navigate doesn't work when we navigate to a new process, - // and for now, onTargetAvailable/onTargetDestroyed doesn't fire on navigation and - // only when navigating to another process. - // So we fallback on DOCUMENT_EVENTS to be notified when we navigates. When we - // navigate within the same process as well as when we navigate to a new process. - // (We would probably revisit that in bug 1632141) - this._startLoadingStyleSheets(); - this._clear(); - } else if (resource.name === "dom-complete") { - await this._waitForLoadingStyleSheets(); - } - }, - async _onTargetAvailable({ targetFront }) { if (targetFront.isTopLevel) { await this.initializeHighlighter(targetFront); + + const stylesheetsFront = await targetFront.getFront("stylesheets"); + stylesheetsFront.on("stylesheet-added", this._addStyleSheet); + targetFront.on("will-navigate", this._clear); + targetFront.on("navigate", this._onNewDocument); + + await this._onNewDocument(); + } + }, + + async _onTargetDestroyed({ targetFront }) { + if (targetFront.isTopLevel) { + this._clear(); } }, destroy: function() { this._toolbox.targetList.unwatchTargets( [this._toolbox.targetList.TYPES.FRAME], - this._onTargetAvailable + this._onTargetAvailable, + this._onTargetDestroyed ); - this._toolbox.resourceWatcher.unwatchResources( - [ - this._toolbox.resourceWatcher.TYPES.DOCUMENT_EVENT, - this._toolbox.resourceWatcher.TYPES.STYLESHEET, - ], - { onAvailable: this._onResourceAvailable } - ); + this.currentTarget.off("will-navigate", this._clear); + this.currentTarget.off("navigate", this._onNewDocument); + + const stylesheetsFront = this.currentTarget.getCachedFront("stylesheets"); + if (stylesheetsFront) { + stylesheetsFront.off("stylesheet-added", this._addStyleSheet); + } this._clearStyleSheetEditors(); this._seenSheets = null; + this._suppressAdd = false; const sidebar = this._panelDoc.querySelector(".splitview-controller"); const sidebarWidth = sidebar.getAttribute("width"); Services.prefs.setIntPref(PREF_NAV_WIDTH, sidebarWidth); - this._sourceMapPrefObserver.off( - PREF_ORIG_SOURCES, - this._onOrigSourcesPrefChanged - ); + this._sourceMapPrefObserver.off(PREF_ORIG_SOURCES, this._onNewDocument); this._sourceMapPrefObserver.destroy(); this._prefObserver.off(PREF_MEDIA_SIDEBAR, this._onMediaPrefChanged); this._prefObserver.destroy(); diff --git a/devtools/client/styleeditor/test/browser_styleeditor_bug_870339.js b/devtools/client/styleeditor/test/browser_styleeditor_bug_870339.js index 2834ae21c5ab..c0407d06d234 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_bug_870339.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_bug_870339.js @@ -22,21 +22,21 @@ const DOCUMENT_WITH_ONE_STYLESHEET = add_task(async function() { const { ui } = await openStyleEditorForURL(DOCUMENT_WITH_ONE_STYLESHEET); - // Spam the _onOrigSourcesPrefChanged callback multiple times before the + // Spam the _onNewDocument callback multiple times before the // StyleEditorActor has a chance to respond to the first one. const SPAM_COUNT = 2; for (let i = 0; i < SPAM_COUNT; ++i) { - ui._onOrigSourcesPrefChanged(); + ui._onNewDocument(); } - // Wait for the StyleEditorActor to respond to each "onOrigSourcesPrefChanged" + // Wait for the StyleEditorActor to respond to each "newDocument" // message. await new Promise(resolve => { let loadCount = 0; - ui.on("stylesheets-refreshed", function onReset() { + ui.on("stylesheets-reset", function onReset() { ++loadCount; if (loadCount == SPAM_COUNT) { - ui.off("stylesheets-refreshed", onReset); + ui.off("stylesheets-reset", onReset); // No matter how large SPAM_COUNT is, the number of style // sheets should never be more than the number of style sheets // in the document. diff --git a/devtools/client/styleeditor/test/browser_styleeditor_fission_switch_target.js b/devtools/client/styleeditor/test/browser_styleeditor_fission_switch_target.js index 73533a23c1dc..ad6d447a8d74 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_fission_switch_target.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_fission_switch_target.js @@ -15,15 +15,18 @@ add_task(async function() { // switch, with or without fission. info("Open a page that runs in the parent process"); - const { ui } = await openStyleEditorForURL(PARENT_PROCESS_URI); + const { toolbox, ui } = await openStyleEditorForURL(PARENT_PROCESS_URI); await waitUntil(() => ui.editors.length === 3); ok(true, `Three style sheets for ${PARENT_PROCESS_URI}`); info("Navigate to a page that runs in the child process"); const onEditorReady = ui.editors[0].getSourceEditor(); - await navigateToAndWaitForStyleSheets(CONTENT_PROCESS_URI, ui, 2); + const onTargetSwitched = toolbox.once("switched-target"); + await navigateToAndWaitForStyleSheets(CONTENT_PROCESS_URI, ui); // We also have to wait for the toolbox to complete the target switching // in order to avoid pending requests during test teardown. + await onTargetSwitched; + await waitUntil(() => ui.editors.length === 2); ok(true, `Two sheets present for ${CONTENT_PROCESS_URI}`); info("Wait until the editor is ready"); diff --git a/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js b/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js index ee9218bf8315..b9aad72fb727 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_inline_friendly_names.js @@ -16,9 +16,9 @@ add_task(async function() { await saveFirstInlineStyleSheet(ui); await testFriendlyNamesAfterSave(ui); - await reloadPageAndWaitForStyleSheets(ui, 2); + await reloadPageAndWaitForStyleSheets(ui); await testFriendlyNamesAfterSave(ui); - await navigateToAndWaitForStyleSheets(SECOND_TEST_PAGE, ui, 2); + await navigateToAndWaitForStyleSheets(SECOND_TEST_PAGE, ui); await testFriendlyNamesAfterNavigation(ui); }); diff --git a/devtools/client/styleeditor/test/browser_styleeditor_navigate.js b/devtools/client/styleeditor/test/browser_styleeditor_navigate.js index 5f867bf45de2..8fe171584e01 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_navigate.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_navigate.js @@ -18,7 +18,7 @@ add_task(async function() { info("Selecting the second editor"); await ui.selectStyleSheet(ui.editors[1].styleSheet, LINE_NO, COL_NO); - await navigateToAndWaitForStyleSheets(NEW_URI, ui, 2); + await navigateToAndWaitForStyleSheets(NEW_URI, ui); info("Waiting for source editor to be ready."); await ui.editors[0].getSourceEditor(); diff --git a/devtools/client/styleeditor/test/browser_styleeditor_reload.js b/devtools/client/styleeditor/test/browser_styleeditor_reload.js index 538a111c8062..19789d75d652 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_reload.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_reload.js @@ -16,27 +16,21 @@ add_task(async function() { info("Selecting the second editor"); await ui.selectStyleSheet(ui.editors[1].styleSheet, LINE_NO, COL_NO); - const selectedStyleSheetIndex = ui.editors[1].styleSheet.styleSheetIndex; - await reloadPageAndWaitForStyleSheets(ui, 2); + await reloadPageAndWaitForStyleSheets(ui); + + is(ui.editors.length, 2, "Two sheets present after reload."); info("Waiting for source editor to be ready."); - const newEditor = findEditor(ui, selectedStyleSheetIndex); - await newEditor.getSourceEditor(); + await ui.editors[1].getSourceEditor(); is( ui.selectedEditor, - newEditor, - "Editor of stylesheet that has styleSheetIndex we selected is selected after reload" + ui.editors[1], + "second editor is selected after reload" ); const { line, ch } = ui.selectedEditor.sourceEditor.getCursor(); is(line, LINE_NO, "correct line selected"); is(ch, COL_NO, "correct column selected"); }); - -function findEditor(ui, styleSheetIndex) { - return ui.editors.find( - editor => editor.styleSheet.styleSheetIndex === styleSheetIndex - ); -} diff --git a/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps.js b/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps.js index 02e4be5e43c6..05b5e647150b 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps.js @@ -127,7 +127,7 @@ function testEditor(editor, possibleNames) { /* Helpers */ function togglePref(UI) { - const editorsPromise = UI.once("stylesheets-refreshed"); + const editorsPromise = UI.once("stylesheets-reset"); const selectedPromise = UI.once("editor-selected"); Services.prefs.setBoolPref(PREF, false); diff --git a/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps_inline.js b/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps_inline.js index d2216c187e8f..546b8e382dff 100644 --- a/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps_inline.js +++ b/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps_inline.js @@ -64,7 +64,7 @@ async function testEditor(editor, expectedName, expectedText) { /* Helpers */ function togglePref(UI) { - const editorsPromise = UI.once("stylesheets-refreshed"); + const editorsPromise = UI.once("stylesheets-reset"); const selectedPromise = UI.once("editor-selected"); Services.prefs.setBoolPref(PREF, false); diff --git a/devtools/client/styleeditor/test/head.js b/devtools/client/styleeditor/test/head.js index ec1abacc319c..1929087b26d7 100644 --- a/devtools/client/styleeditor/test/head.js +++ b/devtools/client/styleeditor/test/head.js @@ -46,22 +46,19 @@ var addTab = function(url, win) { }); }; -var navigateToAndWaitForStyleSheets = async function(url, ui, editorCount) { - const onClear = ui.once("stylesheets-clear"); +var navigateToAndWaitForStyleSheets = async function(url, ui) { + const onReset = ui.once("stylesheets-reset"); await navigateTo(url); - await onClear; - await waitUntil(() => ui.editors.length === editorCount); + await onReset; }; -var reloadPageAndWaitForStyleSheets = async function(ui, editorCount) { +var reloadPageAndWaitForStyleSheets = async function(ui) { info("Reloading the page."); - const onClear = ui.once("stylesheets-clear"); + const onReset = ui.once("stylesheets-reset"); const browser = gBrowser.selectedBrowser; await SpecialPowers.spawn(browser, [], () => content.location.reload()); - await onClear; - - await waitUntil(() => ui.editors.length === editorCount); + await onReset; }; /** diff --git a/devtools/server/actors/stylesheets.js b/devtools/server/actors/stylesheets.js index fc9846c9078e..f570409a4e53 100644 --- a/devtools/server/actors/stylesheets.js +++ b/devtools/server/actors/stylesheets.js @@ -651,17 +651,22 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, { this.parentActor = targetActor; - this._onApplicableStateChanged = this._onApplicableStateChanged.bind(this); this._onNewStyleSheetActor = this._onNewStyleSheetActor.bind(this); + this._onSheetAdded = this._onSheetAdded.bind(this); this._onWindowReady = this._onWindowReady.bind(this); this._transitionSheetLoaded = false; this.parentActor.on("stylesheet-added", this._onNewStyleSheetActor); this.parentActor.on("window-ready", this._onWindowReady); + // We listen for StyleSheetApplicableStateChanged rather than + // StyleSheetAdded, because the latter will be sent before the + // rules are ready. Using the former (with a check to ensure that + // the sheet is enabled) ensures that the sheet is ready before we + // try to make an actor for it. this.parentActor.chromeEventHandler.addEventListener( "StyleSheetApplicableStateChanged", - this._onApplicableStateChanged, + this._onSheetAdded, true ); @@ -683,7 +688,7 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, { this.parentActor.chromeEventHandler.removeEventListener( "StyleSheetApplicableStateChanged", - this._onApplicableStateChanged, + this._onSheetAdded, true ); @@ -740,7 +745,10 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, { // Special case about:PreferenceStyleSheet, as it is generated on the // fly and the URI is not registered with the about: handler. // https://bugzilla.mozilla.org/show_bug.cgi?id=935803#c37 - if (sheet.href?.toLowerCase() === "about:preferencestylesheet") { + if ( + sheet.href && + sheet.href.toLowerCase() == "about:preferencestylesheet" + ) { return false; } @@ -748,32 +756,18 @@ var StyleSheetsActor = protocol.ActorClassWithSpec(styleSheetsSpec, { }, /** - * Event handler that is called when the state of applicable of style sheet is changed. + * Event handler that is called when a new style sheet is added to + * a document. In particular, StyleSheetApplicableStateChanged is + * listened for, because StyleSheetAdded is sent too early, before + * the rules are ready. * - * For now, StyleSheetApplicableStateChanged event will be called at following timings. - * - Append of stylesheet to document - * - Append - - - - - - diff --git a/devtools/shared/resources/tests/style_iframe.css b/devtools/shared/resources/tests/style_iframe.css deleted file mode 100644 index 30e7ae802b5e..000000000000 --- a/devtools/shared/resources/tests/style_iframe.css +++ /dev/null @@ -1 +0,0 @@ -body { padding: 1px; } diff --git a/devtools/shared/resources/tests/style_iframe.html b/devtools/shared/resources/tests/style_iframe.html deleted file mode 100644 index 11ad9f785ba3..000000000000 --- a/devtools/shared/resources/tests/style_iframe.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - Test style iframe document - - - - - - - diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 78c0c440b877..96e84f92dc2d 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -6565,7 +6565,23 @@ void Document::StyleSheetApplicableStateChanged(StyleSheet& aSheet) { } } - PostStyleSheetApplicableStateChangeEvent(aSheet); + if (StyleSheetChangeEventsEnabled()) { + StyleSheetApplicableStateChangeEventInit init; + init.mBubbles = true; + init.mCancelable = true; + init.mStylesheet = &aSheet; + init.mApplicable = applicable; + + RefPtr event = + StyleSheetApplicableStateChangeEvent::Constructor( + this, u"StyleSheetApplicableStateChanged"_ns, init); + event->SetTrusted(true); + event->SetTarget(this); + RefPtr asyncDispatcher = + new AsyncEventDispatcher(this, event); + asyncDispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; + asyncDispatcher->PostDOMEvent(); + } if (!mSSApplicableStateNotificationPending) { MOZ_RELEASE_ASSERT(NS_IsMainThread()); @@ -6577,28 +6593,6 @@ void Document::StyleSheetApplicableStateChanged(StyleSheet& aSheet) { } } -void Document::PostStyleSheetApplicableStateChangeEvent(StyleSheet& aSheet) { - if (!StyleSheetChangeEventsEnabled()) { - return; - } - - StyleSheetApplicableStateChangeEventInit init; - init.mBubbles = true; - init.mCancelable = true; - init.mStylesheet = &aSheet; - init.mApplicable = aSheet.IsApplicable(); - - RefPtr event = - StyleSheetApplicableStateChangeEvent::Constructor( - this, u"StyleSheetApplicableStateChanged"_ns, init); - event->SetTrusted(true); - event->SetTarget(this); - RefPtr asyncDispatcher = - new AsyncEventDispatcher(this, event); - asyncDispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes; - asyncDispatcher->PostDOMEvent(); -} - void Document::NotifyStyleSheetApplicableStateChanged() { mSSApplicableStateNotificationPending = false; nsCOMPtr observerService = diff --git a/dom/base/Document.h b/dom/base/Document.h index 5479a0387f11..3c2b10905a14 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -1679,8 +1679,6 @@ class Document : public nsINode, */ void StyleSheetApplicableStateChanged(StyleSheet&); - void PostStyleSheetApplicableStateChangeEvent(StyleSheet&); - enum additionalSheetType { eAgentSheet, eUserSheet, diff --git a/layout/style/SharedStyleSheetCache.cpp b/layout/style/SharedStyleSheetCache.cpp index 6cfa56cb4b80..82bb19e40a28 100644 --- a/layout/style/SharedStyleSheetCache.cpp +++ b/layout/style/SharedStyleSheetCache.cpp @@ -317,12 +317,6 @@ void SharedStyleSheetCache::LoadCompletedInternal( "should not get a forced unique inner during parsing"); data->mSheet->SetComplete(); data->ScheduleLoadEventIfNeeded(); - } else if (data->mSheet->IsApplicable()) { - if (dom::Document* doc = data->mLoader->GetDocument()) { - // We post these events for devtools, even though the applicable state - // has not actually changed, to make the cache not observable. - doc->PostStyleSheetApplicableStateChangeEvent(*data->mSheet); - } } aDatasToNotify.AppendElement(data);