OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Common OOBE controller methods. This method is shared between | 6 * @fileoverview Common OOBE controller methods. This method is shared between |
7 * OOBE, login, and the lock screen. Add only methods that need to be shared | 7 * OOBE, login, and the lock screen. Add only methods that need to be shared |
8 * between all *three* screens here, as each additional method increases the | 8 * between all *three* screens here, as each additional method increases the |
9 * time it takes to show the lock screen. | 9 * time it takes to show the lock screen. |
10 * | 10 * |
11 * If a method needs to be shared between the oobe and login screens, add it to | 11 * If a method needs to be shared between the oobe and login screens, add it to |
12 * login_non_lock_shared.js. | 12 * login_non_lock_shared.js. |
13 */ | 13 */ |
14 | 14 |
15 // <include src="test_util.js"> | 15 // <include src="test_util.js"> |
16 // <include src="../../../../../ui/login/screen.js"> | 16 // <include src="../../../../../ui/login/screen.js"> |
17 // <include src="screen_context.js"> | 17 // <include src="screen_context.js"> |
18 // <include src="../user_images_grid.js"> | 18 // <include src="../user_images_grid.js"> |
19 // <include src="apps_menu.js"> | 19 // <include src="apps_menu.js"> |
20 // <include src="../../../../../ui/login/bubble.js"> | 20 // <include src="../../../../../ui/login/bubble.js"> |
21 // <include src="../../../../../ui/login/display_manager.js"> | 21 // <include src="../../../../../ui/login/display_manager.js"> |
22 // <include src="header_bar.js"> | 22 // <include src="header_bar.js"> |
23 | 23 |
24 // <include src="../../../../../ui/login/account_picker/screen_account_picker.js
"> | 24 // <include |
| 25 // src="../../../../../ui/login/account_picker/screen_account_picker.js"> |
25 | 26 |
26 // <include src="../../../../../ui/login/login_ui_tools.js"> | 27 // <include src="../../../../../ui/login/login_ui_tools.js"> |
27 // <include src="../../../../../ui/login/account_picker/user_pod_row.js"> | 28 // <include src="../../../../../ui/login/account_picker/user_pod_row.js"> |
28 // <include src="../../../../../ui/login/resource_loader.js"> | 29 // <include src="../../../../../ui/login/resource_loader.js"> |
29 | 30 |
30 cr.define('cr.ui', function() { | 31 cr.define('cr.ui', function() { |
31 var DisplayManager = cr.ui.login.DisplayManager; | 32 var DisplayManager = cr.ui.login.DisplayManager; |
32 | 33 |
33 /** | 34 /** |
34 * Constructs an Out of box controller. It manages initialization of screens, | 35 * Constructs an Out of box controller. It manages initialization of screens, |
35 * transitions, error messages display. | 36 * transitions, error messages display. |
36 * @extends {DisplayManager} | 37 * @extends {DisplayManager} |
37 * @constructor | 38 * @constructor |
38 */ | 39 */ |
39 function Oobe() { | 40 function Oobe() {} |
40 } | |
41 | 41 |
42 /** | 42 /** |
43 * Delay in milliseconds between start of OOBE animation and start of | 43 * Delay in milliseconds between start of OOBE animation and start of |
44 * header bar animation. | 44 * header bar animation. |
45 */ | 45 */ |
46 var HEADER_BAR_DELAY_MS = 300; | 46 var HEADER_BAR_DELAY_MS = 300; |
47 | 47 |
48 cr.addSingletonGetter(Oobe); | 48 cr.addSingletonGetter(Oobe); |
49 | 49 |
50 Oobe.prototype = { | 50 Oobe.prototype = { |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 Oobe.disableSigninUI(); | 304 Oobe.disableSigninUI(); |
305 chrome.send('skipToLoginForTesting'); | 305 chrome.send('skipToLoginForTesting'); |
306 }; | 306 }; |
307 | 307 |
308 /** | 308 /** |
309 * Login for telemetry. | 309 * Login for telemetry. |
310 * @param {string} username Login username. | 310 * @param {string} username Login username. |
311 * @param {string} password Login password. | 311 * @param {string} password Login password. |
312 * @param {boolean} enterpriseEnroll Login as an enterprise enrollment? | 312 * @param {boolean} enterpriseEnroll Login as an enterprise enrollment? |
313 */ | 313 */ |
314 Oobe.loginForTesting = function(username, password, gaia_id, | 314 Oobe.loginForTesting = function( |
315 enterpriseEnroll = false) { | 315 username, password, gaia_id, enterpriseEnroll = false) { |
316 // Helper method that runs |fn| after |screenName| is visible. | 316 // Helper method that runs |fn| after |screenName| is visible. |
317 function waitForOobeScreen(screenName, fn) { | 317 function waitForOobeScreen(screenName, fn) { |
318 if (Oobe.getInstance().currentScreen && | 318 if (Oobe.getInstance().currentScreen && |
319 Oobe.getInstance().currentScreen.id === screenName) { | 319 Oobe.getInstance().currentScreen.id === screenName) { |
320 fn(); | 320 fn(); |
321 } else { | 321 } else { |
322 $('oobe').addEventListener('screenchanged', function handler(e) { | 322 $('oobe').addEventListener('screenchanged', function handler(e) { |
323 if (e.detail == screenName) { | 323 if (e.detail == screenName) { |
324 $('oobe').removeEventListener('screenchanged', handler); | 324 $('oobe').removeEventListener('screenchanged', handler); |
325 fn(); | 325 fn(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 }; | 401 }; |
402 | 402 |
403 /** | 403 /** |
404 * Returns true if enrollment was successful. Dismisses the enrollment | 404 * Returns true if enrollment was successful. Dismisses the enrollment |
405 * attribute screen if it's present. | 405 * attribute screen if it's present. |
406 */ | 406 */ |
407 Oobe.isEnrollmentSuccessfulForTest = function() { | 407 Oobe.isEnrollmentSuccessfulForTest = function() { |
408 if (document.querySelector('.oauth-enroll-state-attribute-prompt')) | 408 if (document.querySelector('.oauth-enroll-state-attribute-prompt')) |
409 chrome.send('oauthEnrollAttributes', ['', '']); | 409 chrome.send('oauthEnrollAttributes', ['', '']); |
410 | 410 |
411 return $('oauth-enrollment').classList.contains( | 411 return $('oauth-enrollment') |
412 'oauth-enroll-state-success'); | 412 .classList.contains('oauth-enroll-state-success'); |
413 }; | 413 }; |
414 | 414 |
415 /** | 415 /** |
416 * Shows/hides login UI control bar with buttons like [Shut down]. | 416 * Shows/hides login UI control bar with buttons like [Shut down]. |
417 */ | 417 */ |
418 Oobe.showControlBar = function(show) { | 418 Oobe.showControlBar = function(show) { |
419 Oobe.getInstance().headerHidden = !show; | 419 Oobe.getInstance().headerHidden = !show; |
420 }; | 420 }; |
421 | 421 |
422 /** | 422 /** |
423 * Changes some UI which depends on the virtual keyboard being shown/hidden. | 423 * Changes some UI which depends on the virtual keyboard being shown/hidden. |
424 */ | 424 */ |
425 Oobe.setVirtualKeyboardShown = function(shown) { | 425 Oobe.setVirtualKeyboardShown = function(shown) { |
426 Oobe.getInstance().virtualKeyboardShown = shown; | 426 Oobe.getInstance().virtualKeyboardShown = shown; |
427 $('pod-row').setFocusedPodPinVisibility(!shown); | 427 $('pod-row').setFocusedPodPinVisibility(!shown); |
428 }; | 428 }; |
429 | 429 |
430 /** | 430 /** |
431 * Sets the current size of the client area (display size). | 431 * Sets the current size of the client area (display size). |
432 * @param {number} width client area width | 432 * @param {number} width client area width |
433 * @param {number} height client area height | 433 * @param {number} height client area height |
434 */ | 434 */ |
435 Oobe.setClientAreaSize = function(width, height) { | 435 Oobe.setClientAreaSize = function(width, height) { |
436 Oobe.getInstance().setClientAreaSize(width, height); | 436 Oobe.getInstance().setClientAreaSize(width, height); |
437 }; | 437 }; |
438 | 438 |
439 // Export | 439 // Export |
440 return { | 440 return {Oobe: Oobe}; |
441 Oobe: Oobe | |
442 }; | |
443 }); | 441 }); |
444 | 442 |
445 var Oobe = cr.ui.Oobe; | 443 var Oobe = cr.ui.Oobe; |
446 | 444 |
447 // Allow selection events on components with editable text (password field) | 445 // Allow selection events on components with editable text (password field) |
448 // bug (http://code.google.com/p/chromium/issues/detail?id=125863) | 446 // bug (http://code.google.com/p/chromium/issues/detail?id=125863) |
449 disableTextSelectAndDrag(function(e) { | 447 disableTextSelectAndDrag(function(e) { |
450 var src = e.target; | 448 var src = e.target; |
451 return src instanceof HTMLTextAreaElement || | 449 return src instanceof HTMLTextAreaElement || |
452 src instanceof HTMLInputElement && | 450 src instanceof HTMLInputElement && /text|password|search/.test(src.type); |
453 /text|password|search/.test(src.type); | |
454 }); | 451 }); |
455 | 452 |
456 | 453 |
457 (function() { | 454 (function() { |
458 'use strict'; | 455 'use strict'; |
459 | 456 |
460 document.addEventListener('DOMContentLoaded', function() { | 457 document.addEventListener('DOMContentLoaded', function() { |
461 try { | 458 try { |
462 Oobe.initialize(); | 459 Oobe.initialize(); |
463 } finally { | 460 } finally { |
464 // TODO(crbug.com/712078): Do not set readyForTesting in case of that | 461 // TODO(crbug.com/712078): Do not set readyForTesting in case of that |
465 // initialize() is failed. Currently, in some situation, initialize() | 462 // initialize() is failed. Currently, in some situation, initialize() |
466 // raises an exception unexpectedly. It means testing APIs should not | 463 // raises an exception unexpectedly. It means testing APIs should not |
467 // be called then. However, checking it here now causes bots failures | 464 // be called then. However, checking it here now causes bots failures |
468 // unfortunately. So, as a short term workaround, here set | 465 // unfortunately. So, as a short term workaround, here set |
469 // readyForTesting even on failures, just to make test bots happy. | 466 // readyForTesting even on failures, just to make test bots happy. |
470 Oobe.readyForTesting = true; | 467 Oobe.readyForTesting = true; |
471 } | 468 } |
472 }); | 469 }); |
473 | 470 |
474 // Install a global error handler so stack traces are included in logs. | 471 // Install a global error handler so stack traces are included in logs. |
475 window.onerror = function(message, file, line, column, error) { | 472 window.onerror = function(message, file, line, column, error) { |
476 console.error(error.stack); | 473 console.error(error.stack); |
477 }; | 474 }; |
478 })(); | 475 })(); |
OLD | NEW |