git: 04ee4737c5f7 - main - www/chromium: Enable Widevine DRM via foreign-cdm.

From: Gleb Popov <arrowd_at_FreeBSD.org>
Date: Sun, 01 Oct 2023 14:59:13 UTC
The branch main has been updated by arrowd:

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

commit 04ee4737c5f74da5b7d2e6d0f7f40a06343e1222
Author:     Gleb Popov <arrowd@FreeBSD.org>
AuthorDate: 2023-09-04 17:16:44 +0000
Commit:     Gleb Popov <arrowd@FreeBSD.org>
CommitDate: 2023-10-01 14:59:09 +0000

    www/chromium: Enable Widevine DRM via foreign-cdm.
    
    These patches allow native Chromium to call out to the Linux Widevine library
    via a proxy program called foreign-cdm.
    
    Reviewed by: rnagy
    
    Differential Revision: https://reviews.freebsd.org/D42026
---
 www/chromium/Makefile                              |  7 ++-
 www/chromium/files/chrome.in                       |  5 +++
 ..._updater_widevine__cdm__component__installer.cc | 11 +++++
 .../patch-chrome_common_media_cdm__registration.cc | 52 ++++++++++++++++++++++
 ...a_component__widevine__cdm__hint__file__linux.h | 11 +++++
 .../patch-media_cdm_library__cdm_cdm__paths.gni    | 11 +++++
 .../patch-third__party_widevine_cdm_widevine.gni   | 10 +++++
 7 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/www/chromium/Makefile b/www/chromium/Makefile
index 6eee12f3ebd9..fdd0526fd357 100644
--- a/www/chromium/Makefile
+++ b/www/chromium/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	chromium
 PORTVERSION=	117.0.5938.132
+PORTREVISION=	1
 CATEGORIES=	www wayland
 MASTER_SITES=	https://commondatastorage.googleapis.com/chromium-browser-official/ \
 		https://nerd.hu/distfiles/:external
@@ -102,6 +103,7 @@ GN_ARGS+=	clang_use_chrome_plugins=false \
 		enable_nacl=false \
 		enable_remoting=false \
 		enable_rust=false \
+		enable_widevine=true \
 		fatal_linker_warnings=false \
 		icu_use_data_file=false \
 		is_clang=true \
@@ -137,7 +139,7 @@ GN_ARGS+=	google_api_key="AIzaSyBsp9n41JLW8jCokwn7vhoaMejDFRd1mp8"
 SUB_FILES=	chromium-browser.desktop chrome
 SUB_LIST+=	COMMENT="${COMMENT}"
 
-OPTIONS_DEFINE=		CODECS CUPS DEBUG DRIVER KERBEROS LTO PIPEWIRE TEST
+OPTIONS_DEFINE=		CODECS CUPS DEBUG DRIVER KERBEROS LTO PIPEWIRE TEST WIDEVINE
 OPTIONS_DEFAULT=	CODECS CUPS DRIVER KERBEROS PIPEWIRE SNDIO
 OPTIONS_EXCLUDE_aarch64=LTO
 OPTIONS_GROUP=		AUDIO
@@ -212,6 +214,9 @@ SNDIO_LIB_DEPENDS=	libsndio.so:audio/sndio
 SNDIO_VARS=		GN_ARGS+=use_sndio=true
 SNDIO_VARS_OFF=		GN_ARGS+=use_sndio=false
 
+WIDEVINE_DESC=		Depend on foreign-cdm to enable playback of DRM content
+WIDEVINE_RUN_DEPENDS=	foreign-cdm>0:www/foreign-cdm
+
 .include "Makefile.tests"
 TEST_DISTFILES=		${PORTNAME}-${DISTVERSION}-testdata${EXTRACT_SUFX} \
 			test_fonts-336e775eec536b2d785cc80eff6ac39051931286.tar.gz:external
diff --git a/www/chromium/files/chrome.in b/www/chromium/files/chrome.in
index 51ebe9d24bf2..9bd861920963 100644
--- a/www/chromium/files/chrome.in
+++ b/www/chromium/files/chrome.in
@@ -16,4 +16,9 @@ EOMSG
 	exit 1
 fi
 ulimit -c 0
+
+# variables for foreign-cdm
+export FCDM_CDM_SO_PATH=/compat/linux/usr/lib/foreign-cdm/libwidevinecdm.so
+export FCDM_WORKER_PATH=/compat/linux/usr/bin/fcdm-worker
+
 exec %%PREFIX%%/share/chromium/chrome ${1+"$@"}
diff --git a/www/chromium/files/patch-chrome_browser_component__updater_widevine__cdm__component__installer.cc b/www/chromium/files/patch-chrome_browser_component__updater_widevine__cdm__component__installer.cc
new file mode 100644
index 000000000000..ff0187e1cc42
--- /dev/null
+++ b/www/chromium/files/patch-chrome_browser_component__updater_widevine__cdm__component__installer.cc
@@ -0,0 +1,11 @@
+--- chrome/browser/component_updater/widevine_cdm_component_installer.cc.orig	2023-09-04 16:07:23 UTC
++++ chrome/browser/component_updater/widevine_cdm_component_installer.cc
+@@ -72,6 +72,8 @@ const char kWidevineCdmPlatform[] =
+     "cros";
+ #elif BUILDFLAG(IS_LINUX)
+     "linux";
++#elif BUILDFLAG(IS_FREEBSD)
++    "linux";
+ #else
+ #error This file should only be included for supported platforms.
+ #endif
diff --git a/www/chromium/files/patch-chrome_common_media_cdm__registration.cc b/www/chromium/files/patch-chrome_common_media_cdm__registration.cc
new file mode 100644
index 000000000000..cc4ebfdb5a15
--- /dev/null
+++ b/www/chromium/files/patch-chrome_common_media_cdm__registration.cc
@@ -0,0 +1,52 @@
+--- chrome/common/media/cdm_registration.cc.orig	2023-09-04 16:08:25 UTC
++++ chrome/common/media/cdm_registration.cc
+@@ -25,11 +25,11 @@
+ 
+ #if BUILDFLAG(ENABLE_WIDEVINE)
+ #include "third_party/widevine/cdm/widevine_cdm_common.h"  // nogncheck
+-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
++#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FREEBSD)
+ #include "base/native_library.h"
+ #include "chrome/common/chrome_paths.h"
+ #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
+-#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
++#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FREEBSD)
+ #include "base/no_destructor.h"
+ #include "components/cdm/common/cdm_manifest.h"
+ #include "media/cdm/supported_audio_codecs.h"
+@@ -58,7 +58,7 @@ using Robustness = content::CdmInfo::Robustness;
+ #if BUILDFLAG(ENABLE_WIDEVINE)
+ #if (BUILDFLAG(BUNDLE_WIDEVINE_CDM) ||            \
+      BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)) && \
+-    (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
++    (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FREEBSD))
+ // Create a CdmInfo for a Widevine CDM, using |version|, |cdm_library_path|, and
+ // |capability|.
+ std::unique_ptr<content::CdmInfo> CreateWidevineCdmInfo(
+@@ -101,7 +101,7 @@ std::unique_ptr<content::CdmInfo> CreateCdmInfoFromWid
+         // BUILDFLAG(IS_CHROMEOS))
+ 
+ #if BUILDFLAG(BUNDLE_WIDEVINE_CDM) && \
+-    (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
++    (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FREEBSD))
+ // On Linux/ChromeOS we have to preload the CDM since it uses the zygote
+ // sandbox. On Windows and Mac, the bundled CDM is handled by the component
+ // updater.
+@@ -125,7 +125,7 @@ content::CdmInfo* GetBundledWidevine() {
+         // BUILDFLAG(IS_CHROMEOS))
+ 
+ #if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT) && \
+-    (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS))
++    (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FREEBSD))
+ // This code checks to see if a component updated Widevine CDM can be found. If
+ // there is one and it looks valid, return the CdmInfo for that CDM. Otherwise
+ // return nullptr.
+@@ -160,7 +160,7 @@ void AddSoftwareSecureWidevine(std::vector<content::Cd
+       /*supports_sub_key_systems=*/false, kWidevineCdmDisplayName,
+       kWidevineCdmType, base::Version(), base::FilePath());
+ 
+-#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
++#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_FREEBSD)
+ #if defined(WIDEVINE_CDM_MIN_GLIBC_VERSION)
+   base::Version glibc_version(gnu_get_libc_version());
+   DCHECK(glibc_version.IsValid());
diff --git a/www/chromium/files/patch-chrome_common_media_component__widevine__cdm__hint__file__linux.h b/www/chromium/files/patch-chrome_common_media_component__widevine__cdm__hint__file__linux.h
new file mode 100644
index 000000000000..b8d1b2ff2528
--- /dev/null
+++ b/www/chromium/files/patch-chrome_common_media_component__widevine__cdm__hint__file__linux.h
@@ -0,0 +1,11 @@
+--- chrome/common/media/component_widevine_cdm_hint_file_linux.h.orig	2023-09-04 16:25:40 UTC
++++ chrome/common/media/component_widevine_cdm_hint_file_linux.h
+@@ -15,7 +15,7 @@
+ 
+ // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch
+ // of lacros-chrome is complete.
+-#if !(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS))
++#if !(BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_FREEBSD))
+ #error "This file only applies to desktop Linux."
+ #endif
+ 
diff --git a/www/chromium/files/patch-media_cdm_library__cdm_cdm__paths.gni b/www/chromium/files/patch-media_cdm_library__cdm_cdm__paths.gni
new file mode 100644
index 000000000000..751a1249d677
--- /dev/null
+++ b/www/chromium/files/patch-media_cdm_library__cdm_cdm__paths.gni
@@ -0,0 +1,11 @@
+--- media/cdm/library_cdm/cdm_paths.gni.orig	2023-09-04 16:51:48 UTC
++++ media/cdm/library_cdm/cdm_paths.gni
+@@ -23,6 +23,8 @@ if (is_chromeos) {
+   component_os = "mac"
+ } else if (is_fuchsia) {
+   component_os = "fuchsia"
++} else if (is_freebsd) {
++  component_os = "linux"
+ } else {
+   assert(false, "unsupported_platform")
+ }
diff --git a/www/chromium/files/patch-third__party_widevine_cdm_widevine.gni b/www/chromium/files/patch-third__party_widevine_cdm_widevine.gni
new file mode 100644
index 000000000000..8c0c0ff81bf4
--- /dev/null
+++ b/www/chromium/files/patch-third__party_widevine_cdm_widevine.gni
@@ -0,0 +1,10 @@
+--- third_party/widevine/cdm/widevine.gni.orig	2023-09-04 17:14:29 UTC
++++ third_party/widevine/cdm/widevine.gni
+@@ -27,6 +27,7 @@ library_widevine_cdm_available =
+     (is_chromeos &&
+      (target_cpu == "x64" || target_cpu == "arm" || target_cpu == "arm64")) ||
+     (target_os == "linux" && target_cpu == "x64") ||
++    (target_os == "freebsd" && target_cpu == "x64") ||
+     (target_os == "mac" && (target_cpu == "x64" || target_cpu == "arm64")) ||
+     (target_os == "win" &&
+      (target_cpu == "x86" || target_cpu == "x64" || target_cpu == "arm64"))