Chromium Code Reviews| 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. NOTE: It both Cellular and Tether |
| 8 * technologies are available, they are combined into a single 'Mobile data' | |
| 9 * section. See crbug.com/726380. | |
| 8 */ | 10 */ |
| 9 | 11 |
| 10 Polymer({ | 12 Polymer({ |
| 11 is: 'network-summary-item', | 13 is: 'network-summary-item', |
| 12 | 14 |
| 13 behaviors: [CrPolicyNetworkBehavior, I18nBehavior], | 15 behaviors: [CrPolicyNetworkBehavior, I18nBehavior], |
| 14 | 16 |
| 15 properties: { | 17 properties: { |
| 16 /** | 18 /** |
| 17 * Device state for the network type. This might briefly be undefined if a | 19 * Device state for the network type. This might briefly be undefined if a |
| 18 * device becomes unavailable. | 20 * device becomes unavailable. |
| 19 * @type {!CrOnc.DeviceStateProperties|undefined} | 21 * @type {!CrOnc.DeviceStateProperties|undefined} |
| 20 */ | 22 */ |
| 21 deviceState: Object, | 23 deviceState: Object, |
| 22 | 24 |
| 23 /** | 25 /** |
| 26 * If both Cellular and Tether technologies exist, we combine the sections | |
| 27 * and set this to the device state for Tether. | |
| 28 * @type {!CrOnc.DeviceStateProperties|undefined} | |
| 29 */ | |
| 30 tetherDeviceState: Object, | |
| 31 | |
| 32 /** | |
| 24 * Network state for the active network. | 33 * Network state for the active network. |
| 25 * @type {!CrOnc.NetworkStateProperties|undefined} | 34 * @type {!CrOnc.NetworkStateProperties|undefined} |
| 26 */ | 35 */ |
| 27 activeNetworkState: Object, | 36 activeNetworkState: Object, |
| 28 | 37 |
| 29 /** | 38 /** |
| 30 * List of all network state data for the network type. | 39 * List of all network state data for the network type. |
| 31 * @type {!Array<!CrOnc.NetworkStateProperties>} | 40 * @type {!Array<!CrOnc.NetworkStateProperties>} |
| 32 */ | 41 */ |
| 33 networkStateList: { | 42 networkStateList: { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED; | 164 return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED; |
| 156 }, | 165 }, |
| 157 | 166 |
| 158 /** | 167 /** |
| 159 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 168 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 160 * @return {boolean} | 169 * @return {boolean} |
| 161 * @private | 170 * @private |
| 162 */ | 171 */ |
| 163 enableToggleIsVisible_: function(deviceState) { | 172 enableToggleIsVisible_: function(deviceState) { |
| 164 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && | 173 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && |
| 165 deviceState.Type != CrOnc.Type.VPN; | 174 deviceState.Type != CrOnc.Type.VPN && |
| 175 deviceState.State != CrOnc.DeviceState.UNINITIALIZED; | |
|
Kyle Horimoto
2017/06/01 20:15:21
If Type == CELLULAR and neither Cellular or Tether
stevenjb
2017/06/01 21:55:03
Enable/Disable is separate for networks existing,
| |
| 166 }, | 176 }, |
| 167 | 177 |
| 168 /** | 178 /** |
| 169 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 179 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 170 * @return {boolean} | 180 * @return {boolean} |
| 171 * @private | 181 * @private |
| 172 */ | 182 */ |
| 173 enableToggleIsEnabled_: function(deviceState) { | 183 enableToggleIsEnabled_: function(deviceState) { |
| 174 return !!deviceState && deviceState.State != CrOnc.DeviceState.PROHIBITED; | 184 return this.enableToggleIsVisible_(deviceState) && |
| 185 deviceState.State != CrOnc.DeviceState.PROHIBITED; | |
| 175 }, | 186 }, |
| 176 | 187 |
| 177 /** | 188 /** |
| 178 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 189 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 179 * @return {string} | 190 * @return {string} |
| 180 * @private | 191 * @private |
| 181 */ | 192 */ |
| 182 getToggleA11yString_: function(deviceState) { | 193 getToggleA11yString_: function(deviceState) { |
| 183 if (!this.enableToggleIsVisible_(deviceState)) | 194 if (!this.enableToggleIsVisible_(deviceState)) |
| 184 return ''; | 195 return ''; |
| 185 switch (deviceState.Type) { | 196 switch (deviceState.Type) { |
| 186 case CrOnc.Type.TETHER: | 197 case CrOnc.Type.TETHER: |
| 187 return this.i18n('internetToggleTetherA11yLabel'); | |
| 188 case CrOnc.Type.CELLULAR: | 198 case CrOnc.Type.CELLULAR: |
| 189 return this.i18n('internetToggleMobileA11yLabel'); | 199 return this.i18n('internetToggleMobileA11yLabel'); |
| 190 case CrOnc.Type.WI_FI: | 200 case CrOnc.Type.WI_FI: |
| 191 return this.i18n('internetToggleWiFiA11yLabel'); | 201 return this.i18n('internetToggleWiFiA11yLabel'); |
| 192 case CrOnc.Type.WI_MAX: | 202 case CrOnc.Type.WI_MAX: |
| 193 return this.i18n('internetToggleWiMAXA11yLabel'); | 203 return this.i18n('internetToggleWiMAXA11yLabel'); |
| 194 } | 204 } |
| 195 assertNotReached(); | 205 assertNotReached(); |
| 196 return ''; | 206 return ''; |
| 197 }, | 207 }, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 212 /** | 222 /** |
| 213 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 223 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 214 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList | 224 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 215 * @return {boolean} | 225 * @return {boolean} |
| 216 * @private | 226 * @private |
| 217 */ | 227 */ |
| 218 shouldShowSubpage_: function(deviceState, networkStateList) { | 228 shouldShowSubpage_: function(deviceState, networkStateList) { |
| 219 if (!deviceState) | 229 if (!deviceState) |
| 220 return false; | 230 return false; |
| 221 var type = deviceState.Type; | 231 var type = deviceState.Type; |
| 222 var minlen = (deviceState.Type == CrOnc.Type.WI_FI || | 232 if (type == CrOnc.Type.CELLULAR && this.tetherDeviceState) |
|
Kyle Horimoto
2017/06/01 20:15:21
nit: Shouldn't this be !!this.tetherDeviceState?
stevenjb
2017/06/01 21:55:03
That's only necessary when you are returning a boo
| |
| 223 deviceState.Type == CrOnc.Type.VPN || | 233 return true; |
| 224 deviceState.Type == CrOnc.Type.TETHER) ? | 234 var minlen = (type == CrOnc.Type.WI_FI || type == CrOnc.Type.VPN || |
| 235 type == CrOnc.Type.TETHER) ? | |
|
Kyle Horimoto
2017/06/01 20:15:21
Isn't it impossible for type to be TETHER now that
stevenjb
2017/06/01 21:55:03
We combine Tether with Cellular *IF* Cellular exis
| |
| 225 1 : | 236 1 : |
| 226 2; | 237 2; |
| 227 return networkStateList.length >= minlen; | 238 return networkStateList.length >= minlen; |
| 228 }, | 239 }, |
| 229 | 240 |
| 230 /** | 241 /** |
| 231 * @param {!Event} event The enable button event. | 242 * @param {!Event} event The enable button event. |
| 232 * @private | 243 * @private |
| 233 */ | 244 */ |
| 234 onShowDetailsTap_: function(event) { | 245 onShowDetailsTap_: function(event) { |
| 235 if (!this.deviceIsEnabled_(this.deviceState)) { | 246 if (!this.deviceIsEnabled_(this.deviceState)) { |
| 236 this.fire( | 247 if (this.enableToggleIsEnabled_(this.deviceState)) { |
| 237 'device-enabled-toggled', | 248 this.fire( |
| 238 {enabled: true, type: this.deviceState.Type}); | 249 'device-enabled-toggled', |
| 250 {enabled: true, type: this.deviceState.Type}); | |
| 251 } | |
| 239 } else if (this.shouldShowSubpage_( | 252 } else if (this.shouldShowSubpage_( |
| 240 this.deviceState, this.networkStateList)) { | 253 this.deviceState, this.networkStateList)) { |
| 241 this.fire('show-networks', this.deviceState); | 254 this.fire('show-networks', this.deviceState); |
| 242 } else if (this.activeNetworkState.GUID) { | 255 } else if (this.activeNetworkState.GUID) { |
| 243 this.fire('show-detail', this.activeNetworkState); | 256 this.fire('show-detail', this.activeNetworkState); |
| 244 } else if (this.networkStateList.length > 0) { | 257 } else if (this.networkStateList.length > 0) { |
| 245 this.fire('show-detail', this.networkStateList[0]); | 258 this.fire('show-detail', this.networkStateList[0]); |
| 246 } | 259 } |
| 247 event.stopPropagation(); | 260 event.stopPropagation(); |
| 248 }, | 261 }, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 273 */ | 286 */ |
| 274 onDeviceEnabledTap_: function(event) { | 287 onDeviceEnabledTap_: function(event) { |
| 275 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 288 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); |
| 276 var type = this.deviceState ? this.deviceState.Type : ''; | 289 var type = this.deviceState ? this.deviceState.Type : ''; |
| 277 this.fire( | 290 this.fire( |
| 278 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 291 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
| 279 // Make sure this does not propagate to onDetailsTap_. | 292 // Make sure this does not propagate to onDetailsTap_. |
| 280 event.stopPropagation(); | 293 event.stopPropagation(); |
| 281 }, | 294 }, |
| 282 }); | 295 }); |
| OLD | NEW |