Bug 1842141 - fix page style no style menu checked state after reloads or same-origin navigations, r=mconley

The issue here is that authorStyleDisabledDefault persists on the BrowsingContext.
This means it stays set/unset if the BC navigates same-origin (including
reloads). But the actor was keeping its own copy, on the actor, and the actor
gets destroyed in those circumstances, leading to the frontend and the internal
state no longer being in sync.

This patch addresses this by no longer keeping our own state and just reading
the browsingcontext's field directly.

This is a tiny bit hackish because technically, whether this is the 'default'
is not the same as whether the author style is actually disabled, but in
practice the child actor always sets the two at the same time, and it is
the simpler fix (vs. trying to mirror state to the parent some more).

Differential Revision: https://phabricator.services.mozilla.com/D183188
This commit is contained in:
Gijs Kruitbosch 2023-07-11 22:36:31 +00:00
Родитель f2946ec9ad
Коммит e3c02a0ba0
4 изменённых файлов: 23 добавлений и 11 удалений

Просмотреть файл

@ -133,7 +133,6 @@ export class PageStyleChild extends JSWindowActorChild {
let filteredStyleSheets = this.#collectStyleSheets(window);
this.sendAsyncMessage("PageStyle:Add", {
filteredStyleSheets,
authorStyleDisabled: this.docShell.contentViewer.authorStyleDisabled,
preferredStyleSheetSet: this.document.preferredStyleSheetSet,
});
});

Просмотреть файл

@ -21,10 +21,6 @@ export class PageStyleParent extends JSWindowActorParent {
// The URL of the stylesheet. Stylesheets loaded via a data URL will
// have this property set to null.
//
// authorStyleDisabled (bool):
// Whether or not the user currently has "No Style" selected for
// the current page.
//
// preferredStyleSheetSet (bool):
// Whether or not the user currently has the "Default" style selected
// for the current page.
@ -68,7 +64,6 @@ export class PageStyleParent extends JSWindowActorParent {
if (!this.#styleSheetInfo) {
this.#styleSheetInfo = {
filteredStyleSheets: [],
authorStyleDisabled: false,
preferredStyleSheetSet: true,
};
}

Просмотреть файл

@ -18,7 +18,6 @@ var gPageStyleMenu = {
// rather than throwing exceptions immediately.
styleSheetInfo = {
filteredStyleSheets: [],
authorStyleDisabled: false,
preferredStyleSheetSet: true,
};
}
@ -36,7 +35,8 @@ var gPageStyleMenu = {
let styleSheets = styleSheetInfo.filteredStyleSheets;
var currentStyleSheets = {};
var styleDisabled = styleSheetInfo.authorStyleDisabled;
var styleDisabled =
!!gBrowser.selectedBrowser.browsingContext?.authorStyleDisabledDefault;
var haveAltSheets = false;
var altStyleSelected = false;
@ -110,7 +110,6 @@ var gPageStyleMenu = {
*/
switchStyleSheet(title) {
let sheetData = this._getStyleSheetInfo(gBrowser.selectedBrowser);
sheetData.authorStyleDisabled = false;
for (let sheet of sheetData.filteredStyleSheets) {
sheet.disabled = sheet.title !== title;
}
@ -121,8 +120,6 @@ var gPageStyleMenu = {
* Disable all stylesheets. Called with View > Page Style > No Style.
*/
disableStyle() {
let sheetData = this._getStyleSheetInfo(gBrowser.selectedBrowser);
sheetData.authorStyleDisabled = true;
this._sendMessageToAll("PageStyle:Disable", {});
},
};

Просмотреть файл

@ -75,5 +75,26 @@ add_task(async function test_disable_style() {
"second child color after disabling style"
);
await BrowserTestUtils.reloadTab(tab, true);
// Check the menu:
let { menupopup } = document.getElementById("pageStyleMenu");
gPageStyleMenu.fillPopup(menupopup);
Assert.equal(
menupopup.querySelector("menuitem[checked='true']").dataset.l10nId,
"menu-view-page-style-no-style",
"No style menu should be checked."
);
// check the page content still has a disabled author style:
Assert.ok(
await SpecialPowers.spawn(
tab.linkedBrowser,
[],
() => content.docShell.contentViewer.authorStyleDisabled
),
"Author style should still be disabled."
);
BrowserTestUtils.removeTab(tab);
});