#include "extensions/browser/api/device_permissions_manager.h"
#include <stddef.h>
#include <optional>
#include <utility>
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/singleton.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/api/hid/hid_device_manager.h"
#include "extensions/browser/api/usb/usb_device_manager.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/permissions/api_permission.h"
#include "extensions/strings/grit/extensions_strings.h"
#include "services/device/public/cpp/usb/usb_ids.h"
#include "ui/base/l10n/l10n_util.h"
namespace extensions {
BrowserContext;
BrowserThread;
APIPermission;
Extension;
ExtensionHost;
ExtensionPrefs;
namespace {
const char kDevices[] = …;
const char kDeviceType[] = …;
const char kDeviceTypeUsb[] = …;
const char kDeviceTypeHid[] = …;
const char kDeviceVendorId[] = …;
const char kDeviceProductId[] = …;
const char kDeviceSerialNumber[] = …;
const char kDeviceManufacturerString[] = …;
const char kDeviceProductString[] = …;
const char kDeviceLastUsed[] = …;
const char* TypeToString(DevicePermissionEntry::Type type) { … }
void SaveDevicePermissionEntry(BrowserContext* context,
const ExtensionId& extension_id,
scoped_refptr<DevicePermissionEntry> entry) { … }
bool MatchesDevicePermissionEntry(const base::Value::Dict& value,
scoped_refptr<DevicePermissionEntry> entry) { … }
void UpdateDevicePermissionEntry(BrowserContext* context,
const ExtensionId& extension_id,
scoped_refptr<DevicePermissionEntry> entry) { … }
void RemoveDevicePermissionEntry(BrowserContext* context,
const ExtensionId& extension_id,
scoped_refptr<DevicePermissionEntry> entry) { … }
void ClearDevicePermissionEntries(ExtensionPrefs* prefs,
const ExtensionId& extension_id) { … }
scoped_refptr<DevicePermissionEntry> ReadDevicePermissionEntry(
const base::Value::Dict& entry) { … }
std::set<scoped_refptr<DevicePermissionEntry>> GetDevicePermissionEntries(
ExtensionPrefs* prefs,
const ExtensionId& extension_id) { … }
}
DevicePermissionEntry::DevicePermissionEntry(
const device::mojom::UsbDeviceInfo& device)
: … { … }
DevicePermissionEntry::DevicePermissionEntry(
const device::mojom::HidDeviceInfo& device)
: … { … }
DevicePermissionEntry::DevicePermissionEntry(
Type type,
uint16_t vendor_id,
uint16_t product_id,
const std::u16string& serial_number,
const std::u16string& manufacturer_string,
const std::u16string& product_string,
const base::Time& last_used)
: … { … }
DevicePermissionEntry::~DevicePermissionEntry() { … }
bool DevicePermissionEntry::IsPersistent() const { … }
base::Value::Dict DevicePermissionEntry::ToValue() const { … }
std::u16string DevicePermissionEntry::GetPermissionMessageString() const { … }
DevicePermissions::~DevicePermissions() { … }
scoped_refptr<DevicePermissionEntry> DevicePermissions::FindUsbDeviceEntry(
const device::mojom::UsbDeviceInfo& device) const { … }
scoped_refptr<DevicePermissionEntry> DevicePermissions::FindHidDeviceEntry(
const device::mojom::HidDeviceInfo& device) const { … }
DevicePermissions::DevicePermissions(BrowserContext* context,
const ExtensionId& extension_id) { … }
DevicePermissionsManager* DevicePermissionsManager::Get(
BrowserContext* context) { … }
std::u16string DevicePermissionsManager::GetPermissionMessage(
uint16_t vendor_id,
uint16_t product_id,
const std::u16string& manufacturer_string,
const std::u16string& product_string,
const std::u16string& serial_number,
bool always_include_manufacturer) { … }
DevicePermissions* DevicePermissionsManager::GetForExtension(
const ExtensionId& extension_id) { … }
std::vector<std::u16string>
DevicePermissionsManager::GetPermissionMessageStrings(
const ExtensionId& extension_id) const { … }
void DevicePermissionsManager::AllowUsbDevice(
const ExtensionId& extension_id,
const device::mojom::UsbDeviceInfo& device_info) { … }
void DevicePermissionsManager::AllowHidDevice(
const ExtensionId& extension_id,
const device::mojom::HidDeviceInfo& device) { … }
void DevicePermissionsManager::UpdateLastUsed(
const ExtensionId& extension_id,
scoped_refptr<DevicePermissionEntry> entry) { … }
void DevicePermissionsManager::RemoveEntry(
const ExtensionId& extension_id,
scoped_refptr<DevicePermissionEntry> entry) { … }
void DevicePermissionsManager::Clear(const ExtensionId& extension_id) { … }
DevicePermissionsManager::DevicePermissionsManager(
content::BrowserContext* context)
: … { … }
DevicePermissionsManager::~DevicePermissionsManager() { … }
DevicePermissions* DevicePermissionsManager::GetInternal(
const ExtensionId& extension_id) const { … }
void DevicePermissionsManager::RemoveEntryByDeviceGUID(
DevicePermissionEntry::Type type,
const std::string& guid) { … }
DevicePermissionsManager* DevicePermissionsManagerFactory::GetForBrowserContext(
content::BrowserContext* context) { … }
DevicePermissionsManagerFactory*
DevicePermissionsManagerFactory::GetInstance() { … }
DevicePermissionsManagerFactory::DevicePermissionsManagerFactory()
: … { … }
DevicePermissionsManagerFactory::~DevicePermissionsManagerFactory() { … }
std::unique_ptr<KeyedService>
DevicePermissionsManagerFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const { … }
BrowserContext* DevicePermissionsManagerFactory::GetBrowserContextToUse(
BrowserContext* context) const { … }
}