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

Unified Diff: chrome/browser/resources/gaia_auth/background.js

Issue 130963006: Reimplement inline signin with iframe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/background.js
diff --git a/chrome/browser/resources/gaia_auth/background.js b/chrome/browser/resources/gaia_auth/background.js
index a571c10e8561c6e0d9fb885300f8adfb7e7cdb45..afe982ac3431ca46bb7fab3943d135a624941651 100644
--- a/chrome/browser/resources/gaia_auth/background.js
+++ b/chrome/browser/resources/gaia_auth/background.js
@@ -32,6 +32,21 @@ function BackgroundBridge() {
}
BackgroundBridge.prototype = {
+ // Continue URL that is set from main auth script.
+ continueUrl_: null,
+
+ // Whether the extension is loaded in a constrained window.
+ // Set from main auth script.
+ isConstrainedWindow_: null,
+
+ // Email of the newly authenticated user based on the gaia response header
+ // 'google-accounts-signin'.
+ email_: null,
+
+ // Session index of the newly authenticated user based on the gaia response
+ // header 'google-accounts-signin'.
+ sessionIndex_: null,
+
// Gaia URL base that is set from main auth script.
gaiaUrl_: null,
@@ -81,6 +96,12 @@ BackgroundBridge.prototype = {
setupForAuthMain_: function(port) {
this.channelMain_ = new Channel();
this.channelMain_.init(port);
+
+ // Registers for desktop related messages.
+ this.channelMain_.registerMessage(
+ 'initDesktopFlow', this.onInitDesktopFlow_.bind(this));
+
+ // Registers for SAML related messages.
this.channelMain_.registerMessage(
'setGaiaUrl', this.onSetGaiaUrl_.bind(this));
this.channelMain_.registerMessage(
@@ -107,6 +128,86 @@ BackgroundBridge.prototype = {
},
/**
+ * Handler for 'initDesktopFlow' signal sent from the main script.
+ * Only called in desktop mode.
+ */
+ onInitDesktopFlow_: function(msg) {
+ this.gaiaUrl_ = msg.gaiaUrl;
+ this.continueUrl_ = msg.continueUrl;
+ this.isConstrainedWindow_ = msg.isConstrainedWindow;
+
+ var urls = [];
+ var filter = {urls: urls, types: ['sub_frame']};
+ var optExtraInfoSpec = [];
+ if (msg.isConstrainedWindow) {
+ urls.push('<all_urls>');
+ optExtraInfoSpec.push('responseHeaders');
+ } else {
+ urls.push(this.continueUrl_ + '*');
+ }
+
+ chrome.webRequest.onCompleted.addListener(
+ this.onRequestCompletedInDesktopMode_.bind(this),
+ filter, optExtraInfoSpec);
+ chrome.webRequest.onHeadersReceived.addListener(
+ this.onHeadersReceivedInDesktopMode_.bind(this),
+ {urls: [this.gaiaUrl_ + '*'], types: ['sub_frame']},
+ ['responseHeaders']);
+ },
+
+ /**
+ * Event listener for webRequest.onCompleted in desktop mode.
+ */
+ onRequestCompletedInDesktopMode_: function(details) {
+ var msg;
+ if (details.url.lastIndexOf(this.continueUrl_, 0) == 0) {
+ var skipForNow = false;
+ if (details.url.indexOf('ntp=1') >= 0) {
+ skipForNow = true;
+ }
+ var msg = {
+ 'name': 'completeLogin',
+ 'email': this.email_,
+ 'sessionIndex': this.sessionIndex_,
+ 'skipForNow': skipForNow
+ };
+ } else {
+ var headers = details.responseHeaders;
+ for (var i = 0; headers && i < headers.length; ++i) {
+ if (headers[i].name.toLowerCase() == 'google-accounts-embedded') {
+ return;
+ }
+ }
+ msg = {
+ 'name': 'switchToFullTab',
+ 'url': details.url
+ };
+ }
+
+ this.channelMain_.send(msg);
+ },
+
+ /**
+ * Event listener for webRequest.onHeadersReceived in desktop mode.
+ */
+ onHeadersReceivedInDesktopMode_: function(details) {
+ var headers = details.responseHeaders;
+ for (var i = 0; headers && i < headers.length; ++i) {
+ if (headers[i].name.toLowerCase() == 'google-accounts-signin') {
+ var headerValues = headers[i].value.toLowerCase().split(',');
+ var signinDetails = {};
+ headerValues.forEach(function(e) {
+ var pair = e.split('=');
+ signinDetails[pair[0].trim()] = pair[1].trim();
+ });
+ this.email_ = signinDetails['email'].slice(1, -1); // Remove "" around.
+ this.sessionIndex_ = signinDetails['sessionindex'];
+ return;
+ }
+ }
+ },
+
+ /**
* Handler for 'setGaiaUrl' signal sent from the main script.
*/
onSetGaiaUrl_: function(msg) {
@@ -171,3 +272,4 @@ BackgroundBridge.prototype = {
var backgroundBridge = new BackgroundBridge();
backgroundBridge.run();
+
nasko 2014/01/27 17:21:50 nit: no need for blank line.
guohui 2014/01/29 12:50:51 Done.

Powered by Google App Engine
This is Rietveld 408576698