Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1155)

Side by Side Diff: chrome/browser/resources/bluetooth_internals/device_details_page.js

Issue 2617923002: bluetooth: Add service list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Update copyrights, remove unneeded import Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
34 * @constructor 35 * @constructor
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 this.deviceInfo = deviceInfo; 43 this.deviceInfo = deviceInfo;
43 44
44 /** @type {interfaces.BluetoothDevice.Device.ptrClass} */ 45 /** @type {?interfaces.BluetoothDevice.Device.ptrClass} */
45 this.devicePtr = null; 46 this.devicePtr = null;
46 /** @private {!device_collection.ConnectionStatus} */ 47 /** @private {!device_collection.ConnectionStatus} */
47 this.status_ = device_collection.ConnectionStatus.DISCONNECTED; 48 this.status_ = device_collection.ConnectionStatus.DISCONNECTED;
48 49
49 this.pageDiv.appendChild( 50 this.pageDiv.appendChild(
50 document.importNode($('device-details-template').content, 51 document.importNode($('device-details-template').content,
51 true /* deep */)); 52 true /* deep */));
52 53
53 this.pageDiv.querySelector('.forget-btn').addEventListener('click', 54 this.pageDiv.querySelector('.forget-btn').addEventListener('click',
54 function() { 55 function() {
(...skipping 12 matching lines...) Expand all
67 return; 68 return;
68 } 69 }
69 this.connect(); 70 this.connect();
70 }.bind(this)); 71 }.bind(this));
71 72
72 this.deviceFieldSet = new object_fieldset.ObjectFieldSet(); 73 this.deviceFieldSet = new object_fieldset.ObjectFieldSet();
73 this.deviceFieldSet.setPropertyDisplayNames(PROPERTY_NAMES); 74 this.deviceFieldSet.setPropertyDisplayNames(PROPERTY_NAMES);
74 this.pageDiv.querySelector('.device-details').appendChild( 75 this.pageDiv.querySelector('.device-details').appendChild(
75 this.deviceFieldSet); 76 this.deviceFieldSet);
76 77
78 this.serviceList = new service_list.ServiceList();
79 this.serviceList.setLoading(true);
80 this.pageDiv.querySelector('.services').appendChild(this.serviceList);
81
77 this.redraw(); 82 this.redraw();
78 } 83 }
79 84
80 DeviceDetailsPage.prototype = { 85 DeviceDetailsPage.prototype = {
81 __proto__: Page.prototype, 86 __proto__: Page.prototype,
82 87
83 /** Creates a connection to the Bluetooth device. */ 88 /** Creates a connection to the Bluetooth device. */
84 connect: function() { 89 connect: function() {
85 if (this.status_ !== device_collection.ConnectionStatus.DISCONNECTED) 90 if (this.status_ !== device_collection.ConnectionStatus.DISCONNECTED)
86 return; 91 return;
87 92
88 this.updateConnectionStatus_( 93 this.updateConnectionStatus_(
89 device_collection.ConnectionStatus.CONNECTING); 94 device_collection.ConnectionStatus.CONNECTING);
90 this.connecting_ = true; 95 this.connecting_ = true;
91 96
92 adapter_broker.getAdapterBroker().then(function(adapterBroker) { 97 adapter_broker.getAdapterBroker().then(function(adapterBroker) {
93 adapterBroker.connectToDevice(this.deviceInfo.address).then( 98 adapterBroker.connectToDevice(this.deviceInfo.address).then(
94 function(devicePtr) { 99 function(devicePtr) {
95 this.devicePtr = devicePtr; 100 this.devicePtr = devicePtr;
96 101
97 this.updateConnectionStatus_( 102 this.updateConnectionStatus_(
98 device_collection.ConnectionStatus.CONNECTED); 103 device_collection.ConnectionStatus.CONNECTED);
99 104
100 // Fetch services asynchronously. 105 // Fetch services asynchronously.
101 return this.devicePtr.getServices(); 106 return this.devicePtr.getServices();
102 }.bind(this)).then(function(response) { 107 }.bind(this)).then(function(response) {
103 this.deviceInfo.services = response.services; 108 this.serviceList.setData(new ArrayDataModel(response.services));
109 this.deviceInfo.services = this.serviceList.dataModel;
110 this.serviceList.setLoading(false);
111
104 this.redraw(); 112 this.redraw();
105 this.fireDeviceInfoChanged_(); 113 this.fireDeviceInfoChanged_();
106 }.bind(this)).catch(function(error) { 114 }.bind(this)).catch(function(error) {
107 // If a connection error occurs while fetching the services, the 115 // If a connection error occurs while fetching the services, the
108 // devicePtr reference must be removed. 116 // devicePtr reference must be removed.
109 if (this.devicePtr) { 117 if (this.devicePtr) {
110 this.devicePtr.disconnect(); 118 this.devicePtr.disconnect();
111 this.devicePtr = null; 119 this.devicePtr = null;
112 } 120 }
113 121
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 154
147 var deviceViewObj = { 155 var deviceViewObj = {
148 name: this.deviceInfo.name_for_display, 156 name: this.deviceInfo.name_for_display,
149 address: this.deviceInfo.address, 157 address: this.deviceInfo.address,
150 is_gatt_connected: connectedText, 158 is_gatt_connected: connectedText,
151 'rssi.value': (rssi && rssi.value) || 'Unknown', 159 'rssi.value': (rssi && rssi.value) || 'Unknown',
152 'services.length': (services && services.length) || 'Unknown', 160 'services.length': (services && services.length) || 'Unknown',
153 }; 161 };
154 162
155 this.deviceFieldSet.setObject(deviceViewObj); 163 this.deviceFieldSet.setObject(deviceViewObj);
164 this.serviceList.redraw();
156 }, 165 },
157 166
158 /** 167 /**
159 * Sets the page's device info and forces a redraw. 168 * Sets the page's device info and forces a redraw.
160 * @param {!interfaces.BluetoothDevice.DeviceInfo} 169 * @param {!interfaces.BluetoothDevice.DeviceInfo}
161 */ 170 */
162 setDeviceInfo: function(info) { 171 setDeviceInfo: function(info) {
163 this.deviceInfo = info; 172 this.deviceInfo = info;
164 this.redraw(); 173 this.redraw();
165 }, 174 },
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 status: status, 210 status: status,
202 } 211 }
203 })); 212 }));
204 }, 213 },
205 }; 214 };
206 215
207 return { 216 return {
208 DeviceDetailsPage: DeviceDetailsPage, 217 DeviceDetailsPage: DeviceDetailsPage,
209 }; 218 };
210 }); 219 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698