login_common.js revision f2477e01787aa58f445919b809d89e252beef54f
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.
4
5/**
6 * @fileoverview Common OOBE controller methods.
7 */
8
9<include src="screen.js"></include>
10<include src="../user_images_grid.js"></include>
11<include src="apps_menu.js"></include>
12<include src="bubble.js"></include>
13<include src="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="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_message_box.js"></include>
31<include src="user_pod_row.js"></include>
32<include src="resource_loader.js"></include>
33
34cr.define('cr.ui', function() {
35  var DisplayManager = cr.ui.login.DisplayManager;
36
37  /**
38  * Constructs an Out of box controller. It manages initialization of screens,
39  * transitions, error messages display.
40  * @extends {DisplayManager}
41  * @constructor
42  */
43  function Oobe() {
44  }
45
46  cr.addSingletonGetter(Oobe);
47
48  Oobe.prototype = {
49    __proto__: DisplayManager.prototype,
50  };
51
52  /**
53   * Handle accelerators. These are passed from native code instead of a JS
54   * event handler in order to make sure that embedded iframes cannot swallow
55   * them.
56   * @param {string} name Accelerator name.
57   */
58  Oobe.handleAccelerator = function(name) {
59    Oobe.getInstance().handleAccelerator(name);
60  };
61
62  /**
63   * Shows the given screen.
64   * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
65   */
66  Oobe.showScreen = function(screen) {
67    Oobe.getInstance().showScreen(screen);
68  };
69
70  /**
71   * Updates version label visibilty.
72   * @param {boolean} show True if version label should be visible.
73   */
74  Oobe.showVersion = function(show) {
75    Oobe.getInstance().showVersion(show);
76  };
77
78  /**
79   * Update body class to switch between OOBE UI and Login UI.
80   */
81  Oobe.showOobeUI = function(showOobe) {
82    if (showOobe) {
83      document.body.classList.add('oobe-display');
84    } else {
85      document.body.classList.remove('oobe-display');
86      Oobe.getInstance().prepareForLoginDisplay_();
87    }
88
89    // Don't show header bar for OOBE.
90    Oobe.getInstance().headerHidden = showOobe;
91  };
92
93  /**
94   * Enables keyboard driven flow.
95   */
96  Oobe.enableKeyboardFlow = function(value) {
97    // Don't show header bar for OOBE.
98    Oobe.getInstance().forceKeyboardFlow = value;
99  };
100
101  /**
102   * Disables signin UI.
103   */
104  Oobe.disableSigninUI = function() {
105    DisplayManager.disableSigninUI();
106  };
107
108  /**
109   * Shows signin UI.
110   * @param {string} opt_email An optional email for signin UI.
111   */
112  Oobe.showSigninUI = function(opt_email) {
113    DisplayManager.showSigninUI(opt_email);
114  };
115
116  /**
117   * Resets sign-in input fields.
118   * @param {boolean} forceOnline Whether online sign-in should be forced.
119   * If |forceOnline| is false previously used sign-in type will be used.
120   */
121  Oobe.resetSigninUI = function(forceOnline) {
122    DisplayManager.resetSigninUI(forceOnline);
123  };
124
125  /**
126   * Shows sign-in error bubble.
127   * @param {number} loginAttempts Number of login attemps tried.
128   * @param {string} message Error message to show.
129   * @param {string} link Text to use for help link.
130   * @param {number} helpId Help topic Id associated with help link.
131   */
132  Oobe.showSignInError = function(loginAttempts, message, link, helpId) {
133    DisplayManager.showSignInError(loginAttempts, message, link, helpId);
134  };
135
136  /**
137   * Shows password changed screen that offers migration.
138   * @param {boolean} showError Whether to show the incorrect password error.
139   */
140  Oobe.showPasswordChangedScreen = function(showError) {
141    DisplayManager.showPasswordChangedScreen(showError);
142  };
143
144  /**
145   * Shows dialog to create managed user.
146   */
147  Oobe.showManagedUserCreationScreen = function() {
148    DisplayManager.showManagedUserCreationScreen();
149  };
150
151  /**
152   * Shows TPM error screen.
153   */
154  Oobe.showTpmError = function() {
155    DisplayManager.showTpmError();
156  };
157
158  /**
159   * Clears error bubble as well as optional menus that could be open.
160   */
161  Oobe.clearErrors = function() {
162    var accessibilityMenu = $('accessibility-menu');
163    if (accessibilityMenu)
164      accessibilityMenu.hide();
165    DisplayManager.clearErrors();
166  };
167
168  /**
169   * Displays animations on successful authentication, that have to happen
170   * before login UI is dismissed.
171   */
172  Oobe.animateAuthenticationSuccess = function() {
173    login.HeaderBar.animateOut(function() {
174      chrome.send('unlockOnLoginSuccess');
175    });
176  };
177
178  /**
179   * Displays animations that have to happen once login UI is fully displayed.
180   */
181  Oobe.animateOnceFullyDisplayed = function() {
182    login.HeaderBar.animateIn();
183  };
184
185  /**
186   * Handles login success notification.
187   */
188  Oobe.onLoginSuccess = function(username) {
189    if (Oobe.getInstance().currentScreen.id == SCREEN_ACCOUNT_PICKER) {
190      // TODO(nkostylev): Enable animation back when session start jank
191      // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307
192      // $('pod-row').startAuthenticatedAnimation();
193    }
194  };
195
196  /**
197   * Sets text content for a div with |labelId|.
198   * @param {string} labelId Id of the label div.
199   * @param {string} labelText Text for the label.
200   */
201  Oobe.setLabelText = function(labelId, labelText) {
202    DisplayManager.setLabelText(labelId, labelText);
203  };
204
205  /**
206   * Sets the text content of the enterprise info message.
207   * If the text is empty, the entire notification will be hidden.
208   * @param {string} messageText The message text.
209   */
210  Oobe.setEnterpriseInfo = function(messageText) {
211    DisplayManager.setEnterpriseInfo(messageText);
212  };
213
214  /**
215   * Updates the device requisition string shown in the requisition prompt.
216   * @param {string} requisition The device requisition.
217   */
218  Oobe.updateDeviceRequisition = function(requisition) {
219    Oobe.getInstance().updateDeviceRequisition(requisition);
220  };
221
222  /**
223   * Enforces focus on user pod of locked user.
224   */
225  Oobe.forceLockedUserPodFocus = function() {
226    login.AccountPickerScreen.forceLockedUserPodFocus();
227  };
228
229  /**
230   * Clears password field in user-pod.
231   */
232  Oobe.clearUserPodPassword = function() {
233    DisplayManager.clearUserPodPassword();
234  };
235
236  /**
237   * Restores input focus to currently selected pod.
238   */
239  Oobe.refocusCurrentPod = function() {
240    DisplayManager.refocusCurrentPod();
241  };
242
243  /**
244   * Login for autotests.
245   * @param {string} username Login username.
246   * @param {string} password Login password.
247   */
248  Oobe.loginForTesting = function(username, password) {
249    chrome.send('skipToLoginForTesting', [username]);
250    chrome.send('completeLogin', [username, password]);
251  };
252
253  /**
254   * Authenticate for autotests.
255   * @param {string} username Login username.
256   * @param {string} password Login password.
257   */
258  Oobe.authenticateForTesting = function(username, password) {
259    chrome.send('authenticateUser', [username, password]);
260  };
261
262  // Export
263  return {
264    Oobe: Oobe
265  };
266});
267
268var Oobe = cr.ui.Oobe;
269
270// Allow selection events on components with editable text (password field)
271// bug (http://code.google.com/p/chromium/issues/detail?id=125863)
272disableTextSelectAndDrag(function(e) {
273  var src = e.target;
274  return src instanceof HTMLTextAreaElement ||
275         src instanceof HTMLInputElement &&
276         /text|password|search/.test(src.type);
277});
278
279// Register assets for async loading.
280[{
281  id: SCREEN_OOBE_ENROLLMENT,
282  html: [{ url: 'chrome://oobe/enrollment.html', targetID: 'inner-container' }],
283  css: ['chrome://oobe/enrollment.css'],
284  js: ['chrome://oobe/enrollment.js']
285}].forEach(cr.ui.login.ResourceLoader.registerAssets);
286
287document.addEventListener('DOMContentLoaded', function() {
288  'use strict';
289
290  // Immediately load async assets.
291  // TODO(dconnelly): remove this at some point and only load as needed.
292  // See crbug.com/236426
293  cr.ui.login.ResourceLoader.loadAssets(SCREEN_OOBE_ENROLLMENT, function() {
294    // This screen is async-loaded so we manually trigger i18n processing.
295    i18nTemplate.process($('oauth-enrollment'), loadTimeData);
296    // Delayed binding since this isn't defined yet.
297    login.OAuthEnrollmentScreen.register();
298  });
299
300  // Delayed binding since this isn't defined yet.
301  cr.ui.Oobe.initialize();
302});
303