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_confirmation_overlay.js">
18 <include src="oobe_screen_reset.js">
19 <include src="oobe_screen_autolaunch.js">
20 <include src="oobe_screen_enable_kiosk.js">
21 <include src="oobe_screen_terms_of_service.js">
22 <include src="oobe_screen_user_image.js">
23 <include src="../../../../../ui/login/account_picker/screen_account_picker.js">
24 <include src="screen_app_launch_splash.js">
25 <include src="screen_error_message.js">
26 <include src="screen_gaia_signin.js">
27 <include src="screen_password_changed.js">
28 <include src="screen_supervised_user_creation.js">
29 <include src="screen_tpm_error.js">
30 <include src="screen_wrong_hwid.js">
31 <include src="screen_confirm_password.js">
32 <include src="screen_fatal_error.js">
33 <include src="screen_device_disabled.js">
34 <include src="../../../../../ui/login/login_ui_tools.js">
35 <include src="../../../../../ui/login/account_picker/user_pod_row.js">
36 <include src="../../../../../ui/login/resource_loader.js">
38 cr.define('cr.ui', function() {
39 var DisplayManager = cr.ui.login.DisplayManager;
42 * Constructs an Out of box controller. It manages initialization of screens,
43 * transitions, error messages display.
44 * @extends {DisplayManager}
51 * Delay in milliseconds between start of OOBE animation and start of
52 * header bar animation.
54 var HEADER_BAR_DELAY_MS = 300;
56 cr.addSingletonGetter(Oobe);
59 __proto__: DisplayManager.prototype,
63 * Handle accelerators. These are passed from native code instead of a JS
64 * event handler in order to make sure that embedded iframes cannot swallow
66 * @param {string} name Accelerator name.
68 Oobe.handleAccelerator = function(name) {
69 Oobe.getInstance().handleAccelerator(name);
73 * Shows the given screen.
74 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
76 Oobe.showScreen = function(screen) {
77 Oobe.getInstance().showScreen(screen);
81 * Updates version label visibilty.
82 * @param {boolean} show True if version label should be visible.
84 Oobe.showVersion = function(show) {
85 Oobe.getInstance().showVersion(show);
89 * Update body class to switch between OOBE UI and Login UI.
91 Oobe.showOobeUI = function(showOobe) {
93 document.body.classList.add('oobe-display');
95 // Callback to animate the header bar in.
96 var showHeaderBar = function() {
97 login.HeaderBar.animateIn(function() {
98 chrome.send('headerBarVisible');
101 // Start asynchronously so the OOBE network screen comes in first.
102 window.setTimeout(showHeaderBar, HEADER_BAR_DELAY_MS);
104 document.body.classList.remove('oobe-display');
105 Oobe.getInstance().prepareForLoginDisplay_();
108 Oobe.getInstance().headerHidden = false;
112 * Enables keyboard driven flow.
114 Oobe.enableKeyboardFlow = function(value) {
115 // Don't show header bar for OOBE.
116 Oobe.getInstance().forceKeyboardFlow = value;
120 * Disables signin UI.
122 Oobe.disableSigninUI = function() {
123 DisplayManager.disableSigninUI();
128 * @param {string} opt_email An optional email for signin UI.
130 Oobe.showSigninUI = function(opt_email) {
131 DisplayManager.showSigninUI(opt_email);
135 * Resets sign-in input fields.
136 * @param {boolean} forceOnline Whether online sign-in should be forced.
137 * If |forceOnline| is false previously used sign-in type will be used.
139 Oobe.resetSigninUI = function(forceOnline) {
140 DisplayManager.resetSigninUI(forceOnline);
144 * Shows sign-in error bubble.
145 * @param {number} loginAttempts Number of login attemps tried.
146 * @param {string} message Error message to show.
147 * @param {string} link Text to use for help link.
148 * @param {number} helpId Help topic Id associated with help link.
150 Oobe.showSignInError = function(loginAttempts, message, link, helpId) {
151 DisplayManager.showSignInError(loginAttempts, message, link, helpId);
155 * Shows password changed screen that offers migration.
156 * @param {boolean} showError Whether to show the incorrect password error.
158 Oobe.showPasswordChangedScreen = function(showError) {
159 DisplayManager.showPasswordChangedScreen(showError);
163 * Shows dialog to create a supervised user.
165 Oobe.showSupervisedUserCreationScreen = function() {
166 DisplayManager.showSupervisedUserCreationScreen();
170 * Shows TPM error screen.
172 Oobe.showTpmError = function() {
173 DisplayManager.showTpmError();
177 * Clears error bubble as well as optional menus that could be open.
179 Oobe.clearErrors = function() {
180 var accessibilityMenu = $('accessibility-menu');
181 if (accessibilityMenu)
182 accessibilityMenu.hide();
183 DisplayManager.clearErrors();
187 * Displays animations on successful authentication, that have to happen
188 * before login UI is dismissed.
190 Oobe.animateAuthenticationSuccess = function() {
191 login.HeaderBar.animateOut(function() {
192 chrome.send('unlockOnLoginSuccess');
197 * Displays animations that have to happen once login UI is fully displayed.
199 Oobe.animateOnceFullyDisplayed = function() {
200 login.HeaderBar.animateIn();
204 * Sets text content for a div with |labelId|.
205 * @param {string} labelId Id of the label div.
206 * @param {string} labelText Text for the label.
208 Oobe.setLabelText = function(labelId, labelText) {
209 DisplayManager.setLabelText(labelId, labelText);
213 * Sets the text content of the enterprise info message.
214 * If the text is empty, the entire notification will be hidden.
215 * @param {string} messageText The message text.
217 Oobe.setEnterpriseInfo = function(messageText) {
218 DisplayManager.setEnterpriseInfo(messageText);
222 * Updates the device requisition string shown in the requisition prompt.
223 * @param {string} requisition The device requisition.
225 Oobe.updateDeviceRequisition = function(requisition) {
226 Oobe.getInstance().updateDeviceRequisition(requisition);
230 * Enforces focus on user pod of locked user.
232 Oobe.forceLockedUserPodFocus = function() {
233 login.AccountPickerScreen.forceLockedUserPodFocus();
237 * Clears password field in user-pod.
239 Oobe.clearUserPodPassword = function() {
240 DisplayManager.clearUserPodPassword();
244 * Restores input focus to currently selected pod.
246 Oobe.refocusCurrentPod = function() {
247 DisplayManager.refocusCurrentPod();
251 * Skip to login screen for telemetry.
253 Oobe.skipToLoginForTesting = function() {
254 Oobe.disableSigninUI();
255 chrome.send('skipToLoginForTesting');
259 * Login for telemetry.
260 * @param {string} username Login username.
261 * @param {string} password Login password.
263 Oobe.loginForTesting = function(username, password) {
264 Oobe.disableSigninUI();
265 chrome.send('skipToLoginForTesting', [username]);
266 chrome.send('completeLogin', [username, password, false]);
270 * Guest login for telemetry.
272 Oobe.guestLoginForTesting = function() {
273 Oobe.skipToLoginForTesting();
274 chrome.send('launchIncognito');
278 * Authenticate for telemetry - used for screenlocker.
279 * @param {string} username Login username.
280 * @param {string} password Login password.
282 Oobe.authenticateForTesting = function(username, password) {
283 Oobe.disableSigninUI();
284 chrome.send('authenticateUser', [username, password]);
288 * Gaia login screen for telemetry.
290 Oobe.addUserForTesting = function() {
291 Oobe.skipToLoginForTesting();
292 chrome.send('addUser');
296 * Hotrod requisition for telemetry.
298 Oobe.remoraRequisitionForTesting = function() {
299 chrome.send('setDeviceRequisition', ['remora']);
303 * Finish enterprise enrollment for telemetry.
305 Oobe.enterpriseEnrollmentDone = function() {
306 chrome.send('oauthEnrollClose', ['done']);
310 * Shows/hides login UI control bar with buttons like [Shut down].
312 Oobe.showControlBar = function(show) {
313 Oobe.getInstance().headerHidden = !show;
317 * Sets the current state of the virtual keyboard (shown/hidden, size).
319 Oobe.setKeyboardState = function(shown, width, height) {
320 Oobe.getInstance().virtualKeyboardShown = shown;
321 Oobe.getInstance().setVirtualKeyboardSize(width, height);
325 * Sets the current size of the client area (display size).
326 * @param {number} width client area width
327 * @param {number} height client area height
329 Oobe.setClientAreaSize = function(width, height) {
330 Oobe.getInstance().setClientAreaSize(width, height);
339 var Oobe = cr.ui.Oobe;
341 // Allow selection events on components with editable text (password field)
342 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
343 disableTextSelectAndDrag(function(e) {
345 return src instanceof HTMLTextAreaElement ||
346 src instanceof HTMLInputElement &&
347 /text|password|search/.test(src.type);
350 // Register assets for async loading.
352 id: SCREEN_OOBE_ENROLLMENT,
353 html: [{ url: 'chrome://oobe/enrollment.html', targetID: 'inner-container' }],
354 css: ['chrome://oobe/enrollment.css'],
355 js: ['chrome://oobe/enrollment.js']
356 }].forEach(cr.ui.login.ResourceLoader.registerAssets);
361 function initializeOobe() {
362 // Immediately load async assets.
363 // TODO(dconnelly): remove this at some point and only load as needed.
364 // See crbug.com/236426
365 cr.ui.login.ResourceLoader.loadAssets(SCREEN_OOBE_ENROLLMENT, function() {
366 // This screen is async-loaded so we manually trigger i18n processing.
367 i18nTemplate.process($('oauth-enrollment'), loadTimeData);
368 // Delayed binding since this isn't defined yet.
369 login.OAuthEnrollmentScreen.register();
372 cr.ui.Oobe.initialize();
375 document.addEventListener('DOMContentLoaded', function() {
376 if (!window['WAIT_FOR_POLYMER']) {
380 window.addEventListener('polymer-ready', function() {