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