Bug 1176941 - Moving console warning to the current window, r=jib

--HG--
extra : rebase_source : 2f5845ec7055c8b748cda64a61a2cb313e980a57
This commit is contained in:
Martin Thomson 2015-08-28 15:40:44 -07:00
parent 2de024d96c
commit c99d83fa88
4 changed files with 29 additions and 19 deletions

View File

@ -113,14 +113,14 @@ function createLocationFromURI(uri) {
*
* @param domain (string) the domain of the IdP
* @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
*/
function IdpSandbox(domain, protocol, doc) {
function IdpSandbox(domain, protocol, win) {
this.source = IdpSandbox.createIdpUri(domain, protocol || "default");
this.active = null;
this.sandbox = null;
this.document = doc;
this.window = win;
}
IdpSandbox.checkDomain = function(domain) {
@ -181,7 +181,7 @@ IdpSandbox.prototype = {
start: function() {
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));
}
return this.active;
@ -222,19 +222,12 @@ IdpSandbox.prototype = {
Cu.evalInSandbox(result.data, this.sandbox,
'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') {
throw e;
}
// 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.
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);
this._logError(e);
throw new Error('Error in IdP, check console for details');
}
@ -244,6 +237,23 @@ IdpSandbox.prototype = {
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() {
if (this.sandbox) {
Cu.nukeSandbox(this.sandbox);

View File

@ -56,7 +56,7 @@ PeerConnectionIdp.prototype = {
}
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

View File

@ -12,7 +12,7 @@
function getIdentityAssertion(fpArray) {
var Cu = SpecialPowers.Cu;
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()
.then(idp => SpecialPowers.wrap(idp)
.generateAssertion(JSON.stringify({ fingerprint: fpArray }),

View File

@ -26,7 +26,7 @@ function test_domain_sandbox() {
'', 12, null, diabolical, true ];
domains.forEach(function(domain) {
try {
var idp = new IdpSandbox(domain, undefined, window.document);
var idp = new IdpSandbox(domain, undefined, window);
ok(false, 'IdpSandbox allowed a bad domain: ' + domain);
} catch (e) {
var str = (typeof domain === 'string') ? domain : typeof domain;
@ -40,7 +40,7 @@ function test_protocol_sandbox() {
'\\evil', '%5cevil', 12, true, {} ];
protos.forEach(function(proto) {
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);
} catch (e) {
var str = (typeof proto === 'string') ? proto : typeof proto;
@ -56,7 +56,7 @@ function idpName(hash) {
function makeSandbox(js) {
var name = js || idpName();
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));
}