60c4c9fec6
* chore: iwyu buildflags.h * chore: iwyu dictionary.h * chore: iwyu arguments.h * chore: iwyu values.h * chore: iwyu compiler_specific.h * chore: iwyu binder_map.h * chore: iwyu <vector> * chore: iwyu <set> * chore: iwyu raw_ptr * chore: iwyu gfx/canvas.h * chore: iwyu gfx/color_utils.h * chore: iwyu base/strings/stringprintf.h * chore: iwyu base/task/thread_pool.h * chore: iwyu base/no_destructor.h * chore: iwyu base/path_service.h * chore: iwyu base/files/file_pathh * chore: iwyu base/strings/sys_string_conversions.h * chore: iwyu base/logging.h * chore: iwyu base/command_line.h * chore: iwyu base/files/file_util.h * chore: iwyu base/files/scoped_file.h * chore: iwyu base/strings/utf_string_conversions.h * chore: iwyu base/environment.h * chore: iwyu base/scoped_observation.h * chore: iwyu base/strings/string_split.h * chore: iwyu base/strings/pattern.h * chore: iwyu base/json/string_escape.h * chore: iwyu base/json/json_reader.h * chore: iwyu base/memory/singleton.h * chore: iwyu base/observer_list.h * chore: iwyu base/timer/timer.h * fixup! chore: iwyu values.h * chore: iwyu shell/browser/browser.h * chore: iwyu base/stl_util.h * chore: iwyu base/strings/string_util.h * chore: iwyu shell/browser/javascript_environment.h * chore: iwyu base/memory/ref_counted.h * chore: iwyu base/environment.h * chore: iwyu content/public/browser/browser_thread.h * chore: remove unused typedef gin_helper::EventEmitter::ValueArray * chore: iwyu gin/wrappable.h * chore: iwyu shell/common/gin_helper/function_template_extensions.h * chore: iwyu shell/common/gin_converters/login_item_settings_converter.h * chore: iwyu shell/common/gin_helper/arguments.h * chore: iwyu ui/gfx/skia_util.h * chore: iwyu ui/gfx/geometry/rect.h * chore: iwyu ui/gfx/image/image.h * chore: iwyu base/strings/strcat.h * chore: iwyu ui/native_theme/native_theme.h * fixup! chore: iwyu shell/browser/javascript_environment.h * fixup! chore: iwyu gfx/canvas.h * fixup! chore: iwyu content/public/browser/browser_thread.h * fixup! chore: iwyu ui/native_theme/native_theme.h * fixup! chore: iwyu ui/native_theme/native_theme.h
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
// Copyright (c) 2022 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_USB_USB_CHOOSER_CONTROLLER_H_
|
|
#define ELECTRON_SHELL_BROWSER_USB_USB_CHOOSER_CONTROLLER_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
#include "base/scoped_observation.h"
|
|
#include "content/public/browser/web_contents.h"
|
|
#include "content/public/browser/web_contents_observer.h"
|
|
#include "services/device/public/mojom/usb_device.mojom.h"
|
|
#include "shell/browser/api/electron_api_session.h"
|
|
#include "shell/browser/usb/electron_usb_delegate.h"
|
|
#include "shell/browser/usb/usb_chooser_context.h"
|
|
#include "third_party/blink/public/mojom/usb/web_usb_service.mojom.h"
|
|
#include "url/origin.h"
|
|
|
|
namespace content {
|
|
class RenderFrameHost;
|
|
}
|
|
|
|
namespace electron {
|
|
|
|
// UsbChooserController creates a chooser for WebUSB.
|
|
class UsbChooserController final : private UsbChooserContext::DeviceObserver,
|
|
private content::WebContentsObserver {
|
|
public:
|
|
UsbChooserController(
|
|
content::RenderFrameHost* render_frame_host,
|
|
blink::mojom::WebUsbRequestDeviceOptionsPtr options,
|
|
blink::mojom::WebUsbService::GetPermissionCallback callback,
|
|
content::WebContents* web_contents,
|
|
base::WeakPtr<ElectronUsbDelegate> usb_delegate);
|
|
|
|
UsbChooserController(const UsbChooserController&) = delete;
|
|
UsbChooserController& operator=(const UsbChooserController&) = delete;
|
|
|
|
~UsbChooserController() override;
|
|
|
|
// UsbChooserContext::DeviceObserver implementation:
|
|
void OnDeviceAdded(const device::mojom::UsbDeviceInfo& device_info) override;
|
|
void OnDeviceRemoved(
|
|
const device::mojom::UsbDeviceInfo& device_info) override;
|
|
void OnBrowserContextShutdown() override;
|
|
|
|
// content::WebContentsObserver:
|
|
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
|
|
|
|
private:
|
|
api::Session* GetSession();
|
|
void GotUsbDeviceList(std::vector<device::mojom::UsbDeviceInfoPtr> devices);
|
|
bool DisplayDevice(const device::mojom::UsbDeviceInfo& device) const;
|
|
void RunCallback(device::mojom::UsbDeviceInfoPtr device_info);
|
|
void OnDeviceChosen(gin::Arguments* args);
|
|
|
|
blink::mojom::WebUsbRequestDeviceOptionsPtr options_;
|
|
blink::mojom::WebUsbService::GetPermissionCallback callback_;
|
|
url::Origin origin_;
|
|
|
|
base::WeakPtr<UsbChooserContext> chooser_context_;
|
|
base::ScopedObservation<UsbChooserContext, UsbChooserContext::DeviceObserver>
|
|
observation_{this};
|
|
|
|
base::WeakPtr<ElectronUsbDelegate> usb_delegate_;
|
|
|
|
content::GlobalRenderFrameHostId render_frame_host_id_;
|
|
|
|
base::WeakPtrFactory<UsbChooserController> weak_factory_{this};
|
|
};
|
|
|
|
} // namespace electron
|
|
|
|
#endif // ELECTRON_SHELL_BROWSER_USB_USB_CHOOSER_CONTROLLER_H_
|