Ovidio Henriquez | 3d729f6 | 2020-02-07 00:43:29 | [diff] [blame] | 1 | // Copyright 2020 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 CONTENT_PUBLIC_BROWSER_BLUETOOTH_DELEGATE_H_ |
| 6 | #define CONTENT_PUBLIC_BROWSER_BLUETOOTH_DELEGATE_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/containers/flat_set.h" |
| 11 | #include "content/common/content_export.h" |
| 12 | #include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom-forward.h" |
| 13 | |
| 14 | namespace blink { |
| 15 | class WebBluetoothDeviceId; |
| 16 | } // namespace blink |
| 17 | |
| 18 | namespace device { |
| 19 | class BluetoothDevice; |
| 20 | class BluetoothUUID; |
| 21 | } // namespace device |
| 22 | |
| 23 | namespace content { |
| 24 | |
| 25 | class RenderFrameHost; |
| 26 | |
| 27 | // Provides an interface for managing device permissions for Web Bluetooth and |
| 28 | // Web Bluetooth Scanning API. An embedder may implement this to manage these |
| 29 | // permissions. |
| 30 | // TODO(https://crbug.com/1048325): There are several Bluetooth related methods |
| 31 | // in WebContentsDelegate and ContentBrowserClient that can be moved into this |
| 32 | // class. |
| 33 | class CONTENT_EXPORT BluetoothDelegate { |
| 34 | public: |
| 35 | virtual ~BluetoothDelegate() = default; |
| 36 | |
| 37 | // This should return the WebBluetoothDeviceId that corresponds to the device |
| 38 | // with |device_address| in the current |frame|. If there is not a |
| 39 | // corresponding ID, then an invalid WebBluetoothDeviceId should be returned. |
| 40 | virtual blink::WebBluetoothDeviceId GetWebBluetoothDeviceId( |
| 41 | RenderFrameHost* frame, |
| 42 | const std::string& device_address) = 0; |
| 43 | |
| 44 | // This should return the device address corresponding to a device with |
| 45 | // |device_id| in the current |frame|. If there is not a corresponding |
| 46 | // address, then an empty string should be returned. |
| 47 | virtual std::string GetDeviceAddress( |
| 48 | RenderFrameHost* frame, |
| 49 | const blink::WebBluetoothDeviceId& device_id) = 0; |
| 50 | |
| 51 | // This should return the WebBluetoothDeviceId for |device_address| if the |
| 52 | // device has been assigned an ID previously through AddScannedDevice() or |
| 53 | // GrantServiceAccessPermission(). If not, a new ID should be generated for |
| 54 | // |device_address| and stored in a temporary map of address to ID. Service |
| 55 | // access should not be granted to these devices. |
| 56 | virtual blink::WebBluetoothDeviceId AddScannedDevice( |
| 57 | RenderFrameHost* frame, |
| 58 | const std::string& device_address) = 0; |
| 59 | |
| 60 | // This should grant permission to the requesting and embedding origins |
| 61 | // represented by |frame| to connect to the device with |device_address| and |
| 62 | // access its |services|. Once permission is granted, a |WebBluetoothDeviceId| |
| 63 | // should be generated for the device and returned. |
| 64 | virtual blink::WebBluetoothDeviceId GrantServiceAccessPermission( |
| 65 | RenderFrameHost* frame, |
| 66 | const device::BluetoothDevice* device, |
| 67 | const blink::mojom::WebBluetoothRequestDeviceOptions* options) = 0; |
| 68 | |
| 69 | // This should return true if |frame| has been granted permission to access |
| 70 | // the device with |device_id| through GrantServiceAccessPermission(). |
| 71 | // |device_id|s generated with AddScannedDevices() should return false. |
| 72 | virtual bool HasDevicePermission( |
| 73 | RenderFrameHost* frame, |
| 74 | const blink::WebBluetoothDeviceId& device_id) = 0; |
| 75 | |
| 76 | // This should return true if |frame| has permission to access |service| from |
| 77 | // the device with |device_id|. |
| 78 | virtual bool IsAllowedToAccessService( |
| 79 | RenderFrameHost* frame, |
| 80 | const blink::WebBluetoothDeviceId& device_id, |
| 81 | const device::BluetoothUUID& service) = 0; |
| 82 | |
| 83 | // This should return true if |frame| can access at least one service from the |
| 84 | // device with |device_id|. |
| 85 | virtual bool IsAllowedToAccessAtLeastOneService( |
| 86 | RenderFrameHost* frame, |
| 87 | const blink::WebBluetoothDeviceId& device_id) = 0; |
| 88 | }; |
| 89 | |
| 90 | } // namespace content |
| 91 | |
| 92 | #endif // CONTENT_PUBLIC_BROWSER_BLUETOOTH_DELEGATE_H_ |