0

[code cache] Update build_webui to support both grd and grdp gen

This CL updates build_webui() to support generating both grd and
grdp files, dependent on the generate_grdp template param.

Assuming generate_code_cache=true, if

  - generate_grdp=true the rule will generate a grdp file that will
    be aggregated into a higher-level grd file to create a
    consolidated pak file

  - generate_grd=false the rule will generate a template-specific
    grd and pak file

This aligns generating code cache resources with the patterns that
already exist to generate webui resources.

This enables the ability to generate code cache for page-specific
WebUI resources (rather than only for shared resources which are
supported now). These page-specific resources should not all be
bundled into a single resource file as the page-specific resources
need to be associated with their corresponding host to resolve
correctly.

Additionally, this CL applies the updated build-rule to the shared
side panel resources, to assist with the analysis of the below
unbundled WebUIs during experimentation:

 - chrome://bookmarks-side-panel.top-chrome
 - chrome://customize-chrome-side-panel.top-chrome
 - chrome://read-later.top-chrome

Bug: 378504039
Change-Id: Ia17020e27470ecca722a406829590eff9defb214
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6376847
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Tom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1436432}
This commit is contained in:
Thomas Lukaszewicz
2025-03-22 00:06:19 -07:00
committed by Chromium LUCI CQ
parent 76d0bc8d46
commit 3b7cfb54f2
7 changed files with 82 additions and 9 deletions
chrome
tools/gritsettings
ui/webui/resources/tools

@ -10,6 +10,7 @@ import("//printing/buildflags/buildflags.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/repack.gni")
import("//ui/webui/webui_features.gni")
assert(!is_ios, "Chromium/iOS shouldn't use anything in //chrome")
assert(!is_fuchsia, "Fuchsia shouldn't use anything in //chrome")
@ -162,6 +163,12 @@ group("resources") {
}
}
if (enable_webui_generate_code_cache) {
group("code_cache_resources") {
public_deps = [ "side_panel/shared:code_cache_resources" ]
}
}
if (is_chromeos && enable_js_type_check) {
group("closure_compile") {
deps = [

@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//ui/webui/resources/tools/build_webui.gni")
import("//ui/webui/webui_features.gni")
assert(!is_android)
@ -41,4 +42,5 @@ build_webui("build") {
# Used by both trusted and untrusted hosts so all imports in this folder
# should be scheme-relative.
webui_context_type = "relative"
generate_code_cache = enable_webui_generate_code_cache
}

@ -5703,7 +5703,7 @@ static_library("ui") {
if (enable_webui_generate_code_cache) {
deps += [
"//ui/webui:buildflags",
"//chrome/browser/resources:code_cache_resources",
"//ui/webui/resources:code_cache_resources",
]
}

@ -21,6 +21,7 @@
#include "ui/webui/buildflags.h"
#if BUILDFLAG(ENABLE_WEBUI_GENERATE_CODE_CACHE)
#include "chrome/grit/side_panel_shared_code_cache_resources_map.h"
#include "content/public/common/content_features.h"
#include "ui/webui/resources/grit/webui_code_cache_resources_map.h"
#endif // BUILDFLAG(ENABLE_WEBUI_GENERATE_CODE_CACHE)
@ -166,13 +167,33 @@ base::flat_map<GURL, int> GetWebUIResourceUrlToCodeCacheMap() {
#if BUILDFLAG(ENABLE_WEBUI_GENERATE_CODE_CACHE)
if (features::kWebUIBundledCodeCacheGenerateResourceMap.Get()) {
// Currently only shared resources are supported.
// Shared resources.
AppendWebUIResourceURLToCodeCachePairs(
content::kChromeUIScheme, content::kChromeUIResourcesHost,
kWebuiCodeCacheResources, url_to_code_cache_pairs);
AppendWebUIResourceURLToCodeCachePairs(
content::kChromeUIUntrustedScheme, content::kChromeUIResourcesHost,
kWebuiCodeCacheResources, url_to_code_cache_pairs);
// TODO(crbug.com/402625343): We can avoid enumerating host-specific WebUI
// code cache resources here and instead delegate to registered WebUI
// configs or similar. This may also be unnecessary once these mappings are
// exposed in renderers at compile-time.
// chrome://bookmarks-side-panel.top-chrome
AppendWebUIResourceURLToCodeCachePairs(
content::kChromeUIScheme, chrome::kChromeUIBookmarksSidePanelHost,
kSidePanelSharedCodeCacheResources, url_to_code_cache_pairs);
// chrome://customize-chrome-side-panel.top-chrome
AppendWebUIResourceURLToCodeCachePairs(
content::kChromeUIScheme, chrome::kChromeUICustomizeChromeSidePanelHost,
kSidePanelSharedCodeCacheResources, url_to_code_cache_pairs);
// chrome://read-later.top-chrome
AppendWebUIResourceURLToCodeCachePairs(
content::kChromeUIScheme, chrome::kChromeUIReadLaterHost,
kSidePanelSharedCodeCacheResources, url_to_code_cache_pairs);
}
#endif // BUILDFLAG(ENABLE_WEBUI_GENERATE_CODE_CACHE)

@ -537,9 +537,14 @@ template("chrome_extra_paks") {
}
if (enable_webui_generate_code_cache) {
sources +=
[ "$root_gen_dir/ui/webui/resources/webui_code_cache_resources.pak" ]
deps += [ "//ui/webui/resources:code_cache_resources" ]
sources += [
"$root_gen_dir/chrome/side_panel_shared_code_cache_resources.pak",
"$root_gen_dir/ui/webui/resources/webui_code_cache_resources.pak",
]
deps += [
"//chrome/browser/resources/side_panel/shared:code_cache_resources",
"//ui/webui/resources:code_cache_resources",
]
}
}
}

@ -612,6 +612,10 @@
"META": {"sizes": {"includes": [15],}},
"includes": [4900],
},
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/side_panel/shared/code_cache_resources.grd": {
"META": {"sizes": {"includes": [15],}},
"includes": [4910],
},
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/side_panel/shared/resources.grd": {
"META": {"sizes": {"includes": [15],}},
"includes": [4920],

@ -536,8 +536,14 @@ template("build_webui") {
}
if (generate_code_cache) {
generate_code_cache_grd_prefix = grd_prefix + "_code_cache"
generate_code_cache_grd_target_name = "build_code_cache_grd"
if (generate_grdp) {
generate_code_cache_grd_target_name = "build_code_cache_grdp"
}
generate_code_cache("build_code_cache") {
visibility = [ ":build_code_cache_grdp" ]
visibility = [ ":$generate_code_cache_grd_target_name" ]
# Rebase the minified file paths under the minified directory.
minified_outputs =
@ -554,15 +560,43 @@ template("build_webui") {
deps = [ ":build_min_js" ]
}
generate_grd("build_code_cache_grdp") {
generate_grd(generate_code_cache_grd_target_name) {
if (!generate_grdp) {
visibility = [ ":code_cache_resources_grit" ]
}
if (defined(invoker.grd_resource_path_prefix)) {
resource_path_prefix = invoker.grd_resource_path_prefix
}
grd_prefix = grd_prefix + "_code_cache"
out_grd = "$target_gen_dir/code_cache_resources.grdp"
grd_prefix = generate_code_cache_grd_prefix
out_grd = "$target_gen_dir/code_cache_resources.grd"
if (generate_grdp) {
out_grd = "$target_gen_dir/code_cache_resources.grdp"
}
manifest_files = [ "$target_gen_dir/build_code_cache_manifest.json" ]
deps = [ ":build_code_cache" ]
}
if (!generate_grdp) {
grit("code_cache_resources") {
enable_input_discovery_for_gn_analyze = false
source = "$target_gen_dir/code_cache_resources.grd"
outputs = [
"grit/${generate_code_cache_grd_prefix}_resources.h",
"grit/${generate_code_cache_grd_prefix}_resources_map.cc",
"grit/${generate_code_cache_grd_prefix}_resources_map.h",
"${generate_code_cache_grd_prefix}_resources.pak",
]
grit_output_dir = "$root_gen_dir/chrome"
if (defined(invoker.grit_output_dir)) {
grit_output_dir = invoker.grit_output_dir
}
output_dir = grit_output_dir
deps = [ ":$generate_code_cache_grd_target_name" ]
}
}
}
generate_grd(generate_grd_target_name) {