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="../../login/screen.js"></include>
10 <include src="../user_images_grid.js"></include>
11 <include src="apps_menu.js"></include>
12 <include src="../../login/bubble.js"></include>
13 <include src="../../login/display_manager.js"></include>
14 <include src="header_bar.js"></include>
15 <include src="network_dropdown.js"></include>
16 <include src="oobe_screen_reset.js"></include>
17 <include src="oobe_screen_autolaunch.js"></include>
18 <include src="oobe_screen_enable_kiosk.js"></include>
19 <include src="oobe_screen_terms_of_service.js"></include>
20 <include src="oobe_screen_user_image.js"></include>
21 <include src="../../login/screen_account_picker.js"></include>
22 <include src="screen_app_launch_splash.js"></include>
23 <include src="screen_error_message.js"></include>
24 <include src="screen_gaia_signin.js"></include>
25 <include src="screen_locally_managed_user_creation.js"></include>
26 <include src="screen_password_changed.js"></include>
27 <include src="screen_tpm_error.js"></include>
28 <include src="screen_wrong_hwid.js"></include>
29 <include src="screen_confirm_password.js"></include>
30 <include src="screen_fatal_error.js"></include>
31 <include src="../../login/user_pod_row.js"></include>
32 <include src="../../login/resource_loader.js"></include>
34 cr.define('cr.ui', function() {
35 var DisplayManager = cr.ui.login.DisplayManager;
38 * Constructs an Out of box controller. It manages initialization of screens,
39 * transitions, error messages display.
40 * @extends {DisplayManager}
47 * Delay in milliseconds between start of OOBE animation and start of
48 * header bar animation.
50 var HEADER_BAR_DELAY_MS = 300;
52 cr.addSingletonGetter(Oobe);
55 __proto__: DisplayManager.prototype,
59 * Handle accelerators. These are passed from native code instead of a JS
60 * event handler in order to make sure that embedded iframes cannot swallow
62 * @param {string} name Accelerator name.
64 Oobe.handleAccelerator = function(name) {
65 Oobe.getInstance().handleAccelerator(name);
69 * Shows the given screen.
70 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
72 Oobe.showScreen = function(screen) {
73 Oobe.getInstance().showScreen(screen);
77 * Updates version label visibilty.
78 * @param {boolean} show True if version label should be visible.
80 Oobe.showVersion = function(show) {
81 Oobe.getInstance().showVersion(show);
85 * Update body class to switch between OOBE UI and Login UI.
87 Oobe.showOobeUI = function(showOobe) {
89 document.body.classList.add('oobe-display');
91 // Callback to animate the header bar in.
92 var showHeaderBar = function() {
93 login.HeaderBar.animateIn(function() {
94 chrome.send('headerBarVisible');
97 // Start asynchronously so the OOBE network screen comes in first.
98 window.setTimeout(showHeaderBar, HEADER_BAR_DELAY_MS);
100 document.body.classList.remove('oobe-display');
101 Oobe.getInstance().prepareForLoginDisplay_();
104 Oobe.getInstance().headerHidden = false;
108 * Enables keyboard driven flow.
110 Oobe.enableKeyboardFlow = function(value) {
111 // Don't show header bar for OOBE.
112 Oobe.getInstance().forceKeyboardFlow = value;
116 * Disables signin UI.
118 Oobe.disableSigninUI = function() {
119 DisplayManager.disableSigninUI();
124 * @param {string} opt_email An optional email for signin UI.
126 Oobe.showSigninUI = function(opt_email) {
127 DisplayManager.showSigninUI(opt_email);
131 * Resets sign-in input fields.
132 * @param {boolean} forceOnline Whether online sign-in should be forced.
133 * If |forceOnline| is false previously used sign-in type will be used.
135 Oobe.resetSigninUI = function(forceOnline) {
136 DisplayManager.resetSigninUI(forceOnline);
140 * Shows sign-in error bubble.
141 * @param {number} loginAttempts Number of login attemps tried.
142 * @param {string} message Error message to show.
143 * @param {string} link Text to use for help link.
144 * @param {number} helpId Help topic Id associated with help link.
146 Oobe.showSignInError = function(loginAttempts, message, link, helpId) {
147 DisplayManager.showSignInError(loginAttempts, message, link, helpId);
151 * Shows password changed screen that offers migration.
152 * @param {boolean} showError Whether to show the incorrect password error.
154 Oobe.showPasswordChangedScreen = function(showError) {
155 DisplayManager.showPasswordChangedScreen(showError);
159 * Shows dialog to create managed user.
161 Oobe.showManagedUserCreationScreen = function() {
162 DisplayManager.showManagedUserCreationScreen();
166 * Shows TPM error screen.
168 Oobe.showTpmError = function() {
169 DisplayManager.showTpmError();
173 * Clears error bubble as well as optional menus that could be open.
175 Oobe.clearErrors = function() {
176 var accessibilityMenu = $('accessibility-menu');
177 if (accessibilityMenu)
178 accessibilityMenu.hide();
179 DisplayManager.clearErrors();
183 * Displays animations on successful authentication, that have to happen
184 * before login UI is dismissed.
186 Oobe.animateAuthenticationSuccess = function() {
187 login.HeaderBar.animateOut(function() {
188 chrome.send('unlockOnLoginSuccess');
193 * Displays animations that have to happen once login UI is fully displayed.
195 Oobe.animateOnceFullyDisplayed = function() {
196 login.HeaderBar.animateIn();
200 * Handles login success notification.
202 Oobe.onLoginSuccess = function(username) {
203 if (Oobe.getInstance().currentScreen.id == SCREEN_ACCOUNT_PICKER) {
204 // TODO(nkostylev): Enable animation back when session start jank
205 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307
206 // $('pod-row').startAuthenticatedAnimation();
211 * Sets text content for a div with |labelId|.
212 * @param {string} labelId Id of the label div.
213 * @param {string} labelText Text for the label.
215 Oobe.setLabelText = function(labelId, labelText) {
216 DisplayManager.setLabelText(labelId, labelText);
220 * Sets the text content of the enterprise info message.
221 * If the text is empty, the entire notification will be hidden.
222 * @param {string} messageText The message text.
224 Oobe.setEnterpriseInfo = function(messageText) {
225 DisplayManager.setEnterpriseInfo(messageText);
229 * Updates the device requisition string shown in the requisition prompt.
230 * @param {string} requisition The device requisition.
232 Oobe.updateDeviceRequisition = function(requisition) {
233 Oobe.getInstance().updateDeviceRequisition(requisition);
237 * Enforces focus on user pod of locked user.
239 Oobe.forceLockedUserPodFocus = function() {
240 login.AccountPickerScreen.forceLockedUserPodFocus();
244 * Clears password field in user-pod.
246 Oobe.clearUserPodPassword = function() {
247 DisplayManager.clearUserPodPassword();
251 * Restores input focus to currently selected pod.
253 Oobe.refocusCurrentPod = function() {
254 DisplayManager.refocusCurrentPod();
258 * Skip to login screen for telemetry.
260 Oobe.skipToLoginForTesting = function() {
261 Oobe.disableSigninUI();
262 chrome.send('skipToLoginForTesting');
266 * Login for telemetry.
267 * @param {string} username Login username.
268 * @param {string} password Login password.
270 Oobe.loginForTesting = function(username, password) {
271 Oobe.disableSigninUI();
272 chrome.send('skipToLoginForTesting', [username]);
273 chrome.send('completeLogin', [username, password, false]);
277 * Guest login for telemetry.
279 Oobe.guestLoginForTesting = function() {
280 Oobe.skipToLoginForTesting();
281 chrome.send('launchIncognito');
285 * Authenticate for telemetry - used for screenlocker.
286 * @param {string} username Login username.
287 * @param {string} password Login password.
289 Oobe.authenticateForTesting = function(username, password) {
290 Oobe.disableSigninUI();
291 chrome.send('authenticateUser', [username, password]);
295 * Gaia login screen for telemetry.
297 Oobe.addUserForTesting = function() {
298 Oobe.skipToLoginForTesting();
299 chrome.send('addUser');
303 * Hotrod requisition for telemetry.
305 Oobe.remoraRequisitionForTesting = function() {
306 chrome.send('setDeviceRequisition', ['remora']);
310 * Finish enterprise enrollment for telemetry.
312 Oobe.enterpriseEnrollmentDone = function() {
313 chrome.send('oauthEnrollClose', ['done']);
317 * Shows/hides login UI control bar with buttons like [Shut down].
319 Oobe.showControlBar = function(show) {
320 Oobe.getInstance().headerHidden = !show;
329 var Oobe = cr.ui.Oobe;
331 // Allow selection events on components with editable text (password field)
332 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
333 disableTextSelectAndDrag(function(e) {
335 return src instanceof HTMLTextAreaElement ||
336 src instanceof HTMLInputElement &&
337 /text|password|search/.test(src.type);
340 // Register assets for async loading.
342 id: SCREEN_OOBE_ENROLLMENT,
343 html: [{ url: 'chrome://oobe/enrollment.html', targetID: 'inner-container' }],
344 css: ['chrome://oobe/enrollment.css'],
345 js: ['chrome://oobe/enrollment.js']
346 }].forEach(cr.ui.login.ResourceLoader.registerAssets);
348 document.addEventListener('DOMContentLoaded', function() {
351 // Immediately load async assets.
352 // TODO(dconnelly): remove this at some point and only load as needed.
353 // See crbug.com/236426
354 cr.ui.login.ResourceLoader.loadAssets(SCREEN_OOBE_ENROLLMENT, function() {
355 // This screen is async-loaded so we manually trigger i18n processing.
356 i18nTemplate.process($('oauth-enrollment'), loadTimeData);
357 // Delayed binding since this isn't defined yet.
358 login.OAuthEnrollmentScreen.register();
361 // Delayed binding since this isn't defined yet.
362 cr.ui.Oobe.initialize();