#include "chrome/browser/hid/hid_chooser_context.h"
#include <set>
#include <string_view>
#include <utility>
#include "base/containers/contains.h"
#include "base/containers/map_util.h"
#include "base/observer_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/hid/hid_policy_allowed_devices.h"
#include "chrome/browser/hid/hid_policy_allowed_devices_factory.h"
#include "chrome/browser/hid/web_view_chooser_context.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/grit/generated_resources.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "content/public/browser/device_service.h"
#include "extensions/buildflags/buildflags.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/origin.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "components/user_manager/user.h"
#endif
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "base/containers/fixed_flat_set.h"
#include "extensions/common/constants.h"
#endif
namespace {
constexpr char kHidDeviceNameKey[] = …;
constexpr char kHidGuidKey[] = …;
constexpr char kHidVendorIdKey[] = …;
constexpr char kHidProductIdKey[] = …;
constexpr char kHidSerialNumberKey[] = …;
SettingSource;
bool IsPolicyGrantedObject(const base::Value::Dict& object) { … }
base::Value::Dict VendorAndProductIdsToValue(uint16_t vendor_id,
uint16_t product_id) { … }
base::Value::Dict VendorIdToValue(uint16_t vendor_id) { … }
base::Value::Dict UsagePageAndUsageToValue(uint16_t usage_page,
uint16_t usage) { … }
base::Value::Dict UsagePageToValue(uint16_t usage_page) { … }
}
void HidChooserContext::DeviceObserver::OnDeviceAdded(
const device::mojom::HidDeviceInfo& device) { … }
void HidChooserContext::DeviceObserver::OnDeviceRemoved(
const device::mojom::HidDeviceInfo& device) { … }
void HidChooserContext::DeviceObserver::OnDeviceChanged(
const device::mojom::HidDeviceInfo& device) { … }
void HidChooserContext::DeviceObserver::OnHidManagerConnectionError() { … }
HidChooserContext::HidChooserContext(Profile* profile)
: … { … }
HidChooserContext::~HidChooserContext() { … }
base::Value::Dict HidChooserContext::DeviceInfoToValue(
const device::mojom::HidDeviceInfo& device) { … }
std::u16string HidChooserContext::DisplayNameFromDeviceInfo(
const device::mojom::HidDeviceInfo& device) { … }
bool HidChooserContext::CanStorePersistentEntry(
const device::mojom::HidDeviceInfo& device) { … }
std::u16string HidChooserContext::GetObjectDisplayName(
const base::Value::Dict& object) { … }
std::string HidChooserContext::GetKeyForObject(
const base::Value::Dict& object) { … }
bool HidChooserContext::IsValidObject(const base::Value::Dict& object) { … }
std::vector<std::unique_ptr<permissions::ObjectPermissionContextBase::Object>>
HidChooserContext::GetGrantedObjects(const url::Origin& origin) { … }
std::vector<std::unique_ptr<permissions::ObjectPermissionContextBase::Object>>
HidChooserContext::GetAllGrantedObjects() { … }
void HidChooserContext::RevokeObjectPermission(
const url::Origin& origin,
const base::Value::Dict& object) { … }
void HidChooserContext::GrantDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
const std::optional<url::Origin>& embedding_origin_of_web_view) { … }
void HidChooserContext::RevokeDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
const std::optional<url::Origin>& embedding_origin_of_web_view) { … }
void HidChooserContext::RevokePersistentDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) { … }
void HidChooserContext::RevokeEphemeralDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) { … }
bool HidChooserContext::HasDevicePermission(
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device,
const std::optional<url::Origin>& embedding_origin_of_web_view) { … }
bool HidChooserContext::IsFidoAllowedForOrigin(const url::Origin& origin) { … }
void HidChooserContext::AddDeviceObserver(DeviceObserver* observer) { … }
void HidChooserContext::RemoveDeviceObserver(DeviceObserver* observer) { … }
void HidChooserContext::GetDevices(
device::mojom::HidManager::GetDevicesCallback callback) { … }
const device::mojom::HidDeviceInfo* HidChooserContext::GetDeviceInfo(
const std::string& guid) { … }
device::mojom::HidManager* HidChooserContext::GetHidManager() { … }
void HidChooserContext::SetHidManagerForTesting(
mojo::PendingRemote<device::mojom::HidManager> manager,
device::mojom::HidManager::GetDevicesCallback callback) { … }
void HidChooserContext::OnHidManagerInitializedForTesting(
device::mojom::HidManager::GetDevicesCallback callback,
std::vector<device::mojom::HidDeviceInfoPtr> devices) { … }
void HidChooserContext::PermissionForWebViewChanged() { … }
void HidChooserContext::PermissionForWebViewRevoked(
const url::Origin& web_view_origin) { … }
base::WeakPtr<HidChooserContext> HidChooserContext::AsWeakPtr() { … }
void HidChooserContext::Shutdown() { … }
void HidChooserContext::DeviceAdded(device::mojom::HidDeviceInfoPtr device) { … }
void HidChooserContext::DeviceRemoved(device::mojom::HidDeviceInfoPtr device) { … }
void HidChooserContext::DeviceChanged(device::mojom::HidDeviceInfoPtr device) { … }
void HidChooserContext::EnsureHidManagerConnection() { … }
void HidChooserContext::SetUpHidManagerConnection(
mojo::PendingRemote<device::mojom::HidManager> manager) { … }
void HidChooserContext::InitDeviceList(
std::vector<device::mojom::HidDeviceInfoPtr> devices) { … }
void HidChooserContext::OnHidManagerConnectionError() { … }
bool HidChooserContext::CanApplyPolicy() { … }