Commit 0e8ab707 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: Move WebBluetoothDeviceId to blink

This change moves the WebBluetoothDeviceId typemapping into
//third_party/blink/common. This will allow the web_bluetooth.mojom file
to be imported into permissions.mojom to use some of the Web Bluetooth
mojo structs in the BluetoothPermissionDescriptor.

Change-Id: I735b6e82f181fb4c712bf3e09945e9b9f660a16f

Bug: 577953
Change-Id: I735b6e82f181fb4c712bf3e09945e9b9f660a16f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614471
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665283}
parent eeab9a34
......@@ -199,7 +199,6 @@ jumbo_source_set("browser") {
"//third_party/blink/public:scaled_resources",
"//third_party/blink/public/common",
"//third_party/blink/public/mojom:mojom_broadcastchannel_bindings",
"//third_party/blink/public/mojom:web_bluetooth_mojo_bindings",
"//third_party/boringssl",
"//third_party/brotli:dec",
"//third_party/icu",
......
include_rules = [
"+device/bluetooth",
"+third_party/blink/common/bluetooth",
]
......@@ -12,7 +12,6 @@
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "content/browser/bluetooth/bluetooth_blocklist.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
using device::BluetoothUUID;
......@@ -23,7 +22,7 @@ BluetoothAllowedDevices::BluetoothAllowedDevices(
const BluetoothAllowedDevices& other) = default;
BluetoothAllowedDevices::~BluetoothAllowedDevices() {}
const WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
const blink::WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
const std::string& device_address,
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
auto& device_id = AddDevice(device_address);
......@@ -37,7 +36,7 @@ const WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
return device_id;
}
const WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
const blink::WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
const std::string& device_address) {
DVLOG(1) << "Adding a device to Map of Allowed Devices.";
......@@ -46,7 +45,7 @@ const WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
DVLOG(1) << "Device already in map of allowed devices.";
return device_address_to_id_map_[device_address];
}
const WebBluetoothDeviceId device_id = GenerateUniqueDeviceId();
const blink::WebBluetoothDeviceId device_id = GenerateUniqueDeviceId();
DVLOG(1) << "Id generated for device: " << device_id;
device_address_to_id_map_[device_address] = device_id;
......@@ -58,12 +57,13 @@ const WebBluetoothDeviceId& BluetoothAllowedDevices::AddDevice(
}
void BluetoothAllowedDevices::RemoveDevice(const std::string& device_address) {
const WebBluetoothDeviceId* device_id_ptr = GetDeviceId(device_address);
const blink::WebBluetoothDeviceId* device_id_ptr =
GetDeviceId(device_address);
DCHECK(device_id_ptr != nullptr);
// We make a copy because we are going to remove the original value from its
// map.
WebBluetoothDeviceId device_id = *device_id_ptr;
blink::WebBluetoothDeviceId device_id = *device_id_ptr;
// 1. Remove from all three maps.
CHECK(device_address_to_id_map_.erase(device_address));
......@@ -77,7 +77,7 @@ void BluetoothAllowedDevices::RemoveDevice(const std::string& device_address) {
CHECK(device_id_set_.erase(device_id));
}
const WebBluetoothDeviceId* BluetoothAllowedDevices::GetDeviceId(
const blink::WebBluetoothDeviceId* BluetoothAllowedDevices::GetDeviceId(
const std::string& device_address) {
auto id_iter = device_address_to_id_map_.find(device_address);
if (id_iter == device_address_to_id_map_.end()) {
......@@ -87,7 +87,7 @@ const WebBluetoothDeviceId* BluetoothAllowedDevices::GetDeviceId(
}
const std::string& BluetoothAllowedDevices::GetDeviceAddress(
const WebBluetoothDeviceId& device_id) {
const blink::WebBluetoothDeviceId& device_id) {
auto id_iter = device_id_to_address_map_.find(device_id);
return id_iter == device_id_to_address_map_.end() ? base::EmptyString()
......@@ -95,7 +95,7 @@ const std::string& BluetoothAllowedDevices::GetDeviceAddress(
}
bool BluetoothAllowedDevices::IsAllowedToAccessAtLeastOneService(
const WebBluetoothDeviceId& device_id) const {
const blink::WebBluetoothDeviceId& device_id) const {
auto id_iter = device_id_to_services_map_.find(device_id);
return id_iter == device_id_to_services_map_.end() ? false
......@@ -103,7 +103,7 @@ bool BluetoothAllowedDevices::IsAllowedToAccessAtLeastOneService(
}
bool BluetoothAllowedDevices::IsAllowedToAccessService(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
const BluetoothUUID& service_uuid) const {
if (BluetoothBlocklist::Get().IsExcluded(service_uuid)) {
return false;
......@@ -117,18 +117,18 @@ bool BluetoothAllowedDevices::IsAllowedToAccessService(
}
bool BluetoothAllowedDevices::IsAllowedToGATTConnect(
const WebBluetoothDeviceId& device_id) const {
const blink::WebBluetoothDeviceId& device_id) const {
auto id_iter = device_id_to_connectable_map_.find(device_id);
if (id_iter == device_id_to_connectable_map_.end())
return false;
return id_iter->second;
}
WebBluetoothDeviceId BluetoothAllowedDevices::GenerateUniqueDeviceId() {
WebBluetoothDeviceId device_id = WebBluetoothDeviceId::Create();
blink::WebBluetoothDeviceId BluetoothAllowedDevices::GenerateUniqueDeviceId() {
blink::WebBluetoothDeviceId device_id = blink::WebBluetoothDeviceId::Create();
while (base::ContainsKey(device_id_set_, device_id)) {
LOG(WARNING) << "Generated repeated id.";
device_id = WebBluetoothDeviceId::Create();
device_id = blink::WebBluetoothDeviceId::Create();
}
return device_id;
}
......
......@@ -12,8 +12,8 @@
#include <vector>
#include "base/optional.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "content/common/content_export.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 device {
......@@ -36,13 +36,14 @@ class CONTENT_EXPORT BluetoothAllowedDevices final {
// Adds the Bluetooth Device with |device_address| to the map of allowed
// devices. Generates and returns a new random device ID so that devices
// IDs can not be compared between sites.
const WebBluetoothDeviceId& AddDevice(
const blink::WebBluetoothDeviceId& AddDevice(
const std::string& device_address,
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options);
// Same as the above version of |AddDevice| but does not add any services to
// the device id -> services map.
const WebBluetoothDeviceId& AddDevice(const std::string& device_address);
const blink::WebBluetoothDeviceId& AddDevice(
const std::string& device_address);
// Removes the Bluetooth Device with |device_address| from the map of allowed
// devices.
......@@ -50,42 +51,47 @@ class CONTENT_EXPORT BluetoothAllowedDevices final {
// Returns the Bluetooth Device's id if it has been added previously with
// |AddDevice|.
const WebBluetoothDeviceId* GetDeviceId(const std::string& device_address);
const blink::WebBluetoothDeviceId* GetDeviceId(
const std::string& device_address);
// For |device_id|, returns the Bluetooth device's address. If there is no
// such |device_id|, returns an empty string.
const std::string& GetDeviceAddress(const WebBluetoothDeviceId& device_id);
const std::string& GetDeviceAddress(
const blink::WebBluetoothDeviceId& device_id);
// Returns true if access has previously been granted to at least one
// service.
bool IsAllowedToAccessAtLeastOneService(
const WebBluetoothDeviceId& device_id) const;
const blink::WebBluetoothDeviceId& device_id) const;
// Returns true if access has previously been granted to the service.
bool IsAllowedToAccessService(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
const device::BluetoothUUID& service_uuid) const;
bool IsAllowedToGATTConnect(const WebBluetoothDeviceId& device_id) const;
bool IsAllowedToGATTConnect(
const blink::WebBluetoothDeviceId& device_id) const;
private:
typedef std::unordered_map<std::string, WebBluetoothDeviceId>
typedef std::unordered_map<std::string, blink::WebBluetoothDeviceId>
DeviceAddressToIdMap;
typedef std::
unordered_map<WebBluetoothDeviceId, std::string, WebBluetoothDeviceIdHash>
DeviceIdToAddressMap;
typedef std::unordered_map<blink::WebBluetoothDeviceId,
std::string,
blink::WebBluetoothDeviceIdHash>
DeviceIdToAddressMap;
typedef std::unordered_map<
WebBluetoothDeviceId,
blink::WebBluetoothDeviceId,
std::unordered_set<device::BluetoothUUID, device::BluetoothUUIDHash>,
WebBluetoothDeviceIdHash>
blink::WebBluetoothDeviceIdHash>
DeviceIdToServicesMap;
typedef std::
unordered_map<WebBluetoothDeviceId, bool, WebBluetoothDeviceIdHash>
DeviceIdToConnectableMap;
typedef std::unordered_map<blink::WebBluetoothDeviceId,
bool,
blink::WebBluetoothDeviceIdHash>
DeviceIdToConnectableMap;
// Returns an id guaranteed to be unique for the map. The id is randomly
// generated so that an origin can't guess the id used in another origin.
WebBluetoothDeviceId GenerateUniqueDeviceId();
blink::WebBluetoothDeviceId GenerateUniqueDeviceId();
void AddUnionOfServicesTo(
const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options,
std::unordered_set<device::BluetoothUUID, device::BluetoothUUIDHash>*
......@@ -97,7 +103,8 @@ class CONTENT_EXPORT BluetoothAllowedDevices final {
DeviceIdToConnectableMap device_id_to_connectable_map_;
// Keep track of all device_ids in the map.
std::unordered_set<WebBluetoothDeviceId, WebBluetoothDeviceIdHash>
std::unordered_set<blink::WebBluetoothDeviceId,
blink::WebBluetoothDeviceIdHash>
device_id_set_;
};
......
......@@ -6,8 +6,8 @@
#include "base/strings/string_util.h"
#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
#include "url/gurl.h"
using device::BluetoothUUID;
......@@ -58,7 +58,7 @@ TEST_F(BluetoothAllowedDevicesTest, UniqueOriginNotSupported) {
TEST_F(BluetoothAllowedDevicesTest, AddDevice) {
BluetoothAllowedDevices allowed_devices;
const WebBluetoothDeviceId& device_id =
const blink::WebBluetoothDeviceId& device_id =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
// Test that we can retrieve the device address/id.
......@@ -68,9 +68,9 @@ TEST_F(BluetoothAllowedDevicesTest, AddDevice) {
TEST_F(BluetoothAllowedDevicesTest, AddDeviceTwice) {
BluetoothAllowedDevices allowed_devices;
const WebBluetoothDeviceId& device_id1 =
const blink::WebBluetoothDeviceId& device_id1 =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
const WebBluetoothDeviceId& device_id2 =
const blink::WebBluetoothDeviceId& device_id2 =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
EXPECT_EQ(device_id1, device_id2);
......@@ -82,9 +82,9 @@ TEST_F(BluetoothAllowedDevicesTest, AddDeviceTwice) {
TEST_F(BluetoothAllowedDevicesTest, AddTwoDevices) {
BluetoothAllowedDevices allowed_devices;
const WebBluetoothDeviceId& device_id1 =
const blink::WebBluetoothDeviceId& device_id1 =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
const WebBluetoothDeviceId& device_id2 =
const blink::WebBluetoothDeviceId& device_id2 =
allowed_devices.AddDevice(kDeviceAddress2, empty_options_);
EXPECT_NE(device_id1, device_id2);
......@@ -105,9 +105,9 @@ TEST_F(BluetoothAllowedDevicesTest, AddTwoDevicesFromTwoOriginsToMap) {
content::BluetoothAllowedDevices& allowed_devices2 =
allowed_devices_map->GetOrCreateAllowedDevices(kTestOrigin2);
const WebBluetoothDeviceId& device_id1 =
const blink::WebBluetoothDeviceId& device_id1 =
allowed_devices1.AddDevice(kDeviceAddress1, empty_options_);
const WebBluetoothDeviceId& device_id2 =
const blink::WebBluetoothDeviceId& device_id2 =
allowed_devices2.AddDevice(kDeviceAddress2, empty_options_);
EXPECT_NE(device_id1, device_id2);
......@@ -135,9 +135,9 @@ TEST_F(BluetoothAllowedDevicesTest, AddDeviceFromTwoOriginsToMap) {
content::BluetoothAllowedDevices& allowed_devices2 =
allowed_devices_map->GetOrCreateAllowedDevices(kTestOrigin2);
const WebBluetoothDeviceId& device_id1 =
const blink::WebBluetoothDeviceId& device_id1 =
allowed_devices1.AddDevice(kDeviceAddress1, empty_options_);
const WebBluetoothDeviceId& device_id2 =
const blink::WebBluetoothDeviceId& device_id2 =
allowed_devices2.AddDevice(kDeviceAddress1, empty_options_);
EXPECT_NE(device_id1, device_id2);
......@@ -149,12 +149,12 @@ TEST_F(BluetoothAllowedDevicesTest, AddDeviceFromTwoOriginsToMap) {
TEST_F(BluetoothAllowedDevicesTest, AddRemoveAddDevice) {
BluetoothAllowedDevices allowed_devices;
const WebBluetoothDeviceId device_id_first_time =
const blink::WebBluetoothDeviceId device_id_first_time =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
allowed_devices.RemoveDevice(kDeviceAddress1);
const WebBluetoothDeviceId device_id_second_time =
const blink::WebBluetoothDeviceId device_id_second_time =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
EXPECT_NE(device_id_first_time, device_id_second_time);
......@@ -163,7 +163,7 @@ TEST_F(BluetoothAllowedDevicesTest, AddRemoveAddDevice) {
TEST_F(BluetoothAllowedDevicesTest, RemoveDevice) {
BluetoothAllowedDevices allowed_devices;
const WebBluetoothDeviceId device_id =
const blink::WebBluetoothDeviceId device_id =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
allowed_devices.RemoveDevice(kDeviceAddress1);
......@@ -186,7 +186,7 @@ TEST_F(BluetoothAllowedDevicesTest, NoPermissionForAnyService) {
options->filters->push_back({scan_filter.Clone()});
// Add to map.
const WebBluetoothDeviceId device_id =
const blink::WebBluetoothDeviceId device_id =
allowed_devices.AddDevice(kDeviceAddress1, options);
// Try to access at least one service.
......@@ -219,7 +219,7 @@ TEST_F(BluetoothAllowedDevicesTest, AllowedServices_OneDevice) {
options->optional_services.push_back(kHeartRateUUID);
// Add to map.
const WebBluetoothDeviceId device_id1 =
const blink::WebBluetoothDeviceId device_id1 =
allowed_devices.AddDevice(kDeviceAddress1, options);
// Access allowed services.
......@@ -254,7 +254,7 @@ TEST_F(BluetoothAllowedDevicesTest, AllowedServices_OneDevice) {
options2->filters->push_back(scan_filter1.Clone());
options2->filters->push_back(scan_filter2.Clone());
const WebBluetoothDeviceId device_id2 =
const blink::WebBluetoothDeviceId device_id2 =
allowed_devices.AddDevice(kDeviceAddress1, options2);
// Access allowed services.
......@@ -307,9 +307,9 @@ TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoDevices) {
options2->optional_services.push_back(kBloodPressureUUID);
// Add devices to map.
const WebBluetoothDeviceId& device_id1 =
const blink::WebBluetoothDeviceId& device_id1 =
allowed_devices.AddDevice(kDeviceAddress1, options1);
const WebBluetoothDeviceId& device_id2 =
const blink::WebBluetoothDeviceId& device_id2 =
allowed_devices.AddDevice(kDeviceAddress2, options2);
// Access allowed services.
......@@ -375,9 +375,9 @@ TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoOriginsOneDevice) {
options2->optional_services.push_back(kBloodPressureUUID);
// Add devices to map.
const WebBluetoothDeviceId& device_id1 =
const blink::WebBluetoothDeviceId& device_id1 =
allowed_devices1.AddDevice(kDeviceAddress1, options1);
const WebBluetoothDeviceId& device_id2 =
const blink::WebBluetoothDeviceId& device_id2 =
allowed_devices2.AddDevice(kDeviceAddress1, options2);
// Access allowed services.
......@@ -442,7 +442,7 @@ TEST_F(BluetoothAllowedDevicesTest, MergeServices) {
options1->optional_services.push_back(kBatteryServiceUUID);
// Add to map.
const WebBluetoothDeviceId device_id1 =
const blink::WebBluetoothDeviceId device_id1 =
allowed_devices.AddDevice(kDeviceAddress1, options1);
// Setup second request.
......@@ -459,7 +459,7 @@ TEST_F(BluetoothAllowedDevicesTest, MergeServices) {
options2->optional_services.push_back(kBloodPressureUUID);
// Add to map again.
const WebBluetoothDeviceId device_id2 =
const blink::WebBluetoothDeviceId device_id2 =
allowed_devices.AddDevice(kDeviceAddress1, options2);
EXPECT_EQ(device_id1, device_id2);
......@@ -478,10 +478,10 @@ TEST_F(BluetoothAllowedDevicesTest, MergeServices) {
TEST_F(BluetoothAllowedDevicesTest, CorrectIdFormat) {
BluetoothAllowedDevices allowed_devices;
const WebBluetoothDeviceId& device_id =
const blink::WebBluetoothDeviceId& device_id =
allowed_devices.AddDevice(kDeviceAddress1, empty_options_);
EXPECT_TRUE(WebBluetoothDeviceId::IsValid(device_id.str()));
EXPECT_TRUE(blink::WebBluetoothDeviceId::IsValid(device_id.str()));
}
TEST_F(BluetoothAllowedDevicesTest, NoFilterServices) {
......@@ -497,7 +497,7 @@ TEST_F(BluetoothAllowedDevicesTest, NoFilterServices) {
options->filters->push_back(std::move(scan_filter));
// Add to map.
const WebBluetoothDeviceId device_id =
const blink::WebBluetoothDeviceId device_id =
allowed_devices.AddDevice(kDeviceAddress1, options);
EXPECT_FALSE(allowed_devices.IsAllowedToAccessAtLeastOneService(device_id));
......
......@@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
namespace base {
......
......@@ -5,6 +5,7 @@
#ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_UTIL_H_
#define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_UTIL_H_
#include "content/common/content_export.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
namespace content {
......
......@@ -35,7 +35,7 @@ FrameConnectedBluetoothDevices::~FrameConnectedBluetoothDevices() {
}
bool FrameConnectedBluetoothDevices::IsConnectedToDeviceWithId(
const WebBluetoothDeviceId& device_id) {
const blink::WebBluetoothDeviceId& device_id) {
auto connection_iter = device_id_to_connection_map_.find(device_id);
if (connection_iter == device_id_to_connection_map_.end()) {
return false;
......@@ -45,7 +45,7 @@ bool FrameConnectedBluetoothDevices::IsConnectedToDeviceWithId(
}
void FrameConnectedBluetoothDevices::Insert(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
std::unique_ptr<device::BluetoothGattConnection> connection,
blink::mojom::WebBluetoothServerClientAssociatedPtr client) {
if (device_id_to_connection_map_.find(device_id) !=
......@@ -71,7 +71,7 @@ void FrameConnectedBluetoothDevices::Insert(
}
void FrameConnectedBluetoothDevices::CloseConnectionToDeviceWithId(
const WebBluetoothDeviceId& device_id) {
const blink::WebBluetoothDeviceId& device_id) {
auto connection_iter = device_id_to_connection_map_.find(device_id);
if (connection_iter == device_id_to_connection_map_.end()) {
return;
......@@ -82,14 +82,14 @@ void FrameConnectedBluetoothDevices::CloseConnectionToDeviceWithId(
DecrementDevicesConnectedCount();
}
base::Optional<WebBluetoothDeviceId>
base::Optional<blink::WebBluetoothDeviceId>
FrameConnectedBluetoothDevices::CloseConnectionToDeviceWithAddress(
const std::string& device_address) {
auto device_address_iter = device_address_to_id_map_.find(device_address);
if (device_address_iter == device_address_to_id_map_.end()) {
return base::nullopt;
}
WebBluetoothDeviceId device_id = device_address_iter->second;
blink::WebBluetoothDeviceId device_id = device_address_iter->second;
auto device_id_iter = device_id_to_connection_map_.find(device_id);
CHECK(device_id_iter != device_id_to_connection_map_.end());
device_id_iter->second->server_client->GATTServerDisconnected();
......
......@@ -10,8 +10,8 @@
#include <unordered_map>
#include "base/optional.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
#include "url/origin.h"
......@@ -39,24 +39,25 @@ class CONTENT_EXPORT FrameConnectedBluetoothDevices final {
~FrameConnectedBluetoothDevices();
// Returns true if the map holds a connection to |device_id|.
bool IsConnectedToDeviceWithId(const WebBluetoothDeviceId& device_id);
bool IsConnectedToDeviceWithId(const blink::WebBluetoothDeviceId& device_id);
// If a connection doesn't exist already for |device_id|, adds a connection to
// the map and increases the WebContents count of connected devices.
void Insert(const WebBluetoothDeviceId& device_id,
void Insert(const blink::WebBluetoothDeviceId& device_id,
std::unique_ptr<device::BluetoothGattConnection> connection,
blink::mojom::WebBluetoothServerClientAssociatedPtr client);
// Deletes the BluetoothGattConnection for |device_id| and decrements the
// WebContents count of connected devices if |device_id| had a connection.
void CloseConnectionToDeviceWithId(const WebBluetoothDeviceId& device_id);
void CloseConnectionToDeviceWithId(
const blink::WebBluetoothDeviceId& device_id);
// Deletes the BluetoothGattConnection for |device_address| and decrements the
// WebContents count of connected devices if |device_address| had a
// connection. Returns the device_id of the device associated with the
// connection.
base::Optional<WebBluetoothDeviceId> CloseConnectionToDeviceWithAddress(
const std::string& device_address);
base::Optional<blink::WebBluetoothDeviceId>
CloseConnectionToDeviceWithAddress(const std::string& device_address);
private:
// Increments the Connected Devices count of the frame's WebContents.
......@@ -69,13 +70,13 @@ class CONTENT_EXPORT FrameConnectedBluetoothDevices final {
// Keeps the BluetoothGattConnection objects alive so that connections don't
// get closed.
std::unordered_map<WebBluetoothDeviceId,
std::unordered_map<blink::WebBluetoothDeviceId,
std::unique_ptr<GATTConnectionAndServerClient>,
WebBluetoothDeviceIdHash>
blink::WebBluetoothDeviceIdHash>
device_id_to_connection_map_;
// Keeps track of which device addresses correspond to which ids.
std::unordered_map<std::string, WebBluetoothDeviceId>
std::unordered_map<std::string, blink::WebBluetoothDeviceId>
device_address_to_id_map_;
DISALLOW_COPY_AND_ASSIGN(FrameConnectedBluetoothDevices);
......
......@@ -30,11 +30,11 @@ using testing::_;
namespace {
const WebBluetoothDeviceId kDeviceId0("000000000000000000000A==");
const blink::WebBluetoothDeviceId kDeviceId0("000000000000000000000A==");
constexpr char kDeviceAddress0[] = "0";
constexpr char kDeviceName0[] = "Device0";
const WebBluetoothDeviceId kDeviceId1("111111111111111111111A==");
const blink::WebBluetoothDeviceId kDeviceId1("111111111111111111111A==");
constexpr char kDeviceAddress1[] = "1";
constexpr char kDeviceName1[] = "Device1";
......
......@@ -26,7 +26,6 @@
#include "content/browser/permissions/permission_controller_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
......@@ -37,6 +36,7 @@
#include "device/bluetooth/bluetooth_adapter_factory_wrapper.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_descriptor.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
using device::BluetoothAdapterFactoryWrapper;
using device::BluetoothUUID;
......@@ -437,7 +437,7 @@ void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter,
}
if (!device->IsGattConnected()) {
base::Optional<WebBluetoothDeviceId> device_id =
base::Optional<blink::WebBluetoothDeviceId> device_id =
connected_devices_->CloseConnectionToDeviceWithAddress(
device->GetAddress());
......@@ -590,7 +590,7 @@ void WebBluetoothServiceImpl::RequestDevice(
}
void WebBluetoothServiceImpl::RemoteServerConnect(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothServerClientAssociatedPtrInfo client,
RemoteServerConnectCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -642,7 +642,7 @@ void WebBluetoothServiceImpl::RemoteServerConnect(
}
void WebBluetoothServiceImpl::RemoteServerDisconnect(
const WebBluetoothDeviceId& device_id) {
const blink::WebBluetoothDeviceId& device_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (connected_devices_->IsConnectedToDeviceWithId(device_id)) {
......@@ -652,7 +652,7 @@ void WebBluetoothServiceImpl::RemoteServerDisconnect(
}
void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<BluetoothUUID>& services_uuid,
RemoteServerGetPrimaryServicesCallback callback) {
......@@ -1291,7 +1291,7 @@ void WebBluetoothServiceImpl::RequestDeviceImpl(
}
void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<BluetoothUUID>& services_uuid,
RemoteServerGetPrimaryServicesCallback callback,
......@@ -1376,7 +1376,7 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
return;
}
const WebBluetoothDeviceId device_id =
const blink::WebBluetoothDeviceId device_id =
allowed_devices().AddDevice(device_address, options);
DVLOG(1) << "Device: " << device->GetNameForDisplay();
......@@ -1399,7 +1399,7 @@ void WebBluetoothServiceImpl::OnGetDeviceFailed(
}
void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
base::TimeTicks start_time,
blink::mojom::WebBluetoothServerClientAssociatedPtr client,
RemoteServerConnectCallback callback,
......@@ -1529,7 +1529,7 @@ void WebBluetoothServiceImpl::OnDescriptorWriteValueFailed(
}
CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
const WebBluetoothDeviceId& device_id) {
const blink::WebBluetoothDeviceId& device_id) {
const std::string& device_address =
allowed_devices().GetDeviceAddress(device_id);
if (device_address.empty()) {
......@@ -1559,7 +1559,7 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
}
const WebBluetoothDeviceId* device_id =
const blink::WebBluetoothDeviceId* device_id =
allowed_devices().GetDeviceId(device_iter->second);
// Kill the renderer if origin is not allowed to access the device.
if (device_id == nullptr) {
......
......@@ -170,12 +170,13 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
void RequestDevice(blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
RequestDeviceCallback callback) override;
void RemoteServerConnect(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothServerClientAssociatedPtrInfo client,
RemoteServerConnectCallback callback) override;
void RemoteServerDisconnect(const WebBluetoothDeviceId& device_id) override;
void RemoteServerDisconnect(
const blink::WebBluetoothDeviceId& device_id) override;
void RemoteServerGetPrimaryServices(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<device::BluetoothUUID>& services_uuid,
RemoteServerGetPrimaryServicesCallback callback) override;
......@@ -236,7 +237,7 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
// Should only be run after the services have been discovered for
// |device_address|.
void RemoteServerGetPrimaryServicesImpl(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
blink::mojom::WebBluetoothGATTQueryQuantity quantity,
const base::Optional<device::BluetoothUUID>& services_uuid,
RemoteServerGetPrimaryServicesCallback callback,
......@@ -252,7 +253,7 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
// Callbacks for BluetoothDevice::CreateGattConnection.
void OnCreateGATTConnectionSuccess(
const WebBluetoothDeviceId& device_id,
const blink::WebBluetoothDeviceId& device_id,
base::TimeTicks start_time,
blink::mojom::WebBluetoothServerClientAssociatedPtr client,
RemoteServerConnectCallback callback,
......@@ -315,7 +316,8 @@ class CONTENT_EXPORT WebBluetoothServiceImpl
// Queries the platform cache for a Device with |device_id| for |origin|.
// Fills in the |outcome| field and the |device| field if successful.
CacheQueryResult QueryCacheForDevice(const WebBluetoothDeviceId& device_id);
CacheQueryResult QueryCacheForDevice(
const blink::WebBluetoothDeviceId& device_id);
// Queries the platform cache for a Service with |service_instance_id|. Fills
// in the |outcome| field, and |device| and |service| fields if successful.
......
......@@ -53,8 +53,6 @@ source_set("common") {
"ax_content_node_data.h",
"background_fetch/background_fetch_types.cc",
"background_fetch/background_fetch_types.h",
"bluetooth/web_bluetooth_device_id.cc",
"bluetooth/web_bluetooth_device_id.h",
"browser_plugin/browser_plugin_constants.cc",
"browser_plugin/browser_plugin_constants.h",
"browser_plugin/browser_plugin_messages.h",
......@@ -522,7 +520,6 @@ mojom("mojo_bindings") {
"//services/ws/public/mojom",
"//skia/public/interfaces",
"//third_party/blink/public/mojom:mojom_core",
"//third_party/blink/public/mojom:web_bluetooth_mojo_bindings",
"//third_party/blink/public/mojom:web_feature_mojo_bindings",
"//ui/base/ime/mojo",
"//ui/base/mojo",
......
# Copyright 2016 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.
typemaps = [ "//content/common/bluetooth/web_bluetooth_device_id.typemap" ]
......@@ -1759,7 +1759,6 @@ test("content_unittests") {
"../child/font_warmup_win_unittest.cc",
"../common/android/gin_java_bridge_value_unittest.cc",
"../common/background_fetch/background_fetch_struct_traits_unittest.cc",
"../common/bluetooth/web_bluetooth_device_id_unittest.cc",
"../common/common_param_traits_unittest.cc",
"../common/content_security_policy/content_security_policy_unittest.cc",
"../common/content_security_policy/csp_context_unittest.cc",
......
......@@ -17,7 +17,6 @@ _typemap_imports = [
"//components/chromeos_camera/common/typemaps.gni",
"//components/sync/mojo/typemaps.gni",
"//components/typemaps.gni",
"//content/common/bluetooth/typemaps.gni",
"//content/common/typemaps.gni",
"//content/public/common/typemaps.gni",
"//device/bluetooth/public/mojom/typemaps.gni",
......
......@@ -22,6 +22,9 @@ jumbo_source_set("common") {
"associated_interfaces/associated_interface_provider.cc",
"associated_interfaces/associated_interface_registry.cc",
"blob/blob_utils.cc",
"bluetooth/web_bluetooth_device_id.cc",
"bluetooth/web_bluetooth_device_id.h",
"bluetooth/web_bluetooth_device_id_struct_traits.h",
"cache_storage/cache_storage_utils.cc",
"client_hints/client_hints.cc",
"device_memory/approximated_device_memory.cc",
......@@ -121,6 +124,7 @@ jumbo_source_set("common_unittests_sources") {
testonly = true
sources = [
"bluetooth/web_bluetooth_device_id_unittest.cc",
"client_hints/client_hints_unittest.cc",
"device_memory/approximated_device_memory_unittest.cc",
"feature_policy/feature_policy_unittest.cc",
......
include_rules = [
"+crypto/random.h",
]
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
#include "base/base64.h"
#include "base/strings/string_util.h"
#include "crypto/random.h"
namespace content {
namespace blink {
namespace {
......@@ -88,4 +88,4 @@ std::ostream& operator<<(std::ostream& out,
return out << device_id.str();
}
} // namespace content
} // namespace blink
......@@ -3,8 +3,8 @@
# found in the LICENSE file.
mojom = "//third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom"
public_headers = [ "//content/common/bluetooth/web_bluetooth_device_id.h" ]
traits_headers =
[ "//content/common/bluetooth/web_bluetooth_device_id_struct_traits.h" ]
public_headers =
[ "//third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h" ]
traits_headers = [ "//third_party/blink/public/common/bluetooth/web_bluetooth_device_id_struct_traits.h" ]
type_mappings =
[ "blink.mojom.WebBluetoothDeviceId=content::WebBluetoothDeviceId" ]
[ "blink.mojom.WebBluetoothDeviceId=blink::WebBluetoothDeviceId" ]
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/common/bluetooth/web_bluetooth_device_id.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
#include "base/base64.h"
#include "base/strings/string_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::WebBluetoothDeviceId;
using blink::WebBluetoothDeviceId;
namespace {
......
......@@ -3,6 +3,7 @@
# found in the LICENSE file.
typemaps = [
"//third_party/blink/common/bluetooth/web_bluetooth_device_id.typemap",
"//third_party/blink/common/feature_policy/feature_policy.typemap",
"//third_party/blink/common/messaging/cloneable_message.typemap",
"//third_party/blink/common/messaging/transferable_message.typemap",
......
......@@ -16,6 +16,7 @@ component("common") {
public_deps = [
"//third_party/blink/public/common:headers",
"//third_party/blink/public/mojom:mojom_modules",
"//third_party/blink/public/mojom:web_bluetooth_mojo_bindings",
]
deps = [
"//third_party/blink/common",
......@@ -37,6 +38,8 @@ source_set("headers") {
"associated_interfaces/associated_interface_provider.h",
"associated_interfaces/associated_interface_registry.h",
"blob/blob_utils.h",
"bluetooth/web_bluetooth_device_id.h",
"bluetooth/web_bluetooth_device_id_struct_traits.h",
"cache_storage/cache_storage_utils.h",
"client_hints/client_hints.h",
"common_export.h",
......@@ -111,6 +114,7 @@ source_set("headers") {
"//services/network/public/cpp:cpp",
"//skia",
"//third_party/blink/public/mojom:mojom_modules_headers",
"//third_party/blink/public/mojom:web_bluetooth_mojo_bindings_headers",
]
deps = [
......
file://content/browser/bluetooth/OWNERS
# Changes to IPC serialization require a security review to avoid introducing
# new sandbox escapes.
per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
# TEAM: web-bluetooth@chromium.org
# COMPONENT: Blink>Bluetooth
......@@ -2,19 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_H_
#define CONTENT_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_H_
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_H_
#include <string>
#include "content/common/content_export.h"
#include "third_party/blink/public/common/common_export.h"
namespace content {
namespace blink {
// Used to uniquely identify a Bluetooth Device for an Origin.
// A WebBluetoothDeviceId is generated by base64-encoding a 128bit
// string.
class CONTENT_EXPORT WebBluetoothDeviceId {
class BLINK_COMMON_EXPORT WebBluetoothDeviceId {
public:
// Default constructor that creates an invalid id. We implement it so that
// instances of this class in a container, e.g. std::unordered_map, can be
......@@ -47,8 +47,9 @@ class CONTENT_EXPORT WebBluetoothDeviceId {
};
// This is required by gtest to print a readable output on test failures.
CONTENT_EXPORT std::ostream& operator<<(std::ostream& out,
const WebBluetoothDeviceId& device_id);
BLINK_COMMON_EXPORT std::ostream& operator<<(
std::ostream& out,
const WebBluetoothDeviceId& device_id);
struct WebBluetoothDeviceIdHash {
size_t operator()(const WebBluetoothDeviceId& device_id) const {
......@@ -56,6 +57,6 @@ struct WebBluetoothDeviceIdHash {
}
};
} // namespace content
} // namespace blink
#endif // CONTENT_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_H_
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_H_
......@@ -2,38 +2,38 @@
// 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_DEVICE_ID_STRUCT_TRAITS_H_
#define CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_STRUCT_TRAITS_H_
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_STRUCT_TRAITS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_STRUCT_TRAITS_H_
#include <string>
#include "content/common/bluetooth/web_bluetooth_device_id.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 mojo {
template <>
struct StructTraits<blink::mojom::WebBluetoothDeviceIdDataView,
content::WebBluetoothDeviceId> {
blink::WebBluetoothDeviceId> {
static const std::string& device_id(
const content::WebBluetoothDeviceId& device_id) {
const blink::WebBluetoothDeviceId& device_id) {
return device_id.str();
}
static bool Read(blink::mojom::WebBluetoothDeviceIdDataView input,
content::WebBluetoothDeviceId* output) {
blink::WebBluetoothDeviceId* output) {
std::string result;
if (!input.ReadDeviceId(&result))
return false;
if (!content::WebBluetoothDeviceId::IsValid(result))
if (!blink::WebBluetoothDeviceId::IsValid(result))
return false;
*output = content::WebBluetoothDeviceId(std::move(result));
*output = blink::WebBluetoothDeviceId(std::move(result));
return true;
}
};
} // namespace mojo
#endif // CONTENT_BROWSER_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_STRUCT_TRAITS_H_
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_BLUETOOTH_WEB_BLUETOOTH_DEVICE_ID_STRUCT_TRAITS_H_
......@@ -332,12 +332,17 @@ mojom("mojom_modules") {
mojom("web_bluetooth_mojo_bindings") {
visibility = [
"//content/browser:browser",
"//content/common:mojo_bindings",
"//third_party/blink/common",
"//third_party/blink/public/common:common",
"//third_party/blink/public/common:headers",
]
visibility_blink =
[ "//third_party/blink/renderer/platform:blink_platform_public_deps" ]
visibility_blink = [
"//third_party/blink/common",
"//third_party/blink/public/common:common",
"//third_party/blink/public/common:headers",
"//third_party/blink/renderer/platform:blink_platform_public_deps",
]
sources = [
"bluetooth/web_bluetooth.mojom",
......@@ -350,9 +355,9 @@ mojom("web_bluetooth_mojo_bindings") {
# The chromium variant must be linked with content and use the same export
# settings in component build because of the WebBluetoothDeviceId typemap
# inside content.
export_class_attribute = "CONTENT_EXPORT"
export_define = "CONTENT_IMPLEMENTATION=1"
export_header = "content/common/content_export.h"
export_class_attribute = "BLINK_COMMON_EXPORT"
export_define = "BLINK_COMMON_IMPLEMENTATION=1"
export_header = "third_party/blink/public/common/common_export.h"
# Similarly, the blink variant must be linked with the platform component
# since it uses types from it in its typemaps.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment