Bug 1734540: Use document.body.innerHTML instead of document.write in chrome-document-builder.html. r=eeejay

This is a follow-up to my original patch.
It turns out that there is an assertion preventing use of document.write in privileged contexts which my original patch triggered.
Instead, set document.body.innerHTML.

Differential Revision: https://phabricator.services.mozilla.com/D128159
This commit is contained in:
James Teh 2021-10-12 23:43:06 +00:00
Родитель 601f48038d
Коммит 8fefbe08c1
2 изменённых файлов: 24 добавлений и 23 удалений

Просмотреть файл

@ -1,5 +1,8 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Accessibility Test</title>
<script>
/*
* This file is used to load an HTML snippet in the parent process via a
@ -10,11 +13,10 @@
window.addEventListener("DOMContentLoaded", function() {
const params = new URLSearchParams(document.location.search);
const html = params.get("html");
document.open();
// eslint-disable-next-line no-unsanitized/method
document.write(html);
document.close();
// eslint-disable-next-line no-unsanitized/property
document.body.innerHTML = html;
});
</script>
</head>
<body></body>
</html>

Просмотреть файл

@ -413,23 +413,16 @@ function snippetToURL(doc, options = {}) {
doc = wrapWithIFrame(doc, options);
}
const fullDoc = `<html>
const encodedDoc = encodeURIComponent(
`<html>
<head>
<meta charset="utf-8"/>
<title>Accessibility Test</title>
</head>
<body ${attrsToString(attrs)}>${doc}</body>
</html>`;
</html>`
);
if (options.chrome) {
// Load with a chrome:// URL so this loads as a chrome document in the
// parent process.
const url = new URL(`${CURRENT_DIR}chrome-document-builder.html`);
url.searchParams.append("html", fullDoc);
return url.href;
}
const encodedDoc = encodeURIComponent(fullDoc);
return `data:text/html;charset=utf-8,${encodedDoc}`;
}
@ -438,11 +431,17 @@ function accessibleTask(doc, task, options = {}) {
gIsRemoteIframe = options.remoteIframe;
gIsIframe = options.iframe || gIsRemoteIframe;
let url;
if (options.chrome && doc.endsWith("html")) {
if (options.chrome) {
// Load with a chrome:// URL so this loads as a chrome document in the
// parent process.
if (doc.endsWith("html")) {
url = `${CURRENT_DIR}${doc}`;
} else if (!options.chrome && doc.endsWith("html") && !gIsIframe) {
} else {
const urlObj = new URL(`${CURRENT_DIR}chrome-document-builder.html`);
urlObj.searchParams.append("html", doc);
url = urlObj.href;
}
} else if (doc.endsWith("html") && !gIsIframe) {
url = `${CURRENT_CONTENT_DIR}${doc}`;
} else {
url = snippetToURL(doc, options);