Skip to content

Truly independent web browser

LibWeb: Keep the canvas of an iframe in another process transparent

Andreas Kling7ec85d13a2f9
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 4ef2bfaf908..3f7ff21354c 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -6838,7 +6838,9 @@ bool LocalNavigable::commit_frame(PaintConfig paint_config)
// Hit testing can publish a display list before the next frame. Give both paths the same canvas fill so that
// switching between them does not force another recording. Screenshots can supply their own fill rectangle.
- if (is_local_root() && !paint_config.canvas_fill_rect.has_value())
+ // NB: Only the top-level traversable fills its canvas. A local root under a remote parent is an iframe in another
+ // process, and its canvas stays transparent like that of a same-process iframe.
+ if (is_top_level_traversable() && !paint_config.canvas_fill_rect.has_value())
paint_config.canvas_fill_rect = Gfx::IntRect { {}, page().css_to_device_rect(viewport_rect()).size().to_type<int>() };
// A frame is left to the next rendering update while the compositor cannot be reached.
diff --git a/Tests/LibWeb/Ref/input/isolated-iframe-has-a-transparent-canvas.html b/Tests/LibWeb/Ref/input/isolated-iframe-has-a-transparent-canvas.html
new file mode 100644
index 00000000000..05a5309081a
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/isolated-iframe-has-a-transparent-canvas.html
@@ -0,0 +1,49 @@
+<!doctype html>
+<html class="reftest-wait">
+ <link rel="match" href="../expected/isolated-iframe-is-composited-into-its-parent-ref.html" />
+ <style>
+ body {
+ margin: 0;
+ }
+ iframe {
+ background: green;
+ display: block;
+ width: 100px;
+ height: 100px;
+ border: 0;
+ }
+ </style>
+ <script>
+ // The frame's document is cross-site, so another process hosts it. Its document has no background, and its used
+ // color scheme matches the frame's, so its canvas is transparent and the frame's own green background shows
+ // through. The frame reports once its rendering update has finished and the compositor has received its frame.
+ const request = new XMLHttpRequest();
+ const path = `/echo/isolated-iframe-transparent-canvas-${crypto.randomUUID()}`;
+ request.open("POST", "/echo", false);
+ request.setRequestHeader("Content-Type", "application/json");
+ request.send(
+ JSON.stringify({
+ method: "GET",
+ path,
+ status: 200,
+ headers: { "Content-Type": "text/html" },
+ body: `<!DOCTYPE html><style>html, body { margin: 0; height: 100%; }</style>
+ <script>requestAnimationFrame(() => requestAnimationFrame(async () => {
+ const nextTask = () => new Promise(resolve => {
+ const channel = new MessageChannel();
+ channel.port1.onmessage = resolve;
+ channel.port2.postMessage(null);
+ });
+ do await nextTask();
+ while (internals.frameSchedulerState() !== "idle");
+ internals.synchronizeCompositor();
+ parent.postMessage("painted", "*");
+ }));<\/script>`,
+ })
+ );
+
+ const host = `oop-iframe-transparent-canvas-${crypto.randomUUID()}.localhost`;
+ window.addEventListener("message", () => document.documentElement.classList.remove("reftest-wait"));
+ document.write(`<iframe src="http://${host}:${location.port}${path}"></iframe>`);
+ </script>
+</html>
diff --git a/Tests/LibWeb/Ref/input/isolated-iframe-has-a-transparent-canvas.html.headers b/Tests/LibWeb/Ref/input/isolated-iframe-has-a-transparent-canvas.html.headers
new file mode 100644
index 00000000000..156209f9c81
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/isolated-iframe-has-a-transparent-canvas.html.headers
@@ -0,0 +1 @@
+Content-Type: text/html