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