mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 20:30:41 +00:00
Bug 1376357 - Automatically fix ESLint issues in dom/media/*.js*. r=bwc
MozReview-Commit-ID: 6JXIHvJoZqS --HG-- extra : rebase_source : 601c811e8cf623bf5a29c2bdbcdd2f1413a6eaca
This commit is contained in:
parent
fcf4f2c48b
commit
ed3e830fe1
@ -215,6 +215,7 @@ dom/locales/**
|
||||
dom/manifest/**
|
||||
dom/mathml/**
|
||||
dom/media/**
|
||||
!dom/media/*.js*
|
||||
dom/messagechannel/**
|
||||
dom/network/**
|
||||
dom/notification/**
|
||||
@ -251,6 +252,9 @@ dom/xml/**
|
||||
dom/xslt/**
|
||||
dom/xul/**
|
||||
|
||||
# Third-party
|
||||
dom/media/webvtt/**
|
||||
|
||||
# Exclude everything but self-hosted JS
|
||||
js/ductwork/**
|
||||
js/examples/**
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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';
|
||||
"use strict";
|
||||
|
||||
const {
|
||||
classes: Cc,
|
||||
@ -11,23 +11,23 @@ const {
|
||||
results: Cr
|
||||
} = Components;
|
||||
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
Cu.import('resource://gre/modules/NetUtil.jsm');
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
/** This little class ensures that redirects maintain an https:// origin */
|
||||
function RedirectHttpsOnly() {}
|
||||
|
||||
RedirectHttpsOnly.prototype = {
|
||||
asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback) {
|
||||
if (newChannel.URI.scheme !== 'https') {
|
||||
asyncOnChannelRedirect(oldChannel, newChannel, flags, callback) {
|
||||
if (newChannel.URI.scheme !== "https") {
|
||||
callback.onRedirectVerifyCallback(Cr.NS_ERROR_ABORT);
|
||||
} else {
|
||||
callback.onRedirectVerifyCallback(Cr.NS_OK);
|
||||
}
|
||||
},
|
||||
|
||||
getInterface: function(iid) {
|
||||
getInterface(iid) {
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannelEventSink])
|
||||
@ -38,7 +38,7 @@ RedirectHttpsOnly.prototype = {
|
||||
function ResourceLoader(res, rej) {
|
||||
this.resolve = res;
|
||||
this.reject = rej;
|
||||
this.data = '';
|
||||
this.data = "";
|
||||
}
|
||||
|
||||
/** Loads the identified https:// URL. */
|
||||
@ -46,7 +46,7 @@ ResourceLoader.load = function(uri, doc) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let listener = new ResourceLoader(resolve, reject);
|
||||
let ioChannel = NetUtil.newChannel({
|
||||
uri: uri,
|
||||
uri,
|
||||
loadingNode: doc,
|
||||
securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
||||
contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_SCRIPT
|
||||
@ -59,29 +59,29 @@ ResourceLoader.load = function(uri, doc) {
|
||||
};
|
||||
|
||||
ResourceLoader.prototype = {
|
||||
onDataAvailable: function(request, context, input, offset, count) {
|
||||
let stream = Cc['@mozilla.org/scriptableinputstream;1']
|
||||
onDataAvailable(request, context, input, offset, count) {
|
||||
let stream = Cc["@mozilla.org/scriptableinputstream;1"]
|
||||
.createInstance(Ci.nsIScriptableInputStream);
|
||||
stream.init(input);
|
||||
this.data += stream.read(count);
|
||||
},
|
||||
|
||||
onStartRequest: function (request, context) {},
|
||||
onStartRequest(request, context) {},
|
||||
|
||||
onStopRequest: function(request, context, status) {
|
||||
onStopRequest(request, context, status) {
|
||||
if (Components.isSuccessCode(status)) {
|
||||
var statusCode = request.QueryInterface(Ci.nsIHttpChannel).responseStatus;
|
||||
if (statusCode === 200) {
|
||||
this.resolve({ request: request, data: this.data });
|
||||
this.resolve({ request, data: this.data });
|
||||
} else {
|
||||
this.reject(new Error('Non-200 response from server: ' + statusCode));
|
||||
this.reject(new Error("Non-200 response from server: " + statusCode));
|
||||
}
|
||||
} else {
|
||||
this.reject(new Error('Load failed: ' + status));
|
||||
this.reject(new Error("Load failed: " + status));
|
||||
}
|
||||
},
|
||||
|
||||
getInterface: function(iid) {
|
||||
getInterface(iid) {
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener])
|
||||
@ -93,16 +93,16 @@ ResourceLoader.prototype = {
|
||||
function createLocationFromURI(uri) {
|
||||
return {
|
||||
href: uri.spec,
|
||||
protocol: uri.scheme + ':',
|
||||
protocol: uri.scheme + ":",
|
||||
host: uri.host + ((uri.port >= 0) ?
|
||||
(':' + uri.port) : ''),
|
||||
(":" + uri.port) : ""),
|
||||
port: uri.port,
|
||||
hostname: uri.host,
|
||||
pathname: uri.path.replace(/[#\?].*/, ''),
|
||||
search: uri.path.replace(/^[^\?]*/, '').replace(/#.*/, ''),
|
||||
hash: uri.hasRef ? ('#' + uri.ref) : '',
|
||||
pathname: uri.path.replace(/[#\?].*/, ""),
|
||||
search: uri.path.replace(/^[^\?]*/, "").replace(/#.*/, ""),
|
||||
hash: uri.hasRef ? ("#" + uri.ref) : "",
|
||||
origin: uri.prePath,
|
||||
toString: function() {
|
||||
toString() {
|
||||
return uri.spec;
|
||||
}
|
||||
};
|
||||
@ -124,9 +124,9 @@ function IdpSandbox(domain, protocol, win) {
|
||||
}
|
||||
|
||||
IdpSandbox.checkDomain = function(domain) {
|
||||
if (!domain || typeof domain !== 'string') {
|
||||
throw new Error('Invalid domain for identity provider: ' +
|
||||
'must be a non-zero length string');
|
||||
if (!domain || typeof domain !== "string") {
|
||||
throw new Error("Invalid domain for identity provider: " +
|
||||
"must be a non-zero length string");
|
||||
}
|
||||
};
|
||||
|
||||
@ -136,9 +136,9 @@ IdpSandbox.checkDomain = function(domain) {
|
||||
* to move outside of /.well-known/ and into space that they control.
|
||||
*/
|
||||
IdpSandbox.checkProtocol = function(protocol) {
|
||||
let message = 'Invalid protocol for identity provider: ';
|
||||
if (!protocol || typeof protocol !== 'string') {
|
||||
throw new Error(message + 'must be a non-zero length string');
|
||||
let message = "Invalid protocol for identity provider: ";
|
||||
if (!protocol || typeof protocol !== "string") {
|
||||
throw new Error(message + "must be a non-zero length string");
|
||||
}
|
||||
if (decodeURIComponent(protocol).match(/[\/\\]/)) {
|
||||
throw new Error(message + "must not include '/' or '\\'");
|
||||
@ -153,36 +153,36 @@ IdpSandbox.createIdpUri = function(domain, protocol) {
|
||||
IdpSandbox.checkDomain(domain);
|
||||
IdpSandbox.checkProtocol(protocol);
|
||||
|
||||
let message = 'Invalid IdP parameters: ';
|
||||
let message = "Invalid IdP parameters: ";
|
||||
try {
|
||||
let wkIdp = 'https://' + domain + '/.well-known/idp-proxy/' + protocol;
|
||||
let ioService = Components.classes['@mozilla.org/network/io-service;1']
|
||||
let wkIdp = "https://" + domain + "/.well-known/idp-proxy/" + protocol;
|
||||
let ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
let uri = ioService.newURI(wkIdp);
|
||||
|
||||
if (uri.hostPort !== domain) {
|
||||
throw new Error(message + 'domain is invalid');
|
||||
throw new Error(message + "domain is invalid");
|
||||
}
|
||||
if (uri.path.indexOf('/.well-known/idp-proxy/') !== 0) {
|
||||
throw new Error(message + 'must produce a /.well-known/idp-proxy/ URI');
|
||||
if (uri.path.indexOf("/.well-known/idp-proxy/") !== 0) {
|
||||
throw new Error(message + "must produce a /.well-known/idp-proxy/ URI");
|
||||
}
|
||||
|
||||
return uri;
|
||||
} catch (e) {
|
||||
if (typeof e.result !== 'undefined' &&
|
||||
if (typeof e.result !== "undefined" &&
|
||||
e.result === Cr.NS_ERROR_MALFORMED_URI) {
|
||||
throw new Error(message + 'must produce a valid URI');
|
||||
throw new Error(message + "must produce a valid URI");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
IdpSandbox.prototype = {
|
||||
isSame: function(domain, protocol) {
|
||||
isSame(domain, protocol) {
|
||||
return this.source.spec === IdpSandbox.createIdpUri(domain, protocol).spec;
|
||||
},
|
||||
|
||||
start: function() {
|
||||
start() {
|
||||
if (!this.active) {
|
||||
this.active = ResourceLoader.load(this.source, this.window.document)
|
||||
.then(result => this._createSandbox(result));
|
||||
@ -193,29 +193,29 @@ IdpSandbox.prototype = {
|
||||
// Provides the sandbox with some useful facilities. Initially, this is only
|
||||
// a minimal set; it is far easier to add more as the need arises, than to
|
||||
// take them back if we discover a mistake.
|
||||
_populateSandbox: function(uri) {
|
||||
_populateSandbox(uri) {
|
||||
this.sandbox.location = Cu.cloneInto(createLocationFromURI(uri),
|
||||
this.sandbox,
|
||||
{ cloneFunctions: true });
|
||||
},
|
||||
|
||||
_createSandbox: function(result) {
|
||||
_createSandbox(result) {
|
||||
let principal = Services.scriptSecurityManager
|
||||
.getChannelResultPrincipal(result.request);
|
||||
|
||||
this.sandbox = Cu.Sandbox(principal, {
|
||||
sandboxName: 'IdP-' + this.source.host,
|
||||
sandboxName: "IdP-" + this.source.host,
|
||||
wantComponents: false,
|
||||
wantExportHelpers: false,
|
||||
wantGlobalProperties: [
|
||||
'indexedDB', 'XMLHttpRequest', 'TextEncoder', 'TextDecoder',
|
||||
'URL', 'URLSearchParams', 'atob', 'btoa', 'Blob', 'crypto',
|
||||
'rtcIdentityProvider', 'fetch'
|
||||
"indexedDB", "XMLHttpRequest", "TextEncoder", "TextDecoder",
|
||||
"URL", "URLSearchParams", "atob", "btoa", "Blob", "crypto",
|
||||
"rtcIdentityProvider", "fetch"
|
||||
]
|
||||
});
|
||||
let registrar = this.sandbox.rtcIdentityProvider;
|
||||
if (!Cu.isXrayWrapper(registrar)) {
|
||||
throw new Error('IdP setup failed');
|
||||
throw new Error("IdP setup failed");
|
||||
}
|
||||
|
||||
// have to use the ultimate URI, not the starting one to avoid
|
||||
@ -223,19 +223,19 @@ IdpSandbox.prototype = {
|
||||
this._populateSandbox(result.request.URI);
|
||||
try {
|
||||
Cu.evalInSandbox(result.data, this.sandbox,
|
||||
'latest', result.request.URI.spec, 1);
|
||||
"latest", result.request.URI.spec, 1);
|
||||
} catch (e) {
|
||||
// These can be passed straight on, because they are explicitly labelled
|
||||
// as being IdP errors by the IdP and we drop line numbers as a result.
|
||||
if (e.name === 'IdpError' || e.name === 'IdpLoginError') {
|
||||
if (e.name === "IdpError" || e.name === "IdpLoginError") {
|
||||
throw e;
|
||||
}
|
||||
this._logError(e);
|
||||
throw new Error('Error in IdP, check console for details');
|
||||
throw new Error("Error in IdP, check console for details");
|
||||
}
|
||||
|
||||
if (!registrar.hasIdp) {
|
||||
throw new Error('IdP failed to call rtcIdentityProvider.register()');
|
||||
throw new Error("IdP failed to call rtcIdentityProvider.register()");
|
||||
}
|
||||
return registrar;
|
||||
},
|
||||
@ -243,7 +243,7 @@ IdpSandbox.prototype = {
|
||||
// Capture all the details from the error and log them to the console. This
|
||||
// can't rethrow anything else because that could leak information about the
|
||||
// internal workings of the IdP across origins.
|
||||
_logError: function(e) {
|
||||
_logError(e) {
|
||||
let winID = this.window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
|
||||
let scriptError = Cc["@mozilla.org/scripterror;1"]
|
||||
@ -252,12 +252,12 @@ IdpSandbox.prototype = {
|
||||
e.lineNumber, e.columnNumber,
|
||||
Ci.nsIScriptError.errorFlag,
|
||||
"content javascript", winID);
|
||||
let consoleService = Cc['@mozilla.org/consoleservice;1']
|
||||
let consoleService = Cc["@mozilla.org/consoleservice;1"]
|
||||
.getService(Ci.nsIConsoleService);
|
||||
consoleService.logMessage(scriptError);
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
stop() {
|
||||
if (this.sandbox) {
|
||||
Cu.nukeSandbox(this.sandbox);
|
||||
}
|
||||
@ -265,10 +265,10 @@ IdpSandbox.prototype = {
|
||||
this.active = null;
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
toString() {
|
||||
return this.source.spec;
|
||||
}
|
||||
};
|
||||
|
||||
this.EXPORTED_SYMBOLS = ['IdpSandbox'];
|
||||
this.EXPORTED_SYMBOLS = ["IdpSandbox"];
|
||||
this.IdpSandbox = IdpSandbox;
|
||||
|
@ -48,7 +48,7 @@ function logMsg(msg, file, line, flag, winID) {
|
||||
let console = Cc["@mozilla.org/consoleservice;1"].
|
||||
getService(Ci.nsIConsoleService);
|
||||
console.logMessage(scriptError);
|
||||
};
|
||||
}
|
||||
|
||||
let setupPrototype = (_class, dict) => {
|
||||
_class.prototype.classDescription = _class.name;
|
||||
@ -111,7 +111,7 @@ class GlobalPCList {
|
||||
return;
|
||||
}
|
||||
this._list[winID] = this._list[winID].filter(
|
||||
function (e,i,a) { return e.get() !== null; });
|
||||
function(e, i, a) { return e.get() !== null; });
|
||||
|
||||
if (this._list[winID].length === 0) {
|
||||
delete this._list[winID];
|
||||
@ -120,7 +120,7 @@ class GlobalPCList {
|
||||
|
||||
hasActivePeerConnection(winID) {
|
||||
this.removeNullRefs(winID);
|
||||
return this._list[winID] ? true : false;
|
||||
return !!this._list[winID];
|
||||
}
|
||||
|
||||
handleGMPCrash(data) {
|
||||
@ -217,7 +217,7 @@ setupPrototype(GlobalPCList, {
|
||||
Ci.IPeerConnectionManager]),
|
||||
classID: PC_MANAGER_CID,
|
||||
_xpcom_factory: {
|
||||
createInstance: function(outer, iid) {
|
||||
createInstance(outer, iid) {
|
||||
if (outer) {
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
@ -338,11 +338,11 @@ setupPrototype(RTCStatsReport, {
|
||||
contractID: PC_STATS_CONTRACT,
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
|
||||
_specToLegacyFieldMapping: {
|
||||
'inbound-rtp' : 'inboundrtp',
|
||||
'outbound-rtp':'outboundrtp',
|
||||
'candidate-pair':'candidatepair',
|
||||
'local-candidate':'localcandidate',
|
||||
'remote-candidate':'remotecandidate'
|
||||
"inbound-rtp": "inboundrtp",
|
||||
"outbound-rtp": "outboundrtp",
|
||||
"candidate-pair": "candidatepair",
|
||||
"local-candidate": "localcandidate",
|
||||
"remote-candidate": "remotecandidate"
|
||||
}
|
||||
});
|
||||
|
||||
@ -617,7 +617,7 @@ class RTCPeerConnection {
|
||||
}
|
||||
});
|
||||
|
||||
let ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
|
||||
let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
|
||||
let nicerNewURI = uriStr => {
|
||||
try {
|
||||
@ -638,7 +638,7 @@ class RTCPeerConnection {
|
||||
throw new this._win.DOMException(msg + " - missing urls", "InvalidAccessError");
|
||||
}
|
||||
urls.map(url => nicerNewURI(url)).forEach(({ scheme, spec }) => {
|
||||
if (scheme in { turn:1, turns:1 }) {
|
||||
if (scheme in { turn: 1, turns: 1 }) {
|
||||
if (username == undefined) {
|
||||
throw new this._win.DOMException(msg + " - missing username: " + spec,
|
||||
"InvalidAccessError");
|
||||
@ -648,21 +648,21 @@ class RTCPeerConnection {
|
||||
"InvalidAccessError");
|
||||
}
|
||||
if (credentialType != "password") {
|
||||
this.logWarning("RTCConfiguration TURN credentialType \""+
|
||||
this.logWarning("RTCConfiguration TURN credentialType \"" +
|
||||
credentialType +
|
||||
"\" is not yet implemented. Treating as password."+
|
||||
"\" is not yet implemented. Treating as password." +
|
||||
" https://bugzil.la/1247616");
|
||||
}
|
||||
this._hasTurnServer = true;
|
||||
stunServers += 1;
|
||||
} else if (scheme in { stun:1, stuns:1 }) {
|
||||
} else if (scheme in { stun: 1, stuns: 1 }) {
|
||||
this._hasStunServer = true;
|
||||
stunServers += 1;
|
||||
} else {
|
||||
throw new this._win.DOMException(msg + " - improper scheme: " + scheme,
|
||||
"SyntaxError");
|
||||
}
|
||||
if (scheme in { stuns:1, turns:1 }) {
|
||||
if (scheme in { stuns: 1, turns: 1 }) {
|
||||
this.logWarning(scheme.toUpperCase() + " is not yet supported.");
|
||||
}
|
||||
if (stunServers >= 5) {
|
||||
@ -702,11 +702,11 @@ class RTCPeerConnection {
|
||||
if (typeof this._win.onerror === "function") {
|
||||
this._win.onerror(e.message, e.fileName, e.lineNumber);
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// If onerror itself throws, service it.
|
||||
try {
|
||||
this.logMsg(e.message, e.fileName, e.lineNumber, Ci.nsIScriptError.errorFlag);
|
||||
} catch(e) {}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -738,16 +738,16 @@ class RTCPeerConnection {
|
||||
makeGetterSetterEH(name) {
|
||||
Object.defineProperty(this, name,
|
||||
{
|
||||
get:function() { return this.getEH(name); },
|
||||
set:function(h) { return this.setEH(name, h); }
|
||||
get() { return this.getEH(name); },
|
||||
set(h) { return this.setEH(name, h); }
|
||||
});
|
||||
}
|
||||
|
||||
makeLegacyGetterSetterEH(name, msg) {
|
||||
Object.defineProperty(this, name,
|
||||
{
|
||||
get:function() { return this.getEH(name); },
|
||||
set:function(h) {
|
||||
get() { return this.getEH(name); },
|
||||
set(h) {
|
||||
this.logWarning(name + " is deprecated! " + msg);
|
||||
return this.setEH(name, h);
|
||||
}
|
||||
@ -912,7 +912,7 @@ class RTCPeerConnection {
|
||||
name: msg.identity
|
||||
}, this._win));
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
this._rejectPeerIdentity(e);
|
||||
// If we don't expect a specific peer identity, failure to get a valid
|
||||
// peer identity is not a terminal state, so replace the promise to
|
||||
@ -1197,7 +1197,7 @@ class RTCPeerConnection {
|
||||
get idpLoginUrl() { return this._localIdp.idpLoginUrl; }
|
||||
get id() { return this._impl.id; }
|
||||
set id(s) { this._impl.id = s; }
|
||||
get iceGatheringState() { return this._iceGatheringState; }
|
||||
get iceGatheringState() { return this._iceGatheringState; }
|
||||
get iceConnectionState() { return this._iceConnectionState; }
|
||||
|
||||
get signalingState() {
|
||||
@ -1419,34 +1419,31 @@ class PeerConnectionObserver {
|
||||
if (pc.iceConnectionState === iceConnectionState) {
|
||||
return;
|
||||
}
|
||||
if (pc.iceConnectionState === 'new') {
|
||||
if (pc.iceConnectionState === "new") {
|
||||
var checking_histogram = Services.telemetry.getHistogramById("WEBRTC_ICE_CHECKING_RATE");
|
||||
if (iceConnectionState === 'checking') {
|
||||
if (iceConnectionState === "checking") {
|
||||
checking_histogram.add(true);
|
||||
} else if (iceConnectionState === 'failed') {
|
||||
} else if (iceConnectionState === "failed") {
|
||||
checking_histogram.add(false);
|
||||
}
|
||||
} else if (pc.iceConnectionState === 'checking') {
|
||||
} else if (pc.iceConnectionState === "checking") {
|
||||
var success_histogram = Services.telemetry.getHistogramById("WEBRTC_ICE_SUCCESS_RATE");
|
||||
if (iceConnectionState === 'completed' ||
|
||||
iceConnectionState === 'connected') {
|
||||
if (iceConnectionState === "completed" ||
|
||||
iceConnectionState === "connected") {
|
||||
success_histogram.add(true);
|
||||
} else if (iceConnectionState === 'failed') {
|
||||
} else if (iceConnectionState === "failed") {
|
||||
success_histogram.add(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (iceConnectionState === 'failed') {
|
||||
if (iceConnectionState === "failed") {
|
||||
if (!pc._hasStunServer) {
|
||||
pc.logError("ICE failed, add a STUN server and see about:webrtc for more details");
|
||||
}
|
||||
else if (!pc._hasTurnServer) {
|
||||
} else if (!pc._hasTurnServer) {
|
||||
pc.logError("ICE failed, add a TURN server and see about:webrtc for more details");
|
||||
}
|
||||
else if (pc._hasTurnServer && !pc._iceGatheredRelayCandidates) {
|
||||
} else if (pc._hasTurnServer && !pc._iceGatheredRelayCandidates) {
|
||||
pc.logError("ICE failed, your TURN server appears to be broken, see about:webrtc for more details");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pc.logError("ICE failed, see about:webrtc for more details");
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,14 @@
|
||||
* 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/. */
|
||||
|
||||
this.EXPORTED_SYMBOLS = ['PeerConnectionIdp'];
|
||||
this.EXPORTED_SYMBOLS = ["PeerConnectionIdp"];
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
|
||||
Cu.import('resource://gre/modules/Services.jsm');
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
XPCOMUtils.defineLazyModuleGetter(this, 'IdpSandbox',
|
||||
'resource://gre/modules/media/IdpSandbox.jsm');
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "IdpSandbox",
|
||||
"resource://gre/modules/media/IdpSandbox.jsm");
|
||||
|
||||
/**
|
||||
* Creates an IdP helper.
|
||||
@ -27,12 +27,12 @@ function PeerConnectionIdp(win, timeout) {
|
||||
}
|
||||
|
||||
(function() {
|
||||
PeerConnectionIdp._mLinePattern = new RegExp('^m=', 'm');
|
||||
PeerConnectionIdp._mLinePattern = new RegExp("^m=", "m");
|
||||
// attributes are funny, the 'a' is case sensitive, the name isn't
|
||||
let pattern = '^a=[iI][dD][eE][nN][tT][iI][tT][yY]:(\\S+)';
|
||||
PeerConnectionIdp._identityPattern = new RegExp(pattern, 'm');
|
||||
pattern = '^a=[fF][iI][nN][gG][eE][rR][pP][rR][iI][nN][tT]:(\\S+) (\\S+)';
|
||||
PeerConnectionIdp._fingerprintPattern = new RegExp(pattern, 'm');
|
||||
let pattern = "^a=[iI][dD][eE][nN][tT][iI][tT][yY]:(\\S+)";
|
||||
PeerConnectionIdp._identityPattern = new RegExp(pattern, "m");
|
||||
pattern = "^a=[fF][iI][nN][gG][eE][rR][pP][rR][iI][nN][tT]:(\\S+) (\\S+)";
|
||||
PeerConnectionIdp._fingerprintPattern = new RegExp(pattern, "m");
|
||||
})();
|
||||
|
||||
PeerConnectionIdp.prototype = {
|
||||
@ -40,15 +40,15 @@ PeerConnectionIdp.prototype = {
|
||||
return !!this._idp;
|
||||
},
|
||||
|
||||
_resetAssertion: function() {
|
||||
_resetAssertion() {
|
||||
this.assertion = null;
|
||||
this.idpLoginUrl = null;
|
||||
},
|
||||
|
||||
setIdentityProvider: function(provider, protocol, username) {
|
||||
setIdentityProvider(provider, protocol, username) {
|
||||
this._resetAssertion();
|
||||
this.provider = provider;
|
||||
this.protocol = protocol || 'default';
|
||||
this.protocol = protocol || "default";
|
||||
this.username = username;
|
||||
if (this._idp) {
|
||||
if (this._idp.isSame(provider, protocol)) {
|
||||
@ -60,14 +60,14 @@ PeerConnectionIdp.prototype = {
|
||||
},
|
||||
|
||||
// start the IdP and do some error fixup
|
||||
start: function() {
|
||||
start() {
|
||||
return this._idp.start()
|
||||
.catch(e => {
|
||||
throw new this._win.DOMException(e.message, 'IdpError');
|
||||
throw new this._win.DOMException(e.message, "IdpError");
|
||||
});
|
||||
},
|
||||
|
||||
close: function() {
|
||||
close() {
|
||||
this._resetAssertion();
|
||||
this.provider = null;
|
||||
this.protocol = null;
|
||||
@ -77,7 +77,7 @@ PeerConnectionIdp.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
_getFingerprintsFromSdp: function(sdp) {
|
||||
_getFingerprintsFromSdp(sdp) {
|
||||
let fingerprints = {};
|
||||
let m = sdp.match(PeerConnectionIdp._fingerprintPattern);
|
||||
while (m) {
|
||||
@ -89,15 +89,15 @@ PeerConnectionIdp.prototype = {
|
||||
return Object.keys(fingerprints).map(k => fingerprints[k]);
|
||||
},
|
||||
|
||||
_isValidAssertion: function(assertion) {
|
||||
_isValidAssertion(assertion) {
|
||||
return assertion && assertion.idp &&
|
||||
typeof assertion.idp.domain === 'string' &&
|
||||
typeof assertion.idp.domain === "string" &&
|
||||
(!assertion.idp.protocol ||
|
||||
typeof assertion.idp.protocol === 'string') &&
|
||||
typeof assertion.assertion === 'string';
|
||||
typeof assertion.idp.protocol === "string") &&
|
||||
typeof assertion.assertion === "string";
|
||||
},
|
||||
|
||||
_getIdentityFromSdp: function(sdp) {
|
||||
_getIdentityFromSdp(sdp) {
|
||||
// a=identity is session level
|
||||
let idMatch;
|
||||
let mLineMatch = sdp.match(PeerConnectionIdp._mLinePattern);
|
||||
@ -113,12 +113,12 @@ PeerConnectionIdp.prototype = {
|
||||
try {
|
||||
assertion = JSON.parse(atob(idMatch[1]));
|
||||
} catch (e) {
|
||||
throw new this._win.DOMException('invalid identity assertion: ' + e,
|
||||
'InvalidSessionDescriptionError');
|
||||
throw new this._win.DOMException("invalid identity assertion: " + e,
|
||||
"InvalidSessionDescriptionError");
|
||||
}
|
||||
if (!this._isValidAssertion(assertion)) {
|
||||
throw new this._win.DOMException('assertion missing idp/idp.domain/assertion',
|
||||
'InvalidSessionDescriptionError');
|
||||
throw new this._win.DOMException("assertion missing idp/idp.domain/assertion",
|
||||
"InvalidSessionDescriptionError");
|
||||
}
|
||||
return assertion;
|
||||
},
|
||||
@ -133,7 +133,7 @@ PeerConnectionIdp.prototype = {
|
||||
* the fact that the RTCPeerConnection won't connect to a peer if the
|
||||
* fingerprint of the certificate they offer doesn't appear in the SDP.
|
||||
*/
|
||||
verifyIdentityFromSDP: function(sdp, origin) {
|
||||
verifyIdentityFromSDP(sdp, origin) {
|
||||
let identity = this._getIdentityFromSdp(sdp);
|
||||
let fingerprints = this._getFingerprintsFromSdp(sdp);
|
||||
if (!identity || fingerprints.length <= 0) {
|
||||
@ -150,18 +150,18 @@ PeerConnectionIdp.prototype = {
|
||||
* @param name (string) the name to validate
|
||||
* @throws if the name isn't valid
|
||||
*/
|
||||
_validateName: function(name) {
|
||||
_validateName(name) {
|
||||
let error = msg => {
|
||||
throw new this._win.DOMException('assertion name error: ' + msg,
|
||||
'IdpError');
|
||||
throw new this._win.DOMException("assertion name error: " + msg,
|
||||
"IdpError");
|
||||
};
|
||||
|
||||
if (typeof name !== 'string') {
|
||||
error('name not a string');
|
||||
if (typeof name !== "string") {
|
||||
error("name not a string");
|
||||
}
|
||||
let atIdx = name.indexOf('@');
|
||||
let atIdx = name.indexOf("@");
|
||||
if (atIdx <= 0) {
|
||||
error('missing authority in name from IdP');
|
||||
error("missing authority in name from IdP");
|
||||
}
|
||||
|
||||
// no third party assertions... for now
|
||||
@ -169,11 +169,11 @@ PeerConnectionIdp.prototype = {
|
||||
|
||||
// strip the port number, if present
|
||||
let provider = this.provider;
|
||||
let providerPortIdx = provider.indexOf(':');
|
||||
let providerPortIdx = provider.indexOf(":");
|
||||
if (providerPortIdx > 0) {
|
||||
provider = provider.substring(0, providerPortIdx);
|
||||
}
|
||||
let idnService = Components.classes['@mozilla.org/network/idn-service;1']
|
||||
let idnService = Components.classes["@mozilla.org/network/idn-service;1"]
|
||||
.getService(Components.interfaces.nsIIDNService);
|
||||
if (idnService.convertUTF8toACE(tail) !==
|
||||
idnService.convertUTF8toACE(provider)) {
|
||||
@ -187,35 +187,35 @@ PeerConnectionIdp.prototype = {
|
||||
* the message from the IdP proxy. That way, broken IdPs aren't likely to
|
||||
* cause catastrophic damage.
|
||||
*/
|
||||
_checkValidation: function(validation, sdpFingerprints) {
|
||||
_checkValidation(validation, sdpFingerprints) {
|
||||
let error = msg => {
|
||||
throw new this._win.DOMException('IdP validation error: ' + msg,
|
||||
'IdpError');
|
||||
throw new this._win.DOMException("IdP validation error: " + msg,
|
||||
"IdpError");
|
||||
};
|
||||
|
||||
if (!this.provider) {
|
||||
error('IdP closed');
|
||||
error("IdP closed");
|
||||
}
|
||||
|
||||
if (typeof validation !== 'object' ||
|
||||
typeof validation.contents !== 'string' ||
|
||||
typeof validation.identity !== 'string') {
|
||||
error('no payload in validation response');
|
||||
if (typeof validation !== "object" ||
|
||||
typeof validation.contents !== "string" ||
|
||||
typeof validation.identity !== "string") {
|
||||
error("no payload in validation response");
|
||||
}
|
||||
|
||||
let fingerprints;
|
||||
try {
|
||||
fingerprints = JSON.parse(validation.contents).fingerprint;
|
||||
} catch (e) {
|
||||
error('invalid JSON');
|
||||
error("invalid JSON");
|
||||
}
|
||||
|
||||
let isFingerprint = f =>
|
||||
(typeof f.digest === 'string') &&
|
||||
(typeof f.algorithm === 'string');
|
||||
(typeof f.digest === "string") &&
|
||||
(typeof f.algorithm === "string");
|
||||
if (!Array.isArray(fingerprints) || !fingerprints.every(isFingerprint)) {
|
||||
error('fingerprints must be an array of objects' +
|
||||
' with digest and algorithm attributes');
|
||||
error("fingerprints must be an array of objects" +
|
||||
" with digest and algorithm attributes");
|
||||
}
|
||||
|
||||
// everything in `innerSet` is found in `outerSet`
|
||||
@ -228,7 +228,7 @@ PeerConnectionIdp.prototype = {
|
||||
return (a.digest === b.digest) && (a.algorithm === b.algorithm);
|
||||
};
|
||||
if (!isSubsetOf(fingerprints, sdpFingerprints, compareFingerprints)) {
|
||||
error('the fingerprints must be covered by the assertion');
|
||||
error("the fingerprints must be covered by the assertion");
|
||||
}
|
||||
this._validateName(validation.identity);
|
||||
return validation;
|
||||
@ -237,7 +237,7 @@ PeerConnectionIdp.prototype = {
|
||||
/**
|
||||
* Asks the IdP proxy to verify an identity assertion.
|
||||
*/
|
||||
_verifyIdentity: function(assertion, fingerprints, origin) {
|
||||
_verifyIdentity(assertion, fingerprints, origin) {
|
||||
let p = this.start()
|
||||
.then(idp => this._wrapCrossCompartmentPromise(
|
||||
idp.validateAssertion(assertion, origin)))
|
||||
@ -250,7 +250,7 @@ PeerConnectionIdp.prototype = {
|
||||
* Enriches the given SDP with an `a=identity` line. getIdentityAssertion()
|
||||
* must have already run successfully, otherwise this does nothing to the sdp.
|
||||
*/
|
||||
addIdentityAttribute: function(sdp) {
|
||||
addIdentityAttribute(sdp) {
|
||||
if (!this.assertion) {
|
||||
return sdp;
|
||||
}
|
||||
@ -258,7 +258,7 @@ PeerConnectionIdp.prototype = {
|
||||
// yes, we assume that this matches; if it doesn't something is *wrong*
|
||||
let match = sdp.match(PeerConnectionIdp._mLinePattern);
|
||||
return sdp.substring(0, match.index) +
|
||||
'a=identity:' + this.assertion + '\r\n' +
|
||||
"a=identity:" + this.assertion + "\r\n" +
|
||||
sdp.substring(match.index);
|
||||
},
|
||||
|
||||
@ -268,17 +268,17 @@ PeerConnectionIdp.prototype = {
|
||||
* this when another call is still running, because it's not certain which
|
||||
* call will finish first and the final state will be similarly uncertain.
|
||||
*/
|
||||
getIdentityAssertion: function(fingerprint, origin) {
|
||||
getIdentityAssertion(fingerprint, origin) {
|
||||
if (!this.enabled) {
|
||||
throw new this._win.DOMException(
|
||||
'no IdP set, call setIdentityProvider() to set one', 'InvalidStateError');
|
||||
"no IdP set, call setIdentityProvider() to set one", "InvalidStateError");
|
||||
}
|
||||
|
||||
let [algorithm, digest] = fingerprint.split(' ', 2);
|
||||
let [algorithm, digest] = fingerprint.split(" ", 2);
|
||||
let content = {
|
||||
fingerprint: [{
|
||||
algorithm: algorithm,
|
||||
digest: digest
|
||||
algorithm,
|
||||
digest
|
||||
}]
|
||||
};
|
||||
|
||||
@ -289,8 +289,8 @@ PeerConnectionIdp.prototype = {
|
||||
origin, this.username)))
|
||||
.then(assertion => {
|
||||
if (!this._isValidAssertion(assertion)) {
|
||||
throw new this._win.DOMException('IdP generated invalid assertion',
|
||||
'IdpError');
|
||||
throw new this._win.DOMException("IdP generated invalid assertion",
|
||||
"IdpError");
|
||||
}
|
||||
// save the base64+JSON assertion, since that is all that is used
|
||||
this.assertion = btoa(JSON.stringify(assertion));
|
||||
@ -305,19 +305,19 @@ PeerConnectionIdp.prototype = {
|
||||
* they can chain into promises in the `this._win` compartment. Results need
|
||||
* to be cloned across; errors need to be converted.
|
||||
*/
|
||||
_wrapCrossCompartmentPromise: function(sandboxPromise) {
|
||||
_wrapCrossCompartmentPromise(sandboxPromise) {
|
||||
return new this._win.Promise((resolve, reject) => {
|
||||
sandboxPromise.then(
|
||||
result => resolve(Cu.cloneInto(result, this._win)),
|
||||
e => {
|
||||
let message = '' + (e.message || JSON.stringify(e) || 'IdP error');
|
||||
if (e.name === 'IdpLoginError') {
|
||||
if (typeof e.loginUrl === 'string') {
|
||||
let message = "" + (e.message || JSON.stringify(e) || "IdP error");
|
||||
if (e.name === "IdpLoginError") {
|
||||
if (typeof e.loginUrl === "string") {
|
||||
this.idpLoginUrl = e.loginUrl;
|
||||
}
|
||||
reject(new this._win.DOMException(message, 'IdpLoginError'));
|
||||
reject(new this._win.DOMException(message, "IdpLoginError"));
|
||||
} else {
|
||||
reject(new this._win.DOMException(message, 'IdpError'));
|
||||
reject(new this._win.DOMException(message, "IdpError"));
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -328,11 +328,11 @@ PeerConnectionIdp.prototype = {
|
||||
* than the specified time. Returns a promise that rejects if the timeout
|
||||
* elapses before `p` resolves.
|
||||
*/
|
||||
_applyTimeout: function(p) {
|
||||
_applyTimeout(p) {
|
||||
let timeout = new this._win.Promise(
|
||||
r => this._win.setTimeout(r, this._timeout))
|
||||
.then(() => {
|
||||
throw new this._win.DOMException('IdP timed out', 'IdpError');
|
||||
throw new this._win.DOMException("IdP timed out", "IdpError");
|
||||
});
|
||||
return this._win.Promise.race([ timeout, p ]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user