diff options
author | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 22:09:48 +0000 |
---|---|---|
committer | deymo@chromium.org <deymo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 22:09:48 +0000 |
commit | 874a8467c0eed9b3d2be78dd1175c888ac7bc3cb (patch) | |
tree | 6e843af714750919c022178a98d5db878e227920 | |
parent | 8c14843b5e2ee88f9d7c090618a75e557b88eef7 (diff) | |
download | chromium_src-874a8467c0eed9b3d2be78dd1175c888ac7bc3cb.zip chromium_src-874a8467c0eed9b3d2be78dd1175c888ac7bc3cb.tar.gz chromium_src-874a8467c0eed9b3d2be78dd1175c888ac7bc3cb.tar.bz2 |
Bluetooth: Cache the pairing passkey and pincode in the option handler
This patch persist the value of pairing, pincode, passkey and entered
members of the device object sent to the JS UI while updating the
pairing overlay. The passkey and pincode values are persisted only
when the pairing value implies their existence.
This patch also includes a small bugfix in the DBus agent service
provider to properly parse the "entered" argument.
BUG=233786
TEST=Manual test.
Manual test:
============
Take a 2.1 Bluetooth Keyboard (like the Motorola KZ450) and attempt
a pairing with it. While typing the passkey in the keyboard, the keys
on the screen should change the style as you type them.
Note: Typing the wrong key will also highlight the keys on the screen
and that's ok.
Review URL: https://chromiumcodereview.appspot.com/14036016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195909 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 63 insertions, 13 deletions
diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc index 52c316b..5fa3505 100644 --- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc @@ -47,13 +47,19 @@ const char kRemotePinCode[] = "bluetoothRemotePinCode"; const char kRemotePasskey[] = "bluetoothRemotePasskey"; const char kConfirmPasskey[] = "bluetoothConfirmPasskey"; +// An invalid |entered| value to represent the "undefined" value. +const int kInvalidEntered = 0xFFFF; + } // namespace namespace chromeos { namespace options { -BluetoothOptionsHandler::BluetoothOptionsHandler() : discovering_(false), - weak_ptr_factory_(this) { +BluetoothOptionsHandler::BluetoothOptionsHandler() : + discovering_(false), + pairing_device_passkey_(1000000), + pairing_device_entered_(kInvalidEntered), + weak_ptr_factory_(this) { } BluetoothOptionsHandler::~BluetoothOptionsHandler() { @@ -418,6 +424,35 @@ void BluetoothOptionsHandler::SendDeviceNotification( js_properties.SetBoolean("connectable", device->IsConnectable()); if (params) js_properties.MergeDictionary(params); + + // Use the cached values to update js_property. + if (device->GetAddress() == pairing_device_address_) { + std::string pairing; + if (!js_properties.GetString("pairing", &pairing)) { + pairing = pairing_device_pairing_; + js_properties.SetString("pairing", pairing); + } + if (pairing == kRemotePinCode && !js_properties.HasKey("pincode")) + js_properties.SetString("pincode", pairing_device_pincode_); + if (pairing == kRemotePasskey && !js_properties.HasKey("passkey")) + js_properties.SetInteger("passkey", pairing_device_passkey_); + if ((pairing == kRemotePinCode || pairing == kRemotePasskey) && + !js_properties.HasKey("entered") && + pairing_device_entered_ != kInvalidEntered) { + js_properties.SetInteger("entered", pairing_device_entered_); + } + } + + // Update the cache with the new information. + if (js_properties.HasKey("pairing")) { + pairing_device_address_ = device->GetAddress(); + js_properties.GetString("pairing", &pairing_device_pairing_); + js_properties.GetString("pincode", &pairing_device_pincode_); + js_properties.GetInteger("passkey", &pairing_device_passkey_); + if (!js_properties.GetInteger("entered", &pairing_device_entered_)) + pairing_device_entered_ = kInvalidEntered; + } + web_ui()->CallJavascriptFunction( "options.BrowserOptions.addBluetoothDevice", js_properties); @@ -467,6 +502,10 @@ void BluetoothOptionsHandler::ConfirmPasskey(device::BluetoothDevice* device, } void BluetoothOptionsHandler::DismissDisplayOrConfirm() { + // Invalidate the local cache. + pairing_device_address_.clear(); + pairing_device_entered_ = kInvalidEntered; + web_ui()->CallJavascriptFunction( "options.BluetoothPairing.dismissDialog"); } @@ -501,6 +540,12 @@ void BluetoothOptionsHandler::DeviceRemoved(device::BluetoothAdapter* adapter, DCHECK(adapter == adapter_.get()); DCHECK(device); + // Invalidate the local cache if the pairing device is removed. + if (pairing_device_address_ == device->GetAddress()) { + pairing_device_address_.clear(); + pairing_device_entered_ = kInvalidEntered; + } + base::StringValue address(device->GetAddress()); web_ui()->CallJavascriptFunction( "options.BrowserOptions.removeBluetoothDevice", diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h index be7108e..44302ce 100644 --- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h +++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h @@ -213,6 +213,13 @@ class BluetoothOptionsHandler // True while performing device discovery. bool discovering_; + // Cached information about the current pairing device, if any. + std::string pairing_device_address_; + std::string pairing_device_pairing_; + std::string pairing_device_pincode_; + int pairing_device_passkey_; + int pairing_device_entered_; + // Weak pointer factory for generating 'this' pointers that might live longer // than this object does. base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_; diff --git a/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc b/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc index 6501cef..3878df6 100644 --- a/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc +++ b/chromeos/dbus/experimental_bluetooth_agent_service_provider.cc @@ -236,18 +236,15 @@ class ExperimentalBluetoothAgentServiceProviderImpl dbus::MessageReader reader(method_call); dbus::ObjectPath device_path; uint32 passkey; - int16 entered; + uint16 entered; if (!reader.PopObjectPath(&device_path) || - !reader.PopUint32(&passkey)) { + !reader.PopUint32(&passkey) || + !reader.PopUint16(&entered)) { LOG(WARNING) << "DisplayPasskey called with incorrect paramters: " << method_call->ToString(); return; } - // This wasn't always provided, play it safe... - if (!reader.PopInt16(&entered)) - entered = 0; - delegate_->DisplayPasskey(device_path, passkey, entered); response_sender.Run(dbus::Response::FromMethodCall(method_call)); diff --git a/chromeos/dbus/experimental_bluetooth_agent_service_provider.h b/chromeos/dbus/experimental_bluetooth_agent_service_provider.h index 414c8db..ff264f9 100644 --- a/chromeos/dbus/experimental_bluetooth_agent_service_provider.h +++ b/chromeos/dbus/experimental_bluetooth_agent_service_provider.h @@ -114,7 +114,7 @@ class CHROMEOS_EXPORT ExperimentalBluetoothAgentServiceProvider { // As the user enters the passkey onto the device, |entered| will be // updated to reflect the number of digits entered so far. virtual void DisplayPasskey(const dbus::ObjectPath& device_path, - uint32 passkey, int16 entered) = 0; + uint32 passkey, uint16 entered) = 0; // This method will be called when the Bluetooth daemon requires that the // user confirm that the Passkey |passkey| is displayed on the screen diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc index 46d4ae3..54d39d5 100644 --- a/chromeos/dbus/fake_bluetooth_device_client.cc +++ b/chromeos/dbus/fake_bluetooth_device_client.cc @@ -805,7 +805,7 @@ void FakeBluetoothDeviceClient::ConfirmationCallback( } void FakeBluetoothDeviceClient::SimulateKeypress( - int16 entered, + uint16 entered, const dbus::ObjectPath& object_path, const base::Closure& callback, const ErrorCallback& error_callback) { diff --git a/chromeos/dbus/fake_bluetooth_device_client.h b/chromeos/dbus/fake_bluetooth_device_client.h index 69c2745..861121f 100644 --- a/chromeos/dbus/fake_bluetooth_device_client.h +++ b/chromeos/dbus/fake_bluetooth_device_client.h @@ -168,7 +168,7 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient const ErrorCallback& error_callback, ExperimentalBluetoothAgentServiceProvider::Delegate::Status status); void SimulateKeypress( - int16 entered, + uint16 entered, const dbus::ObjectPath& object_path, const base::Closure& callback, const ErrorCallback& error_callback); diff --git a/device/bluetooth/bluetooth_device_experimental_chromeos.cc b/device/bluetooth/bluetooth_device_experimental_chromeos.cc index 4b99dbe..9183803 100644 --- a/device/bluetooth/bluetooth_device_experimental_chromeos.cc +++ b/device/bluetooth/bluetooth_device_experimental_chromeos.cc @@ -341,7 +341,8 @@ void BluetoothDeviceExperimentalChromeOS::RequestPasskey( void BluetoothDeviceExperimentalChromeOS::DisplayPasskey( const dbus::ObjectPath& device_path, - uint32 passkey, int16 entered) { + uint32 passkey, + uint16 entered) { DCHECK(agent_.get()); DCHECK(device_path == object_path_); VLOG(1) << object_path_.value() << ": DisplayPasskey: " << passkey diff --git a/device/bluetooth/bluetooth_device_experimental_chromeos.h b/device/bluetooth/bluetooth_device_experimental_chromeos.h index a6b838c..8433f8e 100644 --- a/device/bluetooth/bluetooth_device_experimental_chromeos.h +++ b/device/bluetooth/bluetooth_device_experimental_chromeos.h @@ -91,7 +91,7 @@ class BluetoothDeviceExperimentalChromeOS virtual void RequestPasskey(const dbus::ObjectPath& device_path, const PasskeyCallback& callback) OVERRIDE; virtual void DisplayPasskey(const dbus::ObjectPath& device_path, - uint32 passkey, int16 entered) OVERRIDE; + uint32 passkey, uint16 entered) OVERRIDE; virtual void RequestConfirmation(const dbus::ObjectPath& device_path, uint32 passkey, const ConfirmationCallback& callback) |