From 307fbaa349be49e27a31dfd5f3489d5c74c644b8 Mon Sep 17 00:00:00 2001 From: Emerick Rogul Date: Sun, 14 May 2023 23:13:09 -0400 Subject: [PATCH] Longer prefixes in external_paths must be first or mappings will be incorrect Since external_paths was modified to support untrusted url's correctly, we need to insure that brave-specific directories are specified first as they have a longer prefix. In addition, the patch must be copied to bundle_js.gni as that will soon replace optimize_webui. Chromium change: https://source.chromium.org/chromium/chromium/src/+/8003c6a30571c4248237a3dba9e2ddca34ac527f commit 8003c6a30571c4248237a3dba9e2ddca34ac527f Author: dpapad Date: Wed May 3 01:08:52 2023 +0000 WebUI: Fix optimize_webui() external paths for untrusted contexts. Stop passing "chrome://" external paths to chrome-untrusted:// contexts, otherwise the output bundle uses chrome:// URLs which is incorrect. Clone the changes in optimize_webui.gni to bundle_js.gni as well. The latter will replace optimize_webui() eventually, and duplication will be removed in follow-ups. Bug: 1441217 --- ...i-webui-resources-tools-bundle_js.gni.patch | 12 ++++++++++++ ...ui-resources-tools-optimize_webui.gni.patch | 18 +++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 patches/ui-webui-resources-tools-bundle_js.gni.patch diff --git a/patches/ui-webui-resources-tools-bundle_js.gni.patch b/patches/ui-webui-resources-tools-bundle_js.gni.patch new file mode 100644 index 00000000000..363827fb49f --- /dev/null +++ b/patches/ui-webui-resources-tools-bundle_js.gni.patch @@ -0,0 +1,12 @@ +diff --git a/ui/webui/resources/tools/bundle_js.gni b/ui/webui/resources/tools/bundle_js.gni +index 6ef57e0cd1de46342a9fc8892fb121b7b2222265..79fb3fbc77e63eb4a9914c094ce7a3882a8aa904 100644 +--- a/ui/webui/resources/tools/bundle_js.gni ++++ b/ui/webui/resources/tools/bundle_js.gni +@@ -102,6 +102,7 @@ template("bundle_js") { + external_paths += [ "//resources/polymer/v3_0/|$polymer_path" ] + + if (!is_chrome_untrusted) { ++ brave_resources_path = rebase_path("$root_gen_dir/brave/ui/webui/resources/tsc/", root_build_dir) external_paths += [ "chrome://resources/brave/|$brave_resources_path", "//resources/brave/|$brave_resources_path" ] + external_paths += [ "chrome://resources/|$resources_path" ] + } + external_paths += [ "//resources/|$resources_path" ] diff --git a/patches/ui-webui-resources-tools-optimize_webui.gni.patch b/patches/ui-webui-resources-tools-optimize_webui.gni.patch index 76408452b3a..e7d3362cd75 100644 --- a/patches/ui-webui-resources-tools-optimize_webui.gni.patch +++ b/patches/ui-webui-resources-tools-optimize_webui.gni.patch @@ -1,20 +1,12 @@ diff --git a/ui/webui/resources/tools/optimize_webui.gni b/ui/webui/resources/tools/optimize_webui.gni -index 697a4526bbe325d72890d9cdecdde5e01f32b042..1344c74bcee1ec89f031823a65064ca6bc02d388 100644 +index 697a4526bbe325d72890d9cdecdde5e01f32b042..c738715ef3be48d12293189f13cb6d0d4d0f86a7 100644 --- a/ui/webui/resources/tools/optimize_webui.gni +++ b/ui/webui/resources/tools/optimize_webui.gni -@@ -64,6 +64,7 @@ template("optimize_webui") { - rebase_path("$root_gen_dir/ui/webui/resources/tsc/", root_build_dir) - is_chrome_untrusted = - string_replace(invoker.host, "chrome-untrusted://", "") != invoker.host -+ brave_resources_path = rebase_path("$root_gen_dir/brave/ui/webui/resources/tsc/", root_build_dir) +@@ -83,6 +83,7 @@ template("optimize_webui") { + external_paths += [ "//resources/polymer/v3_0/|$polymer_path" ] - external_paths = [] - if (is_chromeos_ash) { -@@ -86,6 +87,7 @@ template("optimize_webui") { + if (!is_chrome_untrusted) { ++ brave_resources_path = rebase_path("$root_gen_dir/brave/ui/webui/resources/tsc/", root_build_dir) external_paths += [ "chrome://resources/brave/|$brave_resources_path", "//resources/brave/|$brave_resources_path" ] external_paths += [ "chrome://resources/|$resources_path" ] } external_paths += [ "//resources/|$resources_path" ] -+ external_paths += [ "chrome://resources/brave/|$brave_resources_path", "//resources/brave/|$brave_resources_path" ] - - if (defined(invoker.external_paths)) { - external_paths += invoker.external_paths