| Index: chrome/browser/resources/gaia_auth/main.js
|
| diff --git a/chrome/browser/resources/gaia_auth/main.js b/chrome/browser/resources/gaia_auth/main.js
|
| index 1fb9c033530e9118638fd3ee2ad61a98cfe48baf..56eae51610d303323329c4051e0ebf951601e241 100644
|
| --- a/chrome/browser/resources/gaia_auth/main.js
|
| +++ b/chrome/browser/resources/gaia_auth/main.js
|
| @@ -5,8 +5,7 @@
|
| /**
|
| * Authenticator class wraps the communications between Gaia and its host.
|
| */
|
| -function Authenticator() {
|
| -}
|
| +function Authenticator() {}
|
|
|
| /**
|
| * Gaia auth extension url origin.
|
| @@ -39,10 +38,8 @@ Authenticator.API_KEY_TYPES = [
|
| * Allowed origins of the hosting page.
|
| * @type {Array<string>}
|
| */
|
| -Authenticator.ALLOWED_PARENT_ORIGINS = [
|
| - 'chrome://oobe',
|
| - 'chrome://chrome-signin'
|
| -];
|
| +Authenticator.ALLOWED_PARENT_ORIGINS =
|
| + ['chrome://oobe', 'chrome://chrome-signin'];
|
|
|
| /**
|
| * Singleton getter of Authenticator.
|
| @@ -131,14 +128,13 @@ Authenticator.prototype = {
|
| // TODO(dzhioev): Do not rely on 'load' event after b/16313327 is fixed.
|
| this.assumeLoadedOnLoadEvent_ =
|
| !this.gaiaPath_.startsWith('ServiceLogin') ||
|
| - this.service_ !== 'chromeoslogin' ||
|
| - this.useEafe_;
|
| + this.service_ !== 'chromeoslogin' || this.useEafe_;
|
| },
|
|
|
| isGaiaMessage_: function(msg) {
|
| // Not quite right, but good enough.
|
| return this.gaiaUrl_.startsWith(msg.origin) ||
|
| - this.GAIA_URL.startsWith(msg.origin);
|
| + this.GAIA_URL.startsWith(msg.origin);
|
| },
|
|
|
| isParentMessage_: function(msg) {
|
| @@ -177,9 +173,8 @@ Authenticator.prototype = {
|
| if (this.useEafe_ && this.clientId_) {
|
| // Sends initial handshake message to EAFE. Note this fails with
|
| // SSO redirect because |gaiaFrame| sits on a different origin.
|
| - gaiaFrame.contentWindow.postMessage({
|
| - clientId: this.clientId_
|
| - }, this.gaiaUrl_);
|
| + gaiaFrame.contentWindow.postMessage(
|
| + {clientId: this.clientId_}, this.gaiaUrl_);
|
| }
|
| }
|
| }.bind(this);
|
| @@ -242,9 +237,7 @@ Authenticator.prototype = {
|
| maybeInitialized_: function() {
|
| if (!this.gaiaLoaded_ || !this.supportChannel_)
|
| return;
|
| - var msg = {
|
| - 'method': 'loginUILoaded'
|
| - };
|
| + var msg = {'method': 'loginUILoaded'};
|
| window.parent.postMessage(msg, this.parentPage_);
|
| },
|
|
|
| @@ -254,10 +247,7 @@ Authenticator.prototype = {
|
| * @param {Object=} msg Extra info to send.
|
| */
|
| switchToFullTab_: function(msg) {
|
| - var parentMsg = {
|
| - 'method': 'switchToFullTab',
|
| - 'url': msg.url
|
| - };
|
| + var parentMsg = {'method': 'switchToFullTab', 'url': msg.url};
|
| window.parent.postMessage(parentMsg, this.parentPage_);
|
| },
|
|
|
| @@ -269,14 +259,14 @@ Authenticator.prototype = {
|
| var msg = {
|
| 'method': 'completeLogin',
|
| 'email': (opt_extraMsg && opt_extraMsg.email) || this.email_,
|
| - 'password': this.passwordBytes_ ||
|
| - (opt_extraMsg && opt_extraMsg.password),
|
| + 'password':
|
| + this.passwordBytes_ || (opt_extraMsg && opt_extraMsg.password),
|
| 'usingSAML': this.isSAMLFlow_,
|
| 'chooseWhatToSync': this.chooseWhatToSync_ || false,
|
| - 'skipForNow': (opt_extraMsg && opt_extraMsg.skipForNow) ||
|
| - this.skipForNow_,
|
| - 'sessionIndex': (opt_extraMsg && opt_extraMsg.sessionIndex) ||
|
| - this.sessionIndex_,
|
| + 'skipForNow':
|
| + (opt_extraMsg && opt_extraMsg.skipForNow) || this.skipForNow_,
|
| + 'sessionIndex':
|
| + (opt_extraMsg && opt_extraMsg.sessionIndex) || this.sessionIndex_,
|
| 'gaiaId': (opt_extraMsg && opt_extraMsg.gaiaId) || this.gaiaId_
|
| };
|
| window.parent.postMessage(msg, this.parentPage_);
|
| @@ -293,21 +283,15 @@ Authenticator.prototype = {
|
| 'onAuthPageLoaded', this.onAuthPageLoaded_.bind(this));
|
| this.supportChannel_.registerMessage(
|
| 'onInsecureContentBlocked', this.onInsecureContentBlocked_.bind(this));
|
| - this.supportChannel_.registerMessage(
|
| - 'apiCall', this.onAPICall_.bind(this));
|
| - this.supportChannel_.send({
|
| - name: 'setGaiaUrl',
|
| - gaiaUrl: this.gaiaUrl_
|
| - });
|
| + this.supportChannel_.registerMessage('apiCall', this.onAPICall_.bind(this));
|
| + this.supportChannel_.send({name: 'setGaiaUrl', gaiaUrl: this.gaiaUrl_});
|
| if (!this.desktopMode_ && this.gaiaUrl_.startsWith('https://')) {
|
| // Abort the login flow when content served over an unencrypted connection
|
| // is detected on Chrome OS. This does not apply to tests that explicitly
|
| // set a non-https GAIA URL and want to perform all authentication over
|
| // http.
|
| - this.supportChannel_.send({
|
| - name: 'setBlockInsecureContent',
|
| - blockInsecureContent: true
|
| - });
|
| + this.supportChannel_.send(
|
| + {name: 'setBlockInsecureContent', blockInsecureContent: true});
|
| }
|
| },
|
|
|
| @@ -326,11 +310,13 @@ Authenticator.prototype = {
|
| this.passwordBytes_ = null;
|
| }
|
|
|
| - window.parent.postMessage({
|
| - 'method': 'authPageLoaded',
|
| - 'isSAML': this.isSAMLFlow_,
|
| - 'domain': extractDomain(msg.url)
|
| - }, this.parentPage_);
|
| + window.parent.postMessage(
|
| + {
|
| + 'method': 'authPageLoaded',
|
| + 'isSAML': this.isSAMLFlow_,
|
| + 'domain': extractDomain(msg.url)
|
| + },
|
| + this.parentPage_);
|
| },
|
|
|
| /**
|
| @@ -339,10 +325,9 @@ Authenticator.prototype = {
|
| * @param {!Object} msg Details sent with the message.
|
| */
|
| onInsecureContentBlocked_: function(msg) {
|
| - window.parent.postMessage({
|
| - 'method': 'insecureContentBlocked',
|
| - 'url': stripParams(msg.url)
|
| - }, this.parentPage_);
|
| + window.parent.postMessage(
|
| + {'method': 'insecureContentBlocked', 'url': stripParams(msg.url)},
|
| + this.parentPage_);
|
| },
|
|
|
| /**
|
| @@ -359,8 +344,8 @@ Authenticator.prototype = {
|
| return;
|
| }
|
|
|
| - this.apiVersion_ = Math.min(call.requestedVersion,
|
| - Authenticator.MAX_API_VERSION_VERSION);
|
| + this.apiVersion_ = Math.min(
|
| + call.requestedVersion, Authenticator.MAX_API_VERSION_VERSION);
|
| this.initialized_ = true;
|
| this.sendInitializationSuccess_();
|
| return;
|
| @@ -384,27 +369,27 @@ Authenticator.prototype = {
|
| },
|
|
|
| onGotAuthCode_: function(authCode) {
|
| - window.parent.postMessage({
|
| - 'method': 'completeAuthenticationAuthCodeOnly',
|
| - 'authCode': authCode
|
| - }, this.parentPage_);
|
| + window.parent.postMessage(
|
| + {'method': 'completeAuthenticationAuthCodeOnly', 'authCode': authCode},
|
| + this.parentPage_);
|
| },
|
|
|
| sendInitializationSuccess_: function() {
|
| - this.supportChannel_.send({name: 'apiResponse', response: {
|
| - result: 'initialized',
|
| - version: this.apiVersion_,
|
| - keyTypes: Authenticator.API_KEY_TYPES
|
| - }});
|
| - },
|
| -
|
| - sendInitializationFailure_: function() {
|
| this.supportChannel_.send({
|
| name: 'apiResponse',
|
| - response: {result: 'initialization_failed'}
|
| + response: {
|
| + result: 'initialized',
|
| + version: this.apiVersion_,
|
| + keyTypes: Authenticator.API_KEY_TYPES
|
| + }
|
| });
|
| },
|
|
|
| + sendInitializationFailure_: function() {
|
| + this.supportChannel_.send(
|
| + {name: 'apiResponse', response: {result: 'initialization_failed'}});
|
| + },
|
| +
|
| /**
|
| * Callback invoked for 'completeLogin' message.
|
| * @param {Object=} msg Message sent from background page.
|
| @@ -417,8 +402,8 @@ Authenticator.prototype = {
|
| this.completeLogin_(msg);
|
| } else {
|
| console.error('Missing fields to complete login.');
|
| - window.parent.postMessage({method: 'missingGaiaInfo'},
|
| - this.parentPage_);
|
| + window.parent.postMessage(
|
| + {method: 'missingGaiaInfo'}, this.parentPage_);
|
| return;
|
| }
|
| }
|
| @@ -448,17 +433,18 @@ Authenticator.prototype = {
|
| this.completeLogin_(msg);
|
| } else {
|
| this.supportChannel_.sendWithCallback(
|
| - {name: 'getScrapedPasswords'},
|
| - function(passwords) {
|
| + {name: 'getScrapedPasswords'}, function(passwords) {
|
| if (passwords.length == 0) {
|
| window.parent.postMessage(
|
| - {method: 'noPassword', email: this.email_},
|
| - this.parentPage_);
|
| + {method: 'noPassword', email: this.email_}, this.parentPage_);
|
| } else {
|
| - window.parent.postMessage({method: 'confirmPassword',
|
| - email: this.email_,
|
| - passwordCount: passwords.length},
|
| - this.parentPage_);
|
| + window.parent.postMessage(
|
| + {
|
| + method: 'confirmPassword',
|
| + email: this.email_,
|
| + passwordCount: passwords.length
|
| + },
|
| + this.parentPage_);
|
| }
|
| }.bind(this));
|
| }
|
| @@ -466,8 +452,7 @@ Authenticator.prototype = {
|
|
|
| onVerifyConfirmedPassword_: function(password) {
|
| this.supportChannel_.sendWithCallback(
|
| - {name: 'getScrapedPasswords'},
|
| - function(passwords) {
|
| + {name: 'getScrapedPasswords'}, function(passwords) {
|
| for (var i = 0; i < passwords.length; ++i) {
|
| if (passwords[i] == password) {
|
| this.passwordBytes_ = passwords[i];
|
| @@ -492,15 +477,17 @@ Authenticator.prototype = {
|
| // Sends client ID again on the hello message to work around the SSO
|
| // signin issue.
|
| // TODO(xiyuan): Revisit this when EAFE is integrated or for webview.
|
| - $('gaia-frame').contentWindow.postMessage({
|
| - clientId: this.clientId_
|
| - }, this.gaiaUrl_);
|
| - } else if (typeof msg == 'object' &&
|
| - msg.type == 'authorizationCode' && this.isGaiaMessage_(e)) {
|
| + $('gaia-frame')
|
| + .contentWindow.postMessage(
|
| + {clientId: this.clientId_}, this.gaiaUrl_);
|
| + } else if (
|
| + typeof msg == 'object' && msg.type == 'authorizationCode' &&
|
| + this.isGaiaMessage_(e)) {
|
| this.onGotAuthCode_(msg.authorizationCode);
|
| } else {
|
| - console.error('Authenticator.onMessage: unknown message' +
|
| - ', msg=' + JSON.stringify(msg));
|
| + console.error(
|
| + 'Authenticator.onMessage: unknown message' +
|
| + ', msg=' + JSON.stringify(msg));
|
| }
|
|
|
| return;
|
| @@ -534,15 +521,16 @@ Authenticator.prototype = {
|
| this.supportChannel_.send({name: 'resetAuth'});
|
| // This message is for clearing saml properties in gaia_auth_host and
|
| // oobe_screen_oauth_enrollment.
|
| - window.parent.postMessage({
|
| - 'method': 'resetAuthFlow',
|
| - }, this.parentPage_);
|
| + window.parent.postMessage(
|
| + {
|
| + 'method': 'resetAuthFlow',
|
| + },
|
| + this.parentPage_);
|
| }
|
| - } else if (msg.method == 'verifyConfirmedPassword' &&
|
| - this.isParentMessage_(e)) {
|
| + } else if (
|
| + msg.method == 'verifyConfirmedPassword' && this.isParentMessage_(e)) {
|
| this.onVerifyConfirmedPassword_(msg.password);
|
| - } else if (msg.method == 'redirectToSignin' &&
|
| - this.isParentMessage_(e)) {
|
| + } else if (msg.method == 'redirectToSignin' && this.isParentMessage_(e)) {
|
| $('gaia-frame').src = this.constructInitialFrameUrl_();
|
| } else {
|
| console.error('Authenticator.onMessage: unknown message + origin!?');
|
|
|