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 and modifying a list of cellular | 6 * @fileoverview Polymer element for displaying and modifying a list of cellular |
| 7 * access points. | 7 * access points. |
| 8 */ | 8 */ |
| 9 Polymer({ | 9 Polymer({ |
| 10 is: 'network-apnlist', | 10 is: 'network-apnlist', |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 /** | 13 /** |
| 14 * The current set of properties for the network matching |guid|. | 14 * The current set of properties for the network matching |guid|. |
| 15 * @type {!CrOnc.NetworkProperties|undefined} | 15 * @type {!CrOnc.NetworkProperties|undefined} |
| 16 */ | 16 */ |
| 17 networkProperties: { | 17 networkProperties: { |
| 18 type: Object, | 18 type: Object, |
| 19 observer: 'networkPropertiesChanged_', | 19 observer: 'networkPropertiesChanged_', |
| 20 }, | 20 }, |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * The CrOnc.APNProperties.AccessPointName value of the selected APN. | 23 * The CrOnc.APNProperties.AccessPointName value of the selected APN. |
| 24 * @private | |
| 24 */ | 25 */ |
| 25 selectedApn: { | 26 selectedApn_: { |
| 26 type: String, | 27 type: String, |
| 27 value: '', | 28 value: '', |
| 28 }, | 29 }, |
| 29 | 30 |
| 30 /** | 31 /** |
| 31 * Selectable list of APN dictionaries for the UI. Includes an entry | 32 * Selectable list of APN dictionaries for the UI. Includes an entry |
| 32 * corresponding to |otherApn| (see below). | 33 * corresponding to |otherApn| (see below). |
| 33 * @type {!Array<!CrOnc.APNProperties>} | 34 * @private {!Array<!CrOnc.APNProperties>} |
| 34 */ | 35 */ |
| 35 apnSelectList: { | 36 apnSelectList_: { |
| 36 type: Array, | 37 type: Array, |
| 37 value: function() { | 38 value: function() { |
| 38 return []; | 39 return []; |
| 39 } | 40 } |
| 40 }, | 41 }, |
| 41 | 42 |
| 42 /** | 43 /** |
| 43 * The user settable properties for a new ('other') APN. The values for | 44 * The user settable properties for a new ('other') APN. The values for |
| 44 * AccessPointName, Username, and Password will be set to the currently | 45 * AccessPointName, Username, and Password will be set to the currently |
| 45 * active APN if it does not match an existing list entry. | 46 * active APN if it does not match an existing list entry. |
| 46 * @type {CrOnc.APNProperties|undefined} | 47 * @private {CrOnc.APNProperties|undefined} |
| 47 */ | 48 */ |
| 48 otherApn: { | 49 otherApn_: { |
| 49 type: Object, | 50 type: Object, |
| 50 }, | 51 }, |
| 51 | 52 |
| 52 /** | 53 /** |
| 53 * Array of property names to pass to the Other APN property list. | 54 * Array of property names to pass to the Other APN property list. |
| 54 * @type {!Array<string>} | 55 * @private {!Array<string>} |
| 55 */ | 56 */ |
| 56 otherApnFields_: { | 57 otherApnFields_: { |
| 57 type: Array, | 58 type: Array, |
| 58 value: function() { | 59 value: function() { |
| 59 return ['AccessPointName', 'Username', 'Password']; | 60 return ['AccessPointName', 'Username', 'Password']; |
| 60 }, | 61 }, |
| 61 readOnly: true | 62 readOnly: true |
| 62 }, | 63 }, |
| 63 | 64 |
| 64 /** | 65 /** |
| 65 * Array of edit types to pass to the Other APN property list. | 66 * Array of edit types to pass to the Other APN property list. |
| 67 * @private | |
| 66 */ | 68 */ |
| 67 otherApnEditTypes_: { | 69 otherApnEditTypes_: { |
| 68 type: Object, | 70 type: Object, |
| 69 value: function() { | 71 value: function() { |
| 70 return { | 72 return { |
| 71 'AccessPointName': 'String', | 73 'AccessPointName': 'String', |
| 72 'Username': 'String', | 74 'Username': 'String', |
| 73 'Password': 'String' | 75 'Password': 'String' |
| 74 }; | 76 }; |
| 75 }, | 77 }, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 95 activeApn = /** @type {!CrOnc.APNProperties|undefined} */ ( | 97 activeApn = /** @type {!CrOnc.APNProperties|undefined} */ ( |
| 96 CrOnc.getSimpleActiveProperties(apn)); | 98 CrOnc.getSimpleActiveProperties(apn)); |
| 97 } else if (cellular.LastGoodAPN && cellular.LastGoodAPN.AccessPointName) { | 99 } else if (cellular.LastGoodAPN && cellular.LastGoodAPN.AccessPointName) { |
| 98 activeApn = cellular.LastGoodAPN; | 100 activeApn = cellular.LastGoodAPN; |
| 99 } | 101 } |
| 100 this.setApnSelectList_(activeApn); | 102 this.setApnSelectList_(activeApn); |
| 101 }, | 103 }, |
| 102 | 104 |
| 103 /** | 105 /** |
| 104 * Sets the list of selectable APNs for the UI. Appends an 'Other' entry | 106 * Sets the list of selectable APNs for the UI. Appends an 'Other' entry |
| 105 * (see comments for |otherApn| above). | 107 * (see comments for |otherApn_| above). |
| 106 * @param {CrOnc.APNProperties|undefined} activeApn The currently active APN | 108 * @param {CrOnc.APNProperties|undefined} activeApn The currently active APN |
| 107 * properties. | 109 * properties. |
| 108 * @private | 110 * @private |
| 109 */ | 111 */ |
| 110 setApnSelectList_: function(activeApn) { | 112 setApnSelectList_: function(activeApn) { |
| 111 // Copy the list of APNs from this.networkProperties. | 113 // Copy the list of APNs from this.networkProperties. |
| 112 var result = this.getApnList_().slice(); | 114 var result = this.getApnList_().slice(); |
| 113 | 115 |
| 114 // Test whether |activeApn| is in the current APN list in networkProperties. | 116 // Test whether |activeApn| is in the current APN list in networkProperties. |
| 115 var activeApnInList = activeApn && result.some(function(a) { | 117 var activeApnInList = activeApn && result.some(function(a) { |
| 116 return a.AccessPointName == activeApn.AccessPointName; | 118 return a.AccessPointName == activeApn.AccessPointName; |
| 117 }); | 119 }); |
| 118 | 120 |
| 119 // If |activeApn| is specified and not in the list, use the active | 121 // If |activeApn| is specified and not in the list, use the active |
| 120 // properties for 'other'. Otherwise use any existing 'other' properties. | 122 // properties for 'other'. Otherwise use any existing 'other' properties. |
| 121 var otherApnProperties = | 123 var otherApnProperties = |
| 122 (activeApn && !activeApnInList) ? activeApn : this.otherApn; | 124 (activeApn && !activeApnInList) ? activeApn : this.otherApn_; |
| 123 var otherApn = this.createApnObject_(otherApnProperties); | 125 var otherApn = this.createApnObject_(otherApnProperties); |
| 124 | 126 |
| 125 // Always use 'Other' for the name of custom APN entries (the name does | 127 // Always use 'Other' for the name of custom APN entries (the name does |
| 126 // not get saved). | 128 // not get saved). |
| 127 otherApn.Name = 'Other'; | 129 otherApn.Name = 'Other'; |
| 128 | 130 |
| 129 // If no 'active' or 'other' AccessPointName was provided, use the default. | 131 // If no 'active' or 'other' AccessPointName was provided, use the default. |
| 130 otherApn.AccessPointName = | 132 otherApn.AccessPointName = |
| 131 otherApn.AccessPointName || this.DefaultAccessPointName; | 133 otherApn.AccessPointName || this.DefaultAccessPointName; |
| 132 | 134 |
| 133 // Save the 'other' properties. | 135 // Save the 'other' properties. |
| 134 this.otherApn = otherApn; | 136 this.otherApn_ = otherApn; |
| 135 | 137 |
| 136 // Append 'other' to the end of the list of APNs. | 138 // Append 'other' to the end of the list of APNs. |
| 137 result.push(otherApn); | 139 result.push(otherApn); |
| 138 | 140 |
| 139 this.apnSelectList = result; | 141 this.apnSelectList_ = result; |
| 140 this.selectedApn = | 142 this.selectedApn_ = |
| 141 (activeApn && activeApn.AccessPointName) || otherApn.AccessPointName; | 143 (activeApn && activeApn.AccessPointName) || otherApn.AccessPointName; |
| 142 // We need to flush the DOM here, otherwise the paper-dropdown-menu-light | 144 // We need to flush the DOM here, otherwise the paper-dropdown-menu-light |
| 143 // will not update to correctly display the selected AccessPointName. | 145 // will not update to correctly display the selected AccessPointName. |
| 144 Polymer.dom.flush(); | 146 Polymer.dom.flush(); |
| 145 }, | 147 }, |
| 146 | 148 |
| 147 /** | 149 /** |
| 148 * @param {!CrOnc.APNProperties|undefined=} apnProperties | 150 * @param {!CrOnc.APNProperties|undefined=} apnProperties |
| 149 * @return {!CrOnc.APNProperties} A new APN object with properties from | 151 * @return {!CrOnc.APNProperties} A new APN object with properties from |
| 150 * |apnProperties| if provided. | 152 * |apnProperties| if provided. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 168 /** @type {!chrome.networkingPrivate.ManagedAPNList|undefined} */ var | 170 /** @type {!chrome.networkingPrivate.ManagedAPNList|undefined} */ var |
| 169 apnlist = this.networkProperties.Cellular.APNList; | 171 apnlist = this.networkProperties.Cellular.APNList; |
| 170 if (!apnlist) | 172 if (!apnlist) |
| 171 return []; | 173 return []; |
| 172 return /** @type {!Array<!CrOnc.APNProperties>} */ ( | 174 return /** @type {!Array<!CrOnc.APNProperties>} */ ( |
| 173 CrOnc.getActiveValue(apnlist)); | 175 CrOnc.getActiveValue(apnlist)); |
| 174 }, | 176 }, |
| 175 | 177 |
| 176 /** | 178 /** |
| 177 * Event triggered when the selectApn selection changes. | 179 * Event triggered when the selectApn selection changes. |
| 178 * @param {!{detail: !{selected: string}}} e | 180 * @param {!{detail: !{selected: string}}} event |
| 179 * @private | 181 * @private |
| 180 */ | 182 */ |
| 181 onSelectApnChange_: function(e) { | 183 onSelectApnChange_: function(event) { |
| 182 var selectedApn = e.detail.selected; | 184 var selectedApn = event.detail.selected; |
| 183 // When selecting 'Other', don't set a change event unless a valid | 185 // When selecting 'Other', don't set a change event unless a valid |
| 184 // non-default value has been set for Other. | 186 // non-default value has been set for Other. |
| 185 if (this.isOtherSelected_(this.networkProperties, selectedApn) && | 187 if (this.isOtherSelected_(selectedApn) && |
| 186 (!this.otherApn || !this.otherApn.AccessPointName || | 188 (!this.otherApn_ || !this.otherApn_.AccessPointName || |
| 187 this.otherApn.AccessPointName == this.DefaultAccessPointName)) { | 189 this.otherApn_.AccessPointName == this.DefaultAccessPointName)) { |
| 188 return; | 190 return; |
| 189 } | 191 } |
| 190 this.sendApnChange_(selectedApn); | 192 this.sendApnChange_(selectedApn); |
| 191 }, | 193 }, |
| 192 | 194 |
| 193 /** | 195 /** |
| 194 * Event triggered when any 'Other' APN network property changes. | 196 * Event triggered when any 'Other' APN network property changes. |
| 195 * @param {!{detail: {field: string, value: string}}} event | 197 * @param {!{detail: {field: string, value: string}}} event |
| 196 * @private | 198 * @private |
| 197 */ | 199 */ |
| 198 onOtherApnChange_: function(event) { | 200 onOtherApnChange_: function(event) { |
| 199 this.set('otherApn.' + event.detail.field, event.detail.value); | 201 this.set('otherApn.' + event.detail.field, event.detail.value); |
| 200 // Don't send a change event for 'Other' until the 'Save' button is tapped. | 202 // Don't send a change event for 'Other' until the 'Save' button is tapped. |
| 201 }, | 203 }, |
| 202 | 204 |
| 203 /** | 205 /** |
| 204 * Event triggered when the Other APN 'Save' button is tapped. | 206 * Event triggered when the Other APN 'Save' button is tapped. |
| 205 * @param {Event} event | 207 * @param {Event} event |
| 206 * @private | 208 * @private |
| 207 */ | 209 */ |
| 208 onSaveOtherTap_: function(event) { | 210 onSaveOtherTap_: function(event) { |
| 209 this.sendApnChange_(this.selectedApn); | 211 this.sendApnChange_(this.selectedApn_); |
| 210 }, | 212 }, |
| 211 | 213 |
| 212 /** | 214 /** |
| 213 * Send the apn-change event. | 215 * Send the apn-change event. |
| 214 * @param {string} selectedApn | 216 * @param {string} selectedApn |
| 215 * @private | 217 * @private |
| 216 */ | 218 */ |
| 217 sendApnChange_: function(selectedApn) { | 219 sendApnChange_: function(selectedApn) { |
| 218 var apnList = this.getApnList_(); | 220 var apnList = this.getApnList_(); |
| 219 var apn = this.findApnInList(apnList, selectedApn); | 221 var apn = this.findApnInList(apnList, selectedApn); |
| 220 if (apn == undefined) { | 222 if (apn == undefined) { |
| 221 apn = this.createApnObject_(); | 223 apn = this.createApnObject_(); |
| 222 if (this.otherApn) { | 224 if (this.otherApn_) { |
| 223 apn.AccessPointName = this.otherApn.AccessPointName; | 225 apn.AccessPointName = this.otherApn_.AccessPointName; |
| 224 apn.Username = this.otherApn.Username; | 226 apn.Username = this.otherApn_.Username; |
| 225 apn.Password = this.otherApn.Password; | 227 apn.Password = this.otherApn_.Password; |
| 226 } | 228 } |
| 227 } | 229 } |
| 228 this.fire('apn-change', {field: 'APN', value: apn}); | 230 this.fire('apn-change', {field: 'APN', value: apn}); |
| 229 }, | 231 }, |
| 230 | 232 |
| 231 /** | 233 /** |
| 232 * @param {!CrOnc.NetworkProperties|undefined} networkProperties | |
| 233 * @param {string} selectedApn | 234 * @param {string} selectedApn |
| 234 * @return {boolean} True if the 'other' APN is currently selected. | 235 * @return {boolean} True if the 'other' APN is currently selected. |
| 235 * @private | 236 * @private |
| 236 */ | 237 */ |
| 237 isOtherSelected_: function(networkProperties, selectedApn) { | 238 isOtherSelected_: function(selectedApn) { |
|
Dan Beam
2016/09/01 00:11:39
why are you using selectedApn and not discarding t
stevenjb
2016/09/01 15:18:45
Because selectedApn is not the same as this.select
Dan Beam
2016/09/01 15:52:40
i suspected something like this, but couldn't tell
| |
| 238 if (!networkProperties || !networkProperties.Cellular) | 239 if (!this.networkProperties || !this.networkProperties.Cellular) |
| 239 return false; | 240 return false; |
| 240 var apnList = this.getApnList_(); | 241 var apnList = this.getApnList_(); |
| 241 var apn = this.findApnInList(apnList, selectedApn); | 242 var apn = this.findApnInList(apnList, selectedApn); |
| 242 return apn == undefined; | 243 return apn == undefined; |
| 243 }, | 244 }, |
| 244 | 245 |
| 245 /** | 246 /** |
| 246 * @param {!CrOnc.APNProperties} apn | 247 * @param {!CrOnc.APNProperties} apn |
| 247 * @return {string} The most descriptive name for the access point. | 248 * @return {string} The most descriptive name for the access point. |
| 248 * @private | 249 * @private |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 259 * @private | 260 * @private |
| 260 */ | 261 */ |
| 261 findApnInList: function(apnList, accessPointName) { | 262 findApnInList: function(apnList, accessPointName) { |
| 262 for (let a of apnList) { | 263 for (let a of apnList) { |
| 263 if (a.AccessPointName == accessPointName) | 264 if (a.AccessPointName == accessPointName) |
| 264 return a; | 265 return a; |
| 265 } | 266 } |
| 266 return undefined; | 267 return undefined; |
| 267 } | 268 } |
| 268 }); | 269 }); |
| OLD | NEW |