Chromium Code Reviews| 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. |
| 11 const MANAGED_SCREENS = ['gaia-signin', 'signin']; | 11 const MANAGED_SCREENS = ['gaia-signin']; |
| 12 | |
| 13 // Network state constants. | |
| 14 const NET_STATE = { | |
| 15 OFFLINE: 0, | |
| 16 ONLINE: 1, | |
| 17 PORTAL: 2 | |
| 18 }; | |
| 12 | 19 |
| 13 /** | 20 /** |
| 14 * Creates a new offline message screen div. | 21 * Creates a new offline message screen div. |
| 15 * @constructor | 22 * @constructor |
| 16 * @extends {HTMLDivElement} | 23 * @extends {HTMLDivElement} |
| 17 */ | 24 */ |
| 18 var OfflineMessageScreen = cr.ui.define('div'); | 25 var OfflineMessageScreen = cr.ui.define('div'); |
| 19 | 26 |
| 20 /** | 27 /** |
| 21 * Registers with Oobe. | 28 * Registers with Oobe. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 chrome.send('loginRequestNetworkState', | 61 chrome.send('loginRequestNetworkState', |
| 55 ['login.OfflineMessageScreen.updateState']); | 62 ['login.OfflineMessageScreen.updateState']); |
| 56 }, | 63 }, |
| 57 | 64 |
| 58 /** | 65 /** |
| 59 * Shows or hides offline message based on network on/offline state. | 66 * Shows or hides offline message based on network on/offline state. |
| 60 */ | 67 */ |
| 61 updateState: function(state) { | 68 updateState: function(state) { |
| 62 var currentScreen = Oobe.getInstance().currentScreen; | 69 var currentScreen = Oobe.getInstance().currentScreen; |
| 63 var offlineMessage = this; | 70 var offlineMessage = this; |
| 64 var isOnline = state == 1; | 71 var isOnline = state == NET_STATE.ONLINE; |
|
zel
2011/09/27 22:36:47
nit: put brackets around this expression
xiyuan
2011/09/27 22:42:25
Done.
| |
| 65 var isUnderCaptivePortal = state == 2; | 72 var isUnderCaptivePortal = state == NET_STATE.PORTAL; |
|
zel
2011/09/27 22:36:47
same
xiyuan
2011/09/27 22:42:25
Done.
| |
| 66 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; | 73 var shouldOverlay = MANAGED_SCREENS.indexOf(currentScreen.id) != -1; |
| 67 | 74 |
| 68 if (!isOnline && shouldOverlay) { | 75 if (!isOnline && shouldOverlay) { |
| 76 console.log('Show offline message, state=' + state + | |
| 77 ',isUnderCaptivePortal=' + isUnderCaptivePortal); | |
| 69 offlineMessage.onBeforeShow(); | 78 offlineMessage.onBeforeShow(); |
| 70 | 79 |
| 71 $('offline-message-text').hidden = isUnderCaptivePortal; | 80 $('offline-message-text').hidden = isUnderCaptivePortal; |
| 72 $('captive-portal-message-text').hidden = !isUnderCaptivePortal; | 81 $('captive-portal-message-text').hidden = !isUnderCaptivePortal; |
| 73 | 82 |
| 74 offlineMessage.classList.remove('hidden'); | 83 offlineMessage.classList.remove('hidden'); |
| 75 offlineMessage.classList.remove('faded'); | 84 offlineMessage.classList.remove('faded'); |
| 76 | 85 |
| 77 if (!currentScreen.classList.contains('faded')) { | 86 if (!currentScreen.classList.contains('faded')) { |
| 78 currentScreen.classList.add('faded'); | 87 currentScreen.classList.add('faded'); |
| 79 currentScreen.addEventListener('webkitTransitionEnd', | 88 currentScreen.addEventListener('webkitTransitionEnd', |
| 80 function f(e) { | 89 function f(e) { |
| 81 currentScreen.removeEventListener('webkitTransitionEnd', f); | 90 currentScreen.removeEventListener('webkitTransitionEnd', f); |
| 82 if (currentScreen.classList.contains('faded')) | 91 if (currentScreen.classList.contains('faded')) |
| 83 currentScreen.classList.add('hidden'); | 92 currentScreen.classList.add('hidden'); |
| 84 }); | 93 }); |
| 85 } | 94 } |
| 86 } else { | 95 } else { |
| 87 if (!offlineMessage.classList.contains('faded')) { | 96 if (!offlineMessage.classList.contains('faded')) { |
| 97 console.log('Hide offline message.'); | |
| 88 offlineMessage.onBeforeHide(); | 98 offlineMessage.onBeforeHide(); |
| 89 | 99 |
| 90 offlineMessage.classList.add('faded'); | 100 offlineMessage.classList.add('faded'); |
| 91 offlineMessage.addEventListener('webkitTransitionEnd', | 101 offlineMessage.addEventListener('webkitTransitionEnd', |
| 92 function f(e) { | 102 function f(e) { |
| 93 offlineMessage.removeEventListener('webkitTransitionEnd', f); | 103 offlineMessage.removeEventListener('webkitTransitionEnd', f); |
| 94 if (offlineMessage.classList.contains('faded')) | 104 if (offlineMessage.classList.contains('faded')) |
| 95 offlineMessage.classList.add('hidden'); | 105 offlineMessage.classList.add('hidden'); |
| 96 }); | 106 }); |
| 97 | 107 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 110 OfflineMessageScreen.updateState = function(state) { | 120 OfflineMessageScreen.updateState = function(state) { |
| 111 $('offline-message').updateState(state); | 121 $('offline-message').updateState(state); |
| 112 }; | 122 }; |
| 113 | 123 |
| 114 /** | 124 /** |
| 115 * Handler for iframe's error notification coming from the outside. | 125 * Handler for iframe's error notification coming from the outside. |
| 116 * For more info see C++ class 'SnifferObserver' which calls this method. | 126 * For more info see C++ class 'SnifferObserver' which calls this method. |
| 117 * @param {number} error Error code. | 127 * @param {number} error Error code. |
| 118 */ | 128 */ |
| 119 OfflineMessageScreen.onFrameError = function(error) { | 129 OfflineMessageScreen.onFrameError = function(error) { |
| 130 console.log('Gaia frame error = ' + error); | |
| 131 | |
| 120 // Offline and simple captive portal cases are handled by the | 132 // Offline and simple captive portal cases are handled by the |
| 121 // NetworkStateInformer, so only the case when browser is online is | 133 // NetworkStateInformer, so only the case when browser is online is |
| 122 // valuable. | 134 // valuable. |
| 123 if (window.navigator.onLine) | 135 if (window.navigator.onLine) { |
| 124 this.updateState(2); | 136 this.updateState(NET_STATE.PORTAL); |
| 137 | |
| 138 // Check current network state if currentScreen is a managed one. | |
| 139 var currentScreen = Oobe.getInstance().currentScreen; | |
| 140 if (MANAGED_SCREENS.indexOf(currentScreen.id) != -1) { | |
| 141 chrome.send('loginRequestNetworkState', | |
| 142 ['login.OfflineMessageScreen.maybeRetry']); | |
| 143 } | |
| 144 } | |
| 145 }; | |
| 146 | |
| 147 /** | |
| 148 * Network state callback where we decide whether to schdule a retry. | |
| 149 */ | |
| 150 OfflineMessageScreen.maybeRetry = function(state) { | |
| 151 console.log('OfflineMessageScreen.maybeRetry, state=' + state); | |
| 152 | |
| 153 // No retry if we are not online. | |
| 154 if (state != NET_STATE.ONLINE) | |
| 155 return; | |
| 156 | |
| 157 var currentScreen = Oobe.getInstance().currentScreen; | |
| 158 if (MANAGED_SCREENS.indexOf(currentScreen.id) != -1) { | |
| 159 // Schedules a retry. | |
| 160 currentScreen.schdeduleRetry(); | |
| 161 } | |
| 125 }; | 162 }; |
| 126 | 163 |
| 127 return { | 164 return { |
| 128 OfflineMessageScreen: OfflineMessageScreen | 165 OfflineMessageScreen: OfflineMessageScreen |
| 129 }; | 166 }; |
| 130 }); | 167 }); |
| OLD | NEW |