Commit 97f817cc authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Chromium LUCI CQ

Files SWA: Map resources from file_manager extension

In the SWA Data Source register all the resources from the file_manager
extension so we can use the same relative paths from the main.html used
in the extension.

With this change we can stop inlining the CSS via flattenhtml GRD
option.

Bug: 1113981
Change-Id: I3eb00b8ae3b0dc79273e1cdea00b5abc1426812a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2580670
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835567}
parent 0d2aa692
...@@ -22,6 +22,7 @@ static_library("file_manager_ui") { ...@@ -22,6 +22,7 @@ static_library("file_manager_ui") {
"//chromeos/constants", "//chromeos/constants",
"//chromeos/resources:file_manager_resources", "//chromeos/resources:file_manager_resources",
"//content/public/browser", "//content/public/browser",
"//ui/file_manager:file_manager_gen_resources",
"//ui/file_manager:resources", "//ui/file_manager:resources",
"//ui/webui", "//ui/webui",
] ]
......
...@@ -5,17 +5,35 @@ ...@@ -5,17 +5,35 @@
#include "chromeos/components/file_manager/file_manager_ui.h" #include "chromeos/components/file_manager/file_manager_ui.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "chromeos/components/file_manager/file_manager_page_handler.h" #include "chromeos/components/file_manager/file_manager_page_handler.h"
#include "chromeos/components/file_manager/url_constants.h" #include "chromeos/components/file_manager/url_constants.h"
#include "chromeos/grit/chromeos_file_manager_resources.h" #include "chromeos/grit/chromeos_file_manager_resources.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.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"
#include "ui/file_manager/grit/file_manager_gen_resources_map.h"
#include "ui/file_manager/grit/file_manager_resources.h" #include "ui/file_manager/grit/file_manager_resources.h"
#include "ui/file_manager/grit/file_manager_resources_map.h"
namespace chromeos { namespace chromeos {
namespace file_manager { namespace file_manager {
void AddFilesAppResources(content::WebUIDataSource* source,
const GritResourceMap* entries,
size_t size) {
for (size_t i = 0; i < size; ++i) {
std::string path(entries[i].name);
// Only load resources for Files app.
if (base::StartsWith(path, "file_manager/")) {
// Files app UI has all paths relative to //ui/file_manager/file_manager/
// so we remove the leading file_manager/ to match the existing paths.
base::ReplaceFirstSubstringAfterOffset(&path, 0, "file_manager/", "");
source->AddResourcePath(path, entries[i].value);
}
}
}
FileManagerUI::FileManagerUI(content::WebUI* web_ui, FileManagerUI::FileManagerUI(content::WebUI* web_ui,
std::unique_ptr<FileManagerUIDelegate> delegate) std::unique_ptr<FileManagerUIDelegate> delegate)
: MojoWebUIController(web_ui), delegate_(std::move(delegate)) { : MojoWebUIController(web_ui), delegate_(std::move(delegate)) {
...@@ -47,6 +65,11 @@ FileManagerUI::FileManagerUI(content::WebUI* web_ui, ...@@ -47,6 +65,11 @@ FileManagerUI::FileManagerUI(content::WebUI* web_ui,
source->SetDefaultResource(IDR_FILE_MANAGER_SWA_MAIN_HTML); source->SetDefaultResource(IDR_FILE_MANAGER_SWA_MAIN_HTML);
#endif // !DCHECK_IS_ON() #endif // !DCHECK_IS_ON()
AddFilesAppResources(source.get(), kFileManagerResources,
kFileManagerResourcesSize);
AddFilesAppResources(source.get(), kFileManagerGenResources,
kFileManagerGenResourcesSize);
// TODO(crbug.com/1098685): Trusted Type remaining WebUI. // TODO(crbug.com/1098685): Trusted Type remaining WebUI.
source->DisableTrustedTypesCSP(); source->DisableTrustedTypesCSP();
......
...@@ -30,8 +30,6 @@ action("gen_main_html") { ...@@ -30,8 +30,6 @@ action("gen_main_html") {
rebase_path("//ui/file_manager/file_manager/main.html", root_build_dir), rebase_path("//ui/file_manager/file_manager/main.html", root_build_dir),
"--target", "--target",
rebase_path("$target_gen_dir/main.html", root_build_dir), rebase_path("$target_gen_dir/main.html", root_build_dir),
"--root",
rebase_path("//"), # root of the chrome source checkout.
] ]
outputs = [ outputs = [
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<include name="IDR_FILE_MANAGER_SWA_MOJO_LITE_JS" file="$root_gen_dir/chromeos/components/file_manager/mojom/file_manager.mojom-lite.js" use_base_dir="false" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_MOJO_LITE_JS" file="$root_gen_dir/chromeos/components/file_manager/mojom/file_manager.mojom-lite.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SWA_BROWSER_PROXY_JS" file="browser_proxy.js" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_BROWSER_PROXY_JS" file="browser_proxy.js" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SWA_SCRIPT_LOADER_JS" file="script_loader.js" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_SCRIPT_LOADER_JS" file="script_loader.js" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SWA_MAIN_HTML" file="${root_gen_dir}/chromeos/components/file_manager/resources/main.html" flattenhtml="true" use_base_dir="false" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_MAIN_HTML" file="${root_gen_dir}/chromeos/components/file_manager/resources/main.html" use_base_dir="false" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SWA_MAIN_JS" file="main.js" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_MAIN_JS" file="main.js" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SWA_ICON_192" file="images/icon192.png" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_ICON_192" file="images/icon192.png" type="BINDATA" />
</if> </if>
......
...@@ -14,7 +14,7 @@ import sys ...@@ -14,7 +14,7 @@ import sys
_SWA = '<script type="module" src="chrome://file-manager/main.js"></script>' _SWA = '<script type="module" src="chrome://file-manager/main.js"></script>'
def GenerateSwaMainHtml(source, target, root): def GenerateSwaMainHtml(source, target):
"""Copy source file to target, do SWA edits, then add BUILD time stamp.""" """Copy source file to target, do SWA edits, then add BUILD time stamp."""
# Copy source (main.html) file to the target (main.html) file. # Copy source (main.html) file to the target (main.html) file.
...@@ -28,13 +28,6 @@ def GenerateSwaMainHtml(source, target, root): ...@@ -28,13 +28,6 @@ def GenerateSwaMainHtml(source, target, root):
# Add <meta> charset="utf-8" attribute. # Add <meta> charset="utf-8" attribute.
elif line.find('<meta ') >= 0: elif line.find('<meta ') >= 0:
sys.stdout.write(line.replace('<meta ', '<meta charset="utf-8" ')) sys.stdout.write(line.replace('<meta ', '<meta charset="utf-8" '))
# Root rewrite files app <link> stylesheet href attribute.
elif line.find('<link rel="stylesheet"') >= 0:
if not 'href="chrome://' in line:
href = 'href="' + root + 'ui/file_manager/file_manager/'
sys.stdout.write(line.replace('href="', href))
else:
sys.stdout.write(line)
# Remove files app foreground/js <script> tags: SWA app must load # Remove files app foreground/js <script> tags: SWA app must load
# them after the SWA app has initialized needed resources. # them after the SWA app has initialized needed resources.
elif line.find('<script src="foreground/js/') == -1: elif line.find('<script src="foreground/js/') == -1:
...@@ -48,13 +41,12 @@ def main(args): ...@@ -48,13 +41,12 @@ def main(args):
parser.add_option('--source', help='Files app main.html source file.') parser.add_option('--source', help='Files app main.html source file.')
parser.add_option('--target', help='Target SWA main.html for output.') parser.add_option('--target', help='Target SWA main.html for output.')
parser.add_option('--root', help='Source root: chrome/src path.')
options, _ = parser.parse_args(args) options, _ = parser.parse_args(args)
if options.source and options.target and options.root: if options.source and options.target:
target = os.path.join(os.getcwd(), options.target) target = os.path.join(os.getcwd(), options.target)
GenerateSwaMainHtml(options.source, target, options.root) GenerateSwaMainHtml(options.source, target)
return return
raise SyntaxError('Usage: all arguments are required.') raise SyntaxError('Usage: all arguments are required.')
......
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