Index: chrome/browser/resources/gaia_auth_host/authenticator.js |
diff --git a/chrome/browser/resources/gaia_auth_host/authenticator.js b/chrome/browser/resources/gaia_auth_host/authenticator.js |
index baf6d8e1a0667a4ea8982565d5d20972e8a03c64..3477b5434ab3ea4a4004ac1770ee563b1fc6daa2 100644 |
--- a/chrome/browser/resources/gaia_auth_host/authenticator.js |
+++ b/chrome/browser/resources/gaia_auth_host/authenticator.js |
@@ -49,17 +49,12 @@ cr.define('cr.login', function() { |
* Initializes the authenticator component. |
* @param {webview|string} webview The webview element or its ID to host IdP |
* web pages. |
- * @param {Authenticator.Listener=} opt_listener An optional listener for |
- * authentication events. |
* @constructor |
- * @extends {cr.EventTarget} |
*/ |
- function Authenticator(webview, opt_listener) { |
+ function Authenticator(webview) { |
this.webview_ = typeof webview == 'string' ? $(webview) : webview; |
assert(this.webview_); |
- this.listener_ = opt_listener || null; |
- |
this.email_ = null; |
this.password_ = null; |
this.gaiaId_ = null, |
@@ -73,6 +68,7 @@ cr.define('cr.login', function() { |
this.continueUrlWithoutParams_ = null; |
this.initialFrameUrl_ = null; |
this.reloadUrl_ = null; |
+ this.trusted_ = true; |
} |
// TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the |
@@ -80,48 +76,6 @@ cr.define('cr.login', function() { |
Authenticator.prototype = Object.create(cr.EventTarget.prototype); |
/** |
- * An interface for receiving notifications upon authentication events. |
- * @interface |
- */ |
- Authenticator.Listener = function() {}; |
- |
- /** |
- * Invoked when authentication UI is ready. |
- */ |
- Authenticator.Listener.prototype.onReady = function(e) {}; |
- |
- /** |
- * Invoked when authentication is completed successfully with credential data. |
- * A credential data object looks like this: |
- * <pre> |
- * {@code |
- * { |
- * email: 'xx@gmail.com', |
- * password: 'xxxx', // May be null or empty. |
- * usingSAML: false, |
- * chooseWhatToSync: false, |
- * skipForNow: false, |
- * sessionIndex: '0' |
- * } |
- * } |
- * </pre> |
- * @param {Object} credentials A credential data object. |
- */ |
- Authenticator.Listener.prototype.onSuccess = function(credentials) {}; |
- |
- /** |
- * Invoked when the requested URL does not fit the container. |
- * @param {string} url Request URL. |
- */ |
- Authenticator.Listener.prototype.onResize = function(url) {}; |
- |
- /** |
- * Invoked when a new window event is fired. |
- * @param {Event} e Event object. |
- */ |
- Authenticator.Listener.prototype.onNewWindow = function(e) {}; |
- |
- /** |
* Loads the authenticator component with the given parameters. |
* @param {AuthMode} authMode Authorization mode. |
* @param {Object} data Parameters for the authorization flow. |
@@ -141,6 +95,8 @@ cr.define('cr.login', function() { |
this.webview_.src = this.reloadUrl_; |
this.webview_.addEventListener( |
'newwindow', this.onNewWindow_.bind(this)); |
+ this.webview_.addEventListener( |
+ 'loadstop', this.onLoadStop_.bind(this)); |
this.webview_.request.onCompleted.addListener( |
this.onRequestCompleted_.bind(this), |
{urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'], |
@@ -182,6 +138,10 @@ cr.define('cr.login', function() { |
*/ |
Authenticator.prototype.onRequestCompleted_ = function(details) { |
var currentUrl = details.url; |
+ if (currentUrl.indexOf('https') != 0) { |
+ this.trusted_ = false; |
noms (inactive)
2014/12/19 19:48:59
nit: no {}
Roger Tawa OOO till Jul 10th
2014/12/19 22:23:59
The convention in this file is to include { } in t
|
+ } |
+ |
if (currentUrl.lastIndexOf(this.continueUrlWithoutParams_, 0) == 0) { |
if (currentUrl.indexOf('ntp=1') >= 0) { |
this.skipForNow_ = true; |
@@ -201,8 +161,8 @@ cr.define('cr.login', function() { |
} |
} |
} |
- if (!isEmbeddedPage && this.listener_) { |
- this.listener_.onResize(currentUrl); |
+ if (!isEmbeddedPage) { |
+ this.dispatchEvent(new CustomEvent('resize', {detail: currentUrl})); |
return; |
} |
} |
@@ -210,13 +170,6 @@ cr.define('cr.login', function() { |
if (currentUrl.lastIndexOf(this.idpOrigin_) == 0) { |
this.webview_.contentWindow.postMessage({}, currentUrl); |
} |
- |
- if (!this.loaded_) { |
- this.loaded_ = true; |
- if (this.listener_) { |
- this.listener_.onReady(); |
- } |
- } |
}; |
/** |
@@ -277,22 +230,21 @@ cr.define('cr.login', function() { |
* @private |
*/ |
Authenticator.prototype.onAuthCompleted_ = function() { |
- if (!this.listener_) { |
- return; |
- } |
- |
if (!this.email_ && !this.skipForNow_) { |
this.webview_.src = this.initialFrameUrl_; |
return; |
} |
- this.listener_.onSuccess({email: this.email_, |
- gaiaId: this.gaiaId_, |
- password: this.password_, |
- usingSAML: this.authFlow_ == AuthFlow.SAML, |
- chooseWhatToSync: this.chooseWhatToSync_, |
- skipForNow: this.skipForNow_, |
- sessionIndex: this.sessionIndex_ || ''}); |
+ this.dispatchEvent( |
+ new CustomEvent('authCompleted', |
+ {detail: {email: this.email_, |
+ gaiaId: this.gaiaId_, |
+ password: this.password_, |
+ usingSAML: this.authFlow_ == AuthFlow.SAML, |
+ chooseWhatToSync: this.chooseWhatToSync_, |
+ skipForNow: this.skipForNow_, |
+ sessionIndex: this.sessionIndex_ || '', |
+ trusted: this.trusted_}})); |
}; |
/** |
@@ -300,11 +252,18 @@ cr.define('cr.login', function() { |
* @private |
*/ |
Authenticator.prototype.onNewWindow_ = function(e) { |
- if (!this.listener_) { |
- return; |
- } |
+ this.dispatchEvent(new CustomEvent('newWindow', {detail: e})); |
+ }; |
- this.listener_.onNewWindow(e); |
+ /** |
+ * Invoked when the webview finishes loading a page. |
+ * @private |
+ */ |
+ Authenticator.prototype.onLoadStop_ = function(e) { |
+ if (!this.loaded_) { |
+ this.loaded_ = true; |
+ this.dispatchEvent(new Event('ready')); |
+ } |
}; |
Authenticator.AuthFlow = AuthFlow; |