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 visibility.
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
, email
) {
173 DisplayManager
.showPasswordChangedScreen(showError
, email
);
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();
193 Oobe
.showUserPods = function() {
194 $('pod-row').loadLastWallpaper();
195 Oobe
.showScreen({id
: SCREEN_ACCOUNT_PICKER
});
196 Oobe
.resetSigninUI(true);
200 * Clears error bubble as well as optional menus that could be open.
202 Oobe
.clearErrors = function() {
203 var accessibilityMenu
= $('accessibility-menu');
204 if (accessibilityMenu
)
205 accessibilityMenu
.hide();
206 DisplayManager
.clearErrors();
210 * Displays animations on successful authentication, that have to happen
211 * before login UI is dismissed.
213 Oobe
.animateAuthenticationSuccess = function() {
214 login
.HeaderBar
.animateOut(function() {
215 chrome
.send('unlockOnLoginSuccess');
220 * Displays animations that have to happen once login UI is fully displayed.
222 Oobe
.animateOnceFullyDisplayed = function() {
223 login
.HeaderBar
.animateIn(true, function() {
224 chrome
.send('headerBarVisible');
229 * Sets text content for a div with |labelId|.
230 * @param {string} labelId Id of the label div.
231 * @param {string} labelText Text for the label.
233 Oobe
.setLabelText = function(labelId
, labelText
) {
234 DisplayManager
.setLabelText(labelId
, labelText
);
238 * Sets the text content of the enterprise info message.
239 * If the text is empty, the entire notification will be hidden.
240 * @param {string} messageText The message text.
242 Oobe
.setEnterpriseInfo = function(messageText
, assetId
) {
243 DisplayManager
.setEnterpriseInfo(messageText
, assetId
);
247 * Updates the device requisition string shown in the requisition prompt.
248 * @param {string} requisition The device requisition.
250 Oobe
.updateDeviceRequisition = function(requisition
) {
251 Oobe
.getInstance().updateDeviceRequisition(requisition
);
255 * Enforces focus on user pod of locked user.
257 Oobe
.forceLockedUserPodFocus = function() {
258 login
.AccountPickerScreen
.forceLockedUserPodFocus();
262 * Clears password field in user-pod.
264 Oobe
.clearUserPodPassword = function() {
265 DisplayManager
.clearUserPodPassword();
269 * Restores input focus to currently selected pod.
271 Oobe
.refocusCurrentPod = function() {
272 DisplayManager
.refocusCurrentPod();
276 * Skip to login screen for telemetry.
278 Oobe
.skipToLoginForTesting = function() {
279 Oobe
.disableSigninUI();
280 chrome
.send('skipToLoginForTesting');
284 * Login for telemetry.
285 * @param {string} username Login username.
286 * @param {string} password Login password.
288 Oobe
.loginForTesting = function(username
, password
) {
289 Oobe
.disableSigninUI();
290 chrome
.send('skipToLoginForTesting', [username
]);
291 chrome
.send('completeLogin', ['12345', username
, password
, false]);
295 * Guest login for telemetry.
297 Oobe
.guestLoginForTesting = function() {
298 Oobe
.skipToLoginForTesting();
299 chrome
.send('launchIncognito');
303 * Authenticate for telemetry - used for screenlocker.
304 * @param {string} username Login username.
305 * @param {string} password Login password.
307 Oobe
.authenticateForTesting = function(username
, password
) {
308 Oobe
.disableSigninUI();
309 chrome
.send('authenticateUser', [username
, password
]);
313 * Gaia login screen for telemetry.
315 Oobe
.addUserForTesting = function() {
316 Oobe
.skipToLoginForTesting();
317 chrome
.send('addUser');
321 * Shows the add user dialog. Used in browser tests.
323 Oobe
.showAddUserForTesting = function() {
324 chrome
.send('showAddUser');
328 * Hotrod requisition for telemetry.
330 Oobe
.remoraRequisitionForTesting = function() {
331 chrome
.send('setDeviceRequisition', ['remora']);
335 * Begin enterprise enrollment for telemetry.
337 Oobe
.switchToEnterpriseEnrollmentForTesting = function() {
338 chrome
.send('toggleEnrollmentScreen');
342 * Finish enterprise enrollment for telemetry.
344 Oobe
.enterpriseEnrollmentDone = function() {
345 chrome
.send('oauthEnrollClose', ['done']);
349 * Returns true if enrollment was successful. Dismisses the enrollment
350 * attribute screen if it's present.
352 Oobe
.isEnrollmentSuccessfulForTest = function() {
353 if (document
.querySelector('.oauth-enroll-state-attribute-prompt'))
354 chrome
.send('oauthEnrollAttributes', ['', '']);
356 return $('oauth-enrollment').classList
.contains(
357 'oauth-enroll-state-success');
361 * Shows/hides login UI control bar with buttons like [Shut down].
363 Oobe
.showControlBar = function(show
) {
364 Oobe
.getInstance().headerHidden
= !show
;
368 * Sets the current size of the client area (display size).
369 * @param {number} width client area width
370 * @param {number} height client area height
372 Oobe
.setClientAreaSize = function(width
, height
) {
373 Oobe
.getInstance().setClientAreaSize(width
, height
);
377 * Checks whether the New Gaia flow is active.
379 Oobe
.isNewGaiaFlow = function() {
380 return document
.querySelector('.new-gaia-flow') != undefined;
389 var Oobe
= cr
.ui
.Oobe
;
391 // Allow selection events on components with editable text (password field)
392 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
393 disableTextSelectAndDrag(function(e
) {
395 return src
instanceof HTMLTextAreaElement
||
396 src
instanceof HTMLInputElement
&&
397 /text|password|search/.test(src
.type
);
400 // Register assets for async loading.
402 id
: SCREEN_OOBE_ENROLLMENT
,
403 html
: [{ url
: 'chrome://oobe/enrollment.html', targetID
: 'inner-container' }],
404 css
: ['chrome://oobe/enrollment.css'],
405 js
: ['chrome://oobe/enrollment.js']
406 }].forEach(cr
.ui
.login
.ResourceLoader
.registerAssets
);
411 document
.addEventListener('DOMContentLoaded', function() {
412 // Immediately load async assets.
413 // TODO(dconnelly): remove this at some point and only load as needed.
414 // See crbug.com/236426
415 cr
.ui
.login
.ResourceLoader
.loadAssets(SCREEN_OOBE_ENROLLMENT
, function() {
416 // This screen is async-loaded so we manually trigger i18n processing.
417 i18nTemplate
.process($('oauth-enrollment'), loadTimeData
);
418 // Delayed binding since this isn't defined yet.
419 login
.OAuthEnrollmentScreen
.register();
422 cr
.ui
.Oobe
.initialize();