diff --git a/browser/base/content/test/popupNotifications/browser_displayURI.js b/browser/base/content/test/popupNotifications/browser_displayURI.js index df2bfb54fe25..c27299efb2e7 100644 --- a/browser/base/content/test/popupNotifications/browser_displayURI.js +++ b/browser/base/content/test/popupNotifications/browser_displayURI.js @@ -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": ``, + }, + }); + + 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}); }); diff --git a/browser/modules/PermissionUI.jsm b/browser/modules/PermissionUI.jsm index 9e1aafd67c91..a568df333065 100644 --- a/browser/modules/PermissionUI.jsm +++ b/browser/modules/PermissionUI.jsm @@ -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")) { @@ -460,7 +474,7 @@ GeolocationPermissionPrompt.prototype = { } return gBrowserBundle.formatStringFromName("geolocation.shareWithSite3", - ["<>"], 1); + ["<>"], 1); }, get promptActions() { @@ -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")) { diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index da734e6b56dc..a479beaf3731 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -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;