Chromium Code Reviews| 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 f700878bf38254bd346678f34323608a805d1d43..82aa144ad7774b8cc4118b214538aa586c4e39c7 100644 |
| --- a/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js |
| +++ b/chrome/browser/resources/settings/bluetooth_page/bluetooth_device_dialog.js |
| @@ -46,9 +46,7 @@ settings.BluetoothAddDeviceBehavior = { |
| * @return {boolean} |
| * @private |
| */ |
| - deviceNotPaired_: function(device) { |
| - return !device.paired; |
| - }, |
| + deviceNotPaired_: function(device) { return !device.paired; }, |
| /** |
| * @param {!Array<!chrome.bluetooth.Device>} deviceList |
| @@ -65,7 +63,7 @@ settings.BluetoothAddDeviceBehavior = { |
| */ |
| onDeviceEvent_: function(e) { |
| this.fire('device-event', e.detail); |
| - /** @type {Event} */(e).stopPropagation(); |
| + /** @type {Event} */ (e).stopPropagation(); |
| }, |
| }; |
| @@ -84,6 +82,9 @@ settings.BluetoothPairDeviceBehavior = { |
| */ |
| pairingEvent: Object, |
| + /** Pincode or passkey value, used to trigger connect enabled changes. */ |
| + pinorpass: String, |
| + |
| /** |
| * @const |
| * @type {!Array<number>} |
| @@ -110,6 +111,7 @@ settings.BluetoothPairDeviceBehavior = { |
| this.fire('close-dialog', ''); |
| return; |
| } |
| + this.pinorpass = ''; |
| }, |
| /** |
| @@ -184,14 +186,27 @@ settings.BluetoothPairDeviceBehavior = { |
| if (!pairingEvent) |
| return false; |
| var pairing = pairingEvent.pairing; |
| - if (pairing == PairingEventType.REQUEST_PINCODE) { |
| - var pincode = /** @type {{invalid: boolean}} */(this.$.pincode); |
| - return !pincode.invalid; |
| - } else if (pairing == PairingEventType.REQUEST_PASSKEY) { |
| - var passkey = /** @type {{invalid: boolean}} */(this.$.passkey); |
| - return !passkey.invalid; |
| - } |
| - return false; |
| + return pairing == PairingEventType.REQUEST_PINCODE || |
| + pairing == PairingEventType.REQUEST_PASSKEY; |
| + }, |
| + |
| + /** |
| + * @param {?chrome.bluetoothPrivate.PairingEvent} pairingEvent |
| + * @param {string} pinorpass Unused; call is triggered when this changes. |
| + * @return {boolean} |
| + * @private |
| + */ |
| + enableConnect_: function(pairingEvent, pinorpass) { |
| + if (!this.showConnect_(this.pairingEvent)) |
| + return false; |
| + var inputId = |
| + (this.pairingEvent.pairing == PairingEventType.REQUEST_PINCODE) ? |
| + '#pincode' : |
| + '#passkey'; |
| + var paperInput = /** @type {!PaperInputElement} */ (this.$$(inputId)); |
| + assert(paperInput); |
| + var value = paperInput.value; |
| + return value != undefined && value != '' && paperInput.validate(); |
|
Dan Beam
2016/07/13 02:21:45
return !!value && paperInput.validate();
stevenjb
2016/07/13 17:12:24
That's not quite the same, e.g. if value were 0, b
Dan Beam
2016/07/16 00:35:11
0 == ''
mind == blown
stevenjb
2016/07/16 01:07:03
Yeah, that should have been "value !== ''". I fric
|
| }, |
| /** |
| @@ -235,9 +250,9 @@ settings.BluetoothPairDeviceBehavior = { |
| if (response == chrome.bluetoothPrivate.PairingResponse.CONFIRM) { |
| var pairing = this.pairingEvent.pairing; |
| if (pairing == PairingEventType.REQUEST_PINCODE) |
| - options.pincode = this.$.pincode.value; |
| + options.pincode = this.$$('#pincode').value; |
| else if (pairing == PairingEventType.REQUEST_PASSKEY) |
| - options.passkey = parseInt(this.$.passkey.value, 10); |
| + options.passkey = parseInt(this.$$('#passkey').value, 10); |
| } |
| this.fire('response', options); |
| }, |
| @@ -254,7 +269,7 @@ settings.BluetoothPairDeviceBehavior = { |
| eventType == PairingEventType.REQUEST_AUTHORIZATION) { |
| return 'bluetoothStartConnecting'; |
| } |
| - return 'bluetooth_' + /** @type {string} */(eventType); |
| + return 'bluetooth_' + /** @type {string} */ (eventType); |
| }, |
| /** |
| @@ -271,10 +286,10 @@ settings.BluetoothPairDeviceBehavior = { |
| if (pairing == PairingEventType.DISPLAY_PINCODE && pairingEvent.pincode && |
| index < pairingEvent.pincode.length) { |
| digit = pairingEvent.pincode[index]; |
| - } else if (pairingEvent.passkey && |
| - (pairing == PairingEventType.DISPLAY_PASSKEY || |
| - pairing == PairingEventType.KEYS_ENTERED || |
| - pairing == PairingEventType.CONFIRM_PASSKEY)) { |
| + } else if ( |
| + pairingEvent.passkey && (pairing == PairingEventType.DISPLAY_PASSKEY || |
| + pairing == PairingEventType.KEYS_ENTERED || |
| + pairing == PairingEventType.CONFIRM_PASSKEY)) { |
|
Dan Beam
2016/07/13 02:21:45
is clang format doing these things?
stevenjb
2016/07/13 17:12:24
Yes.
|
| var passkeyString = String(pairingEvent.passkey); |
| if (index < passkeyString.length) |
| digit = passkeyString[index]; |
| @@ -303,7 +318,7 @@ settings.BluetoothPairDeviceBehavior = { |
| pairingEvent.pairing == PairingEventType.KEYS_ENTERED && |
| pairingEvent.enteredKey) { |
| var enteredKey = pairingEvent.enteredKey; // 1-7 |
| - var lastKey = this.digits.length; // 6 |
| + var lastKey = this.digits.length; // 6 |
| if ((index == -1 && enteredKey > lastKey) || (index + 1 == enteredKey)) |
| cssClass += ' next'; |
| else if (index > enteredKey) |
| @@ -324,21 +339,27 @@ Polymer({ |
| properties: { |
| /** Which version of this dialog to show (adding or pairing). */ |
| - dialogType: String, |
| + dialogId: String, |
| }, |
| - /** @private */ |
| - deviceListChanged_: function(e) { |
| - this.$.dialog.notifyResize(); |
| + open: function() { |
| + this.pinorpass = ''; |
| + this.$.dialog.open(); |
| }, |
| + close: function() { this.$.dialog.close(); }, |
| + |
| + /** @private */ |
| + deviceListChanged_: function(e) { this.$.dialog.notifyResize(); }, |
| + |
| /** |
| - * @param {string} dialogType |
| - * @return {string} The title of for that |dialogType|. |
| + * @param {string} dialogId |
| + * @return {string} The title of for that |dialogId|. |
| */ |
| - getTitle_: function(dialogType) { |
| - return this.i18n(dialogType == 'addDevice' ? |
| - 'bluetoothAddDevicePageTitle' : 'bluetoothPairDevicePageTitle'); |
| + getTitle_: function(dialogId) { |
| + return this.i18n( |
| + dialogId == 'addDevice' ? 'bluetoothAddDevicePageTitle' : |
| + 'bluetoothPairDevicePageTitle'); |
| }, |
| /** |
| @@ -361,22 +382,12 @@ Polymer({ |
| /** @private */ |
| onIronOverlayCanceled_: function() { |
| - if (this.dialogType == 'pairDevice') |
| + if (this.dialogId == 'pairDevice') |
| this.sendResponse_(chrome.bluetoothPrivate.PairingResponse.CANCEL); |
| }, |
| /** @private */ |
| - onIronOverlayClosed_: function() { |
| - this.fire('close-dialog', ''); |
| - }, |
| - |
| - open: function() { |
| - this.$.dialog.open(); |
| - }, |
| - |
| - close: function() { |
| - this.$.dialog.close(); |
| - }, |
| + onIronOverlayClosed_: function() { this.fire('close-dialog', ''); }, |
| }); |
| })(); |