Skip to content
Snippets Groups Projects
Commit 4a4dde42 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

Merge pull request #1447 from mozilla/updated_observer_api

implement updated observer API
parents be15b577 f9fc0801
No related branches found
No related tags found
No related merge requests found
......@@ -144,7 +144,7 @@ function checkAssertion(assertion) {
};
navigator.id.experimental.watch({
email: (storage.loggedInUser === 'null') ? null : storage.loggedInUser,
loggedInEmail: (storage.loggedInUser === 'null') ? null : storage.loggedInUser,
onready: function () {
loggit("onready");
var txt = serial++ + ' navigator.id ready at ' + (new Date).toString();
......@@ -157,6 +157,8 @@ navigator.id.experimental.watch({
$(".loginEvents > pre").text(txt);
checkAssertion(assertion);
$(".specify button.assertion").removeAttr('disabled');
},
onlogout: function () {
loggit("onlogout");
......@@ -167,8 +169,6 @@ navigator.id.experimental.watch({
$(document).ready(function() {
$(".specify button.assertion").click(function() {
$("pre").text("... waiting ...");
var requiredEmail = $.trim($('#requiredEmail').val());
if (!requiredEmail.length) requiredEmail = undefined;
......@@ -178,8 +178,8 @@ $(document).ready(function() {
privacyURL: $('#privacy').attr('checked') ? "/privacy.html" : undefined,
tosURL: $('#tos').attr('checked') ? "/TOS.html" : undefined,
requiredEmail: requiredEmail,
onclose: function() {
loggit("onclose");
oncancel: function() {
loggit("oncancel");
$(".specify button.assertion").removeAttr('disabled');
}
});
......
......@@ -91,7 +91,10 @@ BrowserID.Modules.RequiredEmail = (function() {
function cancel() {
this.close(secondaryAuth ? "cancel_state" : "cancel");
// The cancel button is only shown to a user who has to enter their
// password to go from "assertion" authentication to "password"
// authentication.
this.close("cancel_state");
}
var RequiredEmail = bid.Modules.PageModule.extend({
......
......@@ -62,7 +62,9 @@ BrowserID.State = (function() {
handleState("window_unload", function() {
if (!self.success) {
storage.setStagedOnBehalfOf("");
startAction("doCancel");
// do not call doCancel here, let winchan's cancel
// handling do the work. This gives us consistent semantics
// across browsers on the RP side of the WinChan.
}
});
......
......@@ -1012,6 +1012,9 @@
throw "non-function where function expected in parameters to navigator.id.watch()";
}
if (!options.onlogin) throw "'onlogin' is a required argument to navigator.id.watch()";
if (!options.onlogout) throw "'onlogout' is a required argument to navigator.id.watch()";
observers.login = options.onlogin || null;
observers.logout = options.onlogout || null;
observers.ready = options.onready || null;
......@@ -1021,10 +1024,10 @@
// check that the commChan was properly initialized before interacting with it.
// on unsupported browsers commChan might still be undefined, in which case
// we let the dialog display the "unsupported browser" message upon spawning.
if (typeof options.email !== 'undefined' && commChan) {
if (typeof options.loggedInEmail !== 'undefined' && commChan) {
commChan.notify({
method: 'loggedInUser',
params: options.email
params: options.loggedInEmail
});
}
}
......@@ -1092,9 +1095,12 @@
}
}
// complete
if (options && options.onclose) options.onclose();
delete options.onclose;
// if either err indicates the user canceled the signin (expected) or a
// null response was sent (unexpected), invoke the .oncancel() handler.
if (err === 'client closed window' || !r) {
if (options && options.oncancel) options.oncancel();
delete options.oncancel;
}
});
};
......@@ -1132,7 +1138,7 @@
}
}
});
options.onclose = function() {
options.oncancel = function() {
if (callback) {
callback(null);
callback = null;
......
......@@ -454,24 +454,7 @@
});
});
asyncTest("cancel normally raises the 'cancel' message", function() {
var email = "registered@testuser.com",
message = "cancel";
createController({
email: email,
ready: function() {
register(message, function(item, info) {
ok(true, message + " received");
start();
});
controller.cancel();
}
});
});
asyncTest("cancel with 'secondary_auth' raises the 'cancel_state' message", function() {
asyncTest("cancel raises the 'cancel_state' message", function() {
var email = "registered@testuser.com",
message = "cancel_state";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment