| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h" | 
| 6 | 6 | 
| 7 #include "base/bind.h" | 7 #include "base/bind.h" | 
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" | 
| 9 #include "base/callback.h" | 9 #include "base/callback.h" | 
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
| 33 const char kConnectCommand[] = "connect"; | 33 const char kConnectCommand[] = "connect"; | 
| 34 const char kCancelCommand[] = "cancel"; | 34 const char kCancelCommand[] = "cancel"; | 
| 35 const char kAcceptCommand[] = "accept"; | 35 const char kAcceptCommand[] = "accept"; | 
| 36 const char kRejectCommand[] = "reject"; | 36 const char kRejectCommand[] = "reject"; | 
| 37 const char kDisconnectCommand[] = "disconnect"; | 37 const char kDisconnectCommand[] = "disconnect"; | 
| 38 const char kForgetCommand[] = "forget"; | 38 const char kForgetCommand[] = "forget"; | 
| 39 | 39 | 
| 40 // |SendDeviceNotification| may include a pairing parameter whose value | 40 // |SendDeviceNotification| may include a pairing parameter whose value | 
| 41 // is one of the following constants instructing the UI to perform a certain | 41 // is one of the following constants instructing the UI to perform a certain | 
| 42 // action. | 42 // action. | 
|  | 43 const char kStartConnecting[] = "bluetoothStartConnecting"; | 
| 43 const char kEnterPinCode[] = "bluetoothEnterPinCode"; | 44 const char kEnterPinCode[] = "bluetoothEnterPinCode"; | 
| 44 const char kEnterPasskey[] = "bluetoothEnterPasskey"; | 45 const char kEnterPasskey[] = "bluetoothEnterPasskey"; | 
| 45 const char kRemotePinCode[] = "bluetoothRemotePinCode"; | 46 const char kRemotePinCode[] = "bluetoothRemotePinCode"; | 
| 46 const char kRemotePasskey[] = "bluetoothRemotePasskey"; | 47 const char kRemotePasskey[] = "bluetoothRemotePasskey"; | 
| 47 const char kConfirmPasskey[] = "bluetoothConfirmPasskey"; | 48 const char kConfirmPasskey[] = "bluetoothConfirmPasskey"; | 
| 48 | 49 | 
| 49 }  // namespace | 50 }  // namespace | 
| 50 | 51 | 
| 51 namespace chromeos { | 52 namespace chromeos { | 
| 52 namespace options { | 53 namespace options { | 
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 257   args->GetString(kUpdateDeviceCommandIndex, &command); | 258   args->GetString(kUpdateDeviceCommandIndex, &command); | 
| 258 | 259 | 
| 259   if (command == kConnectCommand) { | 260   if (command == kConnectCommand) { | 
| 260     int size = args->GetSize(); | 261     int size = args->GetSize(); | 
| 261     if (size > kUpdateDeviceAuthTokenIndex) { | 262     if (size > kUpdateDeviceAuthTokenIndex) { | 
| 262       // PIN code or Passkey entry during the pairing process. | 263       // PIN code or Passkey entry during the pairing process. | 
| 263       std::string auth_token; | 264       std::string auth_token; | 
| 264       args->GetString(kUpdateDeviceAuthTokenIndex, &auth_token); | 265       args->GetString(kUpdateDeviceAuthTokenIndex, &auth_token); | 
| 265 | 266 | 
| 266       if (device->ExpectingPinCode()) { | 267       if (device->ExpectingPinCode()) { | 
|  | 268         DeviceConnecting(device); | 
| 267         // PIN Code is an array of 1 to 16 8-bit bytes, the usual | 269         // PIN Code is an array of 1 to 16 8-bit bytes, the usual | 
| 268         // interpretation, and the one shared by BlueZ, is a UTF-8 string | 270         // interpretation, and the one shared by BlueZ, is a UTF-8 string | 
| 269         // of as many characters that will fit in that space, thus we | 271         // of as many characters that will fit in that space, thus we | 
| 270         // can use the auth token from JavaScript unmodified. | 272         // can use the auth token from JavaScript unmodified. | 
| 271         DVLOG(1) << "PIN Code supplied: " << address << ": " << auth_token; | 273         DVLOG(1) << "PIN Code supplied: " << address << ": " << auth_token; | 
| 272         device->SetPinCode(auth_token); | 274         device->SetPinCode(auth_token); | 
| 273       } else if (device->ExpectingPasskey()) { | 275       } else if (device->ExpectingPasskey()) { | 
|  | 276         DeviceConnecting(device); | 
| 274         // Passkey is a numeric in the range 0-999999, in this case the | 277         // Passkey is a numeric in the range 0-999999, in this case the | 
| 275         // JavaScript code should have ensured the auth token string only | 278         // JavaScript code should have ensured the auth token string only | 
| 276         // contains digits so a simple conversion is sufficient. In the | 279         // contains digits so a simple conversion is sufficient. In the | 
| 277         // failure case, just use 0 since that's the most likely Passkey | 280         // failure case, just use 0 since that's the most likely Passkey | 
| 278         // anyway, and if it's refused the device will request a new one. | 281         // anyway, and if it's refused the device will request a new one. | 
| 279         unsigned passkey = 0; | 282         unsigned passkey = 0; | 
| 280         base::StringToUint(auth_token, &passkey); | 283         base::StringToUint(auth_token, &passkey); | 
| 281 | 284 | 
| 282         DVLOG(1) << "Passkey supplied: " << address << ": " << passkey; | 285         DVLOG(1) << "Passkey supplied: " << address << ": " << passkey; | 
| 283         device->SetPasskey(passkey); | 286         device->SetPasskey(passkey); | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 400 | 403 | 
| 401 void BluetoothOptionsHandler::SendDeviceNotification( | 404 void BluetoothOptionsHandler::SendDeviceNotification( | 
| 402     const device::BluetoothDevice* device, | 405     const device::BluetoothDevice* device, | 
| 403     base::DictionaryValue* params) { | 406     base::DictionaryValue* params) { | 
| 404   base::DictionaryValue js_properties; | 407   base::DictionaryValue js_properties; | 
| 405   js_properties.SetString("name", device->GetName()); | 408   js_properties.SetString("name", device->GetName()); | 
| 406   js_properties.SetString("address", device->address()); | 409   js_properties.SetString("address", device->address()); | 
| 407   js_properties.SetBoolean("paired", device->IsPaired()); | 410   js_properties.SetBoolean("paired", device->IsPaired()); | 
| 408   js_properties.SetBoolean("bonded", device->IsBonded()); | 411   js_properties.SetBoolean("bonded", device->IsBonded()); | 
| 409   js_properties.SetBoolean("connected", device->IsConnected()); | 412   js_properties.SetBoolean("connected", device->IsConnected()); | 
| 410   if (params) { | 413   if (params) | 
| 411     js_properties.MergeDictionary(params); | 414     js_properties.MergeDictionary(params); | 
| 412   } |  | 
| 413   web_ui()->CallJavascriptFunction( | 415   web_ui()->CallJavascriptFunction( | 
| 414       "options.BrowserOptions.addBluetoothDevice", | 416       "options.BrowserOptions.addBluetoothDevice", | 
| 415       js_properties); | 417       js_properties); | 
| 416 } | 418 } | 
| 417 | 419 | 
| 418 void BluetoothOptionsHandler::RequestPinCode(device::BluetoothDevice* device) { | 420 void BluetoothOptionsHandler::RequestPinCode(device::BluetoothDevice* device) { | 
| 419   DictionaryValue params; | 421   DictionaryValue params; | 
| 420   params.SetString("pairing", kEnterPinCode); | 422   params.SetString("pairing", kEnterPinCode); | 
| 421   SendDeviceNotification(device, ¶ms); | 423   SendDeviceNotification(device, ¶ms); | 
| 422 } | 424 } | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 485                                             device::BluetoothDevice* device) { | 487                                             device::BluetoothDevice* device) { | 
| 486   DCHECK(adapter == adapter_.get()); | 488   DCHECK(adapter == adapter_.get()); | 
| 487   DCHECK(device); | 489   DCHECK(device); | 
| 488 | 490 | 
| 489   base::StringValue address(device->address()); | 491   base::StringValue address(device->address()); | 
| 490   web_ui()->CallJavascriptFunction( | 492   web_ui()->CallJavascriptFunction( | 
| 491       "options.BrowserOptions.removeBluetoothDevice", | 493       "options.BrowserOptions.removeBluetoothDevice", | 
| 492       address); | 494       address); | 
| 493 } | 495 } | 
| 494 | 496 | 
|  | 497 void BluetoothOptionsHandler::DeviceConnecting( | 
|  | 498     device::BluetoothDevice* device) { | 
|  | 499   DCHECK(device); | 
|  | 500   DictionaryValue params; | 
|  | 501   params.SetString("pairing", kStartConnecting); | 
|  | 502   SendDeviceNotification(device, ¶ms); | 
|  | 503 } | 
|  | 504 | 
| 495 }  // namespace options | 505 }  // namespace options | 
| 496 }  // namespace chromeos | 506 }  // namespace chromeos | 
| OLD | NEW | 
|---|