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

Side by Side Diff: chrome/browser/resources/gaia_auth_host/authenticator.js

Issue 905653003: Moved adding listeners on webview from load to constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview An UI component to authenciate to Chrome. The component hosts 6 * @fileoverview An UI component to authenciate to Chrome. The component hosts
7 * IdP web pages in a webview. A client who is interested in monitoring 7 * IdP web pages in a webview. A client who is interested in monitoring
8 * authentication events should pass a listener object of type 8 * authentication events should pass a listener object of type
9 * cr.login.GaiaAuthHost.Listener as defined in this file. After initialization, 9 * cr.login.GaiaAuthHost.Listener as defined in this file. After initialization,
10 * call {@code load} to start the authentication flow. 10 * call {@code load} to start the authentication flow.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 this.chooseWhatToSync_ = false; 83 this.chooseWhatToSync_ = false;
84 this.skipForNow_ = false; 84 this.skipForNow_ = false;
85 this.authFlow_ = AuthFlow.DEFAULT; 85 this.authFlow_ = AuthFlow.DEFAULT;
86 this.loaded_ = false; 86 this.loaded_ = false;
87 this.idpOrigin_ = null; 87 this.idpOrigin_ = null;
88 this.continueUrl_ = null; 88 this.continueUrl_ = null;
89 this.continueUrlWithoutParams_ = null; 89 this.continueUrlWithoutParams_ = null;
90 this.initialFrameUrl_ = null; 90 this.initialFrameUrl_ = null;
91 this.reloadUrl_ = null; 91 this.reloadUrl_ = null;
92 this.trusted_ = true; 92 this.trusted_ = true;
93
94 this.webview_.addEventListener(
95 'newwindow', this.onNewWindow_.bind(this));
96 this.webview_.addEventListener(
97 'contentload', this.onContentLoad_.bind(this));
98 this.webview_.addEventListener(
99 'loadstop', this.onLoadStop_.bind(this));
100 this.webview_.request.onCompleted.addListener(
101 this.onRequestCompleted_.bind(this),
102 {urls: ['<all_urls>'], types: ['main_frame']},
103 ['responseHeaders']);
104 this.webview_.request.onHeadersReceived.addListener(
105 this.onHeadersReceived_.bind(this),
106 {urls: ['<all_urls>'], types: ['main_frame']},
107 ['responseHeaders']);
108 window.addEventListener(
109 'message', this.onMessageFromWebview_.bind(this), false);
110 window.addEventListener(
111 'focus', this.onFocus_.bind(this), false);
112 window.addEventListener(
113 'popstate', this.onPopState_.bind(this), false);
93 } 114 }
94 115
95 // TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the 116 // TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the
96 // old event-based signin flow. 117 // old event-based signin flow.
97 Authenticator.prototype = Object.create(cr.EventTarget.prototype); 118 Authenticator.prototype = Object.create(cr.EventTarget.prototype);
98 119
99 /** 120 /**
100 * Loads the authenticator component with the given parameters. 121 * Loads the authenticator component with the given parameters.
101 * @param {AuthMode} authMode Authorization mode. 122 * @param {AuthMode} authMode Authorization mode.
102 * @param {Object} data Parameters for the authorization flow. 123 * @param {Object} data Parameters for the authorization flow.
103 */ 124 */
104 Authenticator.prototype.load = function(authMode, data) { 125 Authenticator.prototype.load = function(authMode, data) {
105 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN; 126 this.idpOrigin_ = data.gaiaUrl || IDP_ORIGIN;
106 this.continueUrl_ = data.continueUrl || CONTINUE_URL; 127 this.continueUrl_ = data.continueUrl || CONTINUE_URL;
107 this.continueUrlWithoutParams_ = 128 this.continueUrlWithoutParams_ =
108 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) || 129 this.continueUrl_.substring(0, this.continueUrl_.indexOf('?')) ||
109 this.continueUrl_; 130 this.continueUrl_;
110 this.isConstrainedWindow_ = data.constrained == '1'; 131 this.isConstrainedWindow_ = data.constrained == '1';
111 132
112 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data); 133 this.initialFrameUrl_ = this.constructInitialFrameUrl_(data);
113 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_; 134 this.reloadUrl_ = data.frameUrl || this.initialFrameUrl_;
114 this.authFlow_ = AuthFlow.DEFAULT; 135 this.authFlow_ = AuthFlow.DEFAULT;
115 136
116 this.webview_.src = this.reloadUrl_; 137 this.webview_.src = this.reloadUrl_;
117 this.webview_.addEventListener(
118 'newwindow', this.onNewWindow_.bind(this));
119 this.webview_.addEventListener(
120 'contentload', this.onContentLoad_.bind(this));
121 this.webview_.addEventListener(
122 'loadstop', this.onLoadStop_.bind(this));
123 this.webview_.request.onCompleted.addListener(
124 this.onRequestCompleted_.bind(this),
125 {urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'],
126 types: ['main_frame']},
127 ['responseHeaders']);
128 this.webview_.request.onHeadersReceived.addListener(
129 this.onHeadersReceived_.bind(this),
130 {urls: [this.idpOrigin_ + '*'], types: ['main_frame']},
131 ['responseHeaders']);
132 window.addEventListener(
133 'message', this.onMessageFromWebview_.bind(this), false);
134 window.addEventListener(
135 'focus', this.onFocus_.bind(this), false);
136 window.addEventListener(
137 'popstate', this.onPopState_.bind(this), false);
138 138
139 this.loaded_ = false; 139 this.loaded_ = false;
140 }; 140 };
141 141
142 /** 142 /**
143 * Reloads the authenticator component. 143 * Reloads the authenticator component.
144 */ 144 */
145 Authenticator.prototype.reload = function() { 145 Authenticator.prototype.reload = function() {
146 this.webview_.src = this.reloadUrl_; 146 this.webview_.src = this.reloadUrl_;
147 this.authFlow_ = AuthFlow.DEFAULT; 147 this.authFlow_ = AuthFlow.DEFAULT;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 }; 235 };
236 236
237 /** 237 /**
238 * Invoked when headers are received in the main frame of the webview. It 238 * Invoked when headers are received in the main frame of the webview. It
239 * 1) reads the authenticated user info from a signin header, 239 * 1) reads the authenticated user info from a signin header,
240 * 2) signals the start of a saml flow upon receiving a saml header. 240 * 2) signals the start of a saml flow upon receiving a saml header.
241 * @return {!Object} Modified request headers. 241 * @return {!Object} Modified request headers.
242 * @private 242 * @private
243 */ 243 */
244 Authenticator.prototype.onHeadersReceived_ = function(details) { 244 Authenticator.prototype.onHeadersReceived_ = function(details) {
245 var currentUrl = details.url;
246 if (currentUrl.lastIndexOf(this.idpOrigin_, 0) != 0)
247 return;
248
245 var headers = details.responseHeaders; 249 var headers = details.responseHeaders;
246 for (var i = 0; headers && i < headers.length; ++i) { 250 for (var i = 0; headers && i < headers.length; ++i) {
247 var header = headers[i]; 251 var header = headers[i];
248 var headerName = header.name.toLowerCase(); 252 var headerName = header.name.toLowerCase();
249 if (headerName == SIGN_IN_HEADER) { 253 if (headerName == SIGN_IN_HEADER) {
250 var headerValues = header.value.toLowerCase().split(','); 254 var headerValues = header.value.toLowerCase().split(',');
251 var signinDetails = {}; 255 var signinDetails = {};
252 headerValues.forEach(function(e) { 256 headerValues.forEach(function(e) {
253 var pair = e.split('='); 257 var pair = e.split('=');
254 signinDetails[pair[0].trim()] = pair[1].trim(); 258 signinDetails[pair[0].trim()] = pair[1].trim();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 Authenticator.AuthFlow = AuthFlow; 348 Authenticator.AuthFlow = AuthFlow;
345 Authenticator.AuthMode = AuthMode; 349 Authenticator.AuthMode = AuthMode;
346 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS; 350 Authenticator.SUPPORTED_PARAMS = SUPPORTED_PARAMS;
347 351
348 return { 352 return {
349 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old 353 // TODO(guohui, xiyuan): Rename GaiaAuthHost to Authenticator once the old
350 // iframe-based flow is deprecated. 354 // iframe-based flow is deprecated.
351 GaiaAuthHost: Authenticator 355 GaiaAuthHost: Authenticator
352 }; 356 };
353 }); 357 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698