Bug 1725430: disable screenshot shortcut for extension when screenshots.browser.component.enabled is true. r=emalysz,fluent-reviewers,flod

Differential Revision: https://phabricator.services.mozilla.com/D125850
This commit is contained in:
Emma Malysz 2021-09-27 17:30:35 +00:00
Родитель ab2a664e8c
Коммит 53a01f5fb9
13 изменённых файлов: 52 добавлений и 43 удалений

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

@ -91,6 +91,8 @@
<command id="Tools:Sanitize" oncommand="Sanitizer.showUI(window);"/>
<command id="Tools:PrivateBrowsing"
oncommand="OpenBrowserWindow({private: true});"/>
<command id="Browser:Screenshot" oncommand="ScreenshotsUtils.notify(window, 'shortcut')"/>
#ifdef NIGHTLY_BUILD
<command id="Tools:FissionWindow"
oncommand="OpenBrowserWindow({fission: true, private: !!window?.browsingContext?.usePrivateBrowsing});"
@ -303,6 +305,7 @@
<key id="key_privatebrowsing" command="Tools:PrivateBrowsing" data-l10n-id="private-browsing-shortcut"
modifiers="accel,shift" reserved="true"/>
<key id="key_screenshot" data-l10n-id="screenshot-shortcut" command="Browser:Screenshot" modifiers="accel,shift"/>
<key id="key_sanitize" command="Tools:Sanitize" keycode="VK_DELETE" modifiers="accel,shift"/>
#ifdef XP_MACOSX
<key id="key_sanitize_mac" command="Tools:Sanitize" keycode="VK_BACK" modifiers="accel,shift"/>

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

@ -69,6 +69,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
SafeBrowsing: "resource://gre/modules/SafeBrowsing.jsm",
Sanitizer: "resource:///modules/Sanitizer.jsm",
SaveToPocket: "chrome://pocket/content/SaveToPocket.jsm",
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.jsm",
SessionStartup: "resource:///modules/sessionstore/SessionStartup.jsm",
SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
ShortcutUtils: "resource://gre/modules/ShortcutUtils.jsm",

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

@ -76,6 +76,7 @@
<link rel="localization" href="browser/tabbrowser.ftl"/>
<link rel="localization" href="preview/firefoxSuggest.ftl"/>
<link rel="localization" href="browser/toolbarContextMenu.ftl"/>
<link rel="localization" href="browser/screenshots.ftl"/>
<title data-l10n-id="browser-main-window-title"></title>

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

@ -16,6 +16,7 @@
<html:link rel="localization" href="toolkit/global/textActions.ftl"/>
<html:link rel="localization" href="browser/browserSets.ftl"/>
<html:link rel="localization" href="browser/menubar.ftl"/>
<html:link rel="localization" href="browser/screenshots.ftl"/>
</linkset>
# All JS files which are needed by browser.xhtml and other top level windows to

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

@ -1301,7 +1301,11 @@ class nsContextMenu {
if (SCREENSHOT_BROWSER_COMPONENT) {
Services.obs.notifyObservers(window, "menuitem-screenshot", true);
} else {
Services.obs.notifyObservers(null, "menuitem-screenshot-extension", true);
Services.obs.notifyObservers(
null,
"menuitem-screenshot-extension",
"contextMenu"
);
}
}

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

@ -525,6 +525,7 @@ if (Services.prefs.getBoolPref("identity.fxaccounts.enabled")) {
if (!screenshotsDisabled) {
CustomizableWidgets.push({
id: "screenshot-button",
shortcutId: "key_screenshot",
l10nId: "screenshot-toolbarbutton",
onCommand(aEvent) {
if (SCREENSHOT_BROWSER_COMPONENT) {
@ -533,7 +534,11 @@ if (!screenshotsDisabled) {
"menuitem-screenshot"
);
} else {
Services.obs.notifyObservers(null, "menuitem-screenshot-extension");
Services.obs.notifyObservers(
null,
"menuitem-screenshot-extension",
"toolbar"
);
}
},
onCreated(aNode) {

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

@ -26,4 +26,18 @@ var ScreenshotsUtils = {
{ features: "resizable=no", sizeTo: "available" }
);
},
notify(window, type) {
if (window.document.getElementById("screenshot-button").disabled) {
return;
}
if (Services.prefs.getBoolPref("screenshots.browser.component.enabled")) {
Services.obs.notifyObservers(
window.event.currentTarget.ownerGlobal,
"menuitem-screenshot"
);
} else {
Services.obs.notifyObservers(null, "menuitem-screenshot-extension", type);
}
},
};

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

@ -74,7 +74,7 @@ this.main = (function() {
_startShotFlow(tab, "context-menu");
});
exports.onCommand = catcher.watchFunction(tab => {
exports.onShortcut = catcher.watchFunction(tab => {
_startShotFlow(tab, "keyboard-shortcut");
});

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

@ -64,47 +64,26 @@ this.startBackground = (function() {
];
browser.experiments.screenshots.onScreenshotCommand.addListener(
async isContextMenuClick => {
async type => {
try {
let [[tab]] = await Promise.all([
browser.tabs.query({ currentWindow: true, active: true }),
loadIfNecessary(),
]);
zoomFactor = await browser.tabs.getZoom(tab.id);
isContextMenuClick
? main.onClickedContextMenu(tab)
: main.onClicked(tab);
if (type === "contextMenu") {
main.onClickedContextMenu(tab);
} else if (type === "toolbar") {
main.onClicked(tab);
} else if (type === "shortcut") {
main.onShortcut(tab);
}
} catch (error) {
console.error("Error loading Screenshots:", error);
}
}
);
browser.commands.onCommand.addListener(cmd => {
if (cmd !== "take-screenshot") {
return;
}
loadIfNecessary()
.then(() => {
browser.tabs
.query({ currentWindow: true, active: true })
.then(async tabs => {
const activeTab = tabs[0];
zoomFactor = await browser.tabs.getZoom(activeTab.id);
main.onCommand(activeTab);
})
.catch(error => {
throw error;
});
})
.catch(error => {
console.error(
"Error toggling Screenshots via keyboard shortcut: ",
error
);
});
});
browser.runtime.onMessage.addListener((req, sender, sendResponse) => {
loadIfNecessary()
.then(() => {

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

@ -47,8 +47,8 @@ this.screenshots = class extends ExtensionAPI {
name: "experiments.screenshots.onScreenshotCommand",
register: fire => {
let observer = (subject, topic, data) => {
let isContexMenuClick = data;
fire.sync(isContexMenuClick);
let type = data;
fire.sync(type);
};
Services.obs.addObserver(observer, TOPIC);
return () => {

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

@ -18,14 +18,6 @@
"background/startBackground.js"
]
},
"commands": {
"take-screenshot": {
"suggested_key": {
"default": "Ctrl+Shift+S"
},
"description": "Open the Firefox Screenshots UI"
}
},
"content_scripts": [
{
"matches": ["https://screenshots.firefox.com/*"],

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

@ -65,7 +65,13 @@ add_task(async function test_inject_srcdoc() {
});
// Now try to start the screenshot flow:
document.querySelector("keyset[id*=screenshot] > key").doCommand();
CustomizableUI.addWidgetToArea(
"screenshot-button",
CustomizableUI.AREA_NAVBAR
);
let screenshotBtn = document.getElementById("screenshot-button");
screenshotBtn.click();
await Promise.race([errorPromise, responsePromise]);
ok(error, "Should get the relevant error: " + error?.message);
ok(!response, "Should not get a response from the webpage.");

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

@ -6,6 +6,9 @@ screenshot-toolbarbutton =
.label = Screenshot
.tooltiptext = Take a screenshot
screenshot-shortcut =
.key = S
screenshots-instructions = Drag or click on the page to select a region. Press ESC to cancel.
screenshots-cancel-button = Cancel
screenshots-save-visible-button = Save visible