Commit 050cdb40 authored by dpapad's avatar dpapad Committed by Commit Bot

Migrate chrome://usb-internals to use JS modules.

Bug: 1028829,1139849
Change-Id: I1ce5bdbd9e48004cec66f60cf952b0d95207c3d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2480262
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819789}
parent 5907423c
...@@ -7,6 +7,7 @@ import("//tools/grit/grit_rule.gni") ...@@ -7,6 +7,7 @@ import("//tools/grit/grit_rule.gni")
import("//tools/polymer/html_to_js.gni") import("//tools/polymer/html_to_js.gni")
js_type_check("closure_compile") { js_type_check("closure_compile") {
uses_js_modules = true
deps = [ deps = [
":app", ":app",
":descriptor_panel", ":descriptor_panel",
...@@ -17,35 +18,45 @@ js_type_check("closure_compile") { ...@@ -17,35 +18,45 @@ js_type_check("closure_compile") {
js_library("app") { js_library("app") {
deps = [ deps = [
":devices_page", ":devices_page",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings_js_library_for_compile", ":mojo",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:util", "//ui/webui/resources/js/cr/ui:tabs.m",
"//ui/webui/resources/js/cr/ui:tabs",
"//ui/webui/resources/js/cr/ui:tree",
] ]
} }
js_library("devices_page") { js_library("devices_page") {
deps = [ deps = [
":descriptor_panel", ":descriptor_panel",
"//chrome/browser/ui/webui/usb_internals:mojo_bindings_js_library_for_compile", ":mojo",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:util.m",
"//ui/webui/resources/js/cr/ui:tabs.m",
"//ui/webui/resources/js/cr/ui:tree.m",
] ]
} }
js_library("descriptor_panel") { js_library("descriptor_panel") {
deps = [ deps = [
"//chrome/browser/ui/webui/usb_internals:mojo_bindings_js_library_for_compile", ":mojo",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:util.m",
"//ui/webui/resources/js/cr:ui.m",
"//ui/webui/resources/js/cr/ui:tree.m",
] ]
} }
js_library("mojo") {
deps = [ "//chrome/browser/ui/webui/usb_internals:mojo_bindings_js_library_for_compile" ]
}
grit("resources") { grit("resources") {
source = "resources.grd" source = "resources.grd"
outputs = [ outputs = [
"grit/usb_internals_resources.h", "grit/usb_internals_resources.h",
"grit/usb_internals_resources_map.cc",
"grit/usb_internals_resources_map.h",
"usb_internals_resources.pak", "usb_internals_resources.pak",
] ]
output_dir = "$root_gen_dir/chrome" output_dir = "$root_gen_dir/chrome"
......
...@@ -5,6 +5,13 @@ ...@@ -5,6 +5,13 @@
/** /**
* Javascript for usb_internals.html, served from chrome://usb-internals/. * Javascript for usb_internals.html, served from chrome://usb-internals/.
*/ */
import './mojo.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {decorate} from 'chrome://resources/js/cr/ui.m.js';
import {TabBox} from 'chrome://resources/js/cr/ui/tabs.m.js';
import {DevicesPage} from './devices_page.js';
window.setupFn = window.setupFn || function() { window.setupFn = window.setupFn || function() {
return Promise.resolve(); return Promise.resolve();
...@@ -46,9 +53,8 @@ window.setupFn = window.setupFn || function() { ...@@ -46,9 +53,8 @@ window.setupFn = window.setupFn || function() {
await pageHandler.bindUsbDeviceManagerInterface( await pageHandler.bindUsbDeviceManagerInterface(
usbManager.$.bindNewPipeAndPassReceiver()); usbManager.$.bindNewPipeAndPassReceiver());
/** @private {devices_page.DevicesPage} */ /** @private {!DevicesPage} */
this.devicesPage_ = new devices_page.DevicesPage( this.devicesPage_ = new DevicesPage(usbManager, assert(this.shadowRoot));
usbManager, assert(this.shadowRoot));
/** @private {device.mojom.UsbDeviceManagerTestRemote} */ /** @private {device.mojom.UsbDeviceManagerTestRemote} */
this.usbManagerTest_ = new device.mojom.UsbDeviceManagerTestRemote; this.usbManagerTest_ = new device.mojom.UsbDeviceManagerTestRemote;
...@@ -60,7 +66,7 @@ window.setupFn = window.setupFn || function() { ...@@ -60,7 +66,7 @@ window.setupFn = window.setupFn || function() {
}); });
this.refreshTestDeviceList(); this.refreshTestDeviceList();
cr.ui.decorate(assert(this.$('tabbox')), cr.ui.TabBox); decorate(assert(this.$('tabbox')), TabBox);
} }
async refreshTestDeviceList() { async refreshTestDeviceList() {
......
...@@ -6,8 +6,13 @@ ...@@ -6,8 +6,13 @@
* Javascript for DescriptorPanel UI, served from * Javascript for DescriptorPanel UI, served from
* chrome://usb-internals/. * chrome://usb-internals/.
*/ */
import './mojo.js';
import {assert, assertInstanceof} from 'chrome://resources/js/assert.m.js';
import {decorate} from 'chrome://resources/js/cr/ui.m.js';
import {Tree, TreeItem} from 'chrome://resources/js/cr/ui/tree.m.js';
import {queryRequiredElement} from 'chrome://resources/js/util.m.js';
cr.define('descriptor_panel', function() {
const INPUT_TYPE_DECIMAL_WITH_DROPDOWN = 0; const INPUT_TYPE_DECIMAL_WITH_DROPDOWN = 0;
const INPUT_TYPE_HEX_BYTE = 1; const INPUT_TYPE_HEX_BYTE = 1;
...@@ -109,7 +114,7 @@ cr.define('descriptor_panel', function() { ...@@ -109,7 +114,7 @@ cr.define('descriptor_panel', function() {
0x9E, 0x64, 0x8A, 0x9F 0x9E, 0x64, 0x8A, 0x9F
]; ];
class DescriptorPanel { export class DescriptorPanel {
/** /**
* @param {!device.mojom.UsbDeviceInterface} usbDeviceProxy * @param {!device.mojom.UsbDeviceInterface} usbDeviceProxy
* @param {!HTMLElement} rootElement * @param {!HTMLElement} rootElement
...@@ -125,10 +130,10 @@ cr.define('descriptor_panel', function() { ...@@ -125,10 +130,10 @@ cr.define('descriptor_panel', function() {
/** /**
* Adds the reference of the string descriptor panel of the device for * Adds the reference of the string descriptor panel of the device for
* string descriptor functionality. * string descriptor functionality.
* @param {!descriptor_panel.DescriptorPanel} stringDescriptorPanel * @param {!DescriptorPanel} stringDescriptorPanel
*/ */
setStringDescriptorPanel(stringDescriptorPanel) { setStringDescriptorPanel(stringDescriptorPanel) {
/** @type {!descriptor_panel.DescriptorPanel} */ /** @type {!DescriptorPanel} */
this.stringDescriptorPanel_ = stringDescriptorPanel; this.stringDescriptorPanel_ = stringDescriptorPanel;
} }
...@@ -149,7 +154,7 @@ cr.define('descriptor_panel', function() { ...@@ -149,7 +154,7 @@ cr.define('descriptor_panel', function() {
* the string descriptor panel. * the string descriptor panel.
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The offset of the string descriptor index field. * @param {number} offset The offset of the string descriptor index field.
* @param {!cr.ui.TreeItem} item * @param {!TreeItem} item
* @param {string} fieldLabel * @param {string} fieldLabel
* @private * @private
*/ */
...@@ -194,7 +199,7 @@ cr.define('descriptor_panel', function() { ...@@ -194,7 +199,7 @@ cr.define('descriptor_panel', function() {
* Adds a button for getting URL descriptor. * Adds a button for getting URL descriptor.
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The offset of the URL descriptor index. * @param {number} offset The offset of the URL descriptor index.
* @param {!cr.ui.TreeItem} item * @param {!TreeItem} item
* @param {string} fieldLabel Not used in this function, but used to match * @param {string} fieldLabel Not used in this function, but used to match
* other extraTreeItemFormatter. * other extraTreeItemFormatter.
* @private * @private
...@@ -225,7 +230,7 @@ cr.define('descriptor_panel', function() { ...@@ -225,7 +230,7 @@ cr.define('descriptor_panel', function() {
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the Microsoft OS 2.0 * @param {number} offset The start offset of the Microsoft OS 2.0
* descriptor set information. * descriptor set information.
* @param {!cr.ui.TreeItem} item * @param {!TreeItem} item
* @param {string} fieldLabel Not used in this function, but used to match * @param {string} fieldLabel Not used in this function, but used to match
* other extraTreeItemFormatter. * other extraTreeItemFormatter.
* @private * @private
...@@ -269,7 +274,7 @@ cr.define('descriptor_panel', function() { ...@@ -269,7 +274,7 @@ cr.define('descriptor_panel', function() {
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the Microsoft OS 2.0 * @param {number} offset The start offset of the Microsoft OS 2.0
* descriptor set information. * descriptor set information.
* @param {!cr.ui.TreeItem} item * @param {!TreeItem} item
* @param {string} fieldLabel Not used in this function, but used to match * @param {string} fieldLabel Not used in this function, but used to match
* other extraTreeItemFormatter. * other extraTreeItemFormatter.
* @private * @private
...@@ -303,7 +308,7 @@ cr.define('descriptor_panel', function() { ...@@ -303,7 +308,7 @@ cr.define('descriptor_panel', function() {
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the registry Property * @param {number} offset The start offset of the registry Property
* descriptor. * descriptor.
* @param {!cr.ui.TreeItem} item * @param {!TreeItem} item
* @param {string} fieldLabel Not used in this function, but used to match * @param {string} fieldLabel Not used in this function, but used to match
* other extraTreeItemFormatter. * other extraTreeItemFormatter.
* @param {number} featureRegistryPropertyDataType * @param {number} featureRegistryPropertyDataType
...@@ -344,13 +349,13 @@ cr.define('descriptor_panel', function() { ...@@ -344,13 +349,13 @@ cr.define('descriptor_panel', function() {
* and raw form view. * and raw form view.
* @param {!Uint8Array} data * @param {!Uint8Array} data
* @param {number=} languageCode * @param {number=} languageCode
* @param {cr.ui.TreeItem=} treeItem * @param {TreeItem=} treeItem
* @private * @private
*/ */
async renderStandardDescriptor_( async renderStandardDescriptor_(
data, languageCode = 0, treeItem = undefined) { data, languageCode = 0, treeItem = undefined) {
const displayElement = addNewDescriptorDisplayElement(this.rootElement_); const displayElement = addNewDescriptorDisplayElement(this.rootElement_);
/** @type {!cr.ui.Tree} */ /** @type {!Tree} */
const rawDataTreeRoot = displayElement.rawDataTreeRoot; const rawDataTreeRoot = displayElement.rawDataTreeRoot;
/** @type {!HTMLElement} */ /** @type {!HTMLElement} */
const rawDataByteElement = displayElement.rawDataByteElement; const rawDataByteElement = displayElement.rawDataByteElement;
...@@ -486,7 +491,7 @@ cr.define('descriptor_panel', function() { ...@@ -486,7 +491,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a view to display device descriptor hex data in both tree view * Renders a view to display device descriptor hex data in both tree view
* and raw form. * and raw form.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the device descriptor. * @param {number} offset The start offset of the device descriptor.
...@@ -623,7 +628,7 @@ cr.define('descriptor_panel', function() { ...@@ -623,7 +628,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a view to display configuration descriptor hex data in both tree * Renders a view to display configuration descriptor hex data in both tree
* view and raw form. * view and raw form.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the configuration descriptor. * @param {number} offset The start offset of the configuration descriptor.
...@@ -683,13 +688,13 @@ cr.define('descriptor_panel', function() { ...@@ -683,13 +688,13 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display interface descriptor at index * Renders a tree item to display interface descriptor at index
* indexInterface. * indexInterface.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the interface * @param {number} offset The start offset of the interface
* descriptor. * descriptor.
* @param {number} indexInterface * @param {number} indexInterface
* @return {!cr.ui.TreeItem} * @return {!TreeItem}
* @private * @private
*/ */
renderInterfaceDescriptor_( renderInterfaceDescriptor_(
...@@ -758,7 +763,7 @@ cr.define('descriptor_panel', function() { ...@@ -758,7 +763,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display endpoint descriptor at index * Renders a tree item to display endpoint descriptor at index
* indexEndpoint. * indexEndpoint.
* @param {!cr.ui.Tree|!cr.ui.TreeItem} rawDataTreeRoot * @param {!Tree|!TreeItem} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the endpoint * @param {number} offset The start offset of the endpoint
...@@ -814,7 +819,7 @@ cr.define('descriptor_panel', function() { ...@@ -814,7 +819,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display length and type of unknown descriptor at * Renders a tree item to display length and type of unknown descriptor at
* index indexUnknown. * index indexUnknown.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the this descriptor. * @param {number} originalOffset The start offset of the this descriptor.
...@@ -922,7 +927,7 @@ cr.define('descriptor_panel', function() { ...@@ -922,7 +927,7 @@ cr.define('descriptor_panel', function() {
* and language code, and display it. * and language code, and display it.
* @param {number} index * @param {number} index
* @param {number} languageCode * @param {number} languageCode
* @param {!cr.ui.TreeItem=} treeItem * @param {!TreeItem=} treeItem
* @private * @private
*/ */
async getStringDescriptorForLanguageCode_( async getStringDescriptorForLanguageCode_(
...@@ -960,12 +965,12 @@ cr.define('descriptor_panel', function() { ...@@ -960,12 +965,12 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders string descriptor of current device with given index and language * Renders string descriptor of current device with given index and language
* code. * code.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the string descriptor. * @param {number} offset The start offset of the string descriptor.
* @param {number=} languageCode * @param {number=} languageCode
* @param {cr.ui.TreeItem=} treeItem * @param {TreeItem=} treeItem
* @private * @private
*/ */
renderStringDescriptorForLanguageCode_( renderStringDescriptorForLanguageCode_(
...@@ -1018,7 +1023,7 @@ cr.define('descriptor_panel', function() { ...@@ -1018,7 +1023,7 @@ cr.define('descriptor_panel', function() {
* Gets string descriptor in all supported languages of current device with * Gets string descriptor in all supported languages of current device with
* given index. * given index.
* @param {number} index * @param {number} index
* @param {cr.ui.TreeItem=} treeItem * @param {TreeItem=} treeItem
* @private * @private
*/ */
async getStringDescriptorForAllLanguages_(index, treeItem = undefined) { async getStringDescriptorForAllLanguages_(index, treeItem = undefined) {
...@@ -1127,7 +1132,7 @@ cr.define('descriptor_panel', function() { ...@@ -1127,7 +1132,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a view to display Binary device Object Store (BOS) descriptor hex * Renders a view to display Binary device Object Store (BOS) descriptor hex
* data in both tree view and raw form. * data in both tree view and raw form.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the BOS descriptor. * @param {number} offset The start offset of the BOS descriptor.
...@@ -1165,7 +1170,7 @@ cr.define('descriptor_panel', function() { ...@@ -1165,7 +1170,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a view to display device capability descriptor hex data in both * Renders a view to display device capability descriptor hex data in both
* tree view and raw form. * tree view and raw form.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the BOS descriptor. * @param {number} offset The start offset of the BOS descriptor.
...@@ -1199,7 +1204,7 @@ cr.define('descriptor_panel', function() { ...@@ -1199,7 +1204,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display WebUSB platform capability descriptor at * Renders a tree item to display WebUSB platform capability descriptor at
* index indexWebUsb. * index indexWebUsb.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the WebUSB platform * @param {number} offset The start offset of the WebUSB platform
...@@ -1264,7 +1269,7 @@ cr.define('descriptor_panel', function() { ...@@ -1264,7 +1269,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 platform capability * Renders a tree item to display Microsoft OS 2.0 platform capability
* descriptor at index indexMsOs20. * descriptor at index indexMsOs20.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the Microsoft OS 2.0 platform * @param {number} offset The start offset of the Microsoft OS 2.0 platform
...@@ -1327,7 +1332,7 @@ cr.define('descriptor_panel', function() { ...@@ -1327,7 +1332,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 descriptor set * Renders a tree item to display Microsoft OS 2.0 descriptor set
* information at index indexMsOs20DescriptorSetInfo. * information at index indexMsOs20DescriptorSetInfo.
* @param {!cr.ui.Tree|!cr.ui.TreeItem} rawDataTreeRoot * @param {!Tree|!TreeItem} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The start offset of the Microsoft OS 2.0 * @param {number} offset The start offset of the Microsoft OS 2.0
...@@ -1386,7 +1391,7 @@ cr.define('descriptor_panel', function() { ...@@ -1386,7 +1391,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display unknown device capability descriptor at * Renders a tree item to display unknown device capability descriptor at
* indexUnknownDevCapability * indexUnknownDevCapability
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the unknown device * @param {number} originalOffset The start offset of the unknown device
...@@ -1441,7 +1446,7 @@ cr.define('descriptor_panel', function() { ...@@ -1441,7 +1446,7 @@ cr.define('descriptor_panel', function() {
* the URL descriptor index item. * the URL descriptor index item.
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} offset The offset of the WebUSB descriptor. * @param {number} offset The offset of the WebUSB descriptor.
* @param {!cr.ui.TreeItem} item The URL descriptor index item. * @param {!TreeItem} item The URL descriptor index item.
* @private * @private
*/ */
async getUrlDescriptor_(rawData, offset, item) { async getUrlDescriptor_(rawData, offset, item) {
...@@ -1595,7 +1600,7 @@ cr.define('descriptor_panel', function() { ...@@ -1595,7 +1600,7 @@ cr.define('descriptor_panel', function() {
renderMsOs20DescriptorSet_(msOs20RawData) { renderMsOs20DescriptorSet_(msOs20RawData) {
const displayElement = addNewDescriptorDisplayElement( const displayElement = addNewDescriptorDisplayElement(
this.rootElement_, 'Microsoft OS 2.0 Descriptor Set'); this.rootElement_, 'Microsoft OS 2.0 Descriptor Set');
/** @type {!cr.ui.Tree} */ /** @type {!Tree} */
const rawDataTreeRoot = displayElement.rawDataTreeRoot; const rawDataTreeRoot = displayElement.rawDataTreeRoot;
/** @type {!HTMLElement} */ /** @type {!HTMLElement} */
const rawDataByteElement = displayElement.rawDataByteElement; const rawDataByteElement = displayElement.rawDataByteElement;
...@@ -1679,7 +1684,7 @@ cr.define('descriptor_panel', function() { ...@@ -1679,7 +1684,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 descriptor set header. * Renders a tree item to display Microsoft OS 2.0 descriptor set header.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -1733,7 +1738,7 @@ cr.define('descriptor_panel', function() { ...@@ -1733,7 +1738,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 configuration subset * Renders a tree item to display Microsoft OS 2.0 configuration subset
* header. * header.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -1799,7 +1804,7 @@ cr.define('descriptor_panel', function() { ...@@ -1799,7 +1804,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 function subset header. * Renders a tree item to display Microsoft OS 2.0 function subset header.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -1864,7 +1869,7 @@ cr.define('descriptor_panel', function() { ...@@ -1864,7 +1869,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 compatible ID Descriptor. * Renders a tree item to display Microsoft OS 2.0 compatible ID Descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -1925,7 +1930,7 @@ cr.define('descriptor_panel', function() { ...@@ -1925,7 +1930,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 registry property * Renders a tree item to display Microsoft OS 2.0 registry property
* descriptor. * descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -2025,7 +2030,7 @@ cr.define('descriptor_panel', function() { ...@@ -2025,7 +2030,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 minimum USB resume time * Renders a tree item to display Microsoft OS 2.0 minimum USB resume time
* descriptor. * descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -2086,7 +2091,7 @@ cr.define('descriptor_panel', function() { ...@@ -2086,7 +2091,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 model ID descriptor. * Renders a tree item to display Microsoft OS 2.0 model ID descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -2142,7 +2147,7 @@ cr.define('descriptor_panel', function() { ...@@ -2142,7 +2147,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 Common Class Generic * Renders a tree item to display Microsoft OS 2.0 Common Class Generic
* Parent (CCGP) device descriptor. * Parent (CCGP) device descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -2195,7 +2200,7 @@ cr.define('descriptor_panel', function() { ...@@ -2195,7 +2200,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display Microsoft OS 2.0 vendor revision * Renders a tree item to display Microsoft OS 2.0 vendor revision
* descriptor. * descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the Microsoft OS 2.0 * @param {number} originalOffset The start offset of the Microsoft OS 2.0
...@@ -2250,7 +2255,7 @@ cr.define('descriptor_panel', function() { ...@@ -2250,7 +2255,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree item to display an unknown Microsoft OS 2.0 descriptor. * Renders a tree item to display an unknown Microsoft OS 2.0 descriptor.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
* @param {number} originalOffset The start offset of the unknown Microsoft * @param {number} originalOffset The start offset of the unknown Microsoft
...@@ -2350,7 +2355,7 @@ cr.define('descriptor_panel', function() { ...@@ -2350,7 +2355,7 @@ cr.define('descriptor_panel', function() {
*/ */
async renderTestingData_(rawData) { async renderTestingData_(rawData) {
const displayElement = addNewDescriptorDisplayElement(this.rootElement_); const displayElement = addNewDescriptorDisplayElement(this.rootElement_);
/** @type {!cr.ui.Tree} */ /** @type {!Tree} */
const rawDataTreeRoot = displayElement.rawDataTreeRoot; const rawDataTreeRoot = displayElement.rawDataTreeRoot;
rawDataTreeRoot.style.display = 'none'; rawDataTreeRoot.style.display = 'none';
/** @type {!HTMLElement} */ /** @type {!HTMLElement} */
...@@ -2652,7 +2657,7 @@ cr.define('descriptor_panel', function() { ...@@ -2652,7 +2657,7 @@ cr.define('descriptor_panel', function() {
* Adds a display area which contains a tree view and a byte view. * Adds a display area which contains a tree view and a byte view.
* @param {!HTMLElement} rootElement * @param {!HTMLElement} rootElement
* @param {string=} descriptorPanelTitle * @param {string=} descriptorPanelTitle
* @return {{rawDataTreeRoot:!cr.ui.Tree,rawDataByteElement:!HTMLElement}} * @return {{rawDataTreeRoot:!Tree,rawDataByteElement:!HTMLElement}}
*/ */
function addNewDescriptorDisplayElement( function addNewDescriptorDisplayElement(
rootElement, descriptorPanelTitle = undefined) { rootElement, descriptorPanelTitle = undefined) {
...@@ -2670,7 +2675,7 @@ cr.define('descriptor_panel', function() { ...@@ -2670,7 +2675,7 @@ cr.define('descriptor_panel', function() {
const rawDataByteElement = const rawDataByteElement =
queryRequiredElement('.raw-data-byte-view', descriptorPanelClone); queryRequiredElement('.raw-data-byte-view', descriptorPanelClone);
cr.ui.decorate(rawDataTreeRoot, cr.ui.Tree); decorate(rawDataTreeRoot, Tree);
rawDataTreeRoot.detail = {payload: {}, children: {}}; rawDataTreeRoot.detail = {payload: {}, children: {}};
if (descriptorPanelTitle) { if (descriptorPanelTitle) {
...@@ -2713,10 +2718,10 @@ cr.define('descriptor_panel', function() { ...@@ -2713,10 +2718,10 @@ cr.define('descriptor_panel', function() {
* Renders a customized TreeItem with the given content and class name. * Renders a customized TreeItem with the given content and class name.
* @param {string} itemLabel * @param {string} itemLabel
* @param {string=} className * @param {string=} className
* @return {!cr.ui.TreeItem} * @return {!TreeItem}
*/ */
function customTreeItem(itemLabel, className = undefined) { function customTreeItem(itemLabel, className = undefined) {
const item = new cr.ui.TreeItem({ const item = new TreeItem({
label: itemLabel, label: itemLabel,
icon: '', icon: '',
}); });
...@@ -2728,7 +2733,7 @@ cr.define('descriptor_panel', function() { ...@@ -2728,7 +2733,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Adds function for mapping between two views. * Adds function for mapping between two views.
* @param {!cr.ui.Tree} rawDataTreeRoot * @param {!Tree} rawDataTreeRoot
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
*/ */
function addMappingAction(rawDataTreeRoot, rawDataByteElement) { function addMappingAction(rawDataTreeRoot, rawDataByteElement) {
...@@ -2811,7 +2816,7 @@ cr.define('descriptor_panel', function() { ...@@ -2811,7 +2816,7 @@ cr.define('descriptor_panel', function() {
/** /**
* Renders a tree view to display the raw data in readable text. * Renders a tree view to display the raw data in readable text.
* @param {!cr.ui.Tree|!cr.ui.TreeItem} root * @param {!Tree|!TreeItem} root
* @param {!HTMLElement} rawDataByteElement * @param {!HTMLElement} rawDataByteElement
* @param {!Array<Object>} fields * @param {!Array<Object>} fields
* @param {!Uint8Array} rawData * @param {!Uint8Array} rawData
...@@ -3185,10 +3190,5 @@ cr.define('descriptor_panel', function() { ...@@ -3185,10 +3190,5 @@ cr.define('descriptor_panel', function() {
return true; return true;
} }
return {
DescriptorPanel,
};
});
window.deviceDescriptorCompleteFn = window.deviceDescriptorCompleteFn =
window.deviceDescriptorCompleteFn || function() {}; window.deviceDescriptorCompleteFn || function() {};
...@@ -7,13 +7,22 @@ ...@@ -7,13 +7,22 @@
* chrome://usb-internals/. * chrome://usb-internals/.
*/ */
cr.define('devices_page', function() { import './mojo.js';
import {assertInstanceof} from 'chrome://resources/js/assert.m.js';
import {decorate} from 'chrome://resources/js/cr/ui.m.js';
import {Tab, TabPanel} from 'chrome://resources/js/cr/ui/tabs.m.js';
import {Tree, TreeItem} from 'chrome://resources/js/cr/ui/tree.m.js';
import {queryRequiredElement} from 'chrome://resources/js/util.m.js';
import {DescriptorPanel} from './descriptor_panel.js';
const UsbDeviceRemote = device.mojom.UsbDeviceRemote; const UsbDeviceRemote = device.mojom.UsbDeviceRemote;
/** /**
* Page that contains a tab header and a tab panel displaying devices table. * Page that contains a tab header and a tab panel displaying devices table.
*/ */
class DevicesPage { export class DevicesPage {
/** /**
* @param {!device.mojom.UsbDeviceManagerRemote} usbManager * @param {!device.mojom.UsbDeviceManagerRemote} usbManager
* @param {!ShadowRoot} root * @param {!ShadowRoot} root
...@@ -126,7 +135,7 @@ cr.define('devices_page', function() { ...@@ -126,7 +135,7 @@ cr.define('devices_page', function() {
tab.id = device.guid; tab.id = device.guid;
tabs.appendChild(tabClone); tabs.appendChild(tabClone);
cr.ui.decorate(tab, cr.ui.Tab); decorate(tab, Tab);
const tabPanels = queryRequiredElement('tabpanels', this.root); const tabPanels = queryRequiredElement('tabpanels', this.root);
const tabPanelTemplate = const tabPanelTemplate =
...@@ -139,7 +148,7 @@ cr.define('devices_page', function() { ...@@ -139,7 +148,7 @@ cr.define('devices_page', function() {
*/ */
const treeViewRoot = assertInstanceof( const treeViewRoot = assertInstanceof(
tabPanelClone.querySelector('.tree-view'), HTMLElement); tabPanelClone.querySelector('.tree-view'), HTMLElement);
cr.ui.decorate(treeViewRoot, cr.ui.Tree); decorate(treeViewRoot, Tree);
treeViewRoot.detail = {payload: {}, children: {}}; treeViewRoot.detail = {payload: {}, children: {}};
// Clear the tree first before populating it with the new content. // Clear the tree first before populating it with the new content.
treeViewRoot.innerText = ''; treeViewRoot.innerText = '';
...@@ -150,7 +159,7 @@ cr.define('devices_page', function() { ...@@ -150,7 +159,7 @@ cr.define('devices_page', function() {
this.initializeDescriptorPanels_(tabPanel, device.guid); this.initializeDescriptorPanels_(tabPanel, device.guid);
tabPanels.appendChild(tabPanelClone); tabPanels.appendChild(tabPanelClone);
cr.ui.decorate(tabPanel, cr.ui.TabPanel); decorate(tabPanel, TabPanel);
} }
/** /**
...@@ -190,7 +199,7 @@ cr.define('devices_page', function() { ...@@ -190,7 +199,7 @@ cr.define('devices_page', function() {
/** /**
* Renders a tree to display the device's detail information. * Renders a tree to display the device's detail information.
* @param {!device.mojom.UsbDeviceInfo} device * @param {!device.mojom.UsbDeviceInfo} device
* @param {!cr.ui.Tree} root * @param {!Tree} root
*/ */
function renderDeviceTree(device, root) { function renderDeviceTree(device, root) {
root.add(customTreeItem(`USB Version: ${device.usbVersionMajor}.${ root.add(customTreeItem(`USB Version: ${device.usbVersionMajor}.${
...@@ -247,7 +256,7 @@ cr.define('devices_page', function() { ...@@ -247,7 +256,7 @@ cr.define('devices_page', function() {
/** /**
* Renders a tree item to display the device's configuration information. * Renders a tree item to display the device's configuration information.
* @param {!Array<!device.mojom.UsbConfigurationInfo>} configurationsArray * @param {!Array<!device.mojom.UsbConfigurationInfo>} configurationsArray
* @param {!cr.ui.Tree} root * @param {!Tree} root
*/ */
function renderConfigurationTreeItem(configurationsArray, root) { function renderConfigurationTreeItem(configurationsArray, root) {
for (const configuration of configurationsArray) { for (const configuration of configurationsArray) {
...@@ -269,7 +278,7 @@ cr.define('devices_page', function() { ...@@ -269,7 +278,7 @@ cr.define('devices_page', function() {
/** /**
* Renders a tree item to display the device's interface information. * Renders a tree item to display the device's interface information.
* @param {!Array<!device.mojom.UsbInterfaceInfo>} interfacesArray * @param {!Array<!device.mojom.UsbInterfaceInfo>} interfacesArray
* @param {!cr.ui.TreeItem} root * @param {!TreeItem} root
*/ */
function renderInterfacesTreeItem(interfacesArray, root) { function renderInterfacesTreeItem(interfacesArray, root) {
for (const currentInterface of interfacesArray) { for (const currentInterface of interfacesArray) {
...@@ -287,7 +296,7 @@ cr.define('devices_page', function() { ...@@ -287,7 +296,7 @@ cr.define('devices_page', function() {
* Renders a tree item to display the device's alternate interfaces * Renders a tree item to display the device's alternate interfaces
* information. * information.
* @param {!Array<!device.mojom.UsbAlternateInterfaceInfo>} alternatesArray * @param {!Array<!device.mojom.UsbAlternateInterfaceInfo>} alternatesArray
* @param {!cr.ui.TreeItem} root * @param {!TreeItem} root
*/ */
function renderAlternatesTreeItem(alternatesArray, root) { function renderAlternatesTreeItem(alternatesArray, root) {
for (const alternate of alternatesArray) { for (const alternate of alternatesArray) {
...@@ -317,7 +326,7 @@ cr.define('devices_page', function() { ...@@ -317,7 +326,7 @@ cr.define('devices_page', function() {
/** /**
* Renders a tree item to display the device's endpoints information. * Renders a tree item to display the device's endpoints information.
* @param {!Array<!device.mojom.UsbEndpointInfo>} endpointsArray * @param {!Array<!device.mojom.UsbEndpointInfo>} endpointsArray
* @param {!cr.ui.TreeItem} root * @param {!TreeItem} root
*/ */
function renderEndpointsTreeItem(endpointsArray, root) { function renderEndpointsTreeItem(endpointsArray, root) {
for (const endpoint of endpointsArray) { for (const endpoint of endpointsArray) {
...@@ -366,13 +375,13 @@ cr.define('devices_page', function() { ...@@ -366,13 +375,13 @@ cr.define('devices_page', function() {
* @param {string} panelType * @param {string} panelType
* @param {!device.mojom.UsbDeviceRemote} usbDevice * @param {!device.mojom.UsbDeviceRemote} usbDevice
* @param {string} guid * @param {string} guid
* @return {!descriptor_panel.DescriptorPanel} * @return {!DescriptorPanel}
*/ */
function initialInspectorPanel(tabPanel, panelType, usbDevice, guid) { function initialInspectorPanel(tabPanel, panelType, usbDevice, guid) {
const button = queryRequiredElement(`.${panelType}-button`, tabPanel); const button = queryRequiredElement(`.${panelType}-button`, tabPanel);
const displayElement = const displayElement =
queryRequiredElement(`.${panelType}-panel`, tabPanel); queryRequiredElement(`.${panelType}-panel`, tabPanel);
const descriptorPanel = new descriptor_panel.DescriptorPanel( const descriptorPanel = new DescriptorPanel(
usbDevice, /** @type {!HTMLElement} */ (displayElement)); usbDevice, /** @type {!HTMLElement} */ (displayElement));
switch (panelType) { switch (panelType) {
case 'string-descriptor': case 'string-descriptor':
...@@ -429,21 +438,16 @@ cr.define('devices_page', function() { ...@@ -429,21 +438,16 @@ cr.define('devices_page', function() {
/** /**
* Renders a customized TreeItem with the given content and class name. * Renders a customized TreeItem with the given content and class name.
* @param {string} itemLabel * @param {string} itemLabel
* @return {!cr.ui.TreeItem} * @return {!TreeItem}
* @private * @private
*/ */
function customTreeItem(itemLabel) { function customTreeItem(itemLabel) {
return new cr.ui.TreeItem({ return new TreeItem({
label: itemLabel, label: itemLabel,
icon: '', icon: '',
}); });
} }
return {
DevicesPage,
};
});
window.deviceListCompleteFn = window.deviceListCompleteFn || function() {}; window.deviceListCompleteFn = window.deviceListCompleteFn || function() {};
window.deviceTabInitializedFn = window.deviceTabInitializedFn || function() {}; window.deviceTabInitializedFn = window.deviceTabInitializedFn || function() {};
// 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.
// TODO(crbug.com/1004256): Use proper Mojo JS modules instead.
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/big_buffer.mojom-lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/file.mojom-lite.js';
import 'chrome://resources/mojo/mojo/public/mojom/base/string16.mojom-lite.js';
import 'chrome://resources/mojo/url/mojom/url.mojom-lite.js';
import './usb_device.mojom-lite.js';
import './usb_manager_client.mojom-lite.js';
import './usb_enumeration_options.mojom-lite.js';
import './usb_manager.mojom-lite.js';
import './usb_manager_test.mojom-lite.js';
import './usb_internals.mojom-lite.js';
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
<output filename="grit/usb_internals_resources.h" type="rc_header"> <output filename="grit/usb_internals_resources.h" type="rc_header">
<emit emit_type='prepend'></emit> <emit emit_type='prepend'></emit>
</output> </output>
<output filename="grit/usb_internals_resources_map.cc"
type="resource_file_map_source" />
<output filename="grit/usb_internals_resources_map.h"
type="resource_map_header" />
<output filename="usb_internals_resources.pak" type="data_package" /> <output filename="usb_internals_resources.pak" type="data_package" />
</outputs> </outputs>
<release seq="1"> <release seq="1">
...@@ -21,15 +25,18 @@ ...@@ -21,15 +25,18 @@
type="BINDATA" /> type="BINDATA" />
<include name="IDR_USB_INTERNALS_HTML" <include name="IDR_USB_INTERNALS_HTML"
file="usb_internals.html" file="usb_internals.html"
flattenhtml="true" type="BINDATA" />
allowexternalscript="true" <include name="IDR_USB_INTERNALS_MOJO_JS"
file="mojo.js"
type="BINDATA" /> type="BINDATA" />
<include name="IDR_USB_INTERNALS_MOJOM_LITE_JS" <include name="IDR_USB_INTERNALS_MOJOM_LITE_JS"
file="${root_gen_dir}\chrome\browser\ui\webui\usb_internals\usb_internals.mojom-lite.js" file="${root_gen_dir}\chrome\browser\ui\webui\usb_internals\usb_internals.mojom-lite.js"
resource_path="usb_internals.mojom-lite.js"
use_base_dir="false" use_base_dir="false"
type="BINDATA" /> type="BINDATA" />
<include name="IDR_USB_INTERNALS_APP_JS" <include name="IDR_USB_INTERNALS_APP_JS"
file="${root_gen_dir}\chrome\browser\resources\usb_internals\app.js" file="${root_gen_dir}\chrome\browser\resources\usb_internals\app.js"
resource_path="app.js"
use_base_dir="false" use_base_dir="false"
type="BINDATA" /> type="BINDATA" />
</includes> </includes>
......
...@@ -5,35 +5,11 @@ ...@@ -5,35 +5,11 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>USB Internals</title> <title>USB Internals</title>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css"> <link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<script src="chrome://resources/js/assert.js"></script>
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://resources/js/promise_resolver.js"></script>
<script src="chrome://resources/js/cr/ui.js"></script>
<script src="chrome://resources/js/cr/ui/focus_outline_manager.js"></script>
<script src="chrome://resources/js/cr/ui/tabs.js"></script>
<script src="chrome://resources/js/cr/ui/tree.js"></script>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/mojo/mojo/public/mojom/base/big_buffer.mojom-lite.js"></script>
<script src="chrome://resources/mojo/mojo/public/mojom/base/file.mojom-lite.js"></script>
<script src="chrome://resources/mojo/mojo/public/mojom/base/string16.mojom-lite.js"></script>
<script src="chrome://resources/mojo/url/mojom/url.mojom-lite.js"></script>
<script src="usb_device.mojom-lite.js"></script>
<script src="usb_manager_client.mojom-lite.js"></script>
<script src="usb_enumeration_options.mojom-lite.js"></script>
<script src="usb_manager.mojom-lite.js"></script>
<script src="usb_manager_test.mojom-lite.js"></script>
<script src="usb_internals.mojom-lite.js"></script>
<script src="descriptor_panel.js"></script>
<script src="devices_page.js"></script>
</head> </head>
<body> <body>
<usb-internals-app></usb-internals-app> <usb-internals-app></usb-internals-app>
<script src="app.js"></script> <script type="module" src="app.js"></script>
</body> </body>
</html> </html>
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/usb_internals_resources.h" #include "chrome/grit/usb_internals_resources.h"
#include "chrome/grit/usb_internals_resources_map.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
UsbInternalsUI::UsbInternalsUI(content::WebUI* web_ui) UsbInternalsUI::UsbInternalsUI(content::WebUI* web_ui)
...@@ -20,11 +21,6 @@ UsbInternalsUI::UsbInternalsUI(content::WebUI* web_ui) ...@@ -20,11 +21,6 @@ UsbInternalsUI::UsbInternalsUI(content::WebUI* web_ui)
content::WebUIDataSource::Create(chrome::kChromeUIUsbInternalsHost); content::WebUIDataSource::Create(chrome::kChromeUIUsbInternalsHost);
static constexpr webui::ResourcePath kPaths[] = { static constexpr webui::ResourcePath kPaths[] = {
{"app.js", IDR_USB_INTERNALS_APP_JS},
{"usb_internals.css", IDR_USB_INTERNALS_CSS},
{"usb_internals.mojom-lite.js", IDR_USB_INTERNALS_MOJOM_LITE_JS},
{"descriptor_panel.js", IDR_USB_INTERNALS_DESCRIPTOR_PANEL_JS},
{"devices_page.js", IDR_USB_INTERNALS_DEVICES_PAGE_JS},
{"usb_device.mojom-lite.js", IDR_USB_DEVICE_MOJOM_LITE_JS}, {"usb_device.mojom-lite.js", IDR_USB_DEVICE_MOJOM_LITE_JS},
{"usb_enumeration_options.mojom-lite.js", {"usb_enumeration_options.mojom-lite.js",
IDR_USB_ENUMERATION_OPTIONS_MOJOM_LITE_JS}, IDR_USB_ENUMERATION_OPTIONS_MOJOM_LITE_JS},
...@@ -36,8 +32,10 @@ UsbInternalsUI::UsbInternalsUI(content::WebUI* web_ui) ...@@ -36,8 +32,10 @@ UsbInternalsUI::UsbInternalsUI(content::WebUI* web_ui)
}; };
webui::AddResourcePathsBulk(source, kPaths); webui::AddResourcePathsBulk(source, kPaths);
source->SetDefaultResource(IDR_USB_INTERNALS_HTML); webui::SetupWebUIDataSource(
source->DisableTrustedTypesCSP(); source,
base::make_span(kUsbInternalsResources, kUsbInternalsResourcesSize), "",
IDR_USB_INTERNALS_HTML);
content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source); content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), source);
} }
......
...@@ -18,7 +18,8 @@ UsbInternalsTest.prototype = { ...@@ -18,7 +18,8 @@ UsbInternalsTest.prototype = {
__proto__: testing.Test.prototype, __proto__: testing.Test.prototype,
/** @override */ /** @override */
browsePreload: 'chrome://usb-internals', browsePreload:
'chrome://usb-internals/test_loader.html?module=usb_internals_test.js',
/** @override */ /** @override */
isAsync: true, isAsync: true,
...@@ -27,9 +28,6 @@ UsbInternalsTest.prototype = { ...@@ -27,9 +28,6 @@ UsbInternalsTest.prototype = {
extraLibraries: [ extraLibraries: [
'//third_party/mocha/mocha.js', '//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js', '//chrome/test/data/webui/mocha_adapter.js',
'//ui/webui/resources/js/promise_resolver.js',
'//chrome/test/data/webui/test_browser_proxy.js',
'//chrome/test/data/webui/usb_internals_test.js',
], ],
}; };
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
// Use of this source code is governed by a BSD-style 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.
import 'chrome://usb-internals/mojo.js';
import 'chrome://usb-internals/app.js';
import {PromiseResolver} from 'chrome://resources/js/promise_resolver.m.js';
import {TestBrowserProxy} from 'chrome://test/test_browser_proxy.m.js';
/** @implements {mojom.UsbInternalsPageHandlerRemote} */ /** @implements {mojom.UsbInternalsPageHandlerRemote} */
class FakePageHandlerRemote extends TestBrowserProxy { class FakePageHandlerRemote extends TestBrowserProxy {
constructor(handle) { constructor(handle) {
...@@ -243,10 +249,10 @@ window.setupFn = () => { ...@@ -243,10 +249,10 @@ window.setupFn = () => {
mojom.UsbInternalsPageHandler.$interfaceName); mojom.UsbInternalsPageHandler.$interfaceName);
pageHandlerInterceptor.oninterfacerequest = (e) => { pageHandlerInterceptor.oninterfacerequest = (e) => {
pageHandler = new FakePageHandlerRemote(e.handle); pageHandler = new FakePageHandlerRemote(e.handle);
setupResolver.resolve();
}; };
pageHandlerInterceptor.start(); pageHandlerInterceptor.start();
setupResolver.resolve();
return Promise.resolve(); return Promise.resolve();
}; };
...@@ -254,16 +260,15 @@ window.setupFn = () => { ...@@ -254,16 +260,15 @@ window.setupFn = () => {
suite('UsbInternalsUITest', function() { suite('UsbInternalsUITest', function() {
let app = null; let app = null;
suiteSetup(function() { suiteSetup(async function() {
app = document.querySelector('usb-internals-app'); document.body.innerHTML = '';
app = document.createElement('usb-internals-app');
document.body.appendChild(app);
// Before tests are run, make sure setup completes. // Before tests are run, make sure setup completes.
return setupResolver.promise.then(function() { await setupResolver.promise;
return Promise.all([ await pageHandler.whenCalled('bindUsbDeviceManagerInterface');
pageHandler.whenCalled('bindUsbDeviceManagerInterface'), await pageHandler.deviceManager.whenCalled('getDevices');
pageHandler.deviceManager.whenCalled('getDevices'),
]);
});
}); });
teardown(function() { teardown(function() {
......
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