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