From f65e79c357b8145e0950e7a68947d08ad02b8822 Mon Sep 17 00:00:00 2001 From: "jennyz@chromium.org" Date: Fri, 1 Feb 2013 22:15:30 +0000 Subject: Fix the crashing issue of bluetooth pairing dialog closed from hosting dialog. Since I have added support for web dialog to fire window.onbeforeunload event when hosting dialog closes(crbug.com/172067), this bug is fixed by just hooking cleaning up code in window.onbeforeunload in js. Do not display error message if user cancels/closes for the pairing dialog, which happens with pairing dialog from settings page, since BluetoothDevice callback code calling into BluetoothPairing.showMessage with ConnectError after the dialog is closed by the user. BUG=172364 Review URL: https://codereview.chromium.org/12090105 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180197 0039d316-1c4b-4281-b951-d872f2087c98 --- .../resources/chromeos/bluetooth_pair_device.js | 7 +++++++ .../chromeos/bluetooth_pair_device_overlay.js | 24 +++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/chrome/browser/resources/chromeos/bluetooth_pair_device.js b/chrome/browser/resources/chromeos/bluetooth_pair_device.js index 9b20449..da2d72c 100644 --- a/chrome/browser/resources/chromeos/bluetooth_pair_device.js +++ b/chrome/browser/resources/chromeos/bluetooth_pair_device.js @@ -12,6 +12,13 @@ OptionsPage.closeOverlay = function() { }; /** + * Listener for the |beforeunload| event. + */ +window.onbeforeunload = function() { + OptionsPage.willClose(); +}; + +/** * DOMContentLoaded handler, sets up the page. */ function load() { diff --git a/chrome/browser/resources/options/chromeos/bluetooth_pair_device_overlay.js b/chrome/browser/resources/options/chromeos/bluetooth_pair_device_overlay.js index 25fae1d..294dd96 100644 --- a/chrome/browser/resources/options/chromeos/bluetooth_pair_device_overlay.js +++ b/chrome/browser/resources/options/chromeos/bluetooth_pair_device_overlay.js @@ -18,6 +18,8 @@ cr.define('options', function() { REMOTE_PIN_CODE: 'bluetoothRemotePinCode', REMOTE_PASSKEY: 'bluetoothRemotePasskey', CONFIRM_PASSKEY: 'bluetoothConfirmPasskey', + CONNECT_FAILED: 'bluetoothConnectFailed', + CANCELED: 'bluetoothPairingCanceled', DISMISSED: 'bluetoothPairingDismissed', // pairing dismissed(succeeded or // canceled). }; @@ -79,8 +81,6 @@ cr.define('options', function() { OptionsPage.prototype.initializePage.call(this); var self = this; $('bluetooth-pair-device-cancel-button').onclick = function() { - chrome.send('updateBluetoothDevice', - [self.device_.address, 'cancel']); OptionsPage.closeOverlay(); }; $('bluetooth-pair-device-reject-button').onclick = function() { @@ -133,7 +133,9 @@ cr.define('options', function() { /** @override */ didClosePage: function() { - if (this.device_.pairing != PAIRING.DISMISSED) { + if (this.device_.pairing != PAIRING.DISMISSED && + this.device_.pairing != PAIRING.CONNECT_FAILED) { + this.device_.pairing = PAIRING.CANCELED; chrome.send('updateBluetoothDevice', [this.device_.address, 'cancel']); } @@ -339,10 +341,18 @@ cr.define('options', function() { * string: address} data Data for constructing the message. */ BluetoothPairing.showMessage = function(data) { - var name = ''; - if (data.address.length > 0) { - name = data.address; - var list = $('bluetooth-paired-devices-list'); + var name = data.address; + if (name.length == 0) + return; + var dialog = BluetoothPairing.getInstance(); + if (name == dialog.device_.address && + dialog.device_.pairing == PAIRING.CANCELED) { + // Do not show any error message after cancelation of the pairing. + return; + } + + var list = $('bluetooth-paired-devices-list'); + if (list) { var index = list.find(name); if (index == undefined) { list = $('bluetooth-unpaired-devices-list'); -- cgit v1.1