Bug 1022193 - Add a "forceIdSelection" to navigator.getMobileIdAssertion. Part 3: MobileIdentityManager. r=jedp, a=lmandel
authorFernando Jiménez <ferjmoreno@gmail.com>
Fri, 27 Jun 2014 01:18:21 +0200
changeset 208929 778cae6edf6dc64626be815dfe28dbb70784e64c
parent 208928 7f0e02fcef8518fe2944f757e15a3229ec182407
child 208930 6fe99dfd2bfc5557f9e847319645ba1843cc693a
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjedp, lmandel
bugs1022193
milestone32.0a2
Bug 1022193 - Add a "forceIdSelection" to navigator.getMobileIdAssertion. Part 3: MobileIdentityManager. r=jedp, a=lmandel
services/mobileid/MobileIdentityManager.jsm
--- a/services/mobileid/MobileIdentityManager.jsm
+++ b/services/mobileid/MobileIdentityManager.jsm
@@ -83,18 +83,17 @@ let MobileIdentityManager = {
 
     let msg = aMessage.json;
 
     // We save the message target message manager so we can later dispatch
     // back messages without broadcasting to all child processes.
     let promiseId = msg.promiseId;
     this.messageManagers[promiseId] = aMessage.target;
 
-    this.getMobileIdAssertion(aMessage.principal, promiseId,
-                              msg.msisdn, msg.prompt);
+    this.getMobileIdAssertion(aMessage.principal, promiseId, msg.options);
   },
 
   observe: function(subject, topic, data) {
     if (topic != "xpcom-shutdown") {
       return;
     }
 
     ppmm.removeMessageListener(GET_ASSERTION_IPC_MSG, this);
@@ -696,37 +695,43 @@ let MobileIdentityManager = {
           }, deferred.reject
         );
       }
     );
 
     return deferred.promise;
   },
 
-  getMobileIdAssertion: function(aPrincipal, aPromiseId) {
+  getMobileIdAssertion: function(aPrincipal, aPromiseId, aOptions) {
     log.debug("getMobileIdAssertion ${}", aPrincipal);
 
     let uri = Services.io.newURI(aPrincipal.origin, null, null);
     let principal = securityManager.getAppCodebasePrincipal(
       uri, aPrincipal.appid, aPrincipal.isInBrowserElement);
     let manifestURL = appsService.getManifestURLByLocalId(aPrincipal.appId);
 
     // First of all we look if we already have credentials for this origin.
     // If we don't have credentials it means that it is the first time that
     // the caller requested an assertion.
     return this.credStore.getByOrigin(aPrincipal.origin)
     .then(
       (creds) => {
         log.debug("creds ${creds} - ${origin}", { creds: creds,
-                                                  origin: aPrincipal.origin});
+                                                  origin: aPrincipal.origin });
         if (!creds || !creds.sessionToken) {
           log.debug("No credentials");
           return;
         }
 
+        // Even if we already have credentials for this origin, the consumer of
+        // the API might want to force the identity selection dialog.
+        if (aOptions.forceSelection) {
+          return this.promptAndVerify(principal, manifestURL, creds);
+        }
+
         // It is possible that the ICC associated with the stored
         // credentials is not present in the device anymore, so we ask the
         // user if she still wants to use it anyway or if she prefers to use
         // another phone number.
         // If the credentials are associated with an external SIM or there is
         // no SIM in the device, we just return the credentials.
         if (this.iccInfo && creds.iccId) {
           for (let i = 0; i < this.iccInfo.length; i++) {
@@ -734,16 +739,17 @@ let MobileIdentityManager = {
               return creds;
             }
           }
           // At this point we know that the SIM associated with the credentials
           // is not present in the device any more, so we need to ask the user
           // what to do.
           return this.promptAndVerify(principal, manifestURL, creds);
         }
+
         return creds;
       }
     )
     .then(
       (creds) => {
         // Even if we have credentails it is possible that the user has
         // removed the permission to share its mobile id with this origin, so
         // we check the permission and if it is not granted, we ask the user