| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 Oobe signin screen implementation. | 6 * @fileoverview Oobe signin screen implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('login', function() { | 9 cr.define('login', function() { |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 window.addEventListener('message', | 25 window.addEventListener('message', |
| 26 screen.onMessage_.bind(screen), false); | 26 screen.onMessage_.bind(screen), false); |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 GaiaSigninScreen.prototype = { | 29 GaiaSigninScreen.prototype = { |
| 30 __proto__: HTMLDivElement.prototype, | 30 __proto__: HTMLDivElement.prototype, |
| 31 | 31 |
| 32 // Authentication extension's start page URL. | 32 // Authentication extension's start page URL. |
| 33 extension_url_: null, | 33 extension_url_: null, |
| 34 | 34 |
| 35 // Number of times that we reload extension frame. |
| 36 retryCount_: 0, |
| 37 |
| 38 // Timer id of pending retry. |
| 39 retryTimer_: undefined, |
| 40 |
| 35 /** @inheritDoc */ | 41 /** @inheritDoc */ |
| 36 decorate: function() { | 42 decorate: function() { |
| 37 $('createAccount').innerHTML = localStrings.getStringF( | 43 $('createAccount').innerHTML = localStrings.getStringF( |
| 38 'createAccount', | 44 'createAccount', |
| 39 '<a id="createAccountLink" class="signin-link" href="#">', | 45 '<a id="createAccountLink" class="signin-link" href="#">', |
| 40 '</a>'); | 46 '</a>'); |
| 41 $('guestSignin').innerHTML = localStrings.getStringF( | 47 $('guestSignin').innerHTML = localStrings.getStringF( |
| 42 'guestSignin', | 48 'guestSignin', |
| 43 '<a id="guestSigninLink" class="signin-link" href="#">', | 49 '<a id="guestSigninLink" class="signin-link" href="#">', |
| 44 '</a>'); | 50 '</a>'); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 125 |
| 120 // Announce the name of the screen, if accessibility is on. | 126 // Announce the name of the screen, if accessibility is on. |
| 121 $('gaia-signin-aria-label').setAttribute( | 127 $('gaia-signin-aria-label').setAttribute( |
| 122 'aria-label', localStrings.getString('signinScreenTitle')); | 128 'aria-label', localStrings.getString('signinScreenTitle')); |
| 123 | 129 |
| 124 // Button header is always visible when sign in is presented. | 130 // Button header is always visible when sign in is presented. |
| 125 // Header is hidden once GAIA reports on successful sign in. | 131 // Header is hidden once GAIA reports on successful sign in. |
| 126 Oobe.getInstance().headerHidden = false; | 132 Oobe.getInstance().headerHidden = false; |
| 127 | 133 |
| 128 this.loading = true; | 134 this.loading = true; |
| 135 this.clearRetry_(); |
| 129 }, | 136 }, |
| 130 | 137 |
| 131 /** | 138 /** |
| 132 * Checks if message comes from the loaded authentication extension. | 139 * Checks if message comes from the loaded authentication extension. |
| 133 * @param e {object} Payload of the received HTML5 message. | 140 * @param e {object} Payload of the received HTML5 message. |
| 134 * @type {bool} | 141 * @type {bool} |
| 135 */ | 142 */ |
| 136 isAuthExtMessage_: function(e) { | 143 isAuthExtMessage_: function(e) { |
| 137 return this.extension_url_ != null && | 144 return this.extension_url_ != null && |
| 138 this.extension_url_.indexOf(e.origin) == 0 && | 145 this.extension_url_.indexOf(e.origin) == 0 && |
| 139 e.source == $('signin-frame').contentWindow; | 146 e.source == $('signin-frame').contentWindow; |
| 140 }, | 147 }, |
| 141 | 148 |
| 142 /** | 149 /** |
| 143 * Event handler that is invoked when HTML5 message is received. | 150 * Event handler that is invoked when HTML5 message is received. |
| 144 * @param e {object} Payload of the received HTML5 message. | 151 * @param e {object} Payload of the received HTML5 message. |
| 145 */ | 152 */ |
| 146 onMessage_: function(e) { | 153 onMessage_: function(e) { |
| 147 var msg = e.data; | 154 var msg = e.data; |
| 148 if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) { | 155 if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) { |
| 149 chrome.send('completeLogin', [msg.email, msg.password] ); | 156 chrome.send('completeLogin', [msg.email, msg.password] ); |
| 150 this.loading = true; | 157 this.loading = true; |
| 151 // Now that we're in logged in state header should be hidden. | 158 // Now that we're in logged in state header should be hidden. |
| 152 Oobe.getInstance().headerHidden = true; | 159 Oobe.getInstance().headerHidden = true; |
| 153 } else if (msg.method == 'loginUILoaded' && this.isAuthExtMessage_(e)) { | 160 } else if (msg.method == 'loginUILoaded' && this.isAuthExtMessage_(e)) { |
| 154 $('offline-message').update(); | 161 $('offline-message').update(); |
| 155 this.loading = false; | 162 this.loading = false; |
| 163 this.clearRetry_(); |
| 156 chrome.send('loginWebuiReady'); | 164 chrome.send('loginWebuiReady'); |
| 157 } | 165 } |
| 158 }, | 166 }, |
| 159 | 167 |
| 160 /** | 168 /** |
| 161 * Clears input fields and switches to input mode. | 169 * Clears input fields and switches to input mode. |
| 162 * @param {boolean} takeFocus True to take focus. | 170 * @param {boolean} takeFocus True to take focus. |
| 163 */ | 171 */ |
| 164 reset: function(takeFocus) { | 172 reset: function(takeFocus) { |
| 165 // Reload and show the sign-in UI if needed. | 173 // Reload and show the sign-in UI if needed. |
| 166 if (takeFocus) | 174 if (takeFocus) |
| 167 Oobe.showSigninUI(); | 175 Oobe.showSigninUI(); |
| 176 }, |
| 177 |
| 178 /** |
| 179 * Clears retry data. |
| 180 * @private |
| 181 */ |
| 182 clearRetry_: function() { |
| 183 this.retryCount_ = 0; |
| 184 if (this.retryTimer_) { |
| 185 window.clearTimeout(this.retryTimer_); |
| 186 this.retryTimer_ = undefined; |
| 187 } |
| 188 }, |
| 189 |
| 190 /** |
| 191 * Reloads extension frame. |
| 192 * @private |
| 193 */ |
| 194 doReload_: function() { |
| 195 console.log('Reload auth extension frame.'); |
| 196 $('signin-frame').src = this.extension_url_; |
| 197 this.retryTimer_ = undefined; |
| 198 }, |
| 199 |
| 200 /** |
| 201 * Schedules extension frame reload. |
| 202 */ |
| 203 schdeduleRetry: function() { |
| 204 if (this.retryCount_ >= 3 || this.retryTimer_) |
| 205 return; |
| 206 |
| 207 const MAX_DELAY = 7200; // 7200 seconds (i.e. 2 hours) |
| 208 const MIN_DELAY = 1; // 1 second |
| 209 |
| 210 var delay = Math.pow(2, this.retryCount_) * 5; |
| 211 delay = Math.max(MIN_DELAY, Math.min(MAX_DELAY, delay)) * 1000; |
| 212 |
| 213 ++this.retryCount_; |
| 214 this.retryTimer_ = window.setTimeout(this.doReload_.bind(this), delay); |
| 215 console.log('GaiaSigninScreen schdeduleRetry in ' + delay + 'ms.'); |
| 168 } | 216 } |
| 169 }; | 217 }; |
| 170 | 218 |
| 171 return { | 219 return { |
| 172 GaiaSigninScreen: GaiaSigninScreen | 220 GaiaSigninScreen: GaiaSigninScreen |
| 173 }; | 221 }; |
| 174 }); | 222 }); |
| OLD | NEW |