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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 }); | 84 }); |
85 | 85 |
86 /** @private {!object_fieldset.ObjectFieldSet} */ | 86 /** @private {!object_fieldset.ObjectFieldSet} */ |
87 this.propertiesFieldSet_ = new object_fieldset.ObjectFieldSet(); | 87 this.propertiesFieldSet_ = new object_fieldset.ObjectFieldSet(); |
88 this.propertiesFieldSet_.setPropertyDisplayNames( | 88 this.propertiesFieldSet_.setPropertyDisplayNames( |
89 PROPERTIES_PROPERTY_NAMES); | 89 PROPERTIES_PROPERTY_NAMES); |
90 var Property = interfaces.BluetoothDevice.Property; | 90 var Property = interfaces.BluetoothDevice.Property; |
91 this.propertiesFieldSet_.setObject({ | 91 this.propertiesFieldSet_.setObject({ |
92 broadcast: (this.info.properties & Property.BROADCAST) > 0, | 92 broadcast: (this.info.properties & Property.BROADCAST) > 0, |
93 read: (this.info.properties & Property.READ) > 0, | 93 read: (this.info.properties & Property.READ) > 0, |
94 write_without_response: (this.info.properties & | 94 write_without_response: |
95 Property.WRITE_WITHOUT_RESPONSE) > 0, | 95 (this.info.properties & Property.WRITE_WITHOUT_RESPONSE) > 0, |
96 write: (this.info.properties & Property.WRITE) > 0, | 96 write: (this.info.properties & Property.WRITE) > 0, |
97 notify: (this.info.properties & Property.NOTIFY) > 0, | 97 notify: (this.info.properties & Property.NOTIFY) > 0, |
98 indicate: (this.info.properties & Property.INDICATE) > 0, | 98 indicate: (this.info.properties & Property.INDICATE) > 0, |
99 authenticated_signed_writes: (this.info.properties & | 99 authenticated_signed_writes: |
100 Property.AUTHENTICATED_SIGNED_WRITES) > 0, | 100 (this.info.properties & Property.AUTHENTICATED_SIGNED_WRITES) > 0, |
101 extended_properties: (this.info.properties & | 101 extended_properties: |
102 Property.EXTENDED_PROPERTIES) > 0, | 102 (this.info.properties & Property.EXTENDED_PROPERTIES) > 0, |
103 reliable_write: (this.info.properties & Property.RELIABLE_WRITE) > 0, | 103 reliable_write: (this.info.properties & Property.RELIABLE_WRITE) > 0, |
104 writable_auxiliaries: (this.info.properties & | 104 writable_auxiliaries: |
105 Property.WRITABLE_AUXILIARIES) > 0, | 105 (this.info.properties & Property.WRITABLE_AUXILIARIES) > 0, |
106 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, | 106 read_encrypted: (this.info.properties & Property.READ_ENCRYPTED) > 0, |
107 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, | 107 write_encrypted: (this.info.properties & Property.WRITE_ENCRYPTED) > 0, |
108 read_encrypted_authenticated: (this.info.properties & | 108 read_encrypted_authenticated: |
109 Property.READ_ENCRYPTED_AUTHENTICATED) > 0, | 109 (this.info.properties & Property.READ_ENCRYPTED_AUTHENTICATED) > 0, |
110 write_encrypted_authenticated: (this.info.properties & | 110 write_encrypted_authenticated: |
111 Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, | 111 (this.info.properties & Property.WRITE_ENCRYPTED_AUTHENTICATED) > 0, |
112 }); | 112 }); |
113 | 113 |
114 /** @private {!value_control.ValueControl} */ | 114 /** @private {!value_control.ValueControl} */ |
115 this.valueControl_ = new value_control.ValueControl(); | 115 this.valueControl_ = new value_control.ValueControl(); |
116 | 116 |
117 this.valueControl_.load({ | 117 this.valueControl_.load({ |
118 deviceAddress: this.deviceAddress_, | 118 deviceAddress: this.deviceAddress_, |
119 serviceId: this.serviceId_, | 119 serviceId: this.serviceId_, |
120 characteristicId: this.info.id, | 120 characteristicId: this.info.id, |
121 properties: this.info.properties, | 121 properties: this.info.properties, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 * @param {string} serviceId | 218 * @param {string} serviceId |
219 */ | 219 */ |
220 load: function(deviceAddress, serviceId) { | 220 load: function(deviceAddress, serviceId) { |
221 if (this.characteristicsRequested_ || !this.isSpinnerShowing()) | 221 if (this.characteristicsRequested_ || !this.isSpinnerShowing()) |
222 return; | 222 return; |
223 | 223 |
224 this.deviceAddress_ = deviceAddress; | 224 this.deviceAddress_ = deviceAddress; |
225 this.serviceId_ = serviceId; | 225 this.serviceId_ = serviceId; |
226 this.characteristicsRequested_ = true; | 226 this.characteristicsRequested_ = true; |
227 | 227 |
228 device_broker.connectToDevice(deviceAddress).then(function(device) { | 228 device_broker.connectToDevice(deviceAddress) |
229 return device.getCharacteristics(serviceId); | 229 .then(function(device) { |
230 }.bind(this)).then(function(response) { | 230 return device.getCharacteristics(serviceId); |
231 this.setData(new ArrayDataModel(response.characteristics || [])); | 231 }.bind(this)) |
232 this.setSpinnerShowing(false); | 232 .then(function(response) { |
233 this.characteristicsRequested_ = false; | 233 this.setData(new ArrayDataModel(response.characteristics || [])); |
234 }.bind(this)).catch(function(error) { | 234 this.setSpinnerShowing(false); |
235 this.characteristicsRequested_ = false; | 235 this.characteristicsRequested_ = false; |
236 Snackbar.show( | 236 }.bind(this)) |
237 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry', | 237 .catch(function(error) { |
238 function() { | 238 this.characteristicsRequested_ = false; |
239 this.load(deviceAddress, serviceId); | 239 Snackbar.show( |
240 }.bind(this)); | 240 deviceAddress + ': ' + error.message, SnackbarType.ERROR, |
241 }.bind(this)); | 241 'Retry', function() { |
| 242 this.load(deviceAddress, serviceId); |
| 243 }.bind(this)); |
| 244 }.bind(this)); |
242 }, | 245 }, |
243 }; | 246 }; |
244 | 247 |
245 return { | 248 return { |
246 CharacteristicList: CharacteristicList, | 249 CharacteristicList: CharacteristicList, |
247 CharacteristicListItem: CharacteristicListItem, | 250 CharacteristicListItem: CharacteristicListItem, |
248 }; | 251 }; |
249 }); | 252 }); |
OLD | NEW |