Truly independent web browser
WebContent: Don’t build the accessibility tree on a remote traversable
sideshowbarker75a991536f2c
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex 7dcb3492d1b..023e97e19fc 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -1736,6 +1736,12 @@ void Internals::set_accessibility_focus_target(DOM::Element& element)element.document().set_accessibility_focus_target(&element);}+// Makes the page report accessibility tree changes as it does once an assistive technology has asked for the tree.+void Internals::set_accessibility_interested()+{+ page().set_accessibility_interested(true);+}+u16 Internals::get_echo_server_port(){return s_echo_server_port;diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex bb9915d521b..9034c9844e5 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -201,6 +201,7 @@ public:Utf16String get_computed_label(DOM::Element& element);Utf16String get_computed_aria_level(DOM::Element& element);void set_accessibility_focus_target(DOM::Element& element);+ void set_accessibility_interested();static u16 get_echo_server_port();static void set_echo_server_port(u16 port);diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex 463a57d9ff8..ba978ce4922 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -204,6 +204,7 @@ interface Internals {DOMString getComputedLabel(Element element);DOMString getComputedAriaLevel(Element element);undefined setAccessibilityFocusTarget(Element element);+ undefined setAccessibilityInterested();unsigned short getEchoServerPort();unsigned short getHttpsEchoServerPort();diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cppindex f8421655e16..5e9c485bb4d 100644--- a/Services/WebContent/ConnectionFromClient.cpp+++ b/Services/WebContent/ConnectionFromClient.cpp@@ -1882,7 +1882,7 @@ void ConnectionFromClient::clear_grid_highlight(Web::PageId page_id, Web::Uniquevoid ConnectionFromClient::inspect_accessibility_tree(Web::PageId page_id){- if (auto page = this->page(page_id); page.has_value()) {+ if (auto page = this->page(page_id); page.has_value() && page->page().has_local_traversable()) {if (auto doc = page->page().local_traversable()->active_document())async_did_inspect_accessibility_tree(page_id, doc->dump_accessibility_tree_as_json().to_utf8());}@@ -1896,6 +1896,10 @@ void ConnectionFromClient::request_accessibility_tree(Web::PageId page_id)// path, so they pay for neither.if (auto page = this->page(page_id); page.has_value()) {page->page().set_accessibility_interested(true);+ // A request can arrive after the tab's document moved to another process, which leaves this page's traversable+ // remote, with no document of its own to report.+ if (!page->page().has_local_traversable())+ return;if (auto doc = page->page().local_traversable()->active_document()) {doc->update_layout(Web::DOM::UpdateLayoutReason::InspectAccessibilityTree);async_did_get_accessibility_tree(page_id, doc->build_accessibility_node_data());diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cppindex b2c1d5cec0e..d38603564e5 100644--- a/Services/WebContent/PageClient.cpp+++ b/Services/WebContent/PageClient.cpp@@ -1156,6 +1156,10 @@ void PageClient::schedule_accessibility_tree_update()m_accessibility_update_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(200), [this] {if (m_is_closed)return;+ // The tab's document can move to another process before the timer fires, which leaves this page's+ // traversable remote, with no document of its own to report.+ if (!page().has_local_traversable())+ return;if (auto doc = page().local_traversable()->active_document()) {doc->update_layout(Web::DOM::UpdateLayoutReason::InspectAccessibilityTree);client().async_did_get_accessibility_tree(m_id, doc->build_accessibility_node_data());diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/accessibility-tree-update-in-isolated-iframe.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/accessibility-tree-update-in-isolated-iframe.txtnew file mode 100644index 00000000000..3ab8c0bbce6--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/accessibility-tree-update-in-isolated-iframe.txt@@ -0,0 +1,4 @@+child loaded: true+child is remote: true+child mutated: true+child still answers: truediff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/accessibility-tree-update-in-isolated-iframe.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/accessibility-tree-update-in-isolated-iframe.htmlnew file mode 100644index 00000000000..72f20f3af73--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/accessibility-tree-update-in-isolated-iframe.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script>+ // Once an assistive technology has asked for the accessibility tree, a DOM change schedules an update of the tree+ // 200ms out. In an isolated iframe's process, the page's top-level traversable is remote: The update has no+ // document of its own to report, and the iframe's process keeps running.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const childUrl = new URL(+ await httpServer.createEcho("GET", "/oop-accessibility-tree-update-child", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html>child<script>+ addEventListener("message", event => {+ if (event.data === "mutate") {+ internals.setAccessibilityInterested();+ document.body.append(document.createElement("p"));+ }+ parent.postMessage(event.data + "-done", "*");+ });+ addEventListener("load", () => parent.postMessage("loaded", "*"));+ <\/script>`,+ })+ );+ childUrl.hostname = uniqueLocalhostHostname("oop-accessibility-tree-update");++ const received = [];+ window.addEventListener("message", event => received.push(event.data));+ const waitFor = what => waitForCondition(() => received.includes(what));++ const iframe = document.createElement("iframe");+ iframe.src = childUrl;+ document.body.appendChild(iframe);+ println(`child loaded: ${await waitFor("loaded")}`);+ println(`child is remote: ${await waitForCondition(() => remoteFrameCount() === 1)}`);++ frames[0].postMessage("mutate", "*");+ println(`child mutated: ${await waitFor("mutate-done")}`);++ // Outlast the update's 200ms delay, then check that the child's process still answers.+ await timeout(500);+ frames[0].postMessage("ping", "*");+ println(`child still answers: ${await waitFor("ping-done")}`);+ });+</script>