Bug 729522: Implement navigator.getUserMedia() permission UI; r=dolske,ui-r=boriss

This commit is contained in:
Dão Gottwald 2012-10-05 02:37:00 -07:00
parent bf2365d9ed
commit 8b30ebb1cd
16 changed files with 219 additions and 44 deletions

View File

@ -44,6 +44,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "BrowserNewTabPreloader",
XPCOMUtils.defineLazyModuleGetter(this, "PdfJs",
"resource://pdf.js/PdfJs.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "webrtcUI",
"resource:///modules/webrtcUI.jsm");
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
@ -320,6 +323,7 @@ BrowserGlue.prototype = {
UserAgentOverrides.uninit();
webappsUI.uninit();
SignInToWebsiteUX.uninit();
webrtcUI.uninit();
},
_onAppDefaults: function BG__onAppDefaults() {
@ -351,6 +355,7 @@ BrowserGlue.prototype = {
BrowserNewTabPreloader.init();
SignInToWebsiteUX.init();
PdfJs.init();
webrtcUI.init();
Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
},

View File

@ -423,3 +423,17 @@ identity.next.accessKey = n
identity.loggedIn.description = Signed in as: %S
identity.loggedIn.signOut.label = Sign Out
identity.loggedIn.signOut.accessKey = O
# LOCALIZATION NOTE (getUserMedia.shareCamera.message, getUserMedia.shareMicrophone.message, getUserMedia.shareCameraAndMicrophone.message): %S is the website origin (e.g. www.mozilla.org)
# LOCALIZATION NOTE (getUserMedia.shareMicrophone.message, getUserMedia.shareSpecificMicrophone.label): %S is the website origin (e.g. www.mozilla.org)
getUserMedia.shareCamera.message = Would you like to share your camera with %S?
getUserMedia.shareCamera.label = Share Camera
getUserMedia.shareCamera.accesskey = S
getUserMedia.shareSpecificCamera.label = Share Camera: %S
getUserMedia.shareMicrophone.message = Would you like to share your microphone with %S?
getUserMedia.shareMicrophone.label = Share Microphone
getUserMedia.shareMicrophone.accesskey = S
getUserMedia.shareSpecificMicrophone.label = Share Microphone: %S
getUserMedia.shareCameraAndMicrophone.message = Would you like to share your camera and microphone with %S?
getUserMedia.shareCameraAndMicrophone.label = Share Camera and Microphone
getUserMedia.shareCameraAndMicrophone.accesskey = S

View File

@ -24,6 +24,7 @@ EXTRA_JS_MODULES = \
TelemetryTimestamps.jsm \
Social.jsm \
webappsUI.jsm \
webrtcUI.jsm \
$(NULL)
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)

View File

@ -0,0 +1,123 @@
/* 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/. */
"use strict";
let EXPORTED_SYMBOLS = ["webrtcUI"];
const Cu = Components.utils;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
let webrtcUI = {
init: function () {
Services.obs.addObserver(handleRequest, "getUserMedia:request", false);
},
uninit: function () {
Services.obs.removeObserver(handleRequest, "getUserMedia:request");
}
}
function handleRequest(aSubject, aTopic, aData) {
let {windowID: windowID, callID: callID} = JSON.parse(aData);
let someWindow = Services.wm.getMostRecentWindow(null);
let contentWindow = someWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.getOuterWindowWithId(windowID);
let browser = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
let params = aSubject.QueryInterface(Ci.nsIMediaStreamOptions);
browser.ownerDocument.defaultView.navigator.mozGetUserMediaDevices(
function (devices) {
prompt(browser, callID, params.audio, params.video, devices);
},
function (error) {
Cu.reportError(error);
}
);
}
function prompt(aBrowser, aCallID, aAudioRequested, aVideoRequested, aDevices) {
let audioDevices = [];
let videoDevices = [];
for (let device of aDevices) {
device = device.QueryInterface(Ci.nsIMediaDevice);
switch (device.type) {
case "audio":
if (aAudioRequested)
audioDevices.push(device);
break;
case "video":
if (aVideoRequested)
videoDevices.push(device);
break;
}
}
let requestType;
if (audioDevices.length && videoDevices.length)
requestType = "shareCameraAndMicrophone";
else if (audioDevices.length)
requestType = "shareMicrophone";
else if (videoDevices.length)
requestType = "shareCamera";
else
return;
let host = aBrowser.contentDocument.documentURIObject.asciiHost;
let chromeWin = aBrowser.ownerDocument.defaultView;
let stringBundle = chromeWin.gNavigatorBundle;
let message = stringBundle.getFormattedString("getUserMedia." + requestType + ".message",
[ host ]);
let responseSent = false;
let mainAction = {
label: stringBundle.getString("getUserMedia." + requestType + ".label"),
accessKey: stringBundle.getString("getUserMedia." + requestType + ".accesskey"),
callback: function () {
Services.obs.notifyObservers(null, "getUserMedia:response:allow", aCallID);
responseSent = true;
}
};
let secondaryActions = [];
let selectableDevices = videoDevices.length ? videoDevices : audioDevices;
if (selectableDevices.length > 1) {
let selectableDeviceNumber = 0;
for (let device of selectableDevices) {
selectableDeviceNumber++;
secondaryActions.push({
label: stringBundle.getFormattedString(
device.type == "audio" ?
"getUserMedia.shareSpecificMicrophone.label" :
"getUserMedia.shareSpecificCamera.label",
[ device.name ]),
accessKey: selectableDeviceNumber,
callback: function () {
Services.obs.notifyObservers(device, "getUserMedia:response:allow", aCallID);
responseSent = true;
}
});
}
}
let options = {
removeOnDismissal: true,
eventCallback: function (aType) {
if (!responseSent && aType == "removed")
Services.obs.notifyObservers(null, "getUserMedia:response:deny", aCallID);
}
};
chromeWin.PopupNotifications.show(aBrowser, "webRTC-shareDevices", message,
"webRTC-notification-icon", mainAction,
secondaryActions, options);
}

View File

@ -1199,6 +1199,10 @@ toolbar[iconsize="small"] #feed-button {
list-style-image: url(chrome://browser/skin/webapps-64.png);
}
.popup-notification-icon[popupid="webRTC-shareDevices"] {
list-style-image: url(chrome://browser/skin/webRTC-shareDevice-64.png);
}
/* Notification icon box */
#notification-popup-box {
position: relative;
@ -1266,6 +1270,10 @@ toolbar[iconsize="small"] #feed-button {
list-style-image: url(chrome://mozapps/skin/plugins/pluginGeneric-16.png);
}
#webRTC-notification-icon {
list-style-image: url(chrome://browser/skin/webRTC-shareDevice-16.png);
}
#treecolAutoCompleteImage {
max-width : 36px;
}

View File

@ -5,9 +5,9 @@
browser.jar:
% skin browser classic/1.0 %skin/classic/browser/
% override chrome://global/skin/icons/warning-16.png moz-icon://stock/gtk-dialog-warning?size=menu
skin/classic/browser/sanitizeDialog.css (sanitizeDialog.css)
* skin/classic/browser/aboutPrivateBrowsing.css (aboutPrivateBrowsing.css)
* skin/classic/browser/aboutSessionRestore.css (aboutSessionRestore.css)
skin/classic/browser/sanitizeDialog.css
* skin/classic/browser/aboutPrivateBrowsing.css
* skin/classic/browser/aboutSessionRestore.css
skin/classic/browser/aboutSessionRestore-window-icon.png
skin/classic/browser/aboutCertError.css
skin/classic/browser/aboutCertError_sectionCollapsed.png
@ -18,8 +18,8 @@ browser.jar:
skin/classic/browser/aboutSyncTabs.css
#endif
skin/classic/browser/actionicon-tab.png
* skin/classic/browser/browser.css (browser.css)
* skin/classic/browser/engineManager.css (engineManager.css)
* skin/classic/browser/browser.css
* skin/classic/browser/engineManager.css
skin/classic/browser/Geolocation-16.png
skin/classic/browser/Geolocation-64.png
skin/classic/browser/Go-arrow.png
@ -36,13 +36,15 @@ browser.jar:
skin/classic/browser/page-livemarks.png
skin/classic/browser/Privacy-16.png
skin/classic/browser/Privacy-48.png
skin/classic/browser/searchbar.css (searchbar.css)
skin/classic/browser/searchbar.css
skin/classic/browser/Secure.png
skin/classic/browser/Security-broken.png
skin/classic/browser/setDesktopBackground.css
skin/classic/browser/Toolbar.png
skin/classic/browser/Toolbar-small.png
skin/classic/browser/urlbar-arrow.png
skin/classic/browser/webRTC-shareDevice-16.png
skin/classic/browser/webRTC-shareDevice-64.png
skin/classic/browser/downloads/buttons.png (downloads/buttons.png)
skin/classic/browser/downloads/download-glow.png (downloads/download-glow.png)
skin/classic/browser/downloads/download-notification.png (downloads/download-notification.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -3027,6 +3027,10 @@ toolbarbutton.chevron > .toolbarbutton-menu-dropmarker {
list-style-image: url(chrome://mozapps/skin/plugins/pluginGeneric-16.png);
}
#webRTC-notification-icon {
list-style-image: url(chrome://browser/skin/webRTC-shareDevice-16.png);
}
.popup-notification-icon {
width: 64px;
height: 64px;
@ -3107,6 +3111,10 @@ toolbarbutton.chevron > .toolbarbutton-menu-dropmarker {
list-style-image: url(chrome://browser/skin/webapps-64.png);
}
.popup-notification-icon[popupid="webRTC-shareDevices"] {
list-style-image: url(chrome://browser/skin/webRTC-shareDevice-64.png);
}
/* Popup Buttons */
#identity-popup-more-info-button {
@hudButton@

View File

@ -66,6 +66,8 @@ browser.jar:
skin/classic/browser/urlbar-arrow@2x.png
skin/classic/browser/urlbar-popup-blocked.png
skin/classic/browser/urlbar-popup-blocked@2x.png
skin/classic/browser/webRTC-shareDevice-16.png
skin/classic/browser/webRTC-shareDevice-64.png
skin/classic/browser/downloads/buttons.png (downloads/buttons.png)
skin/classic/browser/downloads/download-glow.png (downloads/download-glow.png)
skin/classic/browser/downloads/download-notification.png (downloads/download-notification.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -2330,6 +2330,10 @@ toolbarbutton.bookmark-item[dragover="true"][open="true"] {
list-style-image: url(chrome://browser/skin/webapps-64.png);
}
.popup-notification-icon[popupid="webRTC-shareDevices"] {
list-style-image: url(chrome://browser/skin/webRTC-shareDevice-64.png);
}
/* Notification icon box */
#notification-popup-box {
position: relative;
@ -2395,6 +2399,10 @@ toolbarbutton.bookmark-item[dragover="true"][open="true"] {
list-style-image: url(chrome://mozapps/skin/plugins/pluginGeneric-16.png);
}
#webRTC-notification-icon {
list-style-image: url(chrome://browser/skin/webRTC-shareDevice-16.png);
}
#identity-popup-container {
min-width: 280px;
}

View File

@ -7,9 +7,9 @@ browser.jar:
% skin browser classic/1.0 %skin/classic/browser/ os!=WINNT
# NOTE: If you add a new file here, you'll need to add it to the aero
# section at the bottom of this file
skin/classic/browser/sanitizeDialog.css (sanitizeDialog.css)
* skin/classic/browser/aboutPrivateBrowsing.css (aboutPrivateBrowsing.css)
* skin/classic/browser/aboutSessionRestore.css (aboutSessionRestore.css)
skin/classic/browser/sanitizeDialog.css
* skin/classic/browser/aboutPrivateBrowsing.css
* skin/classic/browser/aboutSessionRestore.css
skin/classic/browser/aboutSessionRestore-window-icon.png (preferences/application.png)
skin/classic/browser/aboutCertError.css
skin/classic/browser/aboutCertError_sectionCollapsed.png
@ -22,42 +22,44 @@ browser.jar:
skin/classic/browser/actionicon-tab.png
skin/classic/browser/appmenu-icons.png
skin/classic/browser/appmenu-dropmarker.png
* skin/classic/browser/browser.css (browser.css)
* skin/classic/browser/engineManager.css (engineManager.css)
* skin/classic/browser/browser.css
* skin/classic/browser/engineManager.css
skin/classic/browser/Geolocation-16.png
skin/classic/browser/Geolocation-64.png
skin/classic/browser/webapps-16.png
skin/classic/browser/webapps-64.png
skin/classic/browser/Info.png (Info.png)
skin/classic/browser/identity.png (identity.png)
skin/classic/browser/Info.png
skin/classic/browser/identity.png
skin/classic/browser/identity-icons-generic.png
skin/classic/browser/identity-icons-https.png
skin/classic/browser/identity-icons-https-ev.png
skin/classic/browser/keyhole-forward-mask.svg
skin/classic/browser/KUI-background.png
skin/classic/browser/KUI-close.png
skin/classic/browser/livemark-folder.png
skin/classic/browser/menu-back.png
skin/classic/browser/menu-forward.png
skin/classic/browser/monitor.png
skin/classic/browser/monitor_16-10.png
skin/classic/browser/pageInfo.css
skin/classic/browser/pageInfo.png (pageInfo.png)
skin/classic/browser/pageInfo.png
skin/classic/browser/page-livemarks.png (feeds/feedIcon16.png)
skin/classic/browser/livemark-folder.png (livemark-folder.png)
skin/classic/browser/Privacy-16.png
skin/classic/browser/Privacy-48.png
skin/classic/browser/reload-stop-go.png
skin/classic/browser/Secure24.png (Secure24.png)
skin/classic/browser/Toolbar.png (Toolbar.png)
skin/classic/browser/searchbar.css
skin/classic/browser/searchbar-dropdown-arrow.png
skin/classic/browser/Secure24.png
skin/classic/browser/setDesktopBackground.css
skin/classic/browser/Toolbar.png
skin/classic/browser/Toolbar-inverted.png
skin/classic/browser/toolbarbutton-dropdown-arrow.png
skin/classic/browser/toolbarbutton-dropdown-arrow-inverted.png
skin/classic/browser/searchbar.css (searchbar.css)
skin/classic/browser/searchbar-dropdown-arrow.png
skin/classic/browser/setDesktopBackground.css
skin/classic/browser/menu-back.png (menu-back.png)
skin/classic/browser/menu-forward.png (menu-forward.png)
skin/classic/browser/monitor.png
skin/classic/browser/monitor_16-10.png
skin/classic/browser/urlbar-arrow.png
skin/classic/browser/urlbar-popup-blocked.png
skin/classic/browser/urlbar-history-dropmarker.png
skin/classic/browser/webapps-16.png
skin/classic/browser/webapps-64.png
skin/classic/browser/webRTC-shareDevice-16.png
skin/classic/browser/webRTC-shareDevice-64.png
skin/classic/browser/downloads/buttons.png (downloads/buttons.png)
skin/classic/browser/downloads/download-glow.png (downloads/download-glow.png)
skin/classic/browser/downloads/download-notification.png (downloads/download-notification.png)
@ -223,15 +225,13 @@ browser.jar:
#ifdef MOZ_SERVICES_SYNC
skin/classic/aero/browser/aboutSyncTabs.css
#endif
skin/classic/aero/browser/actionicon-tab.png (actionicon-tab.png)
skin/classic/aero/browser/actionicon-tab.png
skin/classic/aero/browser/appmenu-dropmarker.png
skin/classic/aero/browser/appmenu-icons.png
* skin/classic/aero/browser/browser.css (browser-aero.css)
* skin/classic/aero/browser/engineManager.css (engineManager.css)
* skin/classic/aero/browser/engineManager.css
skin/classic/aero/browser/Geolocation-16.png
skin/classic/aero/browser/Geolocation-64.png
skin/classic/aero/browser/webapps-16.png
skin/classic/aero/browser/webapps-64.png
skin/classic/aero/browser/Info.png (Info-aero.png)
skin/classic/aero/browser/identity.png (identity-aero.png)
skin/classic/aero/browser/identity-icons-generic.png
@ -240,28 +240,32 @@ browser.jar:
skin/classic/aero/browser/keyhole-forward-mask.svg
skin/classic/aero/browser/KUI-background.png
skin/classic/aero/browser/KUI-close.png
skin/classic/aero/browser/pageInfo.css
skin/classic/aero/browser/pageInfo.png (pageInfo-aero.png)
skin/classic/aero/browser/page-livemarks.png (feeds/feedIcon16-aero.png)
skin/classic/aero/browser/livemark-folder.png (livemark-folder-aero.png)
skin/classic/aero/browser/Privacy-16.png (Privacy-16-aero.png)
skin/classic/aero/browser/Privacy-48.png (Privacy-48-aero.png)
skin/classic/aero/browser/reload-stop-go.png
skin/classic/aero/browser/Secure24.png (Secure24-aero.png)
skin/classic/aero/browser/Toolbar.png
skin/classic/aero/browser/Toolbar-inverted.png
skin/classic/aero/browser/toolbarbutton-dropdown-arrow.png
skin/classic/aero/browser/toolbarbutton-dropdown-arrow-inverted.png
skin/classic/aero/browser/searchbar.css (searchbar.css)
skin/classic/aero/browser/searchbar-dropdown-arrow.png (searchbar-dropdown-arrow-aero.png)
skin/classic/aero/browser/setDesktopBackground.css
skin/classic/aero/browser/menu-back.png (menu-back-aero.png)
skin/classic/aero/browser/menu-forward.png (menu-forward-aero.png)
skin/classic/aero/browser/monitor.png
skin/classic/aero/browser/monitor_16-10.png
skin/classic/aero/browser/pageInfo.css
skin/classic/aero/browser/pageInfo.png (pageInfo-aero.png)
skin/classic/aero/browser/page-livemarks.png (feeds/feedIcon16-aero.png)
skin/classic/aero/browser/Privacy-16.png (Privacy-16-aero.png)
skin/classic/aero/browser/Privacy-48.png (Privacy-48-aero.png)
skin/classic/aero/browser/reload-stop-go.png
skin/classic/aero/browser/searchbar.css
skin/classic/aero/browser/searchbar-dropdown-arrow.png (searchbar-dropdown-arrow-aero.png)
skin/classic/aero/browser/Secure24.png (Secure24-aero.png)
skin/classic/aero/browser/setDesktopBackground.css
skin/classic/aero/browser/Toolbar.png
skin/classic/aero/browser/Toolbar-inverted.png
skin/classic/aero/browser/toolbarbutton-dropdown-arrow.png
skin/classic/aero/browser/toolbarbutton-dropdown-arrow-inverted.png
skin/classic/aero/browser/urlbar-arrow.png
skin/classic/aero/browser/urlbar-popup-blocked.png
skin/classic/aero/browser/urlbar-history-dropmarker.png
skin/classic/aero/browser/webapps-16.png
skin/classic/aero/browser/webapps-64.png
skin/classic/aero/browser/webRTC-shareDevice-16.png
skin/classic/aero/browser/webRTC-shareDevice-64.png
skin/classic/aero/browser/downloads/buttons.png (downloads/buttons-aero.png)
skin/classic/aero/browser/downloads/download-glow.png (downloads/download-glow-aero.png)
skin/classic/aero/browser/downloads/download-notification.png (downloads/download-notification.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB