Bug 1790855 - Enable screenshots button on about pages when screenshots component is enabled. r=sfoster

Differential Revision: https://phabricator.services.mozilla.com/D157355
This commit is contained in:
Niklas Baumgardner
2022-10-04 00:03:56 +00:00
parent f95e379091
commit cc57189ab5
3 changed files with 54 additions and 9 deletions

View File

@@ -547,6 +547,34 @@ XPCOMUtils.defineLazyPreferenceGetter(
true
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gScreenshotsDisabled",
"extensions.screenshots.disabled",
false,
() => {
Services.obs.notifyObservers(
window,
"toggle-screenshot-disable",
gScreenshots.shouldScreenshotsButtonBeDisabled()
);
}
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gScreenshotsComponentEnabled",
"screenshots.browser.component.enabled",
false,
() => {
Services.obs.notifyObservers(
window,
"toggle-screenshot-disable",
gScreenshots.shouldScreenshotsButtonBeDisabled()
);
}
);
customElements.setElementCreationCallback("translation-notification", () => {
Services.scriptloader.loadSubScript(
"chrome://browser/content/translation-notification.js",
@@ -679,6 +707,25 @@ var gNavigatorBundle = {
},
};
var gScreenshots = {
shouldScreenshotsButtonBeDisabled(uri) {
// About pages other than about:reader are not currently supported by
// the screenshots extension (see Bug 1620992).
let shouldBeDisabled;
if (uri) {
shouldBeDisabled =
gScreenshotsDisabled ||
(!gScreenshotsComponentEnabled &&
uri.scheme === "about" &&
!uri.spec.startsWith("about:reader"));
} else {
shouldBeDisabled = gScreenshotsDisabled || !gScreenshotsComponentEnabled;
}
return shouldBeDisabled;
},
};
function updateFxaToolbarMenu(enable, isInitialUpdate = false) {
// We only show the Firefox Account toolbar menu if the feature is enabled and
// if sync is enabled.
@@ -5441,14 +5488,13 @@ var XULBrowserWindow = {
closeOpenPanels("panel[locationspecific='true']");
}
// About pages other than about:reader are not currently supported by
// screenshots (see Bug 1620992).
let screenshotsButtonsDisabled = gScreenshots.shouldScreenshotsButtonBeDisabled(
aLocationURI
);
Services.obs.notifyObservers(
window,
"toggle-screenshot-disable",
(aLocationURI.scheme == "about" &&
!aLocationURI.spec.startsWith("about:reader")) ||
Services.prefs.getBoolPref("extensions.screenshots.disabled")
screenshotsButtonsDisabled
);
gPermissionPanel.onLocationChange();

View File

@@ -1280,8 +1280,7 @@ class nsContextMenu {
// screenshots (see Bug 1620992)
let uri = this.contentData?.documentURIObject;
let shouldShow =
!screenshotsDisabled &&
(uri.scheme != "about" || uri.spec.startsWith("about:reader")) &&
!gScreenshots.shouldScreenshotsButtonBeDisabled(uri) &&
this.inTabBrowser &&
!this.onTextInput &&
!this.onLink &&

View File

@@ -19,8 +19,8 @@ add_task(async function testScreenshotButtonDisabled() {
await BrowserTestUtils.withNewTab("about:home", () => {
Assert.equal(
screenshotBtn.disabled,
true,
"Screenshots button is now disabled"
false,
"Screenshots button is still enabled on about pages"
);
});
});