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>
|
|
|
|
|
2023-10-17 20:54:53 +00:00
|
|
|
#include "base/containers/flat_map.h"
|
|
|
|
#include "content/public/browser/hid_chooser.h"
|
2021-09-23 11:00:11 +00:00
|
|
|
#include "content/public/browser/hid_delegate.h"
|
2023-10-17 20:54:53 +00:00
|
|
|
#include "services/device/public/mojom/hid.mojom-forward.h"
|
|
|
|
#include "third_party/blink/public/mojom/hid/hid.mojom-forward.h"
|
|
|
|
#include "url/origin.h"
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class BrowserContext;
|
|
|
|
class RenderFrameHost;
|
|
|
|
} // namespace content
|
2021-09-23 11:00:11 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
class HidChooserController;
|
|
|
|
|
2023-10-17 20:54:53 +00:00
|
|
|
class ElectronHidDelegate : public content::HidDelegate {
|
2021-09-23 11:00:11 +00:00
|
|
|
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,
|
2024-02-29 09:31:13 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2022-06-27 20:50:08 +00:00
|
|
|
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,
|
2024-02-29 09:31:13 +00:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2022-06-27 20:50:08 +00:00
|
|
|
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;
|
2023-01-06 02:35:34 +00:00
|
|
|
void IncrementConnectionCount(content::BrowserContext* browser_context,
|
|
|
|
const url::Origin& origin) override {}
|
|
|
|
void DecrementConnectionCount(content::BrowserContext* browser_context,
|
|
|
|
const url::Origin& origin) override {}
|
2021-09-23 11:00:11 +00:00
|
|
|
|
|
|
|
void DeleteControllerForFrame(content::RenderFrameHost* render_frame_host);
|
|
|
|
|
|
|
|
private:
|
2023-10-17 20:54:53 +00:00
|
|
|
class ContextObservation;
|
|
|
|
|
|
|
|
ContextObservation* GetContextObserver(
|
|
|
|
content::BrowserContext* browser_context);
|
|
|
|
|
|
|
|
base::flat_map<content::BrowserContext*, std::unique_ptr<ContextObservation>>
|
|
|
|
observations_;
|
|
|
|
|
2021-09-23 11:00:11 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
std::unordered_map<content::RenderFrameHost*,
|
|
|
|
std::unique_ptr<HidChooserController>>
|
|
|
|
controller_map_;
|
|
|
|
|
|
|
|
base::WeakPtrFactory<ElectronHidDelegate> weak_factory_{this};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_HID_ELECTRON_HID_DELEGATE_H_
|