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<include src="../../../../ui/login/screen.js"> 5<include src="../../../../ui/login/bubble.js"> 6<include src="../../../../ui/login/login_ui_tools.js"> 7<include src="../../../../ui/login/display_manager.js"> 8<include src="control_bar.js"> 9<include src="../../../../ui/login/account_picker/screen_account_picker.js"> 10<include src="../../../../ui/login/account_picker/user_pod_row.js"> 11<include src="../../../../ui/login/resource_loader.js"> 12<include src="user_manager_tutorial.js"> 13 14cr.define('cr.ui', function() { 15 var DisplayManager = cr.ui.login.DisplayManager; 16 var UserManagerTutorial = cr.ui.login.UserManagerTutorial; 17 18 /** 19 * Constructs an Out of box controller. It manages initialization of screens, 20 * transitions, error messages display. 21 * @extends {DisplayManager} 22 * @constructor 23 */ 24 function Oobe() { 25 } 26 27 cr.addSingletonGetter(Oobe); 28 29 Oobe.prototype = { 30 __proto__: DisplayManager.prototype, 31 }; 32 33 /** 34 * Shows the given screen. 35 * @param {bool} showGuest Whether the 'Browse as Guest' button is displayed. 36 * @param {bool} showAddPerson Whether the 'Add Person' button is displayed. 37 */ 38 Oobe.showUserManagerScreen = function(showGuest, showAddPerson) { 39 Oobe.getInstance().showScreen({id: 'account-picker', 40 data: {disableAddUser: false}}); 41 // The ChromeOS account-picker will hide the AddUser button if a user is 42 // logged in and the screen is "locked", so we must re-enabled it 43 $('add-user-header-bar-item').hidden = false; 44 45 // Hide control options if the user does not have the right permissions. 46 $('guest-user-button').hidden = !showGuest; 47 $('add-user-button').hidden = !showAddPerson; 48 $('login-header-bar').hidden = false; 49 50 // Disable the context menu, as the Print/Inspect element items don't 51 // make sense when displayed as a widget. 52 document.addEventListener('contextmenu', function(e) {e.preventDefault();}); 53 54 var hash = window.location.hash; 55 if (hash && hash == '#tutorial') 56 UserManagerTutorial.startTutorial(); 57 }; 58 59 /** 60 * Open a new browser for the given profile. 61 * @param {string} email The user's email, if signed in. 62 * @param {string} displayName The user's display name. 63 */ 64 Oobe.launchUser = function(email, displayName) { 65 chrome.send('launchUser', [email, displayName]); 66 }; 67 68 /** 69 * Disables signin UI. 70 */ 71 Oobe.disableSigninUI = function() { 72 DisplayManager.disableSigninUI(); 73 }; 74 75 /** 76 * Shows signin UI. 77 * @param {string} opt_email An optional email for signin UI. 78 */ 79 Oobe.showSigninUI = function(opt_email) { 80 DisplayManager.showSigninUI(opt_email); 81 }; 82 83 /** 84 * Shows sign-in error bubble. 85 * @param {number} loginAttempts Number of login attemps tried. 86 * @param {string} message Error message to show. 87 * @param {string} link Text to use for help link. 88 * @param {number} helpId Help topic Id associated with help link. 89 */ 90 Oobe.showSignInError = function(loginAttempts, message, link, helpId) { 91 DisplayManager.showSignInError(loginAttempts, message, link, helpId); 92 }; 93 94 /** 95 * Clears error bubble as well as optional menus that could be open. 96 */ 97 Oobe.clearErrors = function() { 98 DisplayManager.clearErrors(); 99 }; 100 101 /** 102 * Clears password field in user-pod. 103 */ 104 Oobe.clearUserPodPassword = function() { 105 DisplayManager.clearUserPodPassword(); 106 }; 107 108 /** 109 * Restores input focus to currently selected pod. 110 */ 111 Oobe.refocusCurrentPod = function() { 112 DisplayManager.refocusCurrentPod(); 113 }; 114 115 /** 116 * Show the user manager tutorial 117 * @param {string} email The user's email, if signed in. 118 * @param {string} displayName The user's display name. 119 */ 120 Oobe.showUserManagerTutorial = function() { 121 UserManagerTutorial.startTutorial(); 122 }; 123 124 // Export 125 return { 126 Oobe: Oobe 127 }; 128}); 129 130cr.define('UserManager', function() { 131 'use strict'; 132 133 function initialize() { 134 cr.ui.login.DisplayManager.initialize(); 135 cr.ui.login.UserManagerTutorial.initialize(); 136 login.AccountPickerScreen.register(); 137 cr.ui.Bubble.decorate($('bubble')); 138 login.HeaderBar.decorate($('login-header-bar')); 139 140 // Hide the header bar until the showUserManagerMethod can apply function 141 // parameters that affect widget visiblity. 142 $('login-header-bar').hidden = true; 143 144 chrome.send('userManagerInitialize', [window.location.hash]); 145 } 146 147 // Return an object with all of the exports. 148 return { 149 initialize: initialize 150 }; 151}); 152 153var Oobe = cr.ui.Oobe; 154 155// Allow selection events on components with editable text (password field) 156// bug (http://code.google.com/p/chromium/issues/detail?id=125863) 157disableTextSelectAndDrag(function(e) { 158 var src = e.target; 159 return src instanceof HTMLTextAreaElement || 160 src instanceof HTMLInputElement && 161 /text|password|search/.test(src.type); 162}); 163 164document.addEventListener('DOMContentLoaded', UserManager.initialize); 165