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 * @fileoverview | 6 * @fileoverview |
7 * 'settings-bluetooth-subpage' is the settings subpage for managing bluetooth | 7 * 'settings-bluetooth-subpage' is the settings subpage for managing bluetooth |
8 * properties and devices. | 8 * properties and devices. |
9 */ | 9 */ |
10 | 10 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 /** | 249 /** |
250 * If bluetooth is enabled, request the complete list of devices and update | 250 * If bluetooth is enabled, request the complete list of devices and update |
251 * this.deviceList_. | 251 * this.deviceList_. |
252 * @private | 252 * @private |
253 */ | 253 */ |
254 updateDeviceList_: function() { | 254 updateDeviceList_: function() { |
255 if (!this.bluetoothToggleState) { | 255 if (!this.bluetoothToggleState) { |
256 this.deviceList_ = []; | 256 this.deviceList_ = []; |
257 return; | 257 return; |
258 } | 258 } |
259 this.bluetooth.getDevices(function(devices) { | 259 this.bluetooth.getDevices(devices => { |
260 this.deviceList_ = devices; | 260 this.deviceList_ = devices; |
261 }.bind(this)); | 261 }); |
262 }, | 262 }, |
263 | 263 |
264 /** | 264 /** |
265 * Process bluetooth.onDeviceAdded and onDeviceChanged events. | 265 * Process bluetooth.onDeviceAdded and onDeviceChanged events. |
266 * @param {!chrome.bluetooth.Device} device | 266 * @param {!chrome.bluetooth.Device} device |
267 * @private | 267 * @private |
268 */ | 268 */ |
269 onBluetoothDeviceUpdated_: function(device) { | 269 onBluetoothDeviceUpdated_: function(device) { |
270 var address = device.address; | 270 var address = device.address; |
271 if (this.dialogId_ && this.pairingDevice_ && | 271 if (this.dialogId_ && this.pairingDevice_ && |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 * @param {!chrome.bluetooth.Device} device | 378 * @param {!chrome.bluetooth.Device} device |
379 * @private | 379 * @private |
380 */ | 380 */ |
381 connectDevice_: function(device) { | 381 connectDevice_: function(device) { |
382 // If the device is not paired, show the pairing dialog before connecting. | 382 // If the device is not paired, show the pairing dialog before connecting. |
383 if (!device.paired) { | 383 if (!device.paired) { |
384 this.pairingDevice_ = device; | 384 this.pairingDevice_ = device; |
385 this.openDialog_('pairDevice'); | 385 this.openDialog_('pairDevice'); |
386 } | 386 } |
387 | 387 |
388 this.bluetoothPrivate.connect(device.address, function(result) { | 388 this.bluetoothPrivate.connect(device.address, result => { |
389 var error; | 389 var error; |
390 if (chrome.runtime.lastError) { | 390 if (chrome.runtime.lastError) { |
391 error = chrome.runtime.lastError.message; | 391 error = chrome.runtime.lastError.message; |
392 } else { | 392 } else { |
393 switch (result) { | 393 switch (result) { |
394 case chrome.bluetoothPrivate.ConnectResultType.IN_PROGRESS: | 394 case chrome.bluetoothPrivate.ConnectResultType.IN_PROGRESS: |
395 return; // Do not close the dialog | 395 return; // Do not close the dialog |
396 case chrome.bluetoothPrivate.ConnectResultType.ALREADY_CONNECTED: | 396 case chrome.bluetoothPrivate.ConnectResultType.ALREADY_CONNECTED: |
397 case chrome.bluetoothPrivate.ConnectResultType.AUTH_CANCELED: | 397 case chrome.bluetoothPrivate.ConnectResultType.AUTH_CANCELED: |
398 case chrome.bluetoothPrivate.ConnectResultType.SUCCESS: | 398 case chrome.bluetoothPrivate.ConnectResultType.SUCCESS: |
(...skipping 10 matching lines...) Expand all Loading... |
409 | 409 |
410 var name = device.name || device.address; | 410 var name = device.name || device.address; |
411 var id = 'bluetooth_connect_' + error; | 411 var id = 'bluetooth_connect_' + error; |
412 if (this.i18nExists(id)) { | 412 if (this.i18nExists(id)) { |
413 this.errorMessage_ = this.i18n(id, name); | 413 this.errorMessage_ = this.i18n(id, name); |
414 } else { | 414 } else { |
415 this.errorMessage_ = error; | 415 this.errorMessage_ = error; |
416 console.error('Unexpected error connecting to: ' + name + ': ' + error); | 416 console.error('Unexpected error connecting to: ' + name + ': ' + error); |
417 } | 417 } |
418 this.openDialog_('connectError'); | 418 this.openDialog_('connectError'); |
419 }.bind(this)); | 419 }); |
420 }, | 420 }, |
421 | 421 |
422 /** | 422 /** |
423 * @param {!chrome.bluetooth.Device} device | 423 * @param {!chrome.bluetooth.Device} device |
424 * @private | 424 * @private |
425 */ | 425 */ |
426 disconnectDevice_: function(device) { | 426 disconnectDevice_: function(device) { |
427 this.bluetoothPrivate.disconnectAll(device.address, function() { | 427 this.bluetoothPrivate.disconnectAll(device.address, function() { |
428 if (chrome.runtime.lastError) { | 428 if (chrome.runtime.lastError) { |
429 console.error( | 429 console.error( |
430 'Error disconnecting: ' + device.address + | 430 'Error disconnecting: ' + device.address + |
431 chrome.runtime.lastError.message); | 431 chrome.runtime.lastError.message); |
432 } | 432 } |
433 }); | 433 }); |
434 }, | 434 }, |
435 | 435 |
436 /** | 436 /** |
437 * @param {!chrome.bluetooth.Device} device | 437 * @param {!chrome.bluetooth.Device} device |
438 * @private | 438 * @private |
439 */ | 439 */ |
440 forgetDevice_: function(device) { | 440 forgetDevice_: function(device) { |
441 this.bluetoothPrivate.forgetDevice(device.address, function() { | 441 this.bluetoothPrivate.forgetDevice(device.address, () => { |
442 if (chrome.runtime.lastError) { | 442 if (chrome.runtime.lastError) { |
443 console.error( | 443 console.error( |
444 'Error forgetting: ' + device.name + ': ' + | 444 'Error forgetting: ' + device.name + ': ' + |
445 chrome.runtime.lastError.message); | 445 chrome.runtime.lastError.message); |
446 } | 446 } |
447 this.updateDeviceList_(); | 447 this.updateDeviceList_(); |
448 }.bind(this)); | 448 }); |
449 }, | 449 }, |
450 | 450 |
451 /** | 451 /** |
452 * @param {string} dialogId | 452 * @param {string} dialogId |
453 * @private | 453 * @private |
454 */ | 454 */ |
455 openDialog_: function(dialogId) { | 455 openDialog_: function(dialogId) { |
456 if (this.dialogId_) { | 456 if (this.dialogId_) { |
457 // Dialog already opened, just update the contents. | 457 // Dialog already opened, just update the contents. |
458 this.dialogId_ = dialogId; | 458 this.dialogId_ = dialogId; |
459 return; | 459 return; |
460 } | 460 } |
461 this.dialogId_ = dialogId; | 461 this.dialogId_ = dialogId; |
462 // Call flush so that the dialog gets sized correctly before it is opened. | 462 // Call flush so that the dialog gets sized correctly before it is opened. |
463 Polymer.dom.flush(); | 463 Polymer.dom.flush(); |
464 this.$.deviceDialog.open(); | 464 this.$.deviceDialog.open(); |
465 }, | 465 }, |
466 | 466 |
467 /** @private */ | 467 /** @private */ |
468 onDialogClose_: function() { | 468 onDialogClose_: function() { |
469 this.dialogId_ = ''; | 469 this.dialogId_ = ''; |
470 this.pairingDevice_ = undefined; | 470 this.pairingDevice_ = undefined; |
471 // The list is dynamic so focus the first item. | 471 // The list is dynamic so focus the first item. |
472 var device = this.$$('#unpairedContainer bluetooth-device-list-item'); | 472 var device = this.$$('#unpairedContainer bluetooth-device-list-item'); |
473 if (device) | 473 if (device) |
474 device.focus(); | 474 device.focus(); |
475 }, | 475 }, |
476 }); | 476 }); |
OLD | NEW |