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