#include "chrome/browser/hid/chrome_hid_delegate.h"
#include <cstddef>
#include <utility>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/observer_list.h"
#include "base/scoped_observation.h"
#include "chrome/browser/hid/hid_chooser_context.h"
#include "chrome/browser/hid/hid_chooser_context_factory.h"
#include "chrome/browser/hid/hid_connection_tracker.h"
#include "chrome/browser/hid/hid_connection_tracker_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/hid/hid_chooser.h"
#include "chrome/browser/ui/hid/hid_chooser_controller.h"
#include "chrome/common/chrome_features.h"
#include "components/permissions/object_permission_context_base.h"
#include "content/public/browser/render_frame_host.h"
#include "extensions/buildflags/buildflags.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "services/device/public/mojom/hid.mojom-forward.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_features.h"
#endif
namespace {
HidChooserContext* GetChooserContext(content::BrowserContext* browser_context) { … }
HidConnectionTracker* GetConnectionTracker(
content::BrowserContext* browser_context,
bool create) { … }
std::optional<url::Origin> GetWebViewEmbedderOrigin(
content::RenderFrameHost* render_frame_host) { … }
#if BUILDFLAG(ENABLE_EXTENSIONS)
void GrantDevicePermission(
content::GlobalRenderFrameHostId requesting_rfh_id,
content::HidChooser::Callback callback,
std::vector<device::mojom::HidDeviceInfoPtr> devices) { … }
#endif
}
class ChromeHidDelegate::ContextObservation
: public permissions::ObjectPermissionContextBase::PermissionObserver,
public HidChooserContext::DeviceObserver { … };
ChromeHidDelegate::ChromeHidDelegate() = default;
ChromeHidDelegate::~ChromeHidDelegate() = default;
std::unique_ptr<content::HidChooser> ChromeHidDelegate::RunChooser(
content::RenderFrameHost* render_frame_host,
std::vector<blink::mojom::HidDeviceFilterPtr> filters,
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
content::HidChooser::Callback callback) { … }
bool ChromeHidDelegate::CanRequestDevicePermission(
content::BrowserContext* browser_context,
const url::Origin& origin) { … }
bool ChromeHidDelegate::HasDevicePermission(
content::BrowserContext* browser_context,
content::RenderFrameHost* render_frame_host,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) { … }
void ChromeHidDelegate::RevokeDevicePermission(
content::BrowserContext* browser_context,
content::RenderFrameHost* render_frame_host,
const url::Origin& origin,
const device::mojom::HidDeviceInfo& device) { … }
device::mojom::HidManager* ChromeHidDelegate::GetHidManager(
content::BrowserContext* browser_context) { … }
void ChromeHidDelegate::AddObserver(content::BrowserContext* browser_context,
Observer* observer) { … }
void ChromeHidDelegate::RemoveObserver(
content::BrowserContext* browser_context,
content::HidDelegate::Observer* observer) { … }
const device::mojom::HidDeviceInfo* ChromeHidDelegate::GetDeviceInfo(
content::BrowserContext* browser_context,
const std::string& guid) { … }
bool ChromeHidDelegate::IsFidoAllowedForOrigin(
content::BrowserContext* browser_context,
const url::Origin& origin) { … }
bool ChromeHidDelegate::IsServiceWorkerAllowedForOrigin(
const url::Origin& origin) { … }
ChromeHidDelegate::ContextObservation* ChromeHidDelegate::GetContextObserver(
content::BrowserContext* browser_context) { … }
void ChromeHidDelegate::IncrementConnectionCount(
content::BrowserContext* browser_context,
const url::Origin& origin) { … }
void ChromeHidDelegate::DecrementConnectionCount(
content::BrowserContext* browser_context,
const url::Origin& origin) { … }
#if BUILDFLAG(ENABLE_EXTENSIONS)
void ChromeHidDelegate::OnWebViewHidPermissionRequestCompleted(
base::WeakPtr<HidChooser> chooser,
content::GlobalRenderFrameHostId embedder_rfh_id,
std::vector<blink::mojom::HidDeviceFilterPtr> filters,
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
content::HidChooser::Callback callback,
bool allow) { … }
#endif