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.
6 * @fileoverview Offline message screen implementation.
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';
13 /** @const */ var FIX_PROXY_SETTINGS_ID = 'proxy-settings-fix-link';
15 // Class of the elements which hold current network name.
16 /** @const */ var CURRENT_NETWORK_NAME_CLASS =
17 'portal-network-name';
19 // Link which triggers frame reload.
20 /** @const */ var RELOAD_PAGE_ID = 'proxy-error-signin-retry-link';
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,
35 // The help topic linked from the auto enrollment error message.
36 /** @const */ var HELP_TOPIC_AUTO_ENROLLMENT = 4632009;
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'
48 // Possible error states of the screen. Must be in the same order as
49 // ErrorScreen::ErrorState enum values.
50 /** @const */ var ERROR_STATES = [
55 ERROR_STATE.AUTH_EXT_TIMEOUT,
56 ERROR_STATE.KIOSK_ONLINE
61 'updateLocalizedContent',
68 'showConnectingIndicator'
71 // Error screen initial UI state.
72 ui_state_: ERROR_SCREEN_UI_STATE.UNKNOWN,
74 // Error screen initial error state.
75 error_state_: ERROR_STATE.UNKNOWN,
78 decorate: function() {
79 cr.ui.DropDown.decorate($('offline-networks-list'));
80 this.updateLocalizedContent();
84 * Updates localized content of the screen that is not updated via template.
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" ' +
94 $('auto-enrollment-learn-more').onclick = function() {
95 chrome.send('launchHelpApp', [HELP_TOPIC_AUTO_ENROLLMENT]);
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="#">',
103 $(FIX_CAPTIVE_PORTAL_ID).onclick = function() {
104 chrome.send('showCaptivePortal');
107 $('captive-portal-proxy-message-text').innerHTML =
108 loadTimeData.getStringF(
109 'captivePortalProxyMessage',
110 '<a id="' + FIX_PROXY_SETTINGS_ID + '" class="signin-link" href="#">',
112 $(FIX_PROXY_SETTINGS_ID).onclick = function() {
113 chrome.send('openProxySettings');
115 $('update-proxy-message-text').innerHTML = loadTimeData.getStringF(
116 'updateProxyMessageText',
117 '<a id="update-proxy-error-fix-proxy" class="signin-link" href="#">',
119 $('update-proxy-error-fix-proxy').onclick = function() {
120 chrome.send('openProxySettings');
122 $('signin-proxy-message-text').innerHTML = loadTimeData.getStringF(
123 'signinProxyMessageText',
124 '<a id="' + RELOAD_PAGE_ID + '" class="signin-link" href="#">',
126 '<a id="signin-proxy-error-fix-proxy" class="signin-link" href="#">',
128 $(RELOAD_PAGE_ID).onclick = function() {
129 var gaiaScreen = $(SCREEN_GAIA_SIGNIN);
130 // Schedules an immediate retry.
131 gaiaScreen.doReload();
133 $('signin-proxy-error-fix-proxy').onclick = function() {
134 chrome.send('openProxySettings');
137 $('error-guest-signin').innerHTML = loadTimeData.getStringF(
139 '<a id="error-guest-signin-link" class="signin-link" href="#">',
141 $('error-guest-signin-link').onclick = this.launchGuestSession_;
143 $('error-guest-signin-fix-network').innerHTML = loadTimeData.getStringF(
144 'guestSigninFixNetwork',
145 '<a id="error-guest-fix-network-signin-link" class="signin-link" ' +
148 $('error-guest-fix-network-signin-link').onclick =
149 this.launchGuestSession_;
151 $('error-offline-login').innerHTML = loadTimeData.getStringF(
153 '<a id="error-offline-login-link" class="signin-link" href="#">',
155 $('error-offline-login-link').onclick = function() {
156 chrome.send('offlineLogin');
160 for (var i = 1; i <= 3; ++i) {
162 '<span id="connecting-indicator-ellipsis-' + i + '">.</span>';
164 $('connecting-indicator').innerHTML =
165 loadTimeData.getStringF('connectingIndicatorText', ellipsis);
167 this.onContentChange_();
171 * Event handler that is invoked just before the screen in shown.
172 * @param {Object} data Screen init payload.
174 onBeforeShow: function(data) {
175 cr.ui.Oobe.clearErrors();
176 cr.ui.DropDown.show('offline-networks-list', false);
177 if (data === undefined)
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']);
192 * Event handler that is invoked just before the screen is hidden.
194 onBeforeHide: function() {
195 cr.ui.DropDown.hide('offline-networks-list');
199 * Buttons in oobe wizard's button strip.
200 * @type {array} Array of Buttons.
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');
212 buttons.push(rebootButton);
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');
221 buttons.push(diagnoseButton);
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');
230 buttons.push(certsButton);
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');
240 buttons.push(continueButton);
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');
250 buttons.push(okButton);
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);
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');
266 buttons.push(powerwashButton);
272 * Sets current UI state of the screen.
273 * @param {string} ui_state New UI state of the screen.
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);
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;
287 this.onContentChange_();
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
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_();
307 /* Method called after content of the screen changed.
310 onContentChange_: function() {
311 if (Oobe.getInstance().currentScreen === this)
312 Oobe.getInstance().updateScreenSize(this);
316 * Event handler for guest session launch.
319 launchGuestSession_: function() {
320 chrome.send(Oobe.getInstance().isOobeUI() ?
321 'launchOobeGuestSession' : 'launchIncognito');
325 * Prepares error screen to show guest signin link.
328 allowGuestSignin: function(allowed) {
329 this.classList.toggle('allow-guest-signin', allowed);
330 this.onContentChange_();
334 * Prepares error screen to show offline login link.
337 allowOfflineLogin: function(allowed) {
338 this.classList.toggle('allow-offline-login', allowed);
339 this.onContentChange_();
343 * Sets current UI state of the screen.
344 * @param {number} ui_state New UI state of the screen.
347 setUIState: function(ui_state) {
348 this.setUIState_(UI_STATES[ui_state]);
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
357 setErrorState: function(error_state, network) {
358 this.setErrorState_(ERROR_STATES[error_state], network);
362 * Updates visibility of the label indicating we're reconnecting.
363 * @param {boolean} show Whether the label should be shown.
365 showConnectingIndicator: function(show) {
366 this.classList.toggle('show-connecting-indicator', show);
367 this.onContentChange_();