| OLD | NEW |
| (Empty) |
| 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="test_util.js"> | |
| 10 <include src="../../../../../ui/login/screen.js"> | |
| 11 <include src="screen_context.js"> | |
| 12 <include src="../user_images_grid.js"> | |
| 13 <include src="apps_menu.js"> | |
| 14 <include src="../../../../../ui/login/bubble.js"> | |
| 15 <include src="../../../../../ui/login/display_manager.js"> | |
| 16 <include src="header_bar.js"> | |
| 17 <include src="network_dropdown.js"> | |
| 18 <include src="oobe_screen_reset_confirmation_overlay.js"> | |
| 19 <include src="oobe_screen_reset.js"> | |
| 20 <include src="oobe_screen_autolaunch.js"> | |
| 21 <include src="oobe_screen_enable_kiosk.js"> | |
| 22 <include src="oobe_screen_terms_of_service.js"> | |
| 23 <include src="oobe_screen_user_image.js"> | |
| 24 <include src="../../../../../ui/login/account_picker/screen_account_picker.js"> | |
| 25 <include src="screen_app_launch_splash.js"> | |
| 26 <include src="screen_error_message.js"> | |
| 27 <include src="screen_gaia_signin.js"> | |
| 28 <include src="screen_password_changed.js"> | |
| 29 <include src="screen_supervised_user_creation.js"> | |
| 30 <include src="screen_tpm_error.js"> | |
| 31 <include src="screen_wrong_hwid.js"> | |
| 32 <include src="screen_confirm_password.js"> | |
| 33 <include src="screen_fatal_error.js"> | |
| 34 <include src="screen_device_disabled.js"> | |
| 35 <include src="screen_unrecoverable_cryptohome_error.js"> | |
| 36 <include src="../../../../../ui/login/login_ui_tools.js"> | |
| 37 <include src="../../../../../ui/login/account_picker/user_pod_row.js"> | |
| 38 <include src="../../../../../ui/login/resource_loader.js"> | |
| 39 | |
| 40 cr.define('cr.ui', function() { | |
| 41 var DisplayManager = cr.ui.login.DisplayManager; | |
| 42 | |
| 43 /** | |
| 44 * Constructs an Out of box controller. It manages initialization of screens, | |
| 45 * transitions, error messages display. | |
| 46 * @extends {DisplayManager} | |
| 47 * @constructor | |
| 48 */ | |
| 49 function Oobe() { | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Delay in milliseconds between start of OOBE animation and start of | |
| 54 * header bar animation. | |
| 55 */ | |
| 56 var HEADER_BAR_DELAY_MS = 300; | |
| 57 | |
| 58 cr.addSingletonGetter(Oobe); | |
| 59 | |
| 60 Oobe.prototype = { | |
| 61 __proto__: DisplayManager.prototype, | |
| 62 }; | |
| 63 | |
| 64 /** | |
| 65 * Handle accelerators. These are passed from native code instead of a JS | |
| 66 * event handler in order to make sure that embedded iframes cannot swallow | |
| 67 * them. | |
| 68 * @param {string} name Accelerator name. | |
| 69 */ | |
| 70 Oobe.handleAccelerator = function(name) { | |
| 71 Oobe.getInstance().handleAccelerator(name); | |
| 72 }; | |
| 73 | |
| 74 /** | |
| 75 * Shows the given screen. | |
| 76 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data} | |
| 77 */ | |
| 78 Oobe.showScreen = function(screen) { | |
| 79 Oobe.getInstance().showScreen(screen); | |
| 80 }; | |
| 81 | |
| 82 /** | |
| 83 * Updates missin API keys message visibility. | |
| 84 * @param {boolean} show True if the message should be visible. | |
| 85 */ | |
| 86 Oobe.showAPIKeysNotice = function(show) { | |
| 87 $('api-keys-notice-container').hidden = !show; | |
| 88 }; | |
| 89 | |
| 90 /** | |
| 91 * Updates version label visibility. | |
| 92 * @param {boolean} show True if version label should be visible. | |
| 93 */ | |
| 94 Oobe.showVersion = function(show) { | |
| 95 Oobe.getInstance().showVersion(show); | |
| 96 }; | |
| 97 | |
| 98 /** | |
| 99 * Update body class to switch between OOBE UI and Login UI. | |
| 100 */ | |
| 101 Oobe.showOobeUI = function(showOobe) { | |
| 102 if (showOobe) { | |
| 103 document.body.classList.add('oobe-display'); | |
| 104 | |
| 105 // Callback to animate the header bar in. | |
| 106 var showHeaderBar = function() { | |
| 107 login.HeaderBar.animateIn(false, function() { | |
| 108 chrome.send('headerBarVisible'); | |
| 109 }); | |
| 110 }; | |
| 111 // Start asynchronously so the OOBE network screen comes in first. | |
| 112 window.setTimeout(showHeaderBar, HEADER_BAR_DELAY_MS); | |
| 113 } else { | |
| 114 document.body.classList.remove('oobe-display'); | |
| 115 Oobe.getInstance().prepareForLoginDisplay_(); | |
| 116 // Ensure header bar is visible when switching to Login UI from oobe. | |
| 117 if (Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE) | |
| 118 login.HeaderBar.animateIn(true); | |
| 119 } | |
| 120 | |
| 121 Oobe.getInstance().headerHidden = false; | |
| 122 }; | |
| 123 | |
| 124 /** | |
| 125 * When |showShutdown| is set to "true", the shutdown button is shown and the | |
| 126 * reboot button hidden. If set to "false", the reboot button is visible and | |
| 127 * the shutdown button hidden. | |
| 128 */ | |
| 129 Oobe.showShutdown = function(showShutdown) { | |
| 130 $('login-header-bar').showShutdownButton = showShutdown; | |
| 131 $('login-header-bar').showRebootButton = !showShutdown; | |
| 132 }; | |
| 133 | |
| 134 /** | |
| 135 * Enables keyboard driven flow. | |
| 136 */ | |
| 137 Oobe.enableKeyboardFlow = function(value) { | |
| 138 // Don't show header bar for OOBE. | |
| 139 Oobe.getInstance().forceKeyboardFlow = value; | |
| 140 }; | |
| 141 | |
| 142 /** | |
| 143 * Disables signin UI. | |
| 144 */ | |
| 145 Oobe.disableSigninUI = function() { | |
| 146 DisplayManager.disableSigninUI(); | |
| 147 }; | |
| 148 | |
| 149 /** | |
| 150 * Shows signin UI. | |
| 151 * @param {string} opt_email An optional email for signin UI. | |
| 152 */ | |
| 153 Oobe.showSigninUI = function(opt_email) { | |
| 154 DisplayManager.showSigninUI(opt_email); | |
| 155 }; | |
| 156 | |
| 157 /** | |
| 158 * Resets sign-in input fields. | |
| 159 * @param {boolean} forceOnline Whether online sign-in should be forced. | |
| 160 * If |forceOnline| is false previously used sign-in type will be used. | |
| 161 */ | |
| 162 Oobe.resetSigninUI = function(forceOnline) { | |
| 163 DisplayManager.resetSigninUI(forceOnline); | |
| 164 }; | |
| 165 | |
| 166 /** | |
| 167 * Shows sign-in error bubble. | |
| 168 * @param {number} loginAttempts Number of login attemps tried. | |
| 169 * @param {string} message Error message to show. | |
| 170 * @param {string} link Text to use for help link. | |
| 171 * @param {number} helpId Help topic Id associated with help link. | |
| 172 */ | |
| 173 Oobe.showSignInError = function(loginAttempts, message, link, helpId) { | |
| 174 DisplayManager.showSignInError(loginAttempts, message, link, helpId); | |
| 175 }; | |
| 176 | |
| 177 /** | |
| 178 * Shows password changed screen that offers migration. | |
| 179 * @param {boolean} showError Whether to show the incorrect password error. | |
| 180 */ | |
| 181 Oobe.showPasswordChangedScreen = function(showError, email) { | |
| 182 DisplayManager.showPasswordChangedScreen(showError, email); | |
| 183 }; | |
| 184 | |
| 185 /** | |
| 186 * Shows dialog to create a supervised user. | |
| 187 */ | |
| 188 Oobe.showSupervisedUserCreationScreen = function() { | |
| 189 DisplayManager.showSupervisedUserCreationScreen(); | |
| 190 }; | |
| 191 | |
| 192 /** | |
| 193 * Shows TPM error screen. | |
| 194 */ | |
| 195 Oobe.showTpmError = function() { | |
| 196 DisplayManager.showTpmError(); | |
| 197 }; | |
| 198 | |
| 199 /** | |
| 200 * Show user-pods. | |
| 201 */ | |
| 202 Oobe.showUserPods = function() { | |
| 203 $('pod-row').loadLastWallpaper(); | |
| 204 Oobe.showScreen({id: SCREEN_ACCOUNT_PICKER}); | |
| 205 Oobe.resetSigninUI(true); | |
| 206 }; | |
| 207 | |
| 208 /** | |
| 209 * Clears error bubble as well as optional menus that could be open. | |
| 210 */ | |
| 211 Oobe.clearErrors = function() { | |
| 212 var accessibilityMenu = $('accessibility-menu'); | |
| 213 if (accessibilityMenu) | |
| 214 accessibilityMenu.hide(); | |
| 215 DisplayManager.clearErrors(); | |
| 216 }; | |
| 217 | |
| 218 /** | |
| 219 * Displays animations on successful authentication, that have to happen | |
| 220 * before login UI is dismissed. | |
| 221 */ | |
| 222 Oobe.animateAuthenticationSuccess = function() { | |
| 223 login.HeaderBar.animateOut(function() { | |
| 224 chrome.send('unlockOnLoginSuccess'); | |
| 225 }); | |
| 226 }; | |
| 227 | |
| 228 /** | |
| 229 * Displays animations that have to happen once login UI is fully displayed. | |
| 230 */ | |
| 231 Oobe.animateOnceFullyDisplayed = function() { | |
| 232 login.HeaderBar.animateIn(true, function() { | |
| 233 chrome.send('headerBarVisible'); | |
| 234 }); | |
| 235 }; | |
| 236 | |
| 237 /** | |
| 238 * Sets text content for a div with |labelId|. | |
| 239 * @param {string} labelId Id of the label div. | |
| 240 * @param {string} labelText Text for the label. | |
| 241 */ | |
| 242 Oobe.setLabelText = function(labelId, labelText) { | |
| 243 DisplayManager.setLabelText(labelId, labelText); | |
| 244 }; | |
| 245 | |
| 246 /** | |
| 247 * Sets the text content of the enterprise info message. | |
| 248 * If the text is empty, the entire notification will be hidden. | |
| 249 * @param {string} messageText The message text. | |
| 250 */ | |
| 251 Oobe.setEnterpriseInfo = function(messageText, assetId) { | |
| 252 DisplayManager.setEnterpriseInfo(messageText, assetId); | |
| 253 }; | |
| 254 | |
| 255 /** | |
| 256 * Updates the device requisition string shown in the requisition prompt. | |
| 257 * @param {string} requisition The device requisition. | |
| 258 */ | |
| 259 Oobe.updateDeviceRequisition = function(requisition) { | |
| 260 Oobe.getInstance().updateDeviceRequisition(requisition); | |
| 261 }; | |
| 262 | |
| 263 /** | |
| 264 * Enforces focus on user pod of locked user. | |
| 265 */ | |
| 266 Oobe.forceLockedUserPodFocus = function() { | |
| 267 login.AccountPickerScreen.forceLockedUserPodFocus(); | |
| 268 }; | |
| 269 | |
| 270 /** | |
| 271 * Clears password field in user-pod. | |
| 272 */ | |
| 273 Oobe.clearUserPodPassword = function() { | |
| 274 DisplayManager.clearUserPodPassword(); | |
| 275 }; | |
| 276 | |
| 277 /** | |
| 278 * Restores input focus to currently selected pod. | |
| 279 */ | |
| 280 Oobe.refocusCurrentPod = function() { | |
| 281 DisplayManager.refocusCurrentPod(); | |
| 282 }; | |
| 283 | |
| 284 /** | |
| 285 * Skip to login screen for telemetry. | |
| 286 */ | |
| 287 Oobe.skipToLoginForTesting = function() { | |
| 288 Oobe.disableSigninUI(); | |
| 289 chrome.send('skipToLoginForTesting'); | |
| 290 }; | |
| 291 | |
| 292 /** | |
| 293 * Login for telemetry. | |
| 294 * @param {string} username Login username. | |
| 295 * @param {string} password Login password. | |
| 296 */ | |
| 297 Oobe.loginForTesting = function(username, password, gaia_id) { | |
| 298 Oobe.disableSigninUI(); | |
| 299 chrome.send('skipToLoginForTesting', [username]); | |
| 300 if (!gaia_id) { | |
| 301 /* TODO (alemate): Remove this backward compatibility hack when | |
| 302 as soon as all telemetry tests will pass gaia_id directly. | |
| 303 */ | |
| 304 gaia_id = '12345'; | |
| 305 } | |
| 306 chrome.send('completeLogin', [gaia_id, username, password, false]); | |
| 307 }; | |
| 308 | |
| 309 /** | |
| 310 * Guest login for telemetry. | |
| 311 */ | |
| 312 Oobe.guestLoginForTesting = function() { | |
| 313 Oobe.skipToLoginForTesting(); | |
| 314 chrome.send('launchIncognito'); | |
| 315 }; | |
| 316 | |
| 317 /** | |
| 318 * Authenticate for telemetry - used for screenlocker. | |
| 319 * @param {string} username Login username. | |
| 320 * @param {string} password Login password. | |
| 321 */ | |
| 322 Oobe.authenticateForTesting = function(username, password) { | |
| 323 Oobe.disableSigninUI(); | |
| 324 chrome.send('authenticateUser', [username, password]); | |
| 325 }; | |
| 326 | |
| 327 /** | |
| 328 * Gaia login screen for telemetry. | |
| 329 */ | |
| 330 Oobe.addUserForTesting = function() { | |
| 331 Oobe.skipToLoginForTesting(); | |
| 332 chrome.send('addUser'); | |
| 333 }; | |
| 334 | |
| 335 /** | |
| 336 * Shows the add user dialog. Used in browser tests. | |
| 337 */ | |
| 338 Oobe.showAddUserForTesting = function() { | |
| 339 chrome.send('showAddUser'); | |
| 340 }; | |
| 341 | |
| 342 /** | |
| 343 * Hotrod requisition for telemetry. | |
| 344 */ | |
| 345 Oobe.remoraRequisitionForTesting = function() { | |
| 346 chrome.send('setDeviceRequisition', ['remora']); | |
| 347 }; | |
| 348 | |
| 349 /** | |
| 350 * Begin enterprise enrollment for telemetry. | |
| 351 */ | |
| 352 Oobe.switchToEnterpriseEnrollmentForTesting = function() { | |
| 353 chrome.send('toggleEnrollmentScreen'); | |
| 354 }; | |
| 355 | |
| 356 /** | |
| 357 * Finish enterprise enrollment for telemetry. | |
| 358 */ | |
| 359 Oobe.enterpriseEnrollmentDone = function() { | |
| 360 chrome.send('oauthEnrollClose', ['done']); | |
| 361 }; | |
| 362 | |
| 363 /** | |
| 364 * Returns true if enrollment was successful. Dismisses the enrollment | |
| 365 * attribute screen if it's present. | |
| 366 */ | |
| 367 Oobe.isEnrollmentSuccessfulForTest = function() { | |
| 368 if (document.querySelector('.oauth-enroll-state-attribute-prompt')) | |
| 369 chrome.send('oauthEnrollAttributes', ['', '']); | |
| 370 | |
| 371 return $('oauth-enrollment').classList.contains( | |
| 372 'oauth-enroll-state-success'); | |
| 373 }; | |
| 374 | |
| 375 /** | |
| 376 * Shows/hides login UI control bar with buttons like [Shut down]. | |
| 377 */ | |
| 378 Oobe.showControlBar = function(show) { | |
| 379 Oobe.getInstance().headerHidden = !show; | |
| 380 }; | |
| 381 | |
| 382 /** | |
| 383 * Sets the current size of the client area (display size). | |
| 384 * @param {number} width client area width | |
| 385 * @param {number} height client area height | |
| 386 */ | |
| 387 Oobe.setClientAreaSize = function(width, height) { | |
| 388 Oobe.getInstance().setClientAreaSize(width, height); | |
| 389 }; | |
| 390 | |
| 391 // Export | |
| 392 return { | |
| 393 Oobe: Oobe | |
| 394 }; | |
| 395 }); | |
| 396 | |
| 397 var Oobe = cr.ui.Oobe; | |
| 398 | |
| 399 // Allow selection events on components with editable text (password field) | |
| 400 // bug (http://code.google.com/p/chromium/issues/detail?id=125863) | |
| 401 disableTextSelectAndDrag(function(e) { | |
| 402 var src = e.target; | |
| 403 return src instanceof HTMLTextAreaElement || | |
| 404 src instanceof HTMLInputElement && | |
| 405 /text|password|search/.test(src.type); | |
| 406 }); | |
| 407 | |
| 408 // Register assets for async loading. | |
| 409 [{ | |
| 410 id: SCREEN_OOBE_ENROLLMENT, | |
| 411 html: [{ url: 'chrome://oobe/enrollment.html', targetID: 'inner-container' }], | |
| 412 css: ['chrome://oobe/enrollment.css'], | |
| 413 js: ['chrome://oobe/enrollment.js'] | |
| 414 }].forEach(cr.ui.login.ResourceLoader.registerAssets); | |
| 415 | |
| 416 (function() { | |
| 417 'use strict'; | |
| 418 | |
| 419 document.addEventListener('DOMContentLoaded', function() { | |
| 420 // Immediately load async assets. | |
| 421 // TODO(dconnelly): remove this at some point and only load as needed. | |
| 422 // See crbug.com/236426 | |
| 423 cr.ui.login.ResourceLoader.loadAssets(SCREEN_OOBE_ENROLLMENT, function() { | |
| 424 // This screen is async-loaded so we manually trigger i18n processing. | |
| 425 i18nTemplate.process($('oauth-enrollment'), loadTimeData); | |
| 426 // Delayed binding since this isn't defined yet. | |
| 427 login.OAuthEnrollmentScreen.register(); | |
| 428 }); | |
| 429 | |
| 430 cr.ui.Oobe.initialize(); | |
| 431 }); | |
| 432 })(); | |
| OLD | NEW |