2021-09-23 11:00:11 +00:00
|
|
|
// 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.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_HID_ELECTRON_HID_DELEGATE_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_HID_ELECTRON_HID_DELEGATE_H_
|
2021-09-23 11:00:11 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/observer_list.h"
|
|
|
|
#include "base/scoped_observation.h"
|
|
|
|
#include "content/public/browser/hid_delegate.h"
|
|
|
|
#include "shell/browser/hid/hid_chooser_context.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class HidChooserController;
|
|
|
|
|
|
|
|
class ElectronHidDelegate : public content::HidDelegate,
|
|
|
|
public HidChooserContext::DeviceObserver {
|
|
|
|
public:
|
|
|
|
ElectronHidDelegate();
|
|
|
|
ElectronHidDelegate(ElectronHidDelegate&) = delete;
|
|
|
|
ElectronHidDelegate& operator=(ElectronHidDelegate&) = delete;
|
|
|
|
~ElectronHidDelegate() override;
|
|
|
|
|
|
|
|
// content::HidDelegate:
|
|
|
|
std::unique_ptr<content::HidChooser> RunChooser(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
std::vector<blink::mojom::HidDeviceFilterPtr> filters,
|
2022-04-12 11:19:14 +00:00
|
|
|
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
|
2021-09-23 11:00:11 +00:00
|
|
|
content::HidChooser::Callback callback) override;
|
2022-06-27 20:50:08 +00:00
|
|
|
bool CanRequestDevicePermission(content::BrowserContext* browser_context,
|
|
|
|
const url::Origin& origin) override;
|
|
|
|
bool HasDevicePermission(content::BrowserContext* browser_context,
|
|
|
|
const url::Origin& origin,
|
2021-09-23 11:00:11 +00:00
|
|
|
const device::mojom::HidDeviceInfo& device) override;
|
2022-02-10 02:58:52 +00:00
|
|
|
void RevokeDevicePermission(
|
2022-06-27 20:50:08 +00:00
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const url::Origin& origin,
|
2022-02-10 02:58:52 +00:00
|
|
|
const device::mojom::HidDeviceInfo& device) override;
|
2021-09-23 11:00:11 +00:00
|
|
|
device::mojom::HidManager* GetHidManager(
|
2022-06-27 20:50:08 +00:00
|
|
|
content::BrowserContext* browser_context) override;
|
|
|
|
void AddObserver(content::BrowserContext* browser_context,
|
2021-09-23 11:00:11 +00:00
|
|
|
content::HidDelegate::Observer* observer) override;
|
2022-08-17 18:35:53 +00:00
|
|
|
void RemoveObserver(content::BrowserContext* browser_context,
|
|
|
|
content::HidDelegate::Observer* observer) override;
|
2021-09-23 11:00:11 +00:00
|
|
|
const device::mojom::HidDeviceInfo* GetDeviceInfo(
|
2022-06-27 20:50:08 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2021-09-23 11:00:11 +00:00
|
|
|
const std::string& guid) override;
|
2022-06-27 20:50:08 +00:00
|
|
|
bool IsFidoAllowedForOrigin(content::BrowserContext* browser_context,
|
2022-02-10 02:58:52 +00:00
|
|
|
const url::Origin& origin) override;
|
2022-07-13 21:26:16 +00:00
|
|
|
bool IsServiceWorkerAllowedForOrigin(const url::Origin& origin) override;
|
2021-09-23 11:00:11 +00:00
|
|
|
|
|
|
|
// HidChooserContext::DeviceObserver:
|
|
|
|
void OnDeviceAdded(const device::mojom::HidDeviceInfo&) override;
|
|
|
|
void OnDeviceRemoved(const device::mojom::HidDeviceInfo&) override;
|
|
|
|
void OnDeviceChanged(const device::mojom::HidDeviceInfo&) override;
|
|
|
|
void OnHidManagerConnectionError() override;
|
|
|
|
void OnHidChooserContextShutdown() override;
|
|
|
|
|
|
|
|
void DeleteControllerForFrame(content::RenderFrameHost* render_frame_host);
|
|
|
|
|
|
|
|
private:
|
|
|
|
HidChooserController* ControllerForFrame(
|
|
|
|
content::RenderFrameHost* render_frame_host);
|
|
|
|
|
|
|
|
HidChooserController* AddControllerForFrame(
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
std::vector<blink::mojom::HidDeviceFilterPtr> filters,
|
2022-04-12 11:19:14 +00:00
|
|
|
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
|
2021-09-23 11:00:11 +00:00
|
|
|
content::HidChooser::Callback callback);
|
|
|
|
|
2022-11-17 19:59:23 +00:00
|
|
|
base::ScopedObservation<HidChooserContext, HidChooserContext::DeviceObserver>
|
2021-09-23 11:00:11 +00:00
|
|
|
device_observation_{this};
|
|
|
|
base::ObserverList<content::HidDelegate::Observer> observer_list_;
|
|
|
|
|
|
|
|
std::unordered_map<content::RenderFrameHost*,
|
|
|
|
std::unique_ptr<HidChooserController>>
|
|
|
|
controller_map_;
|
|
|
|
|
|
|
|
base::WeakPtrFactory<ElectronHidDelegate> weak_factory_{this};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2022-11-17 19:59:23 +00:00
|
|
|
namespace base {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct base::ScopedObservationTraits<
|
|
|
|
electron::HidChooserContext,
|
|
|
|
electron::HidChooserContext::DeviceObserver> {
|
|
|
|
static void AddObserver(
|
|
|
|
electron::HidChooserContext* source,
|
|
|
|
electron::HidChooserContext::DeviceObserver* observer) {
|
|
|
|
source->AddDeviceObserver(observer);
|
|
|
|
}
|
|
|
|
static void RemoveObserver(
|
|
|
|
electron::HidChooserContext* source,
|
|
|
|
electron::HidChooserContext::DeviceObserver* observer) {
|
|
|
|
source->RemoveDeviceObserver(observer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace base
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_HID_ELECTRON_HID_DELEGATE_H_
|