Bug 1459613 - Show extension name in PermissionUI / webrtcUI doorhangers and menus items. r=johannh

MozReview-Commit-ID: 2NbbsWkxDHm

--HG--
extra : rebase_source : eba0db59a07266a6d3d2f0829dd886d5375b296e
This commit is contained in:
Luca Greco 2018-05-16 19:32:42 +02:00
Родитель be36d3cc96
Коммит a895c895dc
3 изменённых файлов: 65 добавлений и 13 удалений

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

@ -2,7 +2,7 @@
* Make sure that the correct origin is shown for permission prompts.
*/
async function check(contentTask) {
async function check(contentTask, options = {}) {
await BrowserTestUtils.withNewTab("https://test1.example.com/", async function(browser) {
let popupShownPromise = waitForNotificationPanel();
await ContentTask.spawn(browser, null, contentTask);
@ -20,7 +20,7 @@ async function check(contentTask) {
});
channel = channel.QueryInterface(Ci.nsIFileChannel);
return BrowserTestUtils.withNewTab(channel.file.path, async function(browser) {
await BrowserTestUtils.withNewTab(channel.file.path, async function(browser) {
let popupShownPromise = waitForNotificationPanel();
await ContentTask.spawn(browser, null, contentTask);
let panel = await popupShownPromise;
@ -34,6 +34,41 @@ async function check(contentTask) {
ok(body.innerHTML.includes("Unknown origin"), "file:// URIs should be displayed as unknown origin.");
}
});
if (!options.skipOnExtension) {
// Test the scenario also on the extension page if not explicitly unsupported
// (e.g. an extension page can't be navigated on a blob URL).
let extension = ExtensionTestUtils.loadExtension({
manifest: {
name: "Test Extension Name",
},
background() {
let {browser} = this;
browser.test.sendMessage("extension-tab-url",
browser.extension.getURL("extension-tab-page.html"));
},
files: {
"extension-tab-page.html": `<!DOCTYPE html><html><body></body></html>`,
},
});
await extension.startup();
let extensionURI = await extension.awaitMessage("extension-tab-url");
await BrowserTestUtils.withNewTab(extensionURI, async function(browser) {
let popupShownPromise = waitForNotificationPanel();
await ContentTask.spawn(browser, null, contentTask);
let panel = await popupShownPromise;
let notification = panel.children[0];
let body = document.getAnonymousElementByAttribute(notification,
"class",
"popup-notification-body");
ok(body.innerHTML.includes("Test Extension Name"),
"Check the the extension name is present in the markup");
});
await extension.unload();
}
}
add_task(async function setup() {
@ -61,7 +96,7 @@ add_task(async function test_displayURI_geo_blob() {
let blob = new Blob([text], {type: "text/html"});
let url = content.URL.createObjectURL(blob);
content.location.href = url;
});
}, {skipOnExtension: true});
});
add_task(async function test_displayURI_camera_blob() {
@ -70,6 +105,6 @@ add_task(async function test_displayURI_camera_blob() {
let blob = new Blob([text], {type: "text/html"});
let url = content.URL.createObjectURL(blob);
content.location.href = url;
});
}, {skipOnExtension: true});
});

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

@ -108,6 +108,20 @@ var PermissionPromptPrototype = {
throw new Error("Not implemented.");
},
/**
* Provides the preferred name to use in the permission popups,
* based on the principal URI (the URI.hostPort for any URI scheme
* besides the moz-extension one which should default to the
* extension name).
*/
get principalName() {
if (this.principal.addonPolicy) {
return this.principal.addonPolicy.name;
}
return this.principal.URI.hostPort;
},
/**
* If the nsIPermissionManager is being queried and written
* to for this permission request, set this to the key to be
@ -427,7 +441,7 @@ GeolocationPermissionPrompt.prototype = {
let options = {
learnMoreURL: Services.urlFormatter.formatURLPref(pref),
displayURI: false,
name: this.principal.URI.hostPort,
name: this.principalName,
};
if (this.principal.URI.schemeIs("file")) {
@ -535,7 +549,7 @@ DesktopNotificationPermissionPrompt.prototype = {
return {
learnMoreURL,
displayURI: false,
name: this.principal.URI.hostPort,
name: this.principalName,
};
},
@ -617,7 +631,7 @@ PersistentStoragePermissionPrompt.prototype = {
checkbox,
learnMoreURL,
displayURI: false,
name: this.principal.URI.hostPort,
name: this.principalName,
};
},
@ -684,7 +698,7 @@ MIDIPermissionPrompt.prototype = {
// TODO (bug 1433235) We need a security/permissions explanation URL for this
let options = {
displayURI: false,
name: this.principal.URI.hostPort,
name: this.principalName,
};
if (this.principal.URI.schemeIs("file")) {

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

@ -300,14 +300,17 @@ function denyRequest(aBrowser, aRequest) {
windowID: aRequest.windowID});
}
function getHost(uri, href) {
function getHostOrExtensionName(uri, href) {
let host;
try {
if (!uri) {
uri = Services.io.newURI(href);
}
host = uri.host;
let addonPolicy = WebExtensionPolicy.getByURI(uri);
host = addonPolicy ? addonPolicy.name : uri.host;
} catch (ex) {}
if (!host) {
if (uri && uri.scheme.toLowerCase() == "about") {
// For about URIs, just use the full spec, without any #hash parts.
@ -419,7 +422,7 @@ function prompt(aBrowser, aRequest) {
let productName = gBrandBundle.GetStringFromName("brandShortName");
let options = {
name: getHost(uri),
name: getHostOrExtensionName(uri),
persistent: true,
hideClose: !Services.prefs.getBoolPref("privacy.permissionPrompts.showCloseButton"),
eventCallback(aTopic, aNewBrowser) {
@ -1007,7 +1010,7 @@ function onTabSharingMenuPopupShowing(e) {
let doc = e.target.ownerDocument;
let bundle = doc.defaultView.gNavigatorBundle;
let origin = getHost(null, streamInfo.uri);
let origin = getHostOrExtensionName(null, streamInfo.uri);
let menuitem = doc.createElement("menuitem");
menuitem.setAttribute("label", bundle.getFormattedString(stringName, [origin]));
menuitem.stream = streamInfo;