Chromium Code Reviews| 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 |
| 53 listItem.info = characteristicInfo; | 56 listItem.info = characteristicInfo; |
| 57 listItem.deviceAddress_ = deviceAddress; | |
|
Dan Beam
2017/01/24 06:07:29
can we add type definitions for these properties i
mbrunson
2017/01/24 21:29:46
Done.
| |
| 58 listItem.serviceId_ = serviceId; | |
| 54 listItem.decorate(); | 59 listItem.decorate(); |
| 55 | 60 |
| 56 return listItem; | 61 return listItem; |
| 57 } | 62 } |
| 58 | 63 |
| 59 CharacteristicListItem.prototype = { | 64 CharacteristicListItem.prototype = { |
| 60 __proto__: ExpandableListItem.prototype, | 65 __proto__: ExpandableListItem.prototype, |
| 61 | 66 |
| 62 /** | 67 /** |
| 63 * Decorates the element as a characteristic list item. Creates and caches | 68 * Decorates the element as a characteristic list item. Creates and caches |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 writable_auxiliaries: (this.info.properties & | 101 writable_auxiliaries: (this.info.properties & |
| 97 Property.WRITABLE_AUXILIARIES) > 0, | 102 Property.WRITABLE_AUXILIARIES) > 0, |
| 98 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, | 103 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, |
| 99 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, | 104 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, |
| 100 read_encrypted_authenticated: (this.info.properties & | 105 read_encrypted_authenticated: (this.info.properties & |
| 101 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, | 106 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, |
| 102 write_encrypted_authenticated: (this.info.properties & | 107 write_encrypted_authenticated: (this.info.properties & |
| 103 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, | 108 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, |
| 104 }); | 109 }); |
| 105 | 110 |
| 111 /** @private {!descriptor_list.DescriptorList} */ | |
| 112 this.descriptorList_ = new descriptor_list.DescriptorList(); | |
| 113 | |
| 106 // Create content for display in brief content container. | 114 // Create content for display in brief content container. |
| 107 var characteristicHeaderText = document.createElement('div'); | 115 var characteristicHeaderText = document.createElement('div'); |
| 108 characteristicHeaderText.textContent = 'Characteristic:'; | 116 characteristicHeaderText.textContent = 'Characteristic:'; |
| 109 | 117 |
| 110 var characteristicHeaderValue = document.createElement('div'); | 118 var characteristicHeaderValue = document.createElement('div'); |
| 111 characteristicHeaderValue.textContent = this.info.uuid.uuid; | 119 characteristicHeaderValue.textContent = this.info.uuid.uuid; |
| 112 | 120 |
| 113 var characteristicHeader = document.createElement('div'); | 121 var characteristicHeader = document.createElement('div'); |
| 114 characteristicHeader.appendChild(characteristicHeaderText); | 122 characteristicHeader.appendChild(characteristicHeaderText); |
| 115 characteristicHeader.appendChild(characteristicHeaderValue); | 123 characteristicHeader.appendChild(characteristicHeaderValue); |
| 116 this.briefContent_.appendChild(characteristicHeader); | 124 this.briefContent_.appendChild(characteristicHeader); |
| 117 | 125 |
| 118 // Create content for display in expanded content container. | 126 // Create content for display in expanded content container. |
| 119 var characteristicInfoHeader = document.createElement('h4'); | 127 var characteristicInfoHeader = document.createElement('h4'); |
| 120 characteristicInfoHeader.textContent = 'Characteristic Info'; | 128 characteristicInfoHeader.textContent = 'Characteristic Info'; |
| 121 | 129 |
| 122 var characteristicDiv = document.createElement('div'); | 130 var characteristicDiv = document.createElement('div'); |
| 123 characteristicDiv.classList.add('flex'); | 131 characteristicDiv.classList.add('flex'); |
| 124 characteristicDiv.appendChild(this.characteristicFieldSet_); | 132 characteristicDiv.appendChild(this.characteristicFieldSet_); |
| 125 | 133 |
| 126 var propertiesHeader = document.createElement('h4'); | 134 var propertiesHeader = document.createElement('h4'); |
| 127 propertiesHeader.textContent = 'Properties'; | 135 propertiesHeader.textContent = 'Properties'; |
| 128 | 136 |
| 129 var propertiesDiv = document.createElement('div'); | 137 var propertiesDiv = document.createElement('div'); |
| 130 propertiesDiv.classList.add('flex'); | 138 propertiesDiv.classList.add('flex'); |
| 131 propertiesDiv.appendChild(this.propertiesFieldSet_); | 139 propertiesDiv.appendChild(this.propertiesFieldSet_); |
| 132 | 140 |
| 141 var descriptorsHeader = document.createElement('h4'); | |
| 142 descriptorsHeader.textContent = 'Descriptors'; | |
| 143 | |
| 133 var infoDiv = document.createElement('div'); | 144 var infoDiv = document.createElement('div'); |
| 134 infoDiv.classList.add('info-container'); | 145 infoDiv.classList.add('info-container'); |
| 135 infoDiv.appendChild(characteristicInfoHeader); | 146 infoDiv.appendChild(characteristicInfoHeader); |
| 136 infoDiv.appendChild(characteristicDiv); | 147 infoDiv.appendChild(characteristicDiv); |
| 137 infoDiv.appendChild(propertiesHeader); | 148 infoDiv.appendChild(propertiesHeader); |
| 138 infoDiv.appendChild(propertiesDiv); | 149 infoDiv.appendChild(propertiesDiv); |
| 150 infoDiv.appendChild(descriptorsHeader); | |
| 151 infoDiv.appendChild(this.descriptorList_); | |
| 139 | 152 |
| 140 this.expandedContent_.appendChild(infoDiv); | 153 this.expandedContent_.appendChild(infoDiv); |
| 141 }, | 154 }, |
| 155 | |
| 156 /** @override */ | |
| 157 onExpandInternal: function(expanded) { | |
| 158 this.descriptorList_.load( | |
| 159 this.deviceAddress_, this.serviceId_, this.info.id); | |
| 160 }, | |
| 142 }; | 161 }; |
| 143 | 162 |
| 144 /** | 163 /** |
| 145 * A list that displays CharacteristicListItems. | 164 * A list that displays CharacteristicListItems. |
| 146 * @constructor | 165 * @constructor |
| 147 */ | 166 */ |
| 148 var CharacteristicList = cr.ui.define('list'); | 167 var CharacteristicList = cr.ui.define('list'); |
| 149 | 168 |
| 150 CharacteristicList.prototype = { | 169 CharacteristicList.prototype = { |
| 151 __proto__: ExpandableList.prototype, | 170 __proto__: ExpandableList.prototype, |
| 152 | 171 |
| 153 /** @override */ | 172 /** @override */ |
| 154 decorate: function() { | 173 decorate: function() { |
| 155 ExpandableList.prototype.decorate.call(this); | 174 ExpandableList.prototype.decorate.call(this); |
| 156 | 175 |
| 157 /** @private {boolean} */ | 176 /** @private {boolean} */ |
| 158 this.characteristicsRequested_ = false; | 177 this.characteristicsRequested_ = false; |
| 159 | 178 |
| 160 this.classList.add('characteristic-list'); | 179 this.classList.add('characteristic-list'); |
| 161 this.setEmptyMessage('No Characteristics Found'); | 180 this.setEmptyMessage('No Characteristics Found'); |
| 162 }, | 181 }, |
| 163 | 182 |
| 164 /** @override */ | 183 /** @override */ |
| 165 createItem: function(data) { | 184 createItem: function(data) { |
| 166 return new CharacteristicListItem(data); | 185 return new CharacteristicListItem( |
| 186 data, this.deviceAddress_, this.serviceId_); | |
| 167 }, | 187 }, |
| 168 | 188 |
| 169 /** | 189 /** |
| 170 * Loads the characteristic list with an array of CharacteristicInfo from | 190 * Loads the characteristic list with an array of CharacteristicInfo from |
| 171 * the device with |deviceAddress| and service with |serviceId|. If no | 191 * the device with |deviceAddress| and service with |serviceId|. If no |
| 172 * active connection to the device exists, one is created. | 192 * active connection to the device exists, one is created. |
| 173 * @param {string} deviceAddress | 193 * @param {string} deviceAddress |
| 174 * @param {string} serviceId | 194 * @param {string} serviceId |
| 175 */ | 195 */ |
| 176 load: function(deviceAddress, serviceId) { | 196 load: function(deviceAddress, serviceId) { |
| 177 if (this.characteristicsRequested_ || !this.isLoading()) | 197 if (this.characteristicsRequested_ || !this.isLoading()) |
| 178 return; | 198 return; |
| 179 | 199 |
| 200 this.deviceAddress_ = deviceAddress; | |
| 201 this.serviceId_ = serviceId; | |
| 180 this.characteristicsRequested_ = true; | 202 this.characteristicsRequested_ = true; |
| 181 | 203 |
| 182 device_broker.connectToDevice(deviceAddress).then(function(device) { | 204 device_broker.connectToDevice(deviceAddress).then(function(device) { |
| 183 return device.getCharacteristics(serviceId); | 205 return device.getCharacteristics(serviceId); |
| 184 }.bind(this)).then(function(response) { | 206 }.bind(this)).then(function(response) { |
| 185 this.setData(new ArrayDataModel(response.characteristics)); | 207 this.setData(new ArrayDataModel(response.characteristics)); |
| 186 this.setLoading(false); | 208 this.setLoading(false); |
| 187 this.characteristicsRequested_ = false; | 209 this.characteristicsRequested_ = false; |
| 188 }.bind(this)).catch(function(error) { | 210 }.bind(this)).catch(function(error) { |
| 189 this.characteristicsRequested_ = false; | 211 this.characteristicsRequested_ = false; |
| 190 Snackbar.show( | 212 Snackbar.show( |
| 191 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', | 213 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', |
| 192 function() { | 214 function() { |
| 193 this.load(deviceAddress, serviceId); | 215 this.load(deviceAddress, serviceId); |
| 194 }.bind(this)); | 216 }.bind(this)); |
| 195 }.bind(this)); | 217 }.bind(this)); |
| 196 }, | 218 }, |
| 197 }; | 219 }; |
| 198 | 220 |
| 199 return { | 221 return { |
| 200 CharacteristicList: CharacteristicList, | 222 CharacteristicList: CharacteristicList, |
| 201 CharacteristicListItem: CharacteristicListItem, | 223 CharacteristicListItem: CharacteristicListItem, |
| 202 }; | 224 }; |
| 203 }); | 225 }); |
| OLD | NEW |