1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
content / browser / resources / webxr_internals / webxr_internals.ts [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './active_runtime_info_table.js';
import './device_info_table.js';
import './runtime_changelog_table.js';
import './session_info_table.js';
import './session_statistics_table.js';
import {assert} from 'chrome://resources/js/assert.js';
import {getRequiredElement} from 'chrome://resources/js/util.js';
import type {ActiveRuntimeInfoTableElement} from './active_runtime_info_table.js';
import {BrowserProxy} from './browser_proxy.js';
import type {RuntimeInfo, SessionRejectedRecord, SessionRequestedRecord, SessionStartedRecord, SessionStoppedRecord} from './webxr_internals.mojom-webui.js';
import type {XRDeviceId} from './xr_device.mojom-webui.js';
import type {XrFrameStatistics, XrLogMessage} from './xr_session.mojom-webui.js';
let browserProxy: BrowserProxy;
async function bootstrap() {
browserProxy = BrowserProxy.getInstance();
assert(browserProxy);
setupSidebarButtonListeners();
renderDeviceInfoContent();
renderSessionInfoContent();
renderRuntimeInfoContent();
renderSessionStatisticsContent();
}
async function setupSidebarButtonListeners() {
const deviceInfoButton = getRequiredElement('device-info-button');
const sessionInfoButton = getRequiredElement('session-info-button');
const runtimeInfoButton = getRequiredElement('runtime-info-button');
const sessionStatisticsButton =
getRequiredElement('session-statistics-button');
deviceInfoButton.addEventListener('click', () => {
switchSidebar('device-info');
});
sessionInfoButton.addEventListener('click', () => {
switchSidebar('session-info');
});
runtimeInfoButton.addEventListener('click', () => {
switchSidebar('runtime-info');
});
sessionStatisticsButton.addEventListener('click', () => {
switchSidebar('session-statistics');
});
}
function ensureOnlyContentSelected(
sidebarId: string, querySelectorString: string, elementSuffix: string) {
const elements = document.body.querySelectorAll(querySelectorString);
elements.forEach(element => element.classList.remove('active'));
const selectedElement = getRequiredElement(sidebarId + elementSuffix);
selectedElement.classList.add('active');
}
function switchSidebar(sidebarId: string) {
ensureOnlyContentSelected(sidebarId, '.tab-content', '-content');
ensureOnlyContentSelected(sidebarId, '.tab-button', '-button');
}
async function renderDeviceInfoContent() {
const deviceInfo = await browserProxy.getDeviceInfo();
const deviceInfoContent = getRequiredElement('device-info-content');
assert(deviceInfoContent);
const table = document.createElement('device-info-table');
table.addRow('Operating System Name', deviceInfo.operatingSystemName);
table.addRow('Operating System Version', deviceInfo.operatingSystemVersion);
table.addRow('GPU Gl Vendor', deviceInfo.gpuGlVendor);
table.addRow('GPU GL Renderer', deviceInfo.gpuGlRenderer);
deviceInfoContent.appendChild(table);
}
async function renderSessionInfoContent() {
const sessionInfoContent = getRequiredElement('session-info-content');
assert(sessionInfoContent);
const table = document.createElement('session-info-table');
browserProxy.getBrowserCallback().logXrSessionRequested.addListener(
(sessionRequestedRecord: SessionRequestedRecord) => {
table.addSessionRequestedRow(sessionRequestedRecord);
});
browserProxy.getBrowserCallback().logXrSessionRejected.addListener(
(sessionRejectedRecord: SessionRejectedRecord) => {
table.addSessionRejectedRow(sessionRejectedRecord);
});
browserProxy.getBrowserCallback().logXrSessionStarted.addListener(
(sessionStartedRecord: SessionStartedRecord) => {
table.addSessionStartedRow(sessionStartedRecord);
});
browserProxy.getBrowserCallback().logXrSessionStopped.addListener(
(sessionStoppedRecord: SessionStoppedRecord) => {
table.addSessionStoppedRow(sessionStoppedRecord);
});
sessionInfoContent.appendChild(table);
}
async function renderActiveRuntimesTable(
runtimeInfoTable: ActiveRuntimeInfoTableElement) {
const activeRuntimes = await browserProxy.getActiveRuntimes();
runtimeInfoTable.recreateActiveRuntimesTable(activeRuntimes);
}
async function renderRuntimeInfoContent() {
const runtimeInfoContent = getRequiredElement('runtime-info-content');
assert(runtimeInfoContent);
const activeRuntimeTable =
document.createElement('active-runtime-info-table');
const runtimeChangelogTable =
document.createElement('runtime-changelog-table');
renderActiveRuntimesTable(activeRuntimeTable);
browserProxy.getBrowserCallback().logXrRuntimeAdded.addListener(
(runtimeInfo: RuntimeInfo) => {
runtimeChangelogTable.addRuntimeAddedRecord(runtimeInfo);
renderActiveRuntimesTable(activeRuntimeTable);
});
browserProxy.getBrowserCallback().logXrRuntimeRemoved.addListener(
(deviceId: XRDeviceId) => {
runtimeChangelogTable.addRuntimeRemovedRecord(deviceId);
renderActiveRuntimesTable(activeRuntimeTable);
});
runtimeInfoContent.appendChild(activeRuntimeTable);
runtimeInfoContent.appendChild(runtimeChangelogTable);
}
async function renderSessionStatisticsContent() {
const sessionStatisticsContent =
getRequiredElement('session-statistics-content');
assert(sessionStatisticsContent);
const table = document.createElement('session-statistics-table');
browserProxy.getBrowserCallback().logConsoleMessages.addListener(
(xrLogMessage: XrLogMessage) => {
table.addConsoleMessageRow(xrLogMessage);
});
sessionStatisticsContent.appendChild(table);
browserProxy.getBrowserCallback().logFrameData.addListener(
(xrSessionStatistics: XrFrameStatistics) => {
table.addXrSessionStatisticsRow(xrSessionStatistics);
});
sessionStatisticsContent.appendChild(table);
}
document.addEventListener('DOMContentLoaded', bootstrap);