Commit d6526dfd authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[filesapp] Auto-generate SWA main.html from files app main.html

Add a file_manager/resources/BUILD.gn action('gen_main_html') to use a
script to auto-generate SWA main.html from files app main.html.

Update file_manager/resources/file_manager_resources.grd file to fetch
auto-generated SWA main.html from the generated resources directory.

Bug: 1113981
Change-Id: I116d5fb15e63148e3a1cdbe9cf7e179a53165957
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536584
Auto-Submit: Noel Gordon <noel@chromium.org>
Commit-Queue: Roman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827733}
parent 84894a06
...@@ -18,3 +18,23 @@ js_type_check("closure_compile") { ...@@ -18,3 +18,23 @@ js_type_check("closure_compile") {
uses_js_modules = true uses_js_modules = true
deps = [ ":main_js" ] deps = [ ":main_js" ]
} }
action("gen_main_html") {
inputs = [ "//ui/file_manager/file_manager/main.html" ]
script = "//chromeos/components/file_manager/resources/gen_main_html.py"
args = [
"--source",
rebase_path("//ui/file_manager/file_manager/main.html", root_build_dir),
"--target",
rebase_path("$target_gen_dir/main.html", root_build_dir),
"--root",
rebase_path("//"), # root of the chrome source checkout.
]
outputs = [
"$target_gen_dir/main.html",
"$target_gen_dir/main.html.stamp",
]
}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<if expr="is_official_build == false"> <if expr="is_official_build == false">
<!-- Privileged app host contents. --> <!-- Privileged app host contents. -->
<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_MAIN_HTML" file="main.html" flattenhtml="true" 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_CSS" file="main.css" type="BINDATA" /> <include name="IDR_FILE_MANAGER_SWA_MAIN_CSS" file="main.css" 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" />
......
#!/usr/bin/env python
#
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Generate SWA files app main.html from files app main.html"""
import fileinput
import optparse
import os
import shutil
import sys
_SWA = '<script type="module" src="chrome://file-manager/main.js"></script>'
def GenerateSwaMainHtml(source, target, root):
"""Copy source file to target, do SWA edits, then add BUILD time stamp."""
# Copy source (main.html) file to the target (main.html) file.
shutil.copyfile(source, target)
# Edit the target file.
for line in fileinput.input(target, inplace=True):
# Add _SWA <script> tag after the <head> tag.
if line.find('<head>') >= 0:
print line + ' ' + _SWA
# Add <meta> charset="utf-8" attribute.
elif line.find('<meta ') >= 0:
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 lazy-load
# them after the SWA app has initialized needed resources.
elif line.find('<script src="foreground/js/') == -1:
sys.stdout.write(line)
# Create a BUILD time stamp for the target file.
open(target + '.stamp', 'a').close()
def main(args):
parser = optparse.OptionParser()
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('--root', help='Source root: chrome/src path.')
options, _ = parser.parse_args(args)
if options.source and options.target and options.root:
target = os.path.join(os.getcwd(), options.target)
GenerateSwaMainHtml(options.source, target, options.root)
return
raise SyntaxError('Usage: all arguments are required.')
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
<!-- Copyright (c) 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!doctype html>
<html dir="$i18n{textdirection}" lang="$i18n{language}">
<head>
<title>$i18n{FILEMANAGER_APP_NAME}</title>
<meta charset="utf-8">
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<link rel="stylesheet" href="main.css">
<script type="module" src="chrome://file-manager/main.js"></script>
<!-- LEGACY UI START -->
<script src="chrome://resources/polymer/v1_0/html-imports/html-imports.min.js"></script>
<link rel="import" href="chrome://resources/html/polymer.html">
<!-- LEGACY UI END -->
</head>
<body aria-label="$i18n{FILEMANAGER_APP_NAME}" tabindex="-1">
<h1>$i18n{FILEMANAGER_APP_NAME} SWA Demo</h1>
</body>
</html>
...@@ -85,6 +85,9 @@ grit("connectivity_diagnostics_resources") { ...@@ -85,6 +85,9 @@ grit("connectivity_diagnostics_resources") {
# Resources used by chrome://file-manager # Resources used by chrome://file-manager
if (!is_official_build) { if (!is_official_build) {
grit("file_manager_resources") { grit("file_manager_resources") {
# main.html is generated at build time.
enable_input_discovery_for_gn_analyze = false
source = "../components/file_manager/resources/file_manager_resources.grd" source = "../components/file_manager/resources/file_manager_resources.grd"
outputs = [ outputs = [
...@@ -97,6 +100,7 @@ if (!is_official_build) { ...@@ -97,6 +100,7 @@ if (!is_official_build) {
deps = [ deps = [
"//chromeos/components/file_manager/mojom:mojom_js", "//chromeos/components/file_manager/mojom:mojom_js",
"//chromeos/components/file_manager/resources:gen_main_html",
"//mojo/public/js:bindings_lite", "//mojo/public/js:bindings_lite",
] ]
} }
......
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