Commit c513527e authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Use JS modules for chrome://weblayer

Simple adaptation of this WebUI to use JS modules in lieu of manually
managing dependency imports.

Bug: 1004256
Change-Id: Ib9e5477f1a1578772f9a2d657d41aa5c36aee516
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556700
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830767}
parent 1d559231
......@@ -8,8 +8,8 @@ IDR_SECURITY_INTERSTITIAL_QUIET_HTML
IDR_SAFE_BROWSING_CSS
IDR_SAFE_BROWSING_JS
IDR_SAFE_BROWSING_HTML
IDR_WEBUI_JS_CR_JS
IDR_WEBUI_JS_ASSERT_JS
IDR_WEBUI_JS_UTIL_JS
IDR_WEBUI_JS_PROMISE_RESOLVER_JS
IDR_MOJO_MOJO_BINDINGS_LITE_JS
IDR_WEBUI_JS_CR_M_JS
IDR_WEBUI_JS_ASSERT_M_JS
IDR_WEBUI_JS_UTIL_M_JS
IDR_WEBUI_JS_PROMISE_RESOLVER_M_JS
IDR_MOJO_BINDINGS_JS
......@@ -813,7 +813,7 @@ grit("resources") {
"grit/weblayer_resources.h",
"weblayer_resources.pak",
]
deps = [ "//weblayer/browser/webui:mojo_bindings_js" ]
deps = [ "//weblayer/browser/webui:mojo_bindings_webui_js" ]
}
# TODO(jam): move weblayer_shell_resources_grit and copy_shell_resources here in
# a way that's shareable?
......@@ -4,14 +4,7 @@
<meta charset="utf-8">
<title>WebLayer Internals</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/js/assert.js"></script>
<script src="chrome://resources/js/promise_resolver.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="weblayer_internals.mojom-lite.js"></script>
<script src="weblayer_internals.js"></script>
<script type="module" src="weblayer_internals.js"></script>
</head>
<body>
<h1>WebLayer Internals</h1>
......
......@@ -2,26 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/* Javascript module for chrome://weblayer. */
(function() {
import {isAndroid} from 'chrome://resources/js/cr.m.js';
import {$} from 'chrome://resources/js/util.m.js';
import {PageHandler} from './weblayer_internals.mojom-webui.js';
/* Main entry point. */
document.addEventListener('DOMContentLoaded', function() {
window.document.addEventListener('DOMContentLoaded', async function() {
// Setup backend mojo.
const pageHandler = weblayerInternals.mojom.PageHandler.getRemote();
if (cr.isAndroid) {
pageHandler.getRemoteDebuggingEnabled().then((response) => {
let checkbox = $('remote-debug');
checkbox.checked = response.enabled;
checkbox.addEventListener('click', (event) => {
pageHandler.setRemoteDebuggingEnabled(event.target.checked);
});
$('remote-debug-label').removeAttribute('hidden');
const pageHandler = PageHandler.getRemote();
if (isAndroid) {
const {enabled} = await pageHandler.getRemoteDebuggingEnabled();
const checkbox = $('remote-debug');
checkbox.checked = enabled;
checkbox.addEventListener('click', (event) => {
pageHandler.setRemoteDebuggingEnabled(event.target.checked);
});
$('remote-debug-label').removeAttribute('hidden');
}
});
}());
......@@ -6,4 +6,5 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojo_bindings") {
sources = [ "weblayer_internals.mojom" ]
webui_module_path = "/"
}
......@@ -18,7 +18,7 @@ WebLayerInternalsUI::WebLayerInternalsUI(content::WebUI* web_ui)
content::WebUIDataSource* source =
content::WebUIDataSource::Create(kChromeUIWebLayerHost);
source->AddResourcePath("weblayer_internals.js", IDR_WEBLAYER_INTERNALS_JS);
source->AddResourcePath("weblayer_internals.mojom-lite.js",
source->AddResourcePath("weblayer_internals.mojom-webui.js",
IDR_WEBLAYER_INTERNALS_MOJO_JS);
source->SetDefaultResource(IDR_WEBLAYER_INTERNALS_HTML);
content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
......
......@@ -11,7 +11,7 @@
<includes>
<include name="IDR_WEBLAYER_INTERNALS_HTML" file="browser/resources/weblayer_internals/weblayer_internals.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_WEBLAYER_INTERNALS_JS" file="browser/resources/weblayer_internals/weblayer_internals.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_WEBLAYER_INTERNALS_MOJO_JS" file="${root_gen_dir}/weblayer/browser/webui/weblayer_internals.mojom-lite.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_WEBLAYER_INTERNALS_MOJO_JS" file="${root_gen_dir}/mojom-webui/weblayer/browser/webui/weblayer_internals.mojom-webui.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_SUBRESOURCE_FILTER_UNINDEXED_RULESET" file="../third_party/subresource-filter-ruleset/data/UnindexedRules" type="BINDATA" compress="brotli" />
<include name="IDR_SUBRESOURCE_FILTER_UNINDEXED_RULESET_MANIFEST_JSON" file="../third_party/subresource-filter-ruleset/manifest.json" type="BINDATA" />
</includes>
......
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