OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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-page' is the settings page for managing bluetooth | 7 * 'settings-bluetooth-page' is the settings page for managing bluetooth |
8 * properties and devices. | 8 * properties and devices. |
9 * | 9 * |
10 * Example: | 10 * Example: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 * The ordered list of bluetooth devices. | 66 * The ordered list of bluetooth devices. |
67 * @type {!Array<!chrome.bluetooth.Device>} | 67 * @type {!Array<!chrome.bluetooth.Device>} |
68 */ | 68 */ |
69 deviceList: { | 69 deviceList: { |
70 type: Array, | 70 type: Array, |
71 value: function() { return []; }, | 71 value: function() { return []; }, |
72 }, | 72 }, |
73 | 73 |
74 /** | 74 /** |
75 * Set to the name of the dialog to show. This page uses a single | 75 * Set to the name of the dialog to show. This page uses a single |
76 * paper-dialog to host one of two dialog elements, 'addDevice' or | 76 * paper-dialog to host one of three dialog elements, 'addDevice', |
77 * 'pairDevice'. This allows a seamless transition between adding and | 77 * 'pairDevice', or 'connectError'. This allows a seamless transition |
78 * pairing dialogs. Note: This property should be set before opening the | 78 * between dialogs. Note: This property should be set before opening the |
79 * dialog, and setting the property will not itself cause the dialog to | 79 * dialog and setting the property will not itself cause the dialog to open. |
80 * open. | |
81 */ | 80 */ |
82 dialogId: String, | 81 dialogId: String, |
83 | 82 |
84 /** | 83 /** |
85 * Current Pairing device. | 84 * Current Pairing device. |
86 * @type {?chrome.bluetooth.Device|undefined} | 85 * @type {?chrome.bluetooth.Device|undefined} |
87 */ | 86 */ |
88 pairingDevice: Object, | 87 pairingDevice: Object, |
89 | 88 |
90 /** | 89 /** |
91 * Current Pairing event. | 90 * Current Pairing event. |
92 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined} | 91 * @type {?chrome.bluetoothPrivate.PairingEvent|undefined} |
93 */ | 92 */ |
94 pairingEvent: Object, | 93 pairingEvent: Object, |
95 | 94 |
| 95 /** The translated error message to show when a connect error occurs. */ |
| 96 errorMessage: String, |
| 97 |
96 /** | 98 /** |
97 * Interface for bluetooth calls. May be overriden by tests. | 99 * Interface for bluetooth calls. May be overriden by tests. |
98 * @type {Bluetooth} | 100 * @type {Bluetooth} |
99 */ | 101 */ |
100 bluetooth: { | 102 bluetooth: { |
101 type: Object, | 103 type: Object, |
102 value: chrome.bluetooth, | 104 value: chrome.bluetooth, |
103 }, | 105 }, |
104 | 106 |
105 /** | 107 /** |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // If the device is not paired, show the pairing dialog. | 434 // If the device is not paired, show the pairing dialog. |
433 if (!device.paired) { | 435 if (!device.paired) { |
434 // Set the pairing device and clear any pairing event. | 436 // Set the pairing device and clear any pairing event. |
435 this.pairingDevice = device; | 437 this.pairingDevice = device; |
436 this.pairingEvent = null; | 438 this.pairingEvent = null; |
437 | 439 |
438 this.openDialog_('pairDevice'); | 440 this.openDialog_('pairDevice'); |
439 } | 441 } |
440 | 442 |
441 this.bluetoothPrivate.connect(device.address, function(result) { | 443 this.bluetoothPrivate.connect(device.address, function(result) { |
| 444 var error; |
442 if (chrome.runtime.lastError) { | 445 if (chrome.runtime.lastError) { |
443 console.error( | 446 error = chrome.runtime.lastError.message; |
444 'Error connecting: ' + device.address + | 447 } else { |
445 chrome.runtime.lastError.message); | 448 switch (result) { |
446 // TODO(stevenjb): Show error message insead. | 449 case chrome.bluetoothPrivate.ConnectResultType.ALREADY_CONNECTED: |
| 450 case chrome.bluetoothPrivate.ConnectResultType.AUTH_CANCELED: |
| 451 case chrome.bluetoothPrivate.ConnectResultType.IN_PROGRESS: |
| 452 case chrome.bluetoothPrivate.ConnectResultType.SUCCESS: |
| 453 break; |
| 454 default: |
| 455 error = result; |
| 456 } |
| 457 } |
| 458 |
| 459 if (!error) { |
447 this.closeDialog_(); | 460 this.closeDialog_(); |
| 461 return; |
448 } | 462 } |
| 463 |
| 464 var name = this.getDeviceName_(device); |
| 465 var id = 'bluetooth_connect_' + error; |
| 466 if (this.i18nExists(id)) { |
| 467 this.errorMessage = this.i18n(id, name); |
| 468 } else { |
| 469 this.errorMessage = error; |
| 470 console.error('Unexpected error connecting to: ' + name + ': ' + error); |
| 471 } |
| 472 this.openDialog_('connectError'); |
449 }.bind(this)); | 473 }.bind(this)); |
450 }, | 474 }, |
451 | 475 |
452 /** | 476 /** |
453 * @param {!chrome.bluetooth.Device} device | 477 * @param {!chrome.bluetooth.Device} device |
454 * @private | 478 * @private |
455 */ | 479 */ |
456 disconnectDevice_: function(device) { | 480 disconnectDevice_: function(device) { |
457 this.bluetoothPrivate.disconnectAll(device.address, function() { | 481 this.bluetoothPrivate.disconnectAll(device.address, function() { |
458 if (chrome.runtime.lastError) { | 482 if (chrome.runtime.lastError) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 541 |
518 /** @private */ | 542 /** @private */ |
519 onCloseDialog_: function(event) { this.closeDialog_(); }, | 543 onCloseDialog_: function(event) { this.closeDialog_(); }, |
520 | 544 |
521 /** @private */ | 545 /** @private */ |
522 onDialogOpened_: function() { this.startDiscovery_(); }, | 546 onDialogOpened_: function() { this.startDiscovery_(); }, |
523 | 547 |
524 /** @private */ | 548 /** @private */ |
525 onDialogClosed_: function() { this.stopDiscovery_(); }, | 549 onDialogClosed_: function() { this.stopDiscovery_(); }, |
526 }); | 550 }); |
OLD | NEW |