1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * @fileoverview Common OOBE controller methods.
9 <include src
="test_util.js">
10 <include src
="../../../../../ui/login/screen.js">
11 <include src
="screen_context.js">
12 <include src
="../user_images_grid.js">
13 <include src
="apps_menu.js">
14 <include src
="../../../../../ui/login/bubble.js">
15 <include src
="../../../../../ui/login/display_manager.js">
16 <include src
="header_bar.js">
17 <include src
="network_dropdown.js">
18 <include src
="oobe_screen_reset_confirmation_overlay.js">
19 <include src
="oobe_screen_reset.js">
20 <include src
="oobe_screen_autolaunch.js">
21 <include src
="oobe_screen_enable_kiosk.js">
22 <include src
="oobe_screen_terms_of_service.js">
23 <include src
="oobe_screen_user_image.js">
24 <include src
="../../../../../ui/login/account_picker/screen_account_picker.js">
25 <include src
="screen_app_launch_splash.js">
26 <include src
="screen_error_message.js">
27 <include src
="screen_gaia_signin.js">
28 <include src
="screen_password_changed.js">
29 <include src
="screen_supervised_user_creation.js">
30 <include src
="screen_tpm_error.js">
31 <include src
="screen_wrong_hwid.js">
32 <include src
="screen_confirm_password.js">
33 <include src
="screen_fatal_error.js">
34 <include src
="screen_device_disabled.js">
35 <include src
="../../../../../ui/login/login_ui_tools.js">
36 <include src
="../../../../../ui/login/account_picker/user_pod_row.js">
37 <include src
="../../../../../ui/login/resource_loader.js">
39 cr
.define('cr.ui', function() {
40 var DisplayManager
= cr
.ui
.login
.DisplayManager
;
43 * Constructs an Out of box controller. It manages initialization of screens,
44 * transitions, error messages display.
45 * @extends {DisplayManager}
52 * Delay in milliseconds between start of OOBE animation and start of
53 * header bar animation.
55 var HEADER_BAR_DELAY_MS
= 300;
57 cr
.addSingletonGetter(Oobe
);
60 __proto__
: DisplayManager
.prototype,
64 * Handle accelerators. These are passed from native code instead of a JS
65 * event handler in order to make sure that embedded iframes cannot swallow
67 * @param {string} name Accelerator name.
69 Oobe
.handleAccelerator = function(name
) {
70 Oobe
.getInstance().handleAccelerator(name
);
74 * Shows the given screen.
75 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
77 Oobe
.showScreen = function(screen
) {
78 Oobe
.getInstance().showScreen(screen
);
82 * Updates version label visibilty.
83 * @param {boolean} show True if version label should be visible.
85 Oobe
.showVersion = function(show
) {
86 Oobe
.getInstance().showVersion(show
);
90 * Update body class to switch between OOBE UI and Login UI.
92 Oobe
.showOobeUI = function(showOobe
) {
94 document
.body
.classList
.add('oobe-display');
96 // Callback to animate the header bar in.
97 var showHeaderBar = function() {
98 login
.HeaderBar
.animateIn(false, function() {
99 chrome
.send('headerBarVisible');
102 // Start asynchronously so the OOBE network screen comes in first.
103 window
.setTimeout(showHeaderBar
, HEADER_BAR_DELAY_MS
);
105 document
.body
.classList
.remove('oobe-display');
106 Oobe
.getInstance().prepareForLoginDisplay_();
107 // Ensure header bar is visible when switching to Login UI from oobe.
108 if (Oobe
.getInstance().displayType
== DISPLAY_TYPE
.OOBE
)
109 login
.HeaderBar
.animateIn(true);
112 Oobe
.getInstance().headerHidden
= false;
116 * When |showShutdown| is set to "true", the shutdown button is shown and the
117 * reboot button hidden. If set to "false", the reboot button is visible and
118 * the shutdown button hidden.
120 Oobe
.showShutdown = function(showShutdown
) {
121 $('login-header-bar').showShutdownButton
= showShutdown
;
122 $('login-header-bar').showRebootButton
= !showShutdown
;
126 * Enables keyboard driven flow.
128 Oobe
.enableKeyboardFlow = function(value
) {
129 // Don't show header bar for OOBE.
130 Oobe
.getInstance().forceKeyboardFlow
= value
;
134 * Disables signin UI.
136 Oobe
.disableSigninUI = function() {
137 DisplayManager
.disableSigninUI();
142 * @param {string} opt_email An optional email for signin UI.
144 Oobe
.showSigninUI = function(opt_email
) {
145 DisplayManager
.showSigninUI(opt_email
);
149 * Resets sign-in input fields.
150 * @param {boolean} forceOnline Whether online sign-in should be forced.
151 * If |forceOnline| is false previously used sign-in type will be used.
153 Oobe
.resetSigninUI = function(forceOnline
) {
154 DisplayManager
.resetSigninUI(forceOnline
);
158 * Shows sign-in error bubble.
159 * @param {number} loginAttempts Number of login attemps tried.
160 * @param {string} message Error message to show.
161 * @param {string} link Text to use for help link.
162 * @param {number} helpId Help topic Id associated with help link.
164 Oobe
.showSignInError = function(loginAttempts
, message
, link
, helpId
) {
165 DisplayManager
.showSignInError(loginAttempts
, message
, link
, helpId
);
169 * Shows password changed screen that offers migration.
170 * @param {boolean} showError Whether to show the incorrect password error.
172 Oobe
.showPasswordChangedScreen = function(showError
) {
173 DisplayManager
.showPasswordChangedScreen(showError
);
177 * Shows dialog to create a supervised user.
179 Oobe
.showSupervisedUserCreationScreen = function() {
180 DisplayManager
.showSupervisedUserCreationScreen();
184 * Shows TPM error screen.
186 Oobe
.showTpmError = function() {
187 DisplayManager
.showTpmError();
191 * Clears error bubble as well as optional menus that could be open.
193 Oobe
.clearErrors = function() {
194 var accessibilityMenu
= $('accessibility-menu');
195 if (accessibilityMenu
)
196 accessibilityMenu
.hide();
197 DisplayManager
.clearErrors();
201 * Displays animations on successful authentication, that have to happen
202 * before login UI is dismissed.
204 Oobe
.animateAuthenticationSuccess = function() {
205 login
.HeaderBar
.animateOut(function() {
206 chrome
.send('unlockOnLoginSuccess');
211 * Displays animations that have to happen once login UI is fully displayed.
213 Oobe
.animateOnceFullyDisplayed = function() {
214 login
.HeaderBar
.animateIn(true, function() {
215 chrome
.send('headerBarVisible');
220 * Sets text content for a div with |labelId|.
221 * @param {string} labelId Id of the label div.
222 * @param {string} labelText Text for the label.
224 Oobe
.setLabelText = function(labelId
, labelText
) {
225 DisplayManager
.setLabelText(labelId
, labelText
);
229 * Sets the text content of the enterprise info message.
230 * If the text is empty, the entire notification will be hidden.
231 * @param {string} messageText The message text.
233 Oobe
.setEnterpriseInfo = function(messageText
) {
234 DisplayManager
.setEnterpriseInfo(messageText
);
238 * Updates the device requisition string shown in the requisition prompt.
239 * @param {string} requisition The device requisition.
241 Oobe
.updateDeviceRequisition = function(requisition
) {
242 Oobe
.getInstance().updateDeviceRequisition(requisition
);
246 * Enforces focus on user pod of locked user.
248 Oobe
.forceLockedUserPodFocus = function() {
249 login
.AccountPickerScreen
.forceLockedUserPodFocus();
253 * Clears password field in user-pod.
255 Oobe
.clearUserPodPassword = function() {
256 DisplayManager
.clearUserPodPassword();
260 * Restores input focus to currently selected pod.
262 Oobe
.refocusCurrentPod = function() {
263 DisplayManager
.refocusCurrentPod();
267 * Skip to login screen for telemetry.
269 Oobe
.skipToLoginForTesting = function() {
270 Oobe
.disableSigninUI();
271 chrome
.send('skipToLoginForTesting');
275 * Login for telemetry.
276 * @param {string} username Login username.
277 * @param {string} password Login password.
279 Oobe
.loginForTesting = function(username
, password
) {
280 Oobe
.disableSigninUI();
281 chrome
.send('skipToLoginForTesting', [username
]);
282 chrome
.send('completeLogin', ['12345', username
, password
, false]);
286 * Guest login for telemetry.
288 Oobe
.guestLoginForTesting = function() {
289 Oobe
.skipToLoginForTesting();
290 chrome
.send('launchIncognito');
294 * Authenticate for telemetry - used for screenlocker.
295 * @param {string} username Login username.
296 * @param {string} password Login password.
298 Oobe
.authenticateForTesting = function(username
, password
) {
299 Oobe
.disableSigninUI();
300 chrome
.send('authenticateUser', [username
, password
]);
304 * Gaia login screen for telemetry.
306 Oobe
.addUserForTesting = function() {
307 Oobe
.skipToLoginForTesting();
308 chrome
.send('addUser');
312 * Shows the add user dialog. Used in browser tests.
314 Oobe
.showAddUserForTesting = function() {
315 chrome
.send('showAddUser');
319 * Hotrod requisition for telemetry.
321 Oobe
.remoraRequisitionForTesting = function() {
322 chrome
.send('setDeviceRequisition', ['remora']);
326 * Finish enterprise enrollment for telemetry.
328 Oobe
.enterpriseEnrollmentDone = function() {
329 chrome
.send('oauthEnrollClose', ['done']);
333 * Shows/hides login UI control bar with buttons like [Shut down].
335 Oobe
.showControlBar = function(show
) {
336 Oobe
.getInstance().headerHidden
= !show
;
340 * Sets the current state of the virtual keyboard (shown/hidden, size).
342 Oobe
.setKeyboardState = function(shown
, width
, height
) {
343 Oobe
.getInstance().virtualKeyboardShown
= shown
;
344 Oobe
.getInstance().setVirtualKeyboardSize(width
, height
);
348 * Sets the current size of the client area (display size).
349 * @param {number} width client area width
350 * @param {number} height client area height
352 Oobe
.setClientAreaSize = function(width
, height
) {
353 Oobe
.getInstance().setClientAreaSize(width
, height
);
362 var Oobe
= cr
.ui
.Oobe
;
364 // Allow selection events on components with editable text (password field)
365 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
366 disableTextSelectAndDrag(function(e
) {
368 return src
instanceof HTMLTextAreaElement
||
369 src
instanceof HTMLInputElement
&&
370 /text|password|search/.test(src
.type
);
373 // Register assets for async loading.
375 id
: SCREEN_OOBE_ENROLLMENT
,
376 html
: [{ url
: 'chrome://oobe/enrollment.html', targetID
: 'inner-container' }],
377 css
: ['chrome://oobe/enrollment.css'],
378 js
: ['chrome://oobe/enrollment.js']
379 }].forEach(cr
.ui
.login
.ResourceLoader
.registerAssets
);
384 function initializeOobe() {
385 // Immediately load async assets.
386 // TODO(dconnelly): remove this at some point and only load as needed.
387 // See crbug.com/236426
388 cr
.ui
.login
.ResourceLoader
.loadAssets(SCREEN_OOBE_ENROLLMENT
, function() {
389 // This screen is async-loaded so we manually trigger i18n processing.
390 i18nTemplate
.process($('oauth-enrollment'), loadTimeData
);
391 // Delayed binding since this isn't defined yet.
392 login
.OAuthEnrollmentScreen
.register();
395 cr
.ui
.Oobe
.initialize();
398 document
.addEventListener('DOMContentLoaded', function() {
399 if (!window
['WAIT_FOR_POLYMER']) {
403 window
.addEventListener('polymer-ready', function() {