Commit 3fed3e13 authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

WebUI: Migrate chrome://sandbox to JS Modules.

Also fixing JS type checking errors in sandbox_internals_win.js
which is not type caught on the bots as JS type checking is not
performed on Win bots.

Bug: 1028829
Change-Id: I1dff426272f4793ab23a13d117ac5f0a3a8bf99d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587094
Auto-Submit: dpapad <dpapad@chromium.org>
Commit-Queue: John Lee <johntlee@chromium.org>
Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836180}
parent 72bf334e
...@@ -61,7 +61,7 @@ This file specifies browser resources for developer-facing chrome:// pages ...@@ -61,7 +61,7 @@ This file specifies browser resources for developer-facing chrome:// pages
<if expr="is_android or is_linux"> <if expr="is_android or is_linux">
<include name="IDR_SANDBOX_INTERNALS_HTML" file="resources\sandbox_internals\sandbox_internals.html" preprocess="true" type="BINDATA" /> <include name="IDR_SANDBOX_INTERNALS_HTML" file="resources\sandbox_internals\sandbox_internals.html" preprocess="true" type="BINDATA" />
<include name="IDR_SANDBOX_INTERNALS_JS" file="resources\sandbox_internals\sandbox_internals.js" type="BINDATA" /> <include name="IDR_SANDBOX_INTERNALS_JS" file="resources\sandbox_internals\sandbox_internals.js" preprocess="true" type="BINDATA" />
</if> </if>
<if expr="is_win"> <if expr="is_win">
<include name="IDR_SANDBOX_INTERNALS_HTML" file="resources\sandbox_internals\sandbox_internals.html" preprocess="true" type="BINDATA" /> <include name="IDR_SANDBOX_INTERNALS_HTML" file="resources\sandbox_internals\sandbox_internals.html" preprocess="true" type="BINDATA" />
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") { js_type_check("closure_compile") {
uses_js_modules = true
if (is_win) { if (is_win) {
deps = [ ":sandbox_internals_win" ] deps = [ ":sandbox_internals_win" ]
} }
...@@ -17,9 +18,8 @@ js_library("sandbox_internals") { ...@@ -17,9 +18,8 @@ js_library("sandbox_internals") {
# Android & Linux both need _externs for type checks as they share a js file. # Android & Linux both need _externs for type checks as they share a js file.
deps = [ deps = [
":sandbox_android_externs", ":sandbox_android_externs",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:load_time_data", "//ui/webui/resources/js:util.m",
"//ui/webui/resources/js:util",
] ]
} }
...@@ -28,7 +28,8 @@ js_library("sandbox_android_externs") { ...@@ -28,7 +28,8 @@ js_library("sandbox_android_externs") {
js_library("sandbox_internals_win") { js_library("sandbox_internals_win") {
deps = [ deps = [
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:util", "//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:util.m",
] ]
} }
...@@ -2,6 +2,18 @@ ...@@ -2,6 +2,18 @@
// 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.
/**
* @typedef {{
* seccompStatus: number,
* pid: string,
* uid: string,
* secontext: string,
* procStatus: string,
* androidBuildId: string
* }}
*/
let AndroidSandboxStatus;
/** /**
* This function is only exposed to the Android chrome://sandbox webui. * This function is only exposed to the Android chrome://sandbox webui.
* @param {!function(!AndroidSandboxStatus)=} callback * @param {!function(!AndroidSandboxStatus)=} callback
......
...@@ -40,17 +40,7 @@ ...@@ -40,17 +40,7 @@
} }
</if> </if>
</style> </style>
<script src="chrome://resources/js/cr.js"></script> <script type="module" src="sandbox_internals.js"></script>
<if expr="is_linux">
<script src="chrome://resources/js/load_time_data.js"></script>
<script src="chrome://sandbox/strings.js"></script>
</if>
<script src="chrome://resources/js/assert.js"></script>
<if expr="is_win">
<script src="chrome://resources/js/promise_resolver.js"></script>
</if>
<script src="chrome://resources/js/util.js"></script>
<script src="sandbox_internals.js"></script>
</head> </head>
<body> <body>
<h1>Sandbox Status</h1> <h1>Sandbox Status</h1>
......
...@@ -2,19 +2,13 @@ ...@@ -2,19 +2,13 @@
// 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 {$} from 'chrome://resources/js/util.m.js';
* @typedef {{
* seccompStatus: number, // <if expr="is_linux">
* pid: string, import './strings.m.js';
* uid: string, import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
* secontext: string, // </if>
* procStatus: string,
* androidBuildId: string
* }}
*/
let AndroidSandboxStatus;
(function() {
/** /**
* CSS classes for different statuses. * CSS classes for different statuses.
* @enum {string} * @enum {string}
...@@ -72,6 +66,7 @@ function setEvaluation(result) { ...@@ -72,6 +66,7 @@ function setEvaluation(result) {
$('evaluation').innerText = message; $('evaluation').innerText = message;
} }
// <if expr="is_android">
/** /**
* Main page handler for Android. * Main page handler for Android.
*/ */
...@@ -135,7 +130,9 @@ function androidHandler() { ...@@ -135,7 +130,9 @@ function androidHandler() {
setEvaluation(isIsolated && isTsync && isChromeSeccomp); setEvaluation(isIsolated && isTsync && isChromeSeccomp);
}); });
} }
// </if>
// <if expr="is_linux">
/** /**
* Main page handler for desktop Linux. * Main page handler for desktop Linux.
*/ */
...@@ -178,12 +175,13 @@ function linuxHandler() { ...@@ -178,12 +175,13 @@ function linuxHandler() {
setEvaluation(loadTimeData.getBoolean('sandboxGood')); setEvaluation(loadTimeData.getBoolean('sandboxGood'));
} }
// </if>
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
if (cr.isAndroid) { // <if expr="is_android">
androidHandler(); androidHandler();
} else { // </if>
linuxHandler(); // <if expr="is_linux">
} linuxHandler();
// </if>
}); });
})();
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
// 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 {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {sendWithPromise} from 'chrome://resources/js/cr.m.js';
import {$} from 'chrome://resources/js/util.m.js';
/** /**
* @typedef {{ * @typedef {{
* processId: number, * processId: number,
...@@ -44,12 +48,6 @@ let SandboxDiagnostics; ...@@ -44,12 +48,6 @@ let SandboxDiagnostics;
/** /**
* Represents a mitigation field from the PROCESS_CREATION_MITITAGION_POLICY* * Represents a mitigation field from the PROCESS_CREATION_MITITAGION_POLICY*
* series in Winbase.h. * series in Winbase.h.
* @typedef {{
* mitigation: !string,
* value: !number,
* mask: !number,
* offset: !number
* }}
*/ */
class MitigationField { class MitigationField {
/** /**
...@@ -60,15 +58,19 @@ class MitigationField { ...@@ -60,15 +58,19 @@ class MitigationField {
* @param {number} offset within PC section. * @param {number} offset within PC section.
*/ */
constructor(mitigation, value, mask, offset) { constructor(mitigation, value, mask, offset) {
/** @type {string} */
this.mitigation = mitigation; this.mitigation = mitigation;
/** @type {number} */
this.value = value; this.value = value;
/** @type {number} */
this.mask = mask; this.mask = mask;
/** @type {number} */
this.offset = offset; this.offset = offset;
} }
/** /**
* Each PC field overrides this as they know where their data is. * Each PC field overrides this as they know where their data is.
* @param {Uint8Array} platform mitigations data. * @param {Uint8Array} bytes platform mitigations data.
* @return {Uint8Array} chunk containing this field or null. * @return {Uint8Array} chunk containing this field or null.
*/ */
getFieldData(bytes) { getFieldData(bytes) {
...@@ -78,7 +80,7 @@ class MitigationField { ...@@ -78,7 +80,7 @@ class MitigationField {
/** /**
* Are all the bits of this field set in the mitigations represented by * Are all the bits of this field set in the mitigations represented by
* |bytes|. * |bytes|.
* @param {Uint8Array} platform mitigations. * @param {Uint8Array} bytes platform mitigations.
* @return {boolean} * @return {boolean}
*/ */
isFieldSet(bytes) { isFieldSet(bytes) {
...@@ -100,7 +102,7 @@ class MitigationField { ...@@ -100,7 +102,7 @@ class MitigationField {
*/ */
class PC0Field extends MitigationField { class PC0Field extends MitigationField {
/** /**
* @param {Uint8Array} platform mitigations data. * @param {Uint8Array} bytes platform mitigations data.
* @return {Uint8Array} chunk containing this field or null. * @return {Uint8Array} chunk containing this field or null.
*/ */
getFieldData(bytes) { getFieldData(bytes) {
...@@ -121,13 +123,12 @@ class PC0Field extends MitigationField { ...@@ -121,13 +123,12 @@ class PC0Field extends MitigationField {
class PC1Field extends MitigationField { class PC1Field extends MitigationField {
/** @override */ /** @override */
getFieldData(bytes) { getFieldData(bytes) {
if (bytes.length == 4) { if (bytes.length == 8) {
return null;
} else if (bytes.length == 8) {
return bytes; return bytes;
} else if (bytes.length == 16) { } else if (bytes.length == 16) {
return bytes.slice(0, 8); return bytes.slice(0, 8);
} }
return null;
} }
} }
...@@ -137,13 +138,12 @@ class PC1Field extends MitigationField { ...@@ -137,13 +138,12 @@ class PC1Field extends MitigationField {
class PC2Field extends MitigationField { class PC2Field extends MitigationField {
/** @override */ /** @override */
getFieldData(bytes) { getFieldData(bytes) {
if (bytes.length == 4) { if (bytes.length == 8) {
return null;
} else if (bytes.length == 8) {
return null; return null;
} else if (bytes.length == 16) { } else if (bytes.length == 16) {
return bytes.slice(8, 16); return bytes.slice(8, 16);
} }
return null;
} }
} }
...@@ -267,8 +267,8 @@ class DecodeMitigations { ...@@ -267,8 +267,8 @@ class DecodeMitigations {
/** /**
* Return a list of platform mitigation which are set in |mitigations|. * Return a list of platform mitigation which are set in |mitigations|.
* Mitigations will be in the same order as Winbase.h. * Mitigations will be in the same order as Winbase.h.
* @param {string} str Hex encoded process mitigation flags. * @param {string} mitigations Hex encoded process mitigation flags.
* @return {Array<string>} Matched mitigation values. * @return {!Array<string>} Matched mitigation values.
*/ */
enabledMitigations(mitigations) { enabledMitigations(mitigations) {
const bytes = this.parseHexString(mitigations); const bytes = this.parseHexString(mitigations);
...@@ -341,6 +341,7 @@ function makeExpandableEntry(mainEntry, expandable) { ...@@ -341,6 +341,7 @@ function makeExpandableEntry(mainEntry, expandable) {
* mitigations. * mitigations.
* @param {string} platformMitigations * @param {string} platformMitigations
* @return {Node} * @return {Node}
* @suppress {globalThis}
*/ */
function makeMitigationEntry(platformMitigations) { function makeMitigationEntry(platformMitigations) {
const expander = { const expander = {
...@@ -422,5 +423,5 @@ function onGetSandboxDiagnostics(results) { ...@@ -422,5 +423,5 @@ function onGetSandboxDiagnostics(results) {
} }
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
cr.sendWithPromise('requestSandboxDiagnostics').then(onGetSandboxDiagnostics); sendWithPromise('requestSandboxDiagnostics').then(onGetSandboxDiagnostics);
}); });
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