2014-09-22 22:39:57 +04: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";
|
|
|
|
|
2018-07-30 20:53:15 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["WebRTCChild"];
|
2014-09-22 22:39:57 +04:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2018-07-30 20:53:15 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
|
2018-07-24 18:12:50 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
2014-09-22 22:39:57 +04:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "MediaManagerService",
|
|
|
|
"@mozilla.org/mediaManagerService;1",
|
|
|
|
"nsIMediaManagerService");
|
|
|
|
|
2018-07-24 18:12:50 +03:00
|
|
|
const kBrowserURL = AppConstants.BROWSER_CHROME_URL;
|
2016-11-07 14:14:29 +03:00
|
|
|
|
2018-07-30 20:53:15 +03:00
|
|
|
class WebRTCChild extends ActorChild {
|
2015-01-17 00:20:46 +03:00
|
|
|
// Called only for 'unload' to remove pending gUM prompts in reloaded frames.
|
2018-07-30 20:53:15 +03:00
|
|
|
static handleEvent(aEvent) {
|
2015-01-17 00:20:46 +03:00
|
|
|
let contentWindow = aEvent.target.defaultView;
|
|
|
|
let mm = getMessageManagerForWindow(contentWindow);
|
2015-08-07 22:22:30 +03:00
|
|
|
for (let key of contentWindow.pendingGetUserMediaRequests.keys()) {
|
2015-01-17 00:20:46 +03:00
|
|
|
mm.sendAsyncMessage("webrtc:CancelRequest", key);
|
2015-08-07 22:22:30 +03:00
|
|
|
}
|
|
|
|
for (let key of contentWindow.pendingPeerConnectionRequests.keys()) {
|
|
|
|
mm.sendAsyncMessage("rtcpeer:CancelRequest", key);
|
|
|
|
}
|
2018-07-30 20:53:15 +03:00
|
|
|
}
|
2015-01-17 00:20:46 +03:00
|
|
|
|
2017-04-07 18:48:58 +03:00
|
|
|
// This observer is registered in ContentObservers.js to avoid
|
|
|
|
// loading this .jsm when WebRTC is not in use.
|
2018-07-30 20:53:15 +03:00
|
|
|
static observe(aSubject, aTopic, aData) {
|
2017-04-07 18:48:58 +03:00
|
|
|
switch (aTopic) {
|
|
|
|
case "getUserMedia:request":
|
2017-07-04 19:00:18 +03:00
|
|
|
handleGUMRequest(aSubject, aTopic, aData);
|
|
|
|
break;
|
2017-04-07 18:48:58 +03:00
|
|
|
case "recording-device-stopped":
|
2017-07-04 19:00:18 +03:00
|
|
|
handleGUMStop(aSubject, aTopic, aData);
|
|
|
|
break;
|
2017-04-07 18:48:58 +03:00
|
|
|
case "PeerConnection:request":
|
2017-07-04 19:00:18 +03:00
|
|
|
handlePCRequest(aSubject, aTopic, aData);
|
|
|
|
break;
|
2017-04-07 18:48:58 +03:00
|
|
|
case "recording-device-events":
|
2017-07-04 19:00:18 +03:00
|
|
|
updateIndicators(aSubject, aTopic, aData);
|
|
|
|
break;
|
2017-04-07 18:48:58 +03:00
|
|
|
case "recording-window-ended":
|
2017-07-04 19:00:18 +03:00
|
|
|
removeBrowserSpecificIndicator(aSubject, aTopic, aData);
|
|
|
|
break;
|
2017-04-07 18:48:58 +03:00
|
|
|
}
|
2018-07-30 20:53:15 +03:00
|
|
|
}
|
2017-04-07 18:48:58 +03:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
receiveMessage(aMessage) {
|
2014-09-22 22:39:57 +04:00
|
|
|
switch (aMessage.name) {
|
2015-08-07 22:22:30 +03:00
|
|
|
case "rtcpeer:Allow":
|
|
|
|
case "rtcpeer:Deny": {
|
|
|
|
let callID = aMessage.data.callID;
|
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aMessage.data.windowID);
|
|
|
|
forgetPCRequest(contentWindow, callID);
|
|
|
|
let topic = (aMessage.name == "rtcpeer:Allow") ? "PeerConnection:response:allow" :
|
|
|
|
"PeerConnection:response:deny";
|
|
|
|
Services.obs.notifyObservers(null, topic, callID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webrtc:Allow": {
|
2014-09-22 22:39:58 +04:00
|
|
|
let callID = aMessage.data.callID;
|
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aMessage.data.windowID);
|
|
|
|
let devices = contentWindow.pendingGetUserMediaRequests.get(callID);
|
2015-08-07 22:22:30 +03:00
|
|
|
forgetGUMRequest(contentWindow, callID);
|
2014-09-22 22:39:58 +04:00
|
|
|
|
2016-10-14 20:06:37 +03:00
|
|
|
let allowedDevices = Cc["@mozilla.org/array;1"]
|
|
|
|
.createInstance(Ci.nsIMutableArray);
|
2014-09-22 22:39:58 +04:00
|
|
|
for (let deviceIndex of aMessage.data.devices)
|
2017-04-14 22:51:39 +03:00
|
|
|
allowedDevices.appendElement(devices[deviceIndex]);
|
2014-09-22 22:39:58 +04:00
|
|
|
|
|
|
|
Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", callID);
|
|
|
|
break;
|
2015-08-07 22:22:30 +03:00
|
|
|
}
|
2014-09-22 22:39:58 +04:00
|
|
|
case "webrtc:Deny":
|
2015-08-07 22:22:30 +03:00
|
|
|
denyGUMRequest(aMessage.data);
|
2014-09-22 22:39:58 +04:00
|
|
|
break;
|
2014-09-22 22:39:57 +04:00
|
|
|
case "webrtc:StopSharing":
|
|
|
|
Services.obs.notifyObservers(null, "getUserMedia:revoke", aMessage.data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 20:53:15 +03:00
|
|
|
}
|
2014-09-22 22:39:57 +04:00
|
|
|
|
2015-08-07 22:22:30 +03:00
|
|
|
function handlePCRequest(aSubject, aTopic, aData) {
|
2015-08-11 20:48:55 +03:00
|
|
|
let { windowID, innerWindowID, callID, isSecure } = aSubject;
|
2015-08-07 22:22:30 +03:00
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(windowID);
|
|
|
|
|
2015-10-16 19:16:24 +03:00
|
|
|
let mm = getMessageManagerForWindow(contentWindow);
|
|
|
|
if (!mm) {
|
|
|
|
// Workaround for Bug 1207784. To use WebRTC, add-ons right now use
|
|
|
|
// hiddenWindow.mozRTCPeerConnection which is only privileged on OSX. Other
|
|
|
|
// platforms end up here without a message manager.
|
|
|
|
// TODO: Remove once there's a better way (1215591).
|
|
|
|
|
|
|
|
// Skip permission check in the absence of a message manager.
|
|
|
|
Services.obs.notifyObservers(null, "PeerConnection:response:allow", callID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-07 22:22:30 +03:00
|
|
|
if (!contentWindow.pendingPeerConnectionRequests) {
|
|
|
|
setupPendingListsInitially(contentWindow);
|
|
|
|
}
|
|
|
|
contentWindow.pendingPeerConnectionRequests.add(callID);
|
|
|
|
|
|
|
|
let request = {
|
2016-12-30 02:34:54 +03:00
|
|
|
windowID,
|
|
|
|
innerWindowID,
|
|
|
|
callID,
|
2015-08-07 22:22:30 +03:00
|
|
|
documentURI: contentWindow.document.documentURI,
|
|
|
|
secure: isSecure,
|
|
|
|
};
|
|
|
|
mm.sendAsyncMessage("rtcpeer:Request", request);
|
|
|
|
}
|
|
|
|
|
2017-01-19 07:24:59 +03:00
|
|
|
function handleGUMStop(aSubject, aTopic, aData) {
|
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aSubject.windowID);
|
|
|
|
|
|
|
|
let request = {
|
|
|
|
windowID: aSubject.windowID,
|
|
|
|
rawID: aSubject.rawID,
|
|
|
|
mediaSource: aSubject.mediaSource,
|
|
|
|
};
|
|
|
|
|
|
|
|
let mm = getMessageManagerForWindow(contentWindow);
|
2017-02-02 06:39:08 +03:00
|
|
|
if (mm)
|
|
|
|
mm.sendAsyncMessage("webrtc:StopRecording", request);
|
2017-01-19 07:24:59 +03:00
|
|
|
}
|
|
|
|
|
2015-08-07 22:22:30 +03:00
|
|
|
function handleGUMRequest(aSubject, aTopic, aData) {
|
2014-09-22 22:39:58 +04:00
|
|
|
let constraints = aSubject.getConstraints();
|
|
|
|
let secure = aSubject.isSecure;
|
2018-01-10 23:07:59 +03:00
|
|
|
let isHandlingUserInput = aSubject.isHandlingUserInput;
|
2014-09-22 22:39:58 +04:00
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aSubject.windowID);
|
|
|
|
|
|
|
|
contentWindow.navigator.mozGetUserMediaDevices(
|
|
|
|
constraints,
|
2016-11-11 19:10:51 +03:00
|
|
|
function(devices) {
|
2016-04-05 13:13:45 +03:00
|
|
|
// If the window has been closed while we were waiting for the list of
|
|
|
|
// devices, there's nothing to do in the callback anymore.
|
|
|
|
if (contentWindow.closed)
|
|
|
|
return;
|
|
|
|
|
2014-09-22 22:39:58 +04:00
|
|
|
prompt(contentWindow, aSubject.windowID, aSubject.callID,
|
2018-01-10 23:07:59 +03:00
|
|
|
constraints, devices, secure, isHandlingUserInput);
|
2014-09-22 22:39:58 +04:00
|
|
|
},
|
2016-11-11 19:10:51 +03:00
|
|
|
function(error) {
|
2018-04-10 08:49:15 +03:00
|
|
|
// Device enumeration is done ahead of handleGUMRequest, so we're not
|
|
|
|
// responsible for handling the NotFoundError spec case.
|
|
|
|
denyGUMRequest({callID: aSubject.callID});
|
2014-09-22 22:39:58 +04:00
|
|
|
},
|
2016-01-08 01:30:10 +03:00
|
|
|
aSubject.innerWindowID,
|
|
|
|
aSubject.callID);
|
2014-09-22 22:39:58 +04:00
|
|
|
}
|
|
|
|
|
2018-01-10 23:07:59 +03:00
|
|
|
function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSecure, aIsHandlingUserInput) {
|
2014-09-22 22:39:58 +04:00
|
|
|
let audioDevices = [];
|
|
|
|
let videoDevices = [];
|
|
|
|
let devices = [];
|
|
|
|
|
|
|
|
// MediaStreamConstraints defines video as 'boolean or MediaTrackConstraints'.
|
|
|
|
let video = aConstraints.video || aConstraints.picture;
|
2015-07-24 15:28:17 +03:00
|
|
|
let audio = aConstraints.audio;
|
2014-09-22 22:39:58 +04:00
|
|
|
let sharingScreen = video && typeof(video) != "boolean" &&
|
|
|
|
video.mediaSource != "camera";
|
2015-07-24 15:28:17 +03:00
|
|
|
let sharingAudio = audio && typeof(audio) != "boolean" &&
|
|
|
|
audio.mediaSource != "microphone";
|
2014-09-22 22:39:58 +04:00
|
|
|
for (let device of aDevices) {
|
|
|
|
device = device.QueryInterface(Ci.nsIMediaDevice);
|
|
|
|
switch (device.type) {
|
2018-07-16 12:29:12 +03:00
|
|
|
case "audioinput":
|
2015-07-24 15:28:17 +03:00
|
|
|
// 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,
|
2016-11-07 14:14:29 +03:00
|
|
|
id: device.rawId, mediaSource: device.mediaSource});
|
2014-09-22 22:39:58 +04:00
|
|
|
devices.push(device);
|
|
|
|
}
|
|
|
|
break;
|
2018-07-16 12:29:12 +03:00
|
|
|
case "videoinput":
|
2014-09-22 22:39:58 +04: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 (video && (device.mediaSource == "camera") != sharingScreen) {
|
2016-11-07 14:15:37 +03:00
|
|
|
let deviceObject = {name: device.name, deviceIndex: devices.length,
|
|
|
|
id: device.rawId, mediaSource: device.mediaSource};
|
|
|
|
if (device.scary)
|
|
|
|
deviceObject.scary = true;
|
|
|
|
videoDevices.push(deviceObject);
|
2014-09-22 22:39:58 +04:00
|
|
|
devices.push(device);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let requestTypes = [];
|
|
|
|
if (videoDevices.length)
|
|
|
|
requestTypes.push(sharingScreen ? "Screen" : "Camera");
|
|
|
|
if (audioDevices.length)
|
2015-07-24 15:28:17 +03:00
|
|
|
requestTypes.push(sharingAudio ? "AudioCapture" : "Microphone");
|
2014-09-22 22:39:58 +04:00
|
|
|
|
|
|
|
if (!requestTypes.length) {
|
2018-04-10 08:49:15 +03:00
|
|
|
// Device enumeration is done ahead of handleGUMRequest, so we're not
|
|
|
|
// responsible for handling the NotFoundError spec case.
|
|
|
|
denyGUMRequest({callID: aCallID});
|
2014-09-22 22:39:58 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-17 00:20:46 +03:00
|
|
|
if (!aContentWindow.pendingGetUserMediaRequests) {
|
2015-08-07 22:22:30 +03:00
|
|
|
setupPendingListsInitially(aContentWindow);
|
2015-01-17 00:20:46 +03:00
|
|
|
}
|
2014-09-22 22:39:58 +04:00
|
|
|
aContentWindow.pendingGetUserMediaRequests.set(aCallID, devices);
|
|
|
|
|
2018-01-10 23:07:59 +03:00
|
|
|
// Record third party origins for telemetry.
|
|
|
|
let isThirdPartyOrigin =
|
|
|
|
aContentWindow.document.location.origin != aContentWindow.top.document.location.origin;
|
|
|
|
|
2014-09-22 22:39:58 +04:00
|
|
|
let request = {
|
|
|
|
callID: aCallID,
|
|
|
|
windowID: aWindowID,
|
2017-06-13 13:10:39 +03:00
|
|
|
origin: aContentWindow.origin,
|
2014-09-22 22:39:58 +04:00
|
|
|
documentURI: aContentWindow.document.documentURI,
|
|
|
|
secure: aSecure,
|
2018-01-10 23:07:59 +03:00
|
|
|
isHandlingUserInput: aIsHandlingUserInput,
|
|
|
|
isThirdPartyOrigin,
|
2016-12-30 02:34:54 +03:00
|
|
|
requestTypes,
|
|
|
|
sharingScreen,
|
|
|
|
sharingAudio,
|
|
|
|
audioDevices,
|
2018-08-31 08:59:17 +03:00
|
|
|
videoDevices,
|
2014-09-22 22:39:58 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
let mm = getMessageManagerForWindow(aContentWindow);
|
|
|
|
mm.sendAsyncMessage("webrtc:Request", request);
|
|
|
|
}
|
|
|
|
|
2018-04-10 08:49:15 +03:00
|
|
|
function denyGUMRequest(aData) {
|
2018-10-10 11:28:41 +03:00
|
|
|
let subject;
|
|
|
|
if (aData.noOSPermission) {
|
|
|
|
subject = "getUserMedia:response:noOSPermission";
|
|
|
|
} else {
|
|
|
|
subject = "getUserMedia:response:deny";
|
|
|
|
}
|
|
|
|
Services.obs.notifyObservers(null, subject, aData.callID);
|
2014-09-22 22:39:58 +04:00
|
|
|
|
|
|
|
if (!aData.windowID)
|
|
|
|
return;
|
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aData.windowID);
|
|
|
|
if (contentWindow.pendingGetUserMediaRequests)
|
2015-08-07 22:22:30 +03:00
|
|
|
forgetGUMRequest(contentWindow, aData.callID);
|
2014-09-22 22:39:58 +04:00
|
|
|
}
|
|
|
|
|
2015-08-07 22:22:30 +03:00
|
|
|
function forgetGUMRequest(aContentWindow, aCallID) {
|
2015-01-17 00:20:46 +03:00
|
|
|
aContentWindow.pendingGetUserMediaRequests.delete(aCallID);
|
2015-08-07 22:22:30 +03:00
|
|
|
forgetPendingListsEventually(aContentWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
function forgetPCRequest(aContentWindow, aCallID) {
|
|
|
|
aContentWindow.pendingPeerConnectionRequests.delete(aCallID);
|
|
|
|
forgetPendingListsEventually(aContentWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
function setupPendingListsInitially(aContentWindow) {
|
|
|
|
if (aContentWindow.pendingGetUserMediaRequests) {
|
2015-01-17 00:20:46 +03:00
|
|
|
return;
|
2015-08-07 22:22:30 +03:00
|
|
|
}
|
|
|
|
aContentWindow.pendingGetUserMediaRequests = new Map();
|
|
|
|
aContentWindow.pendingPeerConnectionRequests = new Set();
|
2018-07-30 20:53:15 +03:00
|
|
|
aContentWindow.addEventListener("unload", WebRTCChild.handleEvent);
|
2015-08-07 22:22:30 +03:00
|
|
|
}
|
2015-01-17 00:20:46 +03:00
|
|
|
|
2015-08-07 22:22:30 +03:00
|
|
|
function forgetPendingListsEventually(aContentWindow) {
|
|
|
|
if (aContentWindow.pendingGetUserMediaRequests.size ||
|
|
|
|
aContentWindow.pendingPeerConnectionRequests.size) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-17 00:20:46 +03:00
|
|
|
aContentWindow.pendingGetUserMediaRequests = null;
|
2015-08-07 22:22:30 +03:00
|
|
|
aContentWindow.pendingPeerConnectionRequests = null;
|
2018-07-30 20:53:15 +03:00
|
|
|
aContentWindow.removeEventListener("unload", WebRTCChild.handleEvent);
|
2015-01-17 00:20:46 +03:00
|
|
|
}
|
2014-09-22 22:39:58 +04:00
|
|
|
|
2016-11-07 14:14:29 +03:00
|
|
|
function updateIndicators(aSubject, aTopic, aData) {
|
|
|
|
if (aSubject instanceof Ci.nsIPropertyBag &&
|
|
|
|
aSubject.getProperty("requestURL") == kBrowserURL) {
|
|
|
|
// Ignore notifications caused by the browser UI showing previews.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-14 20:06:27 +03:00
|
|
|
let contentWindowArray = MediaManagerService.activeMediaCaptureWindows;
|
|
|
|
let count = contentWindowArray.length;
|
2014-09-22 22:39:57 +04:00
|
|
|
|
|
|
|
let state = {
|
|
|
|
showGlobalIndicator: count > 0,
|
|
|
|
showCameraIndicator: false,
|
|
|
|
showMicrophoneIndicator: false,
|
2018-08-31 08:59:17 +03:00
|
|
|
showScreenSharingIndicator: "",
|
2014-09-22 22:39:57 +04:00
|
|
|
};
|
|
|
|
|
2017-11-28 22:21:33 +03:00
|
|
|
Services.cpmm.sendAsyncMessage("webrtc:UpdatingIndicators");
|
2014-10-01 14:39:52 +04:00
|
|
|
|
|
|
|
// If several iframes in the same page use media streams, it's possible to
|
|
|
|
// have the same top level window several times. We use a Set to avoid
|
|
|
|
// sending duplicate notifications.
|
|
|
|
let contentWindows = new Set();
|
2014-09-22 22:39:57 +04:00
|
|
|
for (let i = 0; i < count; ++i) {
|
2016-10-14 20:06:27 +03:00
|
|
|
contentWindows.add(contentWindowArray.queryElementAt(i, Ci.nsISupports).top);
|
2014-10-01 14:39:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let contentWindow of contentWindows) {
|
2016-11-07 14:14:29 +03:00
|
|
|
if (contentWindow.document.documentURI == kBrowserURL) {
|
|
|
|
// There may be a preview shown at the same time as other streams.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-26 18:42:51 +03:00
|
|
|
let tabState = getTabStateForContentWindow(contentWindow);
|
2017-11-16 21:33:19 +03:00
|
|
|
if (tabState.camera == MediaManagerService.STATE_CAPTURE_ENABLED ||
|
|
|
|
tabState.camera == MediaManagerService.STATE_CAPTURE_DISABLED) {
|
2014-09-22 22:39:57 +04:00
|
|
|
state.showCameraIndicator = true;
|
2017-11-16 21:33:19 +03:00
|
|
|
}
|
|
|
|
if (tabState.microphone == MediaManagerService.STATE_CAPTURE_ENABLED ||
|
|
|
|
tabState.microphone == MediaManagerService.STATE_CAPTURE_DISABLED) {
|
2014-09-22 22:39:57 +04:00
|
|
|
state.showMicrophoneIndicator = true;
|
2017-11-16 21:33:19 +03:00
|
|
|
}
|
2016-04-26 18:42:51 +03:00
|
|
|
if (tabState.screen) {
|
2017-11-16 21:33:19 +03:00
|
|
|
if (tabState.screen.startsWith("Screen")) {
|
2016-04-26 18:42:51 +03:00
|
|
|
state.showScreenSharingIndicator = "Screen";
|
2017-11-16 21:33:19 +03:00
|
|
|
} else if (tabState.screen.startsWith("Window")) {
|
2016-04-26 18:42:51 +03:00
|
|
|
if (state.showScreenSharingIndicator != "Screen")
|
|
|
|
state.showScreenSharingIndicator = "Window";
|
2017-11-16 21:33:19 +03:00
|
|
|
} else if (tabState.screen.startsWith("Application")) {
|
2016-04-26 18:42:51 +03:00
|
|
|
if (!state.showScreenSharingIndicator)
|
|
|
|
state.showScreenSharingIndicator = "Application";
|
2017-11-16 21:33:19 +03:00
|
|
|
} else if (tabState.screen.startsWith("Browser")) {
|
2016-04-26 18:42:51 +03:00
|
|
|
if (!state.showScreenSharingIndicator)
|
|
|
|
state.showScreenSharingIndicator = "Browser";
|
|
|
|
}
|
2015-03-11 18:34:31 +03:00
|
|
|
}
|
2017-11-16 21:33:19 +03:00
|
|
|
|
2014-09-22 22:39:57 +04:00
|
|
|
let mm = getMessageManagerForWindow(contentWindow);
|
|
|
|
mm.sendAsyncMessage("webrtc:UpdateBrowserIndicators", tabState);
|
|
|
|
}
|
|
|
|
|
2017-11-28 22:21:33 +03:00
|
|
|
Services.cpmm.sendAsyncMessage("webrtc:UpdateGlobalIndicators", state);
|
2014-09-22 22:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeBrowserSpecificIndicator(aSubject, aTopic, aData) {
|
2016-04-26 18:42:51 +03:00
|
|
|
let contentWindow = Services.wm.getOuterWindowWithId(aData).top;
|
2016-11-07 14:14:29 +03:00
|
|
|
if (contentWindow.document.documentURI == kBrowserURL) {
|
|
|
|
// Ignore notifications caused by the browser UI showing previews.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-26 18:42:51 +03:00
|
|
|
let tabState = getTabStateForContentWindow(contentWindow);
|
2017-11-17 22:13:06 +03:00
|
|
|
if (tabState.camera == MediaManagerService.STATE_NOCAPTURE &&
|
|
|
|
tabState.microphone == MediaManagerService.STATE_NOCAPTURE &&
|
|
|
|
!tabState.screen)
|
2016-04-26 18:42:51 +03:00
|
|
|
tabState = {windowId: tabState.windowId};
|
|
|
|
|
2014-09-22 22:39:57 +04:00
|
|
|
let mm = getMessageManagerForWindow(contentWindow);
|
|
|
|
if (mm)
|
2016-04-26 18:42:51 +03:00
|
|
|
mm.sendAsyncMessage("webrtc:UpdateBrowserIndicators", tabState);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTabStateForContentWindow(aContentWindow) {
|
|
|
|
let camera = {}, microphone = {}, screen = {}, window = {}, app = {}, browser = {};
|
2017-11-17 22:13:06 +03:00
|
|
|
MediaManagerService.mediaCaptureWindowState(aContentWindow,
|
|
|
|
camera, microphone,
|
2016-04-26 18:42:51 +03:00
|
|
|
screen, window, app, browser);
|
|
|
|
let tabState = {camera: camera.value, microphone: microphone.value};
|
2017-11-16 21:33:19 +03:00
|
|
|
if (screen.value == MediaManagerService.STATE_CAPTURE_ENABLED)
|
2016-04-26 18:42:51 +03:00
|
|
|
tabState.screen = "Screen";
|
2017-11-16 21:33:19 +03:00
|
|
|
else if (window.value == MediaManagerService.STATE_CAPTURE_ENABLED)
|
2016-04-26 18:42:51 +03:00
|
|
|
tabState.screen = "Window";
|
2017-11-16 21:33:19 +03:00
|
|
|
else if (app.value == MediaManagerService.STATE_CAPTURE_ENABLED)
|
2016-04-26 18:42:51 +03:00
|
|
|
tabState.screen = "Application";
|
2017-11-16 21:33:19 +03:00
|
|
|
else if (browser.value == MediaManagerService.STATE_CAPTURE_ENABLED)
|
2016-04-26 18:42:51 +03:00
|
|
|
tabState.screen = "Browser";
|
2017-11-16 21:33:19 +03:00
|
|
|
else if (screen.value == MediaManagerService.STATE_CAPTURE_DISABLED)
|
|
|
|
tabState.screen = "ScreenPaused";
|
|
|
|
else if (window.value == MediaManagerService.STATE_CAPTURE_DISABLED)
|
|
|
|
tabState.screen = "WindowPaused";
|
|
|
|
else if (app.value == MediaManagerService.STATE_CAPTURE_DISABLED)
|
|
|
|
tabState.screen = "ApplicationPaused";
|
|
|
|
else if (browser.value == MediaManagerService.STATE_CAPTURE_DISABLED)
|
|
|
|
tabState.screen = "BrowserPaused";
|
|
|
|
|
2018-03-08 16:08:21 +03:00
|
|
|
let screenEnabled = tabState.screen && !tabState.screen.includes("Paused");
|
|
|
|
let cameraEnabled = tabState.camera == MediaManagerService.STATE_CAPTURE_ENABLED;
|
|
|
|
let microphoneEnabled = tabState.microphone == MediaManagerService.STATE_CAPTURE_ENABLED;
|
|
|
|
|
|
|
|
// tabState.sharing controls which global indicator should be shown
|
|
|
|
// for the tab. It should always be set to the _enabled_ device which
|
|
|
|
// we consider most intrusive (screen > camera > microphone).
|
|
|
|
if (screenEnabled) {
|
|
|
|
tabState.sharing = "screen";
|
|
|
|
} else if (cameraEnabled) {
|
|
|
|
tabState.sharing = "camera";
|
|
|
|
} else if (microphoneEnabled) {
|
|
|
|
tabState.sharing = "microphone";
|
|
|
|
} else if (tabState.screen) {
|
2017-11-16 21:33:19 +03:00
|
|
|
tabState.sharing = "screen";
|
|
|
|
} else if (tabState.camera) {
|
|
|
|
tabState.sharing = "camera";
|
|
|
|
} else if (tabState.microphone) {
|
|
|
|
tabState.sharing = "microphone";
|
|
|
|
}
|
|
|
|
|
|
|
|
// The stream is considered paused when we're sharing something
|
|
|
|
// but all devices are off or set to disabled.
|
|
|
|
tabState.paused = tabState.sharing &&
|
2018-03-08 16:08:21 +03:00
|
|
|
!screenEnabled && !cameraEnabled && !microphoneEnabled;
|
2016-04-26 18:42:51 +03:00
|
|
|
|
|
|
|
tabState.windowId = getInnerWindowIDForWindow(aContentWindow);
|
|
|
|
tabState.documentURI = aContentWindow.document.documentURI;
|
|
|
|
|
|
|
|
return tabState;
|
2014-09-22 22:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getInnerWindowIDForWindow(aContentWindow) {
|
2018-07-25 02:47:41 +03:00
|
|
|
return aContentWindow.windowUtils.currentInnerWindowID;
|
2014-09-22 22:39:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMessageManagerForWindow(aContentWindow) {
|
2018-08-01 20:07:10 +03:00
|
|
|
let docShell = aContentWindow.docShell;
|
|
|
|
if (!docShell) {
|
|
|
|
// Closed tab.
|
|
|
|
return null;
|
2017-02-16 02:13:46 +03:00
|
|
|
}
|
|
|
|
|
2018-08-03 06:49:09 +03:00
|
|
|
return docShell.messageManager;
|
2014-09-22 22:39:57 +04:00
|
|
|
}
|