2012-10-05 02:37:00 -07:00
|
|
|
/* 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";
|
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.EXPORTED_SYMBOLS = ["webrtcUI"];
|
2012-10-05 02:37:00 -07:00
|
|
|
|
|
|
|
const Cu = Components.utils;
|
2012-12-21 13:05:45 -08:00
|
|
|
const Cc = Components.classes;
|
2012-10-05 02:37:00 -07:00
|
|
|
const Ci = Components.interfaces;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-12-28 01:25:59 -08:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
2014-04-22 20:19:12 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
|
|
|
|
"resource://gre/modules/PluralForm.jsm");
|
|
|
|
|
2012-12-28 01:25:59 -08:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "MediaManagerService",
|
|
|
|
"@mozilla.org/mediaManagerService;1",
|
|
|
|
"nsIMediaManagerService");
|
2012-10-05 02:37:00 -07:00
|
|
|
|
2012-10-31 09:13:28 -07:00
|
|
|
this.webrtcUI = {
|
2012-10-05 02:37:00 -07:00
|
|
|
init: function () {
|
|
|
|
Services.obs.addObserver(handleRequest, "getUserMedia:request", false);
|
2013-03-01 01:28:01 -08:00
|
|
|
Services.obs.addObserver(updateIndicators, "recording-device-events", false);
|
2013-02-16 02:10:41 -08:00
|
|
|
Services.obs.addObserver(removeBrowserSpecificIndicator, "recording-window-ended", false);
|
2012-10-05 02:37:00 -07:00
|
|
|
},
|
2012-12-28 01:25:59 -08:00
|
|
|
|
2012-10-05 02:37:00 -07:00
|
|
|
uninit: function () {
|
|
|
|
Services.obs.removeObserver(handleRequest, "getUserMedia:request");
|
2013-03-01 01:28:01 -08:00
|
|
|
Services.obs.removeObserver(updateIndicators, "recording-device-events");
|
2013-02-16 02:10:41 -08:00
|
|
|
Services.obs.removeObserver(removeBrowserSpecificIndicator, "recording-window-ended");
|
2012-12-28 01:25:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
showGlobalIndicator: false,
|
|
|
|
|
|
|
|
get activeStreams() {
|
|
|
|
let contentWindowSupportsArray = MediaManagerService.activeMediaCaptureWindows;
|
|
|
|
let count = contentWindowSupportsArray.Count();
|
|
|
|
let activeStreams = [];
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
let contentWindow = contentWindowSupportsArray.GetElementAt(i);
|
2013-06-05 10:15:14 -07:00
|
|
|
let browser = getBrowserForWindow(contentWindow);
|
|
|
|
let browserWindow = browser.ownerDocument.defaultView;
|
2012-12-28 01:25:59 -08:00
|
|
|
let tab = browserWindow.gBrowser &&
|
|
|
|
browserWindow.gBrowser._getTabForContentWindow(contentWindow.top);
|
2013-06-05 10:15:14 -07:00
|
|
|
activeStreams.push({
|
|
|
|
uri: contentWindow.location.href,
|
|
|
|
tab: tab,
|
|
|
|
browser: browser
|
|
|
|
});
|
2012-12-28 01:25:59 -08:00
|
|
|
}
|
|
|
|
return activeStreams;
|
2012-10-05 02:37:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-16 02:10:41 -08:00
|
|
|
function getBrowserForWindowId(aWindowID) {
|
2013-05-30 11:02:49 -07:00
|
|
|
return getBrowserForWindow(Services.wm.getOuterWindowWithId(aWindowID));
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBrowserForWindow(aContentWindow) {
|
|
|
|
return aContentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler;
|
2013-02-16 02:10:41 -08:00
|
|
|
}
|
2012-10-05 02:37:00 -07:00
|
|
|
|
2013-02-16 02:10:41 -08:00
|
|
|
function handleRequest(aSubject, aTopic, aData) {
|
2013-09-15 23:34:57 -07:00
|
|
|
let constraints = aSubject.getConstraints();
|
2014-04-15 23:22:19 -07:00
|
|
|
let secure = aSubject.isSecure;
|
2014-02-14 11:32:58 -08:00
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aSubject.windowID);
|
2012-10-05 02:37:00 -07:00
|
|
|
|
2014-02-14 11:32:58 -08:00
|
|
|
contentWindow.navigator.mozGetUserMediaDevices(
|
2013-09-15 23:34:57 -07:00
|
|
|
constraints,
|
2012-10-05 02:37:00 -07:00
|
|
|
function (devices) {
|
2014-02-14 11:32:58 -08:00
|
|
|
prompt(contentWindow, aSubject.callID, constraints.audio,
|
2014-04-15 23:22:19 -07:00
|
|
|
constraints.video || constraints.picture, devices, secure);
|
2012-10-05 02:37:00 -07:00
|
|
|
},
|
|
|
|
function (error) {
|
2013-02-15 19:22:27 -08:00
|
|
|
// bug 827146 -- In the future, the UI should catch NO_DEVICES_FOUND
|
|
|
|
// and allow the user to plug in a device, instead of immediately failing.
|
2013-09-15 23:34:57 -07:00
|
|
|
denyRequest(aSubject.callID, error);
|
2014-02-14 11:32:58 -08:00
|
|
|
},
|
|
|
|
aSubject.innerWindowID);
|
2012-10-05 02:37:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-23 03:56:23 -08:00
|
|
|
function denyRequest(aCallID, aError) {
|
|
|
|
let msg = null;
|
|
|
|
if (aError) {
|
|
|
|
msg = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
|
|
msg.data = aError;
|
|
|
|
}
|
|
|
|
Services.obs.notifyObservers(msg, "getUserMedia:response:deny", aCallID);
|
|
|
|
}
|
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
function prompt(aContentWindow, aCallID, aAudio, aVideo, aDevices, aSecure) {
|
2012-10-05 02:37:00 -07:00
|
|
|
let audioDevices = [];
|
|
|
|
let videoDevices = [];
|
2014-07-07 00:08:00 -07:00
|
|
|
|
|
|
|
// MediaStreamConstraints defines video as 'boolean or MediaTrackConstraints'.
|
|
|
|
let sharingScreen = aVideo && typeof(aVideo) != "boolean" &&
|
|
|
|
aVideo.mediaSource != "camera";
|
2012-10-05 02:37:00 -07:00
|
|
|
for (let device of aDevices) {
|
|
|
|
device = device.QueryInterface(Ci.nsIMediaDevice);
|
|
|
|
switch (device.type) {
|
|
|
|
case "audio":
|
2014-07-07 00:08:00 -07:00
|
|
|
if (aAudio)
|
2012-10-05 02:37:00 -07:00
|
|
|
audioDevices.push(device);
|
|
|
|
break;
|
|
|
|
case "video":
|
2014-07-07 00:08:00 -07:00
|
|
|
// Verify that if we got a camera, we haven't requested a screen share,
|
|
|
|
// or that if we requested a screen share we aren't getting a camera.
|
|
|
|
if (aVideo && (device.mediaSource == "camera") != sharingScreen)
|
2012-10-05 02:37:00 -07:00
|
|
|
videoDevices.push(device);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
let requestTypes = [];
|
|
|
|
if (videoDevices.length)
|
|
|
|
requestTypes.push(sharingScreen ? "Screen" : "Camera");
|
|
|
|
if (audioDevices.length)
|
|
|
|
requestTypes.push("Microphone");
|
|
|
|
|
|
|
|
if (!requestTypes.length) {
|
2013-02-23 03:56:23 -08:00
|
|
|
denyRequest(aCallID, "NO_DEVICES_FOUND");
|
2012-10-05 02:37:00 -07:00
|
|
|
return;
|
2013-02-23 03:56:23 -08:00
|
|
|
}
|
2012-10-05 02:37:00 -07:00
|
|
|
|
2014-02-25 03:50:42 -08:00
|
|
|
let uri = aContentWindow.document.documentURIObject;
|
2014-02-14 11:32:58 -08:00
|
|
|
let browser = getBrowserForWindow(aContentWindow);
|
2013-05-30 11:02:49 -07:00
|
|
|
let chromeDoc = browser.ownerDocument;
|
2012-12-21 13:05:45 -08:00
|
|
|
let chromeWin = chromeDoc.defaultView;
|
2012-10-05 02:37:00 -07:00
|
|
|
let stringBundle = chromeWin.gNavigatorBundle;
|
2014-07-07 00:08:00 -07:00
|
|
|
let stringId = "getUserMedia.share" + requestTypes.join("And") + ".message";
|
|
|
|
let message = stringBundle.getFormattedString(stringId, [uri.host]);
|
2012-10-05 02:37:00 -07:00
|
|
|
|
|
|
|
let mainAction = {
|
2014-07-07 00:08:00 -07:00
|
|
|
label: PluralForm.get(requestTypes.length,
|
2012-12-21 13:05:45 -08:00
|
|
|
stringBundle.getString("getUserMedia.shareSelectedDevices.label")),
|
|
|
|
accessKey: stringBundle.getString("getUserMedia.shareSelectedDevices.accesskey"),
|
2013-12-19 13:16:10 -08:00
|
|
|
// The real callback will be set during the "showing" event. The
|
|
|
|
// empty function here is so that PopupNotifications.show doesn't
|
|
|
|
// reject the action.
|
|
|
|
callback: function() {}
|
2012-10-05 02:37:00 -07:00
|
|
|
};
|
|
|
|
|
2014-02-25 03:50:42 -08:00
|
|
|
let secondaryActions = [
|
|
|
|
{
|
|
|
|
label: stringBundle.getString("getUserMedia.denyRequest.label"),
|
|
|
|
accessKey: stringBundle.getString("getUserMedia.denyRequest.accesskey"),
|
|
|
|
callback: function () {
|
|
|
|
denyRequest(aCallID);
|
|
|
|
}
|
2014-07-07 00:08:00 -07:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!sharingScreen) { // Bug 1037438: implement 'never' for screen sharing.
|
|
|
|
secondaryActions.push({
|
2014-02-25 03:50:42 -08:00
|
|
|
label: stringBundle.getString("getUserMedia.never.label"),
|
|
|
|
accessKey: stringBundle.getString("getUserMedia.never.accesskey"),
|
|
|
|
callback: function () {
|
|
|
|
denyRequest(aCallID);
|
2014-04-17 15:37:59 -07:00
|
|
|
// Let someone save "Never" for http sites so that they can be stopped from
|
|
|
|
// bothering you with doorhangers.
|
2014-02-25 03:50:42 -08:00
|
|
|
let perms = Services.perms;
|
|
|
|
if (audioDevices.length)
|
|
|
|
perms.add(uri, "microphone", perms.DENY_ACTION);
|
|
|
|
if (videoDevices.length)
|
|
|
|
perms.add(uri, "camera", perms.DENY_ACTION);
|
|
|
|
}
|
2014-07-07 00:08:00 -07:00
|
|
|
});
|
|
|
|
}
|
2012-10-05 02:37:00 -07:00
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
if (aSecure && !sharingScreen) {
|
|
|
|
// 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).
|
2014-04-17 15:37:59 -07:00
|
|
|
secondaryActions.unshift({
|
|
|
|
label: stringBundle.getString("getUserMedia.always.label"),
|
|
|
|
accessKey: stringBundle.getString("getUserMedia.always.accesskey"),
|
|
|
|
callback: function () {
|
|
|
|
mainAction.callback(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:16:10 -08:00
|
|
|
let options = {
|
|
|
|
eventCallback: function(aTopic, aNewBrowser) {
|
|
|
|
if (aTopic == "swapping")
|
|
|
|
return true;
|
|
|
|
|
2014-02-28 09:47:18 -08:00
|
|
|
let chromeDoc = this.browser.ownerDocument;
|
|
|
|
|
|
|
|
if (aTopic == "shown") {
|
|
|
|
let PopupNotifications = chromeDoc.defaultView.PopupNotifications;
|
2014-07-07 00:08:00 -07:00
|
|
|
let popupId = "Devices";
|
|
|
|
if (requestTypes.length == 1 && requestTypes[0] == "Microphone")
|
|
|
|
popupId = "Microphone";
|
2014-02-28 09:47:18 -08:00
|
|
|
PopupNotifications.panel.firstChild.setAttribute("popupid", "webRTC-share" + popupId);
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:16:10 -08:00
|
|
|
if (aTopic != "showing")
|
|
|
|
return false;
|
|
|
|
|
2014-06-13 05:51:12 -07:00
|
|
|
// DENY_ACTION is handled immediately by MediaManager, but handling
|
|
|
|
// of ALLOW_ACTION is delayed until the popupshowing event
|
|
|
|
// to avoid granting permissions automatically to background tabs.
|
|
|
|
if (aSecure) {
|
|
|
|
let perms = Services.perms;
|
|
|
|
|
|
|
|
let micPerm = perms.testExactPermission(uri, "microphone");
|
|
|
|
if (micPerm == perms.PROMPT_ACTION)
|
|
|
|
micPerm = perms.UNKNOWN_ACTION;
|
|
|
|
|
|
|
|
let camPerm = perms.testExactPermission(uri, "camera");
|
|
|
|
if (camPerm == perms.PROMPT_ACTION)
|
|
|
|
camPerm = perms.UNKNOWN_ACTION;
|
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
// Screen sharing shouldn't follow the camera permissions.
|
|
|
|
if (videoDevices.length && sharingScreen)
|
|
|
|
camPerm = perms.UNKNOWN_ACTION;
|
|
|
|
|
2014-06-13 05:51:12 -07:00
|
|
|
// We don't check that permissions are set to ALLOW_ACTION in this
|
|
|
|
// test; only that they are set. This is because if audio is allowed
|
|
|
|
// and video is denied persistently, we don't want to show the prompt,
|
|
|
|
// and will grant audio access immediately.
|
|
|
|
if ((!audioDevices.length || micPerm) && (!videoDevices.length || camPerm)) {
|
|
|
|
// All permissions we were about to request are already persistently set.
|
|
|
|
let allowedDevices = Cc["@mozilla.org/supports-array;1"]
|
|
|
|
.createInstance(Ci.nsISupportsArray);
|
|
|
|
if (videoDevices.length && camPerm == perms.ALLOW_ACTION)
|
|
|
|
allowedDevices.AppendElement(videoDevices[0]);
|
|
|
|
if (audioDevices.length && micPerm == perms.ALLOW_ACTION)
|
|
|
|
allowedDevices.AppendElement(audioDevices[0]);
|
|
|
|
Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", aCallID);
|
|
|
|
this.remove();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:16:10 -08:00
|
|
|
function listDevices(menupopup, devices) {
|
|
|
|
while (menupopup.lastChild)
|
|
|
|
menupopup.removeChild(menupopup.lastChild);
|
|
|
|
|
|
|
|
let deviceIndex = 0;
|
|
|
|
for (let device of devices) {
|
|
|
|
addDeviceToList(menupopup, device.name, deviceIndex);
|
|
|
|
deviceIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
function listScreenShareDevices(menupopup, devices) {
|
|
|
|
while (menupopup.lastChild)
|
|
|
|
menupopup.removeChild(menupopup.lastChild);
|
|
|
|
|
|
|
|
// "No Window or Screen" is the default because we can't pick a
|
|
|
|
// 'default' window to share.
|
|
|
|
addDeviceToList(menupopup,
|
|
|
|
stringBundle.getString("getUserMedia.noWindowOrScreen.label"),
|
|
|
|
"-1");
|
|
|
|
|
|
|
|
// Then add the 'Entire screen' item if mozGetUserMediaDevices returned it.
|
|
|
|
for (let i = 0; i < devices.length; ++i) {
|
|
|
|
if (devices[i].mediaSource == "screen") {
|
|
|
|
menupopup.appendChild(chromeDoc.createElement("menuseparator"));
|
|
|
|
addDeviceToList(menupopup,
|
|
|
|
stringBundle.getString("getUserMedia.shareEntireScreen.label"),
|
|
|
|
i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally add all the window names.
|
|
|
|
let separatorNeeded = true;
|
|
|
|
for (let i = 0; i < devices.length; ++i) {
|
|
|
|
if (devices[i].mediaSource == "window") {
|
|
|
|
if (separatorNeeded) {
|
|
|
|
menupopup.appendChild(chromeDoc.createElement("menuseparator"));
|
|
|
|
separatorNeeded = false;
|
|
|
|
}
|
|
|
|
addDeviceToList(menupopup, devices[i].name, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-19 13:16:10 -08:00
|
|
|
function addDeviceToList(menupopup, deviceName, deviceIndex) {
|
|
|
|
let menuitem = chromeDoc.createElement("menuitem");
|
|
|
|
menuitem.setAttribute("value", deviceIndex);
|
|
|
|
menuitem.setAttribute("label", deviceName);
|
|
|
|
menuitem.setAttribute("tooltiptext", deviceName);
|
|
|
|
menupopup.appendChild(menuitem);
|
|
|
|
}
|
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
chromeDoc.getElementById("webRTC-selectCamera").hidden = !videoDevices.length || sharingScreen;
|
|
|
|
chromeDoc.getElementById("webRTC-selectWindowOrScreen").hidden = !sharingScreen || !videoDevices.length;
|
2013-12-19 13:16:10 -08:00
|
|
|
chromeDoc.getElementById("webRTC-selectMicrophone").hidden = !audioDevices.length;
|
|
|
|
|
|
|
|
let camMenupopup = chromeDoc.getElementById("webRTC-selectCamera-menupopup");
|
2014-07-07 00:08:00 -07:00
|
|
|
let windowMenupopup = chromeDoc.getElementById("webRTC-selectWindow-menupopup");
|
2013-12-19 13:16:10 -08:00
|
|
|
let micMenupopup = chromeDoc.getElementById("webRTC-selectMicrophone-menupopup");
|
2014-07-07 00:08:00 -07:00
|
|
|
if (sharingScreen)
|
|
|
|
listScreenShareDevices(windowMenupopup, videoDevices);
|
|
|
|
else
|
|
|
|
listDevices(camMenupopup, videoDevices);
|
2013-12-19 13:16:10 -08:00
|
|
|
listDevices(micMenupopup, audioDevices);
|
2014-07-07 00:08:00 -07:00
|
|
|
if (requestTypes.length == 2) {
|
2013-12-19 13:16:10 -08:00
|
|
|
let stringBundle = chromeDoc.defaultView.gNavigatorBundle;
|
2014-07-07 00:08:00 -07:00
|
|
|
if (!sharingScreen)
|
|
|
|
addDeviceToList(camMenupopup, stringBundle.getString("getUserMedia.noVideo.label"), "-1");
|
2013-12-19 13:16:10 -08:00
|
|
|
addDeviceToList(micMenupopup, stringBundle.getString("getUserMedia.noAudio.label"), "-1");
|
|
|
|
}
|
|
|
|
|
2014-02-25 03:50:42 -08:00
|
|
|
this.mainAction.callback = function(aRemember) {
|
2013-12-19 13:16:10 -08:00
|
|
|
let allowedDevices = Cc["@mozilla.org/supports-array;1"]
|
|
|
|
.createInstance(Ci.nsISupportsArray);
|
2014-02-25 03:50:42 -08:00
|
|
|
let perms = Services.perms;
|
2013-12-19 13:16:10 -08:00
|
|
|
if (videoDevices.length) {
|
2014-07-07 00:08:00 -07:00
|
|
|
let listId = "webRTC-select" + (sharingScreen ? "Window" : "Camera") + "-menulist";
|
|
|
|
let videoDeviceIndex = chromeDoc.getElementById(listId).value;
|
2014-02-25 03:50:42 -08:00
|
|
|
let allowCamera = videoDeviceIndex != "-1";
|
|
|
|
if (allowCamera)
|
2013-12-19 13:16:10 -08:00
|
|
|
allowedDevices.AppendElement(videoDevices[videoDeviceIndex]);
|
2014-02-25 03:50:42 -08:00
|
|
|
if (aRemember) {
|
|
|
|
perms.add(uri, "camera",
|
|
|
|
allowCamera ? perms.ALLOW_ACTION : perms.DENY_ACTION);
|
|
|
|
}
|
2013-12-19 13:16:10 -08:00
|
|
|
}
|
|
|
|
if (audioDevices.length) {
|
|
|
|
let audioDeviceIndex = chromeDoc.getElementById("webRTC-selectMicrophone-menulist").value;
|
2014-02-25 03:50:42 -08:00
|
|
|
let allowMic = audioDeviceIndex != "-1";
|
|
|
|
if (allowMic)
|
2013-12-19 13:16:10 -08:00
|
|
|
allowedDevices.AppendElement(audioDevices[audioDeviceIndex]);
|
2014-02-25 03:50:42 -08:00
|
|
|
if (aRemember) {
|
|
|
|
perms.add(uri, "microphone",
|
|
|
|
allowMic ? perms.ALLOW_ACTION : perms.DENY_ACTION);
|
|
|
|
}
|
2013-12-19 13:16:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (allowedDevices.Count() == 0) {
|
|
|
|
denyRequest(aCallID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", aCallID);
|
|
|
|
};
|
2014-04-07 10:37:50 -07:00
|
|
|
return false;
|
2013-12-19 13:16:10 -08:00
|
|
|
}
|
|
|
|
};
|
2012-10-05 02:37:00 -07:00
|
|
|
|
2014-07-07 00:08:00 -07:00
|
|
|
let anchorId = "webRTC-shareDevices-notification-icon";
|
|
|
|
if (requestTypes.length == 1 && requestTypes[0] == "Microphone")
|
|
|
|
anchorId = "webRTC-shareMicrophone-notification-icon";
|
2013-05-30 11:02:49 -07:00
|
|
|
chromeWin.PopupNotifications.show(browser, "webRTC-shareDevices", message,
|
2014-02-28 09:47:18 -08:00
|
|
|
anchorId, mainAction, secondaryActions, options);
|
2012-10-05 02:37:00 -07:00
|
|
|
}
|
2012-12-28 01:25:59 -08:00
|
|
|
|
2013-03-01 01:28:01 -08:00
|
|
|
function updateIndicators() {
|
2012-12-28 01:25:59 -08:00
|
|
|
webrtcUI.showGlobalIndicator =
|
|
|
|
MediaManagerService.activeMediaCaptureWindows.Count() > 0;
|
|
|
|
|
|
|
|
let e = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (e.hasMoreElements())
|
|
|
|
e.getNext().WebrtcIndicator.updateButton();
|
2013-03-01 01:28:01 -08:00
|
|
|
|
2013-06-05 10:15:14 -07:00
|
|
|
for (let {browser: browser} of webrtcUI.activeStreams)
|
|
|
|
showBrowserSpecificIndicator(browser);
|
2013-03-01 01:28:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function showBrowserSpecificIndicator(aBrowser) {
|
|
|
|
let hasVideo = {};
|
|
|
|
let hasAudio = {};
|
|
|
|
MediaManagerService.mediaCaptureWindowState(aBrowser.contentWindow,
|
|
|
|
hasVideo, hasAudio);
|
|
|
|
let captureState;
|
|
|
|
if (hasVideo.value && hasAudio.value) {
|
|
|
|
captureState = "CameraAndMicrophone";
|
|
|
|
} else if (hasVideo.value) {
|
|
|
|
captureState = "Camera";
|
|
|
|
} else if (hasAudio.value) {
|
|
|
|
captureState = "Microphone";
|
|
|
|
} else {
|
|
|
|
Cu.reportError("showBrowserSpecificIndicator: got neither video nor audio access");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let chromeWin = aBrowser.ownerDocument.defaultView;
|
|
|
|
let stringBundle = chromeWin.gNavigatorBundle;
|
|
|
|
|
2013-05-30 11:02:49 -07:00
|
|
|
let message = stringBundle.getString("getUserMedia.sharing" + captureState + ".message2");
|
2014-01-23 02:50:03 -08:00
|
|
|
|
2014-02-25 03:50:42 -08:00
|
|
|
let uri = aBrowser.contentWindow.document.documentURIObject;
|
2014-01-23 02:50:03 -08:00
|
|
|
let windowId = aBrowser.contentWindow
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindowUtils)
|
|
|
|
.currentInnerWindowID;
|
|
|
|
let mainAction = {
|
|
|
|
label: stringBundle.getString("getUserMedia.continueSharing.label"),
|
|
|
|
accessKey: stringBundle.getString("getUserMedia.continueSharing.accesskey"),
|
|
|
|
callback: function () {},
|
|
|
|
dismiss: true
|
|
|
|
};
|
|
|
|
let secondaryActions = [{
|
|
|
|
label: stringBundle.getString("getUserMedia.stopSharing.label"),
|
|
|
|
accessKey: stringBundle.getString("getUserMedia.stopSharing.accesskey"),
|
|
|
|
callback: function () {
|
2014-02-25 03:50:42 -08:00
|
|
|
let perms = Services.perms;
|
|
|
|
if (hasVideo.value &&
|
|
|
|
perms.testExactPermission(uri, "camera") == perms.ALLOW_ACTION)
|
|
|
|
perms.remove(uri.host, "camera");
|
|
|
|
if (hasAudio.value &&
|
|
|
|
perms.testExactPermission(uri, "microphone") == perms.ALLOW_ACTION)
|
|
|
|
perms.remove(uri.host, "microphone");
|
|
|
|
|
2014-01-23 02:50:03 -08:00
|
|
|
Services.obs.notifyObservers(null, "getUserMedia:revoke", windowId);
|
|
|
|
}
|
|
|
|
}];
|
2013-03-01 01:28:01 -08:00
|
|
|
let options = {
|
2014-01-23 02:50:03 -08:00
|
|
|
hideNotNow: true,
|
2013-12-19 13:16:10 -08:00
|
|
|
dismissed: true,
|
2014-02-28 09:47:18 -08:00
|
|
|
eventCallback: function(aTopic) {
|
|
|
|
if (aTopic == "shown") {
|
|
|
|
let PopupNotifications = this.browser.ownerDocument.defaultView.PopupNotifications;
|
|
|
|
let popupId = captureState == "Microphone" ? "Microphone" : "Devices";
|
|
|
|
PopupNotifications.panel.firstChild.setAttribute("popupid", "webRTC-sharing" + popupId);
|
|
|
|
}
|
|
|
|
return aTopic == "swapping";
|
|
|
|
}
|
2013-03-01 01:28:01 -08:00
|
|
|
};
|
2014-02-28 09:47:18 -08:00
|
|
|
let anchorId = captureState == "Microphone" ? "webRTC-sharingMicrophone-notification-icon"
|
|
|
|
: "webRTC-sharingDevices-notification-icon";
|
2013-03-01 01:28:01 -08:00
|
|
|
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingDevices", message,
|
2014-02-28 09:47:18 -08:00
|
|
|
anchorId, mainAction, secondaryActions, options);
|
2012-12-28 01:25:59 -08:00
|
|
|
}
|
2013-02-16 02:10:41 -08:00
|
|
|
|
|
|
|
function removeBrowserSpecificIndicator(aSubject, aTopic, aData) {
|
|
|
|
let browser = getBrowserForWindowId(aData);
|
|
|
|
let PopupNotifications = browser.ownerDocument.defaultView.PopupNotifications;
|
|
|
|
let notification = PopupNotifications &&
|
|
|
|
PopupNotifications.getNotification("webRTC-sharingDevices",
|
|
|
|
browser);
|
|
|
|
if (notification)
|
|
|
|
PopupNotifications.remove(notification);
|
|
|
|
}
|