mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1176941 - Moving console warning to the current window, r=jib
--HG-- extra : rebase_source : 2f5845ec7055c8b748cda64a61a2cb313e980a57
This commit is contained in:
parent
2de024d96c
commit
c99d83fa88
@ -113,14 +113,14 @@ function createLocationFromURI(uri) {
|
|||||||
*
|
*
|
||||||
* @param domain (string) the domain of the IdP
|
* @param domain (string) the domain of the IdP
|
||||||
* @param protocol (string?) the protocol of the IdP [default: 'default']
|
* @param protocol (string?) the protocol of the IdP [default: 'default']
|
||||||
* @param doc (obj) the current document
|
* @param win (obj) the current window
|
||||||
* @throws if the domain or protocol aren't valid
|
* @throws if the domain or protocol aren't valid
|
||||||
*/
|
*/
|
||||||
function IdpSandbox(domain, protocol, doc) {
|
function IdpSandbox(domain, protocol, win) {
|
||||||
this.source = IdpSandbox.createIdpUri(domain, protocol || "default");
|
this.source = IdpSandbox.createIdpUri(domain, protocol || "default");
|
||||||
this.active = null;
|
this.active = null;
|
||||||
this.sandbox = null;
|
this.sandbox = null;
|
||||||
this.document = doc;
|
this.window = win;
|
||||||
}
|
}
|
||||||
|
|
||||||
IdpSandbox.checkDomain = function(domain) {
|
IdpSandbox.checkDomain = function(domain) {
|
||||||
@ -181,7 +181,7 @@ IdpSandbox.prototype = {
|
|||||||
|
|
||||||
start: function() {
|
start: function() {
|
||||||
if (!this.active) {
|
if (!this.active) {
|
||||||
this.active = ResourceLoader.load(this.source, this.document)
|
this.active = ResourceLoader.load(this.source, this.window.document)
|
||||||
.then(result => this._createSandbox(result));
|
.then(result => this._createSandbox(result));
|
||||||
}
|
}
|
||||||
return this.active;
|
return this.active;
|
||||||
@ -222,19 +222,12 @@ IdpSandbox.prototype = {
|
|||||||
Cu.evalInSandbox(result.data, this.sandbox,
|
Cu.evalInSandbox(result.data, this.sandbox,
|
||||||
'latest', result.request.URI.spec, 1);
|
'latest', result.request.URI.spec, 1);
|
||||||
} catch (e) {
|
} 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;
|
throw e;
|
||||||
}
|
}
|
||||||
// Capture all the details from the error and log them to the console.
|
this._logError(e);
|
||||||
// This can't rethrow anything else because that could leak information
|
|
||||||
// about the internal workings of the IdP across origins.
|
|
||||||
let scriptErrorClass = Cc["@mozilla.org/scripterror;1"];
|
|
||||||
let scriptError = scriptErrorClass.createInstance(Ci.nsIScriptError);
|
|
||||||
scriptError.init(e.message, e.fileName, null, e.lineNumber, e.columnNumber,
|
|
||||||
Ci.nsIScriptError.errorFlag, "content javascript");
|
|
||||||
let consoleService = Cc['@mozilla.org/consoleservice;1']
|
|
||||||
.getService(Ci.nsIConsoleService);
|
|
||||||
consoleService.logMessage(scriptError);
|
|
||||||
throw new Error('Error in IdP, check console for details');
|
throw new Error('Error in IdP, check console for details');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +237,23 @@ IdpSandbox.prototype = {
|
|||||||
return registrar;
|
return registrar;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
let winID = this.window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
|
||||||
|
let scriptError = Cc["@mozilla.org/scripterror;1"]
|
||||||
|
.createInstance(Ci.nsIScriptError);
|
||||||
|
scriptError.initWithWindowID(e.message, e.fileName, null,
|
||||||
|
e.lineNumber, e.columnNumber,
|
||||||
|
Ci.nsIScriptError.errorFlag,
|
||||||
|
"content javascript", winID);
|
||||||
|
let consoleService = Cc['@mozilla.org/consoleservice;1']
|
||||||
|
.getService(Ci.nsIConsoleService);
|
||||||
|
consoleService.logMessage(scriptError);
|
||||||
|
},
|
||||||
|
|
||||||
stop: function() {
|
stop: function() {
|
||||||
if (this.sandbox) {
|
if (this.sandbox) {
|
||||||
Cu.nukeSandbox(this.sandbox);
|
Cu.nukeSandbox(this.sandbox);
|
||||||
|
@ -56,7 +56,7 @@ PeerConnectionIdp.prototype = {
|
|||||||
}
|
}
|
||||||
this._idp.stop();
|
this._idp.stop();
|
||||||
}
|
}
|
||||||
this._idp = new IdpSandbox(provider, protocol, this._win.document);
|
this._idp = new IdpSandbox(provider, protocol, this._win);
|
||||||
},
|
},
|
||||||
|
|
||||||
// start the IdP and do some error fixup
|
// start the IdP and do some error fixup
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
function getIdentityAssertion(fpArray) {
|
function getIdentityAssertion(fpArray) {
|
||||||
var Cu = SpecialPowers.Cu;
|
var Cu = SpecialPowers.Cu;
|
||||||
var rtcid = Cu.import('resource://gre/modules/media/IdpSandbox.jsm');
|
var rtcid = Cu.import('resource://gre/modules/media/IdpSandbox.jsm');
|
||||||
var sandbox = new rtcid.IdpSandbox('example.com', 'idp.js', window.document);
|
var sandbox = new rtcid.IdpSandbox('example.com', 'idp.js', window);
|
||||||
return sandbox.start()
|
return sandbox.start()
|
||||||
.then(idp => SpecialPowers.wrap(idp)
|
.then(idp => SpecialPowers.wrap(idp)
|
||||||
.generateAssertion(JSON.stringify({ fingerprint: fpArray }),
|
.generateAssertion(JSON.stringify({ fingerprint: fpArray }),
|
||||||
|
@ -26,7 +26,7 @@ function test_domain_sandbox() {
|
|||||||
'', 12, null, diabolical, true ];
|
'', 12, null, diabolical, true ];
|
||||||
domains.forEach(function(domain) {
|
domains.forEach(function(domain) {
|
||||||
try {
|
try {
|
||||||
var idp = new IdpSandbox(domain, undefined, window.document);
|
var idp = new IdpSandbox(domain, undefined, window);
|
||||||
ok(false, 'IdpSandbox allowed a bad domain: ' + domain);
|
ok(false, 'IdpSandbox allowed a bad domain: ' + domain);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var str = (typeof domain === 'string') ? domain : typeof domain;
|
var str = (typeof domain === 'string') ? domain : typeof domain;
|
||||||
@ -40,7 +40,7 @@ function test_protocol_sandbox() {
|
|||||||
'\\evil', '%5cevil', 12, true, {} ];
|
'\\evil', '%5cevil', 12, true, {} ];
|
||||||
protos.forEach(function(proto) {
|
protos.forEach(function(proto) {
|
||||||
try {
|
try {
|
||||||
var idp = new IdpSandbox('example.com', proto, window.document);
|
var idp = new IdpSandbox('example.com', proto, window);
|
||||||
ok(false, 'IdpSandbox allowed a bad protocol: ' + proto);
|
ok(false, 'IdpSandbox allowed a bad protocol: ' + proto);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var str = (typeof proto === 'string') ? proto : typeof proto;
|
var str = (typeof proto === 'string') ? proto : typeof proto;
|
||||||
@ -56,7 +56,7 @@ function idpName(hash) {
|
|||||||
function makeSandbox(js) {
|
function makeSandbox(js) {
|
||||||
var name = js || idpName();
|
var name = js || idpName();
|
||||||
info('Creating a sandbox for the protocol: ' + name);
|
info('Creating a sandbox for the protocol: ' + name);
|
||||||
var sandbox = new IdpSandbox('example.com', name, window.document);
|
var sandbox = new IdpSandbox('example.com', name, window);
|
||||||
return sandbox.start().then(idp => SpecialPowers.wrap(idp));
|
return sandbox.start().then(idp => SpecialPowers.wrap(idp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user