Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / chromeos / login / screen_error_message.js
1 // Copyright (c) 2012 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 Offline message screen implementation.
7  */
8
9 login.createScreen('ErrorMessageScreen', 'error-message', function() {
10   // Link which starts guest session for captive portal fixing.
11   /** @const */ var FIX_CAPTIVE_PORTAL_ID = 'captive-portal-fix-link';
12
13   /** @const */ var FIX_PROXY_SETTINGS_ID = 'proxy-settings-fix-link';
14
15   // Class of the elements which hold current network name.
16   /** @const */ var CURRENT_NETWORK_NAME_CLASS =
17       'portal-network-name';
18
19   // Link which triggers frame reload.
20   /** @const */ var RELOAD_PAGE_ID = 'proxy-error-signin-retry-link';
21
22   // Array of the possible UI states of the screen. Must be in the
23   // same order as ErrorScreen::UIState enum values.
24   /** @const */ var UI_STATES = [
25     ERROR_SCREEN_UI_STATE.UNKNOWN,
26     ERROR_SCREEN_UI_STATE.UPDATE,
27     ERROR_SCREEN_UI_STATE.SIGNIN,
28     ERROR_SCREEN_UI_STATE.MANAGED_USER_CREATION_FLOW,
29     ERROR_SCREEN_UI_STATE.KIOSK_MODE,
30     ERROR_SCREEN_UI_STATE.LOCAL_STATE_ERROR,
31     ERROR_SCREEN_UI_STATE.AUTO_ENROLLMENT_ERROR,
32     ERROR_SCREEN_UI_STATE.ROLLBACK_ERROR,
33   ];
34
35   // The help topic linked from the auto enrollment error message.
36   /** @const */ var HELP_TOPIC_AUTO_ENROLLMENT = 4632009;
37
38   // Possible error states of the screen.
39   /** @const */ var ERROR_STATE = {
40     UNKNOWN: 'error-state-unknown',
41     PORTAL: 'error-state-portal',
42     OFFLINE: 'error-state-offline',
43     PROXY: 'error-state-proxy',
44     AUTH_EXT_TIMEOUT: 'error-state-auth-ext-timeout',
45     KIOSK_ONLINE: 'error-state-kiosk-online'
46   };
47
48   // Possible error states of the screen. Must be in the same order as
49   // ErrorScreen::ErrorState enum values.
50   /** @const */ var ERROR_STATES = [
51     ERROR_STATE.UNKNOWN,
52     ERROR_STATE.PORTAL,
53     ERROR_STATE.OFFLINE,
54     ERROR_STATE.PROXY,
55     ERROR_STATE.AUTH_EXT_TIMEOUT,
56     ERROR_STATE.KIOSK_ONLINE
57   ];
58
59   return {
60     EXTERNAL_API: [
61       'updateLocalizedContent',
62       'onBeforeShow',
63       'onBeforeHide',
64       'allowGuestSignin',
65       'allowOfflineLogin',
66       'setUIState',
67       'setErrorState',
68       'showConnectingIndicator'
69     ],
70
71     // Error screen initial UI state.
72     ui_state_: ERROR_SCREEN_UI_STATE.UNKNOWN,
73
74     // Error screen initial error state.
75     error_state_: ERROR_STATE.UNKNOWN,
76
77     /** @override */
78     decorate: function() {
79       cr.ui.DropDown.decorate($('offline-networks-list'));
80       this.updateLocalizedContent();
81     },
82
83     /**
84      * Updates localized content of the screen that is not updated via template.
85      */
86     updateLocalizedContent: function() {
87       $('auto-enrollment-offline-message-text').innerHTML =
88           loadTimeData.getStringF(
89               'autoEnrollmentOfflineMessageBody',
90               '<b class="' + CURRENT_NETWORK_NAME_CLASS + '"></b>',
91               '<a id="auto-enrollment-learn-more" class="signin-link" ' +
92                   '"href="#">',
93               '</a>');
94       $('auto-enrollment-learn-more').onclick = function() {
95         chrome.send('launchHelpApp', [HELP_TOPIC_AUTO_ENROLLMENT]);
96       };
97
98       $('captive-portal-message-text').innerHTML = loadTimeData.getStringF(
99         'captivePortalMessage',
100         '<b class="' + CURRENT_NETWORK_NAME_CLASS + '"></b>',
101         '<a id="' + FIX_CAPTIVE_PORTAL_ID + '" class="signin-link" href="#">',
102         '</a>');
103       $(FIX_CAPTIVE_PORTAL_ID).onclick = function() {
104         chrome.send('showCaptivePortal');
105       };
106
107       $('captive-portal-proxy-message-text').innerHTML =
108         loadTimeData.getStringF(
109           'captivePortalProxyMessage',
110           '<a id="' + FIX_PROXY_SETTINGS_ID + '" class="signin-link" href="#">',
111           '</a>');
112       $(FIX_PROXY_SETTINGS_ID).onclick = function() {
113         chrome.send('openProxySettings');
114       };
115       $('update-proxy-message-text').innerHTML = loadTimeData.getStringF(
116           'updateProxyMessageText',
117           '<a id="update-proxy-error-fix-proxy" class="signin-link" href="#">',
118           '</a>');
119       $('update-proxy-error-fix-proxy').onclick = function() {
120         chrome.send('openProxySettings');
121       };
122       $('signin-proxy-message-text').innerHTML = loadTimeData.getStringF(
123           'signinProxyMessageText',
124           '<a id="' + RELOAD_PAGE_ID + '" class="signin-link" href="#">',
125           '</a>',
126           '<a id="signin-proxy-error-fix-proxy" class="signin-link" href="#">',
127           '</a>');
128       $(RELOAD_PAGE_ID).onclick = function() {
129         var gaiaScreen = $(SCREEN_GAIA_SIGNIN);
130         // Schedules an immediate retry.
131         gaiaScreen.doReload();
132       };
133       $('signin-proxy-error-fix-proxy').onclick = function() {
134         chrome.send('openProxySettings');
135       };
136
137       $('error-guest-signin').innerHTML = loadTimeData.getStringF(
138           'guestSignin',
139           '<a id="error-guest-signin-link" class="signin-link" href="#">',
140           '</a>');
141       $('error-guest-signin-link').onclick = this.launchGuestSession_;
142
143       $('error-guest-signin-fix-network').innerHTML = loadTimeData.getStringF(
144           'guestSigninFixNetwork',
145           '<a id="error-guest-fix-network-signin-link" class="signin-link" ' +
146               'href="#">',
147           '</a>');
148       $('error-guest-fix-network-signin-link').onclick =
149           this.launchGuestSession_;
150
151       $('error-offline-login').innerHTML = loadTimeData.getStringF(
152           'offlineLogin',
153           '<a id="error-offline-login-link" class="signin-link" href="#">',
154           '</a>');
155       $('error-offline-login-link').onclick = function() {
156         chrome.send('offlineLogin');
157       };
158
159       var ellipsis = '';
160       for (var i = 1; i <= 3; ++i) {
161         ellipsis +=
162             '<span id="connecting-indicator-ellipsis-' + i + '">.</span>';
163       }
164       $('connecting-indicator').innerHTML =
165           loadTimeData.getStringF('connectingIndicatorText', ellipsis);
166
167       this.onContentChange_();
168     },
169
170     /**
171      * Event handler that is invoked just before the screen in shown.
172      * @param {Object} data Screen init payload.
173      */
174     onBeforeShow: function(data) {
175       cr.ui.Oobe.clearErrors();
176       cr.ui.DropDown.show('offline-networks-list', false);
177       if (data === undefined)
178         return;
179       if ('uiState' in data)
180         this.setUIState(data['uiState']);
181       if ('errorState' in data && 'network' in data)
182         this.setErrorState(data['errorState'], data['network']);
183       if ('guestSigninAllowed' in data)
184         this.allowGuestSignin(data['guestSigninAllowed']);
185       if ('offlineLoginAllowed' in data)
186         this.allowOfflineLogin(data['offlineLoginAllowed']);
187       if ('showConnectingIndicator' in data)
188         this.showConnectingIndicator(data['showConnectingIndicator']);
189     },
190
191     /**
192      * Event handler that is invoked just before the screen is hidden.
193      */
194     onBeforeHide: function() {
195       cr.ui.DropDown.hide('offline-networks-list');
196     },
197
198     /**
199      * Buttons in oobe wizard's button strip.
200      * @type {array} Array of Buttons.
201      */
202     get buttons() {
203       var buttons = [];
204
205       var rebootButton = this.ownerDocument.createElement('button');
206       rebootButton.textContent = loadTimeData.getString('rebootButton');
207       rebootButton.classList.add('show-with-ui-state-kiosk-mode');
208       rebootButton.addEventListener('click', function(e) {
209         chrome.send('rebootButtonClicked');
210         e.stopPropagation();
211       });
212       buttons.push(rebootButton);
213
214       var diagnoseButton = this.ownerDocument.createElement('button');
215       diagnoseButton.textContent = loadTimeData.getString('diagnoseButton');
216       diagnoseButton.classList.add('show-with-ui-state-kiosk-mode');
217       diagnoseButton.addEventListener('click', function(e) {
218         chrome.send('diagnoseButtonClicked');
219         e.stopPropagation();
220       });
221       buttons.push(diagnoseButton);
222
223       var certsButton = this.ownerDocument.createElement('button');
224       certsButton.textContent = loadTimeData.getString('configureCertsButton');
225       certsButton.classList.add('show-with-ui-state-kiosk-mode');
226       certsButton.addEventListener('click', function(e) {
227         chrome.send('configureCertsClicked');
228         e.stopPropagation();
229       });
230       buttons.push(certsButton);
231
232       var continueButton = this.ownerDocument.createElement('button');
233       continueButton.id = 'continue-network-config-btn';
234       continueButton.textContent = loadTimeData.getString('continueButton');
235       continueButton.classList.add('show-with-error-state-kiosk-online');
236       continueButton.addEventListener('click', function(e) {
237         chrome.send('continueAppLaunch');
238         e.stopPropagation();
239       });
240       buttons.push(continueButton);
241
242       var okButton = this.ownerDocument.createElement('button');
243       okButton.id = 'ok-error-screen-btn';
244       okButton.textContent = loadTimeData.getString('okButton');
245       okButton.classList.add('show-with-ui-state-rollback-error');
246       okButton.addEventListener('click', function(e) {
247         chrome.send('cancelOnReset');
248         e.stopPropagation();
249       });
250       buttons.push(okButton);
251
252       var spacer = this.ownerDocument.createElement('div');
253       spacer.classList.add('button-spacer');
254       spacer.classList.add('show-with-ui-state-kiosk-mode');
255       buttons.push(spacer);
256
257       var powerwashButton = this.ownerDocument.createElement('button');
258       powerwashButton.id = 'error-message-restart-and-powerwash-button';
259       powerwashButton.textContent =
260         loadTimeData.getString('localStateErrorPowerwashButton');
261       powerwashButton.classList.add('show-with-ui-state-local-state-error');
262       powerwashButton.addEventListener('click', function(e) {
263         chrome.send('localStateErrorPowerwashButtonClicked');
264         e.stopPropagation();
265       });
266       buttons.push(powerwashButton);
267
268       return buttons;
269     },
270
271     /**
272       * Sets current UI state of the screen.
273       * @param {string} ui_state New UI state of the screen.
274       * @private
275       */
276     setUIState_: function(ui_state) {
277       this.classList.remove(this.ui_state);
278       this.ui_state = ui_state;
279       this.classList.add(this.ui_state);
280
281       if (ui_state == ERROR_SCREEN_UI_STATE.LOCAL_STATE_ERROR) {
282         // Hide header bar and progress dots, because there are no way
283         // from the error screen about broken local state.
284         Oobe.getInstance().headerHidden = true;
285         $('progress-dots').hidden = true;
286       }
287       this.onContentChange_();
288     },
289
290     /**
291       * Sets current error state of the screen.
292       * @param {string} error_state New error state of the screen.
293       * @param {string} network Name of the current network
294       * @private
295       */
296     setErrorState_: function(error_state, network) {
297       this.classList.remove(this.error_state);
298       var networkNameElems =
299           document.getElementsByClassName(CURRENT_NETWORK_NAME_CLASS);
300       for (var i = 0; i < networkNameElems.length; ++i)
301         networkNameElems[i].textContent = network;
302       this.error_state = error_state;
303       this.classList.add(this.error_state);
304       this.onContentChange_();
305     },
306
307     /* Method called after content of the screen changed.
308      * @private
309      */
310     onContentChange_: function() {
311       if (Oobe.getInstance().currentScreen === this)
312         Oobe.getInstance().updateScreenSize(this);
313     },
314
315     /**
316      * Event handler for guest session launch.
317      * @private
318      */
319     launchGuestSession_: function() {
320       chrome.send(Oobe.getInstance().isOobeUI() ?
321           'launchOobeGuestSession' : 'launchIncognito');
322     },
323
324     /**
325      * Prepares error screen to show guest signin link.
326      * @private
327      */
328     allowGuestSignin: function(allowed) {
329       this.classList.toggle('allow-guest-signin', allowed);
330       this.onContentChange_();
331     },
332
333     /**
334      * Prepares error screen to show offline login link.
335      * @private
336      */
337     allowOfflineLogin: function(allowed) {
338       this.classList.toggle('allow-offline-login', allowed);
339       this.onContentChange_();
340     },
341
342     /**
343       * Sets current UI state of the screen.
344       * @param {number} ui_state New UI state of the screen.
345       * @private
346       */
347     setUIState: function(ui_state) {
348       this.setUIState_(UI_STATES[ui_state]);
349     },
350
351     /**
352       * Sets current error state of the screen.
353       * @param {number} error_state New error state of the screen.
354       * @param {string} network Name of the current network
355       * @private
356       */
357     setErrorState: function(error_state, network) {
358       this.setErrorState_(ERROR_STATES[error_state], network);
359     },
360
361     /**
362      * Updates visibility of the label indicating we're reconnecting.
363      * @param {boolean} show Whether the label should be shown.
364      */
365     showConnectingIndicator: function(show) {
366       this.classList.toggle('show-connecting-indicator', show);
367       this.onContentChange_();
368     }
369   };
370 });