Bug 982969 - DIALOG_CLOSED_BY_USER fires oncancel. r=jedp
authorSam Penrose <spenrose@mozilla.com>
Tue, 13 May 2014 13:56:30 -0700
changeset 183154 249b516e02d30a3007937985949b949bfc7ae1a9
parent 183153 0c59bda826ad7fb25f39821f18ee99a517f72893
child 183155 22e8b2a218da4ba3b08d31204321dfc2550d8fb4
push idunknown
push userunknown
push dateunknown
reviewersjedp
bugs982969
milestone32.0a1
Bug 982969 - DIALOG_CLOSED_BY_USER fires oncancel. r=jedp
b2g/components/FxAccountsMgmtService.jsm
b2g/components/FxAccountsUIGlue.js
toolkit/identity/FirefoxAccounts.jsm
--- a/b2g/components/FxAccountsMgmtService.jsm
+++ b/b2g/components/FxAccountsMgmtService.jsm
@@ -66,23 +66,28 @@ this.FxAccountsMgmtService = {
           eventName: aTopic.substring(aTopic.indexOf(":") + 1)
         });
         break;
     }
   },
 
   handleEvent: function(aEvent) {
     let msg = aEvent.detail;
-    log.debug("Got content msg " + JSON.stringify(msg));
+    log.debug("MgmtService got content event: " + JSON.stringify(msg));
     let self = FxAccountsMgmtService;
 
     if (!msg.id) {
       return;
     }
 
+    if (msg.error) {
+      self._onReject(msg.id, msg.error);
+      return;
+    }
+
     let data = msg.data;
     if (!data) {
       return;
     }
     // Backwards compatibility: handle accountId coming from Gaia
     if (data.accountId && typeof(data.email === "undefined")) {
       data.email = data.accountId;
       delete data.accountId;
--- a/b2g/components/FxAccountsUIGlue.js
+++ b/b2g/components/FxAccountsUIGlue.js
@@ -33,17 +33,17 @@ FxAccountsUIGlue.prototype = {
       let msg = result.detail;
       if (!msg || !msg.id || msg.id != id) {
         deferred.reject("InternalErrorWrongContentEvent");
         SystemAppProxy.removeEventListener("mozFxAccountsRPContentEvent",
                                            onContentEvent);
         return;
       }
 
-      log.debug("Got content event " + JSON.stringify(msg));
+      log.debug("UIGlue got content event " + JSON.stringify(msg));
 
       if (msg.error) {
         deferred.reject(msg);
       } else {
         deferred.resolve(msg.result);
       }
       SystemAppProxy.removeEventListener("mozFxAccountsRPContentEvent",
                                          onContentEvent);
--- a/toolkit/identity/FirefoxAccounts.jsm
+++ b/toolkit/identity/FirefoxAccounts.jsm
@@ -146,16 +146,20 @@ FxAccountsService.prototype = {
 
     this.fxAccountsManager.getAssertion(rp.audience, options).then(
       data => {
         log.debug("got assertion for " + rp.audience + ": " + data);
         this.doLogin(aRPId, data);
       },
       error => {
         log.error("get assertion failed: " + JSON.stringify(error));
+        // Cancellation is passed through an error channel; here we reroute.
+        if (error.details && (error.details.error == "DIALOG_CLOSED_BY_USER")) {
+          return this.doCancel(aRPId);
+        }
         this.doError(aRPId, error);
       }
     );
   },
 
   /**
    * Invoked when a user wishes to logout of a site (for instance, when clicking
    * on an in-content logout button).
@@ -193,57 +197,57 @@ FxAccountsService.prototype = {
         this._rpFlows.delete(key);
       }
     }
   },
 
   doLogin: function doLogin(aRpCallerId, aAssertion) {
     let rp = this._rpFlows.get(aRpCallerId);
     if (!rp) {
-      log.warn("doLogin found no rp to go with callerId " + aRpCallerId + "\n");
+      log.warn("doLogin found no rp to go with callerId " + aRpCallerId);
       return;
     }
 
     rp.doLogin(aAssertion);
   },
 
   doLogout: function doLogout(aRpCallerId) {
     let rp = this._rpFlows.get(aRpCallerId);
     if (!rp) {
-      log.warn("doLogout found no rp to go with callerId " + aRpCallerId + "\n");
+      log.warn("doLogout found no rp to go with callerId " + aRpCallerId);
       return;
     }
 
     rp.doLogout();
   },
 
   doReady: function doReady(aRpCallerId) {
     let rp = this._rpFlows.get(aRpCallerId);
     if (!rp) {
-      log.warn("doReady found no rp to go with callerId " + aRpCallerId + "\n");
+      log.warn("doReady found no rp to go with callerId " + aRpCallerId);
       return;
     }
 
     rp.doReady();
   },
 
   doCancel: function doCancel(aRpCallerId) {
     let rp = this._rpFlows.get(aRpCallerId);
     if (!rp) {
-      log.warn("doCancel found no rp to go with callerId " + aRpCallerId + "\n");
+      log.warn("doCancel found no rp to go with callerId " + aRpCallerId);
       return;
     }
 
     rp.doCancel();
   },
 
   doError: function doError(aRpCallerId, aError) {
     let rp = this._rpFlows.get(aRpCallerId);
     if (!rp) {
-      log.warn("doCancel found no rp to go with callerId " + aRpCallerId + "\n");
+      log.warn("doError found no rp to go with callerId " + aRpCallerId);
       return;
     }
 
     rp.doError(aError);
   }
 };
 
 this.FirefoxAccounts = new FxAccountsService();