| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 // Note that OfflineMessageScreen is not registered with Oobe because | 27 // Note that OfflineMessageScreen is not registered with Oobe because |
| 28 // it is shown on top of sign-in screen instead of as an independent screen. | 28 // it is shown on top of sign-in screen instead of as an independent screen. |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 OfflineMessageScreen.prototype = { | 31 OfflineMessageScreen.prototype = { |
| 32 __proto__: HTMLDivElement.prototype, | 32 __proto__: HTMLDivElement.prototype, |
| 33 | 33 |
| 34 /** @inheritDoc */ | 34 /** @inheritDoc */ |
| 35 decorate: function() { | 35 decorate: function() { |
| 36 window.addEventListener('online', | 36 chrome.send('loginAddNetworkStateObserver', |
| 37 this.handleNetworkStateChange_.bind(this)); | 37 ['login.OfflineMessageScreen.updateState']); |
| 38 window.addEventListener('offline', | 38 |
| 39 this.handleNetworkStateChange_.bind(this)); | |
| 40 $('captive-portal-start-guest-session').onclick = function() { | 39 $('captive-portal-start-guest-session').onclick = function() { |
| 41 chrome.send('fixCaptivePortal'); | 40 chrome.send('fixCaptivePortal'); |
| 42 } | 41 } |
| 43 cr.ui.DropDown.decorate($('offline-networks-list')); | 42 cr.ui.DropDown.decorate($('offline-networks-list')); |
| 44 }, | 43 }, |
| 45 | 44 |
| 46 onBeforeShow: function() { | 45 onBeforeShow: function() { |
| 47 cr.ui.DropDown.setActive('offline-networks-list', true); | 46 cr.ui.DropDown.setActive('offline-networks-list', true); |
| 48 }, | 47 }, |
| 49 | 48 |
| 50 onBeforeHide: function() { | 49 onBeforeHide: function() { |
| 51 cr.ui.DropDown.setActive('offline-networks-list', false); | 50 cr.ui.DropDown.setActive('offline-networks-list', false); |
| 52 }, | 51 }, |
| 53 | 52 |
| 53 update: function() { |
| 54 chrome.send('loginRequestNetworkState', |
| 55 ['login.OfflineMessageScreen.updateState']); |
| 56 }, |
| 57 |
| 54 /** | 58 /** |
| 55 * Shows or hides offline message based on network on/offline state. | 59 * Shows or hides offline message based on network on/offline state. |
| 56 */ | 60 */ |
| 57 update: function() { | 61 updateState: function(state) { |
| 58 var currentScreen = Oobe.getInstance().currentScreen; | 62 var currentScreen = Oobe.getInstance().currentScreen; |
| 59 var offlineMessage = this; | 63 var offlineMessage = this; |
| 60 var isOffline = !window.navigator.onLine; | 64 var isOnline = state == 1; |
| 65 var isUnderCaptivePortal = state == 2; |
| 61 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; | 66 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; |
| 62 | 67 |
| 63 if (isOffline && shouldOverlay) { | 68 if (!isOnline && shouldOverlay) { |
| 64 offlineMessage.onBeforeShow(); | 69 offlineMessage.onBeforeShow(); |
| 65 | 70 |
| 66 $('offline-message-text').hidden = false; | 71 $('offline-message-text').hidden = isUnderCaptivePortal; |
| 67 $('captive-portal-message-text').hidden = true; | 72 $('captive-portal-message-text').hidden = !isUnderCaptivePortal; |
| 68 | 73 |
| 69 offlineMessage.classList.remove('hidden'); | 74 offlineMessage.classList.remove('hidden'); |
| 70 offlineMessage.classList.remove('faded'); | 75 offlineMessage.classList.remove('faded'); |
| 71 | 76 |
| 72 if (!currentScreen.classList.contains('faded')) { | 77 if (!currentScreen.classList.contains('faded')) { |
| 73 currentScreen.classList.add('faded'); | 78 currentScreen.classList.add('faded'); |
| 74 currentScreen.addEventListener('webkitTransitionEnd', | 79 currentScreen.addEventListener('webkitTransitionEnd', |
| 75 function f(e) { | 80 function f(e) { |
| 76 currentScreen.removeEventListener('webkitTransitionEnd', f); | 81 currentScreen.removeEventListener('webkitTransitionEnd', f); |
| 77 if (currentScreen.classList.contains('faded')) | 82 if (currentScreen.classList.contains('faded')) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 offlineMessage.removeEventListener('webkitTransitionEnd', f); | 93 offlineMessage.removeEventListener('webkitTransitionEnd', f); |
| 89 if (offlineMessage.classList.contains('faded')) | 94 if (offlineMessage.classList.contains('faded')) |
| 90 offlineMessage.classList.add('hidden'); | 95 offlineMessage.classList.add('hidden'); |
| 91 }); | 96 }); |
| 92 | 97 |
| 93 currentScreen.classList.remove('hidden'); | 98 currentScreen.classList.remove('hidden'); |
| 94 currentScreen.classList.remove('faded'); | 99 currentScreen.classList.remove('faded'); |
| 95 } | 100 } |
| 96 } | 101 } |
| 97 }, | 102 }, |
| 98 | |
| 99 /** | |
| 100 * Handler of online/offline event. | |
| 101 */ | |
| 102 handleNetworkStateChange_: function() { | |
| 103 this.update(); | |
| 104 } | |
| 105 }; | 103 }; |
| 106 | 104 |
| 107 /** | 105 /** |
| 106 * Network state changed callback. |
| 107 * @param {Integer} state Current state of the network: 0 - offline; |
| 108 * 1 - online; 2 - under the captive portal. |
| 109 */ |
| 110 OfflineMessageScreen.updateState = function(state) { |
| 111 $('offline-message').updateState(state); |
| 112 }; |
| 113 |
| 114 /** |
| 108 * Handler for iframe's error notification coming from the outside. | 115 * Handler for iframe's error notification coming from the outside. |
| 109 * For more info see C++ class 'SnifferObserver' which calls this method. | 116 * For more info see C++ class 'SnifferObserver' which calls this method. |
| 110 * @param {number} error Error code. | 117 * @param {number} error Error code. |
| 111 */ | 118 */ |
| 112 OfflineMessageScreen.onFrameError = function(error) { | 119 OfflineMessageScreen.onFrameError = function(error) { |
| 113 var currentScreen = Oobe.getInstance().currentScreen; | 120 // Offline and simple captive portal cases are handled by the |
| 114 var offlineMessage = $('offline-message'); | 121 // NetworkStateInformer, so only the case when browser is online is |
| 115 var isOffline = !window.navigator.onLine; | 122 // valuable. |
| 116 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; | 123 if (window.navigator.onLine) |
| 117 | 124 this.updateState(2); |
| 118 if (!shouldOverlay) | |
| 119 return; | |
| 120 | |
| 121 if (!isOffline) { | |
| 122 $('offline-message-text').hidden = true; | |
| 123 $('captive-portal-message-text').hidden = false; | |
| 124 } | |
| 125 | |
| 126 if (!currentScreen.classList.contains('faded')) { | |
| 127 offlineMessage.onBeforeShow(); | |
| 128 | |
| 129 offlineMessage.classList.remove('hidden'); | |
| 130 offlineMessage.classList.remove('faded'); | |
| 131 | |
| 132 currentScreen.classList.add('faded'); | |
| 133 currentScreen.addEventListener('webkitTransitionEnd', | |
| 134 function f(e) { | |
| 135 currentScreen.removeEventListener('webkitTransitionEnd', f); | |
| 136 if (currentScreen.classList.contains('faded')) | |
| 137 currentScreen.classList.add('hidden'); | |
| 138 }); | |
| 139 } | |
| 140 }; | 125 }; |
| 141 | 126 |
| 142 return { | 127 return { |
| 143 OfflineMessageScreen: OfflineMessageScreen | 128 OfflineMessageScreen: OfflineMessageScreen |
| 144 }; | 129 }; |
| 145 }); | 130 }); |
| OLD | NEW |