OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Offline message screen implementation. | 6 * @fileoverview Offline message screen implementation. |
7 */ | 7 */ |
8 | 8 |
9 cr.define('login', function() { | 9 cr.define('login', function() { |
10 // Screens that should have offline message overlay. | 10 // Screens that should have offline message overlay. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 /** @inheritDoc */ | 61 /** @inheritDoc */ |
62 decorate: function() { | 62 decorate: function() { |
63 chrome.send('loginAddNetworkStateObserver', | 63 chrome.send('loginAddNetworkStateObserver', |
64 ['login.ErrorMessageScreen.updateState']); | 64 ['login.ErrorMessageScreen.updateState']); |
65 | 65 |
66 cr.ui.DropDown.decorate($('offline-networks-list')); | 66 cr.ui.DropDown.decorate($('offline-networks-list')); |
67 this.updateLocalizedContent_(); | 67 this.updateLocalizedContent_(); |
68 }, | 68 }, |
69 | 69 |
70 onBeforeShow: function() { | |
71 cr.ui.DropDown.setActive('offline-networks-list', true, false); | |
72 | |
73 $('error-guest-signin').hidden = $('guestSignin').hidden || | |
74 !$('add-user-header-bar-item').hidden; | |
75 }, | |
76 | |
77 onBeforeHide: function() { | |
78 cr.ui.DropDown.setActive('offline-networks-list', false, false); | |
79 }, | |
80 | |
81 update: function() { | |
82 chrome.send('loginRequestNetworkState', | |
83 ['login.ErrorMessageScreen.updateState', | |
84 'update']); | |
85 }, | |
86 | |
87 /** | 70 /** |
88 * Updates localized content of the screen that is not updated via template. | 71 * Updates localized content of the screen that is not updated via template. |
89 */ | 72 */ |
90 updateLocalizedContent_: function() { | 73 updateLocalizedContent_: function() { |
91 $('captive-portal-message-text').innerHTML = localStrings.getStringF( | 74 $('captive-portal-message-text').innerHTML = localStrings.getStringF( |
92 'captivePortalMessage', | 75 'captivePortalMessage', |
93 '<b id="' + CURRENT_NETWORK_NAME_ID + '"></b>', | 76 '<b id="' + CURRENT_NETWORK_NAME_ID + '"></b>', |
94 '<a id="' + FIX_CAPTIVE_PORTAL_ID + '" class="signin-link" href="#">', | 77 '<a id="' + FIX_CAPTIVE_PORTAL_ID + '" class="signin-link" href="#">', |
95 '</a>'); | 78 '</a>'); |
96 $(FIX_CAPTIVE_PORTAL_ID).onclick = function() { | 79 $(FIX_CAPTIVE_PORTAL_ID).onclick = function() { |
(...skipping 13 matching lines...) Expand all Loading... |
110 // TODO(altimofeev): Support offline sign-in as well. | 93 // TODO(altimofeev): Support offline sign-in as well. |
111 $('error-guest-signin').innerHTML = localStrings.getStringF( | 94 $('error-guest-signin').innerHTML = localStrings.getStringF( |
112 'guestSignin', | 95 'guestSignin', |
113 '<a id="error-guest-signin-link" class="signin-link" href="#">', | 96 '<a id="error-guest-signin-link" class="signin-link" href="#">', |
114 '</a>'); | 97 '</a>'); |
115 $('error-guest-signin-link').onclick = function() { | 98 $('error-guest-signin-link').onclick = function() { |
116 chrome.send('launchIncognito'); | 99 chrome.send('launchIncognito'); |
117 }; | 100 }; |
118 }, | 101 }, |
119 | 102 |
| 103 onBeforeShow: function(lastNetworkType) { |
| 104 cr.ui.DropDown.show('offline-networks-list', false, lastNetworkType); |
| 105 |
| 106 $('error-guest-signin').hidden = $('guestSignin').hidden || |
| 107 !$('add-user-header-bar-item').hidden; |
| 108 }, |
| 109 |
| 110 onBeforeHide: function() { |
| 111 cr.ui.DropDown.hide('offline-networks-list'); |
| 112 }, |
| 113 |
| 114 update: function() { |
| 115 chrome.send('loginRequestNetworkState', |
| 116 ['login.ErrorMessageScreen.updateState', |
| 117 'update']); |
| 118 }, |
| 119 |
120 /** | 120 /** |
121 * Shows or hides offline message based on network on/offline state. | 121 * Shows or hides offline message based on network on/offline state. |
| 122 * @param {Integer} state Current state of the network (see NET_STATE). |
| 123 * @param {string} network Name of the current network. |
| 124 * @param {string} reason Reason the callback was called. |
| 125 * @param {int} lastNetworkType Last active network type. |
122 */ | 126 */ |
123 updateState_: function(state, network, reason) { | 127 updateState_: function(state, network, reason, lastNetworkType) { |
124 var currentScreen = Oobe.getInstance().currentScreen; | 128 var currentScreen = Oobe.getInstance().currentScreen; |
125 var offlineMessage = this; | 129 var offlineMessage = this; |
126 var isOnline = (state == NET_STATE.ONLINE); | 130 var isOnline = (state == NET_STATE.ONLINE); |
127 var isUnderCaptivePortal = (state == NET_STATE.PORTAL); | 131 var isUnderCaptivePortal = (state == NET_STATE.PORTAL); |
128 var isProxyError = reason == ERROR_REASONS.PROXY_AUTH_CANCELLED || | 132 var isProxyError = reason == ERROR_REASONS.PROXY_AUTH_CANCELLED || |
129 reason == ERROR_REASONS.PROXY_CONNECTION_FAILED; | 133 reason == ERROR_REASONS.PROXY_CONNECTION_FAILED; |
130 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; | 134 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; |
131 | 135 |
132 if (reason == 'proxy changed' && shouldOverlay && | 136 if (reason == 'proxy changed' && shouldOverlay && |
133 !offlineMessage.classList.contains('hidden') && | 137 !offlineMessage.classList.contains('hidden') && |
134 offlineMessage.classList.contains('show-captive-portal')) { | 138 offlineMessage.classList.contains('show-captive-portal')) { |
135 // Schedules a immediate retry. | 139 // Schedules a immediate retry. |
136 currentScreen.doReload(); | 140 currentScreen.doReload(); |
137 console.log('Retry page load since proxy settings has been changed'); | 141 console.log('Retry page load since proxy settings has been changed'); |
138 } | 142 } |
139 | 143 |
140 if (!isOnline && shouldOverlay) { | 144 if (!isOnline && shouldOverlay) { |
141 console.log('Show offline message, state=' + state + | 145 console.log('Show offline message, state=' + state + |
142 ', network=' + network + | 146 ', network=' + network + |
143 ', isUnderCaptivePortal=' + isUnderCaptivePortal); | 147 ', isUnderCaptivePortal=' + isUnderCaptivePortal); |
144 offlineMessage.onBeforeShow(); | 148 offlineMessage.onBeforeShow(lastNetworkType); |
145 | 149 |
146 if (isUnderCaptivePortal) { | 150 if (isUnderCaptivePortal) { |
147 if (isProxyError) { | 151 if (isProxyError) { |
148 offlineMessage.classList.remove('show-offline-message'); | 152 offlineMessage.classList.remove('show-offline-message'); |
149 offlineMessage.classList.remove('show-captive-portal'); | 153 offlineMessage.classList.remove('show-captive-portal'); |
150 offlineMessage.classList.add('show-proxy-error'); | 154 offlineMessage.classList.add('show-proxy-error'); |
151 } else { | 155 } else { |
152 $(CURRENT_NETWORK_NAME_ID).textContent = network; | 156 $(CURRENT_NETWORK_NAME_ID).textContent = network; |
153 offlineMessage.classList.remove('show-offline-message'); | 157 offlineMessage.classList.remove('show-offline-message'); |
154 offlineMessage.classList.remove('show-proxy-error'); | 158 offlineMessage.classList.remove('show-proxy-error'); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 194 } |
191 } | 195 } |
192 }, | 196 }, |
193 }; | 197 }; |
194 | 198 |
195 /** | 199 /** |
196 * Network state changed callback. | 200 * Network state changed callback. |
197 * @param {Integer} state Current state of the network (see NET_STATE). | 201 * @param {Integer} state Current state of the network (see NET_STATE). |
198 * @param {string} network Name of the current network. | 202 * @param {string} network Name of the current network. |
199 * @param {string} reason Reason the callback was called. | 203 * @param {string} reason Reason the callback was called. |
| 204 * @param {int} lastNetworkType Last active network type. |
200 */ | 205 */ |
201 ErrorMessageScreen.updateState = function(state, network, reason) { | 206 ErrorMessageScreen.updateState = function( |
202 $('error-message').updateState_(state, network, reason); | 207 state, network, reason, lastNetworkType) { |
| 208 $('error-message').updateState_(state, network, reason, lastNetworkType); |
203 }; | 209 }; |
204 | 210 |
205 /** | 211 /** |
206 * Handler for iframe's error notification coming from the outside. | 212 * Handler for iframe's error notification coming from the outside. |
207 * For more info see C++ class 'SnifferObserver' which calls this method. | 213 * For more info see C++ class 'SnifferObserver' which calls this method. |
208 * @param {number} error Error code. | 214 * @param {number} error Error code. |
209 */ | 215 */ |
210 ErrorMessageScreen.onFrameError = function(error) { | 216 ErrorMessageScreen.onFrameError = function(error) { |
211 console.log('Gaia frame error = ' + error); | 217 console.log('Gaia frame error = ' + error); |
212 if (error == NET_ERROR.ABORTED_BY_USER) { | 218 if (error == NET_ERROR.ABORTED_BY_USER) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 * via template. | 258 * via template. |
253 */ | 259 */ |
254 ErrorMessageScreen.updateLocalizedContent = function() { | 260 ErrorMessageScreen.updateLocalizedContent = function() { |
255 $('error-message').updateLocalizedContent_(); | 261 $('error-message').updateLocalizedContent_(); |
256 }; | 262 }; |
257 | 263 |
258 return { | 264 return { |
259 ErrorMessageScreen: ErrorMessageScreen | 265 ErrorMessageScreen: ErrorMessageScreen |
260 }; | 266 }; |
261 }); | 267 }); |
OLD | NEW |