| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 Polymer element for displaying the network state for a specific | 6 * @fileoverview Polymer element for displaying the network state for a specific |
| 7 * type and a list of networks for that type. | 7 * type and a list of networks for that type. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** @typedef {chrome.networkingPrivate.DeviceStateProperties} */ | |
| 11 var DeviceStateProperties; | |
| 12 | |
| 13 Polymer({ | 10 Polymer({ |
| 14 is: 'network-summary-item', | 11 is: 'network-summary-item', |
| 15 | 12 |
| 16 behaviors: [CrPolicyNetworkBehavior, I18nBehavior], | 13 behaviors: [CrPolicyNetworkBehavior, I18nBehavior], |
| 17 | 14 |
| 18 properties: { | 15 properties: { |
| 19 /** | 16 /** |
| 20 * Device state for the network type. | 17 * Device state for the network type. This might briefly be undefined if a |
| 21 * @type {!DeviceStateProperties|undefined} | 18 * device becomes unavailable. |
| 19 * @type {!CrOnc.DeviceStateProperties|undefined} |
| 22 */ | 20 */ |
| 23 deviceState: Object, | 21 deviceState: Object, |
| 24 | 22 |
| 25 /** | 23 /** |
| 26 * Network state for the active network. | 24 * Network state for the active network. |
| 27 * @type {!CrOnc.NetworkStateProperties|undefined} | 25 * @type {!CrOnc.NetworkStateProperties|undefined} |
| 28 */ | 26 */ |
| 29 activeNetworkState: Object, | 27 activeNetworkState: Object, |
| 30 | 28 |
| 31 /** | 29 /** |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 | 46 |
| 49 /** | 47 /** |
| 50 * @return {string} | 48 * @return {string} |
| 51 * @private | 49 * @private |
| 52 */ | 50 */ |
| 53 getNetworkName_: function() { | 51 getNetworkName_: function() { |
| 54 return CrOncStrings['OncType' + this.activeNetworkState.Type]; | 52 return CrOncStrings['OncType' + this.activeNetworkState.Type]; |
| 55 }, | 53 }, |
| 56 | 54 |
| 57 /** | 55 /** |
| 56 * @param {!CrOnc.NetworkStateProperties} activeNetworkState |
| 57 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 58 * @return {string} | 58 * @return {string} |
| 59 * @private | 59 * @private |
| 60 */ | 60 */ |
| 61 getNetworkStateText_: function() { | 61 getNetworkStateText_: function(activeNetworkState, deviceState) { |
| 62 var network = this.activeNetworkState; | 62 var state = activeNetworkState.ConnectionState; |
| 63 var state = network.ConnectionState; | 63 var name = CrOnc.getNetworkName(activeNetworkState); |
| 64 var name = CrOnc.getNetworkName(network); | |
| 65 if (state) | 64 if (state) |
| 66 return this.getConnectionStateText_(state, name); | 65 return this.getConnectionStateText_(state, name); |
| 67 var deviceState = this.deviceState; | |
| 68 if (deviceState) { | 66 if (deviceState) { |
| 69 if (deviceState.State == | 67 if (deviceState.State == CrOnc.DeviceState.ENABLING) |
| 70 chrome.networkingPrivate.DeviceStateType.ENABLING) { | |
| 71 return this.i18n('internetDeviceEnabling'); | 68 return this.i18n('internetDeviceEnabling'); |
| 72 } | 69 if (deviceState.Type == CrOnc.Type.CELLULAR && this.deviceState.Scanning) |
| 73 if (deviceState.Type == CrOnc.Type.CELLULAR && | |
| 74 this.deviceState.Scanning) { | |
| 75 return this.i18n('internetMobileSearching'); | 70 return this.i18n('internetMobileSearching'); |
| 76 } | 71 if (deviceState.State == CrOnc.DeviceState.ENABLED) |
| 77 if (deviceState.State == chrome.networkingPrivate.DeviceStateType.ENABLED) | |
| 78 return CrOncStrings.networkListItemNotConnected; | 72 return CrOncStrings.networkListItemNotConnected; |
| 79 } | 73 } |
| 80 return this.i18n('deviceOff'); | 74 return this.i18n('deviceOff'); |
| 81 }, | 75 }, |
| 82 | 76 |
| 83 /** | 77 /** |
| 84 * @param {CrOnc.ConnectionState} state | 78 * @param {CrOnc.ConnectionState} state |
| 85 * @param {string} name | 79 * @param {string} name |
| 86 * @return {string} | 80 * @return {string} |
| 87 * @private | 81 * @private |
| 88 */ | 82 */ |
| 89 getConnectionStateText_: function(state, name) { | 83 getConnectionStateText_: function(state, name) { |
| 90 switch (state) { | 84 switch (state) { |
| 91 case CrOnc.ConnectionState.CONNECTED: | 85 case CrOnc.ConnectionState.CONNECTED: |
| 92 return name; | 86 return name; |
| 93 case CrOnc.ConnectionState.CONNECTING: | 87 case CrOnc.ConnectionState.CONNECTING: |
| 94 if (name) | 88 if (name) |
| 95 return CrOncStrings.networkListItemConnectingTo.replace('$1', name); | 89 return CrOncStrings.networkListItemConnectingTo.replace('$1', name); |
| 96 return CrOncStrings.networkListItemConnecting; | 90 return CrOncStrings.networkListItemConnecting; |
| 97 case CrOnc.ConnectionState.NOT_CONNECTED: | 91 case CrOnc.ConnectionState.NOT_CONNECTED: |
| 98 return CrOncStrings.networkListItemNotConnected; | 92 return CrOncStrings.networkListItemNotConnected; |
| 99 } | 93 } |
| 100 assertNotReached(); | 94 assertNotReached(); |
| 101 return state; | 95 return state; |
| 102 }, | 96 }, |
| 103 | 97 |
| 104 /** | 98 /** |
| 99 * @param {!CrOnc.NetworkStateProperties} activeNetworkState |
| 105 * @return {boolean} | 100 * @return {boolean} |
| 106 * @private | 101 * @private |
| 107 */ | 102 */ |
| 108 showPolicyIndicator_: function() { | 103 showPolicyIndicator_: function(activeNetworkState) { |
| 109 var network = this.activeNetworkState; | 104 return activeNetworkState.ConnectionState == |
| 110 return network.ConnectionState == CrOnc.ConnectionState.CONNECTED || | 105 CrOnc.ConnectionState.CONNECTED || |
| 111 this.isPolicySource(network.Source); | 106 this.isPolicySource(activeNetworkState.Source); |
| 112 }, | 107 }, |
| 113 | 108 |
| 114 /** | 109 /** |
| 115 * Show the <network-siminfo> element if this is a disabled and locked | 110 * Show the <network-siminfo> element if this is a disabled and locked |
| 116 * cellular device. | 111 * cellular device. |
| 112 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 117 * @return {boolean} | 113 * @return {boolean} |
| 118 * @private | 114 * @private |
| 119 */ | 115 */ |
| 120 showSimInfo_: function() { | 116 showSimInfo_: function(deviceState) { |
| 121 var device = this.deviceState; | 117 if (!deviceState || deviceState.Type != CrOnc.Type.CELLULAR || |
| 122 if (device.Type != CrOnc.Type.CELLULAR || | 118 this.deviceIsEnabled_(deviceState)) { |
| 123 this.deviceIsEnabled_(this.deviceState)) { | |
| 124 return false; | 119 return false; |
| 125 } | 120 } |
| 126 return device.SimPresent === false || | 121 return deviceState.SimPresent === false || |
| 127 device.SimLockType == CrOnc.LockType.PIN || | 122 deviceState.SimLockType == CrOnc.LockType.PIN || |
| 128 device.SimLockType == CrOnc.LockType.PUK; | 123 deviceState.SimLockType == CrOnc.LockType.PUK; |
| 129 }, | 124 }, |
| 130 | 125 |
| 131 /** | 126 /** |
| 132 * Returns a NetworkProperties object for <network-siminfo> built from | 127 * Returns a NetworkProperties object for <network-siminfo> built from |
| 133 * the device properties (since there will be no active network). | 128 * the device properties (since there will be no active network). |
| 134 * @param {!DeviceStateProperties} deviceState | 129 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 135 * @return {!CrOnc.NetworkProperties} | 130 * @return {!CrOnc.NetworkProperties|undefined} |
| 136 * @private | 131 * @private |
| 137 */ | 132 */ |
| 138 getCellularState_: function(deviceState) { | 133 getCellularState_: function(deviceState) { |
| 134 if (!deviceState) |
| 135 return undefined; |
| 139 return { | 136 return { |
| 140 GUID: '', | 137 GUID: '', |
| 141 Type: CrOnc.Type.CELLULAR, | 138 Type: CrOnc.Type.CELLULAR, |
| 142 Cellular: { | 139 Cellular: { |
| 143 SIMLockStatus: { | 140 SIMLockStatus: { |
| 144 LockType: deviceState.SimLockType || '', | 141 LockType: deviceState.SimLockType || '', |
| 145 LockEnabled: deviceState.SimLockType != CrOnc.LockType.NONE, | 142 LockEnabled: deviceState.SimLockType != CrOnc.LockType.NONE, |
| 146 }, | 143 }, |
| 147 SIMPresent: deviceState.SimPresent, | 144 SIMPresent: deviceState.SimPresent, |
| 148 }, | 145 }, |
| 149 }; | 146 }; |
| 150 }, | 147 }, |
| 151 | 148 |
| 152 /** | 149 /** |
| 153 * @param {!DeviceStateProperties|undefined} deviceState | 150 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 154 * @return {boolean} Whether or not the device state is enabled. | 151 * @return {boolean} Whether or not the device state is enabled. |
| 155 * @private | 152 * @private |
| 156 */ | 153 */ |
| 157 deviceIsEnabled_: function(deviceState) { | 154 deviceIsEnabled_: function(deviceState) { |
| 158 return !!deviceState && | 155 return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED; |
| 159 deviceState.State == chrome.networkingPrivate.DeviceStateType.ENABLED; | |
| 160 }, | 156 }, |
| 161 | 157 |
| 162 /** | 158 /** |
| 163 * @param {!DeviceStateProperties} deviceState | 159 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 164 * @return {boolean} | 160 * @return {boolean} |
| 165 * @private | 161 * @private |
| 166 */ | 162 */ |
| 167 enableToggleIsVisible_: function(deviceState) { | 163 enableToggleIsVisible_: function(deviceState) { |
| 168 return deviceState.Type != CrOnc.Type.ETHERNET && | 164 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && |
| 169 deviceState.Type != CrOnc.Type.VPN; | 165 deviceState.Type != CrOnc.Type.VPN; |
| 170 }, | 166 }, |
| 171 | 167 |
| 172 /** | 168 /** |
| 173 * @param {!DeviceStateProperties} deviceState | 169 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 174 * @return {boolean} | 170 * @return {boolean} |
| 175 * @private | 171 * @private |
| 176 */ | 172 */ |
| 177 enableToggleIsEnabled_: function(deviceState) { | 173 enableToggleIsEnabled_: function(deviceState) { |
| 178 return deviceState.State != | 174 return !!deviceState && deviceState.State != CrOnc.DeviceState.PROHIBITED; |
| 179 chrome.networkingPrivate.DeviceStateType.PROHIBITED; | |
| 180 }, | 175 }, |
| 181 | 176 |
| 182 /** | 177 /** |
| 183 * @param {!DeviceStateProperties} deviceState | 178 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 184 * @return {string} | 179 * @return {string} |
| 185 * @private | 180 * @private |
| 186 */ | 181 */ |
| 187 getToggleA11yString_: function(deviceState) { | 182 getToggleA11yString_: function(deviceState) { |
| 188 if (!this.enableToggleIsVisible_(deviceState)) | 183 if (!this.enableToggleIsVisible_(deviceState)) |
| 189 return ''; | 184 return ''; |
| 190 switch (deviceState.Type) { | 185 switch (deviceState.Type) { |
| 191 case CrOnc.Type.TETHER: | 186 case CrOnc.Type.TETHER: |
| 192 return this.i18n('internetToggleTetherA11yLabel'); | 187 return this.i18n('internetToggleTetherA11yLabel'); |
| 193 case CrOnc.Type.CELLULAR: | 188 case CrOnc.Type.CELLULAR: |
| 194 return this.i18n('internetToggleMobileA11yLabel'); | 189 return this.i18n('internetToggleMobileA11yLabel'); |
| 195 case CrOnc.Type.WI_FI: | 190 case CrOnc.Type.WI_FI: |
| 196 return this.i18n('internetToggleWiFiA11yLabel'); | 191 return this.i18n('internetToggleWiFiA11yLabel'); |
| 197 case CrOnc.Type.WI_MAX: | 192 case CrOnc.Type.WI_MAX: |
| 198 return this.i18n('internetToggleWiMAXA11yLabel'); | 193 return this.i18n('internetToggleWiMAXA11yLabel'); |
| 199 } | 194 } |
| 200 assertNotReached(); | 195 assertNotReached(); |
| 201 return ''; | 196 return ''; |
| 202 }, | 197 }, |
| 203 | 198 |
| 204 /** | 199 /** |
| 200 * @param {!CrOnc.NetworkStateProperties} activeNetworkState |
| 201 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 202 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 205 * @return {boolean} | 203 * @return {boolean} |
| 206 * @private | 204 * @private |
| 207 */ | 205 */ |
| 208 showDetailsIsVisible_: function() { | 206 showDetailsIsVisible_: function( |
| 209 return this.deviceIsEnabled_(this.deviceState) && | 207 activeNetworkState, deviceState, networkStateList) { |
| 210 (!!this.activeNetworkState.GUID || this.networkStateList.length > 0); | 208 return this.deviceIsEnabled_(deviceState) && |
| 209 (!!activeNetworkState.GUID || networkStateList.length > 0); |
| 211 }, | 210 }, |
| 212 | 211 |
| 213 /** | 212 /** |
| 213 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 214 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 214 * @return {boolean} | 215 * @return {boolean} |
| 215 * @private | 216 * @private |
| 216 */ | 217 */ |
| 217 shouldShowList_: function() { | 218 shouldShowSubpage_: function(deviceState, networkStateList) { |
| 218 var minlen = (this.deviceState.Type == CrOnc.Type.WI_FI || | 219 if (!deviceState) |
| 219 this.deviceState.Type == CrOnc.Type.VPN || | 220 return false; |
| 220 this.deviceState.Type == CrOnc.Type.TETHER) ? | 221 var type = deviceState.Type; |
| 222 var minlen = (deviceState.Type == CrOnc.Type.WI_FI || |
| 223 deviceState.Type == CrOnc.Type.VPN || |
| 224 deviceState.Type == CrOnc.Type.TETHER) ? |
| 221 1 : | 225 1 : |
| 222 2; | 226 2; |
| 223 return this.networkStateList.length >= minlen; | 227 return networkStateList.length >= minlen; |
| 224 }, | 228 }, |
| 225 | 229 |
| 226 /** | 230 /** |
| 227 * @param {!Event} event The enable button event. | 231 * @param {!Event} event The enable button event. |
| 228 * @private | 232 * @private |
| 229 */ | 233 */ |
| 230 onShowDetailsTap_: function(event) { | 234 onShowDetailsTap_: function(event) { |
| 231 if (!this.deviceIsEnabled_(this.deviceState)) { | 235 if (!this.deviceIsEnabled_(this.deviceState)) { |
| 232 this.fire( | 236 this.fire( |
| 233 'device-enabled-toggled', | 237 'device-enabled-toggled', |
| 234 {enabled: true, type: this.deviceState.Type}); | 238 {enabled: true, type: this.deviceState.Type}); |
| 235 } else if (this.shouldShowList_()) { | 239 } else if (this.shouldShowSubpage_( |
| 240 this.deviceState, this.networkStateList)) { |
| 236 this.fire('show-networks', this.deviceState); | 241 this.fire('show-networks', this.deviceState); |
| 237 } else if (this.activeNetworkState.GUID) { | 242 } else if (this.activeNetworkState.GUID) { |
| 238 this.fire('show-detail', this.activeNetworkState); | 243 this.fire('show-detail', this.activeNetworkState); |
| 239 } else if (this.networkStateList.length > 0) { | 244 } else if (this.networkStateList.length > 0) { |
| 240 this.fire('show-detail', this.networkStateList[0]); | 245 this.fire('show-detail', this.networkStateList[0]); |
| 241 } | 246 } |
| 242 event.stopPropagation(); | 247 event.stopPropagation(); |
| 243 }, | 248 }, |
| 244 | 249 |
| 245 /** | 250 /** |
| 251 * @param {!CrOnc.NetworkStateProperties} activeNetworkState |
| 252 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 253 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 246 * @return {string} | 254 * @return {string} |
| 247 * @private | 255 * @private |
| 248 */ | 256 */ |
| 249 getDetailsA11yString_: function() { | 257 getDetailsA11yString_: function( |
| 250 if (!this.shouldShowList_()) { | 258 activeNetworkState, deviceState, networkStateList) { |
| 251 if (this.activeNetworkState.GUID) { | 259 if (!this.shouldShowSubpage_(deviceState, networkStateList)) { |
| 252 return CrOnc.getNetworkName(this.activeNetworkState); | 260 if (activeNetworkState.GUID) { |
| 253 } else if (this.networkStateList.length > 0) { | 261 return CrOnc.getNetworkName(activeNetworkState); |
| 254 return CrOnc.getNetworkName(this.networkStateList[0]); | 262 } else if (networkStateList.length > 0) { |
| 263 return CrOnc.getNetworkName(networkStateList[0]); |
| 255 } | 264 } |
| 256 } | 265 } |
| 257 return this.i18n('OncType' + this.deviceState.Type); | 266 return this.i18n('OncType' + deviceState.Type); |
| 258 }, | 267 }, |
| 259 | 268 |
| 260 /** | 269 /** |
| 261 * Event triggered when the enable button is toggled. | 270 * Event triggered when the enable button is toggled. |
| 262 * @param {!Event} event | 271 * @param {!Event} event |
| 263 * @private | 272 * @private |
| 264 */ | 273 */ |
| 265 onDeviceEnabledTap_: function(event) { | 274 onDeviceEnabledTap_: function(event) { |
| 266 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 275 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); |
| 267 var type = this.deviceState ? this.deviceState.Type : ''; | 276 var type = this.deviceState ? this.deviceState.Type : ''; |
| 268 this.fire( | 277 this.fire( |
| 269 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 278 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
| 270 // Make sure this does not propagate to onDetailsTap_. | 279 // Make sure this does not propagate to onDetailsTap_. |
| 271 event.stopPropagation(); | 280 event.stopPropagation(); |
| 272 }, | 281 }, |
| 273 }); | 282 }); |
| OLD | NEW |