Commit 06f40cb6 authored by Kenton Lam's avatar Kenton Lam Committed by Chromium LUCI CQ

Refactor emoji_picker to autogenerate grd and use SetupWebUIDataSource()

Uses generate_grd and grit rules to create and bundle the necessary
resource files. Functionality is equivalent to existing code.

Bug: 1156851,1156859
Change-Id: I0724137a3f6cffbc5d44539e5515b335f702f447
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586289Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Reviewed-by: default avatarJohn Palmer <jopalmer@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Kenton Lam <kentonlam@google.com>
Cr-Commit-Position: refs/heads/master@{#836828}
parent da9b5ec0
...@@ -537,11 +537,6 @@ ...@@ -537,11 +537,6 @@
<include name="IDR_MACHINE_LEARNING_INTERNALS_TIME_MOJO_JS" file="${root_gen_dir}\mojo/public/mojom/base/time.mojom-lite.js" use_base_dir="false" type="BINDATA" /> <include name="IDR_MACHINE_LEARNING_INTERNALS_TIME_MOJO_JS" file="${root_gen_dir}\mojo/public/mojom/base/time.mojom-lite.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_MACHINE_LEARNING_INTERNALS_UTILS_JS" file="resources\chromeos\machine_learning\machine_learning_internals_utils.js" type="BINDATA" /> <include name="IDR_MACHINE_LEARNING_INTERNALS_UTILS_JS" file="resources\chromeos\machine_learning\machine_learning_internals_utils.js" type="BINDATA" />
</if> </if>
<if expr="chromeos">
<include name="IDR_EMOJI_PICKER_HTML" file="resources\chromeos\emoji_picker\emoji_picker.html" type="BINDATA" />
<include name="IDR_EMOJI_PICKER_CSS" file="resources\chromeos\emoji_picker\emoji_picker.css" type="BINDATA" />
<include name="IDR_EMOJI_PICKER_JS" file="resources\chromeos\emoji_picker\emoji_picker.js" type="BINDATA" />
</if>
</includes> </includes>
</release> </release>
</grit> </grit>
...@@ -40,6 +40,7 @@ group("resources") { ...@@ -40,6 +40,7 @@ group("resources") {
"chromeos:cellular_setup_resources", "chromeos:cellular_setup_resources",
"chromeos:multidevice_setup_resources", "chromeos:multidevice_setup_resources",
"chromeos/accessibility:build", "chromeos/accessibility:build",
"chromeos/emoji_picker:resources",
"chromeos/multidevice_internals:resources", "chromeos/multidevice_internals:resources",
"nearby_internals:nearby_internals_resources", "nearby_internals:nearby_internals_resources",
"nearby_share:nearby_share_dialog_resources", "nearby_share:nearby_share_dialog_resources",
......
...@@ -3,6 +3,34 @@ ...@@ -3,6 +3,34 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
resources_grd_file = "$target_gen_dir/resources.grd"
generate_grd("build_grd") {
grd_prefix = "emoji_picker"
out_grd = resources_grd_file
input_files = [
"emoji_picker.css",
"emoji_picker.html",
"emoji_picker.js",
]
input_files_base_dir = rebase_path(".", "//")
}
grit("resources") {
# These arguments are needed since the grd is generated at build time.
enable_input_discovery_for_gn_analyze = false
source = resources_grd_file
deps = [ ":build_grd" ]
outputs = [
"grit/emoji_picker_resources.h",
"grit/emoji_picker_resources_map.cc",
"grit/emoji_picker_resources_map.h",
"emoji_picker_resources.pak",
]
output_dir = "$root_gen_dir/chrome"
}
js_library("emoji_picker") { js_library("emoji_picker") {
deps = [ "//ui/webui/resources/js:load_time_data.m" ] deps = [ "//ui/webui/resources/js:load_time_data.m" ]
......
// Copyright 2020 The Chromium Authors. All Rights Reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by the Apache v2.0 license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/webui/chromeos/emoji/emoji_picker.h" #include "chrome/browser/ui/webui/chromeos/emoji/emoji_picker.h"
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/emoji_picker_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/emoji_picker_resources_map.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
...@@ -22,8 +23,8 @@ namespace chromeos { ...@@ -22,8 +23,8 @@ namespace chromeos {
EmojiPicker::EmojiPicker(content::WebUI* web_ui) EmojiPicker::EmojiPicker(content::WebUI* web_ui)
: content::WebUIController(web_ui) { : content::WebUIController(web_ui) {
// Set up the chrome://emoji-picker source. // Set up the chrome://emoji-picker source.
content::WebUIDataSource* html_source = std::unique_ptr<content::WebUIDataSource> html_source(
content::WebUIDataSource::Create(chrome::kChromeUIEmojiPickerHost); content::WebUIDataSource::Create(chrome::kChromeUIEmojiPickerHost));
// As a demonstration of passing a variable for JS to use we pass in some // As a demonstration of passing a variable for JS to use we pass in some
// emoji. // emoji.
...@@ -32,13 +33,14 @@ EmojiPicker::EmojiPicker(content::WebUI* web_ui) ...@@ -32,13 +33,14 @@ EmojiPicker::EmojiPicker(content::WebUI* web_ui)
html_source->UseStringsJs(); html_source->UseStringsJs();
// Add required resources. // Add required resources.
html_source->AddResourcePath("emoji_picker.css", IDR_EMOJI_PICKER_CSS); webui::SetupWebUIDataSource(
html_source->AddResourcePath("emoji_picker.js", IDR_EMOJI_PICKER_JS); html_source.get(),
html_source->SetDefaultResource(IDR_EMOJI_PICKER_HTML); base::make_span(kEmojiPickerResources, kEmojiPickerResourcesSize), "",
IDR_EMOJI_PICKER_EMOJI_PICKER_HTML);
content::BrowserContext* browser_context = content::BrowserContext* browser_context =
web_ui->GetWebContents()->GetBrowserContext(); web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, html_source); content::WebUIDataSource::Add(browser_context, html_source.release());
} }
EmojiPicker::~EmojiPicker() {} EmojiPicker::~EmojiPicker() {}
......
...@@ -176,6 +176,7 @@ template("chrome_extra_paks") { ...@@ -176,6 +176,7 @@ template("chrome_extra_paks") {
"$root_gen_dir/chrome/bluetooth_pairing_dialog_resources.pak", "$root_gen_dir/chrome/bluetooth_pairing_dialog_resources.pak",
"$root_gen_dir/chrome/browser/supervised_user/supervised_user_unscaled_resources.pak", "$root_gen_dir/chrome/browser/supervised_user/supervised_user_unscaled_resources.pak",
"$root_gen_dir/chrome/cellular_setup_resources.pak", "$root_gen_dir/chrome/cellular_setup_resources.pak",
"$root_gen_dir/chrome/emoji_picker_resources.pak",
"$root_gen_dir/chrome/multidevice_internals_resources.pak", "$root_gen_dir/chrome/multidevice_internals_resources.pak",
"$root_gen_dir/chrome/multidevice_setup_resources.pak", "$root_gen_dir/chrome/multidevice_setup_resources.pak",
"$root_gen_dir/chrome/nearby_internals_resources.pak", "$root_gen_dir/chrome/nearby_internals_resources.pak",
...@@ -200,6 +201,7 @@ template("chrome_extra_paks") { ...@@ -200,6 +201,7 @@ template("chrome_extra_paks") {
"//chrome/browser/resources:bluetooth_pairing_dialog_resources", "//chrome/browser/resources:bluetooth_pairing_dialog_resources",
"//chrome/browser/resources/chromeos:cellular_setup_resources", "//chrome/browser/resources/chromeos:cellular_setup_resources",
"//chrome/browser/resources/chromeos:multidevice_setup_resources", "//chrome/browser/resources/chromeos:multidevice_setup_resources",
"//chrome/browser/resources/chromeos/emoji_picker:resources",
"//chrome/browser/resources/chromeos/multidevice_internals:resources", "//chrome/browser/resources/chromeos/multidevice_internals:resources",
"//chrome/browser/resources/nearby_internals:nearby_internals_resources", "//chrome/browser/resources/nearby_internals:nearby_internals_resources",
"//chrome/browser/resources/nearby_share:nearby_share_dialog_resources", "//chrome/browser/resources/nearby_share:nearby_share_dialog_resources",
......
...@@ -113,6 +113,10 @@ ...@@ -113,6 +113,10 @@
"chrome/browser/resources/chromeos/cellular_setup/cellular_setup_resources.grd": { "chrome/browser/resources/chromeos/cellular_setup/cellular_setup_resources.grd": {
"structures": [1360], "structures": [1360],
}, },
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/chromeos/emoji_picker/resources.grd": {
"META": {"sizes": {"includes": [20]}},
"includes": [1365],
},
"<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/chromeos/multidevice_internals/resources.grd": { "<(SHARED_INTERMEDIATE_DIR)/chrome/browser/resources/chromeos/multidevice_internals/resources.grd": {
"META": {"sizes": {"includes": [35]}}, "META": {"sizes": {"includes": [35]}},
"includes": [1370], "includes": [1370],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment