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
<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_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 expr="is_win">
<include name="IDR_SANDBOX_INTERNALS_HTML" file="resources\sandbox_internals\sandbox_internals.html" preprocess="true" type="BINDATA" />
......
......@@ -5,6 +5,7 @@
import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
uses_js_modules = true
if (is_win) {
deps = [ ":sandbox_internals_win" ]
}
......@@ -17,9 +18,8 @@ js_library("sandbox_internals") {
# Android & Linux both need _externs for type checks as they share a js file.
deps = [
":sandbox_android_externs",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:load_time_data",
"//ui/webui/resources/js:util",
"//ui/webui/resources/js:load_time_data.m",
"//ui/webui/resources/js:util.m",
]
}
......@@ -28,7 +28,8 @@ js_library("sandbox_android_externs") {
js_library("sandbox_internals_win") {
deps = [
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:util",
"//ui/webui/resources/js:assert.m",
"//ui/webui/resources/js:cr.m",
"//ui/webui/resources/js:util.m",
]
}
......@@ -2,6 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// 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.
* @param {!function(!AndroidSandboxStatus)=} callback
......
......@@ -40,17 +40,7 @@
}
</if>
</style>
<script src="chrome://resources/js/cr.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>
<script type="module" src="sandbox_internals.js"></script>
</head>
<body>
<h1>Sandbox Status</h1>
......
......@@ -2,19 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @typedef {{
* seccompStatus: number,
* pid: string,
* uid: string,
* secontext: string,
* procStatus: string,
* androidBuildId: string
* }}
*/
let AndroidSandboxStatus;
import {$} from 'chrome://resources/js/util.m.js';
// <if expr="is_linux">
import './strings.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
// </if>
(function() {
/**
* CSS classes for different statuses.
* @enum {string}
......@@ -72,6 +66,7 @@ function setEvaluation(result) {
$('evaluation').innerText = message;
}
// <if expr="is_android">
/**
* Main page handler for Android.
*/
......@@ -135,7 +130,9 @@ function androidHandler() {
setEvaluation(isIsolated && isTsync && isChromeSeccomp);
});
}
// </if>
// <if expr="is_linux">
/**
* Main page handler for desktop Linux.
*/
......@@ -178,12 +175,13 @@ function linuxHandler() {
setEvaluation(loadTimeData.getBoolean('sandboxGood'));
}
// </if>
document.addEventListener('DOMContentLoaded', () => {
if (cr.isAndroid) {
// <if expr="is_android">
androidHandler();
} else {
// </if>
// <if expr="is_linux">
linuxHandler();
}
// </if>
});
})();
......@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// 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 {{
* processId: number,
......@@ -44,12 +48,6 @@ let SandboxDiagnostics;
/**
* Represents a mitigation field from the PROCESS_CREATION_MITITAGION_POLICY*
* series in Winbase.h.
* @typedef {{
* mitigation: !string,
* value: !number,
* mask: !number,
* offset: !number
* }}
*/
class MitigationField {
/**
......@@ -60,15 +58,19 @@ class MitigationField {
* @param {number} offset within PC section.
*/
constructor(mitigation, value, mask, offset) {
/** @type {string} */
this.mitigation = mitigation;
/** @type {number} */
this.value = value;
/** @type {number} */
this.mask = mask;
/** @type {number} */
this.offset = offset;
}
/**
* 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.
*/
getFieldData(bytes) {
......@@ -78,7 +80,7 @@ class MitigationField {
/**
* Are all the bits of this field set in the mitigations represented by
* |bytes|.
* @param {Uint8Array} platform mitigations.
* @param {Uint8Array} bytes platform mitigations.
* @return {boolean}
*/
isFieldSet(bytes) {
......@@ -100,7 +102,7 @@ class MitigationField {
*/
class PC0Field extends MitigationField {
/**
* @param {Uint8Array} platform mitigations data.
* @param {Uint8Array} bytes platform mitigations data.
* @return {Uint8Array} chunk containing this field or null.
*/
getFieldData(bytes) {
......@@ -121,13 +123,12 @@ class PC0Field extends MitigationField {
class PC1Field extends MitigationField {
/** @override */
getFieldData(bytes) {
if (bytes.length == 4) {
return null;
} else if (bytes.length == 8) {
if (bytes.length == 8) {
return bytes;
} else if (bytes.length == 16) {
return bytes.slice(0, 8);
}
return null;
}
}
......@@ -137,13 +138,12 @@ class PC1Field extends MitigationField {
class PC2Field extends MitigationField {
/** @override */
getFieldData(bytes) {
if (bytes.length == 4) {
return null;
} else if (bytes.length == 8) {
if (bytes.length == 8) {
return null;
} else if (bytes.length == 16) {
return bytes.slice(8, 16);
}
return null;
}
}
......@@ -267,8 +267,8 @@ class DecodeMitigations {
/**
* Return a list of platform mitigation which are set in |mitigations|.
* Mitigations will be in the same order as Winbase.h.
* @param {string} str Hex encoded process mitigation flags.
* @return {Array<string>} Matched mitigation values.
* @param {string} mitigations Hex encoded process mitigation flags.
* @return {!Array<string>} Matched mitigation values.
*/
enabledMitigations(mitigations) {
const bytes = this.parseHexString(mitigations);
......@@ -341,6 +341,7 @@ function makeExpandableEntry(mainEntry, expandable) {
* mitigations.
* @param {string} platformMitigations
* @return {Node}
* @suppress {globalThis}
*/
function makeMitigationEntry(platformMitigations) {
const expander = {
......@@ -422,5 +423,5 @@ function onGetSandboxDiagnostics(results) {
}
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