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 0fc093e2689b64f806cb411210bdace2771b41e8..3dea8adf47859439279388fedd4513ae553a65d1 100644 |
--- a/chrome/browser/resources/gaia_auth_host/authenticator.js |
+++ b/chrome/browser/resources/gaia_auth_host/authenticator.js |
@@ -424,29 +424,40 @@ cr.define('cr.login', function() { |
}; |
/** |
- * Invoked when an HTML5 message is received from the webview element. |
+ * Returns true if given HTML5 message is received from the webview element. |
* @param {object} e Payload of the received HTML5 message. |
- * @private |
*/ |
- Authenticator.prototype.onMessageFromWebview_ = function(e) { |
+ Authenticator.prototype.isGaiaMessage = function(e) { |
if (!this.isWebviewEvent_(e)) |
- return; |
+ return false; |
// The event origin does not have a trailing slash. |
if (e.origin != this.idpOrigin_.substring(0, this.idpOrigin_.length - 1)) { |
- return; |
+ return false; |
} |
// Gaia messages must be an object with 'method' property. |
if (typeof e.data != 'object' || !e.data.hasOwnProperty('method')) { |
- return; |
+ return false; |
} |
+ return true; |
+ }; |
+ |
+ /** |
+ * Invoked when an HTML5 message is received from the webview element. |
+ * @param {object} e Payload of the received HTML5 message. |
+ * @private |
+ */ |
+ Authenticator.prototype.onMessageFromWebview_ = function(e) { |
+ if (!this.isGaiaMessage(e)) |
+ return; |
var msg = e.data; |
if (msg.method == 'attemptLogin') { |
this.email_ = msg.email; |
this.password_ = msg.password; |
this.chooseWhatToSync_ = msg.chooseWhatToSync; |
+ this.dispatchEvent(new CustomEvent('attemptLogin', {detail: msg.email})); |
Nikita (slow)
2015/04/22 16:51:52
As discussed, we should only process 'attemptLogin
Alexander Alekseev
2015/04/22 17:58:07
Done.
|
} else if (msg.method == 'dialogShown') { |
this.dispatchEvent(new Event('dialogShown')); |
} else if (msg.method == 'dialogHidden') { |
@@ -665,6 +676,19 @@ cr.define('cr.login', function() { |
}; |
/** |
+ * Informs Gaia of new deviceId to be used. |
+ */ |
+ Authenticator.prototype.updateDeviceId = function(deviceId) { |
+ var msg = { |
+ 'method': 'updateDeviceId', |
+ 'deviceId': deviceId, |
+ }; |
+ |
+ var currentUrl = this.webview_.src; |
+ this.webview_.contentWindow.postMessage(msg, currentUrl); |
+ }; |
+ |
+ /** |
* The current auth flow of the hosted auth page. |
* @type {AuthFlow} |
*/ |