2023-11-08 13:47:41 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-12-04 03:40:33 -05:00
|
|
|
#include <LibJS/Runtime/VM.h>
|
2023-12-04 03:57:13 -05:00
|
|
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
2023-11-08 13:47:41 -05:00
|
|
|
#include <WebWorker/ConnectionFromClient.h>
|
|
|
|
#include <WebWorker/PageHost.h>
|
|
|
|
|
|
|
|
namespace WebWorker {
|
|
|
|
|
2024-04-06 13:16:18 -04:00
|
|
|
JS_DEFINE_ALLOCATOR(PageHost);
|
|
|
|
|
2023-12-04 03:40:33 -05:00
|
|
|
JS::NonnullGCPtr<PageHost> PageHost::create(JS::VM& vm, ConnectionFromClient& client)
|
|
|
|
{
|
|
|
|
return vm.heap().allocate_without_realm<PageHost>(client);
|
|
|
|
}
|
|
|
|
|
2023-11-08 13:47:41 -05:00
|
|
|
PageHost::~PageHost() = default;
|
|
|
|
|
|
|
|
Web::Page& PageHost::page()
|
|
|
|
{
|
|
|
|
return *m_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
Web::Page const& PageHost::page() const
|
|
|
|
{
|
|
|
|
return *m_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gfx::Palette PageHost::palette() const
|
|
|
|
{
|
|
|
|
return Gfx::Palette(*m_palette_impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageHost::setup_palette()
|
|
|
|
{
|
|
|
|
// FIXME: We don't actually need a palette :thonk:
|
|
|
|
auto buffer_or_error = Core::AnonymousBuffer::create_with_size(sizeof(Gfx::SystemTheme));
|
|
|
|
VERIFY(!buffer_or_error.is_error());
|
|
|
|
auto buffer = buffer_or_error.release_value();
|
|
|
|
auto* theme = buffer.data<Gfx::SystemTheme>();
|
|
|
|
theme->color[to_underlying(Gfx::ColorRole::Window)] = Color::Magenta;
|
|
|
|
theme->color[to_underlying(Gfx::ColorRole::WindowText)] = Color::Cyan;
|
|
|
|
m_palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PageHost::is_connection_open() const
|
|
|
|
{
|
|
|
|
return m_client.is_open();
|
|
|
|
}
|
|
|
|
|
|
|
|
Web::DevicePixelRect PageHost::screen_rect() const
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
double PageHost::device_pixels_per_css_pixel() const
|
|
|
|
{
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Web::CSS::PreferredColorScheme PageHost::preferred_color_scheme() const
|
|
|
|
{
|
|
|
|
return Web::CSS::PreferredColorScheme::Auto;
|
|
|
|
}
|
|
|
|
|
2023-12-06 11:49:45 -05:00
|
|
|
void PageHost::paint(Web::DevicePixelRect const&, Gfx::Bitmap&, Web::PaintOptions)
|
2023-11-08 13:47:41 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageHost::request_file(Web::FileRequest request)
|
|
|
|
{
|
|
|
|
m_client.request_file(move(request));
|
|
|
|
}
|
|
|
|
|
|
|
|
PageHost::PageHost(ConnectionFromClient& client)
|
|
|
|
: m_client(client)
|
2023-12-04 03:57:13 -05:00
|
|
|
, m_page(Web::Page::create(Web::Bindings::main_thread_vm(), *this))
|
2023-11-08 13:47:41 -05:00
|
|
|
{
|
|
|
|
setup_palette();
|
|
|
|
}
|
|
|
|
|
2023-12-04 03:57:13 -05:00
|
|
|
void PageHost::visit_edges(JS::Cell::Visitor& visitor)
|
|
|
|
{
|
|
|
|
Base::visit_edges(visitor);
|
|
|
|
visitor.visit(m_page);
|
|
|
|
}
|
|
|
|
|
2023-11-08 13:47:41 -05:00
|
|
|
}
|