Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Unified Diff: chrome/browser/resources/gaia_auth_host/authenticator.js

Issue 1063753004: Use HTML messages to inform GAIA about deviceId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6220d95113f622f3fac8f690f0a4253805f95a3f 100644
--- a/chrome/browser/resources/gaia_auth_host/authenticator.js
+++ b/chrome/browser/resources/gaia_auth_host/authenticator.js
@@ -247,7 +247,7 @@ cr.define('cr.login', function() {
url = appendParam(url, 'client_id', data.clientId);
if (data.enterpriseDomain)
url = appendParam(url, 'manageddomain', data.enterpriseDomain);
- this.setDeviceId(data.deviceId);
+ this.deviceId_ = data.deviceId;
this.sessionIsEphemeral_ = data.sessionIsEphemeral;
} else {
url = appendParam(url, 'continue', this.continueUrl_);
@@ -269,13 +269,6 @@ cr.define('cr.login', function() {
};
/**
- * Invoked when deviceId is set or updated.
- */
- Authenticator.prototype.setDeviceId = function(deviceId) {
- this.deviceId_ = deviceId;
- };
-
- /**
* Invoked when a main frame request in the webview has completed.
* @private
*/
@@ -400,11 +393,7 @@ cr.define('cr.login', function() {
if (this.isNewGaiaFlowChromeOS && this.deviceId_) {
var headers = details.requestHeaders;
var found = false;
- var deviceId;
- if (this.sessionIsEphemeral_)
- deviceId = EPHEMERAL_DEVICE_ID_PREFIX + this.deviceId_;
- else
- deviceId = this.deviceId_;
+ var deviceId = this.getGAIADeviceId_();
for (var i = 0, l = headers.length; i < l; ++i) {
if (headers[i].name == X_DEVICE_ID_HEADER) {
@@ -424,29 +413,44 @@ 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;
+ // We need to dispatch only first event, before user enters password.
+ if (!msg.password) {
+ this.dispatchEvent(
+ new CustomEvent('attemptLogin', {detail: msg.email}));
+ }
} else if (msg.method == 'dialogShown') {
this.dispatchEvent(new Event('dialogShown'));
} else if (msg.method == 'dialogHidden') {
@@ -612,8 +616,10 @@ cr.define('cr.login', function() {
var currentUrl = this.webview_.src;
if (currentUrl.lastIndexOf(this.idpOrigin_) == 0) {
var msg = {
- 'method': 'handshake'
+ 'method': 'handshake',
+ 'deviceId': this.getGAIADeviceId_(),
};
+
this.webview_.contentWindow.postMessage(msg, currentUrl);
}
};
@@ -665,6 +671,37 @@ cr.define('cr.login', function() {
};
/**
+ * Format deviceId for GAIA .
+ * @return {string} deviceId.
+ * @private
+ */
+ Authenticator.prototype.getGAIADeviceId_ = function() {
+ // deviceId_ is empty when we do not need to send it. For example,
+ // in case of device enrollment.
+ if (!(this.isNewGaiaFlowChromeOS && this.deviceId_))
+ return;
+
+ if (this.sessionIsEphemeral_)
+ return EPHEMERAL_DEVICE_ID_PREFIX + this.deviceId_;
+ else
+ return this.deviceId_;
+ };
+
+ /**
+ * Informs Gaia of new deviceId to be used.
+ */
+ Authenticator.prototype.updateDeviceId = function(deviceId) {
+ this.deviceId_ = deviceId;
+ var msg = {
+ 'method': 'updateDeviceId',
+ 'deviceId': this.getGAIADeviceId_(),
+ };
+
+ var currentUrl = this.webview_.src;
+ this.webview_.contentWindow.postMessage(msg, currentUrl);
+ };
+
+ /**
* The current auth flow of the hosted auth page.
* @type {AuthFlow}
*/

Powered by Google App Engine
This is Rietveld 408576698