Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | this.EXPORTED_SYMBOLS = []; |
michael@0 | 8 | |
michael@0 | 9 | let Cc = Components.classes; |
michael@0 | 10 | let Ci = Components.interfaces; |
michael@0 | 11 | let Cu = Components.utils; |
michael@0 | 12 | |
michael@0 | 13 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 14 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 15 | |
michael@0 | 16 | function handleRequest(aSubject, aTopic, aData) { |
michael@0 | 17 | let { windowID, callID } = aSubject; |
michael@0 | 18 | let constraints = aSubject.getConstraints(); |
michael@0 | 19 | let contentWindow = Services.wm.getOuterWindowWithId(windowID); |
michael@0 | 20 | |
michael@0 | 21 | contentWindow.navigator.mozGetUserMediaDevices( |
michael@0 | 22 | constraints, |
michael@0 | 23 | function (devices) { |
michael@0 | 24 | prompt(contentWindow, callID, constraints.audio, |
michael@0 | 25 | constraints.video || constraints.picture, |
michael@0 | 26 | devices); |
michael@0 | 27 | }, |
michael@0 | 28 | function (error) { |
michael@0 | 29 | denyRequest(callID, error); |
michael@0 | 30 | }); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function prompt(aWindow, aCallID, aAudioRequested, aVideoRequested, aDevices) { |
michael@0 | 34 | let audioDevices = []; |
michael@0 | 35 | let videoDevices = []; |
michael@0 | 36 | for (let device of aDevices) { |
michael@0 | 37 | device = device.QueryInterface(Ci.nsIMediaDevice); |
michael@0 | 38 | switch (device.type) { |
michael@0 | 39 | case "audio": |
michael@0 | 40 | if (aAudioRequested) { |
michael@0 | 41 | audioDevices.push(device); |
michael@0 | 42 | } |
michael@0 | 43 | break; |
michael@0 | 44 | |
michael@0 | 45 | case "video": |
michael@0 | 46 | if (aVideoRequested) { |
michael@0 | 47 | videoDevices.push(device); |
michael@0 | 48 | } |
michael@0 | 49 | break; |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | if (audioDevices.length == 0 && videoDevices.length == 0) { |
michael@0 | 54 | denyRequest(aCallID); |
michael@0 | 55 | return; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | let params = { |
michael@0 | 59 | videoDevices: videoDevices, |
michael@0 | 60 | audioDevices: audioDevices, |
michael@0 | 61 | out: null |
michael@0 | 62 | }; |
michael@0 | 63 | aWindow.openDialog("chrome://webapprt/content/getUserMediaDialog.xul", "", |
michael@0 | 64 | "chrome, dialog, modal", params).focus(); |
michael@0 | 65 | |
michael@0 | 66 | if (!params.out) { |
michael@0 | 67 | denyRequest(aCallID); |
michael@0 | 68 | return; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | let allowedDevices = Cc["@mozilla.org/supports-array;1"]. |
michael@0 | 72 | createInstance(Ci.nsISupportsArray); |
michael@0 | 73 | let videoIndex = params.out.video; |
michael@0 | 74 | let audioIndex = params.out.audio; |
michael@0 | 75 | |
michael@0 | 76 | if (videoIndex != -1) { |
michael@0 | 77 | allowedDevices.AppendElement(videoDevices[videoIndex]); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | if (audioIndex != -1) { |
michael@0 | 81 | allowedDevices.AppendElement(audioDevices[audioIndex]); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | if (allowedDevices.Count()) { |
michael@0 | 85 | Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow", |
michael@0 | 86 | aCallID); |
michael@0 | 87 | } else { |
michael@0 | 88 | denyRequest(aCallID); |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function denyRequest(aCallID, aError) { |
michael@0 | 93 | let msg = null; |
michael@0 | 94 | if (aError) { |
michael@0 | 95 | msg = Cc["@mozilla.org/supports-string;1"]. |
michael@0 | 96 | createInstance(Ci.nsISupportsString); |
michael@0 | 97 | msg.data = aError; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | Services.obs.notifyObservers(msg, "getUserMedia:response:deny", aCallID); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | Services.obs.addObserver(handleRequest, "getUserMedia:request", false); |