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 <dpapad@chromium.org>
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
This commit is contained in:
Emerick Rogul
2023-06-19 16:00:08 -04:00
parent aed766c2a0
commit 307fbaa349
2 changed files with 17 additions and 13 deletions
@@ -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" ]
@@ -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