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 {!descriptor_list.DescriptorList} */ |
| 115 this.descriptorList_ = new descriptor_list.DescriptorList(); |
| 116 |
106 // Create content for display in brief content container. | 117 // Create content for display in brief content container. |
107 var characteristicHeaderText = document.createElement('div'); | 118 var characteristicHeaderText = document.createElement('div'); |
108 characteristicHeaderText.textContent = 'Characteristic:'; | 119 characteristicHeaderText.textContent = 'Characteristic:'; |
109 | 120 |
110 var characteristicHeaderValue = document.createElement('div'); | 121 var characteristicHeaderValue = document.createElement('div'); |
111 characteristicHeaderValue.textContent = this.info.uuid.uuid; | 122 characteristicHeaderValue.textContent = this.info.uuid.uuid; |
112 | 123 |
113 var characteristicHeader = document.createElement('div'); | 124 var characteristicHeader = document.createElement('div'); |
114 characteristicHeader.appendChild(characteristicHeaderText); | 125 characteristicHeader.appendChild(characteristicHeaderText); |
115 characteristicHeader.appendChild(characteristicHeaderValue); | 126 characteristicHeader.appendChild(characteristicHeaderValue); |
116 this.briefContent_.appendChild(characteristicHeader); | 127 this.briefContent_.appendChild(characteristicHeader); |
117 | 128 |
118 // Create content for display in expanded content container. | 129 // Create content for display in expanded content container. |
119 var characteristicInfoHeader = document.createElement('h4'); | 130 var characteristicInfoHeader = document.createElement('h4'); |
120 characteristicInfoHeader.textContent = 'Characteristic Info'; | 131 characteristicInfoHeader.textContent = 'Characteristic Info'; |
121 | 132 |
122 var characteristicDiv = document.createElement('div'); | 133 var characteristicDiv = document.createElement('div'); |
123 characteristicDiv.classList.add('flex'); | 134 characteristicDiv.classList.add('flex'); |
124 characteristicDiv.appendChild(this.characteristicFieldSet_); | 135 characteristicDiv.appendChild(this.characteristicFieldSet_); |
125 | 136 |
126 var propertiesHeader = document.createElement('h4'); | 137 var propertiesHeader = document.createElement('h4'); |
127 propertiesHeader.textContent = 'Properties'; | 138 propertiesHeader.textContent = 'Properties'; |
128 | 139 |
129 var propertiesDiv = document.createElement('div'); | 140 var propertiesDiv = document.createElement('div'); |
130 propertiesDiv.classList.add('flex'); | 141 propertiesDiv.classList.add('flex'); |
131 propertiesDiv.appendChild(this.propertiesFieldSet_); | 142 propertiesDiv.appendChild(this.propertiesFieldSet_); |
132 | 143 |
| 144 var descriptorsHeader = document.createElement('h4'); |
| 145 descriptorsHeader.textContent = 'Descriptors'; |
| 146 |
133 var infoDiv = document.createElement('div'); | 147 var infoDiv = document.createElement('div'); |
134 infoDiv.classList.add('info-container'); | 148 infoDiv.classList.add('info-container'); |
135 infoDiv.appendChild(characteristicInfoHeader); | 149 infoDiv.appendChild(characteristicInfoHeader); |
136 infoDiv.appendChild(characteristicDiv); | 150 infoDiv.appendChild(characteristicDiv); |
137 infoDiv.appendChild(propertiesHeader); | 151 infoDiv.appendChild(propertiesHeader); |
138 infoDiv.appendChild(propertiesDiv); | 152 infoDiv.appendChild(propertiesDiv); |
| 153 infoDiv.appendChild(descriptorsHeader); |
| 154 infoDiv.appendChild(this.descriptorList_); |
139 | 155 |
140 this.expandedContent_.appendChild(infoDiv); | 156 this.expandedContent_.appendChild(infoDiv); |
141 }, | 157 }, |
| 158 |
| 159 /** @override */ |
| 160 onExpandInternal: function(expanded) { |
| 161 this.descriptorList_.load( |
| 162 this.deviceAddress_, this.serviceId_, this.info.id); |
| 163 }, |
142 }; | 164 }; |
143 | 165 |
144 /** | 166 /** |
145 * A list that displays CharacteristicListItems. | 167 * A list that displays CharacteristicListItems. |
146 * @constructor | 168 * @constructor |
147 */ | 169 */ |
148 var CharacteristicList = cr.ui.define('list'); | 170 var CharacteristicList = cr.ui.define('list'); |
149 | 171 |
150 CharacteristicList.prototype = { | 172 CharacteristicList.prototype = { |
151 __proto__: ExpandableList.prototype, | 173 __proto__: ExpandableList.prototype, |
152 | 174 |
153 /** @override */ | 175 /** @override */ |
154 decorate: function() { | 176 decorate: function() { |
155 ExpandableList.prototype.decorate.call(this); | 177 ExpandableList.prototype.decorate.call(this); |
156 | 178 |
157 /** @private {boolean} */ | 179 /** @private {boolean} */ |
158 this.characteristicsRequested_ = false; | 180 this.characteristicsRequested_ = false; |
159 | 181 |
160 this.classList.add('characteristic-list'); | 182 this.classList.add('characteristic-list'); |
161 this.setEmptyMessage('No Characteristics Found'); | 183 this.setEmptyMessage('No Characteristics Found'); |
162 }, | 184 }, |
163 | 185 |
164 /** @override */ | 186 /** @override */ |
165 createItem: function(data) { | 187 createItem: function(data) { |
166 return new CharacteristicListItem(data); | 188 return new CharacteristicListItem( |
| 189 data, this.deviceAddress_, this.serviceId_); |
167 }, | 190 }, |
168 | 191 |
169 /** | 192 /** |
170 * Loads the characteristic list with an array of CharacteristicInfo from | 193 * Loads the characteristic list with an array of CharacteristicInfo from |
171 * the device with |deviceAddress| and service with |serviceId|. If no | 194 * the device with |deviceAddress| and service with |serviceId|. If no |
172 * active connection to the device exists, one is created. | 195 * active connection to the device exists, one is created. |
173 * @param {string} deviceAddress | 196 * @param {string} deviceAddress |
174 * @param {string} serviceId | 197 * @param {string} serviceId |
175 */ | 198 */ |
176 load: function(deviceAddress, serviceId) { | 199 load: function(deviceAddress, serviceId) { |
177 if (this.characteristicsRequested_ || !this.isLoading()) | 200 if (this.characteristicsRequested_ || !this.isSpinnerShowing()) |
178 return; | 201 return; |
179 | 202 |
| 203 this.deviceAddress_ = deviceAddress; |
| 204 this.serviceId_ = serviceId; |
180 this.characteristicsRequested_ = true; | 205 this.characteristicsRequested_ = true; |
181 | 206 |
182 device_broker.connectToDevice(deviceAddress).then(function(device) { | 207 device_broker.connectToDevice(deviceAddress).then(function(device) { |
183 return device.getCharacteristics(serviceId); | 208 return device.getCharacteristics(serviceId); |
184 }.bind(this)).then(function(response) { | 209 }.bind(this)).then(function(response) { |
185 this.setData(new ArrayDataModel(response.characteristics || [])); | 210 this.setData(new ArrayDataModel(response.characteristics || [])); |
186 this.setLoading(false); | 211 this.setSpinnerShowing(false); |
187 this.characteristicsRequested_ = false; | 212 this.characteristicsRequested_ = false; |
188 }.bind(this)).catch(function(error) { | 213 }.bind(this)).catch(function(error) { |
189 this.characteristicsRequested_ = false; | 214 this.characteristicsRequested_ = false; |
190 Snackbar.show( | 215 Snackbar.show( |
191 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', | 216 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', |
192 function() { | 217 function() { |
193 this.load(deviceAddress, serviceId); | 218 this.load(deviceAddress, serviceId); |
194 }.bind(this)); | 219 }.bind(this)); |
195 }.bind(this)); | 220 }.bind(this)); |
196 }, | 221 }, |
197 }; | 222 }; |
198 | 223 |
199 return { | 224 return { |
200 CharacteristicList: CharacteristicList, | 225 CharacteristicList: CharacteristicList, |
201 CharacteristicListItem: CharacteristicListItem, | 226 CharacteristicListItem: CharacteristicListItem, |
202 }; | 227 }; |
203 }); | 228 }); |
OLD | NEW |