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
="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_fatal_error.js"></include
>
31 <include src
="user_pod_row.js"></include
>
32 <include src
="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}
46 cr
.addSingletonGetter(Oobe
);
49 __proto__
: DisplayManager
.prototype,
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
56 * @param {string} name Accelerator name.
58 Oobe
.handleAccelerator = function(name
) {
59 Oobe
.getInstance().handleAccelerator(name
);
63 * Shows the given screen.
64 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data}
66 Oobe
.showScreen = function(screen
) {
67 Oobe
.getInstance().showScreen(screen
);
71 * Updates version label visibilty.
72 * @param {boolean} show True if version label should be visible.
74 Oobe
.showVersion = function(show
) {
75 Oobe
.getInstance().showVersion(show
);
79 * Update body class to switch between OOBE UI and Login UI.
81 Oobe
.showOobeUI = function(showOobe
) {
83 document
.body
.classList
.add('oobe-display');
85 document
.body
.classList
.remove('oobe-display');
86 Oobe
.getInstance().prepareForLoginDisplay_();
89 // Don't show header bar for OOBE.
90 Oobe
.getInstance().headerHidden
= showOobe
;
94 * Enables keyboard driven flow.
96 Oobe
.enableKeyboardFlow = function(value
) {
97 // Don't show header bar for OOBE.
98 Oobe
.getInstance().forceKeyboardFlow
= value
;
102 * Disables signin UI.
104 Oobe
.disableSigninUI = function() {
105 DisplayManager
.disableSigninUI();
110 * @param {string} opt_email An optional email for signin UI.
112 Oobe
.showSigninUI = function(opt_email
) {
113 DisplayManager
.showSigninUI(opt_email
);
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.
121 Oobe
.resetSigninUI = function(forceOnline
) {
122 DisplayManager
.resetSigninUI(forceOnline
);
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.
132 Oobe
.showSignInError = function(loginAttempts
, message
, link
, helpId
) {
133 DisplayManager
.showSignInError(loginAttempts
, message
, link
, helpId
);
137 * Shows password changed screen that offers migration.
138 * @param {boolean} showError Whether to show the incorrect password error.
140 Oobe
.showPasswordChangedScreen = function(showError
) {
141 DisplayManager
.showPasswordChangedScreen(showError
);
145 * Shows dialog to create managed user.
147 Oobe
.showManagedUserCreationScreen = function() {
148 DisplayManager
.showManagedUserCreationScreen();
152 * Shows TPM error screen.
154 Oobe
.showTpmError = function() {
155 DisplayManager
.showTpmError();
159 * Clears error bubble as well as optional menus that could be open.
161 Oobe
.clearErrors = function() {
162 var accessibilityMenu
= $('accessibility-menu');
163 if (accessibilityMenu
)
164 accessibilityMenu
.hide();
165 DisplayManager
.clearErrors();
169 * Displays animations on successful authentication, that have to happen
170 * before login UI is dismissed.
172 Oobe
.animateAuthenticationSuccess = function() {
173 login
.HeaderBar
.animateOut(function() {
174 chrome
.send('unlockOnLoginSuccess');
179 * Displays animations that have to happen once login UI is fully displayed.
181 Oobe
.animateOnceFullyDisplayed = function() {
182 login
.HeaderBar
.animateIn();
186 * Handles login success notification.
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();
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.
201 Oobe
.setLabelText = function(labelId
, labelText
) {
202 DisplayManager
.setLabelText(labelId
, labelText
);
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.
210 Oobe
.setEnterpriseInfo = function(messageText
) {
211 DisplayManager
.setEnterpriseInfo(messageText
);
215 * Updates the device requisition string shown in the requisition prompt.
216 * @param {string} requisition The device requisition.
218 Oobe
.updateDeviceRequisition = function(requisition
) {
219 Oobe
.getInstance().updateDeviceRequisition(requisition
);
223 * Enforces focus on user pod of locked user.
225 Oobe
.forceLockedUserPodFocus = function() {
226 login
.AccountPickerScreen
.forceLockedUserPodFocus();
230 * Clears password field in user-pod.
232 Oobe
.clearUserPodPassword = function() {
233 DisplayManager
.clearUserPodPassword();
237 * Restores input focus to currently selected pod.
239 Oobe
.refocusCurrentPod = function() {
240 DisplayManager
.refocusCurrentPod();
244 * Login for autotests.
245 * @param {string} username Login username.
246 * @param {string} password Login password.
248 Oobe
.loginForTesting = function(username
, password
) {
249 chrome
.send('skipToLoginForTesting', [username
]);
250 chrome
.send('completeLogin', [username
, password
, false]);
254 * Authenticate for autotests.
255 * @param {string} username Login username.
256 * @param {string} password Login password.
258 Oobe
.authenticateForTesting = function(username
, password
) {
259 chrome
.send('authenticateUser', [username
, password
]);
268 var Oobe
= cr
.ui
.Oobe
;
270 // Allow selection events on components with editable text (password field)
271 // bug (http://code.google.com/p/chromium/issues/detail?id=125863)
272 disableTextSelectAndDrag(function(e
) {
274 return src
instanceof HTMLTextAreaElement
||
275 src
instanceof HTMLInputElement
&&
276 /text|password|search/.test(src
.type
);
279 // Register assets for async loading.
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
);
287 document
.addEventListener('DOMContentLoaded', function() {
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();
300 // Delayed binding since this isn't defined yet.
301 cr
.ui
.Oobe
.initialize();