| 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 DeviceDetailsPage which displays all of the details of a | 6 * Javascript for DeviceDetailsPage which displays all of the details of a |
| 7 * device. The page is generated and managed dynamically in bluetooth_internals. | 7 * device. The page is generated and managed dynamically in bluetooth_internals. |
| 8 * served from chrome://bluetooth-internals/. | 8 * served from chrome://bluetooth-internals/. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 cr.define('device_details_page', function() { | 11 cr.define('device_details_page', function() { |
| 12 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 12 /** @const */ var Page = cr.ui.pageManager.Page; | 13 /** @const */ var Page = cr.ui.pageManager.Page; |
| 13 /** @const */ var Snackbar = snackbar.Snackbar; | 14 /** @const */ var Snackbar = snackbar.Snackbar; |
| 14 /** @const */ var SnackbarType = snackbar.SnackbarType; | 15 /** @const */ var SnackbarType = snackbar.SnackbarType; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * Property names that will be displayed in the ObjectFieldSet which contains | 18 * Property names that will be displayed in the ObjectFieldSet which contains |
| 18 * the DeviceInfo object. | 19 * the DeviceInfo object. |
| 19 */ | 20 */ |
| 20 var PROPERTY_NAMES = { | 21 var PROPERTY_NAMES = { |
| 21 name: 'Name', | 22 name: 'Name', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 35 * @param {string} id | 36 * @param {string} id |
| 36 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo | 37 * @param {!interfaces.BluetoothDevice.DeviceInfo} deviceInfo |
| 37 * @extends {cr.ui.pageManager.Page} | 38 * @extends {cr.ui.pageManager.Page} |
| 38 */ | 39 */ |
| 39 function DeviceDetailsPage(id, deviceInfo) { | 40 function DeviceDetailsPage(id, deviceInfo) { |
| 40 Page.call(this, id, deviceInfo.name_for_display, id); | 41 Page.call(this, id, deviceInfo.name_for_display, id); |
| 41 | 42 |
| 42 /** @type {interfaces.BluetoothDevice.DeviceInfo} */ | 43 /** @type {interfaces.BluetoothDevice.DeviceInfo} */ |
| 43 this.deviceInfo = deviceInfo; | 44 this.deviceInfo = deviceInfo; |
| 44 | 45 |
| 45 /** @type {interfaces.BluetoothDevice.Device.ptrClass} */ | 46 /** @type {?interfaces.BluetoothDevice.Device.ptrClass} */ |
| 46 this.devicePtr = null; | 47 this.devicePtr = null; |
| 47 | 48 |
| 48 /** @type {!object_fieldset.ObjectFieldSet} */ | 49 /** @type {!object_fieldset.ObjectFieldSet} */ |
| 49 this.deviceFieldSet = new object_fieldset.ObjectFieldSet(); | 50 this.deviceFieldSet = new object_fieldset.ObjectFieldSet(); |
| 50 this.deviceFieldSet.setPropertyDisplayNames(PROPERTY_NAMES); | 51 this.deviceFieldSet.setPropertyDisplayNames(PROPERTY_NAMES); |
| 51 | 52 |
| 53 /** @type {!service_list.ServiceList} */ |
| 54 this.serviceList = new service_list.ServiceList(); |
| 55 this.serviceList.setLoading(true); |
| 56 |
| 52 /** @private {!device_collection.ConnectionStatus} */ | 57 /** @private {!device_collection.ConnectionStatus} */ |
| 53 this.status_ = device_collection.ConnectionStatus.DISCONNECTED; | 58 this.status_ = device_collection.ConnectionStatus.DISCONNECTED; |
| 54 | 59 |
| 55 /** @private {?HTMLElement} */ | 60 /** @private {?HTMLElement} */ |
| 56 this.connectBtn_ = null; | 61 this.connectBtn_ = null; |
| 57 | 62 |
| 58 this.pageDiv.appendChild( | 63 this.pageDiv.appendChild( |
| 59 document.importNode($('device-details-template').content, | 64 document.importNode($('device-details-template').content, |
| 60 true /* deep */)); | 65 true /* deep */)); |
| 61 | 66 |
| 62 this.pageDiv.querySelector('.device-details').appendChild( | 67 this.pageDiv.querySelector('.device-details').appendChild( |
| 63 this.deviceFieldSet); | 68 this.deviceFieldSet); |
| 69 this.pageDiv.querySelector('.services').appendChild(this.serviceList); |
| 64 | 70 |
| 65 this.pageDiv.querySelector('.forget').addEventListener( | 71 this.pageDiv.querySelector('.forget').addEventListener( |
| 66 'click', function() { | 72 'click', function() { |
| 67 this.disconnect(); | 73 this.disconnect(); |
| 68 this.pageDiv.dispatchEvent(new CustomEvent('forgetpressed', { | 74 this.pageDiv.dispatchEvent(new CustomEvent('forgetpressed', { |
| 69 detail: { | 75 detail: { |
| 70 address: this.deviceInfo.address, | 76 address: this.deviceInfo.address, |
| 71 }, | 77 }, |
| 72 })); | 78 })); |
| 73 }.bind(this)); | 79 }.bind(this)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 95 return adapterBroker.connectToDevice(this.deviceInfo.address); | 101 return adapterBroker.connectToDevice(this.deviceInfo.address); |
| 96 }.bind(this)).then(function(devicePtr) { | 102 }.bind(this)).then(function(devicePtr) { |
| 97 this.devicePtr = devicePtr; | 103 this.devicePtr = devicePtr; |
| 98 | 104 |
| 99 this.updateConnectionStatus_( | 105 this.updateConnectionStatus_( |
| 100 device_collection.ConnectionStatus.CONNECTED); | 106 device_collection.ConnectionStatus.CONNECTED); |
| 101 | 107 |
| 102 // Fetch services asynchronously. | 108 // Fetch services asynchronously. |
| 103 return this.devicePtr.getServices(); | 109 return this.devicePtr.getServices(); |
| 104 }.bind(this)).then(function(response) { | 110 }.bind(this)).then(function(response) { |
| 105 this.deviceInfo.services = response.services; | 111 this.serviceList.setData(new ArrayDataModel(response.services)); |
| 112 this.deviceInfo.services = this.serviceList.dataModel; |
| 113 this.serviceList.setLoading(false); |
| 114 |
| 106 this.redraw(); | 115 this.redraw(); |
| 107 this.fireDeviceInfoChanged_(); | 116 this.fireDeviceInfoChanged_(); |
| 108 }.bind(this)).catch(function(error) { | 117 }.bind(this)).catch(function(error) { |
| 109 // If a connection error occurs while fetching the services, the | 118 // If a connection error occurs while fetching the services, the |
| 110 // devicePtr reference must be removed. | 119 // devicePtr reference must be removed. |
| 111 if (this.devicePtr) { | 120 if (this.devicePtr) { |
| 112 this.devicePtr.disconnect(); | 121 this.devicePtr.disconnect(); |
| 113 this.devicePtr = null; | 122 this.devicePtr = null; |
| 114 } | 123 } |
| 115 | 124 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 162 |
| 154 var deviceViewObj = { | 163 var deviceViewObj = { |
| 155 name: this.deviceInfo.name_for_display, | 164 name: this.deviceInfo.name_for_display, |
| 156 address: this.deviceInfo.address, | 165 address: this.deviceInfo.address, |
| 157 is_gatt_connected: connectedText, | 166 is_gatt_connected: connectedText, |
| 158 'rssi.value': rssiValue, | 167 'rssi.value': rssiValue, |
| 159 'services.length': serviceCount, | 168 'services.length': serviceCount, |
| 160 }; | 169 }; |
| 161 | 170 |
| 162 this.deviceFieldSet.setObject(deviceViewObj); | 171 this.deviceFieldSet.setObject(deviceViewObj); |
| 172 this.serviceList.redraw(); |
| 163 }, | 173 }, |
| 164 | 174 |
| 165 /** | 175 /** |
| 166 * Sets the page's device info and forces a redraw. | 176 * Sets the page's device info and forces a redraw. |
| 167 * @param {!interfaces.BluetoothDevice.DeviceInfo} | 177 * @param {!interfaces.BluetoothDevice.DeviceInfo} |
| 168 */ | 178 */ |
| 169 setDeviceInfo: function(info) { | 179 setDeviceInfo: function(info) { |
| 170 this.deviceInfo = info; | 180 this.deviceInfo = info; |
| 171 this.redraw(); | 181 this.redraw(); |
| 172 }, | 182 }, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 status: status, | 224 status: status, |
| 215 } | 225 } |
| 216 })); | 226 })); |
| 217 }, | 227 }, |
| 218 }; | 228 }; |
| 219 | 229 |
| 220 return { | 230 return { |
| 221 DeviceDetailsPage: DeviceDetailsPage, | 231 DeviceDetailsPage: DeviceDetailsPage, |
| 222 }; | 232 }; |
| 223 }); | 233 }); |
| OLD | NEW |