| 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.Type == CrOnc.Type.TETHER || |
| 176 deviceState.State != CrOnc.DeviceState.UNINITIALIZED); |
| 166 }, | 177 }, |
| 167 | 178 |
| 168 /** | 179 /** |
| 169 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 180 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 170 * @return {boolean} | 181 * @return {boolean} |
| 171 * @private | 182 * @private |
| 172 */ | 183 */ |
| 173 enableToggleIsEnabled_: function(deviceState) { | 184 enableToggleIsEnabled_: function(deviceState) { |
| 174 return !!deviceState && deviceState.State != CrOnc.DeviceState.PROHIBITED; | 185 return this.enableToggleIsVisible_(deviceState) && |
| 186 deviceState.State != CrOnc.DeviceState.PROHIBITED && |
| 187 deviceState.State != CrOnc.DeviceState.UNINITIALIZED; |
| 175 }, | 188 }, |
| 176 | 189 |
| 177 /** | 190 /** |
| 178 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 191 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 179 * @return {string} | 192 * @return {string} |
| 180 * @private | 193 * @private |
| 181 */ | 194 */ |
| 182 getToggleA11yString_: function(deviceState) { | 195 getToggleA11yString_: function(deviceState) { |
| 183 if (!this.enableToggleIsVisible_(deviceState)) | 196 if (!this.enableToggleIsVisible_(deviceState)) |
| 184 return ''; | 197 return ''; |
| 185 switch (deviceState.Type) { | 198 switch (deviceState.Type) { |
| 186 case CrOnc.Type.TETHER: | 199 case CrOnc.Type.TETHER: |
| 187 return this.i18n('internetToggleTetherA11yLabel'); | |
| 188 case CrOnc.Type.CELLULAR: | 200 case CrOnc.Type.CELLULAR: |
| 189 return this.i18n('internetToggleMobileA11yLabel'); | 201 return this.i18n('internetToggleMobileA11yLabel'); |
| 190 case CrOnc.Type.WI_FI: | 202 case CrOnc.Type.WI_FI: |
| 191 return this.i18n('internetToggleWiFiA11yLabel'); | 203 return this.i18n('internetToggleWiFiA11yLabel'); |
| 192 case CrOnc.Type.WI_MAX: | 204 case CrOnc.Type.WI_MAX: |
| 193 return this.i18n('internetToggleWiMAXA11yLabel'); | 205 return this.i18n('internetToggleWiMAXA11yLabel'); |
| 194 } | 206 } |
| 195 assertNotReached(); | 207 assertNotReached(); |
| 196 return ''; | 208 return ''; |
| 197 }, | 209 }, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 212 /** | 224 /** |
| 213 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState | 225 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 214 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList | 226 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 215 * @return {boolean} | 227 * @return {boolean} |
| 216 * @private | 228 * @private |
| 217 */ | 229 */ |
| 218 shouldShowSubpage_: function(deviceState, networkStateList) { | 230 shouldShowSubpage_: function(deviceState, networkStateList) { |
| 219 if (!deviceState) | 231 if (!deviceState) |
| 220 return false; | 232 return false; |
| 221 var type = deviceState.Type; | 233 var type = deviceState.Type; |
| 222 var minlen = (deviceState.Type == CrOnc.Type.WI_FI || | 234 if (type == CrOnc.Type.CELLULAR && this.tetherDeviceState) |
| 223 deviceState.Type == CrOnc.Type.VPN || | 235 return true; |
| 224 deviceState.Type == CrOnc.Type.TETHER) ? | 236 var minlen = (type == CrOnc.Type.WI_FI || type == CrOnc.Type.VPN || |
| 237 type == CrOnc.Type.TETHER) ? |
| 225 1 : | 238 1 : |
| 226 2; | 239 2; |
| 227 return networkStateList.length >= minlen; | 240 return networkStateList.length >= minlen; |
| 228 }, | 241 }, |
| 229 | 242 |
| 230 /** | 243 /** |
| 231 * @param {!Event} event The enable button event. | 244 * @param {!Event} event The enable button event. |
| 232 * @private | 245 * @private |
| 233 */ | 246 */ |
| 234 onShowDetailsTap_: function(event) { | 247 onShowDetailsTap_: function(event) { |
| 235 if (!this.deviceIsEnabled_(this.deviceState)) { | 248 if (!this.deviceIsEnabled_(this.deviceState)) { |
| 236 this.fire( | 249 if (this.enableToggleIsEnabled_(this.deviceState)) { |
| 237 'device-enabled-toggled', | 250 this.fire( |
| 238 {enabled: true, type: this.deviceState.Type}); | 251 'device-enabled-toggled', |
| 252 {enabled: true, type: this.deviceState.Type}); |
| 253 } |
| 239 } else if (this.shouldShowSubpage_( | 254 } else if (this.shouldShowSubpage_( |
| 240 this.deviceState, this.networkStateList)) { | 255 this.deviceState, this.networkStateList)) { |
| 241 this.fire('show-networks', this.deviceState); | 256 this.fire('show-networks', this.deviceState); |
| 242 } else if (this.activeNetworkState.GUID) { | 257 } else if (this.activeNetworkState.GUID) { |
| 243 this.fire('show-detail', this.activeNetworkState); | 258 this.fire('show-detail', this.activeNetworkState); |
| 244 } else if (this.networkStateList.length > 0) { | 259 } else if (this.networkStateList.length > 0) { |
| 245 this.fire('show-detail', this.networkStateList[0]); | 260 this.fire('show-detail', this.networkStateList[0]); |
| 246 } | 261 } |
| 247 event.stopPropagation(); | 262 event.stopPropagation(); |
| 248 }, | 263 }, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 273 */ | 288 */ |
| 274 onDeviceEnabledTap_: function(event) { | 289 onDeviceEnabledTap_: function(event) { |
| 275 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 290 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); |
| 276 var type = this.deviceState ? this.deviceState.Type : ''; | 291 var type = this.deviceState ? this.deviceState.Type : ''; |
| 277 this.fire( | 292 this.fire( |
| 278 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 293 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
| 279 // Make sure this does not propagate to onDetailsTap_. | 294 // Make sure this does not propagate to onDetailsTap_. |
| 280 event.stopPropagation(); | 295 event.stopPropagation(); |
| 281 }, | 296 }, |
| 282 }); | 297 }); |
| OLD | NEW |