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="screen_context.js"></include>
11 <include src="../user_images_grid.js"></include>
12 <include src="apps_menu.js"></include>
13 <include src="../../login/bubble.js"></include>
14 <include src="../../login/display_manager.js"></include>
15 <include src="header_bar.js"></include>
16 <include src="network_dropdown.js"></include>
17 <include src="oobe_screen_reset.js"></include>
18 <include src="oobe_screen_autolaunch.js"></include>
19 <include src="oobe_screen_enable_kiosk.js"></include>
20 <include src="oobe_screen_terms_of_service.js"></include>
21 <include src="oobe_screen_user_image.js"></include>
22 <include src="../../login/screen_account_picker.js"></include>
23 <include src="screen_app_launch_splash.js"></include>
24 <include src="screen_error_message.js"></include>
25 <include src="screen_gaia_signin.js"></include>
26 <include src="screen_locally_managed_user_creation.js"></include>
27 <include src="screen_password_changed.js"></include>
28 <include src="screen_tpm_error.js"></include>
29 <include src="screen_wrong_hwid.js"></include>
30 <include src="screen_confirm_password.js"></include>
31 <include src="screen_fatal_error.js"></include>
32 <include src="../../login/user_pod_row.js"></include>
33 <include src="../../login/resource_loader.js"></include>
35 cr.define('cr.ui', function() {
36 var DisplayManager = cr.ui.login.DisplayManager;
39 * Constructs an Out of box controller. It manages initialization of screens,
40 * transitions, error messages display.
41 * @extends {DisplayManager}
48 * Delay in milliseconds between start of OOBE animation and start of
49 * header bar animation.
51 var HEADER_BAR_DELAY_MS = 300;
53 cr.addSingletonGetter(Oobe);
56 __proto__: DisplayManager.prototype,
60 * Handle accelerators. These are passed from native code instead of a JS
61 * event handler in order to make sure that embedded iframes cannot swallow
63 * @param {string} name Accelerator name.
65 Oobe.handleAccelerator = function(name) {
66 Oobe.getInstance().handleAccelerator(name);
70 * Shows the given screen.
71 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
73 Oobe.showScreen = function(screen) {
74 Oobe.getInstance().showScreen(screen);
78 * Updates version label visibilty.
79 * @param {boolean} show True if version label should be visible.
81 Oobe.showVersion = function(show) {
82 Oobe.getInstance().showVersion(show);
86 * Update body class to switch between OOBE UI and Login UI.
88 Oobe.showOobeUI = function(showOobe) {
90 document.body.classList.add('oobe-display');
92 // Callback to animate the header bar in.
93 var showHeaderBar = function() {
94 login.HeaderBar.animateIn(function() {
95 chrome.send('headerBarVisible');
98 // Start asynchronously so the OOBE network screen comes in first.
99 window.setTimeout(showHeaderBar, HEADER_BAR_DELAY_MS);
101 document.body.classList.remove('oobe-display');
102 Oobe.getInstance().prepareForLoginDisplay_();
105 Oobe.getInstance().headerHidden = false;
109 * Enables keyboard driven flow.
111 Oobe.enableKeyboardFlow = function(value) {
112 // Don't show header bar for OOBE.
113 Oobe.getInstance().forceKeyboardFlow = value;
117 * Disables signin UI.
119 Oobe.disableSigninUI = function() {
120 DisplayManager.disableSigninUI();
125 * @param {string} opt_email An optional email for signin UI.
127 Oobe.showSigninUI = function(opt_email) {
128 DisplayManager.showSigninUI(opt_email);
132 * Resets sign-in input fields.
133 * @param {boolean} forceOnline Whether online sign-in should be forced.
134 * If |forceOnline| is false previously used sign-in type will be used.
136 Oobe.resetSigninUI = function(forceOnline) {
137 DisplayManager.resetSigninUI(forceOnline);
141 * Shows sign-in error bubble.
142 * @param {number} loginAttempts Number of login attemps tried.
143 * @param {string} message Error message to show.
144 * @param {string} link Text to use for help link.
145 * @param {number} helpId Help topic Id associated with help link.
147 Oobe.showSignInError = function(loginAttempts, message, link, helpId) {
148 DisplayManager.showSignInError(loginAttempts, message, link, helpId);
152 * Shows password changed screen that offers migration.
153 * @param {boolean} showError Whether to show the incorrect password error.
155 Oobe.showPasswordChangedScreen = function(showError) {
156 DisplayManager.showPasswordChangedScreen(showError);
160 * Shows dialog to create managed user.
162 Oobe.showManagedUserCreationScreen = function() {
163 DisplayManager.showManagedUserCreationScreen();
167 * Shows TPM error screen.
169 Oobe.showTpmError = function() {
170 DisplayManager.showTpmError();
174 * Clears error bubble as well as optional menus that could be open.
176 Oobe.clearErrors = function() {
177 var accessibilityMenu = $('accessibility-menu');
178 if (accessibilityMenu)
179 accessibilityMenu.hide();
180 DisplayManager.clearErrors();
184 * Displays animations on successful authentication, that have to happen
185 * before login UI is dismissed.
187 Oobe.animateAuthenticationSuccess = function() {
188 login.HeaderBar.animateOut(function() {
189 chrome.send('unlockOnLoginSuccess');
194 * Displays animations that have to happen once login UI is fully displayed.
196 Oobe.animateOnceFullyDisplayed = function() {
197 login.HeaderBar.animateIn();
201 * Sets text content for a div with |labelId|.
202 * @param {string} labelId Id of the label div.
203 * @param {string} labelText Text for the label.
205 Oobe.setLabelText = function(labelId, labelText) {
206 DisplayManager.setLabelText(labelId, labelText);
210 * Sets the text content of the enterprise info message.
211 * If the text is empty, the entire notification will be hidden.
212 * @param {string} messageText The message text.
214 Oobe.setEnterpriseInfo = function(messageText) {
215 DisplayManager.setEnterpriseInfo(messageText);
219 * Updates the device requisition string shown in the requisition prompt.
220 * @param {string} requisition The device requisition.
222 Oobe.updateDeviceRequisition = function(requisition) {
223 Oobe.getInstance().updateDeviceRequisition(requisition);
227 * Enforces focus on user pod of locked user.
229 Oobe.forceLockedUserPodFocus = function() {
230 login.AccountPickerScreen.forceLockedUserPodFocus();
234 * Clears password field in user-pod.
236 Oobe.clearUserPodPassword = function() {
237 DisplayManager.clearUserPodPassword();
241 * Restores input focus to currently selected pod.
243 Oobe.refocusCurrentPod = function() {
244 DisplayManager.refocusCurrentPod();
248 * Skip to login screen for telemetry.
250 Oobe.skipToLoginForTesting = function() {
251 Oobe.disableSigninUI();
252 chrome.send('skipToLoginForTesting');
256 * Login for telemetry.
257 * @param {string} username Login username.
258 * @param {string} password Login password.
260 Oobe.loginForTesting = function(username, password) {
261 Oobe.disableSigninUI();
262 chrome.send('skipToLoginForTesting', [username]);
263 chrome.send('completeLogin', [username, password, false]);
267 * Guest login for telemetry.
269 Oobe.guestLoginForTesting = function() {
270 Oobe.skipToLoginForTesting();
271 chrome.send('launchIncognito');
275 * Authenticate for telemetry - used for screenlocker.
276 * @param {string} username Login username.
277 * @param {string} password Login password.
279 Oobe.authenticateForTesting = function(username, password) {
280 Oobe.disableSigninUI();
281 chrome.send('authenticateUser', [username, password]);
285 * Gaia login screen for telemetry.
287 Oobe.addUserForTesting = function() {
288 Oobe.skipToLoginForTesting();
289 chrome.send('addUser');
293 * Hotrod requisition for telemetry.
295 Oobe.remoraRequisitionForTesting = function() {
296 chrome.send('setDeviceRequisition', ['remora']);
300 * Finish enterprise enrollment for telemetry.
302 Oobe.enterpriseEnrollmentDone = function() {
303 chrome.send('oauthEnrollClose', ['done']);
307 * Shows/hides login UI control bar with buttons like [Shut down].
309 Oobe.showControlBar = function(show) {
310 Oobe.getInstance().headerHidden = !show;
314 * Sets the current state of the virtual keyboard (shown/hidden, size).
316 Oobe.setKeyboardState = function(shown, width, height) {
317 Oobe.getInstance().virtualKeyboardShown = shown;
318 Oobe.getInstance().setVirtualKeyboardSize(width, height);
322 * Sets the current size of the client area (display size).
323 * @param {number} width client area width
324 * @param {number} height client area height
326 Oobe.setClientAreaSize = function(width, height) {
327 Oobe.getInstance().setClientAreaSize(width, height);
336 var Oobe = cr.ui.Oobe;
338 // Allow selection events on components with editable text (password field)
339 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
340 disableTextSelectAndDrag(function(e) {
342 return src instanceof HTMLTextAreaElement ||
343 src instanceof HTMLInputElement &&
344 /text|password|search/.test(src.type);
347 // Register assets for async loading.
349 id: SCREEN_OOBE_ENROLLMENT,
350 html: [{ url: 'chrome://oobe/enrollment.html', targetID: 'inner-container' }],
351 css: ['chrome://oobe/enrollment.css'],
352 js: ['chrome://oobe/enrollment.js']
353 }].forEach(cr.ui.login.ResourceLoader.registerAssets);
355 document.addEventListener('DOMContentLoaded', function() {
358 // Immediately load async assets.
359 // TODO(dconnelly): remove this at some point and only load as needed.
360 // See crbug.com/236426
361 cr.ui.login.ResourceLoader.loadAssets(SCREEN_OOBE_ENROLLMENT, function() {
362 // This screen is async-loaded so we manually trigger i18n processing.
363 i18nTemplate.process($('oauth-enrollment'), loadTimeData);
364 // Delayed binding since this isn't defined yet.
365 login.OAuthEnrollmentScreen.register();
368 // Delayed binding since this isn't defined yet.
369 cr.ui.Oobe.initialize();