diff --git a/browser/base/content/test/general/browser_devices_get_user_media.js b/browser/base/content/test/general/browser_devices_get_user_media.js index 051a887acf8c..966be0a86dde 100644 --- a/browser/base/content/test/general/browser_devices_get_user_media.js +++ b/browser/base/content/test/general/browser_devices_get_user_media.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + const kObservedTopics = [ "getUserMedia:response:allow", "getUserMedia:revoke", @@ -736,6 +740,50 @@ let gTests = [ info("request video, stop sharing resets video only"); yield stopAndCheckPerm(false, true); } +}, + +{ + desc: "'Always Allow' ignored and not shown on http pages", + run: function checkNoAlwaysOnHttp() { + // Load an http page instead of the https version. + let deferred = Promise.defer(); + let browser = gBrowser.selectedTab.linkedBrowser; + browser.addEventListener("load", function onload() { + browser.removeEventListener("load", onload, true); + deferred.resolve(); + }, true); + content.location = content.location.href.replace("https://", "http://"); + yield deferred.promise; + + // Initially set both permissions to 'allow'. + let Perms = Services.perms; + let uri = content.document.documentURIObject; + Perms.add(uri, "microphone", Perms.ALLOW_ACTION); + Perms.add(uri, "camera", Perms.ALLOW_ACTION); + + // Request devices and expect a prompt despite the saved 'Allow' permission, + // because the connection isn't secure. + yield promisePopupNotificationShown("webRTC-shareDevices", () => { + content.wrappedJSObject.requestDevice(true, true); + }); + expectObserverCalled("getUserMedia:request"); + + // Ensure that the 'Always Allow' action isn't shown. + let alwaysLabel = gNavigatorBundle.getString("getUserMedia.always.label"); + ok(!!alwaysLabel, "found the 'Always Allow' localized label"); + let labels = []; + let notification = PopupNotifications.panel.firstChild; + for (let node of notification.childNodes) { + if (node.localName == "menuitem") + labels.push(node.getAttribute("label")); + } + is(labels.indexOf(alwaysLabel), -1, "The 'Always Allow' item isn't shown"); + + // Cleanup. + yield closeStream(true); + Perms.remove(uri.host, "camera"); + Perms.remove(uri.host, "microphone"); + } } ]; diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index 4ef39eadd6b8..96ef492d22c9 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -140,14 +140,6 @@ function prompt(aContentWindow, aCallID, aAudioRequested, aVideoRequested, aDevi }; let secondaryActions = [ - { - label: stringBundle.getString("getUserMedia.always.label"), - accessKey: stringBundle.getString("getUserMedia.always.accesskey"), - callback: function () { - // don't save unless secure load! - mainAction.callback(aSecure); - } - }, { label: stringBundle.getString("getUserMedia.denyRequest.label"), accessKey: stringBundle.getString("getUserMedia.denyRequest.accesskey"), @@ -160,8 +152,8 @@ function prompt(aContentWindow, aCallID, aAudioRequested, aVideoRequested, aDevi accessKey: stringBundle.getString("getUserMedia.never.accesskey"), callback: function () { denyRequest(aCallID); - // Let someone save "Never" for http sites so that they can be stopped from - // bothering you with doorhangers + // Let someone save "Never" for http sites so that they can be stopped from + // bothering you with doorhangers. let perms = Services.perms; if (audioDevices.length) perms.add(uri, "microphone", perms.DENY_ACTION); @@ -171,6 +163,17 @@ function prompt(aContentWindow, aCallID, aAudioRequested, aVideoRequested, aDevi } ]; + if (aSecure) { + // Don't show the 'Always' action if the connection isn't secure. + secondaryActions.unshift({ + label: stringBundle.getString("getUserMedia.always.label"), + accessKey: stringBundle.getString("getUserMedia.always.accesskey"), + callback: function () { + mainAction.callback(true); + } + }); + } + let options = { eventCallback: function(aTopic, aNewBrowser) { if (aTopic == "swapping")