From 787584c554a676630c32f65a1c078827c248f20d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Qu=C3=A8ze?= Date: Fri, 11 Sep 2015 14:18:15 +0200 Subject: [PATCH] Bug 1201973 - 'Stop Sharing' should also revoke persistent permissions granted to frames, r=Gijs. --- ...browser_devices_get_user_media_in_frame.js | 15 ++++++- browser/modules/webrtcUI.jsm | 41 ++++++++++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/browser/base/content/test/general/browser_devices_get_user_media_in_frame.js b/browser/base/content/test/general/browser_devices_get_user_media_in_frame.js index def150e26a5e..fca7a23e6a77 100644 --- a/browser/base/content/test/general/browser_devices_get_user_media_in_frame.js +++ b/browser/base/content/test/general/browser_devices_get_user_media_in_frame.js @@ -269,7 +269,7 @@ let gTests = [ let indicator = promiseIndicatorWindow(); yield promiseMessage("ok", () => { - PopupNotifications.panel.firstChild.button.click(); + activateSecondaryAction(kActionAlways); }); expectObserverCalled("getUserMedia:response:allow"); expectObserverCalled("recording-device-events"); @@ -279,6 +279,13 @@ let gTests = [ yield indicator; yield checkSharingUI({video: true, audio: true}); + let Perms = Services.perms; + let uri = Services.io.newURI("https://example.com/", null, null); + is(Perms.testExactPermission(uri, "microphone"), Perms.ALLOW_ACTION, + "microphone persistently allowed"); + is(Perms.testExactPermission(uri, "camera"), Perms.ALLOW_ACTION, + "camera persistently allowed"); + yield promiseNotificationShown(PopupNotifications.getNotification("webRTC-sharingDevices")); activateSecondaryAction(kActionDeny); @@ -296,6 +303,12 @@ let gTests = [ expectNoObserverCalled(); yield checkNotSharing(); + // The persistent permissions for the frame should have been removed. + is(Perms.testExactPermission(uri, "microphone"), Perms.UNKNOWN_ACTION, + "microphone not persistently allowed"); + is(Perms.testExactPermission(uri, "camera"), Perms.UNKNOWN_ACTION, + "camera not persistently allowed"); + // the stream is already closed, but this will do some cleanup anyway yield closeStream(global, true); } diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index 7132febae3fd..f4cb9dacbae6 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -393,7 +393,16 @@ function prompt(aBrowser, aRequest) { allowedDevices.push(videoDevices[0].deviceIndex); if (audioDevices.length && micPerm == perms.ALLOW_ACTION) allowedDevices.push(audioDevices[0].deviceIndex); - let mm = this.browser.messageManager; + + // Remember on which URIs we found persistent permissions so that we + // can remove them if the user clicks 'Stop Sharing'. There's no + // other way for the stop sharing code to know the hostnames of frames + // using devices until bug 1066082 is fixed. + let browser = this.browser; + browser._devicePermissionURIs = browser._devicePermissionURIs || []; + browser._devicePermissionURIs.push(uri); + + let mm = browser.messageManager; mm.sendAsyncMessage("webrtc:Allow", {callID: aRequest.callID, windowID: aRequest.windowID, devices: allowedDevices}); @@ -534,6 +543,13 @@ function prompt(aBrowser, aRequest) { return; } + if (aRemember) { + // Remember on which URIs we set persistent permissions so that we + // can remove them if the user clicks 'Stop Sharing'. + aBrowser._devicePermissionURIs = aBrowser._devicePermissionURIs || []; + aBrowser._devicePermissionURIs.push(uri); + } + let mm = notification.browser.messageManager; mm.sendAsyncMessage("webrtc:Allow", {callID: aRequest.callID, windowID: aRequest.windowID, @@ -862,15 +878,17 @@ function updateBrowserSpecificIndicator(aBrowser, aState) { label: stringBundle.getString("getUserMedia.stopSharing.label"), accessKey: stringBundle.getString("getUserMedia.stopSharing.accesskey"), callback: function () { - let uri = Services.io.newURI(aState.documentURI, null, null); + let uris = aBrowser._devicePermissionURIs || []; + uris = uris.concat(Services.io.newURI(aState.documentURI, null, null)); let perms = Services.perms; - if (aState.camera && - perms.testExactPermission(uri, "camera") == perms.ALLOW_ACTION) - perms.remove(uri, "camera"); - if (aState.microphone && - perms.testExactPermission(uri, "microphone") == perms.ALLOW_ACTION) - perms.remove(uri, "microphone"); - + for (let uri of uris) { + if (aState.camera && + perms.testExactPermission(uri, "camera") == perms.ALLOW_ACTION) + perms.remove(uri, "camera"); + if (aState.microphone && + perms.testExactPermission(uri, "microphone") == perms.ALLOW_ACTION) + perms.remove(uri, "microphone"); + } let mm = notification.browser.messageManager; mm.sendAsyncMessage("webrtc:StopSharing", windowId); } @@ -902,12 +920,13 @@ function updateBrowserSpecificIndicator(aBrowser, aState) { anchorId, mainAction, secondaryActions, options); } else { - removeBrowserNotification(aBrowser,"webRTC-sharingDevices"); + removeBrowserNotification(aBrowser, "webRTC-sharingDevices"); + aBrowser._devicePermissionURIs = null; } // Now handle the screen sharing indicator. if (!aState.screen) { - removeBrowserNotification(aBrowser,"webRTC-sharingScreen"); + removeBrowserNotification(aBrowser, "webRTC-sharingScreen"); return; }