diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 35c684299c2acf5a966be36473775ba832312e37..39d9ffc2b72b4d8f56fc55bc3b4e01d9c1d47235 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -103,6 +103,10 @@ $.Controller("Dialog", {}, { var issuer = storedID.issuer; var audience = this.remoteOrigin.replace(/^(http|https):\/\//, ''); var assertion = CryptoStubs.createAssertion(audience, email, privkey, issuer); + // Clear onerror before the call to onsuccess - the code to onsuccess + // calls window.close, which would trigger the onerror callback if we + // tried this afterwards. + this.onerror = null; this.onsuccess(assertion); }, @@ -219,6 +223,14 @@ $.Controller("Dialog", {}, { this.onerror = onerror; this.remoteOrigin = origin_url.replace(/^.*:\/\//, ""); this.doStart(); + var me=this; + $(window).bind("unload", function() { + // In the success case, me.onerror will have been cleared before unload + // is triggered. + if (me.onerror) { + me.onerror("canceled"); + } + }); }, doStart: function() { @@ -550,3 +562,5 @@ $.Controller("Dialog", {}, { } }); + +