зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1382953: Fix permission prompts in about:addons options browsers. r=aswan
MozReview-Commit-ID: At5F5cqGSWu --HG-- extra : rebase_source : 2bce19447ae0bd4b6cd8f51b16f1e7fabe59d6c8 extra : amend_source : 911e5b1f2d7ee501d08918c6191a79217f0d0b6f
This commit is contained in:
Родитель
7262fc3cf9
Коммит
b5c2235a0f
|
@ -55,15 +55,68 @@ add_task(async function testSources() {
|
|||
});
|
||||
browser.contextMenus.onClicked.addListener(() => request("webNavigation"));
|
||||
|
||||
browser.test.onMessage.addListener(msg => {
|
||||
if (msg === "openOptionsPage") {
|
||||
browser.runtime.openOptionsPage();
|
||||
}
|
||||
});
|
||||
|
||||
browser.test.sendMessage("actions-ready");
|
||||
},
|
||||
|
||||
files: {
|
||||
"options.html": `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<script src="options.js"></script>
|
||||
<script src="https://example.com/tests/SimpleTest/EventUtils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<a id="link" href="#">Link</a>
|
||||
</body>
|
||||
</html>`,
|
||||
|
||||
"options.js"() {
|
||||
addEventListener("load", async () => {
|
||||
let link = document.getElementById("link");
|
||||
link.onclick = async event => {
|
||||
event.preventDefault();
|
||||
|
||||
try {
|
||||
let result = await browser.permissions.request({
|
||||
permissions: ["webRequest"],
|
||||
});
|
||||
browser.test.sendMessage("request", {success: true, result});
|
||||
} catch (err) {
|
||||
browser.test.sendMessage("request", {success: false, errmsg: err.message});
|
||||
}
|
||||
};
|
||||
|
||||
// Make a few trips through the event loop to make sure the
|
||||
// options browser is fully visible. This is a bit dodgy, but
|
||||
// we don't really have a reliable way to detect this from the
|
||||
// options page side, and synthetic click events won't work
|
||||
// until it is.
|
||||
for (let i = 0; i < 10; i++) {
|
||||
await new Promise(resolve => setTimeout(resolve, 0));
|
||||
}
|
||||
|
||||
synthesizeMouseAtCenter(link, {});
|
||||
}, {once: true});
|
||||
},
|
||||
},
|
||||
|
||||
manifest: {
|
||||
browser_action: {default_title: "test"},
|
||||
page_action: {default_title: "test"},
|
||||
permissions: ["contextMenus"],
|
||||
optional_permissions: ["bookmarks", "tabs", "webNavigation"],
|
||||
optional_permissions: ["bookmarks", "tabs", "webNavigation", "webRequest"],
|
||||
options_ui: {page: "options.html"},
|
||||
content_security_policy: "script-src 'self' https://example.com; object-src 'none';",
|
||||
},
|
||||
|
||||
useAddonManager: "temporary",
|
||||
});
|
||||
|
||||
async function check(what) {
|
||||
|
@ -105,10 +158,18 @@ add_task(async function testSources() {
|
|||
EventUtils.synthesizeMouseAtCenter(items[0], {});
|
||||
await check("context menu click");
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
extension.sendMessage("openOptionsPage");
|
||||
promisePopupNotificationShown("addon-webext-permissions").then(panel => {
|
||||
panel.button.click();
|
||||
});
|
||||
await check("options page link click");
|
||||
|
||||
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
||||
await BrowserTestUtils.removeTab(tab);
|
||||
|
||||
await extension.unload();
|
||||
|
||||
registerCleanupFunction(() => CustomizableUI.reset());
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,13 @@ const BRAND_PROPERTIES = "chrome://branding/locale/brand.properties";
|
|||
|
||||
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
|
||||
function getTabBrowser(browser) {
|
||||
while (browser.ownerDocument.docShell.itemType !== Ci.nsIDocShell.typeChrome) {
|
||||
browser = browser.ownerDocument.docShell.chromeEventHandler;
|
||||
}
|
||||
return {browser, window: browser.ownerGlobal};
|
||||
}
|
||||
|
||||
var ExtensionsUI = {
|
||||
sideloaded: new Set(),
|
||||
updates: new Set(),
|
||||
|
@ -166,9 +173,7 @@ var ExtensionsUI = {
|
|||
showAddonsManager(browser, strings, icon, histkey) {
|
||||
let global = browser.selectedBrowser.ownerGlobal;
|
||||
return global.BrowserOpenAddonsMgr("addons://list/extension").then(aomWin => {
|
||||
let aomBrowser = aomWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDocShell)
|
||||
.chromeEventHandler;
|
||||
let aomBrowser = aomWin.document.docShell.chromeEventHandler;
|
||||
return this.showPermissionsPrompt(aomBrowser, strings, icon, histkey);
|
||||
});
|
||||
},
|
||||
|
@ -208,10 +213,12 @@ var ExtensionsUI = {
|
|||
if (topic == "webextension-permission-prompt") {
|
||||
let {target, info} = subject.wrappedJSObject;
|
||||
|
||||
let {browser, window} = getTabBrowser(target);
|
||||
|
||||
// Dismiss the progress notification. Note that this is bad if
|
||||
// there are multiple simultaneous installs happening, see
|
||||
// bug 1329884 for a longer explanation.
|
||||
let progressNotification = target.ownerGlobal.PopupNotifications.getNotification("addon-progress", target);
|
||||
let progressNotification = window.PopupNotifications.getNotification("addon-progress", browser);
|
||||
if (progressNotification) {
|
||||
progressNotification.remove();
|
||||
}
|
||||
|
@ -245,7 +252,7 @@ var ExtensionsUI = {
|
|||
histkey = "installWeb";
|
||||
}
|
||||
|
||||
this.showPermissionsPrompt(target, strings, icon, histkey)
|
||||
this.showPermissionsPrompt(browser, strings, icon, histkey)
|
||||
.then(answer => {
|
||||
if (answer) {
|
||||
info.resolve();
|
||||
|
@ -323,13 +330,13 @@ var ExtensionsUI = {
|
|||
return strings;
|
||||
},
|
||||
|
||||
async showPermissionsPrompt(browser, strings, icon, histkey) {
|
||||
let win = browser.ownerGlobal;
|
||||
async showPermissionsPrompt(target, strings, icon, histkey) {
|
||||
let {browser, window} = getTabBrowser(target);
|
||||
|
||||
// Wait for any pending prompts in this window to complete before
|
||||
// showing the next one.
|
||||
let pending;
|
||||
while ((pending = this.pendingNotifications.get(win))) {
|
||||
while ((pending = this.pendingNotifications.get(window))) {
|
||||
await pending;
|
||||
}
|
||||
|
||||
|
@ -397,17 +404,17 @@ var ExtensionsUI = {
|
|||
},
|
||||
];
|
||||
|
||||
win.PopupNotifications.show(browser, "addon-webext-permissions", strings.header,
|
||||
"addons-notification-icon", action,
|
||||
secondaryActions, popupOptions);
|
||||
window.PopupNotifications.show(browser, "addon-webext-permissions", strings.header,
|
||||
"addons-notification-icon", action,
|
||||
secondaryActions, popupOptions);
|
||||
});
|
||||
|
||||
this.pendingNotifications.set(win, promise);
|
||||
promise.finally(() => this.pendingNotifications.delete(win));
|
||||
this.pendingNotifications.set(window, promise);
|
||||
promise.finally(() => this.pendingNotifications.delete(window));
|
||||
return promise;
|
||||
},
|
||||
|
||||
showDefaultSearchPrompt(browser, strings, icon) {
|
||||
showDefaultSearchPrompt(target, strings, icon) {
|
||||
return new Promise(resolve => {
|
||||
let popupOptions = {
|
||||
hideClose: true,
|
||||
|
@ -440,20 +447,20 @@ var ExtensionsUI = {
|
|||
},
|
||||
];
|
||||
|
||||
let win = browser.ownerGlobal;
|
||||
win.PopupNotifications.show(browser, "addon-webext-defaultsearch", strings.text,
|
||||
"addons-notification-icon", action,
|
||||
secondaryActions, popupOptions);
|
||||
let {browser, window} = getTabBrowser(target);
|
||||
window.PopupNotifications.show(browser, "addon-webext-defaultsearch", strings.text,
|
||||
"addons-notification-icon", action,
|
||||
secondaryActions, popupOptions);
|
||||
});
|
||||
},
|
||||
|
||||
showInstallNotification(target, addon) {
|
||||
let win = target.ownerGlobal;
|
||||
let popups = win.PopupNotifications;
|
||||
let {browser, window} = getTabBrowser(target);
|
||||
let popups = window.PopupNotifications;
|
||||
|
||||
let brandBundle = win.document.getElementById("bundle_brand");
|
||||
let brandBundle = window.document.getElementById("bundle_brand");
|
||||
let appName = brandBundle.getString("brandShortName");
|
||||
let bundle = win.gNavigatorBundle;
|
||||
let bundle = window.gNavigatorBundle;
|
||||
|
||||
let message = bundle.getFormattedString("addonPostInstall.message1",
|
||||
["<>", appName]);
|
||||
|
@ -479,7 +486,7 @@ var ExtensionsUI = {
|
|||
name: addon.name,
|
||||
};
|
||||
|
||||
popups.show(target, "addon-installed", message, "addons-notification-icon",
|
||||
popups.show(browser, "addon-installed", message, "addons-notification-icon",
|
||||
action, null, options);
|
||||
});
|
||||
},
|
||||
|
|
Загрузка…
Ссылка в новой задаче