| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Authenticator class wraps the communications between Gaia and its host. | 6 * Authenticator class wraps the communications between Gaia and its host. |
| 7 */ | 7 */ |
| 8 function Authenticator() { | 8 function Authenticator() { |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 this.inputEmail_ = params.email; | 54 this.inputEmail_ = params.email; |
| 55 this.service_ = params.service || this.SERVICE_ID; | 55 this.service_ = params.service || this.SERVICE_ID; |
| 56 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; | 56 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; |
| 57 this.continueUrlWithoutParams_ = stripParams(this.continueUrl_); | 57 this.continueUrlWithoutParams_ = stripParams(this.continueUrl_); |
| 58 this.inlineMode_ = params.inlineMode == '1'; | 58 this.inlineMode_ = params.inlineMode == '1'; |
| 59 this.constrained_ = params.constrained == '1'; | 59 this.constrained_ = params.constrained == '1'; |
| 60 this.partitionId_ = params.partitionId || ''; | 60 this.partitionId_ = params.partitionId || ''; |
| 61 this.initialFrameUrl_ = params.frameUrl || this.constructInitialFrameUrl_(); | 61 this.initialFrameUrl_ = params.frameUrl || this.constructInitialFrameUrl_(); |
| 62 this.initialFrameUrlWithoutParams_ = stripParams(this.initialFrameUrl_); | 62 this.initialFrameUrlWithoutParams_ = stripParams(this.initialFrameUrl_); |
| 63 this.loaded_ = false; | 63 this.loaded_ = false; |
| 64 this.load_start_ts_ = 0; |
| 64 | 65 |
| 65 document.addEventListener('DOMContentLoaded', this.onPageLoad.bind(this)); | 66 document.addEventListener('DOMContentLoaded', this.onPageLoad.bind(this)); |
| 66 document.addEventListener('enableSAML', this.onEnableSAML_.bind(this)); | 67 document.addEventListener('enableSAML', this.onEnableSAML_.bind(this)); |
| 67 }, | 68 }, |
| 68 | 69 |
| 69 isGaiaMessage_: function(msg) { | 70 isGaiaMessage_: function(msg) { |
| 70 // Not quite right, but good enough. | 71 // Not quite right, but good enough. |
| 71 return this.gaiaUrl_.indexOf(msg.origin) == 0 || | 72 return this.gaiaUrl_.indexOf(msg.origin) == 0 || |
| 72 this.GAIA_URL.indexOf(msg.origin) == 0; | 73 this.GAIA_URL.indexOf(msg.origin) == 0; |
| 73 }, | 74 }, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 'method': 'switchToFullTab', | 162 'method': 'switchToFullTab', |
| 162 'url': details.url | 163 'url': details.url |
| 163 }; | 164 }; |
| 164 window.parent.postMessage(msg, this.parentPage_); | 165 window.parent.postMessage(msg, this.parentPage_); |
| 165 }, | 166 }, |
| 166 | 167 |
| 167 loadFrame_: function() { | 168 loadFrame_: function() { |
| 168 var gaiaFrame = $('gaia-frame'); | 169 var gaiaFrame = $('gaia-frame'); |
| 169 gaiaFrame.partition = this.partitionId_; | 170 gaiaFrame.partition = this.partitionId_; |
| 170 gaiaFrame.src = this.initialFrameUrl_; | 171 gaiaFrame.src = this.initialFrameUrl_; |
| 172 this.load_start_ts_ = Date.now(); |
| 173 |
| 171 if (this.inlineMode_) { | 174 if (this.inlineMode_) { |
| 172 gaiaFrame.addEventListener( | 175 gaiaFrame.addEventListener( |
| 173 'loadstop', this.onWebviewLoadstop_.bind(this, gaiaFrame)); | 176 'loadstop', this.onWebviewLoadstop_.bind(this, gaiaFrame)); |
| 174 gaiaFrame.addEventListener( | 177 gaiaFrame.addEventListener( |
| 175 'newwindow', this.onWebviewNewWindow_.bind(this, gaiaFrame)); | 178 'newwindow', this.onWebviewNewWindow_.bind(this, gaiaFrame)); |
| 176 } | 179 } |
| 177 if (this.constrained_) { | 180 if (this.constrained_) { |
| 178 gaiaFrame.request.onCompleted.addListener( | 181 gaiaFrame.request.onCompleted.addListener( |
| 179 this.onWebviewRequestCompleted_.bind(this), | 182 this.onWebviewRequestCompleted_.bind(this), |
| 180 {urls: ['<all_urls>'], types: ['main_frame']}, | 183 {urls: ['<all_urls>'], types: ['main_frame']}, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 } else if (call.method == 'confirm') { | 256 } else if (call.method == 'confirm') { |
| 254 if (call.token != this.apiToken_) | 257 if (call.token != this.apiToken_) |
| 255 console.error('Authenticator.onAPICall_: token mismatch'); | 258 console.error('Authenticator.onAPICall_: token mismatch'); |
| 256 } else { | 259 } else { |
| 257 console.error('Authenticator.onAPICall_: unknown message'); | 260 console.error('Authenticator.onAPICall_: unknown message'); |
| 258 } | 261 } |
| 259 }, | 262 }, |
| 260 | 263 |
| 261 onLoginUILoaded: function() { | 264 onLoginUILoaded: function() { |
| 262 var msg = { | 265 var msg = { |
| 263 'method': 'loginUILoaded' | 266 'method': 'loginUILoaded', |
| 267 'load_start_ts': this.load_start_ts_, |
| 268 'load_stop_ts': Date.now() |
| 264 }; | 269 }; |
| 265 window.parent.postMessage(msg, this.parentPage_); | 270 window.parent.postMessage(msg, this.parentPage_); |
| 266 if (this.inlineMode_) { | 271 if (this.inlineMode_) { |
| 267 // TODO(guohui): temporary workaround until webview team fixes the focus | 272 // TODO(guohui): temporary workaround until webview team fixes the focus |
| 268 // on their side. | 273 // on their side. |
| 269 var gaiaFrame = $('gaia-frame'); | 274 var gaiaFrame = $('gaia-frame'); |
| 270 gaiaFrame.focus(); | 275 gaiaFrame.focus(); |
| 271 gaiaFrame.onblur = function() { | 276 gaiaFrame.onblur = function() { |
| 272 gaiaFrame.focus(); | 277 gaiaFrame.focus(); |
| 273 }; | 278 }; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } else if (msg.method == 'redirectToSignin' && | 369 } else if (msg.method == 'redirectToSignin' && |
| 365 this.isParentMessage_(e)) { | 370 this.isParentMessage_(e)) { |
| 366 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 371 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
| 367 } else { | 372 } else { |
| 368 console.error('Authenticator.onMessage: unknown message + origin!?'); | 373 console.error('Authenticator.onMessage: unknown message + origin!?'); |
| 369 } | 374 } |
| 370 } | 375 } |
| 371 }; | 376 }; |
| 372 | 377 |
| 373 Authenticator.getInstance().initialize(); | 378 Authenticator.getInstance().initialize(); |
| OLD | NEW |