1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
#include <string>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
#include "chrome/browser/ui/webui/options/options_ui.h"
namespace base {
class DictionaryValue;
}
namespace chromeos {
namespace options {
// Handler for Bluetooth options on the system options page.
class BluetoothOptionsHandler : public ::options::OptionsPageUIHandler,
public chromeos::BluetoothAdapter::Observer,
public BluetoothDevice::PairingDelegate {
public:
BluetoothOptionsHandler();
virtual ~BluetoothOptionsHandler();
// OptionsPageUIHandler implementation.
virtual void GetLocalizedValues(
base::DictionaryValue* localized_strings) OVERRIDE;
virtual void RegisterMessages() OVERRIDE;
virtual void InitializeHandler() OVERRIDE;
virtual void InitializePage() OVERRIDE;
// Sends a notification to the Web UI of the status of a Bluetooth device.
// |device| is the Bluetooth device.
// |params| is an optional set of parameters.
void SendDeviceNotification(const BluetoothDevice* device,
base::DictionaryValue* params);
// BluetoothDevice::PairingDelegate override.
//
// This method will be called when the Bluetooth daemon requires a
// PIN Code for authentication of the device |device|, the UI will display
// a blank entry form to obtain the PIN code from the user.
//
// PIN Codes are generally required for Bluetooth 2.0 and earlier devices
// for which there is no automatic pairing or special handling.
virtual void RequestPinCode(BluetoothDevice* device) OVERRIDE;
// BluetoothDevice::PairingDelegate override.
//
// This method will be called when the Bluetooth daemon requires a
// Passkey for authentication of the device |device|, the UI will display
// a blank entry form to obtain the passkey from the user (a numeric in the
// range 0-999999).
//
// Passkeys are generally required for Bluetooth 2.1 and later devices
// which cannot provide input or display on their own, and don't accept
// passkey-less pairing.
virtual void RequestPasskey(BluetoothDevice* device) OVERRIDE;
// BluetoothDevice::PairingDelegate override.
//
// This method will be called when the Bluetooth daemon requires that the
// user enter the PIN code |pincode| into the device |device| so that it
// may be authenticated, the UI will display the PIN code with accompanying
// instructions.
//
// This is used for Bluetooth 2.0 and earlier keyboard devices, the
// |pincode| will always be a six-digit numeric in the range 000000-999999
// for compatibilty with later specifications.
virtual void DisplayPinCode(BluetoothDevice* device,
const std::string& pincode) OVERRIDE;
// BluetoothDevice::PairingDelegate override.
//
// This method will be called when the Bluetooth daemon requires that the
// user enter the Passkey |passkey| into the device |device| so that it
// may be authenticated, the UI will display the passkey with accompanying
// instructions.
//
// This is used for Bluetooth 2.1 and later devices that support input
// but not display, such as keyboards. The Passkey is a numeric in the
// range 0-999999 and should be always presented zero-padded to six
// digits.
virtual void DisplayPasskey(BluetoothDevice* device,
uint32 passkey) OVERRIDE;
// BluetoothDevice::PairingDelegate override.
//
// This method will be called when the Bluetooth daemon requires that the
// user confirm that the Passkey |passkey| is displayed on the screen
// of the device |device| so that it may be authenticated, the UI will
// display the passkey with accompanying instructions.
//
// This is used for Bluetooth 2.1 and later devices that support display,
// such as other computers or phones. The Passkey is a numeric in the
// range 0-999999 and should be always present zero-padded to six
// digits.
virtual void ConfirmPasskey(BluetoothDevice* device,
uint32 passkey) OVERRIDE;
// BluetoothDevice::PairingDelegate override.
//
// This method will be called when any previous DisplayPinCode(),
// DisplayPasskey() or ConfirmPasskey() request should be concluded
// and removed from the user.
virtual void DismissDisplayOrConfirm() OVERRIDE;
// Displays a Bluetooth error.
// |error| maps to a localized resource for the error message.
// |address| is the address of the Bluetooth device. May be an empty
// string if the error is not specific to a single device.
void ReportError(const std::string& error, const std::string& address);
// BluetoothAdapter::Observer implementation.
virtual void AdapterPresentChanged(BluetoothAdapter* adapter,
bool present) OVERRIDE;
virtual void AdapterPoweredChanged(BluetoothAdapter* adapter,
bool powered) OVERRIDE;
virtual void DeviceAdded(BluetoothAdapter* adapter,
BluetoothDevice* device) OVERRIDE;
virtual void DeviceChanged(BluetoothAdapter* adapter,
BluetoothDevice* device) OVERRIDE;
virtual void DeviceRemoved(BluetoothAdapter* adapter,
BluetoothDevice* device) OVERRIDE;
private:
// Called by BluetoothAdapter in response to a failure to change the
// power status of the adapter.
void EnableChangeError();
// Called by BluetoothAdapter in response to a failure to set the adapter
// into discovery mode.
void FindDevicesError();
// Called by BluetoothAdapter in response to a failure to remove the adapter
// from discovery mode.
void StopDiscoveryError();
// Called by BluetoothDevice in response to a failure to connect to the
// device with bluetooth address |address|.
void ConnectError(const std::string& address);
// Called by BluetoothDevice in response to a failure to disconnect the
// device with bluetooth address |address|.
void DisconnectError(const std::string& address);
// Called by BluetoothDevice in response to a failure to disconnect and
// unpair the device with bluetooth address |address|.
void ForgetError(const std::string& address);
// Called when the 'Enable bluetooth' checkbox value is changed.
// |args| will contain the checkbox checked state as a string
// ("true" or "false").
void EnableChangeCallback(const base::ListValue* args);
// Called when the 'Find Devices' button is pressed from the Bluetooth
// ssettings.
// |args| will be an empty list.
void FindDevicesCallback(const base::ListValue* args);
// Called when the user requests to connect to or disconnect from a Bluetooth
// device.
// |args| will be a list containing two or three arguments, the first argument
// is the device ID and the second is the requested action. If a third
// argument is present, it is the passkey for pairing confirmation.
void UpdateDeviceCallback(const base::ListValue* args);
// Called when the "Add a device" dialog closes to stop the discovery
// process.
// |args| will be an empty list.
void StopDiscoveryCallback(const base::ListValue* args);
// Called when the list of paired devices is initialized in order to
// populate the list.
// |args| will be an empty list.
void GetPairedDevicesCallback(const base::ListValue* args);
// Default bluetooth adapter, used for all operations.
scoped_refptr<BluetoothAdapter> adapter_;
// Weak pointer factory for generating 'this' pointers that might live longer
// than this object does.
base::WeakPtrFactory<BluetoothOptionsHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler);
};
} // namespace options
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER_H_
|