electron/shell/browser/serial/electron_serial_delegate.h
electron-roller[bot] 150c2bcef9
chore: bump chromium to 124.0.6351.0 (main) (#41514)
* chore: bump chromium in DEPS to 124.0.6339.0

* chore: update patches

* chore: bump chromium in DEPS to 124.0.6341.0

* chore: update patches

* chore: bump chromium in DEPS to 124.0.6343.0

* chore: bump chromium in DEPS to 124.0.6345.0

* chore: update patches

* build: temporarily patch out usage of reclient inputs cfg

* chore: implement missing OnPortConnectedStateChanged

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5039155

* fix: move NativeHandlers in extensions to new RendererAPIProvider

Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5332839
Ref: https://chromium-review.googlesource.com/c/chromium/src/+/5334058

* chore: add missing websocket method

* refactor: use std::erase instead of base::Erase

Ref: https://issues.chromium.org/issues/40256229

* build: fix reclient inputs processor bug (workaround)

* fix: delay extensions::Dispatcher construction

* chore: bump chromium in DEPS to 124.0.6347.0

* chore: bump chromium in DEPS to 124.0.6349.0

* 5326217: [ViewsAX] Remove WebAXPlatformTreeManagerDelegate

https://chromium-review.googlesource.com/c/chromium/src/+/5326217

* 5347916: Get origin from parent for process-isolated srcdoc.

https://chromium-review.googlesource.com/c/chromium/src/+/5347916

* chore: patches fixup

* 4866222: [api] Deprecate vector<v8::Local>, part 1

https://chromium-review.googlesource.com/c/v8/v8/+/4866222

* 5337304: Remove DXDiag telemetry code.

https://chromium-review.googlesource.com/c/chromium/src/+/5337304

* 5328275: Implement watermark routing to the BrowserView

https://chromium-review.googlesource.com/c/chromium/src/+/5328275

* [libc++] Rename __fwd/hash.h to __fwd/functional.h and add reference_wrapper

* chore: bump chromium in DEPS to 124.0.6351.0

* chore: update patches

* 5342763: [object] Fast path for adding props with existing transition

https://chromium-review.googlesource.com/c/v8/v8/+/5342763

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <marshallofsound@electronjs.org>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2024-03-12 10:15:41 +01:00

105 lines
4 KiB
C++

// Copyright (c) 2020 Microsoft, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_SERIAL_ELECTRON_SERIAL_DELEGATE_H_
#define ELECTRON_SHELL_BROWSER_SERIAL_ELECTRON_SERIAL_DELEGATE_H_
#include <memory>
#include <unordered_map>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "content/public/browser/serial_delegate.h"
#include "shell/browser/serial/serial_chooser_context.h"
#include "shell/browser/serial/serial_chooser_controller.h"
namespace electron {
class SerialChooserController;
class ElectronSerialDelegate : public content::SerialDelegate,
public SerialChooserContext::PortObserver {
public:
ElectronSerialDelegate();
~ElectronSerialDelegate() override;
// disable copy
ElectronSerialDelegate(const ElectronSerialDelegate&) = delete;
ElectronSerialDelegate& operator=(const ElectronSerialDelegate&) = delete;
std::unique_ptr<content::SerialChooser> RunChooser(
content::RenderFrameHost* frame,
std::vector<blink::mojom::SerialPortFilterPtr> filters,
std::vector<device::BluetoothUUID> allowed_bluetooth_service_class_ids,
content::SerialChooser::Callback callback) override;
bool CanRequestPortPermission(content::RenderFrameHost* frame) override;
bool HasPortPermission(content::RenderFrameHost* frame,
const device::mojom::SerialPortInfo& port) override;
void RevokePortPermissionWebInitiated(
content::RenderFrameHost* frame,
const base::UnguessableToken& token) override;
const device::mojom::SerialPortInfo* GetPortInfo(
content::RenderFrameHost* frame,
const base::UnguessableToken& token) override;
device::mojom::SerialPortManager* GetPortManager(
content::RenderFrameHost* frame) override;
void AddObserver(content::RenderFrameHost* frame,
content::SerialDelegate::Observer* observer) override;
void RemoveObserver(content::RenderFrameHost* frame,
content::SerialDelegate::Observer* observer) override;
void DeleteControllerForFrame(content::RenderFrameHost* render_frame_host);
// SerialChooserContext::PortObserver:
void OnPortAdded(const device::mojom::SerialPortInfo& port) override;
void OnPortRemoved(const device::mojom::SerialPortInfo& port) override;
void OnPortConnectedStateChanged(
const device::mojom::SerialPortInfo& port) override {}
void OnPortManagerConnectionError() override;
void OnPermissionRevoked(const url::Origin& origin) override {}
void OnSerialChooserContextShutdown() override;
private:
SerialChooserController* ControllerForFrame(
content::RenderFrameHost* render_frame_host);
SerialChooserController* AddControllerForFrame(
content::RenderFrameHost* render_frame_host,
std::vector<blink::mojom::SerialPortFilterPtr> filters,
content::SerialChooser::Callback callback);
base::ScopedObservation<SerialChooserContext,
SerialChooserContext::PortObserver>
port_observation_{this};
base::ObserverList<content::SerialDelegate::Observer> observer_list_;
std::unordered_map<content::RenderFrameHost*,
std::unique_ptr<SerialChooserController>>
controller_map_;
base::WeakPtrFactory<ElectronSerialDelegate> weak_factory_{this};
};
} // namespace electron
namespace base {
template <>
struct ScopedObservationTraits<electron::SerialChooserContext,
electron::SerialChooserContext::PortObserver> {
static void AddObserver(
electron::SerialChooserContext* source,
electron::SerialChooserContext::PortObserver* observer) {
source->AddPortObserver(observer);
}
static void RemoveObserver(
electron::SerialChooserContext* source,
electron::SerialChooserContext::PortObserver* observer) {
source->RemovePortObserver(observer);
}
};
} // namespace base
#endif // ELECTRON_SHELL_BROWSER_SERIAL_ELECTRON_SERIAL_DELEGATE_H_