git: b92dcd07c7b1 - main - www/chromium: unbreak WebAuthn USB FIDO support by implementing a fake USB service

From: Rene Ladan <rene_at_FreeBSD.org>
Date: Sat, 29 Oct 2022 13:53:29 UTC
The branch main has been updated by rene:

URL: https://cgit.FreeBSD.org/ports/commit/?id=b92dcd07c7b1066c536dd24a8129dafe503f7fc9

commit b92dcd07c7b1066c536dd24a8129dafe503f7fc9
Author:     Robert Nagy <robert@openbsd.org>
AuthorDate: 2022-10-29 13:32:44 +0000
Commit:     Rene Ladan <rene@FreeBSD.org>
CommitDate: 2022-10-29 13:52:29 +0000

    www/chromium: unbreak WebAuthn USB FIDO support by implementing a fake USB service
    
    PR:             263790
---
 www/chromium/Makefile                              |  1 +
 .../files/patch-services_device_usb_BUILD.gn       | 20 ++++++--
 .../patch-services_device_usb_usb__service.cc      | 22 +++++++++
 ...patch-services_device_usb_usb__service__fake.cc | 54 ++++++++++++++++++++++
 .../patch-services_device_usb_usb__service__fake.h | 51 ++++++++++++++++++++
 5 files changed, 145 insertions(+), 3 deletions(-)

diff --git a/www/chromium/Makefile b/www/chromium/Makefile
index c6bae9d7775a..322244388162 100644
--- a/www/chromium/Makefile
+++ b/www/chromium/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	chromium
 PORTVERSION=	107.0.5304.87
+PORTREVISION=	1
 CATEGORIES=	www wayland
 MASTER_SITES=	https://commondatastorage.googleapis.com/chromium-browser-official/ \
 		https://nerd.hu/distfiles/:external
diff --git a/www/chromium/files/patch-services_device_usb_BUILD.gn b/www/chromium/files/patch-services_device_usb_BUILD.gn
index 9e9f692c95ad..d731f6cf42b4 100644
--- a/www/chromium/files/patch-services_device_usb_BUILD.gn
+++ b/www/chromium/files/patch-services_device_usb_BUILD.gn
@@ -1,4 +1,4 @@
---- services/device/usb/BUILD.gn.orig	2022-02-28 16:54:41 UTC
+--- services/device/usb/BUILD.gn.orig	2022-10-29 13:32:26 UTC
 +++ services/device/usb/BUILD.gn
 @@ -103,15 +103,17 @@ static_library("usb") {
      deps += [ "//third_party/re2" ]
@@ -13,7 +13,7 @@
 -      "usb_service_mac.cc",
 -      "usb_service_mac.h",
 -    ]
-+  if (is_mac || is_bsd) {
++  if (is_mac || is_openbsd) {
 +    if (is_mac) {
 +      sources += [
 +        "usb_device_handle_mac.cc",
@@ -27,7 +27,21 @@
  
      # These sources and deps are required for libusb.
      # TODO(https://crbug.com/1096743) Remove these sources.
-@@ -152,7 +154,7 @@ static_library("usb") {
+@@ -135,6 +137,13 @@ static_library("usb") {
+     deps += [ "//third_party/libusb" ]
+   }
+ 
++  if (is_freebsd) {
++    sources += [
++      "usb_service_fake.cc",
++      "usb_service_fake.h",
++    ]
++  }
++
+   if (is_linux || is_chromeos) {
+     sources += [
+       "usb_device_linux.cc",
+@@ -152,7 +161,7 @@ static_library("usb") {
      deps += [ "//device/udev_linux" ]
    }
  
diff --git a/www/chromium/files/patch-services_device_usb_usb__service.cc b/www/chromium/files/patch-services_device_usb_usb__service.cc
new file mode 100644
index 000000000000..296a4d907b0a
--- /dev/null
+++ b/www/chromium/files/patch-services_device_usb_usb__service.cc
@@ -0,0 +1,22 @@
+--- services/device/usb/usb_service.cc.orig	2022-10-29 13:32:26 UTC
++++ services/device/usb/usb_service.cc
+@@ -29,6 +29,10 @@
+ #include "services/device/usb/usb_service_mac.h"
+ #elif BUILDFLAG(IS_WIN)
+ #include "services/device/usb/usb_service_win.h"
++#elif BUILDFLAG(IS_OPENBSD)
++#include "services/device/usb/usb_service_impl.h"
++#elif BUILDFLAG(IS_FREEBSD)
++#include "services/device/usb/usb_service_fake.h"
+ #endif
+ 
+ namespace device {
+@@ -60,6 +64,8 @@ std::unique_ptr<UsbService> UsbService::Create() {
+     return base::WrapUnique(new UsbServiceMac());
+   else
+     return base::WrapUnique(new UsbServiceImpl());
++#elif BUILDFLAG(IS_BSD)
++  return base::WrapUnique(new UsbServiceImpl());
+ #else
+   return nullptr;
+ #endif
diff --git a/www/chromium/files/patch-services_device_usb_usb__service__fake.cc b/www/chromium/files/patch-services_device_usb_usb__service__fake.cc
new file mode 100644
index 000000000000..0ca04b12762e
--- /dev/null
+++ b/www/chromium/files/patch-services_device_usb_usb__service__fake.cc
@@ -0,0 +1,54 @@
+--- services/device/usb/usb_service_fake.cc.orig	2022-10-29 13:32:26 UTC
++++ services/device/usb/usb_service_fake.cc
+@@ -0,0 +1,51 @@
++// Copyright 2014 The Chromium Authors
++// Use of this source code is governed by a BSD-style license that can be
++// found in the LICENSE file.
++
++#include "services/device/usb/usb_service_fake.h"
++
++#include <stdint.h>
++
++#include <list>
++#include <memory>
++#include <set>
++#include <utility>
++
++#include "base/barrier_closure.h"
++#include "base/bind.h"
++#include "base/callback_helpers.h"
++#include "base/containers/contains.h"
++#include "base/location.h"
++#include "base/memory/ref_counted_memory.h"
++#include "base/memory/weak_ptr.h"
++#include "base/strings/string_number_conversions.h"
++#include "base/strings/utf_string_conversions.h"
++#include "base/task/sequenced_task_runner.h"
++#include "base/task/single_thread_task_runner.h"
++#include "base/task/thread_pool.h"
++#include "base/threading/scoped_blocking_call.h"
++#include "build/build_config.h"
++#include "components/device_event_log/device_event_log.h"
++#include "services/device/usb/usb_device_handle.h"
++#include "services/device/usb/usb_error.h"
++#include "services/device/usb/webusb_descriptors.h"
++
++namespace device {
++
++UsbServiceImpl::UsbServiceImpl()
++    : task_runner_(base::SequencedTaskRunnerHandle::Get()) {
++  NOTIMPLEMENTED();
++}
++
++UsbServiceImpl::~UsbServiceImpl() {
++  NOTIMPLEMENTED();
++  NotifyWillDestroyUsbService();
++}
++
++void UsbServiceImpl::GetDevices(GetDevicesCallback callback) {
++  NOTIMPLEMENTED();
++  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
++  UsbService::GetDevices(std::move(callback));
++}
++
++}  // namespace device
diff --git a/www/chromium/files/patch-services_device_usb_usb__service__fake.h b/www/chromium/files/patch-services_device_usb_usb__service__fake.h
new file mode 100644
index 000000000000..2e123db7f3be
--- /dev/null
+++ b/www/chromium/files/patch-services_device_usb_usb__service__fake.h
@@ -0,0 +1,51 @@
+--- services/device/usb/usb_service_fake.h.orig	2022-10-29 13:32:26 UTC
++++ services/device/usb/usb_service_fake.h
+@@ -0,0 +1,48 @@
++// Copyright 2015 The Chromium Authors
++// Use of this source code is governed by a BSD-style license that can be
++// found in the LICENSE file.
++
++#ifndef SERVICES_DEVICE_USB_USB_SERVICE_IMPL_H_
++#define SERVICES_DEVICE_USB_USB_SERVICE_IMPL_H_
++
++#include "services/device/usb/usb_service.h"
++
++#include <stddef.h>
++
++#include <map>
++#include <set>
++#include <string>
++#include <vector>
++
++#include "base/containers/queue.h"
++#include "base/memory/weak_ptr.h"
++#include "build/build_config.h"
++#include "services/device/usb/usb_context.h"
++#include "services/device/usb/usb_device_impl.h"
++#include "third_party/abseil-cpp/absl/types/optional.h"
++
++namespace device {
++
++class UsbDeviceImpl;
++
++class UsbServiceImpl final : public UsbService {
++ public:
++  UsbServiceImpl();
++
++  UsbServiceImpl(const UsbServiceImpl&) = delete;
++  UsbServiceImpl& operator=(const UsbServiceImpl&) = delete;
++
++  ~UsbServiceImpl() override;
++
++ private:
++  // device::UsbService implementation
++  void GetDevices(GetDevicesCallback callback) override;
++
++  void OnUsbContext(scoped_refptr<UsbContext> context);
++
++  scoped_refptr<base::SequencedTaskRunner> task_runner_;
++};
++
++}  // namespace device
++
++#endif  // SERVICES_DEVICE_USB_USB_SERVICE_IMPL_H_