Bug 806605 - Replace loggedInEmail parameter with loggedInUser. r=benadida, a=blocking-basecamp
authorJed Parsons <jparsons@mozilla.com>
Wed, 31 Oct 2012 15:43:00 -0400
changeset 117391 1cb531b32040fa510e921c7e7512d3eb7d4d70fb
parent 117390 bc6356e7ebd0d6128b387b34cd0e052b380d17d6
child 117392 8f03aaf1f30655b340af93f68b2cc7f77d8dc466
push idunknown
push userunknown
push dateunknown
reviewersbenadida, blocking-basecamp
bugs806605
milestone18.0
Bug 806605 - Replace loggedInEmail parameter with loggedInUser. r=benadida, a=blocking-basecamp
b2g/components/SignInToWebsite.jsm
b2g/components/test/unit/head_identity.js
dom/identity/DOMIdentity.jsm
dom/identity/nsDOMIdentity.js
toolkit/identity/Identity.jsm
toolkit/identity/Makefile.in
toolkit/identity/MinimalIdentity.jsm
toolkit/identity/RelyingParty.jsm
toolkit/identity/tests/unit/head_identity.js
--- a/b2g/components/SignInToWebsite.jsm
+++ b/b2g/components/SignInToWebsite.jsm
@@ -139,17 +139,17 @@ let GaiaInterface = {
  */
 let Pipe = {
 
   /*
    * communicate - launch a gaia window with certain options and
    * provide a callback for handling messages.
    *
    * @param aRpOptions        options describing the Relying Party's
-   *        (dicitonary)      call, such as origin and loggedInEmail.
+   *        (dictionary)      call, such as origin and loggedInUser.
    *
    * @param aGaiaOptions      showUI:   boolean
    *        (dictionary)      message:  name of the message to emit
    *                                    (request, logout, watch)
    *
    * @param aMessageCallback  function to call on receipt of a
    *        (function)        do-method message.  These messages name
    *                          a method ('login', 'logout', etc.) and
--- a/b2g/components/test/unit/head_identity.js
+++ b/b2g/components/test/unit/head_identity.js
@@ -45,17 +45,17 @@ function uuid() {
   return uuidGenerator.generateUUID().toString();
 }
 
 // create a mock "doc" object, which the Identity Service
 // uses as a pointer back into the doc object
 function mockDoc(aIdentity, aOrigin, aDoFunc) {
   let mockedDoc = {};
   mockedDoc.id = uuid();
-  mockedDoc.loggedInEmail = aIdentity;
+  mockedDoc.loggedInUser = aIdentity;
   mockedDoc.origin = aOrigin;
   mockedDoc['do'] = aDoFunc;
   mockedDoc.doReady = partial(aDoFunc, 'ready');
   mockedDoc.doLogin = partial(aDoFunc, 'login');
   mockedDoc.doLogout = partial(aDoFunc, 'logout');
   mockedDoc.doError = partial(aDoFunc, 'error');
   mockedDoc.doCancel = partial(aDoFunc, 'cancel');
   mockedDoc.doCoffee = partial(aDoFunc, 'coffee');
--- a/dom/identity/DOMIdentity.jsm
+++ b/dom/identity/DOMIdentity.jsm
@@ -82,27 +82,27 @@ IDPAuthenticationContext.prototype = {
                               message);
   },
 
   doError: function IDPAC_doError(msg) {
     log("Authentication ERROR: " + msg);
   },
 };
 
-function RPWatchContext(aID, aOrigin, aLoggedInEmail, aTargetMM) {
+function RPWatchContext(aID, aOrigin, aLoggedInUser, aTargetMM) {
   this._id = aID;
   this._origin = aOrigin;
-  this._loggedInEmail = aLoggedInEmail;
+  this._loggedInUser = aLoggedInUser;
   this._mm = aTargetMM;
 }
 
 RPWatchContext.prototype = {
   get id() this._id,
   get origin() this._origin,
-  get loggedInEmail() this._loggedInEmail,
+  get loggedInUser() this._loggedInUser,
 
   doLogin: function RPWatchContext_onlogin(aAssertion) {
     log("doLogin: " + this.id);
     let message = new IDDOMMessage(this.id);
     message.assertion = aAssertion;
     this._mm.sendAsyncMessage("Identity:RP:Watch:OnLogin", message);
   },
 
@@ -216,17 +216,17 @@ this.DOMIdentity = {
     aContext._mm.sendAsyncMessage("Identity:ResetState", message);
   },
 
   _watch: function DOMIdentity__watch(message, targetMM) {
     log("DOMIdentity__watch: " + message.id);
     // Pass an object with the watch members to Identity.jsm so it can call the
     // callbacks.
     let context = new RPWatchContext(message.id, message.origin,
-                                     message.loggedInEmail, targetMM);
+                                     message.loggedInUser, targetMM);
     IdentityService.RP.watch(context);
   },
 
   _request: function DOMIdentity__request(message) {
     IdentityService.RP.request(message.id, message);
   },
 
   _logout: function DOMIdentity__logout(message) {
--- a/dom/identity/nsDOMIdentity.js
+++ b/dom/identity/nsDOMIdentity.js
@@ -11,16 +11,17 @@ const PREF_ENABLED = "dom.identity.enabl
 
 // Maximum length of a string that will go through IPC
 const MAX_STRING_LENGTH = 2048;
 // Maximum number of times navigator.id.request can be called for a document
 const MAX_RP_CALLS = 100;
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/IdentityUtils.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
                                    "@mozilla.org/childprocessmessagemanager;1",
                                    "nsIMessageSender");
 
 // This is the child process corresponding to nsIDOMIdentity.
 
 
@@ -73,34 +74,40 @@ nsDOMIdentity.prototype = {
     // Optional callback "onready"
     if (aOptions["onready"]
         && typeof(aOptions['onready']) !== "function") {
       throw new Error("onready must be a function");
     }
 
     let message = this.DOMIdentityMessage();
 
-    // loggedInEmail
-    message.loggedInEmail = null;
-    let emailType = typeof(aOptions["loggedInEmail"]);
-    if (aOptions["loggedInEmail"] && aOptions["loggedInEmail"] !== "undefined") {
+    // loggedInUser vs loggedInEmail
+    // https://developer.mozilla.org/en-US/docs/DOM/navigator.id.watch
+    // This parameter, loggedInUser, was renamed from loggedInEmail in early
+    // September, 2012. Both names will continue to work for the time being,
+    // but code should be changed to use loggedInUser instead.
+    checkRenamed(aOptions, "loggedInEmail", "loggedInUser");
+    message["loggedInUser"] = aOptions["loggedInUser"];
+
+    let emailType = typeof(aOptions["loggedInUser"]);
+    if (aOptions["loggedInUser"] && aOptions["loggedInUser"] !== "undefined") {
       if (emailType !== "string") {
-        throw new Error("loggedInEmail must be a String or null");
+        throw new Error("loggedInUser must be a String or null");
       }
 
       // TODO: Bug 767610 - check email format.
       // See nsHTMLInputElement::IsValidEmailAddress
-      if (aOptions["loggedInEmail"].indexOf("@") == -1
-          || aOptions["loggedInEmail"].length > MAX_STRING_LENGTH) {
-        throw new Error("loggedInEmail is not valid");
+      if (aOptions["loggedInUser"].indexOf("@") == -1
+          || aOptions["loggedInUser"].length > MAX_STRING_LENGTH) {
+        throw new Error("loggedInUser is not valid");
       }
-      // Set loggedInEmail in this block that "undefined" doesn't get through.
-      message.loggedInEmail = aOptions.loggedInEmail;
+      // Set loggedInUser in this block that "undefined" doesn't get through.
+      message.loggedInUser = aOptions.loggedInUser;
     }
-    this._log("loggedInEmail: " + message.loggedInEmail);
+    this._log("loggedInUser: " + message.loggedInUser);
 
     this._rpWatcher = aOptions;
     this._identityInternal._mm.sendAsyncMessage("Identity:RP:Watch", message);
   },
 
   request: function nsDOMIdentity_request(aOptions) {
     let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor)
                            .getInterface(Ci.nsIDOMWindowUtils);
--- a/toolkit/identity/Identity.jsm
+++ b/toolkit/identity/Identity.jsm
@@ -126,17 +126,17 @@ IDService.prototype = {
       return;
     }
 
     // It's possible that we are in the process of provisioning an
     // identity.
     let provId = rp.provId;
 
     let rpLoginOptions = {
-      loggedInEmail: aIdentity,
+      loggedInUser: aIdentity,
       origin: rp.origin
     };
     log("selectIdentity: provId:", provId, "origin:", rp.origin);
 
     // Once we have a cert, and once the user is authenticated with the
     // IdP, we can generate an assertion and deliver it to the doc.
     let self = this;
     this.RP._generateAssertion(rp.origin, aIdentity, function hadReadyAssertion(err, assertion) {
--- a/toolkit/identity/Makefile.in
+++ b/toolkit/identity/Makefile.in
@@ -25,16 +25,17 @@ XPIDLSRCS = \
   nsIIdentityCryptoService.idl \
   $(NULL)
 
 CPPSRCS = \
   IdentityCryptoService.cpp \
   $(NULL)
 
 EXTRA_JS_MODULES = \
+	IdentityUtils.jsm \
 	Identity.jsm \
 	IdentityProvider.jsm \
 	IdentityStore.jsm \
 	jwcrypto.jsm \
 	LogUtils.jsm \
 	MinimalIdentity.jsm \
 	RelyingParty.jsm \
 	Sandbox.jsm \
--- a/toolkit/identity/MinimalIdentity.jsm
+++ b/toolkit/identity/MinimalIdentity.jsm
@@ -80,38 +80,37 @@ IDService.prototype = {
   /**
    * Register a listener for a given windowID as a result of a call to
    * navigator.id.watch().
    *
    * @param aCaller
    *        (Object)  an object that represents the caller document, and
    *                  is expected to have properties:
    *                  - id (unique, e.g. uuid)
-   *                  - loggedInEmail (string or null)
+   *                  - loggedInUser (string or null)
    *                  - origin (string)
    *
    *                  and a bunch of callbacks
    *                  - doReady()
    *                  - doLogin()
    *                  - doLogout()
    *                  - doError()
    *                  - doCancel()
    *
    */
   watch: function watch(aRpCaller) {
     log("watch: caller keys:", Object.keys(aRpCaller));
     log("watch: rpcaller:", aRpCaller);
     // store the caller structure and notify the UI observers
 
-    // note that, unfortunately, what here is loggedInEmail is called
-    // loggedInUser in the native API.
     this._rpFlows[aRpCaller.id] = aRpCaller;
+
     let options = {rpId: aRpCaller.id,
                    origin: aRpCaller.origin,
-                   loggedInUser: aRpCaller.loggedInEmail || null};
+                   loggedInUser: aRpCaller.loggedInUser};
     log("sending identity-controller-watch:", options);
     Services.obs.notifyObservers({wrappedJSObject: options},"identity-controller-watch", null);
   },
 
   /**
    * Initiate a login with user interaction as a result of a call to
    * navigator.id.request().
    *
--- a/toolkit/identity/RelyingParty.jsm
+++ b/toolkit/identity/RelyingParty.jsm
@@ -65,17 +65,17 @@ IdentityRelyingParty.prototype = {
   /**
    * Register a listener for a given windowID as a result of a call to
    * navigator.id.watch().
    *
    * @param aCaller
    *        (Object)  an object that represents the caller document, and
    *                  is expected to have properties:
    *                  - id (unique, e.g. uuid)
-   *                  - loggedInEmail (string or null)
+   *                  - loggedInUser (string or null)
    *                  - origin (string)
    *
    *                  and a bunch of callbacks
    *                  - doReady()
    *                  - doLogin()
    *                  - doLogout()
    *                  - doError()
    *                  - doCancel()
@@ -83,51 +83,51 @@ IdentityRelyingParty.prototype = {
    */
   watch: function watch(aRpCaller) {
     this._rpFlows[aRpCaller.id] = aRpCaller;
     let origin = aRpCaller.origin;
     let state = this._store.getLoginState(origin) || { isLoggedIn: false, email: null };
 
     log("watch: rpId:", aRpCaller.id,
         "origin:", origin,
-        "loggedInEmail:", aRpCaller.loggedInEmail,
+        "loggedInUser:", aRpCaller.loggedInUser,
         "loggedIn:", state.isLoggedIn,
         "email:", state.email);
 
     // If the user is already logged in, then there are three cases
     // to deal with:
     //
     //   1. the email is valid and unchanged:  'ready'
     //   2. the email is null:                 'login'; 'ready'
     //   3. the email has changed:             'login'; 'ready'
     if (state.isLoggedIn) {
-      if (state.email && aRpCaller.loggedInEmail === state.email) {
+      if (state.email && aRpCaller.loggedInUser === state.email) {
         this._notifyLoginStateChanged(aRpCaller.id, state.email);
         return aRpCaller.doReady();
 
-      } else if (aRpCaller.loggedInEmail === null) {
+      } else if (aRpCaller.loggedInUser === null) {
         // Generate assertion for existing login
-        let options = {loggedInEmail: state.email, origin: origin};
+        let options = {loggedInUser: state.email, origin: origin};
         return this._doLogin(aRpCaller, options);
 
       } else {
-        // A loggedInEmail different from state.email has been specified.
+        // A loggedInUser different from state.email has been specified.
         // Change login identity.
 
-        let options = {loggedInEmail: state.email, origin: origin};
+        let options = {loggedInUser: state.email, origin: origin};
         return this._doLogin(aRpCaller, options);
       }
 
     // If the user is not logged in, there are two cases:
     //
     //   1. a logged in email was provided: 'ready'; 'logout'
     //   2. not logged in, no email given:  'ready';
 
     } else {
-      if (aRpCaller.loggedInEmail) {
+      if (aRpCaller.loggedInUser) {
         return this._doLogout(aRpCaller, {origin: origin});
 
       } else {
         return aRpCaller.doReady();
       }
     }
   },
 
@@ -136,18 +136,18 @@ IdentityRelyingParty.prototype = {
    * on login
    *
    * Note that this calls _getAssertion
    */
   _doLogin: function _doLogin(aRpCaller, aOptions, aAssertion) {
     log("_doLogin: rpId:", aRpCaller.id, "origin:", aOptions.origin);
 
     let loginWithAssertion = function loginWithAssertion(assertion) {
-      this._store.setLoginState(aOptions.origin, true, aOptions.loggedInEmail);
-      this._notifyLoginStateChanged(aRpCaller.id, aOptions.loggedInEmail);
+      this._store.setLoginState(aOptions.origin, true, aOptions.loggedInUser);
+      this._notifyLoginStateChanged(aRpCaller.id, aOptions.loggedInUser);
       aRpCaller.doLogin(assertion);
       aRpCaller.doReady();
     }.bind(this);
 
     if (aAssertion) {
       loginWithAssertion(aAssertion);
     } else {
       this._getAssertion(aOptions, function gotAssertion(err, assertion) {
@@ -285,17 +285,17 @@ IdentityRelyingParty.prototype = {
    *          "audience"      : The audience for which the assertion is to be
    *                            issued. If this property is not set an exception
    *                            will be thrown.
    *
    *        Any properties not listed above will be ignored.
    */
   _getAssertion: function _getAssertion(aOptions, aCallback) {
     let audience = aOptions.origin;
-    let email = aOptions.loggedInEmail || this.getDefaultEmailForOrigin(audience);
+    let email = aOptions.loggedInUser || this.getDefaultEmailForOrigin(audience);
     log("_getAssertion: audience:", audience, "email:", email);
     if (!audience) {
       throw "audience required for _getAssertion";
     }
 
     // We might not have any identity info for this email
     if (!this._store.fetchIdentity(email)) {
       this._store.addIdentity(email, null, null);
--- a/toolkit/identity/tests/unit/head_identity.js
+++ b/toolkit/identity/tests/unit/head_identity.js
@@ -95,17 +95,17 @@ function uuid() {
   return uuidGenerator.generateUUID().toString();
 }
 
 // create a mock "doc" object, which the Identity Service
 // uses as a pointer back into the doc object
 function mock_doc(aIdentity, aOrigin, aDoFunc) {
   let mockedDoc = {};
   mockedDoc.id = uuid();
-  mockedDoc.loggedInEmail = aIdentity;
+  mockedDoc.loggedInUser = aIdentity;
   mockedDoc.origin = aOrigin;
   mockedDoc['do'] = aDoFunc;
   mockedDoc.doReady = partial(aDoFunc, 'ready');
   mockedDoc.doLogin = partial(aDoFunc, 'login');
   mockedDoc.doLogout = partial(aDoFunc, 'logout');
   mockedDoc.doError = partial(aDoFunc, 'error');
   mockedDoc.doCancel = partial(aDoFunc, 'cancel');
   mockedDoc.doCoffee = partial(aDoFunc, 'coffee');