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="../../../../../ui/login/screen.js">
10 <include src="screen_context.js">
11 <include src="../user_images_grid.js">
12 <include src="apps_menu.js">
13 <include src="../../../../../ui/login/bubble.js">
14 <include src="../../../../../ui/login/display_manager.js">
15 <include src="header_bar.js">
16 <include src="network_dropdown.js">
17 <include src="oobe_screen_reset.js">
18 <include src="oobe_screen_autolaunch.js">
19 <include src="oobe_screen_enable_kiosk.js">
20 <include src="oobe_screen_terms_of_service.js">
21 <include src="oobe_screen_user_image.js">
22 <include src="../../../../../ui/login/account_picker/screen_account_picker.js">
23 <include src="screen_app_launch_splash.js">
24 <include src="screen_error_message.js">
25 <include src="screen_gaia_signin.js">
26 <include src="screen_password_changed.js">
27 <include src="screen_supervised_user_creation.js">
28 <include src="screen_tpm_error.js">
29 <include src="screen_wrong_hwid.js">
30 <include src="screen_confirm_password.js">
31 <include src="screen_fatal_error.js">
32 <include src="../../../../../ui/login/login_ui_tools.js">
33 <include src="../../../../../ui/login/account_picker/user_pod_row.js">
34 <include src="../../../../../ui/login/resource_loader.js">
36 cr.define('cr.ui', function() {
37 var DisplayManager = cr.ui.login.DisplayManager;
40 * Constructs an Out of box controller. It manages initialization of screens,
41 * transitions, error messages display.
42 * @extends {DisplayManager}
49 * Delay in milliseconds between start of OOBE animation and start of
50 * header bar animation.
52 var HEADER_BAR_DELAY_MS = 300;
54 cr.addSingletonGetter(Oobe);
57 __proto__: DisplayManager.prototype,
61 * Handle accelerators. These are passed from native code instead of a JS
62 * event handler in order to make sure that embedded iframes cannot swallow
64 * @param {string} name Accelerator name.
66 Oobe.handleAccelerator = function(name) {
67 Oobe.getInstance().handleAccelerator(name);
71 * Shows the given screen.
72 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
74 Oobe.showScreen = function(screen) {
75 Oobe.getInstance().showScreen(screen);
79 * Updates version label visibilty.
80 * @param {boolean} show True if version label should be visible.
82 Oobe.showVersion = function(show) {
83 Oobe.getInstance().showVersion(show);
87 * Update body class to switch between OOBE UI and Login UI.
89 Oobe.showOobeUI = function(showOobe) {
91 document.body.classList.add('oobe-display');
93 // Callback to animate the header bar in.
94 var showHeaderBar = function() {
95 login.HeaderBar.animateIn(function() {
96 chrome.send('headerBarVisible');
99 // Start asynchronously so the OOBE network screen comes in first.
100 window.setTimeout(showHeaderBar, HEADER_BAR_DELAY_MS);
102 document.body.classList.remove('oobe-display');
103 Oobe.getInstance().prepareForLoginDisplay_();
106 Oobe.getInstance().headerHidden = false;
110 * Enables keyboard driven flow.
112 Oobe.enableKeyboardFlow = function(value) {
113 // Don't show header bar for OOBE.
114 Oobe.getInstance().forceKeyboardFlow = value;
118 * Disables signin UI.
120 Oobe.disableSigninUI = function() {
121 DisplayManager.disableSigninUI();
126 * @param {string} opt_email An optional email for signin UI.
128 Oobe.showSigninUI = function(opt_email) {
129 DisplayManager.showSigninUI(opt_email);
133 * Resets sign-in input fields.
134 * @param {boolean} forceOnline Whether online sign-in should be forced.
135 * If |forceOnline| is false previously used sign-in type will be used.
137 Oobe.resetSigninUI = function(forceOnline) {
138 DisplayManager.resetSigninUI(forceOnline);
142 * Shows sign-in error bubble.
143 * @param {number} loginAttempts Number of login attemps tried.
144 * @param {string} message Error message to show.
145 * @param {string} link Text to use for help link.
146 * @param {number} helpId Help topic Id associated with help link.
148 Oobe.showSignInError = function(loginAttempts, message, link, helpId) {
149 DisplayManager.showSignInError(loginAttempts, message, link, helpId);
153 * Shows password changed screen that offers migration.
154 * @param {boolean} showError Whether to show the incorrect password error.
156 Oobe.showPasswordChangedScreen = function(showError) {
157 DisplayManager.showPasswordChangedScreen(showError);
161 * Shows dialog to create a supervised user.
163 Oobe.showSupervisedUserCreationScreen = function() {
164 DisplayManager.showSupervisedUserCreationScreen();
168 * Shows TPM error screen.
170 Oobe.showTpmError = function() {
171 DisplayManager.showTpmError();
175 * Clears error bubble as well as optional menus that could be open.
177 Oobe.clearErrors = function() {
178 var accessibilityMenu = $('accessibility-menu');
179 if (accessibilityMenu)
180 accessibilityMenu.hide();
181 DisplayManager.clearErrors();
185 * Displays animations on successful authentication, that have to happen
186 * before login UI is dismissed.
188 Oobe.animateAuthenticationSuccess = function() {
189 login.HeaderBar.animateOut(function() {
190 chrome.send('unlockOnLoginSuccess');
195 * Displays animations that have to happen once login UI is fully displayed.
197 Oobe.animateOnceFullyDisplayed = function() {
198 login.HeaderBar.animateIn();
202 * Sets text content for a div with |labelId|.
203 * @param {string} labelId Id of the label div.
204 * @param {string} labelText Text for the label.
206 Oobe.setLabelText = function(labelId, labelText) {
207 DisplayManager.setLabelText(labelId, labelText);
211 * Sets the text content of the enterprise info message.
212 * If the text is empty, the entire notification will be hidden.
213 * @param {string} messageText The message text.
215 Oobe.setEnterpriseInfo = function(messageText) {
216 DisplayManager.setEnterpriseInfo(messageText);
220 * Updates the device requisition string shown in the requisition prompt.
221 * @param {string} requisition The device requisition.
223 Oobe.updateDeviceRequisition = function(requisition) {
224 Oobe.getInstance().updateDeviceRequisition(requisition);
228 * Enforces focus on user pod of locked user.
230 Oobe.forceLockedUserPodFocus = function() {
231 login.AccountPickerScreen.forceLockedUserPodFocus();
235 * Clears password field in user-pod.
237 Oobe.clearUserPodPassword = function() {
238 DisplayManager.clearUserPodPassword();
242 * Restores input focus to currently selected pod.
244 Oobe.refocusCurrentPod = function() {
245 DisplayManager.refocusCurrentPod();
249 * Skip to login screen for telemetry.
251 Oobe.skipToLoginForTesting = function() {
252 Oobe.disableSigninUI();
253 chrome.send('skipToLoginForTesting');
257 * Login for telemetry.
258 * @param {string} username Login username.
259 * @param {string} password Login password.
261 Oobe.loginForTesting = function(username, password) {
262 Oobe.disableSigninUI();
263 chrome.send('skipToLoginForTesting', [username]);
264 chrome.send('completeLogin', [username, password, false]);
268 * Guest login for telemetry.
270 Oobe.guestLoginForTesting = function() {
271 Oobe.skipToLoginForTesting();
272 chrome.send('launchIncognito');
276 * Authenticate for telemetry - used for screenlocker.
277 * @param {string} username Login username.
278 * @param {string} password Login password.
280 Oobe.authenticateForTesting = function(username, password) {
281 Oobe.disableSigninUI();
282 chrome.send('authenticateUser', [username, password]);
286 * Gaia login screen for telemetry.
288 Oobe.addUserForTesting = function() {
289 Oobe.skipToLoginForTesting();
290 chrome.send('addUser');
294 * Hotrod requisition for telemetry.
296 Oobe.remoraRequisitionForTesting = function() {
297 chrome.send('setDeviceRequisition', ['remora']);
301 * Finish enterprise enrollment for telemetry.
303 Oobe.enterpriseEnrollmentDone = function() {
304 chrome.send('oauthEnrollClose', ['done']);
308 * Shows/hides login UI control bar with buttons like [Shut down].
310 Oobe.showControlBar = function(show) {
311 Oobe.getInstance().headerHidden = !show;
315 * Sets the current state of the virtual keyboard (shown/hidden, size).
317 Oobe.setKeyboardState = function(shown, width, height) {
318 Oobe.getInstance().virtualKeyboardShown = shown;
319 Oobe.getInstance().setVirtualKeyboardSize(width, height);
323 * Sets the current size of the client area (display size).
324 * @param {number} width client area width
325 * @param {number} height client area height
327 Oobe.setClientAreaSize = function(width, height) {
328 Oobe.getInstance().setClientAreaSize(width, height);
337 var Oobe = cr.ui.Oobe;
339 // Allow selection events on components with editable text (password field)
340 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
341 disableTextSelectAndDrag(function(e) {
343 return src instanceof HTMLTextAreaElement ||
344 src instanceof HTMLInputElement &&
345 /text|password|search/.test(src.type);
348 // Register assets for async loading.
350 id: SCREEN_OOBE_ENROLLMENT,
351 html: [{ url: 'chrome://oobe/enrollment.html', targetID: 'inner-container' }],
352 css: ['chrome://oobe/enrollment.css'],
353 js: ['chrome://oobe/enrollment.js']
354 }].forEach(cr.ui.login.ResourceLoader.registerAssets);
356 document.addEventListener('DOMContentLoaded', function() {
359 // Immediately load async assets.
360 // TODO(dconnelly): remove this at some point and only load as needed.
361 // See crbug.com/236426
362 cr.ui.login.ResourceLoader.loadAssets(SCREEN_OOBE_ENROLLMENT, function() {
363 // This screen is async-loaded so we manually trigger i18n processing.
364 i18nTemplate.process($('oauth-enrollment'), loadTimeData);
365 // Delayed binding since this isn't defined yet.
366 login.OAuthEnrollmentScreen.register();
369 // Delayed binding since this isn't defined yet.
370 cr.ui.Oobe.initialize();