summaryrefslogtreecommitdiff
path: root/Userland/Services/WebContent
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-09-21 19:33:57 +0100
committerLinus Groh <mail@linusgroh.de>2022-09-21 20:42:36 +0100
commit6b2a916069a0df08856c6d9fa66c6bf5d0244df0 (patch)
tree0785afae53930cffeb33fd76b361eede441d5653 /Userland/Services/WebContent
parent69dd158f91480551a4b7e1205c3fab77c507fc1a (diff)
downloadserenity-6b2a916069a0df08856c6d9fa66c6bf5d0244df0.zip
LibWeb+WebContent: Move Serenity EventLoop and Font plugins into LibWeb
These are exactly what's wanted by headless-browser too, so this saves us some duplication. LibWeb already links LibCore so it should not cause any issues for Ladybird.
Diffstat (limited to 'Userland/Services/WebContent')
-rw-r--r--Userland/Services/WebContent/CMakeLists.txt3
-rw-r--r--Userland/Services/WebContent/EventLoopPluginSerenity.cpp34
-rw-r--r--Userland/Services/WebContent/EventLoopPluginSerenity.h23
-rw-r--r--Userland/Services/WebContent/FontPluginSerenity.cpp54
-rw-r--r--Userland/Services/WebContent/FontPluginSerenity.h24
-rw-r--r--Userland/Services/WebContent/TimerSerenity.cpp84
-rw-r--r--Userland/Services/WebContent/TimerSerenity.h42
-rw-r--r--Userland/Services/WebContent/main.cpp8
8 files changed, 4 insertions, 268 deletions
diff --git a/Userland/Services/WebContent/CMakeLists.txt b/Userland/Services/WebContent/CMakeLists.txt
index ca7b7395a8..e4643e70c4 100644
--- a/Userland/Services/WebContent/CMakeLists.txt
+++ b/Userland/Services/WebContent/CMakeLists.txt
@@ -10,11 +10,8 @@ compile_ipc(WebContentClient.ipc WebContentClientEndpoint.h)
set(SOURCES
ConnectionFromClient.cpp
ConsoleGlobalObject.cpp
- EventLoopPluginSerenity.cpp
- FontPluginSerenity.cpp
ImageCodecPluginSerenity.cpp
PageHost.cpp
- TimerSerenity.cpp
WebContentClientEndpoint.h
WebContentConsoleClient.cpp
WebContentServerEndpoint.h
diff --git a/Userland/Services/WebContent/EventLoopPluginSerenity.cpp b/Userland/Services/WebContent/EventLoopPluginSerenity.cpp
deleted file mode 100644
index 15a6c17dd1..0000000000
--- a/Userland/Services/WebContent/EventLoopPluginSerenity.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "EventLoopPluginSerenity.h"
-#include "TimerSerenity.h"
-#include <AK/Function.h>
-#include <AK/NonnullRefPtr.h>
-#include <LibCore/EventLoop.h>
-
-namespace WebContent {
-
-EventLoopPluginSerenity::EventLoopPluginSerenity() = default;
-EventLoopPluginSerenity::~EventLoopPluginSerenity() = default;
-
-void EventLoopPluginSerenity::spin_until(Function<bool()> goal_condition)
-{
- Core::EventLoop::current().spin_until(move(goal_condition));
-}
-
-void EventLoopPluginSerenity::deferred_invoke(Function<void()> function)
-{
- VERIFY(function);
- Core::deferred_invoke(move(function));
-}
-
-NonnullRefPtr<Web::Platform::Timer> EventLoopPluginSerenity::create_timer()
-{
- return TimerSerenity::create();
-}
-
-}
diff --git a/Userland/Services/WebContent/EventLoopPluginSerenity.h b/Userland/Services/WebContent/EventLoopPluginSerenity.h
deleted file mode 100644
index 0493ac7ab1..0000000000
--- a/Userland/Services/WebContent/EventLoopPluginSerenity.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWeb/Platform/EventLoopPlugin.h>
-
-namespace WebContent {
-
-class EventLoopPluginSerenity final : public Web::Platform::EventLoopPlugin {
-public:
- EventLoopPluginSerenity();
- virtual ~EventLoopPluginSerenity() override;
-
- virtual void spin_until(Function<bool()> goal_condition) override;
- virtual void deferred_invoke(Function<void()>) override;
- virtual NonnullRefPtr<Web::Platform::Timer> create_timer() override;
-};
-
-}
diff --git a/Userland/Services/WebContent/FontPluginSerenity.cpp b/Userland/Services/WebContent/FontPluginSerenity.cpp
deleted file mode 100644
index b9377b8843..0000000000
--- a/Userland/Services/WebContent/FontPluginSerenity.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "FontPluginSerenity.h"
-#include <AK/String.h>
-#include <LibGfx/Font/FontDatabase.h>
-
-namespace WebContent {
-
-FontPluginSerenity::FontPluginSerenity()
-{
-}
-
-FontPluginSerenity::~FontPluginSerenity() = default;
-
-Gfx::Font& FontPluginSerenity::default_font()
-{
- return Gfx::FontDatabase::default_font();
-}
-
-Gfx::Font& FontPluginSerenity::default_fixed_width_font()
-{
- return Gfx::FontDatabase::default_fixed_width_font();
-}
-
-String FontPluginSerenity::generic_font_name(Web::Platform::GenericFont generic_font)
-{
- // FIXME: Replace hard-coded font names with a relevant call to FontDatabase.
- // Currently, we cannot request the default font's name, or request it at a specific size and weight.
- // So, hard-coded font names it is.
- switch (generic_font) {
- case Web::Platform::GenericFont::SansSerif:
- case Web::Platform::GenericFont::UiSansSerif:
- case Web::Platform::GenericFont::Cursive:
- case Web::Platform::GenericFont::UiRounded:
- return "Katica";
- case Web::Platform::GenericFont::Monospace:
- case Web::Platform::GenericFont::UiMonospace:
- return "Csilla";
- case Web::Platform::GenericFont::Serif:
- case Web::Platform::GenericFont::UiSerif:
- return "Roman";
- case Web::Platform::GenericFont::Fantasy:
- return "Comic Book";
- case Web::Platform::GenericFont::__Count:
- VERIFY_NOT_REACHED();
- }
- VERIFY_NOT_REACHED();
-}
-
-}
diff --git a/Userland/Services/WebContent/FontPluginSerenity.h b/Userland/Services/WebContent/FontPluginSerenity.h
deleted file mode 100644
index 371b0833a6..0000000000
--- a/Userland/Services/WebContent/FontPluginSerenity.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Vector.h>
-#include <LibWeb/Platform/FontPlugin.h>
-
-namespace WebContent {
-
-class FontPluginSerenity final : public Web::Platform::FontPlugin {
-public:
- FontPluginSerenity();
- virtual ~FontPluginSerenity();
-
- virtual Gfx::Font& default_font() override;
- virtual Gfx::Font& default_fixed_width_font() override;
- virtual String generic_font_name(Web::Platform::GenericFont) override;
-};
-
-}
diff --git a/Userland/Services/WebContent/TimerSerenity.cpp b/Userland/Services/WebContent/TimerSerenity.cpp
deleted file mode 100644
index a702ba2eca..0000000000
--- a/Userland/Services/WebContent/TimerSerenity.cpp
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "TimerSerenity.h"
-#include <AK/NonnullRefPtr.h>
-#include <LibCore/Timer.h>
-
-namespace WebContent {
-
-NonnullRefPtr<TimerSerenity> TimerSerenity::create()
-{
- return adopt_ref(*new TimerSerenity);
-}
-
-TimerSerenity::TimerSerenity()
- : m_timer(Core::Timer::construct())
-{
- m_timer->on_timeout = [this] {
- if (on_timeout)
- on_timeout();
- };
-}
-
-TimerSerenity::~TimerSerenity() = default;
-
-void TimerSerenity::start()
-{
- m_timer->start();
-}
-
-void TimerSerenity::start(int interval_ms)
-{
- m_timer->start(interval_ms);
-}
-
-void TimerSerenity::restart()
-{
- m_timer->restart();
-}
-
-void TimerSerenity::restart(int interval_ms)
-{
- m_timer->restart(interval_ms);
-}
-
-void TimerSerenity::stop()
-{
- m_timer->stop();
-}
-
-void TimerSerenity::set_active(bool active)
-{
- m_timer->set_active(active);
-}
-
-bool TimerSerenity::is_active() const
-{
- return m_timer->is_active();
-}
-
-int TimerSerenity::interval() const
-{
- return m_timer->interval();
-}
-
-void TimerSerenity::set_interval(int interval_ms)
-{
- m_timer->set_interval(interval_ms);
-}
-
-bool TimerSerenity::is_single_shot() const
-{
- return m_timer->is_single_shot();
-}
-
-void TimerSerenity::set_single_shot(bool single_shot)
-{
- m_timer->set_single_shot(single_shot);
-}
-
-}
diff --git a/Userland/Services/WebContent/TimerSerenity.h b/Userland/Services/WebContent/TimerSerenity.h
deleted file mode 100644
index d0f9200839..0000000000
--- a/Userland/Services/WebContent/TimerSerenity.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/NonnullRefPtr.h>
-#include <LibCore/Forward.h>
-#include <LibWeb/Platform/Timer.h>
-
-namespace WebContent {
-
-class TimerSerenity final : public Web::Platform::Timer {
-public:
- static NonnullRefPtr<TimerSerenity> create();
-
- virtual ~TimerSerenity();
-
- virtual void start() override;
- virtual void start(int interval_ms) override;
- virtual void restart() override;
- virtual void restart(int interval_ms) override;
- virtual void stop() override;
-
- virtual void set_active(bool) override;
-
- virtual bool is_active() const override;
- virtual int interval() const override;
- virtual void set_interval(int interval_ms) override;
-
- virtual bool is_single_shot() const override;
- virtual void set_single_shot(bool) override;
-
-private:
- TimerSerenity();
-
- NonnullRefPtr<Core::Timer> m_timer;
-};
-
-}
diff --git a/Userland/Services/WebContent/main.cpp b/Userland/Services/WebContent/main.cpp
index ce7c2c5266..ea5c757617 100644
--- a/Userland/Services/WebContent/main.cpp
+++ b/Userland/Services/WebContent/main.cpp
@@ -4,8 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include "EventLoopPluginSerenity.h"
-#include "FontPluginSerenity.h"
#include "ImageCodecPluginSerenity.h"
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
@@ -14,6 +12,8 @@
#include <LibMain/Main.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
+#include <LibWeb/Platform/EventLoopPluginSerenity.h>
+#include <LibWeb/Platform/FontPluginSerenity.h>
#include <LibWeb/WebSockets/WebSocket.h>
#include <LibWebView/RequestServerAdapter.h>
#include <LibWebView/WebSocketClientAdapter.h>
@@ -30,9 +30,9 @@ ErrorOr<int> serenity_main(Main::Arguments)
TRY(Core::System::unveil("/tmp/user/%uid/portal/websocket", "rw"));
TRY(Core::System::unveil(nullptr, nullptr));
- Web::Platform::EventLoopPlugin::install(*new WebContent::EventLoopPluginSerenity);
+ Web::Platform::EventLoopPlugin::install(*new Web::Platform::EventLoopPluginSerenity);
Web::Platform::ImageCodecPlugin::install(*new WebContent::ImageCodecPluginSerenity);
- Web::Platform::FontPlugin::install(*new WebContent::FontPluginSerenity);
+ Web::Platform::FontPlugin::install(*new Web::Platform::FontPluginSerenity);
Web::WebSockets::WebSocketClientManager::initialize(TRY(WebView::WebSocketClientManagerAdapter::try_create()));
Web::ResourceLoader::initialize(TRY(WebView::RequestServerAdapter::try_create()));