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 // Id of the element which holds current network name.
16 /** @const */ var CURRENT_NETWORK_NAME_ID = 'captive-portal-network-name';
18 // Link which triggers frame reload.
19 /** @const */ var RELOAD_PAGE_ID = 'proxy-error-signin-retry-link';
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
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'
41 // Possible error states of the screen. Must be in the same order as
42 // ErrorScreen::ErrorState enum values.
43 /** @const */ var ERROR_STATES = [
48 ERROR_STATE.AUTH_EXT_TIMEOUT
53 'updateLocalizedContent',
62 // Error screen initial UI state.
63 ui_state_: ERROR_SCREEN_UI_STATE.UNKNOWN,
65 // Error screen initial error state.
66 error_state_: ERROR_STATE.UNKNOWN,
69 decorate: function() {
70 cr.ui.DropDown.decorate($('offline-networks-list'));
71 this.updateLocalizedContent();
75 * Updates localized content of the screen that is not updated via template.
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="#">',
83 $(FIX_CAPTIVE_PORTAL_ID).onclick = function() {
84 chrome.send('showCaptivePortal');
87 $('captive-portal-proxy-message-text').innerHTML =
88 loadTimeData.getStringF(
89 'captivePortalProxyMessage',
90 '<a id="' + FIX_PROXY_SETTINGS_ID + '" class="signin-link" href="#">',
92 $(FIX_PROXY_SETTINGS_ID).onclick = function() {
93 chrome.send('openProxySettings');
95 $('update-proxy-message-text').innerHTML = loadTimeData.getStringF(
96 'updateProxyMessageText',
97 '<a id="update-proxy-error-fix-proxy" class="signin-link" href="#">',
99 $('update-proxy-error-fix-proxy').onclick = function() {
100 chrome.send('openProxySettings');
102 $('signin-proxy-message-text').innerHTML = loadTimeData.getStringF(
103 'signinProxyMessageText',
104 '<a id="' + RELOAD_PAGE_ID + '" class="signin-link" href="#">',
106 '<a id="signin-proxy-error-fix-proxy" class="signin-link" href="#">',
108 $(RELOAD_PAGE_ID).onclick = function() {
109 var gaiaScreen = $(SCREEN_GAIA_SIGNIN);
110 // Schedules an immediate retry.
111 gaiaScreen.doReload();
113 $('signin-proxy-error-fix-proxy').onclick = function() {
114 chrome.send('openProxySettings');
117 $('error-guest-signin').innerHTML = loadTimeData.getStringF(
119 '<a id="error-guest-signin-link" class="signin-link" href="#">',
121 $('error-guest-signin-link').onclick = function() {
122 chrome.send('launchIncognito');
125 $('error-offline-login').innerHTML = loadTimeData.getStringF(
127 '<a id="error-offline-login-link" class="signin-link" href="#">',
129 $('error-offline-login-link').onclick = function() {
130 chrome.send('offlineLogin');
132 this.onContentChange_();
136 * Event handler that is invoked just before the screen in shown.
137 * @param {Object} data Screen init payload.
139 onBeforeShow: function(data) {
140 cr.ui.Oobe.clearErrors();
141 cr.ui.DropDown.show('offline-networks-list', false);
142 if (data === undefined)
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']);
155 * Event handler that is invoked just before the screen is hidden.
157 onBeforeHide: function() {
158 cr.ui.DropDown.hide('offline-networks-list');
162 * Buttons in oobe wizard's button strip.
163 * @type {array} Array of Buttons.
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');
175 buttons.push(rebootButton);
177 var spacer = this.ownerDocument.createElement('div');
178 spacer.classList.add('button-spacer');
179 spacer.classList.add('show-with-ui-state-kiosk-mode');
180 buttons.push(spacer);
182 var powerwashButton = this.ownerDocument.createElement('button');
183 powerwashButton.id = 'error-message-restart-and-powerwash-button';
184 powerwashButton.textContent =
185 loadTimeData.getString('localStateErrorPowerwashButton');
186 powerwashButton.classList.add('show-with-ui-state-local-state-error');
187 powerwashButton.addEventListener('click', function(e) {
188 chrome.send('localStateErrorPowerwashButtonClicked');
191 buttons.push(powerwashButton);
197 * Sets current UI state of the screen.
198 * @param {string} ui_state New UI state of the screen.
201 setUIState_: function(ui_state) {
202 this.classList.remove(this.ui_state);
203 this.ui_state = ui_state;
204 this.classList.add(this.ui_state);
206 if (ui_state == ERROR_SCREEN_UI_STATE.LOCAL_STATE_ERROR) {
207 // Hide header bar and progress dots, because there are no way
208 // from the error screen about broken local state.
209 Oobe.getInstance().headerHidden = true;
210 $('progress-dots').hidden = true;
212 this.onContentChange_();
216 * Sets current error state of the screen.
217 * @param {string} error_state New error state of the screen.
218 * @param {string} network Name of the current network
221 setErrorState_: function(error_state, network) {
222 this.classList.remove(this.error_state);
223 $(CURRENT_NETWORK_NAME_ID).textContent = network;
224 this.error_state = error_state;
225 this.classList.add(this.error_state);
226 this.onContentChange_();
229 /* Method called after content of the screen changed.
232 onContentChange_: function() {
233 if (Oobe.getInstance().currentScreen === this)
234 Oobe.getInstance().updateScreenSize(this);
238 * Prepares error screen to show guest signin link.
241 allowGuestSignin: function(allowed) {
242 this.classList.toggle('allow-guest-signin', allowed);
243 this.onContentChange_();
247 * Prepares error screen to show offline login link.
250 allowOfflineLogin: function(allowed) {
251 this.classList.toggle('allow-offline-login', allowed);
252 this.onContentChange_();
256 * Sets current UI state of the screen.
257 * @param {number} ui_state New UI state of the screen.
260 setUIState: function(ui_state) {
261 this.setUIState_(UI_STATES[ui_state]);
265 * Sets current error state of the screen.
266 * @param {number} error_state New error state of the screen.
267 * @param {string} network Name of the current network
270 setErrorState: function(error_state, network) {
271 this.setErrorState_(ERROR_STATES[error_state], network);