DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (fddffdeab170)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/* 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";

this.EXPORTED_SYMBOLS = [];

var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

function handlePCRequest(aSubject, aTopic, aData) {
  aSubject = aSubject.wrappedJSObject;
  let { windowID, innerWindowID, callID, isSecure } = aSubject;
  let contentWindow = Services.wm.getOuterWindowWithId(windowID);

  Services.obs.notifyObservers(null, "PeerConnection:response:allow", callID);
}

function handleGumRequest(aSubject, aTopic, aData) {
  let { windowID, innerWindowID, callID } = aSubject;
  let constraints = aSubject.getConstraints();
  let contentWindow = Services.wm.getOuterWindowWithId(windowID);

  contentWindow.navigator.mozGetUserMediaDevices(
    constraints,
    function (devices) {
      prompt(contentWindow, callID, constraints.audio,
             constraints.video || constraints.picture,
             devices);
    },
    function (error) {
      denyRequest(callID, error);
    },
    innerWindowID,
    callID);
}

function prompt(aWindow, 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;
    }
  }

  if (audioDevices.length == 0 && videoDevices.length == 0) {
    denyRequest(aCallID);
    return;
  }

  let params = {
                 videoDevices: videoDevices,
                 audioDevices: audioDevices,
                 out: null
               };
  aWindow.openDialog("chrome://webapprt/content/getUserMediaDialog.xul", "",
                     "chrome, dialog, modal", params).focus();

  if (!params.out) {
    denyRequest(aCallID);
    return;
  }

  let allowedDevices = Cc["@mozilla.org/supports-array;1"].
                       createInstance(Ci.nsISupportsArray);
  let videoIndex = params.out.video;
  let audioIndex = params.out.audio;

  if (videoIndex != -1) {
    allowedDevices.AppendElement(videoDevices[videoIndex]);
  }

  if (audioIndex != -1) {
    allowedDevices.AppendElement(audioDevices[audioIndex]);
  }

  if (allowedDevices.Count()) {
    Services.obs.notifyObservers(allowedDevices, "getUserMedia:response:allow",
                                 aCallID);
  } else {
    denyRequest(aCallID);
  }
}

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);
}

Services.obs.addObserver(handleGumRequest, "getUserMedia:request", false);
Services.obs.addObserver(handlePCRequest, "PeerConnection:request", false);