Commit 3b282713 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: Add BluetoothChooserContext stub

This change adds the stub interface for BluetoothChooserContext to be
implemented in future patches.

Bug: 589228
Change-Id: I1d4a25effa9676548e16f075a7fc6b792943043f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1927391Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721534}
parent e49e98b3
......@@ -293,7 +293,7 @@ public class WebsitePermissionsFetcherTest {
// If the ContentSettingsType.NUM_TYPES value changes *and* a new value has been exposed on
// Android, then please update this code block to include a test for your new type.
// Otherwise, just update count in the assert.
Assert.assertEquals(55, ContentSettingsType.NUM_TYPES);
Assert.assertEquals(56, ContentSettingsType.NUM_TYPES);
websitePreferenceBridge.addContentSettingException(
new ContentSettingException(ContentSettingsType.COOKIES, googleOrigin,
ContentSettingValues.DEFAULT, preferenceSource));
......
......@@ -3058,6 +3058,10 @@ jumbo_static_library("browser") {
"badging/badge_manager_factory.h",
"banners/app_banner_manager_desktop.cc",
"banners/app_banner_manager_desktop.h",
"bluetooth/bluetooth_chooser_context.cc",
"bluetooth/bluetooth_chooser_context.h",
"bluetooth/bluetooth_chooser_context_factory.cc",
"bluetooth/bluetooth_chooser_context_factory.h",
"bookmarks/bookmark_html_writer.cc",
"bookmarks/bookmark_html_writer.h",
"certificate_viewer.h",
......
file://content/browser/bluetooth/OWNERS
per-file *chooser_context*=file://chrome/browser/permissions/PERMISSIONS_OWNERS
# TEAM: web-bluetooth@chromium.org
# COMPONENT: Blink>Bluetooth
\ No newline at end of file
// Copyright 2019 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.
#include "chrome/browser/bluetooth/bluetooth_chooser_context.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "url/origin.h"
using blink::WebBluetoothDeviceId;
using device::BluetoothUUID;
using device::BluetoothUUIDHash;
BluetoothChooserContext::BluetoothChooserContext(Profile* profile)
: ChooserContextBase(profile,
ContentSettingsType::BLUETOOTH_GUARD,
ContentSettingsType::BLUETOOTH_CHOOSER_DATA) {}
BluetoothChooserContext::~BluetoothChooserContext() = default;
const WebBluetoothDeviceId BluetoothChooserContext::GetWebBluetoothDeviceId(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const std::string& device_address) {
NOTIMPLEMENTED();
return {};
}
const std::string BluetoothChooserContext::GetDeviceAddress(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const WebBluetoothDeviceId& device_id) {
NOTIMPLEMENTED();
return "";
}
const WebBluetoothDeviceId BluetoothChooserContext::GrantDevicePermission(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const std::string& device_address,
base::flat_set<BluetoothUUID, BluetoothUUIDHash>& services) {
NOTIMPLEMENTED();
return {};
}
bool BluetoothChooserContext::HasDevicePermission(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const WebBluetoothDeviceId& device_id) {
NOTIMPLEMENTED();
return false;
}
bool BluetoothChooserContext::IsAllowedToAccessAtLeastOneService(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const WebBluetoothDeviceId& device_id) {
NOTIMPLEMENTED();
return false;
}
bool BluetoothChooserContext::IsAllowedToAccessService(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const WebBluetoothDeviceId& device_id,
BluetoothUUID service) {
NOTIMPLEMENTED();
return false;
}
bool BluetoothChooserContext::IsValidObject(const base::Value& object) {
NOTIMPLEMENTED();
return false;
}
std::vector<std::unique_ptr<ChooserContextBase::Object>>
BluetoothChooserContext::GetGrantedObjects(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin) {
NOTIMPLEMENTED();
return {};
}
std::vector<std::unique_ptr<ChooserContextBase::Object>>
BluetoothChooserContext::GetAllGrantedObjects() {
NOTIMPLEMENTED();
return {};
}
void BluetoothChooserContext::RevokeObjectPermission(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const base::Value& object) {
NOTIMPLEMENTED();
}
// Copyright 2019 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_BLUETOOTH_BLUETOOTH_CHOOSER_CONTEXT_H_
#define CHROME_BROWSER_BLUETOOTH_BLUETOOTH_CHOOSER_CONTEXT_H_
#include <string>
#include "base/containers/flat_set.h"
#include "chrome/browser/permissions/chooser_context_base.h"
#include "device/bluetooth/public/cpp/bluetooth_uuid.h"
#include "third_party/blink/public/common/bluetooth/web_bluetooth_device_id.h"
namespace base {
class Value;
} // namespace base
namespace url {
class Origin;
} // namespace url
// Manages the permissions for Web Bluetooth device objects. A Web Bluetooth
// permission object consists of its WebBluetoothDeviceId and set of Bluetooth
// service UUIDs. The WebBluetoothDeviceId is generated randomly by this class
// and is unique for a given Bluetooth device address and origin pair, so this
// class stores this mapping and provides utility methods to convert between
// the WebBluetoothDeviceId and Bluetooth device address.
class BluetoothChooserContext : public ChooserContextBase {
public:
explicit BluetoothChooserContext(Profile* profile);
~BluetoothChooserContext() override;
// Set class as move-only.
BluetoothChooserContext(const BluetoothChooserContext&) = delete;
BluetoothChooserContext& operator=(const BluetoothChooserContext&) = delete;
// Helper methods for converting between a WebBluetoothDeviceId and a
// Bluetooth device address string for a given origin pair.
const blink::WebBluetoothDeviceId GetWebBluetoothDeviceId(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const std::string& device_address);
const std::string GetDeviceAddress(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const blink::WebBluetoothDeviceId& device_id);
// Bluetooth-specific interface for granting and checking permissions.
const blink::WebBluetoothDeviceId GrantDevicePermission(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const std::string& device_address,
base::flat_set<device::BluetoothUUID, device::BluetoothUUIDHash>&
services);
bool HasDevicePermission(const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const blink::WebBluetoothDeviceId& device_id);
bool IsAllowedToAccessAtLeastOneService(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const blink::WebBluetoothDeviceId& device_id);
bool IsAllowedToAccessService(const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const blink::WebBluetoothDeviceId& device_id,
device::BluetoothUUID service);
protected:
// ChooserContextBase implementation;
bool IsValidObject(const base::Value& object) override;
std::vector<std::unique_ptr<Object>> GetGrantedObjects(
const url::Origin& requesting_origin,
const url::Origin& embedding_origin) override;
std::vector<std::unique_ptr<Object>> GetAllGrantedObjects() override;
void RevokeObjectPermission(const url::Origin& requesting_origin,
const url::Origin& embedding_origin,
const base::Value& object) override;
};
#endif // CHROME_BROWSER_BLUETOOTH_BLUETOOTH_CHOOSER_CONTEXT_H_
// Copyright 2019 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.
#include "chrome/browser/bluetooth/bluetooth_chooser_context_factory.h"
#include "chrome/browser/bluetooth/bluetooth_chooser_context.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
// static
BluetoothChooserContextFactory* BluetoothChooserContextFactory::GetInstance() {
static base::NoDestructor<BluetoothChooserContextFactory> factory;
return factory.get();
}
// static
BluetoothChooserContext* BluetoothChooserContextFactory::GetForProfile(
Profile* profile) {
return static_cast<BluetoothChooserContext*>(
GetInstance()->GetServiceForBrowserContext(profile, /*create=*/true));
}
BluetoothChooserContextFactory::BluetoothChooserContextFactory()
: BrowserContextKeyedServiceFactory(
"BluetoothChooserContext",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(HostContentSettingsMapFactory::GetInstance());
}
BluetoothChooserContextFactory::~BluetoothChooserContextFactory() = default;
KeyedService* BluetoothChooserContextFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new BluetoothChooserContext(Profile::FromBrowserContext(context));
}
content::BrowserContext* BluetoothChooserContextFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
// Copyright 2019 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_BLUETOOTH_BLUETOOTH_CHOOSER_CONTEXT_FACTORY_H_
#define CHROME_BROWSER_BLUETOOTH_BLUETOOTH_CHOOSER_CONTEXT_FACTORY_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class BluetoothChooserContext;
class Profile;
class BluetoothChooserContextFactory
: public BrowserContextKeyedServiceFactory {
public:
static BluetoothChooserContext* GetForProfile(Profile* profile);
static BluetoothChooserContextFactory* GetInstance();
// Move-only class.
BluetoothChooserContextFactory(const BluetoothChooserContextFactory&) =
delete;
BluetoothChooserContextFactory& operator=(
const BluetoothChooserContextFactory&) = delete;
private:
friend base::NoDestructor<BluetoothChooserContextFactory>;
BluetoothChooserContextFactory();
~BluetoothChooserContextFactory() override;
// BrowserContextKeyedBaseFactory implementation:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
};
#endif // CHROME_BROWSER_BLUETOOTH_BLUETOOTH_CHOOSER_CONTEXT_FACTORY_H_
......@@ -714,6 +714,10 @@ void ChromeBrowsingDataRemoverDelegate::RemoveEmbedderData(
ContentSettingsType::USB_CHOOSER_DATA, delete_begin_, delete_end_,
HostContentSettingsMap::PatternSourcePredicate());
host_content_settings_map_->ClearSettingsForOneTypeWithPredicate(
ContentSettingsType::BLUETOOTH_CHOOSER_DATA, delete_begin_, delete_end_,
HostContentSettingsMap::PatternSourcePredicate());
auto* handler_registry =
ProtocolHandlerRegistryFactory::GetForBrowserContext(profile_);
if (handler_registry)
......
......@@ -174,6 +174,10 @@ void ChooserContextBase::RevokeObjectPermission(
NotifyPermissionRevoked(requesting_origin, embedding_origin);
}
bool ChooserContextBase::IsOffTheRecord() {
return host_content_settings_map_->IsOffTheRecord();
}
void ChooserContextBase::NotifyPermissionChanged() {
for (auto& observer : permission_observer_list_) {
observer.OnChooserObjectPermissionChanged(guard_content_settings_type_,
......
......@@ -113,6 +113,9 @@ class ChooserContextBase : public KeyedService {
virtual bool IsValidObject(const base::Value& object) = 0;
protected:
// TODO(odejesush): Use this method in all derived classes instead of using a
// member variable to store this state.
bool IsOffTheRecord();
void NotifyPermissionChanged();
void NotifyPermissionRevoked(const url::Origin& requesting_origin,
const url::Origin& embedding_origin);
......
......@@ -123,6 +123,7 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
{ContentSettingsType::LEGACY_COOKIE_ACCESS, nullptr},
{ContentSettingsType::INSTALLED_WEB_APP_METADATA, nullptr},
{ContentSettingsType::NFC, nullptr},
{ContentSettingsType::BLUETOOTH_CHOOSER_DATA, nullptr},
};
static_assert(base::size(kContentSettingsTypeGroupNames) ==
// ContentSettingsType starts at -1, so add 1 here.
......
......@@ -208,6 +208,13 @@ void WebsiteSettingsRegistry::Init() {
WebsiteSettingsInfo::UNSYNCABLE, WebsiteSettingsInfo::LOSSY,
WebsiteSettingsInfo::SINGLE_ORIGIN_ONLY_SCOPE, DESKTOP,
WebsiteSettingsInfo::DONT_INHERIT_IN_INCOGNITO);
Register(ContentSettingsType::BLUETOOTH_CHOOSER_DATA,
"bluetooth-chooser-data",
/*initial_default_value=*/nullptr, WebsiteSettingsInfo::UNSYNCABLE,
WebsiteSettingsInfo::NOT_LOSSY,
WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE,
DESKTOP | PLATFORM_ANDROID,
WebsiteSettingsInfo::DONT_INHERIT_IN_INCOGNITO);
}
} // namespace content_settings
......@@ -81,6 +81,7 @@ constexpr HistogramValue kHistogramValue[] = {
{ContentSettingsType::NATIVE_FILE_SYSTEM_WRITE_GUARD, 57},
{ContentSettingsType::INSTALLED_WEB_APP_METADATA, 58},
{ContentSettingsType::NFC, 59},
{ContentSettingsType::BLUETOOTH_CHOOSER_DATA, 60},
};
} // namespace
......
......@@ -178,6 +178,10 @@ enum class ContentSettingsType : int32_t {
// Used to store whether to allow a website to exchange data with NFC devices.
NFC,
// Website setting to store permissions granted to access particular Bluetooth
// devices.
BLUETOOTH_CHOOSER_DATA,
NUM_TYPES,
};
......
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