| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * The key types supported by the credentials passing API. | 31 * The key types supported by the credentials passing API. |
| 32 * @type {Array} Array of strings. | 32 * @type {Array} Array of strings. |
| 33 */ | 33 */ |
| 34 Authenticator.API_KEY_TYPES = [ | 34 Authenticator.API_KEY_TYPES = [ |
| 35 'KEY_TYPE_PASSWORD_PLAIN', | 35 'KEY_TYPE_PASSWORD_PLAIN', |
| 36 ]; | 36 ]; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Allowed origins of the hosting page. |
| 40 * @type {Array.<string>} |
| 41 */ |
| 42 Authenticator.ALLOWED_PARENT_ORIGINS = [ |
| 43 'chrome://oobe', |
| 44 'chrome://chrome-signin' |
| 45 ]; |
| 46 |
| 47 /** |
| 39 * Singleton getter of Authenticator. | 48 * Singleton getter of Authenticator. |
| 40 * @return {Object} The singleton instance of Authenticator. | 49 * @return {Object} The singleton instance of Authenticator. |
| 41 */ | 50 */ |
| 42 Authenticator.getInstance = function() { | 51 Authenticator.getInstance = function() { |
| 43 if (!Authenticator.instance_) { | 52 if (!Authenticator.instance_) { |
| 44 Authenticator.instance_ = new Authenticator(); | 53 Authenticator.instance_ = new Authenticator(); |
| 45 } | 54 } |
| 46 return Authenticator.instance_; | 55 return Authenticator.instance_; |
| 47 }; | 56 }; |
| 48 | 57 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 66 // Input params from extension initialization URL. | 75 // Input params from extension initialization URL. |
| 67 inputLang_: undefined, | 76 inputLang_: undefined, |
| 68 intputEmail_: undefined, | 77 intputEmail_: undefined, |
| 69 | 78 |
| 70 isSAMLFlow_: false, | 79 isSAMLFlow_: false, |
| 71 gaiaLoaded_: false, | 80 gaiaLoaded_: false, |
| 72 supportChannel_: null, | 81 supportChannel_: null, |
| 73 | 82 |
| 74 GAIA_URL: 'https://accounts.google.com/', | 83 GAIA_URL: 'https://accounts.google.com/', |
| 75 GAIA_PAGE_PATH: 'ServiceLogin?skipvpage=true&sarp=1&rm=hide', | 84 GAIA_PAGE_PATH: 'ServiceLogin?skipvpage=true&sarp=1&rm=hide', |
| 76 PARENT_PAGE: 'chrome://oobe/', | |
| 77 SERVICE_ID: 'chromeoslogin', | 85 SERVICE_ID: 'chromeoslogin', |
| 78 CONTINUE_URL: Authenticator.THIS_EXTENSION_ORIGIN + '/success.html', | 86 CONTINUE_URL: Authenticator.THIS_EXTENSION_ORIGIN + '/success.html', |
| 79 CONSTRAINED_FLOW_SOURCE: 'chrome', | 87 CONSTRAINED_FLOW_SOURCE: 'chrome', |
| 80 | 88 |
| 81 initialize: function() { | 89 initialize: function() { |
| 82 var params = getUrlSearchParams(location.search); | 90 var handleInitializeMessage = function(e) { |
| 83 this.parentPage_ = params.parentPage || this.PARENT_PAGE; | 91 if (Authenticator.ALLOWED_PARENT_ORIGINS.indexOf(e.origin) == -1) { |
| 92 console.error('Unexpected parent message, origin=' + e.origin); |
| 93 return; |
| 94 } |
| 95 window.removeEventListener('message', handleInitializeMessage); |
| 96 |
| 97 var params = e.data; |
| 98 params.parentPage = e.origin; |
| 99 this.initializeFromParent_(params); |
| 100 this.onPageLoad_(); |
| 101 }.bind(this); |
| 102 |
| 103 document.addEventListener('DOMContentLoaded', function() { |
| 104 window.addEventListener('message', handleInitializeMessage); |
| 105 }); |
| 106 }, |
| 107 |
| 108 initializeFromParent_: function(params) { |
| 109 this.parentPage_ = params.parentPage; |
| 84 this.gaiaUrl_ = params.gaiaUrl || this.GAIA_URL; | 110 this.gaiaUrl_ = params.gaiaUrl || this.GAIA_URL; |
| 85 | |
| 86 // Sanitize Gaia url before continuing. | |
| 87 var scheme = extractProtocol(this.gaiaUrl_); | |
| 88 if (scheme != 'https:' && scheme != 'http:') { | |
| 89 console.error('Bad Gaia URL, url=' + this.gaiaURL_); | |
| 90 return; | |
| 91 } | |
| 92 | |
| 93 this.gaiaPath_ = params.gaiaPath || this.GAIA_PAGE_PATH; | 111 this.gaiaPath_ = params.gaiaPath || this.GAIA_PAGE_PATH; |
| 94 this.inputLang_ = params.hl; | 112 this.inputLang_ = params.hl; |
| 95 this.inputEmail_ = params.email; | 113 this.inputEmail_ = params.email; |
| 96 this.service_ = params.service || this.SERVICE_ID; | 114 this.service_ = params.service || this.SERVICE_ID; |
| 97 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; | 115 this.continueUrl_ = params.continueUrl || this.CONTINUE_URL; |
| 98 this.desktopMode_ = params.desktopMode == '1'; | 116 this.desktopMode_ = params.desktopMode == '1'; |
| 99 this.isConstrainedWindow_ = params.constrained == '1'; | 117 this.isConstrainedWindow_ = params.constrained == '1'; |
| 100 this.initialFrameUrl_ = params.frameUrl || this.constructInitialFrameUrl_(); | 118 this.initialFrameUrl_ = params.frameUrl || this.constructInitialFrameUrl_(); |
| 101 this.initialFrameUrlWithoutParams_ = stripParams(this.initialFrameUrl_); | 119 this.initialFrameUrlWithoutParams_ = stripParams(this.initialFrameUrl_); |
| 102 this.needPassword_ = params.needPassword == '1'; | 120 this.needPassword_ = params.needPassword == '1'; |
| 103 | 121 |
| 104 // For CrOS 'ServiceLogin' we assume that Gaia is loaded if we recieved | 122 // For CrOS 'ServiceLogin' we assume that Gaia is loaded if we recieved |
| 105 // 'clearOldAttempts' message. For other scenarios Gaia doesn't send this | 123 // 'clearOldAttempts' message. For other scenarios Gaia doesn't send this |
| 106 // message so we have to rely on 'load' event. | 124 // message so we have to rely on 'load' event. |
| 107 // TODO(dzhioev): Do not rely on 'load' event after b/16313327 is fixed. | 125 // TODO(dzhioev): Do not rely on 'load' event after b/16313327 is fixed. |
| 108 this.assumeLoadedOnLoadEvent_ = | 126 this.assumeLoadedOnLoadEvent_ = |
| 109 this.gaiaPath_.indexOf('ServiceLogin') !== 0 || | 127 this.gaiaPath_.indexOf('ServiceLogin') !== 0 || |
| 110 this.service_ !== 'chromeoslogin'; | 128 this.service_ !== 'chromeoslogin'; |
| 111 | |
| 112 document.addEventListener('DOMContentLoaded', this.onPageLoad_.bind(this)); | |
| 113 }, | 129 }, |
| 114 | 130 |
| 115 isGaiaMessage_: function(msg) { | 131 isGaiaMessage_: function(msg) { |
| 116 // Not quite right, but good enough. | 132 // Not quite right, but good enough. |
| 117 return this.gaiaUrl_.indexOf(msg.origin) == 0 || | 133 return this.gaiaUrl_.indexOf(msg.origin) == 0 || |
| 118 this.GAIA_URL.indexOf(msg.origin) == 0; | 134 this.GAIA_URL.indexOf(msg.origin) == 0; |
| 119 }, | 135 }, |
| 120 | 136 |
| 121 isParentMessage_: function(msg) { | 137 isParentMessage_: function(msg) { |
| 122 return msg.origin == this.parentPage_; | 138 return msg.origin == this.parentPage_; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 } else if (msg.method == 'redirectToSignin' && | 496 } else if (msg.method == 'redirectToSignin' && |
| 481 this.isParentMessage_(e)) { | 497 this.isParentMessage_(e)) { |
| 482 $('gaia-frame').src = this.constructInitialFrameUrl_(); | 498 $('gaia-frame').src = this.constructInitialFrameUrl_(); |
| 483 } else { | 499 } else { |
| 484 console.error('Authenticator.onMessage: unknown message + origin!?'); | 500 console.error('Authenticator.onMessage: unknown message + origin!?'); |
| 485 } | 501 } |
| 486 } | 502 } |
| 487 }; | 503 }; |
| 488 | 504 |
| 489 Authenticator.getInstance().initialize(); | 505 Authenticator.getInstance().initialize(); |
| OLD | NEW |