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