Skip to content

Commit

Permalink
[Fixit] Clean up redundant executor HTML files. (#36346)
Browse files Browse the repository at this point in the history
Now that we have /common/dispatcher/remote-executor.html, these are no
longer needed. There remain a fair number of custom executors, but those
all perform some additional work compared to the common executor.

Also extract a helper to compute the URL of the common executor and use
it instead of manually concatenating URLs in most places.

Bug: chromium:1273818
Change-Id: I0c9211b9775f280dbf3ab7ed1f6c5dd80bef6229
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3937933
Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org>
Auto-Submit: Titouan Rigoudy <titouan@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Titouan Rigoudy <titouan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1056318}

Co-authored-by: Titouan Rigoudy <titouan@chromium.org>
  • Loading branch information
2 people authored and pull[bot] committed Aug 2, 2023
1 parent 3c90a1f commit c62beb0
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 52 deletions.
20 changes: 20 additions & 0 deletions common/dispatcher/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ const cacheableShowRequestHeaders = function(origin, uuid) {
// This script requires
// - `/common/utils.js` for `token()`.

// Returns the URL of a document that can be used as a `RemoteContext`.
//
// `uuid` should be a UUID uniquely identifying the given remote context.
// `options` has the following shape:
//
// {
// host: (optional) Sets the returned URL's `host` property. Useful for
// cross-origin executors.
// }
function remoteExecutorUrl(uuid, options) {
const url = new URL("/common/dispatcher/remote-executor.html", location);
url.searchParams.set("uuid", uuid);

if (options?.host) {
url.host = options.host;
}

return url;
}

// Represents a remote executor. For more detailed explanation see `README.md`.
class RemoteContext {
// `uuid` is a UUID string that identifies the remote context and should
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ promise_test(async test => {
const child_token = token();
const child = new RemoteContext(child_token);
const iframe = document.createElement("iframe");
iframe.src = get_host_info().REMOTE_ORIGIN +
"/content-security-policy/frame-src/support/executor.html" +
`?uuid=${child_token}`;
iframe.src = remoteExecutorUrl(child_token, {
host: get_host_info().REMOTE_HOST
});
document.body.appendChild(iframe);

// Install a promise waiting for a same-document navigation to happen in the
Expand Down
11 changes: 0 additions & 11 deletions content-security-policy/frame-src/support/executor.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
// popup using the WindowProxy of a new iframe that is still on the initial
// empty document. Check that the sandbox flags are properly inherited.

const executorUrl = uuid =>
(new URL(`./resources/executor.html?uuid=${uuid}`, window.location)).href;

// Return true if the execution context is sandboxed.
const isSandboxed = () => {
try {
Expand All @@ -26,7 +23,7 @@ promise_test(async test => {
// 1. Create a sandboxed iframe, allowing popups, same-origin and scripts.
const iframe_token = token();
const iframe_document = new RemoteContext(iframe_token);
const iframe_url = executorUrl(iframe_token);
const iframe_url = remoteExecutorUrl(iframe_token);
const iframe = document.createElement("iframe");
iframe.sandbox = "allow-same-origin allow-scripts allow-popups";
iframe.src = iframe_url;
Expand All @@ -38,12 +35,12 @@ promise_test(async test => {
// using it's WindowProxy. The popup must inherit sandbox flags.
const popup_token = token();
const popup_document = new RemoteContext(popup_token);
const popup_url = executorUrl(popup_token);
const popup_url = remoteExecutorUrl(popup_token);
iframe_document.execute_script((popup_url) => {
let iframe = document.createElement("iframe");
iframe.name = "iframe_name";
document.body.appendChild(iframe);
iframe_name.open(popup_url);
}, [popup_url]);
}, [popup_url.href]);
assert_true(await popup_document.execute_script(isSandboxed), "popup is sandboxed");
});
7 changes: 0 additions & 7 deletions html/browsers/sandboxing/resources/executor.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
// introduced the precursor to this test:
// https://codereview.chromium.org/1675473002.

function executorUrl(uuid, options) {
const url =
new URL("/common/dispatcher/remote-executor.html", window.location);
url.searchParams.set("uuid", uuid);

if (options?.host) {
url.host = options.host;
}

return url;
}

function nextMessage() {
return new Promise((resolve) => {
window.addEventListener("message", (e) => { resolve(e.data); }, {
Expand All @@ -36,7 +24,7 @@ promise_test(async (t) => {
t.add_cleanup(() => { iframeA.remove(); });

const uuidA = token();
iframeA.src = executorUrl(uuidA, { host: get_host_info().REMOTE_HOST });
iframeA.src = remoteExecutorUrl(uuidA, { host: get_host_info().REMOTE_HOST });
const ctxA = new RemoteContext(uuidA);

// Frame A embeds a cross-origin frame B, which is same-origin with the
Expand All @@ -51,7 +39,7 @@ promise_test(async (t) => {
const iframeB = document.createElement("iframe");
iframeB.src = url;
document.body.appendChild(iframeB);
}, [executorUrl(uuidB).href]);
}, [remoteExecutorUrl(uuidB).href]);

// Start listening for a message, which will come as a result of executing
// the code below in frame B.
Expand Down
8 changes: 4 additions & 4 deletions navigation-timing/nested-unload-timing.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
const popupContext = new RemoteContext(token());
const iframeContext = new RemoteContext(token());
const finalContext = new RemoteContext(token());
const popup = window.open(`resources/exec.html?uuid=${popupContext.context_id}`);
const popup = window.open(remoteExecutorUrl(popupContext.context_id));
t.add_cleanup(() => popup.close());
const registerBusyWaitUnload = duration => window.addEventListener('unload', () => {
const buffer = 3;
Expand All @@ -46,17 +46,17 @@
const unloadIframe = iframeContext.execute_script(registerBusyWaitUnload, [iframeUnloadDuration]);
const loadPopup = popupContext.execute_script(async iframeUid => {
const iframe = document.createElement('iframe');
iframe.src = `./exec.html?uuid=${iframeUid}`;
iframe.src = `/common/dispatcher/remote-executor.html?uuid=${iframeUid}`;
document.body.appendChild(iframe);
await new Promise(resolve => iframe.addEventListener('load', resolve));
}, [iframeContext.context_id]);

await Promise.all([unloadIframe, loadPopup]);
await popupContext.execute_script((uid) => location.href = `./exec.html?uuid=${uid}`, [finalContext.context_id]);
await popupContext.execute_script((uid) => location.href = `/common/dispatcher/remote-executor.html?uuid=${uid}`, [finalContext.context_id]);
const navigationTimingEntry = await finalContext.execute_script(() => performance.getEntriesByType('navigation')[0].toJSON());
const unloadDuration = navigationTimingEntry.unloadEventEnd - navigationTimingEntry.unloadEventStart;
assert_greater_than_equal(unloadDuration, mainWindowUnloadDuration);
assert_less_than(unloadDuration, mainWindowUnloadDuration + iframeUnloadDuration);
});
</script>
</body>
</body>
7 changes: 0 additions & 7 deletions navigation-timing/resources/exec.html

This file was deleted.

0 comments on commit c62beb0

Please sign in to comment.