OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. This method is shared between |
| 7 * OOBE, login, and the lock screen. Add only methods that need to be shared |
| 8 * between all *three* screens here, as each additional method increases the |
| 9 * time it takes to show the lock screen. |
| 10 * |
| 11 * If a method needs to be shared between the oobe and login screens, add it to |
| 12 * login_non_lock_shared.js. |
| 13 */ |
| 14 |
| 15 // <include src="test_util.js"> |
| 16 // <include src="../../../../../ui/login/screen.js"> |
| 17 // <include src="screen_context.js"> |
| 18 // <include src="../user_images_grid.js"> |
| 19 // <include src="apps_menu.js"> |
| 20 // <include src="../../../../../ui/login/bubble.js"> |
| 21 // <include src="../../../../../ui/login/display_manager.js"> |
| 22 // <include src="header_bar.js"> |
| 23 |
| 24 // <include src="../../../../../ui/login/account_picker/md_screen_account_picker
.js"> |
| 25 |
| 26 // <include src="../../../../../ui/login/login_ui_tools.js"> |
| 27 // <include src="../../../../../ui/login/account_picker/md_user_pod_row.js"> |
| 28 // <include src="../../../../../ui/login/resource_loader.js"> |
| 29 |
| 30 cr.define('cr.ui', function() { |
| 31 var DisplayManager = cr.ui.login.DisplayManager; |
| 32 |
| 33 /** |
| 34 * Constructs an Out of box controller. It manages initialization of screens, |
| 35 * transitions, error messages display. |
| 36 * @extends {DisplayManager} |
| 37 * @constructor |
| 38 */ |
| 39 function Oobe() { |
| 40 } |
| 41 |
| 42 /** |
| 43 * Delay in milliseconds between start of OOBE animation and start of |
| 44 * header bar animation. |
| 45 */ |
| 46 var HEADER_BAR_DELAY_MS = 300; |
| 47 |
| 48 cr.addSingletonGetter(Oobe); |
| 49 |
| 50 Oobe.prototype = { |
| 51 __proto__: DisplayManager.prototype, |
| 52 }; |
| 53 |
| 54 /** |
| 55 * Handle accelerators. These are passed from native code instead of a JS |
| 56 * event handler in order to make sure that embedded iframes cannot swallow |
| 57 * them. |
| 58 * @param {string} name Accelerator name. |
| 59 */ |
| 60 Oobe.handleAccelerator = function(name) { |
| 61 Oobe.getInstance().handleAccelerator(name); |
| 62 }; |
| 63 |
| 64 /** |
| 65 * Shows the given screen. |
| 66 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data} |
| 67 */ |
| 68 Oobe.showScreen = function(screen) { |
| 69 Oobe.getInstance().showScreen(screen); |
| 70 }; |
| 71 |
| 72 /** |
| 73 * Updates missin API keys message visibility. |
| 74 * @param {boolean} show True if the message should be visible. |
| 75 */ |
| 76 Oobe.showAPIKeysNotice = function(show) { |
| 77 $('api-keys-notice-container').hidden = !show; |
| 78 }; |
| 79 |
| 80 /** |
| 81 * Updates version label visibility. |
| 82 * @param {boolean} show True if version label should be visible. |
| 83 */ |
| 84 Oobe.showVersion = function(show) { |
| 85 Oobe.getInstance().showVersion(show); |
| 86 }; |
| 87 |
| 88 /** |
| 89 * Update body class to switch between OOBE UI and Login UI. |
| 90 */ |
| 91 Oobe.showOobeUI = function(showOobe) { |
| 92 if (showOobe) { |
| 93 document.body.classList.add('oobe-display'); |
| 94 |
| 95 // Callback to animate the header bar in. |
| 96 var showHeaderBar = function() { |
| 97 login.HeaderBar.animateIn(false, function() { |
| 98 chrome.send('headerBarVisible'); |
| 99 }); |
| 100 }; |
| 101 // Start asynchronously so the OOBE network screen comes in first. |
| 102 window.setTimeout(showHeaderBar, HEADER_BAR_DELAY_MS); |
| 103 } else { |
| 104 document.body.classList.remove('oobe-display'); |
| 105 Oobe.getInstance().prepareForLoginDisplay_(); |
| 106 // Ensure header bar is visible when switching to Login UI from oobe. |
| 107 if (Oobe.getInstance().displayType == DISPLAY_TYPE.OOBE) |
| 108 login.HeaderBar.animateIn(true); |
| 109 } |
| 110 |
| 111 Oobe.getInstance().headerHidden = false; |
| 112 }; |
| 113 |
| 114 /** |
| 115 * When |showShutdown| is set to "true", the shutdown button is shown and the |
| 116 * reboot button hidden. If set to "false", the reboot button is visible and |
| 117 * the shutdown button hidden. |
| 118 */ |
| 119 Oobe.showShutdown = function(showShutdown) { |
| 120 $('login-header-bar').showShutdownButton = showShutdown; |
| 121 $('login-header-bar').showRebootButton = !showShutdown; |
| 122 }; |
| 123 |
| 124 /** |
| 125 * Enables keyboard driven flow. |
| 126 */ |
| 127 Oobe.enableKeyboardFlow = function(value) { |
| 128 // Don't show header bar for OOBE. |
| 129 Oobe.getInstance().forceKeyboardFlow = value; |
| 130 }; |
| 131 |
| 132 /** |
| 133 * Disables signin UI. |
| 134 */ |
| 135 Oobe.disableSigninUI = function() { |
| 136 DisplayManager.disableSigninUI(); |
| 137 }; |
| 138 |
| 139 /** |
| 140 * Shows signin UI. |
| 141 * @param {string} opt_email An optional email for signin UI. |
| 142 */ |
| 143 Oobe.showSigninUI = function(opt_email) { |
| 144 DisplayManager.showSigninUI(opt_email); |
| 145 }; |
| 146 |
| 147 /** |
| 148 * Resets sign-in input fields. |
| 149 * @param {boolean} forceOnline Whether online sign-in should be forced. |
| 150 * If |forceOnline| is false previously used sign-in type will be used. |
| 151 */ |
| 152 Oobe.resetSigninUI = function(forceOnline) { |
| 153 DisplayManager.resetSigninUI(forceOnline); |
| 154 }; |
| 155 |
| 156 /** |
| 157 * Shows sign-in error bubble. |
| 158 * @param {number} loginAttempts Number of login attemps tried. |
| 159 * @param {string} message Error message to show. |
| 160 * @param {string} link Text to use for help link. |
| 161 * @param {number} helpId Help topic Id associated with help link. |
| 162 */ |
| 163 Oobe.showSignInError = function(loginAttempts, message, link, helpId) { |
| 164 DisplayManager.showSignInError(loginAttempts, message, link, helpId); |
| 165 }; |
| 166 |
| 167 /** |
| 168 * Shows password changed screen that offers migration. |
| 169 * @param {boolean} showError Whether to show the incorrect password error. |
| 170 */ |
| 171 Oobe.showPasswordChangedScreen = function(showError, email) { |
| 172 DisplayManager.showPasswordChangedScreen(showError, email); |
| 173 }; |
| 174 |
| 175 /** |
| 176 * Shows dialog to create a supervised user. |
| 177 */ |
| 178 Oobe.showSupervisedUserCreationScreen = function() { |
| 179 DisplayManager.showSupervisedUserCreationScreen(); |
| 180 }; |
| 181 |
| 182 /** |
| 183 * Shows TPM error screen. |
| 184 */ |
| 185 Oobe.showTpmError = function() { |
| 186 DisplayManager.showTpmError(); |
| 187 }; |
| 188 |
| 189 /** |
| 190 * Shows Active Directory password change screen. |
| 191 * @param {string} username Name of the user that should change the password. |
| 192 */ |
| 193 Oobe.showActiveDirectoryPasswordChangeScreen = function(username) { |
| 194 DisplayManager.showActiveDirectoryPasswordChangeScreen(username); |
| 195 }; |
| 196 |
| 197 /** |
| 198 * Show user-pods. |
| 199 */ |
| 200 Oobe.showUserPods = function() { |
| 201 $('pod-row').loadLastWallpaper(); |
| 202 Oobe.showScreen({id: SCREEN_ACCOUNT_PICKER}); |
| 203 Oobe.resetSigninUI(true); |
| 204 }; |
| 205 |
| 206 /** |
| 207 * Clears error bubble as well as optional menus that could be open. |
| 208 */ |
| 209 Oobe.clearErrors = function() { |
| 210 var accessibilityMenu = $('accessibility-menu'); |
| 211 if (accessibilityMenu) |
| 212 accessibilityMenu.hide(); |
| 213 DisplayManager.clearErrors(); |
| 214 }; |
| 215 |
| 216 /** |
| 217 * Displays animations on successful authentication, that have to happen |
| 218 * before login UI is dismissed. |
| 219 */ |
| 220 Oobe.animateAuthenticationSuccess = function() { |
| 221 login.HeaderBar.animateOut(function() { |
| 222 chrome.send('unlockOnLoginSuccess'); |
| 223 }); |
| 224 }; |
| 225 |
| 226 /** |
| 227 * Displays animations that have to happen once login UI is fully displayed. |
| 228 */ |
| 229 Oobe.animateOnceFullyDisplayed = function() { |
| 230 login.HeaderBar.animateIn(true, function() { |
| 231 chrome.send('headerBarVisible'); |
| 232 }); |
| 233 }; |
| 234 |
| 235 /** |
| 236 * Sets text content for a div with |labelId|. |
| 237 * @param {string} labelId Id of the label div. |
| 238 * @param {string} labelText Text for the label. |
| 239 */ |
| 240 Oobe.setLabelText = function(labelId, labelText) { |
| 241 DisplayManager.setLabelText(labelId, labelText); |
| 242 }; |
| 243 |
| 244 /** |
| 245 * Sets the text content of the enterprise info message. |
| 246 * If the text is empty, the entire notification will be hidden. |
| 247 * @param {string} messageText The message text. |
| 248 */ |
| 249 Oobe.setEnterpriseInfo = function(messageText, assetId) { |
| 250 DisplayManager.setEnterpriseInfo(messageText, assetId); |
| 251 }; |
| 252 |
| 253 /** |
| 254 * Updates the device requisition string shown in the requisition prompt. |
| 255 * @param {string} requisition The device requisition. |
| 256 */ |
| 257 Oobe.updateDeviceRequisition = function(requisition) { |
| 258 Oobe.getInstance().updateDeviceRequisition(requisition); |
| 259 }; |
| 260 |
| 261 /** |
| 262 * Enforces focus on user pod of locked user. |
| 263 */ |
| 264 Oobe.forceLockedUserPodFocus = function() { |
| 265 login.AccountPickerScreen.forceLockedUserPodFocus(); |
| 266 }; |
| 267 |
| 268 /** |
| 269 * Clears password field in user-pod. |
| 270 */ |
| 271 Oobe.clearUserPodPassword = function() { |
| 272 DisplayManager.clearUserPodPassword(); |
| 273 }; |
| 274 |
| 275 /** |
| 276 * Restores input focus to currently selected pod. |
| 277 */ |
| 278 Oobe.refocusCurrentPod = function() { |
| 279 DisplayManager.refocusCurrentPod(); |
| 280 }; |
| 281 |
| 282 /** |
| 283 * Some ForTesting APIs directly access to DOM. Because this script is loaded |
| 284 * in header, DOM tree may not be available at beginning. |
| 285 * In DOMContentLoaded, after Oobe.initialize() is done, this is marked to |
| 286 * true, indicating ForTesting methods can be called. |
| 287 * External script using ForTesting APIs should wait for this condition. |
| 288 * @type {boolean} |
| 289 */ |
| 290 Oobe.readyForTesting = false; |
| 291 |
| 292 /** |
| 293 * Skip to login screen for telemetry. |
| 294 */ |
| 295 Oobe.skipToLoginForTesting = function() { |
| 296 Oobe.disableSigninUI(); |
| 297 chrome.send('skipToLoginForTesting'); |
| 298 }; |
| 299 |
| 300 /** |
| 301 * Login for telemetry. |
| 302 * @param {string} username Login username. |
| 303 * @param {string} password Login password. |
| 304 * @param {boolean} enterpriseEnroll Login as an enterprise enrollment? |
| 305 */ |
| 306 Oobe.loginForTesting = function(username, password, gaia_id, |
| 307 enterpriseEnroll = false) { |
| 308 // Helper method that runs |fn| after |screenName| is visible. |
| 309 function waitForOobeScreen(screenName, fn) { |
| 310 if (Oobe.getInstance().currentScreen && |
| 311 Oobe.getInstance().currentScreen.id === screenName) { |
| 312 fn(); |
| 313 } else { |
| 314 $('oobe').addEventListener('screenchanged', function handler(e) { |
| 315 if (e.detail == screenName) { |
| 316 $('oobe').removeEventListener('screenchanged', handler); |
| 317 fn(); |
| 318 } |
| 319 }); |
| 320 } |
| 321 } |
| 322 |
| 323 Oobe.disableSigninUI(); |
| 324 chrome.send('skipToLoginForTesting', [username]); |
| 325 |
| 326 if (!enterpriseEnroll) { |
| 327 chrome.send('completeLogin', [gaia_id, username, password, false]); |
| 328 } else { |
| 329 waitForOobeScreen('gaia-signin', function() { |
| 330 chrome.send('toggleEnrollmentScreen'); |
| 331 chrome.send('toggleFakeEnrollment'); |
| 332 }); |
| 333 |
| 334 waitForOobeScreen('oauth-enrollment', function() { |
| 335 chrome.send('oauthEnrollCompleteLogin', [username, 'authcode']); |
| 336 chrome.send('completeLogin', [gaia_id, username, password, false]); |
| 337 }); |
| 338 } |
| 339 }; |
| 340 |
| 341 /** |
| 342 * Guest login for telemetry. |
| 343 */ |
| 344 Oobe.guestLoginForTesting = function() { |
| 345 Oobe.skipToLoginForTesting(); |
| 346 chrome.send('launchIncognito'); |
| 347 }; |
| 348 |
| 349 /** |
| 350 * Authenticate for telemetry - used for screenlocker. |
| 351 * @param {string} username Login username. |
| 352 * @param {string} password Login password. |
| 353 */ |
| 354 Oobe.authenticateForTesting = function(username, password) { |
| 355 Oobe.disableSigninUI(); |
| 356 chrome.send('authenticateUser', [username, password, false]); |
| 357 }; |
| 358 |
| 359 /** |
| 360 * Gaia login screen for telemetry. |
| 361 */ |
| 362 Oobe.addUserForTesting = function() { |
| 363 Oobe.skipToLoginForTesting(); |
| 364 chrome.send('addUser'); |
| 365 }; |
| 366 |
| 367 /** |
| 368 * Shows the add user dialog. Used in browser tests. |
| 369 */ |
| 370 Oobe.showAddUserForTesting = function() { |
| 371 chrome.send('showAddUser'); |
| 372 }; |
| 373 |
| 374 /** |
| 375 * Hotrod requisition for telemetry. |
| 376 */ |
| 377 Oobe.remoraRequisitionForTesting = function() { |
| 378 chrome.send('setDeviceRequisition', ['remora']); |
| 379 }; |
| 380 |
| 381 /** |
| 382 * Begin enterprise enrollment for telemetry. |
| 383 */ |
| 384 Oobe.switchToEnterpriseEnrollmentForTesting = function() { |
| 385 chrome.send('toggleEnrollmentScreen'); |
| 386 }; |
| 387 |
| 388 /** |
| 389 * Finish enterprise enrollment for telemetry. |
| 390 */ |
| 391 Oobe.enterpriseEnrollmentDone = function() { |
| 392 chrome.send('oauthEnrollClose', ['done']); |
| 393 }; |
| 394 |
| 395 /** |
| 396 * Returns true if enrollment was successful. Dismisses the enrollment |
| 397 * attribute screen if it's present. |
| 398 */ |
| 399 Oobe.isEnrollmentSuccessfulForTest = function() { |
| 400 if (document.querySelector('.oauth-enroll-state-attribute-prompt')) |
| 401 chrome.send('oauthEnrollAttributes', ['', '']); |
| 402 |
| 403 return $('oauth-enrollment').classList.contains( |
| 404 'oauth-enroll-state-success'); |
| 405 }; |
| 406 |
| 407 /** |
| 408 * Shows/hides login UI control bar with buttons like [Shut down]. |
| 409 */ |
| 410 Oobe.showControlBar = function(show) { |
| 411 Oobe.getInstance().headerHidden = !show; |
| 412 }; |
| 413 |
| 414 /** |
| 415 * Changes some UI which depends on the virtual keyboard being shown/hidden. |
| 416 */ |
| 417 Oobe.setVirtualKeyboardShown = function(shown) { |
| 418 Oobe.getInstance().virtualKeyboardShown = shown; |
| 419 $('pod-row').setFocusedPodPinVisibility(!shown); |
| 420 }; |
| 421 |
| 422 /** |
| 423 * Sets the current size of the client area (display size). |
| 424 * @param {number} width client area width |
| 425 * @param {number} height client area height |
| 426 */ |
| 427 Oobe.setClientAreaSize = function(width, height) { |
| 428 Oobe.getInstance().setClientAreaSize(width, height); |
| 429 }; |
| 430 |
| 431 // Export |
| 432 return { |
| 433 Oobe: Oobe |
| 434 }; |
| 435 }); |
| 436 |
| 437 var Oobe = cr.ui.Oobe; |
| 438 |
| 439 // Allow selection events on components with editable text (password field) |
| 440 // bug (http://code.google.com/p/chromium/issues/detail?id=125863) |
| 441 disableTextSelectAndDrag(function(e) { |
| 442 var src = e.target; |
| 443 return src instanceof HTMLTextAreaElement || |
| 444 src instanceof HTMLInputElement && |
| 445 /text|password|search/.test(src.type); |
| 446 }); |
| 447 |
| 448 |
| 449 (function() { |
| 450 'use strict'; |
| 451 |
| 452 document.addEventListener('DOMContentLoaded', function() { |
| 453 try { |
| 454 Oobe.initialize(); |
| 455 } finally { |
| 456 // TODO(crbug.com/712078): Do not set readyForTesting in case of that |
| 457 // initialize() is failed. Currently, in some situation, initialize() |
| 458 // raises an exception unexpectedly. It means testing APIs should not |
| 459 // be called then. However, checking it here now causes bots failures |
| 460 // unfortunately. So, as a short term workaround, here set |
| 461 // readyForTesting even on failures, just to make test bots happy. |
| 462 Oobe.readyForTesting = true; |
| 463 } |
| 464 }); |
| 465 |
| 466 // Install a global error handler so stack traces are included in logs. |
| 467 window.onerror = function(message, file, line, column, error) { |
| 468 console.error(error.stack); |
| 469 } |
| 470 })(); |
OLD | NEW |