| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 */ | 101 */ |
| 108 showPolicyIndicator_: function() { | 102 showPolicyIndicator_: function() { |
| 109 var network = this.activeNetworkState; | 103 var network = this.activeNetworkState; |
| 110 return network.ConnectionState == CrOnc.ConnectionState.CONNECTED || | 104 return network.ConnectionState == CrOnc.ConnectionState.CONNECTED || |
| 111 this.isPolicySource(network.Source); | 105 this.isPolicySource(network.Source); |
| 112 }, | 106 }, |
| 113 | 107 |
| 114 /** | 108 /** |
| 115 * Show the <network-siminfo> element if this is a disabled and locked | 109 * Show the <network-siminfo> element if this is a disabled and locked |
| 116 * cellular device. | 110 * cellular device. |
| 111 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 117 * @return {boolean} | 112 * @return {boolean} |
| 118 * @private | 113 * @private |
| 119 */ | 114 */ |
| 120 showSimInfo_: function() { | 115 showSimInfo_: function(deviceState) { |
| 121 var device = this.deviceState; | 116 if (!deviceState || deviceState.Type != CrOnc.Type.CELLULAR || |
| 122 if (device.Type != CrOnc.Type.CELLULAR || | 117 this.deviceIsEnabled_(deviceState)) { |
| 123 this.deviceIsEnabled_(this.deviceState)) { | |
| 124 return false; | 118 return false; |
| 125 } | 119 } |
| 126 return device.SimPresent === false || | 120 return deviceState.SimPresent === false || |
| 127 device.SimLockType == CrOnc.LockType.PIN || | 121 deviceState.SimLockType == CrOnc.LockType.PIN || |
| 128 device.SimLockType == CrOnc.LockType.PUK; | 122 deviceState.SimLockType == CrOnc.LockType.PUK; |
| 129 }, | 123 }, |
| 130 | 124 |
| 131 /** | 125 /** |
| 132 * Returns a NetworkProperties object for <network-siminfo> built from | 126 * Returns a NetworkProperties object for <network-siminfo> built from |
| 133 * the device properties (since there will be no active network). | 127 * the device properties (since there will be no active network). |
| 134 * @param {!DeviceStateProperties} deviceState | 128 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 135 * @return {!CrOnc.NetworkProperties} | 129 * @return {!CrOnc.NetworkProperties|undefined} |
| 136 * @private | 130 * @private |
| 137 */ | 131 */ |
| 138 getCellularState_: function(deviceState) { | 132 getCellularState_: function(deviceState) { |
| 133 if (!deviceState) |
| 134 return undefined; |
| 139 return { | 135 return { |
| 140 GUID: '', | 136 GUID: '', |
| 141 Type: CrOnc.Type.CELLULAR, | 137 Type: CrOnc.Type.CELLULAR, |
| 142 Cellular: { | 138 Cellular: { |
| 143 SIMLockStatus: { | 139 SIMLockStatus: { |
| 144 LockType: deviceState.SimLockType || '', | 140 LockType: deviceState.SimLockType || '', |
| 145 LockEnabled: deviceState.SimLockType != CrOnc.LockType.NONE, | 141 LockEnabled: deviceState.SimLockType != CrOnc.LockType.NONE, |
| 146 }, | 142 }, |
| 147 SIMPresent: deviceState.SimPresent, | 143 SIMPresent: deviceState.SimPresent, |
| 148 }, | 144 }, |
| 149 }; | 145 }; |
| 150 }, | 146 }, |
| 151 | 147 |
| 152 /** | 148 /** |
| 153 * @param {!DeviceStateProperties|undefined} deviceState | 149 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 154 * @return {boolean} Whether or not the device state is enabled. | 150 * @return {boolean} Whether or not the device state is enabled. |
| 155 * @private | 151 * @private |
| 156 */ | 152 */ |
| 157 deviceIsEnabled_: function(deviceState) { | 153 deviceIsEnabled_: function(deviceState) { |
| 158 return !!deviceState && | 154 return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED; |
| 159 deviceState.State == chrome.networkingPrivate.DeviceStateType.ENABLED; | |
| 160 }, | 155 }, |
| 161 | 156 |
| 162 /** | 157 /** |
| 163 * @param {!DeviceStateProperties} deviceState | 158 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 164 * @return {boolean} | 159 * @return {boolean} |
| 165 * @private | 160 * @private |
| 166 */ | 161 */ |
| 167 enableToggleIsVisible_: function(deviceState) { | 162 enableToggleIsVisible_: function(deviceState) { |
| 168 return deviceState.Type != CrOnc.Type.ETHERNET && | 163 return !!deviceState && deviceState.Type != CrOnc.Type.ETHERNET && |
| 169 deviceState.Type != CrOnc.Type.VPN; | 164 deviceState.Type != CrOnc.Type.VPN; |
| 170 }, | 165 }, |
| 171 | 166 |
| 172 /** | 167 /** |
| 173 * @param {!DeviceStateProperties} deviceState | 168 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 174 * @return {boolean} | 169 * @return {boolean} |
| 175 * @private | 170 * @private |
| 176 */ | 171 */ |
| 177 enableToggleIsEnabled_: function(deviceState) { | 172 enableToggleIsEnabled_: function(deviceState) { |
| 178 return deviceState.State != | 173 return !!deviceState && deviceState.State != CrOnc.DeviceState.PROHIBITED; |
| 179 chrome.networkingPrivate.DeviceStateType.PROHIBITED; | |
| 180 }, | 174 }, |
| 181 | 175 |
| 182 /** | 176 /** |
| 183 * @param {!DeviceStateProperties} deviceState | 177 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 184 * @return {string} | 178 * @return {string} |
| 185 * @private | 179 * @private |
| 186 */ | 180 */ |
| 187 getToggleA11yString_: function(deviceState) { | 181 getToggleA11yString_: function(deviceState) { |
| 188 if (!this.enableToggleIsVisible_(deviceState)) | 182 if (!this.enableToggleIsVisible_(deviceState)) |
| 189 return ''; | 183 return ''; |
| 190 switch (deviceState.Type) { | 184 switch (deviceState.Type) { |
| 191 case CrOnc.Type.TETHER: | 185 case CrOnc.Type.TETHER: |
| 192 return this.i18n('internetToggleTetherA11yLabel'); | 186 return this.i18n('internetToggleTetherA11yLabel'); |
| 193 case CrOnc.Type.CELLULAR: | 187 case CrOnc.Type.CELLULAR: |
| 194 return this.i18n('internetToggleMobileA11yLabel'); | 188 return this.i18n('internetToggleMobileA11yLabel'); |
| 195 case CrOnc.Type.WI_FI: | 189 case CrOnc.Type.WI_FI: |
| 196 return this.i18n('internetToggleWiFiA11yLabel'); | 190 return this.i18n('internetToggleWiFiA11yLabel'); |
| 197 case CrOnc.Type.WI_MAX: | 191 case CrOnc.Type.WI_MAX: |
| 198 return this.i18n('internetToggleWiMAXA11yLabel'); | 192 return this.i18n('internetToggleWiMAXA11yLabel'); |
| 199 } | 193 } |
| 200 assertNotReached(); | 194 assertNotReached(); |
| 201 return ''; | 195 return ''; |
| 202 }, | 196 }, |
| 203 | 197 |
| 204 /** | 198 /** |
| 199 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 205 * @return {boolean} | 200 * @return {boolean} |
| 206 * @private | 201 * @private |
| 207 */ | 202 */ |
| 208 showDetailsIsVisible_: function() { | 203 showDetailsIsVisible_: function(deviceState) { |
| 209 return this.deviceIsEnabled_(this.deviceState) && | 204 return this.deviceIsEnabled_(deviceState) && |
| 210 (!!this.activeNetworkState.GUID || this.networkStateList.length > 0); | 205 (!!this.activeNetworkState.GUID || this.networkStateList.length > 0); |
| 211 }, | 206 }, |
| 212 | 207 |
| 213 /** | 208 /** |
| 209 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 214 * @return {boolean} | 210 * @return {boolean} |
| 215 * @private | 211 * @private |
| 216 */ | 212 */ |
| 217 shouldShowList_: function() { | 213 shouldShowSubpage_: function(deviceState) { |
| 218 var minlen = (this.deviceState.Type == CrOnc.Type.WI_FI || | 214 if (!deviceState) |
| 219 this.deviceState.Type == CrOnc.Type.VPN || | 215 return false; |
| 220 this.deviceState.Type == CrOnc.Type.TETHER) ? | 216 var type = deviceState.Type; |
| 217 var minlen = (deviceState.Type == CrOnc.Type.WI_FI || |
| 218 deviceState.Type == CrOnc.Type.VPN || |
| 219 deviceState.Type == CrOnc.Type.TETHER) ? |
| 221 1 : | 220 1 : |
| 222 2; | 221 2; |
| 223 return this.networkStateList.length >= minlen; | 222 return this.networkStateList.length >= minlen; |
| 224 }, | 223 }, |
| 225 | 224 |
| 226 /** | 225 /** |
| 227 * @param {!Event} event The enable button event. | 226 * @param {!Event} event The enable button event. |
| 228 * @private | 227 * @private |
| 229 */ | 228 */ |
| 230 onShowDetailsTap_: function(event) { | 229 onShowDetailsTap_: function(event) { |
| 231 if (!this.deviceIsEnabled_(this.deviceState)) { | 230 if (!this.deviceIsEnabled_(this.deviceState)) { |
| 232 this.fire( | 231 this.fire( |
| 233 'device-enabled-toggled', | 232 'device-enabled-toggled', |
| 234 {enabled: true, type: this.deviceState.Type}); | 233 {enabled: true, type: this.deviceState.Type}); |
| 235 } else if (this.shouldShowList_()) { | 234 } else if (this.shouldShowSubpage_(this.deviceState)) { |
| 236 this.fire('show-networks', this.deviceState); | 235 this.fire('show-networks', this.deviceState); |
| 237 } else if (this.activeNetworkState.GUID) { | 236 } else if (this.activeNetworkState.GUID) { |
| 238 this.fire('show-detail', this.activeNetworkState); | 237 this.fire('show-detail', this.activeNetworkState); |
| 239 } else if (this.networkStateList.length > 0) { | 238 } else if (this.networkStateList.length > 0) { |
| 240 this.fire('show-detail', this.networkStateList[0]); | 239 this.fire('show-detail', this.networkStateList[0]); |
| 241 } | 240 } |
| 242 event.stopPropagation(); | 241 event.stopPropagation(); |
| 243 }, | 242 }, |
| 244 | 243 |
| 245 /** | 244 /** |
| 245 * @param {!CrOnc.NetworkStateProperties} activeNetworkState |
| 246 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState |
| 247 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStateList |
| 246 * @return {string} | 248 * @return {string} |
| 247 * @private | 249 * @private |
| 248 */ | 250 */ |
| 249 getDetailsA11yString_: function() { | 251 getDetailsA11yString_: function( |
| 250 if (!this.shouldShowList_()) { | 252 activeNetworkState, deviceState, networkStateList) { |
| 253 if (!this.shouldShowSubpage_(deviceState)) { |
| 251 if (this.activeNetworkState.GUID) { | 254 if (this.activeNetworkState.GUID) { |
| 252 return CrOnc.getNetworkName(this.activeNetworkState); | 255 return CrOnc.getNetworkName(this.activeNetworkState); |
| 253 } else if (this.networkStateList.length > 0) { | 256 } else if (this.networkStateList.length > 0) { |
| 254 return CrOnc.getNetworkName(this.networkStateList[0]); | 257 return CrOnc.getNetworkName(this.networkStateList[0]); |
| 255 } | 258 } |
| 256 } | 259 } |
| 257 return this.i18n('OncType' + this.deviceState.Type); | 260 return this.i18n('OncType' + this.deviceState.Type); |
| 258 }, | 261 }, |
| 259 | 262 |
| 260 /** | 263 /** |
| 261 * Event triggered when the enable button is toggled. | 264 * Event triggered when the enable button is toggled. |
| 262 * @param {!Event} event | 265 * @param {!Event} event |
| 263 * @private | 266 * @private |
| 264 */ | 267 */ |
| 265 onDeviceEnabledTap_: function(event) { | 268 onDeviceEnabledTap_: function(event) { |
| 266 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); | 269 var deviceIsEnabled = this.deviceIsEnabled_(this.deviceState); |
| 267 var type = this.deviceState ? this.deviceState.Type : ''; | 270 var type = this.deviceState ? this.deviceState.Type : ''; |
| 268 this.fire( | 271 this.fire( |
| 269 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); | 272 'device-enabled-toggled', {enabled: !deviceIsEnabled, type: type}); |
| 270 // Make sure this does not propagate to onDetailsTap_. | 273 // Make sure this does not propagate to onDetailsTap_. |
| 271 event.stopPropagation(); | 274 event.stopPropagation(); |
| 272 }, | 275 }, |
| 273 }); | 276 }); |
| OLD | NEW |