OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 Login UI based on a stripped down OOBE controller. |
| 7 * TODO(xiyuan): Refactoring this to get a better structure. |
| 8 */ |
| 9 |
| 10 var localStrings = new LocalStrings(); |
| 11 |
| 12 cr.define('cr.ui', function() { |
| 13 var DisplayManager = cr.ui.login.DisplayManager; |
| 14 |
| 15 /** |
| 16 * Constructs an Out of box controller. It manages initialization of screens, |
| 17 * transitions, error messages display. |
| 18 * @extends {DisplayManager} |
| 19 * @constructor |
| 20 */ |
| 21 function Oobe() { |
| 22 } |
| 23 |
| 24 cr.addSingletonGetter(Oobe); |
| 25 |
| 26 Oobe.prototype = { |
| 27 __proto__: DisplayManager.prototype, |
| 28 }; |
| 29 |
| 30 /** |
| 31 * Initializes the OOBE flow. This will cause all C++ handlers to |
| 32 * be invoked to do final setup. |
| 33 */ |
| 34 Oobe.initialize = function() { |
| 35 login.AccountPickerScreen.register(); |
| 36 login.GaiaSigninScreen.register(); |
| 37 oobe.UserImageScreen.register(); |
| 38 login.OfflineMessageScreen.register(); |
| 39 |
| 40 cr.ui.Bubble.decorate($('bubble')); |
| 41 login.HeaderBar.decorate($('login-header-bar')); |
| 42 |
| 43 chrome.send('screenStateInitialize', []); |
| 44 }; |
| 45 |
| 46 /** |
| 47 * Handle accelerators. These are passed from native code instead of a JS |
| 48 * event handler in order to make sure that embedded iframes cannot swallow |
| 49 * them. |
| 50 * @param {string} name Accelerator name. |
| 51 */ |
| 52 Oobe.handleAccelerator = function(name) { |
| 53 Oobe.getInstance().handleAccelerator(name); |
| 54 }; |
| 55 |
| 56 /** |
| 57 * Shows the given screen. |
| 58 * @param {Object} screen Screen params dict, e.g. {id: screenId, data: data} |
| 59 */ |
| 60 Oobe.showScreen = function(screen) { |
| 61 Oobe.getInstance().showScreen(screen); |
| 62 }; |
| 63 |
| 64 /** |
| 65 * Dummy Oobe functions not present with stripped login UI. |
| 66 */ |
| 67 Oobe.enableContinueButton = function(enable) {}; |
| 68 Oobe.setUsageStats = function(checked) {}; |
| 69 Oobe.setOemEulaUrl = function(oemEulaUrl) {}; |
| 70 Oobe.setUpdateProgress = function(progress) {}; |
| 71 Oobe.setUpdateMessage = function(message) {}; |
| 72 Oobe.showUpdateCurtain = function(enable) {}; |
| 73 Oobe.setTpmPassword = function(password) {} |
| 74 Oobe.reloadContent = function(data) {} |
| 75 |
| 76 /** |
| 77 * Update body class to switch between OOBE UI and Login UI. |
| 78 */ |
| 79 Oobe.showOobeUI = function(showOobe) { |
| 80 if (showOobe) { |
| 81 document.body.classList.remove('login-display'); |
| 82 } else { |
| 83 document.body.classList.add('login-display'); |
| 84 Oobe.getInstance().prepareForLoginDisplay_(); |
| 85 } |
| 86 |
| 87 // Don't show header bar for OOBE. |
| 88 Oobe.getInstance().headerHidden = showOobe; |
| 89 }; |
| 90 |
| 91 /** |
| 92 * Shows signin UI. |
| 93 * @param {string} opt_email An optional email for signin UI. |
| 94 */ |
| 95 Oobe.showSigninUI = function(opt_email) { |
| 96 DisplayManager.showSigninUI(opt_email); |
| 97 }; |
| 98 |
| 99 /** |
| 100 * Resets sign-in input fields. |
| 101 */ |
| 102 Oobe.resetSigninUI = function() { |
| 103 DisplayManager.resetSigninUI(); |
| 104 }; |
| 105 |
| 106 /** |
| 107 * Shows sign-in error bubble. |
| 108 * @param {number} loginAttempts Number of login attemps tried. |
| 109 * @param {string} message Error message to show. |
| 110 * @param {string} link Text to use for help link. |
| 111 * @param {number} helpId Help topic Id associated with help link. |
| 112 */ |
| 113 Oobe.showSignInError = function(loginAttempts, message, link, helpId) { |
| 114 DisplayManager.showSignInError(loginAttempts, message, link, helpId); |
| 115 }; |
| 116 |
| 117 /** |
| 118 * Clears error bubble. |
| 119 */ |
| 120 Oobe.clearErrors = function() { |
| 121 DisplayManager.clearErrors(); |
| 122 }; |
| 123 |
| 124 /** |
| 125 * Handles login success notification. |
| 126 */ |
| 127 Oobe.onLoginSuccess = function(username) { |
| 128 if (Oobe.getInstance().currentScreen.id == SCREEN_ACCOUNT_PICKER) { |
| 129 // TODO(nkostylev): Enable animation back when session start jank |
| 130 // is reduced. See http://crosbug.com/11116 http://crosbug.com/18307 |
| 131 // $('pod-row').startAuthenticatedAnimation(); |
| 132 } |
| 133 }; |
| 134 |
| 135 /** |
| 136 * Sets text content for a div with |labelId|. |
| 137 * @param {string} labelId Id of the label div. |
| 138 * @param {string} labelText Text for the label. |
| 139 */ |
| 140 Oobe.setLabelText = function(labelId, labelText) { |
| 141 DisplayManager.setLabelText(labelId, labelText); |
| 142 }; |
| 143 |
| 144 // Export |
| 145 return { |
| 146 Oobe: Oobe |
| 147 }; |
| 148 }); |
| 149 |
| 150 var Oobe = cr.ui.Oobe; |
| 151 |
| 152 // Disable text selection. |
| 153 document.onselectstart = function(e) { |
| 154 e.preventDefault(); |
| 155 } |
| 156 |
| 157 // Disable dragging. |
| 158 document.ondragstart = function(e) { |
| 159 e.preventDefault(); |
| 160 } |
| 161 |
| 162 document.addEventListener('DOMContentLoaded', cr.ui.Oobe.initialize); |
OLD | NEW |