Bug 806605 - Replace loggedInEmail parameter with loggedInUser. r=benadida

This commit is contained in:
Jed Parsons 2012-11-01 19:23:14 -04:00
parent 61ff3d5271
commit 36f266a34c
10 changed files with 87 additions and 34 deletions

View File

@ -143,7 +143,7 @@ let Pipe = {
* 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

View File

@ -50,7 +50,7 @@ function uuid() {
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');

View File

@ -87,17 +87,17 @@ IDPAuthenticationContext.prototype = {
},
};
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);
@ -221,7 +221,7 @@ this.DOMIdentity = {
// 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);
},

View File

@ -16,6 +16,7 @@ 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",
@ -78,24 +79,30 @@ nsDOMIdentity.prototype = {
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);

View File

@ -131,7 +131,7 @@ IDService.prototype = {
let provId = rp.provId;
let rpLoginOptions = {
loggedInEmail: aIdentity,
loggedInUser: aIdentity,
origin: rp.origin
};
log("selectIdentity: provId:", provId, "origin:", rp.origin);

View File

@ -0,0 +1,46 @@
/* -*- Mode: js2; js2-basic-offset: 2; indent-tabs-mode: nil; -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// functions common to Identity.jsm and MinimalIdentity.jsm
"use strict";
const EXPORTED_SYMBOLS = ["checkRenamed"];
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Logger",
"resource://gre/modules/identity/LogUtils.jsm");
function log(...aMessageArgs) {
Logger.log.apply(Logger, ["Identity"].concat(aMessageArgs));
}
function defined(item) {
return typeof item !== 'undefined';
}
function checkDeprecated(aOptions, aField) {
if (defined(aOptions[aField])) {
log("WARNING: field is deprecated:", aField);
return true;
}
return false;
}
let checkRenamed = function checkRenamed(aOptions, aOldName, aNewName) {
if (defined(aOptions[aOldName]) &&
defined(aOptions[aNewName])) {
let err = "You cannot provide both " + aOldName + " and " + aNewName;
Logger.reportError(err);
throw new Error(err);
}
if (checkDeprecated(aOptions, aOldName)) {
aOptions[aNewName] = aOptions[aOldName];
delete(aOptions[aOldName]);
}
};

View File

@ -30,6 +30,7 @@ CPPSRCS = \
$(NULL)
EXTRA_JS_MODULES = \
IdentityUtils.jsm \
Identity.jsm \
IdentityProvider.jsm \
IdentityStore.jsm \

View File

@ -85,7 +85,7 @@ IDService.prototype = {
* (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
@ -101,12 +101,11 @@ IDService.prototype = {
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);
},

View File

@ -70,7 +70,7 @@ IdentityRelyingParty.prototype = {
* (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
@ -88,7 +88,7 @@ IdentityRelyingParty.prototype = {
log("watch: rpId:", aRpCaller.id,
"origin:", origin,
"loggedInEmail:", aRpCaller.loggedInEmail,
"loggedInUser:", aRpCaller.loggedInUser,
"loggedIn:", state.isLoggedIn,
"email:", state.email);
@ -99,20 +99,20 @@ IdentityRelyingParty.prototype = {
// 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);
}
@ -122,7 +122,7 @@ IdentityRelyingParty.prototype = {
// 2. not logged in, no email given: 'ready';
} else {
if (aRpCaller.loggedInEmail) {
if (aRpCaller.loggedInUser) {
return this._doLogout(aRpCaller, {origin: origin});
} else {
@ -141,8 +141,8 @@ IdentityRelyingParty.prototype = {
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);
@ -290,7 +290,7 @@ IdentityRelyingParty.prototype = {
*/
_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";

View File

@ -100,7 +100,7 @@ function uuid() {
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');