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
|
// 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_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_
#define CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_
#pragma once
#include <string>
#include "base/compiler_specific.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_manager.h"
#include "chrome/browser/ui/webui/options2/options_ui2.h"
namespace base {
class DictionaryValue;
}
namespace chromeos {
namespace options2 {
// Handler for Bluetooth options on the system options page.
class BluetoothOptionsHandler : public OptionsPageUIHandler,
public chromeos::BluetoothManager::Observer,
public chromeos::BluetoothAdapter::Observer {
public:
BluetoothOptionsHandler();
virtual ~BluetoothOptionsHandler();
// Potential errors during the process of pairing or connecting to a
// Bluetooth device. Each enumerated value is associated with an i18n
// label for display in the Bluetooth UI.
enum ConnectionError {
DEVICE_NOT_FOUND,
INCORRECT_PIN,
CONNECTION_TIMEOUT,
CONNECTION_REJECTED
};
// OptionsPageUIHandler implementation.
virtual void GetLocalizedValues(
base::DictionaryValue* localized_strings) OVERRIDE;
virtual void Initialize() OVERRIDE;
virtual void RegisterMessages() OVERRIDE;
// 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);
// 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(chromeos::BluetoothDevice* device,
base::DictionaryValue* params);
// Displays a passkey for a device, requesting user confirmation that the
// key matches an expected value (value displayed on a smartphone for
// example).
// |device| is the Bluetooth device being paired.
// |passkey| is the passkey to display for confirmation.
void RequestConfirmation(chromeos::BluetoothDevice* device,
int passkey);
// Displays a passkey for a device, which is being typed remotely. During
// the pairing process, this method may be called repeatedly to track the
// number of characters entered. This method is commonly used for pairing
// keyboards.
// |device| is the Bluetooth device being paired.
// |passkey| is the required passkey.
// |entered| is the number of characters that have already been entered on
// the remote device.
void DisplayPasskey(chromeos::BluetoothDevice* device,
int passkey,
int entered);
// Displays a blank field for entering a passkey. The passkey may be
// a set value specified by the manufacturer of the Bluetooth device, or
// on a remote display. The validation is asychronous, and a call is made
// to |ValidatePasskeyCallback| when the passkey entry is complete.
// |device| is the Bluetooth device being paired.
void RequestPasskey(chromeos::BluetoothDevice* device);
// Displays an error that occurred during the pairing or connection process.
// |device| is the Bluetooth device being paired or connected.
// |error| is the type of error that occurred.
void ReportError(chromeos::BluetoothDevice* device, ConnectionError error);
// chromeos::BluetoothManager::Observer override.
virtual void DefaultAdapterChanged(
chromeos::BluetoothAdapter* adapter) OVERRIDE;
// chromeos::BluetoothAdapter::Observer override.
virtual void DiscoveryStarted(const std::string& adapter_id) OVERRIDE;
// chromeos::BluetoothAdapter::Observer override.
virtual void DiscoveryEnded(const std::string& adapter_id) OVERRIDE;
// chromeos::BluetoothAdapter::Observer override.
virtual void DeviceFound(const std::string& adapter_id,
chromeos::BluetoothDevice* device) OVERRIDE;
private:
// Compares |adapter| with our cached default adapter ID and calls
// DefaultAdapterChanged if there has been an unexpected change.
void ValidateDefaultAdapter(chromeos::BluetoothAdapter* adapter);
// Simulates extracting a list of available bluetooth devices.
// Called when emulating ChromeOS from a desktop environment.
void GenerateFakeDeviceList();
// Simulates the discovery or pairing of a Bluetooth device. Used when
// emulating ChromeOS from a desktop environment.
// |name| is the display name for the device.
// |address| is the unique Mac address of the device.
// |icon| is the base name of the icon to use for the device and corresponds
// to the general device category (e.g. mouse or keyboard).
// |paired| indicates if the device is paired.
// |connected| indicates if the device is connected.
// |pairing| indicates the type of pairing operation.
void GenerateFakeDevice(const std::string& name,
const std::string& address,
const std::string& icon,
bool paired,
bool connected,
const std::string& pairing);
// The id of the current default bluetooth adapter.
// The empty string represents "none".
std::string default_adapter_id_;
DISALLOW_COPY_AND_ASSIGN(BluetoothOptionsHandler);
};
} // namespace options2
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_CHROMEOS_BLUETOOTH_OPTIONS_HANDLER2_H_
|