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