| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 * Javascript for CharacteristicList and CharacteristicListItem, served from | 6 * Javascript for CharacteristicList and CharacteristicListItem, served from |
| 7 * chrome://bluetooth-internals/. | 7 * chrome://bluetooth-internals/. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 cr.define('characteristic_list', function() { | 10 cr.define('characteristic_list', function() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 write_encrypted_authenticated: 'Write Encrypted Authenticated', | 38 write_encrypted_authenticated: 'Write Encrypted Authenticated', |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * A list item that displays the properties of a CharacteristicInfo object. | 42 * A list item that displays the properties of a CharacteristicInfo object. |
| 43 * Two fieldsets are created within the element: one for the primitive | 43 * Two fieldsets are created within the element: one for the primitive |
| 44 * properties, 'id' and 'uuid', and one for the 'properties' bitfield in the | 44 * properties, 'id' and 'uuid', and one for the 'properties' bitfield in the |
| 45 * CharacteristicInfo object. | 45 * CharacteristicInfo object. |
| 46 * @constructor | 46 * @constructor |
| 47 * @param {!interfaces.BluetoothDevice.CharacteristicInfo} characteristicInfo | 47 * @param {!interfaces.BluetoothDevice.CharacteristicInfo} characteristicInfo |
| 48 * @param {string} deviceAddress |
| 49 * @param {string} serviceId |
| 48 */ | 50 */ |
| 49 function CharacteristicListItem(characteristicInfo) { | 51 function CharacteristicListItem( |
| 52 characteristicInfo, deviceAddress, serviceId) { |
| 50 var listItem = new ExpandableListItem(); | 53 var listItem = new ExpandableListItem(); |
| 51 listItem.__proto__ = CharacteristicListItem.prototype; | 54 listItem.__proto__ = CharacteristicListItem.prototype; |
| 52 | 55 |
| 56 /** @type {!interfaces.BluetoothDevice.CharacteristicInfo} */ |
| 53 listItem.info = characteristicInfo; | 57 listItem.info = characteristicInfo; |
| 58 /** @private {string} */ |
| 59 listItem.deviceAddress_ = deviceAddress; |
| 60 /** @private {string} */ |
| 61 listItem.serviceId_ = serviceId; |
| 62 |
| 54 listItem.decorate(); | 63 listItem.decorate(); |
| 55 | |
| 56 return listItem; | 64 return listItem; |
| 57 } | 65 } |
| 58 | 66 |
| 59 CharacteristicListItem.prototype = { | 67 CharacteristicListItem.prototype = { |
| 60 __proto__: ExpandableListItem.prototype, | 68 __proto__: ExpandableListItem.prototype, |
| 61 | 69 |
| 62 /** | 70 /** |
| 63 * Decorates the element as a characteristic list item. Creates and caches | 71 * Decorates the element as a characteristic list item. Creates and caches |
| 64 * two fieldsets for displaying property values. | 72 * two fieldsets for displaying property values. |
| 65 * @override | 73 * @override |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 writable_auxiliaries: (this.info.properties & | 104 writable_auxiliaries: (this.info.properties & |
| 97 Property.WRITABLE_AUXILIARIES) > 0, | 105 Property.WRITABLE_AUXILIARIES) > 0, |
| 98 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, | 106 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, |
| 99 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, | 107 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, |
| 100 read_encrypted_authenticated: (this.info.properties & | 108 read_encrypted_authenticated: (this.info.properties & |
| 101 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, | 109 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, |
| 102 write_encrypted_authenticated: (this.info.properties & | 110 write_encrypted_authenticated: (this.info.properties & |
| 103 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, | 111 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, |
| 104 }); | 112 }); |
| 105 | 113 |
| 114 /** @private {!value_control.ValueControl} */ |
| 115 this.valueControl_ = new value_control.ValueControl(); |
| 116 this.valueControl_.load(this.deviceAddress_, this.serviceId_, this.info); |
| 117 this.valueControl_.setValue(this.info.last_known_value); |
| 118 |
| 119 /** @private {!descriptor_list.DescriptorList} */ |
| 120 this.descriptorList_ = new descriptor_list.DescriptorList(); |
| 121 |
| 106 // Create content for display in brief content container. | 122 // Create content for display in brief content container. |
| 107 var characteristicHeaderText = document.createElement('div'); | 123 var characteristicHeaderText = document.createElement('div'); |
| 108 characteristicHeaderText.textContent = 'Characteristic:'; | 124 characteristicHeaderText.textContent = 'Characteristic:'; |
| 109 | 125 |
| 110 var characteristicHeaderValue = document.createElement('div'); | 126 var characteristicHeaderValue = document.createElement('div'); |
| 111 characteristicHeaderValue.textContent = this.info.uuid.uuid; | 127 characteristicHeaderValue.textContent = this.info.uuid.uuid; |
| 112 | 128 |
| 113 var characteristicHeader = document.createElement('div'); | 129 var characteristicHeader = document.createElement('div'); |
| 114 characteristicHeader.appendChild(characteristicHeaderText); | 130 characteristicHeader.appendChild(characteristicHeaderText); |
| 115 characteristicHeader.appendChild(characteristicHeaderValue); | 131 characteristicHeader.appendChild(characteristicHeaderValue); |
| 116 this.briefContent_.appendChild(characteristicHeader); | 132 this.briefContent_.appendChild(characteristicHeader); |
| 117 | 133 |
| 118 // Create content for display in expanded content container. | 134 // Create content for display in expanded content container. |
| 119 var characteristicInfoHeader = document.createElement('h4'); | 135 var characteristicInfoHeader = document.createElement('h4'); |
| 120 characteristicInfoHeader.textContent = 'Characteristic Info'; | 136 characteristicInfoHeader.textContent = 'Characteristic Info'; |
| 121 | 137 |
| 122 var characteristicDiv = document.createElement('div'); | 138 var characteristicDiv = document.createElement('div'); |
| 123 characteristicDiv.classList.add('flex'); | 139 characteristicDiv.classList.add('flex'); |
| 124 characteristicDiv.appendChild(this.characteristicFieldSet_); | 140 characteristicDiv.appendChild(this.characteristicFieldSet_); |
| 125 | 141 |
| 126 var propertiesHeader = document.createElement('h4'); | 142 var propertiesHeader = document.createElement('h4'); |
| 127 propertiesHeader.textContent = 'Properties'; | 143 propertiesHeader.textContent = 'Properties'; |
| 128 | 144 |
| 129 var propertiesDiv = document.createElement('div'); | 145 var propertiesDiv = document.createElement('div'); |
| 130 propertiesDiv.classList.add('flex'); | 146 propertiesDiv.classList.add('flex'); |
| 131 propertiesDiv.appendChild(this.propertiesFieldSet_); | 147 propertiesDiv.appendChild(this.propertiesFieldSet_); |
| 132 | 148 |
| 149 var descriptorsHeader = document.createElement('h4'); |
| 150 descriptorsHeader.textContent = 'Descriptors'; |
| 151 |
| 133 var infoDiv = document.createElement('div'); | 152 var infoDiv = document.createElement('div'); |
| 134 infoDiv.classList.add('info-container'); | 153 infoDiv.classList.add('info-container'); |
| 154 |
| 155 var valueHeader = document.createElement('h4'); |
| 156 valueHeader.textContent = 'Value'; |
| 157 |
| 135 infoDiv.appendChild(characteristicInfoHeader); | 158 infoDiv.appendChild(characteristicInfoHeader); |
| 136 infoDiv.appendChild(characteristicDiv); | 159 infoDiv.appendChild(characteristicDiv); |
| 137 infoDiv.appendChild(propertiesHeader); | 160 infoDiv.appendChild(propertiesHeader); |
| 138 infoDiv.appendChild(propertiesDiv); | 161 infoDiv.appendChild(propertiesDiv); |
| 162 infoDiv.appendChild(valueHeader); |
| 163 infoDiv.appendChild(this.valueControl_); |
| 164 infoDiv.appendChild(descriptorsHeader); |
| 165 infoDiv.appendChild(this.descriptorList_); |
| 139 | 166 |
| 140 this.expandedContent_.appendChild(infoDiv); | 167 this.expandedContent_.appendChild(infoDiv); |
| 141 }, | 168 }, |
| 169 |
| 170 /** @override */ |
| 171 onExpandInternal: function(expanded) { |
| 172 this.descriptorList_.load( |
| 173 this.deviceAddress_, this.serviceId_, this.info.id); |
| 174 }, |
| 142 }; | 175 }; |
| 143 | 176 |
| 144 /** | 177 /** |
| 145 * A list that displays CharacteristicListItems. | 178 * A list that displays CharacteristicListItems. |
| 146 * @constructor | 179 * @constructor |
| 147 */ | 180 */ |
| 148 var CharacteristicList = cr.ui.define('list'); | 181 var CharacteristicList = cr.ui.define('list'); |
| 149 | 182 |
| 150 CharacteristicList.prototype = { | 183 CharacteristicList.prototype = { |
| 151 __proto__: ExpandableList.prototype, | 184 __proto__: ExpandableList.prototype, |
| 152 | 185 |
| 153 /** @override */ | 186 /** @override */ |
| 154 decorate: function() { | 187 decorate: function() { |
| 155 ExpandableList.prototype.decorate.call(this); | 188 ExpandableList.prototype.decorate.call(this); |
| 156 | 189 |
| 190 /** @private {?string} */ |
| 191 this.deviceAddress_ = null; |
| 192 /** @private {?string} */ |
| 193 this.serviceId_ = null; |
| 157 /** @private {boolean} */ | 194 /** @private {boolean} */ |
| 158 this.characteristicsRequested_ = false; | 195 this.characteristicsRequested_ = false; |
| 159 | 196 |
| 160 this.classList.add('characteristic-list'); | 197 this.classList.add('characteristic-list'); |
| 161 this.setEmptyMessage('No Characteristics Found'); | 198 this.setEmptyMessage('No Characteristics Found'); |
| 162 }, | 199 }, |
| 163 | 200 |
| 164 /** @override */ | 201 /** @override */ |
| 165 createItem: function(data) { | 202 createItem: function(data) { |
| 166 return new CharacteristicListItem(data); | 203 return new CharacteristicListItem( |
| 204 data, this.deviceAddress_, this.serviceId_); |
| 167 }, | 205 }, |
| 168 | 206 |
| 169 /** | 207 /** |
| 170 * Loads the characteristic list with an array of CharacteristicInfo from | 208 * Loads the characteristic list with an array of CharacteristicInfo from |
| 171 * the device with |deviceAddress| and service with |serviceId|. If no | 209 * the device with |deviceAddress| and service with |serviceId|. If no |
| 172 * active connection to the device exists, one is created. | 210 * active connection to the device exists, one is created. |
| 173 * @param {string} deviceAddress | 211 * @param {string} deviceAddress |
| 174 * @param {string} serviceId | 212 * @param {string} serviceId |
| 175 */ | 213 */ |
| 176 load: function(deviceAddress, serviceId) { | 214 load: function(deviceAddress, serviceId) { |
| 177 if (this.characteristicsRequested_ || !this.isLoading()) | 215 if (this.characteristicsRequested_ || !this.isSpinnerShowing()) |
| 178 return; | 216 return; |
| 179 | 217 |
| 218 this.deviceAddress_ = deviceAddress; |
| 219 this.serviceId_ = serviceId; |
| 180 this.characteristicsRequested_ = true; | 220 this.characteristicsRequested_ = true; |
| 181 | 221 |
| 182 device_broker.connectToDevice(deviceAddress).then(function(device) { | 222 device_broker.connectToDevice(deviceAddress).then(function(device) { |
| 183 return device.getCharacteristics(serviceId); | 223 return device.getCharacteristics(serviceId); |
| 184 }.bind(this)).then(function(response) { | 224 }.bind(this)).then(function(response) { |
| 185 this.setData(new ArrayDataModel(response.characteristics || [])); | 225 this.setData(new ArrayDataModel(response.characteristics || [])); |
| 186 this.setLoading(false); | 226 this.setSpinnerShowing(false); |
| 187 this.characteristicsRequested_ = false; | 227 this.characteristicsRequested_ = false; |
| 188 }.bind(this)).catch(function(error) { | 228 }.bind(this)).catch(function(error) { |
| 189 this.characteristicsRequested_ = false; | 229 this.characteristicsRequested_ = false; |
| 190 Snackbar.show( | 230 Snackbar.show( |
| 191 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', | 231 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', |
| 192 function() { | 232 function() { |
| 193 this.load(deviceAddress, serviceId); | 233 this.load(deviceAddress, serviceId); |
| 194 }.bind(this)); | 234 }.bind(this)); |
| 195 }.bind(this)); | 235 }.bind(this)); |
| 196 }, | 236 }, |
| 197 }; | 237 }; |
| 198 | 238 |
| 199 return { | 239 return { |
| 200 CharacteristicList: CharacteristicList, | 240 CharacteristicList: CharacteristicList, |
| 201 CharacteristicListItem: CharacteristicListItem, | 241 CharacteristicListItem: CharacteristicListItem, |
| 202 }; | 242 }; |
| 203 }); | 243 }); |
| OLD | NEW |