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

Unified Diff: chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js

Issue 2655043005: MD Settings: Bluetooth: Move device list to subpage (Closed)
Patch Set: Fix clang, ES6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js
diff --git a/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js b/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js
index a5ebfd0931c94c64369bf1a227d78cd9e803b70b..6e50fb4efadfc3e536178cd325cc9881ddfe2344 100644
--- a/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js
+++ b/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js
@@ -4,8 +4,6 @@
cr.exportPath('settings');
-(function() {
-
var PairingEventType = chrome.bluetoothPrivate.PairingEventType;
// NOTE(dbeam): even though these behaviors are only used privately, they must
@@ -45,7 +43,8 @@ settings.BluetoothAddDeviceBehavior = {
},
},
- /** @type {boolean} */ itemWasFocused_: false,
+ /** @type {boolean} */
+ itemWasFocused_: false,
/** @private */
adapterStateChanged_: function() {
@@ -67,7 +66,9 @@ settings.BluetoothAddDeviceBehavior = {
return;
}
// Otherwise try again.
- setTimeout(function() { this.deviceListChanged_(); }.bind(this), 100);
+ setTimeout(function() {
+ this.deviceListChanged_();
+ }.bind(this), 100);
},
/** @private */
@@ -100,20 +101,33 @@ settings.BluetoothPairDeviceBehavior = {
properties: {
/**
* Current Pairing device.
- * @type {?chrome.bluetooth.Device|undefined}
+ * @type {!chrome.bluetooth.Device|undefined}
*/
pairingDevice: Object,
/**
* Current Pairing event.
- * @type {?chrome.bluetoothPrivate.PairingEvent|undefined}
+ * @type {?chrome.bluetoothPrivate.PairingEvent}
*/
- pairingEvent: Object,
+ pairingEvent_: {
+ type: Object,
+ value: null,
+ },
/** Pincode or passkey value, used to trigger connect enabled changes. */
pinOrPass: String,
/**
+ * Interface for bluetoothPrivate calls. Set in bluetooth-page.
+ * @type {BluetoothPrivate}
+ * @private
+ */
+ bluetoothPrivate: {
+ type: Object,
+ value: chrome.bluetoothPrivate,
+ },
+
+ /**
* @const
* @type {!Array<number>}
*/
@@ -125,13 +139,59 @@ settings.BluetoothPairDeviceBehavior = {
},
observers: [
- 'pairingChanged_(pairingDevice, pairingEvent)',
+ 'pairingChanged_(pairingDevice, pairingEvent_)',
],
+ /**
+ * Listener for chrome.bluetoothPrivate.onPairing events.
+ * @type {?function(!chrome.bluetoothPrivate.PairingEvent)}
+ * @private
+ */
+ bluetoothPrivateOnPairingListener_: null,
+
+ /** Called when the dialog is opened. Starts listening for pairing events. */
+ startPairing: function() {
+ if (!this.bluetoothPrivateOnPairingListener_) {
+ this.bluetoothPrivateOnPairingListener_ =
+ this.onBluetoothPrivateOnPairing_.bind(this);
+ this.bluetoothPrivate.onPairing.addListener(
+ this.bluetoothPrivateOnPairingListener_);
+ }
+ },
+
+ /** Called when the dialog is closed. */
+ endPairing: function() {
+ if (this.bluetoothPrivateOnPairingListener_) {
+ this.bluetoothPrivate.onPairing.removeListener(
+ this.bluetoothPrivateOnPairingListener_);
+ this.bluetoothPrivateOnPairingListener_ = null;
+ }
+ this.pairingEvent_ = null;
+ },
+
+ /**
+ * Process bluetoothPrivate.onPairing events.
+ * @param {!chrome.bluetoothPrivate.PairingEvent} event
+ * @private
+ */
+ onBluetoothPrivateOnPairing_: function(event) {
+ if (!this.pairingDevice ||
+ event.device.address != this.pairingDevice.address) {
+ return;
+ }
+ if (event.pairing == PairingEventType.KEYS_ENTERED &&
+ event.passkey === undefined && this.pairingEvent_) {
+ // 'keysEntered' event might not include the updated passkey so preserve
+ // the current one.
+ event.passkey = this.pairingEvent_.passkey;
+ }
+ this.pairingEvent_ = event;
+ },
+
/** @private */
pairingChanged_: function() {
// Auto-close the dialog when pairing completes.
- if (this.pairingDevice && this.pairingDevice.connected) {
+ if (this.pairingDevice.connected) {
this.close();
return;
}
@@ -143,13 +203,11 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
getMessage_: function() {
- if (!this.pairingDevice)
- return '';
var message;
- if (!this.pairingEvent)
+ if (!this.pairingEvent_)
message = 'bluetoothStartConnecting';
else
- message = this.getEventDesc_(this.pairingEvent.pairing);
+ message = this.getEventDesc_(this.pairingEvent_.pairing);
return this.i18n(message, this.pairingDevice.name);
},
@@ -158,8 +216,8 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
showEnterPincode_: function() {
- return !!this.pairingEvent &&
- this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE;
+ return !!this.pairingEvent_ &&
+ this.pairingEvent_.pairing == PairingEventType.REQUEST_PINCODE;
},
/**
@@ -167,8 +225,8 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
showEnterPasskey_: function() {
- return !!this.pairingEvent &&
- this.pairingEvent.pairing == PairingEventType.REQUEST_PASSKEY;
+ return !!this.pairingEvent_ &&
+ this.pairingEvent_.pairing == PairingEventType.REQUEST_PASSKEY;
},
/**
@@ -176,9 +234,9 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
showDisplayPassOrPin_: function() {
- if (!this.pairingEvent)
+ if (!this.pairingEvent_)
return false;
- var pairing = this.pairingEvent.pairing;
+ var pairing = this.pairingEvent_.pairing;
return (
pairing == PairingEventType.DISPLAY_PINCODE ||
pairing == PairingEventType.DISPLAY_PASSKEY ||
@@ -191,8 +249,8 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
showAcceptReject_: function() {
- return !!this.pairingEvent &&
- this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY;
+ return !!this.pairingEvent_ &&
+ this.pairingEvent_.pairing == PairingEventType.CONFIRM_PASSKEY;
},
/**
@@ -200,9 +258,9 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
showConnect_: function() {
- if (!this.pairingEvent)
+ if (!this.pairingEvent_)
return false;
- var pairing = this.pairingEvent.pairing;
+ var pairing = this.pairingEvent_.pairing;
return pairing == PairingEventType.REQUEST_PINCODE ||
pairing == PairingEventType.REQUEST_PASSKEY;
},
@@ -215,7 +273,7 @@ settings.BluetoothPairDeviceBehavior = {
if (!this.showConnect_())
return false;
var inputId =
- (this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE) ?
+ (this.pairingEvent_.pairing == PairingEventType.REQUEST_PINCODE) ?
'#pincode' :
'#passkey';
var paperInput = /** @type {!PaperInputElement} */ (this.$$(inputId));
@@ -229,9 +287,9 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
showDismiss_: function() {
- return (!!this.paringDevice && this.pairingDevice.paired) ||
- (!!this.pairingEvent &&
- this.pairingEvent.pairing == PairingEventType.COMPLETE);
+ return this.pairingDevice.paired ||
+ (!!this.pairingEvent_ &&
+ this.pairingEvent_.pairing == PairingEventType.COMPLETE);
},
/** @private */
@@ -262,12 +320,23 @@ settings.BluetoothPairDeviceBehavior = {
response: response
};
if (response == chrome.bluetoothPrivate.PairingResponse.CONFIRM) {
- var pairing = this.pairingEvent.pairing;
+ var pairing = this.pairingEvent_.pairing;
if (pairing == PairingEventType.REQUEST_PINCODE)
options.pincode = this.$$('#pincode').value;
else if (pairing == PairingEventType.REQUEST_PASSKEY)
options.passkey = parseInt(this.$$('#passkey').value, 10);
}
+ this.bluetoothPrivate.setPairingResponse(options, function() {
+ if (chrome.runtime.lastError) {
+ // TODO(stevenjb): Show error.
+ console.error(
+ 'Error setting pairing response: ' + options.device.name +
+ ': Response: ' + options.response +
+ ': Error: ' + chrome.runtime.lastError.message);
+ }
+ this.close();
+ }.bind(this));
+
this.fire('response', options);
},
@@ -292,19 +361,20 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
getPinDigit_: function(index) {
- if (!this.pairingEvent)
+ if (!this.pairingEvent_)
return '';
var digit = '0';
- var pairing = this.pairingEvent.pairing;
+ var pairing = this.pairingEvent_.pairing;
if (pairing == PairingEventType.DISPLAY_PINCODE &&
- this.pairingEvent.pincode && index < this.pairingEvent.pincode.length) {
- digit = this.pairingEvent.pincode[index];
+ this.pairingEvent_.pincode &&
+ index < this.pairingEvent_.pincode.length) {
+ digit = this.pairingEvent_.pincode[index];
} else if (
- this.pairingEvent.passkey &&
+ this.pairingEvent_.passkey &&
(pairing == PairingEventType.DISPLAY_PASSKEY ||
pairing == PairingEventType.KEYS_ENTERED ||
pairing == PairingEventType.CONFIRM_PASSKEY)) {
- var passkeyString = String(this.pairingEvent.passkey);
+ var passkeyString = String(this.pairingEvent_.passkey);
if (index < passkeyString.length)
digit = passkeyString[index];
}
@@ -317,21 +387,21 @@ settings.BluetoothPairDeviceBehavior = {
* @private
*/
getPinClass_: function(index) {
- if (!this.pairingEvent)
+ if (!this.pairingEvent_)
return '';
- if (this.pairingEvent.pairing == PairingEventType.CONFIRM_PASSKEY)
+ if (this.pairingEvent_.pairing == PairingEventType.CONFIRM_PASSKEY)
return 'confirm';
var cssClass = 'display';
- if (this.pairingEvent.pairing == PairingEventType.DISPLAY_PASSKEY) {
+ if (this.pairingEvent_.pairing == PairingEventType.DISPLAY_PASSKEY) {
if (index == 0)
cssClass += ' next';
else
cssClass += ' untyped';
} else if (
- this.pairingEvent.pairing == PairingEventType.KEYS_ENTERED &&
- this.pairingEvent.enteredKey) {
- var enteredKey = this.pairingEvent.enteredKey; // 1-7
- var lastKey = this.digits.length; // 6
+ this.pairingEvent_.pairing == PairingEventType.KEYS_ENTERED &&
+ this.pairingEvent_.enteredKey) {
+ var enteredKey = this.pairingEvent_.enteredKey; // 1-7
+ var lastKey = this.digits.length; // 6
if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey))
cssClass += ' next';
else if (index > enteredKey)
@@ -360,16 +430,18 @@ Polymer({
},
observers: [
- 'dialogUpdated_(dialogId, pairingEvent)',
+ 'dialogUpdated_(dialogId, pairingEvent_)',
],
open: function() {
+ this.startPairing();
this.pinOrPass = '';
this.getDialog_().showModal();
this.itemWasFocused_ = false;
},
close: function() {
+ this.endPairing();
var dialog = this.getDialog_();
if (dialog.open)
dialog.close();
@@ -409,7 +481,6 @@ Polymer({
onDialogCanceled_: function() {
if (this.dialogId == 'pairDevice')
this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL);
+ this.endPairing();
},
});
-
-})();

Powered by Google App Engine
This is Rietveld 408576698