From 3a97ca8dd9b96b599ae2d33e40df0dd2f7ea5859 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 14 Aug 2015 11:38:45 +0200 Subject: BASELINE: Update chromium to 45.0.2454.40 Change-Id: Id2121d9f11a8fc633677236c65a3e41feef589e4 Reviewed-by: Andras Becsi --- .../chrome/browser/resources/gaia_auth_host/OWNERS | 1 + .../resources/gaia_auth_host/authenticator.js | 154 +++++++++++++++++---- .../gaia_auth_host/post_message_channel.js | 5 +- .../resources/gaia_auth_host/saml_handler.js | 4 +- 4 files changed, 131 insertions(+), 33 deletions(-) (limited to 'chromium/chrome/browser/resources/gaia_auth_host') diff --git a/chromium/chrome/browser/resources/gaia_auth_host/OWNERS b/chromium/chrome/browser/resources/gaia_auth_host/OWNERS index cac125975e2..210e4ec0dc7 100644 --- a/chromium/chrome/browser/resources/gaia_auth_host/OWNERS +++ b/chromium/chrome/browser/resources/gaia_auth_host/OWNERS @@ -1,3 +1,4 @@ nkostylev@chromium.org xiyuan@chromium.org zelidrag@chromium.org +achuith@chromium.org diff --git a/chromium/chrome/browser/resources/gaia_auth_host/authenticator.js b/chromium/chrome/browser/resources/gaia_auth_host/authenticator.js index 870b368258f..ed83ce3619f 100644 --- a/chromium/chrome/browser/resources/gaia_auth_host/authenticator.js +++ b/chromium/chrome/browser/resources/gaia_auth_host/authenticator.js @@ -25,8 +25,10 @@ cr.define('cr.login', function() { var SIGN_IN_HEADER = 'google-accounts-signin'; var EMBEDDED_FORM_HEADER = 'google-accounts-embedded'; var LOCATION_HEADER = 'location'; + var COOKIE_HEADER = 'cookie'; var SET_COOKIE_HEADER = 'set-cookie'; var OAUTH_CODE_COOKIE = 'oauth_code'; + var GAPS_COOKIE = 'GAPS'; var SERVICE_ID = 'chromeoslogin'; var EMBEDDED_SETUP_CHROMEOS_ENDPOINT = 'embedded/setup/chromeos'; @@ -87,6 +89,7 @@ cr.define('cr.login', function() { 'platformVersion', // Version of the OS build. 'releaseChannel', // Installation channel. 'endpointGen', // Current endpoint generation. + 'gapsCookie', // GAPS cookie ]; /** @@ -114,7 +117,10 @@ cr.define('cr.login', function() { this.initialFrameUrl_ = null; this.reloadUrl_ = null; this.trusted_ = true; - this.oauth_code_ = null; + this.oauthCode_ = null; + this.gapsCookie_ = null; + this.gapsCookieSent_ = false; + this.newGapsCookie_ = null; this.useEafe_ = false; this.clientId_ = null; @@ -170,7 +176,10 @@ cr.define('cr.login', function() { this.email_ = null; this.gaiaId_ = null; this.password_ = null; - this.oauth_code_ = null; + this.oauthCode_ = null; + this.gapsCookie_ = null; + this.gapsCookieSent_ = false; + this.newGapsCookie_ = null; this.chooseWhatToSync_ = false; this.skipForNow_ = false; this.sessionIndex_ = null; @@ -188,6 +197,7 @@ cr.define('cr.login', function() { this.authMode = authMode; this.clearCredentials_(); this.loaded_ = false; + // gaiaUrl parameter is used for testing. Once defined, it is never changed. this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; this.continueUrl_ = data.continueUrl || CONTINUE_URL; this.continueUrlWithoutParams_ = @@ -197,6 +207,9 @@ cr.define('cr.login', function() { this.isNewGaiaFlowChromeOS = data.isNewGaiaFlowChromeOS; this.useEafe_ = data.useEafe || false; this.clientId_ = data.clientId; + this.gapsCookie_ = data.gapsCookie; + this.gapsCookieSent_ = false; + this.newGapsCookie_ = null; this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; @@ -210,6 +223,16 @@ cr.define('cr.login', function() { this.webview_.contextMenus.onShow.addListener(function(e) { e.preventDefault(); }); + + if (!this.onBeforeSetHeadersSet_) { + this.onBeforeSetHeadersSet_ = true; + var filterPrefix = this.idpOrigin_ + EMBEDDED_SETUP_CHROMEOS_ENDPOINT; + // This depends on gaiaUrl parameter, that is why it is here. + this.webview_.request.onBeforeSendHeaders.addListener( + this.onBeforeSendHeaders_.bind(this), + {urls: [filterPrefix + '?*', filterPrefix + '/*']}, + ['requestHeaders', 'blocking']); + } } this.webview_.src = this.reloadUrl_; @@ -374,11 +397,73 @@ cr.define('cr.login', function() { this.isNewGaiaFlowChromeOS && headerName == SET_COOKIE_HEADER) { var headerValue = header.value; if (headerValue.indexOf(OAUTH_CODE_COOKIE + '=', 0) == 0) { - this.oauth_code_ = + this.oauthCode_ = headerValue.substring(OAUTH_CODE_COOKIE.length + 1).split(';')[0]; } + if (headerValue.indexOf(GAPS_COOKIE + '=', 0) == 0) { + this.newGapsCookie_ = + headerValue.substring(GAPS_COOKIE.length + 1).split(';')[0]; + } + } + } + }; + + /** + * This method replaces cookie value in cookie header. + * @param@ {string} header_value Original string value of Cookie header. + * @param@ {string} cookie_name Name of cookie to be replaced. + * @param@ {string} cookie_value New cookie value. + * @return {string} New Cookie header value. + * @private + */ + Authenticator.prototype.updateCookieValue_ = function( + header_value, cookie_name, cookie_value) { + var cookies = header_value.split(/\s*;\s*/); + var found = false; + for (var i = 0; i < cookies.length; ++i) { + if (cookies[i].indexOf(cookie_name + '=', 0) == 0) { + found = true; + cookies[i] = cookie_name + '=' + cookie_value; + break; + } + } + if (!found) { + cookies.push(cookie_name + '=' + cookie_value); + } + return cookies.join('; '); + }; + + /** + * Handler for webView.request.onBeforeSendHeaders . + * @return {!Object} Modified request headers. + * @private + */ + Authenticator.prototype.onBeforeSendHeaders_ = function(details) { + // We should re-send cookie if first request was unsuccessful (i.e. no new + // GAPS cookie was received). + if (this.isNewGaiaFlowChromeOS && this.gapsCookie_ && + (!this.gapsCookieSent_ || !this.newGapsCookie_)) { + var headers = details.requestHeaders; + var found = false; + var gapsCookie = this.gapsCookie_; + + for (var i = 0, l = headers.length; i < l; ++i) { + if (headers[i].name == COOKIE_HEADER) { + headers[i].value = this.updateCookieValue_(headers[i].value, + GAPS_COOKIE, gapsCookie); + found = true; + break; + } + } + if (!found) { + details.requestHeaders.push( + {name: COOKIE_HEADER, value: GAPS_COOKIE + '=' + gapsCookie}); } + this.gapsCookieSent_ = true; } + return { + requestHeaders: details.requestHeaders + }; }; /** @@ -398,14 +483,14 @@ cr.define('cr.login', function() { if (this.useEafe_ && typeof e.data == 'object' && e.data.hasOwnProperty('authorizationCode')) { - assert(!this.oauth_code_); - this.oauth_code_ = e.data.authorizationCode; + assert(!this.oauthCode_); + this.oauthCode_ = e.data.authorizationCode; this.dispatchEvent( new CustomEvent('authCompleted', { detail: { authCodeOnly: true, - authCode: this.oauth_code_ + authCode: this.oauthCode_ } })); return; @@ -445,6 +530,10 @@ cr.define('cr.login', function() { this.dispatchEvent(new CustomEvent('backButton', {detail: msg.show})); } else if (msg.method == 'showView') { this.dispatchEvent(new Event('showView')); + } else if (msg.method == 'identifierEntered') { + this.dispatchEvent(new CustomEvent( + 'identifierEntered', + {detail: {accountIdentifier: msg.accountIdentifier}})); } else { console.warn('Unrecognized message from GAIA: ' + msg.method); } @@ -487,17 +576,23 @@ cr.define('cr.login', function() { return; } - if (this.authFlow != AuthFlow.SAML) { - this.onAuthCompleted_(); - return; - } - if (this.samlHandler_.samlApiUsed) { if (this.samlApiUsedCallback) { this.samlApiUsedCallback(); } this.password_ = this.samlHandler_.apiPasswordBytes; - } else if (this.samlHandler_.scrapedPasswordCount == 0) { + this.onAuthCompleted_(); + return; + } + + // TODO(achuith): Eliminate this branch when credential passing api is + // stable on prod. crbug.com/467778. + if (this.authFlow != AuthFlow.SAML) { + this.onAuthCompleted_(); + return; + } + + if (this.samlHandler_.scrapedPasswordCount == 0) { if (this.noPasswordCallback) { this.noPasswordCallback(this.email_); return; @@ -527,22 +622,23 @@ cr.define('cr.login', function() { Authenticator.prototype.onAuthCompleted_ = function() { assert(this.skipForNow_ || (this.email_ && this.gaiaId_ && this.sessionIndex_)); - this.dispatchEvent( - new CustomEvent('authCompleted', - // TODO(rsorokin): get rid of the stub values. - { - detail: { - email: this.email_ || '', - gaiaId: this.gaiaId_ || '', - password: this.password_ || '', - authCode: this.oauth_code_, - usingSAML: this.authFlow == AuthFlow.SAML, - chooseWhatToSync: this.chooseWhatToSync_, - skipForNow: this.skipForNow_, - sessionIndex: this.sessionIndex_ || '', - trusted: this.trusted_ - } - })); + this.dispatchEvent(new CustomEvent( + 'authCompleted', + // TODO(rsorokin): get rid of the stub values. + { + detail: { + email: this.email_ || '', + gaiaId: this.gaiaId_ || '', + password: this.password_ || '', + authCode: this.oauthCode_, + usingSAML: this.authFlow == AuthFlow.SAML, + chooseWhatToSync: this.chooseWhatToSync_, + skipForNow: this.skipForNow_, + sessionIndex: this.sessionIndex_ || '', + trusted: this.trusted_, + gapsCookie: this.newGapsCookie_ || this.gapsCookie_ || '', + } + })); this.clearCredentials_(); }; @@ -653,7 +749,7 @@ cr.define('cr.login', function() { * @private */ Authenticator.prototype.onLoadCommit_ = function(e) { - if (this.oauth_code_) { + if (this.oauthCode_) { this.skipForNow_ = true; this.maybeCompleteAuth_(); } diff --git a/chromium/chrome/browser/resources/gaia_auth_host/post_message_channel.js b/chromium/chrome/browser/resources/gaia_auth_host/post_message_channel.js index b63f93b2039..0b2b6e7323f 100644 --- a/chromium/chrome/browser/resources/gaia_auth_host/post_message_channel.js +++ b/chromium/chrome/browser/resources/gaia_auth_host/post_message_channel.js @@ -14,7 +14,7 @@ var PostMessageChannel = (function() { /** * Allowed origins of the hosting page. - * @type {Array.} + * @type {Array} */ var ALLOWED_ORIGINS = [ 'chrome://oobe', @@ -78,7 +78,7 @@ var PostMessageChannel = (function() { /** * Channle Id to port map. - * @type {Object.} + * @type {Object} */ this.channels_ = {}; @@ -324,6 +324,7 @@ var PostMessageChannel = (function() { * @constructor */ function PostMessageChannel() { + Channel.apply(this, arguments); }; PostMessageChannel.prototype = { diff --git a/chromium/chrome/browser/resources/gaia_auth_host/saml_handler.js b/chromium/chrome/browser/resources/gaia_auth_host/saml_handler.js index bd8603613d3..9b6ceb94c00 100644 --- a/chromium/chrome/browser/resources/gaia_auth_host/saml_handler.js +++ b/chromium/chrome/browser/resources/gaia_auth_host/saml_handler.js @@ -105,7 +105,7 @@ cr.define('cr.login', function() { /** * Scraped password stored in an id to password field value map. - * @type {Object.} + * @type {Object} * @private */ this.passwordStore_ = {}; @@ -199,7 +199,7 @@ cr.define('cr.login', function() { /** * Gets the de-duped scraped passwords. - * @return {Array.} + * @return {Array} * @private */ getConsolidatedScrapedPasswords_: function() { -- cgit v1.2.1