Commit dd0a30ec authored by Bo Majewski's avatar Bo Majewski Committed by Commit Bot

File SWA: Scaffolding for using Files App UI in File SWA

Bug: 1113981
Change-Id: I72e6c09a8c5e142bb85a1cea995c546aacd7d075
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522800
Commit-Queue: Bo Majewski <majewski@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825126}
parent 36ee01df
......@@ -30,6 +30,7 @@ static_library("file_manager_ui") {
"//chromeos/constants",
"//chromeos/resources:file_manager_resources",
"//content/public/browser",
"//ui/file_manager:resources",
"//ui/webui",
]
}
......@@ -2,5 +2,6 @@ include_rules = [
# Do not add chrome here (use a delegate instead).
"+chromeos/grit/chromeos_file_manager_resources.h",
"+content/public/browser",
"+ui/file_manager/grit",
"+ui/webui",
]
......@@ -11,6 +11,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/file_manager/grit/file_manager_resources.h"
namespace chromeos {
namespace file_manager {
......@@ -25,6 +26,7 @@ FileManagerUI::FileManagerUI(content::WebUI* web_ui,
source->AddResourcePath("", IDR_FILE_MANAGER_SWA_MAIN_HTML);
// The resources requested by chrome://file-manager HTML.
// TOD(majewski): Rename main.* to main_swa.*
source->AddResourcePath("main.css", IDR_FILE_MANAGER_SWA_MAIN_CSS);
source->AddResourcePath("main.js", IDR_FILE_MANAGER_SWA_MAIN_JS);
source->AddResourcePath("file_manager.mojom-lite.js",
......@@ -32,6 +34,10 @@ FileManagerUI::FileManagerUI(content::WebUI* web_ui,
source->AddResourcePath("browser_proxy.js",
IDR_FILE_MANAGER_SWA_BROWSER_PROXY_JS);
// Sets up legacy_main_script.js to be the same as Files App
// ui/file_manager/file_manager/foreground/js/main_scripts.js
source->AddResourcePath("legacy_main_scripts.js", IDR_FILE_MANAGER_MAIN_JS);
#if !DCHECK_IS_ON()
// If a user goes to an invalid url and non-DCHECK mode (DHECK = debug mode)
// is set, serve a default page so the user sees your default page instead
......@@ -40,6 +46,9 @@ FileManagerUI::FileManagerUI(content::WebUI* web_ui,
source->SetDefaultResource(IDR_FILE_MANAGER_SWA_MAIN_HTML);
#endif // !DCHECK_IS_ON()
// TODO(crbug.com/1098685): Trusted Type remaining WebUI.
source->DisableTrustedTypesCSP();
auto* browser_context = web_ui->GetWebContents()->GetBrowserContext();
content::WebUIDataSource::Add(browser_context, source.release());
}
......
......@@ -15,7 +15,7 @@
<if expr="is_official_build == false">
<!-- 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_MAIN_HTML" file="main.html" type="BINDATA" />
<include name="IDR_FILE_MANAGER_SWA_MAIN_HTML" file="main.html" flattenhtml="true" 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_ICON_192" file="images/icon192.png" type="BINDATA" />
......
......@@ -2,7 +2,7 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!doctype html>
<!doctype html>
<html dir="$i18n{textdirection}" lang="$i18n{language}">
<head>
<title>$i18n{FILEMANAGER_APP_NAME}</title>
......@@ -10,11 +10,12 @@
<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>
<p>
$i18n{OFFLINE_HEADER}
</p>
</body>
</html>
......@@ -13,7 +13,19 @@ class FileManagerApp {
console.info('File manager app created ...');
}
run() {
/**
* Lazily loads File App legacy code.
*/
loadLegacyCode() {
const legacyLoader = document.createElement('script');
legacyLoader.src = 'legacy_main_scripts.js';
document.body.appendChild(legacyLoader);
}
/**
* Demonstrates Mojo interactions.
*/
demoMojo() {
// Basic example of establishing communication with the backend.
const browserProxy = new BrowserProxy();
......@@ -39,6 +51,11 @@ class FileManagerApp {
browserProxy.handler.doABarrelRoll();
}, 1000);
}
run() {
this.loadLegacyCode();
this.demoMojo();
}
}
const app = new FileManagerApp();
......
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