Upstream version 5.34.104.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   // Id of the element which holds current network name.
16   /** @const */ var CURRENT_NETWORK_NAME_ID = 'captive-portal-network-name';
17
18   // Link which triggers frame reload.
19   /** @const */ var RELOAD_PAGE_ID = 'proxy-error-signin-retry-link';
20
21   // Array of the possible UI states of the screen. Must be in the
22   // same order as ErrorScreen::UIState enum values.
23   /** @const */ var UI_STATES = [
24     ERROR_SCREEN_UI_STATE.UNKNOWN,
25     ERROR_SCREEN_UI_STATE.UPDATE,
26     ERROR_SCREEN_UI_STATE.SIGNIN,
27     ERROR_SCREEN_UI_STATE.MANAGED_USER_CREATION_FLOW,
28     ERROR_SCREEN_UI_STATE.KIOSK_MODE,
29     ERROR_SCREEN_UI_STATE.LOCAL_STATE_ERROR
30   ];
31
32   // Possible error states of the screen.
33   /** @const */ var ERROR_STATE = {
34     UNKNOWN: 'error-state-unknown',
35     PORTAL: 'error-state-portal',
36     OFFLINE: 'error-state-offline',
37     PROXY: 'error-state-proxy',
38     AUTH_EXT_TIMEOUT: 'error-state-auth-ext-timeout'
39   };
40
41   // Possible error states of the screen. Must be in the same order as
42   // ErrorScreen::ErrorState enum values.
43   /** @const */ var ERROR_STATES = [
44     ERROR_STATE.UNKNOWN,
45     ERROR_STATE.PORTAL,
46     ERROR_STATE.OFFLINE,
47     ERROR_STATE.PROXY,
48     ERROR_STATE.AUTH_EXT_TIMEOUT
49   ];
50
51   return {
52     EXTERNAL_API: [
53       'updateLocalizedContent',
54       'onBeforeShow',
55       'onBeforeHide',
56       'allowGuestSignin',
57       'allowOfflineLogin',
58       'setUIState',
59       'setErrorState'
60     ],
61
62     // Error screen initial UI state.
63     ui_state_: ERROR_SCREEN_UI_STATE.UNKNOWN,
64
65     // Error screen initial error state.
66     error_state_: ERROR_STATE.UNKNOWN,
67
68     /** @override */
69     decorate: function() {
70       cr.ui.DropDown.decorate($('offline-networks-list'));
71       this.updateLocalizedContent();
72     },
73
74     /**
75      * Updates localized content of the screen that is not updated via template.
76      */
77     updateLocalizedContent: function() {
78       $('captive-portal-message-text').innerHTML = loadTimeData.getStringF(
79         'captivePortalMessage',
80         '<b id="' + CURRENT_NETWORK_NAME_ID + '"></b>',
81         '<a id="' + FIX_CAPTIVE_PORTAL_ID + '" class="signin-link" href="#">',
82         '</a>');
83       $(FIX_CAPTIVE_PORTAL_ID).onclick = function() {
84         chrome.send('showCaptivePortal');
85       };
86
87       $('captive-portal-proxy-message-text').innerHTML =
88         loadTimeData.getStringF(
89           'captivePortalProxyMessage',
90           '<a id="' + FIX_PROXY_SETTINGS_ID + '" class="signin-link" href="#">',
91           '</a>');
92       $(FIX_PROXY_SETTINGS_ID).onclick = function() {
93         chrome.send('openProxySettings');
94       };
95       $('update-proxy-message-text').innerHTML = loadTimeData.getStringF(
96           'updateProxyMessageText',
97           '<a id="update-proxy-error-fix-proxy" class="signin-link" href="#">',
98           '</a>');
99       $('update-proxy-error-fix-proxy').onclick = function() {
100         chrome.send('openProxySettings');
101       };
102       $('signin-proxy-message-text').innerHTML = loadTimeData.getStringF(
103           'signinProxyMessageText',
104           '<a id="' + RELOAD_PAGE_ID + '" class="signin-link" href="#">',
105           '</a>',
106           '<a id="signin-proxy-error-fix-proxy" class="signin-link" href="#">',
107           '</a>');
108       $(RELOAD_PAGE_ID).onclick = function() {
109         var gaiaScreen = $(SCREEN_GAIA_SIGNIN);
110         // Schedules an immediate retry.
111         gaiaScreen.doReload();
112       };
113       $('signin-proxy-error-fix-proxy').onclick = function() {
114         chrome.send('openProxySettings');
115       };
116
117       $('error-guest-signin').innerHTML = loadTimeData.getStringF(
118           'guestSignin',
119           '<a id="error-guest-signin-link" class="signin-link" href="#">',
120           '</a>');
121       $('error-guest-signin-link').onclick = function() {
122         chrome.send('launchIncognito');
123       };
124
125       $('error-offline-login').innerHTML = loadTimeData.getStringF(
126           'offlineLogin',
127           '<a id="error-offline-login-link" class="signin-link" href="#">',
128           '</a>');
129       $('error-offline-login-link').onclick = function() {
130         chrome.send('offlineLogin');
131       };
132       this.onContentChange_();
133     },
134
135     /**
136      * Event handler that is invoked just before the screen in shown.
137      * @param {Object} data Screen init payload.
138      */
139     onBeforeShow: function(data) {
140       cr.ui.Oobe.clearErrors();
141       cr.ui.DropDown.show('offline-networks-list', false);
142       if (data === undefined)
143         return;
144       if ('uiState' in data)
145         this.setUIState(data['uiState']);
146       if ('errorState' in data && 'network' in data)
147         this.setErrorState(data['errorState'], data['network']);
148       if ('guestSigninAllowed' in data)
149         this.allowGuestSignin(data['guestSigninAllowed']);
150       if ('offlineLoginAllowed' in data)
151         this.allowOfflineLogin(data['offlineLoginAllowed']);
152     },
153
154     /**
155      * Event handler that is invoked just before the screen is hidden.
156      */
157     onBeforeHide: function() {
158       cr.ui.DropDown.hide('offline-networks-list');
159     },
160
161     /**
162      * Buttons in oobe wizard's button strip.
163      * @type {array} Array of Buttons.
164      */
165     get buttons() {
166       var buttons = [];
167
168       var rebootButton = this.ownerDocument.createElement('button');
169       rebootButton.textContent = loadTimeData.getString('rebootButton');
170       rebootButton.classList.add('show-with-ui-state-kiosk-mode');
171       rebootButton.addEventListener('click', function(e) {
172         chrome.send('rebootButtonClicked');
173         e.stopPropagation();
174       });
175       buttons.push(rebootButton);
176
177       var diagnoseButton = this.ownerDocument.createElement('button');
178       diagnoseButton.textContent = loadTimeData.getString('diagnoseButton');
179       diagnoseButton.classList.add('show-with-ui-state-kiosk-mode');
180       diagnoseButton.addEventListener('click', function(e) {
181         chrome.send('diagnoseButtonClicked');
182         e.stopPropagation();
183       });
184       buttons.push(diagnoseButton);
185
186       var spacer = this.ownerDocument.createElement('div');
187       spacer.classList.add('button-spacer');
188       spacer.classList.add('show-with-ui-state-kiosk-mode');
189       buttons.push(spacer);
190
191       var powerwashButton = this.ownerDocument.createElement('button');
192       powerwashButton.id = 'error-message-restart-and-powerwash-button';
193       powerwashButton.textContent =
194         loadTimeData.getString('localStateErrorPowerwashButton');
195       powerwashButton.classList.add('show-with-ui-state-local-state-error');
196       powerwashButton.addEventListener('click', function(e) {
197         chrome.send('localStateErrorPowerwashButtonClicked');
198         e.stopPropagation();
199       });
200       buttons.push(powerwashButton);
201
202       return buttons;
203     },
204
205     /**
206       * Sets current UI state of the screen.
207       * @param {string} ui_state New UI state of the screen.
208       * @private
209       */
210     setUIState_: function(ui_state) {
211       this.classList.remove(this.ui_state);
212       this.ui_state = ui_state;
213       this.classList.add(this.ui_state);
214
215       if (ui_state == ERROR_SCREEN_UI_STATE.LOCAL_STATE_ERROR) {
216         // Hide header bar and progress dots, because there are no way
217         // from the error screen about broken local state.
218         Oobe.getInstance().headerHidden = true;
219         $('progress-dots').hidden = true;
220       }
221       this.onContentChange_();
222     },
223
224     /**
225       * Sets current error state of the screen.
226       * @param {string} error_state New error state of the screen.
227       * @param {string} network Name of the current network
228       * @private
229       */
230     setErrorState_: function(error_state, network) {
231       this.classList.remove(this.error_state);
232       $(CURRENT_NETWORK_NAME_ID).textContent = network;
233       this.error_state = error_state;
234       this.classList.add(this.error_state);
235       this.onContentChange_();
236     },
237
238     /* Method called after content of the screen changed.
239      * @private
240      */
241     onContentChange_: function() {
242       if (Oobe.getInstance().currentScreen === this)
243         Oobe.getInstance().updateScreenSize(this);
244     },
245
246     /**
247      * Prepares error screen to show guest signin link.
248      * @private
249      */
250     allowGuestSignin: function(allowed) {
251       this.classList.toggle('allow-guest-signin', allowed);
252       this.onContentChange_();
253     },
254
255     /**
256      * Prepares error screen to show offline login link.
257      * @private
258      */
259     allowOfflineLogin: function(allowed) {
260       this.classList.toggle('allow-offline-login', allowed);
261       this.onContentChange_();
262     },
263
264     /**
265       * Sets current UI state of the screen.
266       * @param {number} ui_state New UI state of the screen.
267       * @private
268       */
269     setUIState: function(ui_state) {
270       this.setUIState_(UI_STATES[ui_state]);
271     },
272
273     /**
274       * Sets current error state of the screen.
275       * @param {number} error_state New error state of the screen.
276       * @param {string} network Name of the current network
277       * @private
278       */
279     setErrorState: function(error_state, network) {
280       this.setErrorState_(ERROR_STATES[error_state], network);
281     }
282   };
283 });