Commit 823b2ac8 authored by rsorokin's avatar rsorokin Committed by Commit bot

Moved adding listeners on webview from load to constructor

Current implementation causes same multiple listeners wait for an event after we load page several times. E.g. in ChromeOS: add user->cancel->add user. After login we get multiple identical messages.

BUG=426316
TEST=manual

Review URL: https://codereview.chromium.org/905653003

Cr-Commit-Position: refs/heads/master@{#315286}
parent 3c4788d3
...@@ -90,6 +90,27 @@ cr.define('cr.login', function() { ...@@ -90,6 +90,27 @@ cr.define('cr.login', function() {
this.initialFrameUrl_ = null; this.initialFrameUrl_ = null;
this.reloadUrl_ = null; this.reloadUrl_ = null;
this.trusted_ = true; this.trusted_ = true;
this.webview_.addEventListener(
'newwindow', this.onNewWindow_.bind(this));
this.webview_.addEventListener(
'contentload', this.onContentLoad_.bind(this));
this.webview_.addEventListener(
'loadstop', this.onLoadStop_.bind(this));
this.webview_.request.onCompleted.addListener(
this.onRequestCompleted_.bind(this),
{urls: ['<all_urls>'], types: ['main_frame']},
['responseHeaders']);
this.webview_.request.onHeadersReceived.addListener(
this.onHeadersReceived_.bind(this),
{urls: ['<all_urls>'], types: ['main_frame']},
['responseHeaders']);
window.addEventListener(
'message', this.onMessageFromWebview_.bind(this), false);
window.addEventListener(
'focus', this.onFocus_.bind(this), false);
window.addEventListener(
'popstate', this.onPopState_.bind(this), false);
} }
// TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the // TODO(guohui,xiyuan): no need to inherit EventTarget once we deprecate the
...@@ -114,27 +135,6 @@ cr.define('cr.login', function() { ...@@ -114,27 +135,6 @@ cr.define('cr.login', function() {
this.authFlow_ = AuthFlow.DEFAULT; this.authFlow_ = AuthFlow.DEFAULT;
this.webview_.src = this.reloadUrl_; this.webview_.src = this.reloadUrl_;
this.webview_.addEventListener(
'newwindow', this.onNewWindow_.bind(this));
this.webview_.addEventListener(
'contentload', this.onContentLoad_.bind(this));
this.webview_.addEventListener(
'loadstop', this.onLoadStop_.bind(this));
this.webview_.request.onCompleted.addListener(
this.onRequestCompleted_.bind(this),
{urls: ['*://*/*', this.continueUrlWithoutParams_ + '*'],
types: ['main_frame']},
['responseHeaders']);
this.webview_.request.onHeadersReceived.addListener(
this.onHeadersReceived_.bind(this),
{urls: [this.idpOrigin_ + '*'], types: ['main_frame']},
['responseHeaders']);
window.addEventListener(
'message', this.onMessageFromWebview_.bind(this), false);
window.addEventListener(
'focus', this.onFocus_.bind(this), false);
window.addEventListener(
'popstate', this.onPopState_.bind(this), false);
this.loaded_ = false; this.loaded_ = false;
}; };
...@@ -242,6 +242,10 @@ cr.define('cr.login', function() { ...@@ -242,6 +242,10 @@ cr.define('cr.login', function() {
* @private * @private
*/ */
Authenticator.prototype.onHeadersReceived_ = function(details) { Authenticator.prototype.onHeadersReceived_ = function(details) {
var currentUrl = details.url;
if (currentUrl.lastIndexOf(this.idpOrigin_, 0) != 0)
return;
var headers = details.responseHeaders; var headers = details.responseHeaders;
for (var i = 0; headers && i < headers.length; ++i) { for (var i = 0; headers && i < headers.length; ++i) {
var header = headers[i]; var header = headers[i];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment