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

Side by Side Diff: chrome/browser/resources/chromeos/login/screen_gaia_signin.js

Issue 8564008: [cros,login] Restore the focus after hidden auth extension has grabbed it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 GaiaSigninScreen.decorate(screen); 23 GaiaSigninScreen.decorate(screen);
24 Oobe.getInstance().registerScreen(screen); 24 Oobe.getInstance().registerScreen(screen);
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 extensionUrl_: null,
34
35 // Whether extension should be loaded silently.
36 silentLoad_: false,
37
38 // Whether there is focused element.
39 hasFocused_: false,
34 40
35 // Number of times that we reload extension frame. 41 // Number of times that we reload extension frame.
36 retryCount_: 0, 42 retryCount_: 0,
37 43
38 // Timer id of pending retry. 44 // Timer id of pending retry.
39 retryTimer_: undefined, 45 retryTimer_: undefined,
40 46
41 /** @inheritDoc */ 47 /** @inheritDoc */
42 decorate: function() { 48 decorate: function() {
49 this.frame_ = $('signin-frame');
50
43 $('createAccount').innerHTML = localStrings.getStringF( 51 $('createAccount').innerHTML = localStrings.getStringF(
44 'createAccount', 52 'createAccount',
45 '<a id="createAccountLink" class="signin-link" href="#">', 53 '<a id="createAccountLink" class="signin-link" href="#">',
46 '</a>'); 54 '</a>');
47 $('guestSignin').innerHTML = localStrings.getStringF( 55 $('guestSignin').innerHTML = localStrings.getStringF(
48 'guestSignin', 56 'guestSignin',
49 '<a id="guestSigninLink" class="signin-link" href="#">', 57 '<a id="guestSigninLink" class="signin-link" href="#">',
50 '</a>'); 58 '</a>');
51 $('createAccountLink').onclick = function() { 59 $('createAccountLink').onclick = function() {
52 chrome.send('createAccount'); 60 chrome.send('createAccount');
53 }; 61 };
54 $('guestSigninLink').onclick = function() { 62 $('guestSigninLink').onclick = function() {
55 chrome.send('launchIncognito'); 63 chrome.send('launchIncognito');
56 }; 64 };
65 document.addEventListener(
66 'focusin', this.selfBind_(this.onFocusIn_.bind(this)));
57 }, 67 },
58 68
59 /** 69 /**
60 * Header text of the screen. 70 * Header text of the screen.
61 * @type {string} 71 * @type {string}
62 */ 72 */
63 get header() { 73 get header() {
64 return localStrings.getString('signinScreenTitle'); 74 return localStrings.getString('signinScreenTitle');
65 }, 75 },
66 76
67 /** 77 /**
68 * Shows/hides loading UI. 78 * Shows/hides loading UI.
69 * @param {boolean} show True to show loading UI. 79 * @param {boolean} show True to show loading UI.
70 * @private 80 * @private
71 */ 81 */
72 showLoadingUI_: function(show) { 82 showLoadingUI_: function(show) {
73 $('gaia-loading').hidden = !show; 83 $('gaia-loading').hidden = !show;
74 $('signin-frame').hidden = show; 84 this.frame_.hidden = show;
75 85
76 // Sign-in right panel is hidden if all its items are hidden. 86 // Sign-in right panel is hidden if all its items are hidden.
77 $('signin-right').hidden = show || 87 $('signin-right').hidden = show ||
78 ($('createAccount').hidden && $('guestSignin').hidden); 88 ($('createAccount').hidden && $('guestSignin').hidden);
79 }, 89 },
80 90
81 /** 91 /**
82 * Whether Gaia is loading. 92 * Whether Gaia is loading.
83 * @type {boolean} 93 * @type {boolean}
84 */ 94 */
(...skipping 15 matching lines...) Expand all
100 onBeforeShow: function(data) { 110 onBeforeShow: function(data) {
101 // Announce the name of the screen, if accessibility is on. 111 // Announce the name of the screen, if accessibility is on.
102 $('gaia-signin-aria-label').setAttribute( 112 $('gaia-signin-aria-label').setAttribute(
103 'aria-label', localStrings.getString('signinScreenTitle')); 113 'aria-label', localStrings.getString('signinScreenTitle'));
104 114
105 // Button header is always visible when sign in is presented. 115 // Button header is always visible when sign in is presented.
106 // Header is hidden once GAIA reports on successful sign in. 116 // Header is hidden once GAIA reports on successful sign in.
107 Oobe.getInstance().headerHidden = false; 117 Oobe.getInstance().headerHidden = false;
108 }, 118 },
109 119
110 setExtensionUrl_: function(data) { 120 /**
121 * Returns function which gets an event and passes it and self to listener.
122 * @param {!Object} listener Listener to be wrapped.
123 */
124 selfBind_: function(listener) {
125 var selfBinded = function(e) {
126 listener(e, selfBinded);
127 }
128 return selfBinded;
129 },
130
131 /**
132 * Tracks first focus in event.
133 * @param {!Object} e Focus in event.
134 * @param {!Object} listener Listener which shold be removed from event
135 * listeners list.
136 */
137 onFocusIn_: function(e, listener) {
138 this.hasFocused_ = true;
139 document.removeEventListener('focusin', listener);
140 },
xiyuan 2011/11/14 17:52:28 nit: insert an empty line after
altimofeev 2011/11/14 20:21:45 Done.
141 /**
142 * Restore focus back to the focused element.
143 * @param {!Object} e Focus out event.
144 * @param {!Object} listener Listener which shold be removed from event
145 * listeners list.
146 */
147 onFocusOut_: function(e, listener) {
148 window.setTimeout(e.target.focus.bind(e.target), 0);
149 document.removeEventListener('focusout', listener);
150 },
151
152 loadAuthExtension_: function(data) {
153 this.silentLoad_ = data.silentLoad;
154
111 $('createAccount').hidden = !data.createAccount; 155 $('createAccount').hidden = !data.createAccount;
112 $('guestSignin').hidden = !data.guestSignin; 156 $('guestSignin').hidden = !data.guestSignin;
113 157
114 var params = []; 158 var params = [];
115 if (data.gaiaOrigin) 159 if (data.gaiaOrigin)
116 params.push('gaiaOrigin=' + encodeURIComponent(data.gaiaOrigin)); 160 params.push('gaiaOrigin=' + encodeURIComponent(data.gaiaOrigin));
117 if (data.hl) 161 if (data.hl)
118 params.push('hl=' + encodeURIComponent(data.hl)); 162 params.push('hl=' + encodeURIComponent(data.hl));
119 if (data.email) 163 if (data.email)
120 params.push('email=' + encodeURIComponent(data.email)); 164 params.push('email=' + encodeURIComponent(data.email));
121 if (data.test_email) 165 if (data.test_email)
122 params.push('test_email=' + encodeURIComponent(data.test_email)); 166 params.push('test_email=' + encodeURIComponent(data.test_email));
123 if (data.test_password) 167 if (data.test_password)
124 params.push('test_password=' + encodeURIComponent(data.test_password)); 168 params.push('test_password=' + encodeURIComponent(data.test_password));
125 169
126 var url = data.startUrl; 170 var url = data.startUrl;
127 if (params.length) 171 if (params.length)
128 url += '?' + params.join('&'); 172 url += '?' + params.join('&');
129 173
130 if (data.forceReload || this.extension_url_ != url) { 174 if (data.forceReload || this.extensionUrl_ != url) {
131 console.log('Opening extension: ' + data.startUrl + 175 console.log('Opening extension: ' + data.startUrl +
132 ', opt_email=' + data.email); 176 ', opt_email=' + data.email);
133 177
134 $('signin-frame').src = url; 178 this.frame_.src = url;
135 this.extension_url_ = url; 179 this.extensionUrl_ = url;
136 180
137 this.loading = true; 181 this.loading = true;
138 this.clearRetry_(); 182 this.clearRetry_();
139 } else if (this.loading) { 183 } else if (this.loading) {
140 // Probably an error has occurred, so trying to reload. 184 // Probably an error has occurred, so trying to reload.
141 this.doReload(); 185 this.doReload();
142 } 186 }
143 }, 187 },
144 188
145 /** 189 /**
146 * Checks if message comes from the loaded authentication extension. 190 * Checks if message comes from the loaded authentication extension.
147 * @param e {object} Payload of the received HTML5 message. 191 * @param e {object} Payload of the received HTML5 message.
148 * @type {bool} 192 * @type {bool}
149 */ 193 */
150 isAuthExtMessage_: function(e) { 194 isAuthExtMessage_: function(e) {
151 return this.extension_url_ != null && 195 return this.extensionUrl_ != null &&
152 this.extension_url_.indexOf(e.origin) == 0 && 196 this.extensionUrl_.indexOf(e.origin) == 0 &&
153 e.source == $('signin-frame').contentWindow; 197 e.source == this.frame_.contentWindow;
154 }, 198 },
155 199
156 /** 200 /**
157 * Event handler that is invoked when HTML5 message is received. 201 * Event handler that is invoked when HTML5 message is received.
158 * @param e {object} Payload of the received HTML5 message. 202 * @param e {object} Payload of the received HTML5 message.
159 */ 203 */
160 onMessage_: function(e) { 204 onMessage_: function(e) {
161 var msg = e.data; 205 var msg = e.data;
162 if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) { 206 if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) {
163 chrome.send('completeLogin', [msg.email, msg.password] ); 207 chrome.send('completeLogin', [msg.email, msg.password] );
164 this.loading = true; 208 this.loading = true;
165 // Now that we're in logged in state header should be hidden. 209 // Now that we're in logged in state header should be hidden.
166 Oobe.getInstance().headerHidden = true; 210 Oobe.getInstance().headerHidden = true;
167 } else if (msg.method == 'loginUILoaded' && this.isAuthExtMessage_(e)) { 211 } else if (msg.method == 'loginUILoaded' && this.isAuthExtMessage_(e)) {
212 // TODO(altimofeev): there is no guarantee that next 'focusout' event
213 // will be caused by the extension, so better approach is direct asking
214 // the extension (and gaia consequently) to not grab the focus.
215 if (this.silentLoad_ && this.hasFocused_) {
216 document.addEventListener(
217 'focusout', this.selfBind_(this.onFocusOut_.bind(this)));
218 }
168 $('error-message').update(); 219 $('error-message').update();
169 this.loading = false; 220 this.loading = false;
170 this.clearRetry_(); 221 this.clearRetry_();
171 chrome.send('loginWebuiReady'); 222 chrome.send('loginWebuiReady');
172 } 223 }
173 }, 224 },
174 225
175 /** 226 /**
176 * Clears input fields and switches to input mode. 227 * Clears input fields and switches to input mode.
177 * @param {boolean} takeFocus True to take focus. 228 * @param {boolean} takeFocus True to take focus.
(...skipping 14 matching lines...) Expand all
192 window.clearTimeout(this.retryTimer_); 243 window.clearTimeout(this.retryTimer_);
193 this.retryTimer_ = undefined; 244 this.retryTimer_ = undefined;
194 } 245 }
195 }, 246 },
196 247
197 /** 248 /**
198 * Reloads extension frame. 249 * Reloads extension frame.
199 */ 250 */
200 doReload: function() { 251 doReload: function() {
201 console.log('Reload auth extension frame.'); 252 console.log('Reload auth extension frame.');
202 $('signin-frame').src = this.extension_url_; 253 this.frame_.src = this.extensionUrl_;
203 this.retryTimer_ = undefined; 254 this.retryTimer_ = undefined;
204 }, 255 },
205 256
206 /** 257 /**
207 * Schedules extension frame reload. 258 * Schedules extension frame reload.
208 */ 259 */
209 scheduleRetry: function() { 260 scheduleRetry: function() {
210 if (this.retryCount_ >= 3 || this.retryTimer_) 261 if (this.retryCount_ >= 3 || this.retryTimer_)
211 return; 262 return;
212 263
213 const MAX_DELAY = 7200; // 7200 seconds (i.e. 2 hours) 264 const MAX_DELAY = 7200; // 7200 seconds (i.e. 2 hours)
214 const MIN_DELAY = 1; // 1 second 265 const MIN_DELAY = 1; // 1 second
215 266
216 var delay = Math.pow(2, this.retryCount_) * 5; 267 var delay = Math.pow(2, this.retryCount_) * 5;
217 delay = Math.max(MIN_DELAY, Math.min(MAX_DELAY, delay)) * 1000; 268 delay = Math.max(MIN_DELAY, Math.min(MAX_DELAY, delay)) * 1000;
218 269
219 ++this.retryCount_; 270 ++this.retryCount_;
220 this.retryTimer_ = window.setTimeout(this.doReload.bind(this), delay); 271 this.retryTimer_ = window.setTimeout(this.doReload.bind(this), delay);
221 console.log('GaiaSigninScreen scheduleRetry in ' + delay + 'ms.'); 272 console.log('GaiaSigninScreen scheduleRetry in ' + delay + 'ms.');
222 } 273 }
223 }; 274 };
224 275
225 GaiaSigninScreen.setExtensionUrl = function(data) { 276 GaiaSigninScreen.loadAuthExtension = function(data) {
226 $('gaia-signin').setExtensionUrl_(data); 277 $('gaia-signin').loadAuthExtension_(data);
227 }; 278 };
228 279
229 return { 280 return {
230 GaiaSigninScreen: GaiaSigninScreen 281 GaiaSigninScreen: GaiaSigninScreen
231 }; 282 };
232 }); 283 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698