ladybird/Tests/LibWeb/test-web/TestWebView.cpp
Aliaksandr Kalenik 626dc6ff3f LibWebView+WebContent: Make page IDs browser-assigned
Page IDs were allocated independently by each WebContent PageHost,
starting at zero for every process. That made them unsuitable as a
global identity for page-presenting compositor contexts, because the
same numeric page ID could exist in multiple WebContent processes.

Move page ID allocation to WebView::Application and initialize each
WebContent process with its browser-assigned first page ID over IPC.
New view requests now get a browser-assigned page ID before
WebContent creates the PageClient, and PageHost no longer owns a
local page counter.

This gives page-presenting compositor contexts a stable global page
identity, which will allow their context IDs to be derived from page
IDs and simplify compositor context allocation in a follow-up.
2026-05-30 17:30:00 +01:00

70 lines
2 KiB
C++

/*
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "TestWebView.h"
#include <LibCore/AnonymousBuffer.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ShareableBitmap.h>
namespace TestWeb {
NonnullOwnPtr<TestWebView> TestWebView::create(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size)
{
auto view = adopt_own(*new TestWebView(move(theme), window_size));
view->initialize_client(CreateNewClient::Yes);
return view;
}
TestWebView::TestWebView(Core::AnonymousBuffer theme, Web::DevicePixelSize viewport_size)
: WebView::HeadlessWebView(move(theme), viewport_size)
, m_test_promise(TestPromise::construct())
{
}
void TestWebView::clear_content_blockers()
{
client().async_set_content_blockers(m_client_state.page_index, MUST(Core::AnonymousBuffer::create_with_size(0)));
}
pid_t TestWebView::web_content_pid() const
{
return client().pid();
}
NonnullRefPtr<Core::Promise<RefPtr<Gfx::Bitmap const>>> TestWebView::take_screenshot()
{
VERIFY(!m_pending_screenshot);
m_pending_screenshot = Core::Promise<RefPtr<Gfx::Bitmap const>>::construct();
client().async_take_document_screenshot(page_id());
return *m_pending_screenshot;
}
void TestWebView::did_receive_screenshot(Badge<WebView::WebContentClient>, Gfx::ShareableBitmap const& screenshot)
{
// NOTE: The screenshot may arrive after a timeout already completed the test and cleared m_pending_screenshot.
if (!m_pending_screenshot)
return;
auto pending_screenshot = move(m_pending_screenshot);
pending_screenshot->resolve(screenshot.bitmap());
}
void TestWebView::on_test_complete(TestCompletion completion)
{
m_pending_screenshot.clear();
m_pending_dialog = Web::Page::PendingDialog::None;
m_pending_prompt_text.clear();
m_is_fullscreen = Web::ViewportIsFullscreen::No;
client().async_set_viewport(m_client_state.page_index, viewport_size(), 1.0, Web::ViewportIsFullscreen::No);
m_test_promise->resolve(move(completion));
}
}