From c4fa810bcfc7014ac0b0856e30ae6509f65e64fe Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Mon, 1 Aug 2011 13:50:05 -0700
Subject: [PATCH] Clear onerror so it is not called in success case

---
 .../static/dialog/controllers/dialog_controller.js  | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js
index 2904c0468..39d9ffc2b 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,8 +223,13 @@ $.Controller("Dialog", {}, {
       this.onerror = onerror;
       this.remoteOrigin = origin_url.replace(/^.*:\/\//, "");
       this.doStart();
-      $(window).bind('unload', function() {
-        onerror("canceled");
+      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");
+        }
       });
     },
 
-- 
GitLab