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
content / browser / bluetooth / web_bluetooth_pairing_manager_delegate.h [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_PAIRING_MANAGER_DELEGATE_H_
#define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_PAIRING_MANAGER_DELEGATE_H_
#include <string>
#include "base/functional/callback_forward.h"
#include "content/public/browser/bluetooth_delegate.h"
#include "device/bluetooth/bluetooth_device.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
namespace content {
// A set of functions needed by whatever object (usually
// WebBluetoothServiceImpl) that embeds the WebBluetoothPairingManager and is
// separated into a separate interface for readability and testing purposes.
class WebBluetoothPairingManagerDelegate {
public:
// Return the cached device ID for the given characteric instance ID.
// The returned device ID may be invalid - check before use.
virtual blink::WebBluetoothDeviceId GetCharacteristicDeviceID(
const std::string& characteristic_instance_id) = 0;
// Return the cached device ID for the given descriptor instance ID.
// The returned device ID may be invalid - check before use.
virtual blink::WebBluetoothDeviceId GetDescriptorDeviceId(
const std::string& descriptor_instance_id) = 0;
// Return the cached device ID for the given |device_address|.
// The returned device ID may be invalid - check before use.
virtual blink::WebBluetoothDeviceId GetWebBluetoothDeviceId(
const std::string& device_address) = 0;
// Pair the device identified by |device_id|. If successful, |callback| will
// be run. If unsuccessful |error_callback| wil be run with the corresponding
// error code.
virtual void PairDevice(
const blink::WebBluetoothDeviceId& device_id,
device::BluetoothDevice::PairingDelegate* pairing_delegate,
device::BluetoothDevice::ConnectCallback callback) = 0;
// Cancels a pairing attempt to a remote device, clearing its reference to
// the pairing delegate.
virtual void CancelPairing(const blink::WebBluetoothDeviceId& device_id) = 0;
// Sends the PIN code |pincode| for the remote device during pairing.
virtual void SetPinCode(const blink::WebBluetoothDeviceId& device_id,
const std::string& pincode) = 0;
// The user consented to pairing with the Bluetooth device.
virtual void PairConfirmed(const blink::WebBluetoothDeviceId& device_id) = 0;
// Reads the value for the characteristic identified by
// |characteristic_instance_id|. If the value is successfully read the
// callback will be run with WebBluetoothResult::SUCCESS and the
// characteristic's value. If the value is not successfully read the
// callback will be run with the corresponding error and nullptr for value.
virtual void RemoteCharacteristicReadValue(
const std::string& characteristic_instance_id,
blink::mojom::WebBluetoothService::RemoteCharacteristicReadValueCallback
callback) = 0;
// Writes the |value| for the characteristic identified by
// |characteristic_instance_id|. If the value is successfully written
// |callback| will be run with WebBluetoothResult::SUCCESS. If the value is
// not successfully written |callback| will be run with the corresponding
// error.
virtual void RemoteCharacteristicWriteValue(
const std::string& characteristic_instance_id,
const std::vector<uint8_t>& value,
blink::mojom::WebBluetoothWriteType write_type,
blink::mojom::WebBluetoothService::RemoteCharacteristicWriteValueCallback
callback) = 0;
// Reads the value for the descriptor identified by |descriptor_instance_id|.
// If successfully read |callback| will be run with
// WebBluetoothResult::SUCCESS and the descriptor value. If the value is not
// successfully read the callback will be run with the corresponding error
// and nullptr for value.
virtual void RemoteDescriptorReadValue(
const std::string& descriptor_instance_id,
blink::mojom::WebBluetoothService::RemoteDescriptorReadValueCallback
callback) = 0;
// Writes the |value| for the descriptor identified by
// |descriptor_instance_id|. If the value is successfully written
// |callback| will be run with WebBluetoothResult::SUCCESS. If the value is
// not successfully written |callback| will be run with the corresponding
// error.
virtual void RemoteDescriptorWriteValue(
const std::string& descriptor_instance_id,
const std::vector<uint8_t>& value,
blink::mojom::WebBluetoothService::RemoteDescriptorWriteValueCallback
callback) = 0;
virtual void RemoteCharacteristicStartNotificationsInternal(
const std::string& characteristic_instance_id,
mojo::AssociatedRemote<blink::mojom::WebBluetoothCharacteristicClient>
client,
blink::mojom::WebBluetoothService::
RemoteCharacteristicStartNotificationsCallback callback) = 0;
// Display a dialog to prompt to user for Bluetooth pairing.
// |device_identifier| is any string the caller wants to display to the user
// to identify the device (MAC address, name, etc.). |callback| will be called
// with the dialog result. |pairng_kind| will be used to determined which
// prompt to show.
virtual void PromptForBluetoothPairing(
const std::u16string& device_identifier,
BluetoothDelegate::PairPromptCallback callback,
BluetoothDelegate::PairingKind pairing_kind,
const std::optional<std::u16string>& pin) = 0;
};
} // namespace content
#endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_PAIRING_MANAGER_DELEGATE_H_