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

Unified Diff: chrome/browser/resources/chromeos/emulator/bluetooth_settings.js

Issue 1258783009: Add functionality to Bluetooth settings UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/emulator/bluetooth_settings.js
diff --git a/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js b/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js
index e656e41984789b2ead64e450622ce8f413cb0f74..e49a0bbe9142020ab7e823093de05afcdebba4b4 100644
--- a/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js
+++ b/chrome/browser/resources/chromeos/emulator/bluetooth_settings.js
@@ -9,13 +9,22 @@
var BluetoothDevice = function() {
this.address = '';
this.alias = '';
+
+ // The text label of the selected device class.
this.class = 'Computer';
+
+ // The uint32 value of the selected device class.
this.classValue = 0;
- this.isPairable = true;
+
this.isTrusted = true;
this.name = '';
this.path = '';
- this.pairMethod = 'None';
+
+ // The label of the selected pairing method option.
+ this.pairingMethod = 'None';
+
+ // The text containing a PIN key or passkey for pairing.
+ this.pairingAuthToken = '';
};
Polymer({
@@ -30,13 +39,6 @@ Polymer({
},
/**
- * Indicates whether or not the main bluetooth adapter is turned on.
- */
- powerToMainAdapter: {
- type: Boolean
- },
-
- /**
* A set of bluetooth devices.
* @type !Array<!BluetoothDevice>
*/
@@ -59,7 +61,7 @@ Polymer({
{ text: 'Keyboard', value: 0x2540 },
{ text: 'Audio', value: 0x240408 },
{ text: 'Phone', value: 0x7a020c },
- { text: 'Computer', value: 0x100 }];
+ { text: 'Computer', value: 0x104 }];
}
},
@@ -70,7 +72,15 @@ Polymer({
*/
deviceAuthenticationMethods: {
type: Array,
- value: function() { return ['None', 'Pin Code', 'Pass Key']; }
+ value: function() { return ['None', 'PIN Code', 'PassKey']; }
+ },
+
+ /**
+ * Contains keys for all the device paths which have been discovered.
stevenjb 2015/07/30 18:28:51 @type
rfrappier 2015/07/30 22:21:38 Done.
+ */
+ devicePaths: {
+ type: Object,
+ value: function() { return []; }
xiyuan 2015/07/30 17:21:22 Should we return "{}" for an Object?
stevenjb 2015/07/30 18:28:51 It actually looks like this should be type: Array
xiyuan 2015/07/30 18:33:57 |devicePaths| is used as a dict to look up whether
},
},
@@ -78,9 +88,35 @@ Polymer({
this.title = 'Bluetooth Settings';
},
+ // Checks whether or not the PIN/passkey input field should be shown.
+ // It should only be shown when the pair method is not 'None' or empty.
stevenjb 2015/07/30 18:28:51 @oaram {string} pairMethod @return {boolean} Wheth
rfrappier 2015/07/30 22:21:38 Done.
+ showAuthToken: function(pairMethod) {
+ return pairMethod != 'None' && pairMethod != undefined;
+ },
+
+ // Called by the WebUI which provides a list of devices which are connected
+ // to the main adapter.
stevenjb 2015/07/30 18:28:51 @param ...
rfrappier 2015/07/30 22:21:38 Done.
+ updateBluetoothInfo: function(devices) {
+ device_list = [];
xiyuan 2015/07/30 17:21:21 var deviceList = [];
stevenjb 2015/07/30 18:28:51 Or actually: /** @type {!Array<!BluetoothDevice>}
xiyuan 2015/07/30 18:33:57 device_list -< deviceList, jsdoc is nice.
rfrappier 2015/07/30 22:21:38 Done.
xiyuan 2015/07/30 23:30:37 It would be nice to follow stevenjb@'s suggestion
rfrappier 2015/07/31 00:55:59 Done.
+
+ for (var i = 0; i < devices.length; ++i) {
+ if (this.devicePaths[devices[i]['path']] == undefined) {
stevenjb 2015/07/30 18:28:51 if (this.devicePaths[devices[i]['path']] != undefi
rfrappier 2015/07/30 22:21:38 Done.
+ // Get the label for the device class which should be selected.
+ var selectedClass =
+ this.getTextForDeviceClass(devices[i]['classValue']);
+ devices[i].class = selectedClass;
+ device_list.push(devices[i]);
+ this.devicePaths[devices[i]['path']] = true;
+ }
+ }
+
+ this.devices = device_list;
xiyuan 2015/07/30 17:21:21 |device_list| contains only new devices at this po
rfrappier 2015/07/30 22:21:38 This function is only called in the very beginning
xiyuan 2015/07/30 23:30:37 If we are sure this is only intended to be called
rfrappier 2015/07/31 00:55:59 Done.
+ },
+
pairDevice: function(e) {
var device = this.devices[e.path[2].dataIndex];
device.classValue = this.getValueForDeviceClass(device.class);
+ this.devicePaths[device.path] = true;
// Send device info to the WebUI.
chrome.send('requestBluetoothPair', [device]);
@@ -89,18 +125,41 @@ Polymer({
discoverDevice: function(e) {
var device = this.devices[e.path[2].dataIndex];
device.classValue = this.getValueForDeviceClass(device.class);
+ this.devicePaths[device.path] = true;
// Send device info to WebUI.
chrome.send('requestBluetoothDiscover', [device]);
},
+ // Adds a new device with default settings to the list of devices.
appendNewDevice: function() {
this.push('devices', new BluetoothDevice());
},
- getValueForDeviceClass: function(classValue) {
+ // This is called when a new device is discovered by the main adapter.
+ // The device is only added to the view's list if it is not already in
+ // the list (i.e. its path has not yet been recorded in |devicePaths|).
stevenjb 2015/07/30 18:28:51 @param
rfrappier 2015/07/30 22:21:38 Done.
+ addBluetoothDevice: function(device) {
+ if (this.devicePaths[device['path']] == undefined) {
stevenjb 2015/07/30 18:28:51 if (this.devicePaths[device['path']] != undefined)
rfrappier 2015/07/30 22:21:38 Done.
+ var selectedClass = this.getTextForDeviceClass(device['classValue']);
+ device.class = selectedClass;
+ this.push('devices', device);
+ this.devicePaths[device['path']] = true;
+ }
+ },
+
+ // Returns the text for the label that corresponds to |classValue|.
stevenjb 2015/07/30 18:28:51 @param
rfrappier 2015/07/30 22:21:38 Done.
+ getTextForDeviceClass: function(classValue) {
xiyuan 2015/07/30 17:21:22 We probably should consider move this.deviceClassO
rfrappier 2015/07/30 22:21:38 This may be possible, and I agree that this makes
xiyuan 2015/07/30 23:30:37 I don't understand why it would not work with Poly
rfrappier 2015/07/31 00:55:59 The problem is that Polymer's data binding cannot
rfrappier 2015/07/31 01:09:53 Also, I think having this property in the Polyemr
xiyuan 2015/07/31 02:00:00 Why this would not work? Have you tried it? "new B
+ for (var i = 0; i < this.deviceClassOptions.length; ++i) {
+ if (this.deviceClassOptions[i].value == classValue)
+ return this.deviceClassOptions[i].text;
+ }
+ },
+
+ // Returns the integer value which corresponds with the label |classText|.
stevenjb 2015/07/30 18:28:51 @param @return
rfrappier 2015/07/30 22:21:38 Done.
+ getValueForDeviceClass: function(classText) {
for (var i = 0; i < this.deviceClassOptions.length; ++i) {
- if (this.deviceClassOptions[i].text == classValue)
+ if (this.deviceClassOptions[i].text == classText)
return this.deviceClassOptions[i].value;
}
return 0;

Powered by Google App Engine
This is Rietveld 408576698