From 4397423937395f659d05321df00777fb49f1a474 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Fri, 24 Jul 2015 14:28:17 +0200 Subject: [PATCH] Bug 1156472 - Part 9 - Implement the minimum frontend to play with the feature. r=gijs,florian --- .../locales/en-US/chrome/browser/browser.dtd | 1 + .../en-US/chrome/browser/browser.properties | 23 ++++++++- browser/modules/ContentWebRTC.jsm | 14 ++++-- browser/modules/webrtcUI.jsm | 50 +++++++++++-------- 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/browser/locales/en-US/chrome/browser/browser.dtd b/browser/locales/en-US/chrome/browser/browser.dtd index 89981e6936c4..fe7439e0a445 100644 --- a/browser/locales/en-US/chrome/browser/browser.dtd +++ b/browser/locales/en-US/chrome/browser/browser.dtd @@ -758,6 +758,7 @@ you can use these alternative items. Otherwise, their values should be empty. - + diff --git a/browser/locales/en-US/chrome/browser/browser.properties b/browser/locales/en-US/chrome/browser/browser.properties index 766446fac755..1a71d59b1b09 100644 --- a/browser/locales/en-US/chrome/browser/browser.properties +++ b/browser/locales/en-US/chrome/browser/browser.properties @@ -553,13 +553,17 @@ identity.loggedIn.signOut.accessKey = O # LOCALIZATION NOTE (getUserMedia.shareCamera.message, getUserMedia.shareMicrophone.message, # getUserMedia.shareScreen.message, getUserMedia.shareCameraAndMicrophone.message, -# getUserMedia.shareScreenAndMicrophone.message): +# getUserMedia.shareScreenAndMicrophone.message, getUserMedia.shareCameraAndAudioCapture.message, +# getUserMedia.shareAudioCapture.message, getUserMedia.shareScreenAndAudioCapture.message): # %S is the website origin (e.g. www.mozilla.org) getUserMedia.shareCamera.message = Would you like to share your camera with %S? getUserMedia.shareMicrophone.message = Would you like to share your microphone with %S? getUserMedia.shareScreen.message = Would you like to share your screen with %S? getUserMedia.shareCameraAndMicrophone.message = Would you like to share your camera and microphone with %S? +getUserMedia.shareCameraAndAudioCapture.message = Would you like to share your camera and this tab's audio with %S? getUserMedia.shareScreenAndMicrophone.message = Would you like to share your microphone and screen with %S? +getUserMedia.shareScreenAndAudioCapture.message = Would you like to share this tab's audio and your screen with %S? +getUserMedia.shareAudioCapture.message = Would you like to share this tab's audio with %S? getUserMedia.selectWindow.label=Window to share: getUserMedia.selectWindow.accesskey=W getUserMedia.selectScreen.label=Screen to share: @@ -601,6 +605,7 @@ getUserMedia.sharingApplication.message = You are currently sharing an applicati getUserMedia.sharingScreen.message = You are currently sharing your screen with this page. getUserMedia.sharingWindow.message = You are currently sharing a window with this page. getUserMedia.sharingBrowser.message = You are currently sharing a tab with this page. +getUserMedia.sharingAudioCapture.message = You are currently sharing a tab's audio with this page. getUserMedia.continueSharing.label = Continue Sharing getUserMedia.continueSharing.accesskey = C getUserMedia.stopSharing.label = Stop Sharing @@ -610,6 +615,7 @@ getUserMedia.sharingMenu.label = Tabs sharing devices getUserMedia.sharingMenu.accesskey = d # LOCALIZATION NOTE (getUserMedia.sharingMenuCamera # getUserMedia.sharingMenuMicrophone, +# getUserMedia.sharingMenuAudioCapture, # getUserMedia.sharingMenuApplication, # getUserMedia.sharingMenuScreen, # getUserMedia.sharingMenuWindow, @@ -619,6 +625,11 @@ getUserMedia.sharingMenu.accesskey = d # getUserMedia.sharingMenuCameraMicrophoneScreen, # getUserMedia.sharingMenuCameraMicrophoneWindow, # getUserMedia.sharingMenuCameraMicrophoneBrowser, +# getUserMedia.sharingMenuCameraAudioCapture, +# getUserMedia.sharingMenuCameraAudioCaptureApplication, +# getUserMedia.sharingMenuCameraAudioCaptureScreen, +# getUserMedia.sharingMenuCameraAudioCaptureWindow, +# getUserMedia.sharingMenuCameraAudioCaptureBrowser, # getUserMedia.sharingMenuCameraApplication, # getUserMedia.sharingMenuCameraScreen, # getUserMedia.sharingMenuCameraWindow, @@ -630,6 +641,7 @@ getUserMedia.sharingMenu.accesskey = d # %S is the website origin (e.g. www.mozilla.org) getUserMedia.sharingMenuCamera = %S (camera) getUserMedia.sharingMenuMicrophone = %S (microphone) +getUserMedia.sharingMenuAudioCapture = %S (tab audio) getUserMedia.sharingMenuApplication = %S (application) getUserMedia.sharingMenuScreen = %S (screen) getUserMedia.sharingMenuWindow = %S (window) @@ -639,6 +651,11 @@ getUserMedia.sharingMenuCameraMicrophoneApplication = %S (camera, microphone and getUserMedia.sharingMenuCameraMicrophoneScreen = %S (camera, microphone and screen) getUserMedia.sharingMenuCameraMicrophoneWindow = %S (camera, microphone and window) getUserMedia.sharingMenuCameraMicrophoneBrowser = %S (camera, microphone and tab) +getUserMedia.sharingMenuCameraAudioCapture = %S (camera and tab audio) +getUserMedia.sharingMenuCameraAudioCaptureApplication = %S (camera, tab audio and application) +getUserMedia.sharingMenuCameraAudioCaptureScreen = %S (camera, tab audio and screen) +getUserMedia.sharingMenuCameraAudioCaptureWindow = %S (camera, tab audio and window) +getUserMedia.sharingMenuCameraAudioCaptureBrowser = %S (camera, tab audio and tab) getUserMedia.sharingMenuCameraApplication = %S (camera and application) getUserMedia.sharingMenuCameraScreen = %S (camera and screen) getUserMedia.sharingMenuCameraWindow = %S (camera and window) @@ -647,6 +664,10 @@ getUserMedia.sharingMenuMicrophoneApplication = %S (microphone and application) getUserMedia.sharingMenuMicrophoneScreen = %S (microphone and screen) getUserMedia.sharingMenuMicrophoneWindow = %S (microphone and window) getUserMedia.sharingMenuMicrophoneBrowser = %S (microphone and tab) +getUserMedia.sharingMenuMicrophoneApplication = %S (tab audio and application) +getUserMedia.sharingMenuMicrophoneScreen = %S (tab audio and screen) +getUserMedia.sharingMenuMicrophoneWindow = %S (tab audio and window) +getUserMedia.sharingMenuMicrophoneBrowser = %S (tab audio and tab) # LOCALIZATION NOTE(getUserMedia.sharingMenuUnknownHost): this is used for the website # origin for the sharing menu if no readable origin could be deduced from the URL. getUserMedia.sharingMenuUnknownHost = Unknown origin diff --git a/browser/modules/ContentWebRTC.jsm b/browser/modules/ContentWebRTC.jsm index 5f0514170d6b..e059c60d3d2f 100644 --- a/browser/modules/ContentWebRTC.jsm +++ b/browser/modules/ContentWebRTC.jsm @@ -86,14 +86,21 @@ function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSec // MediaStreamConstraints defines video as 'boolean or MediaTrackConstraints'. let video = aConstraints.video || aConstraints.picture; + let audio = aConstraints.audio; let sharingScreen = video && typeof(video) != "boolean" && video.mediaSource != "camera"; + let sharingAudio = audio && typeof(audio) != "boolean" && + audio.mediaSource != "microphone"; for (let device of aDevices) { device = device.QueryInterface(Ci.nsIMediaDevice); switch (device.type) { case "audio": - if (aConstraints.audio) { - audioDevices.push({name: device.name, deviceIndex: devices.length}); + // Check that if we got a microphone, we have not requested an audio + // capture, and if we have requested an audio capture, we are not + // getting a microphone instead. + if (audio && (device.mediaSource == "microphone") != sharingAudio) { + audioDevices.push({name: device.name, deviceIndex: devices.length, + mediaSource: device.mediaSource}); devices.push(device); } break; @@ -113,7 +120,7 @@ function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSec if (videoDevices.length) requestTypes.push(sharingScreen ? "Screen" : "Camera"); if (audioDevices.length) - requestTypes.push("Microphone"); + requestTypes.push(sharingAudio ? "AudioCapture" : "Microphone"); if (!requestTypes.length) { denyRequest({callID: aCallID}, "NotFoundError"); @@ -133,6 +140,7 @@ function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSec secure: aSecure, requestTypes: requestTypes, sharingScreen: sharingScreen, + sharingAudio: sharingAudio, audioDevices: audioDevices, videoDevices: videoDevices }; diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index be52cb8350f8..792c58bf1dcd 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -188,7 +188,8 @@ function getHost(uri, href) { function prompt(aBrowser, aRequest) { let {audioDevices: audioDevices, videoDevices: videoDevices, - sharingScreen: sharingScreen, requestTypes: requestTypes} = aRequest; + sharingScreen: sharingScreen, sharingAudio: sharingAudio, + requestTypes: requestTypes} = aRequest; let uri = Services.io.newURI(aRequest.documentURI, null, null); let host = getHost(uri); let chromeDoc = aBrowser.ownerDocument; @@ -198,10 +199,9 @@ function prompt(aBrowser, aRequest) { let message = stringBundle.getFormattedString(stringId, [host]); let mainLabel; - if (sharingScreen) { + if (sharingScreen || sharingAudio) { mainLabel = stringBundle.getString("getUserMedia.shareSelectedItems.label"); - } - else { + } else { let string = stringBundle.getString("getUserMedia.shareSelectedDevices.label"); mainLabel = PluralForm.get(requestTypes.length, string); } @@ -225,8 +225,8 @@ function prompt(aBrowser, aRequest) { } } ]; - - if (!sharingScreen) { // Bug 1037438: implement 'never' for screen sharing. + // Bug 1037438: implement 'never' for screen sharing. + if (!sharingScreen && !sharingAudio) { secondaryActions.push({ label: stringBundle.getString("getUserMedia.never.label"), accessKey: stringBundle.getString("getUserMedia.never.accesskey"), @@ -243,10 +243,10 @@ function prompt(aBrowser, aRequest) { }); } - if (aRequest.secure && !sharingScreen) { + if (aRequest.secure && !sharingScreen && !sharingAudio) { // Don't show the 'Always' action if the connection isn't secure, or for - // screen sharing (because we can't guess which window the user wants to - // share without prompting). + // screen/audio sharing (because we can't guess which window the user wants + // to share without prompting). secondaryActions.unshift({ label: stringBundle.getString("getUserMedia.always.label"), accessKey: stringBundle.getString("getUserMedia.always.accesskey"), @@ -266,7 +266,8 @@ function prompt(aBrowser, aRequest) { if (aTopic == "shown") { let PopupNotifications = chromeDoc.defaultView.PopupNotifications; let popupId = "Devices"; - if (requestTypes.length == 1 && requestTypes[0] == "Microphone") + if (requestTypes.length == 1 && (requestTypes[0] == "Microphone" || + requestTypes[0] == "AudioCapture")) popupId = "Microphone"; if (requestTypes.indexOf("Screen") != -1) popupId = "Screen"; @@ -384,7 +385,7 @@ function prompt(aBrowser, aRequest) { chromeDoc.getElementById("webRTC-selectCamera").hidden = !videoDevices.length || sharingScreen; chromeDoc.getElementById("webRTC-selectWindowOrScreen").hidden = !sharingScreen || !videoDevices.length; - chromeDoc.getElementById("webRTC-selectMicrophone").hidden = !audioDevices.length; + chromeDoc.getElementById("webRTC-selectMicrophone").hidden = !audioDevices.length || sharingAudio; let camMenupopup = chromeDoc.getElementById("webRTC-selectCamera-menupopup"); let windowMenupopup = chromeDoc.getElementById("webRTC-selectWindow-menupopup"); @@ -393,12 +394,16 @@ function prompt(aBrowser, aRequest) { listScreenShareDevices(windowMenupopup, videoDevices); else listDevices(camMenupopup, videoDevices); - listDevices(micMenupopup, audioDevices); + + if (!sharingAudio) + listDevices(micMenupopup, audioDevices); + if (requestTypes.length == 2) { let stringBundle = chromeDoc.defaultView.gNavigatorBundle; if (!sharingScreen) addDeviceToList(camMenupopup, stringBundle.getString("getUserMedia.noVideo.label"), "-1"); - addDeviceToList(micMenupopup, stringBundle.getString("getUserMedia.noAudio.label"), "-1"); + if (!sharingAudio) + addDeviceToList(micMenupopup, stringBundle.getString("getUserMedia.noAudio.label"), "-1"); } this.mainAction.callback = function(aRemember) { @@ -416,13 +421,18 @@ function prompt(aBrowser, aRequest) { } } if (audioDevices.length) { - let audioDeviceIndex = chromeDoc.getElementById("webRTC-selectMicrophone-menulist").value; - let allowMic = audioDeviceIndex != "-1"; - if (allowMic) - allowedDevices.push(audioDeviceIndex); - if (aRemember) { - perms.add(uri, "microphone", - allowMic ? perms.ALLOW_ACTION : perms.DENY_ACTION); + if (!sharingAudio) { + let audioDeviceIndex = chromeDoc.getElementById("webRTC-selectMicrophone-menulist").value; + let allowMic = audioDeviceIndex != "-1"; + if (allowMic) + allowedDevices.push(audioDeviceIndex); + if (aRemember) { + perms.add(uri, "microphone", + allowMic ? perms.ALLOW_ACTION : perms.DENY_ACTION); + } + } else { + // Only one device possible for audio capture. + allowedDevices.push(0); } }