From 34c7ff41eddc40321c93fe6e48ad001418e88780 Mon Sep 17 00:00:00 2001
From: psykose <alice@ayaya.dev>
Date: Fri, 20 Jan 2023 08:41:03 +0000
Subject: [PATCH] community/chromium: re-enable system icu

---
 community/chromium/APKBUILD         |  8 ++--
 community/chromium/system-icu.patch | 63 +++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 3 deletions(-)
 create mode 100644 community/chromium/system-icu.patch

diff --git a/community/chromium/APKBUILD b/community/chromium/APKBUILD
index aac114678441..bda2ae6bc3ff 100644
--- a/community/chromium/APKBUILD
+++ b/community/chromium/APKBUILD
@@ -3,7 +3,7 @@
 # Maintainer: psykose <alice@ayaya.dev>
 pkgname=chromium
 pkgver=109.0.5414.74
-pkgrel=2
+pkgrel=3
 pkgdesc="Chromium web browser"
 url="https://www.chromium.org/Home"
 arch="aarch64 armv7 x86_64"
@@ -130,6 +130,7 @@ source="https://commondatastorage.googleapis.com/chromium-browser-official/chrom
 	quiche-arena-size.patch
 	roll-src-third_party-ffmpeg-106.patch
 	scoped-file-no-close.patch
+	system-icu.patch
 	temp-failure-retry.patch
 	wtf-stacksize.patch
 	"
@@ -465,7 +466,6 @@ prepare() {
 	ln -s /usr/bin/node third_party/node/linux/node-linux-x64/bin/
 
 	# reusable system library settings
-	#icu - temp disabled
 	local use_system="
 		brotli
 		dav1d
@@ -474,6 +474,7 @@ prepare() {
 		fontconfig
 		freetype
 		harfbuzz-ng
+		icu
 		jsoncpp
 		libaom
 		libavif
@@ -576,7 +577,7 @@ build() {
 		google_default_client_id=\"$_google_default_client_id\"
 		google_default_client_secret=\"$_google_default_client_secret\"
 		host_toolchain=\"//build/toolchain/linux/unbundle:default\"
-		icu_use_data_file=true
+		icu_use_data_file=false
 		is_cfi=false
 		is_component_ffmpeg=true
 		is_debug=false
@@ -888,6 +889,7 @@ ad563e29ac7d83c203f5af966c4ed3ebdeb5c997835a45fb28ecde08dde5231d0a775fb413f44867
 d315ef36952f35f834742a063b11b312b3adc2b86fc34a73a6906652f4042e6537789aeae5aade3c60523a80eac8d9751eecac3716831b99a2f8725d4ce50df3  quiche-arena-size.patch
 1063e68f477645914ddf5641eabdd3eaf744e569635d645ea860c3546f67a7ef91eded99331378ee75071b67ecfe9bd4be307bd3da7c7ad93509e2bd634d1ec3  roll-src-third_party-ffmpeg-106.patch
 9c44875bcc5dd5431226568ba52d225f086b321325371d9e9e01d1fd892049e5aff324a89ba8268f32c59ce1a47e0b0d5448c9162a45ee5a60a58eecb69ca788  scoped-file-no-close.patch
+b1736d4cbcef69e83826c7f3c25cf5d18726d9bc9ebcd5ad59f070195461b7d8afd22db622452f6d5ce7f5c7f969ac9347553c4b2e028a633970eed6a5aa30f5  system-icu.patch
 ece751cd29d28772dd0955c84f5553a6858ac24d06ccb66ac75fcfc6b13460cf5c1f27392c094487e20e08e621d2099c3b5cc9a2a819a458e8c56c78fea11269  temp-failure-retry.patch
 1d4e8c6e65205e6b72af47b9a2fa6f96aaada9b7d5a74f4e11a345a885df3078b523d02aaf8e9dac3aa30d72bbbd07cd6dc7edcf44fb9ae57a7f81251c398f65  wtf-stacksize.patch
 "
diff --git a/community/chromium/system-icu.patch b/community/chromium/system-icu.patch
new file mode 100644
index 000000000000..b7059c45be91
--- /dev/null
+++ b/community/chromium/system-icu.patch
@@ -0,0 +1,63 @@
+Patch-Source: https://github.com/archlinux/svntogit-packages/blob/a0b214b3bdfbc7ee3d9004a70494a2b9e3da2c80/trunk/fix-the-way-to-handle-codecs-in-the-system-icu.patch
+https://crbug.com/1382032
+--
+From 4885090741554be61cb2ed10194cefb29bf8be64 Mon Sep 17 00:00:00 2001
+From: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
+Date: Wed, 11 Jan 2023 23:51:39 +0000
+Subject: [PATCH] Fix the way to handle codecs in the system icu.
+
+The previous code does not register codecs whose standard name is
+different from the bundled ICU.  As a result, looking up such codecs
+seems to fail unexpectedly.
+
+Bug: 1382032
+Change-Id: I8a61f77d0f70104415d24dd954b3b7061ffca556
+Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4154277
+Reviewed-by: Kent Tamura <tkent@chromium.org>
+Commit-Queue: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
+Cr-Commit-Position: refs/heads/main@{#1091571}
+---
+ .../renderer/platform/wtf/text/text_codec_icu.cc   | 14 ++++++++++----
+ 1 file changed, 10 insertions(+), 4 deletions(-)
+
+diff --git a/third_party/blink/renderer/platform/wtf/text/text_codec_icu.cc b/third_party/blink/renderer/platform/wtf/text/text_codec_icu.cc
+index a70b359984f..33ce43f3563 100644
+--- a/third_party/blink/renderer/platform/wtf/text/text_codec_icu.cc
++++ b/third_party/blink/renderer/platform/wtf/text/text_codec_icu.cc
+@@ -116,6 +116,10 @@ void TextCodecICU::RegisterEncodingNames(EncodingNameRegistrar registrar) {
+       continue;
+     }
+ #endif
++    // Avoid codecs supported by `TextCodecCJK`.
++    if (is_text_codec_cjk_enabled && TextCodecCJK::IsSupported(standard_name)) {
++      continue;
++    }
+ 
+ // A number of these aliases are handled in Chrome's copy of ICU, but
+ // Chromium can be compiled with the system ICU.
+@@ -144,12 +148,13 @@ void TextCodecICU::RegisterEncodingNames(EncodingNameRegistrar registrar) {
+     }
+ #endif
+ 
+-    if (is_text_codec_cjk_enabled && TextCodecCJK::IsSupported(standard_name)) {
+-      continue;
++    // Avoid registering codecs registered by
++    // `TextCodecCJK::RegisterEncodingNames`.
++    if (!is_text_codec_cjk_enabled ||
++        !TextCodecCJK::IsSupported(standard_name)) {
++      registrar(standard_name, standard_name);
+     }
+ 
+-    registrar(standard_name, standard_name);
+-
+     uint16_t num_aliases = ucnv_countAliases(name, &error);
+     DCHECK(U_SUCCESS(error));
+     if (U_SUCCESS(error))
+@@ -289,6 +294,7 @@ void TextCodecICU::RegisterCodecs(TextCodecRegistrar registrar) {
+       continue;
+     }
+ #endif
++    // Avoid codecs supported by `TextCodecCJK`.
+     if (is_text_codec_cjk_enabled && TextCodecCJK::IsSupported(standard_name)) {
+       continue;
+     }
-- 
GitLab