Skip to content

Truly independent web browser

Compositor: Close a connection that nests a context it must not nest

Aliaksandr Kalenikbe4890e249e9
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index f933dc02bc7..72f518dfe47 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -318,6 +318,14 @@ void CompositorState::destroy_context(Web::CompositorContextId context_id)
update_unpainted_video_update_scheduling();
}
+// What a client shows is rooted at the context presented to it, and no context is nested in itself.
+bool CompositorState::context_can_be_nested_in(Web::CompositorContextId context_id, Web::CompositorContextId parent_context_id) const
+{
+ auto const* context = presented_context_if_present(context_id);
+ VERIFY(context);
+ return !context->presenter.presents_to_client() && parent_context_id != context_id;
+}
+
void CompositorState::set_parent_context(Web::CompositorContextId context_id, Optional<Web::CompositorContextId> parent_context_id)
{
auto* context = presented_context_if_present(context_id);
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 04077c7f800..0f4ab5db429 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -111,6 +111,7 @@ public:
void create_context(Web::CompositorContextId, Optional<u64> page_id, CompositorStateWebContentClient&);
void destroy_context(Web::CompositorContextId);
+ bool context_can_be_nested_in(Web::CompositorContextId, Web::CompositorContextId parent_context_id) const;
void set_parent_context(Web::CompositorContextId, Optional<Web::CompositorContextId> parent_context_id);
void stop_presenting_to_client(Web::CompositorContextId);
// Answers false, changing nothing, for async scrolling metadata or a scroll state that do not decode.
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index d75bd0d5775..b6ba0688230 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -260,6 +260,10 @@ void ConnectionFromWebContent::set_parent_context(Web::CompositorContextId conte
{
if (!context_is_owned_by_this_connection(context_id))
return;
+ if (parent_context_id.has_value() && !m_compositor_state->context_can_be_nested_in(context_id, *parent_context_id)) {
+ did_misbehave("WebContent nested a compositor context that cannot be nested");
+ return;
+ }
m_compositor_state->set_parent_context(context_id, parent_context_id);
}