Ladybird+LibWebView: Move CookieJar, Database, and History to LibWebView

These classes are used as-is in all chromes. Move them to LibWebView so
that non-Serenity chromes don't have to awkwardly reach into its headers
and sources.
This commit is contained in:
Timothy Flynn 2023-08-31 07:07:07 -04:00 committed by Andreas Kling
parent 7d313ff83d
commit 5c5a00dd3a
Notes: sideshowbarker 2024-07-16 23:17:55 +09:00
28 changed files with 76 additions and 107 deletions

View file

@ -9,9 +9,9 @@
#include <AK/Optional.h>
#include <AK/StringView.h>
#include <AK/URL.h>
#include <Browser/CookieJar.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWebView/CookieJar.h>
#import <System/Cocoa.h>
@ -21,7 +21,7 @@
@interface ApplicationDelegate : NSObject <NSApplicationDelegate>
- (nullable instancetype)init:(Optional<URL>)initial_url
withCookieJar:(Browser::CookieJar)cookie_jar
withCookieJar:(WebView::CookieJar)cookie_jar
webdriverContentIPCPath:(StringView)webdriver_content_ipc_path;
- (nonnull TabController*)createNewTab:(Optional<URL> const&)url
@ -35,7 +35,7 @@
- (void)removeTab:(nonnull TabController*)controller;
- (Browser::CookieJar&)cookieJar;
- (WebView::CookieJar&)cookieJar;
- (Optional<StringView> const&)webdriverContentIPCPath;
- (Web::CSS::PreferredColorScheme)preferredColorScheme;

View file

@ -22,7 +22,7 @@
URL m_new_tab_page_url;
// This will always be populated, but we cannot have a non-default constructible instance variable.
Optional<Browser::CookieJar> m_cookie_jar;
Optional<WebView::CookieJar> m_cookie_jar;
Optional<StringView> m_webdriver_content_ipc_path;
@ -46,7 +46,7 @@
@implementation ApplicationDelegate
- (instancetype)init:(Optional<URL>)initial_url
withCookieJar:(Browser::CookieJar)cookie_jar
withCookieJar:(WebView::CookieJar)cookie_jar
webdriverContentIPCPath:(StringView)webdriver_content_ipc_path
{
if (self = [super init]) {
@ -110,7 +110,7 @@
[self.managed_tabs removeObject:controller];
}
- (Browser::CookieJar&)cookieJar
- (WebView::CookieJar&)cookieJar
{
return *m_cookie_jar;
}

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Browser/History.h>
#include <LibWebView/History.h>
#import <Application/ApplicationDelegate.h>
#import <UI/LadybirdWebView.h>
@ -34,7 +34,7 @@ enum class IsHistoryNavigation {
{
DeprecatedString m_title;
Browser::History m_history;
WebView::History m_history;
IsHistoryNavigation m_is_history_navigation;
}

View file

@ -4,13 +4,13 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Browser/CookieJar.h>
#include <Browser/Database.h>
#include <Ladybird/Utilities.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibMain/Main.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/Database.h>
#import <Application/Application.h>
#import <Application/ApplicationDelegate.h>
@ -48,8 +48,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv));
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(move(sql_server_paths)));
auto database = TRY(Browser::Database::create(move(sql_client)));
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
auto database = TRY(WebView::Database::create(move(sql_client)));
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
Optional<URL> initial_url;
if (auto parsed_url = Ladybird::sanitize_url(url); parsed_url.is_valid()) {

View file

@ -85,20 +85,10 @@ elseif (APPLE)
find_library(COCOA_LIBRARY Cocoa)
endif()
set(BROWSER_SOURCE_DIR ${SERENITY_SOURCE_DIR}/Userland/Applications/Browser/)
set(SOURCES
${BROWSER_SOURCE_DIR}/CookieJar.cpp
${BROWSER_SOURCE_DIR}/Database.cpp
${BROWSER_SOURCE_DIR}/History.cpp
HelperProcess.cpp
Utilities.cpp
)
set(BROWSER_HEADERS
${BROWSER_SOURCE_DIR}/CookieJar.h
${BROWSER_SOURCE_DIR}/Database.h
${BROWSER_SOURCE_DIR}/History.h
)
set(LADYBIRD_HEADERS
HelperProcess.h
Types.h
@ -156,10 +146,6 @@ else()
add_library(ladybird STATIC ${SOURCES})
endif()
target_sources(ladybird PUBLIC FILE_SET browser TYPE HEADERS
BASE_DIRS ${SERENITY_SOURCE_DIR}/Userland/Applications
FILES ${BROWSER_HEADERS}
)
target_sources(ladybird PUBLIC FILE_SET ladybird TYPE HEADERS
BASE_DIRS ${SERENITY_SOURCE_DIR}
FILES ${LADYBIRD_HEADERS}

View file

@ -14,10 +14,10 @@
#include "StringUtils.h"
#include "WebContentView.h"
#include <AK/TypeCasts.h>
#include <Browser/CookieJar.h>
#include <Ladybird/Utilities.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWebView/CookieJar.h>
#include <QAction>
#include <QActionGroup>
#include <QClipboard>
@ -39,7 +39,7 @@ static QIcon const& app_icon()
return icon;
}
BrowserWindow::BrowserWindow(Optional<URL> const& initial_url, Browser::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking)
BrowserWindow::BrowserWindow(Optional<URL> const& initial_url, WebView::CookieJar& cookie_jar, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling, UseLagomNetworking use_lagom_networking)
: m_cookie_jar(cookie_jar)
, m_webdriver_content_ipc_path(webdriver_content_ipc_path)
, m_enable_callgrind_profiling(enable_callgrind_profiling)

View file

@ -10,6 +10,7 @@
#include "Tab.h"
#include <LibCore/Forward.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWebView/Forward.h>
#include <QIcon>
#include <QLineEdit>
#include <QMainWindow>
@ -17,10 +18,6 @@
#include <QTabWidget>
#include <QToolBar>
namespace Browser {
class CookieJar;
}
namespace Ladybird {
class WebContentView;
@ -28,7 +25,7 @@ class WebContentView;
class BrowserWindow : public QMainWindow {
Q_OBJECT
public:
explicit BrowserWindow(Optional<URL> const& initial_url, Browser::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking);
explicit BrowserWindow(Optional<URL> const& initial_url, WebView::CookieJar&, StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling, UseLagomNetworking);
WebContentView& view() const { return m_current_tab->view(); }
@ -119,7 +116,7 @@ private:
OwnPtr<QAction> m_view_source_action {};
OwnPtr<QAction> m_inspect_dom_node_action {};
Browser::CookieJar& m_cookie_jar;
WebView::CookieJar& m_cookie_jar;
StringView m_webdriver_content_ipc_path;
WebView::EnableCallgrindProfiling m_enable_callgrind_profiling;

View file

@ -11,7 +11,6 @@
#include "Settings.h"
#include "StringUtils.h"
#include "TVGIconEngine.h"
#include <Browser/History.h>
#include <LibGfx/ImageFormats/BMPWriter.h>
#include <LibGfx/Painter.h>
#include <LibWebView/SourceHighlighter.h>

View file

@ -9,7 +9,7 @@
#include "LocationEdit.h"
#include "WebContentView.h"
#include <Browser/History.h>
#include <LibWebView/History.h>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
@ -82,7 +82,7 @@ private:
LocationEdit* m_location_edit { nullptr };
WebContentView* m_view { nullptr };
BrowserWindow* m_window { nullptr };
Browser::History m_history;
WebView::History m_history;
QString m_title;
QLabel* m_hover_label { nullptr };

View file

@ -9,8 +9,6 @@
#include "Settings.h"
#include "WebContentView.h"
#include <AK/OwnPtr.h>
#include <Browser/CookieJar.h>
#include <Browser/Database.h>
#include <Ladybird/HelperProcess.h>
#include <Ladybird/Utilities.h>
#include <LibCore/ArgsParser.h>
@ -21,6 +19,8 @@
#include <LibGfx/Font/FontDatabase.h>
#include <LibMain/Main.h>
#include <LibSQL/SQLClient.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/Database.h>
#include <QApplication>
namespace Ladybird {
@ -95,15 +95,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return url;
};
RefPtr<Browser::Database> database;
RefPtr<WebView::Database> database;
if (enable_sql_database) {
auto sql_server_paths = TRY(get_paths_for_helper_process("SQLServer"sv));
auto sql_client = TRY(SQL::SQLClient::launch_server_and_create_client(move(sql_server_paths)));
database = TRY(Browser::Database::create(move(sql_client)));
database = TRY(WebView::Database::create(move(sql_client)));
}
auto cookie_jar = database ? TRY(Browser::CookieJar::create(*database)) : Browser::CookieJar::create();
auto cookie_jar = database ? TRY(WebView::CookieJar::create(*database)) : WebView::CookieJar::create();
Optional<URL> initial_url;
if (auto url = TRY(get_formatted_url(raw_url)); url.is_valid())

View file

@ -11,7 +11,6 @@
#include "BookmarksBarWidget.h"
#include "Browser.h"
#include "ConsoleWidget.h"
#include "CookieJar.h"
#include "InspectorWidget.h"
#include "Tab.h"
#include <Applications/Browser/BrowserWindowGML.h>
@ -35,6 +34,7 @@
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/OutOfProcessWebView.h>
#include <LibWebView/WebContentClient.h>
@ -56,7 +56,7 @@ static DeprecatedString search_engines_file_path()
return builder.to_deprecated_string();
}
BrowserWindow::BrowserWindow(CookieJar& cookie_jar, URL url)
BrowserWindow::BrowserWindow(WebView::CookieJar& cookie_jar, URL url)
: m_cookie_jar(cookie_jar)
, m_window_actions(*this)
{

View file

@ -14,10 +14,10 @@
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Window.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWebView/Forward.h>
namespace Browser {
class CookieJar;
class Tab;
class BrowserWindow final : public GUI::Window
@ -51,7 +51,7 @@ public:
void broadcast_window_size(Gfx::IntSize);
private:
BrowserWindow(CookieJar&, URL);
BrowserWindow(WebView::CookieJar&, URL);
void build_menus();
ErrorOr<void> load_search_engines(GUI::Menu& settings_menu);
@ -76,7 +76,7 @@ private:
RefPtr<GUI::Menu> m_zoom_menu;
CookieJar& m_cookie_jar;
WebView::CookieJar& m_cookie_jar;
WindowActions m_window_actions;
RefPtr<GUI::TabWidget> m_tab_widget;
RefPtr<BookmarksBarWidget> m_bookmarks_bar;

View file

@ -15,12 +15,9 @@ set(SOURCES
BookmarksBarWidget.cpp
BrowserWindow.cpp
ConsoleWidget.cpp
CookieJar.cpp
CookiesModel.cpp
Database.cpp
DownloadWidget.cpp
ElementSizePreviewWidget.cpp
History.cpp
History/HistoryModel.cpp
History/HistoryWidget.cpp
IconBag.cpp
@ -41,5 +38,5 @@ set(GENERATED_SOURCES
)
serenity_app(Browser ICON app-browser)
target_link_libraries(Browser PRIVATE LibCore LibFileSystem LibWebView LibWeb LibProtocol LibPublicSuffix LibGUI LibDesktop LibConfig LibGfx LibIPC LibJS LibLocale LibMain LibSyntax LibSQL)
target_link_libraries(Browser PRIVATE LibCore LibFileSystem LibWebView LibWeb LibProtocol LibPublicSuffix LibGUI LibDesktop LibConfig LibGfx LibIPC LibJS LibLocale LibMain LibSyntax)
link_with_locale_data(Browser)

View file

@ -1,25 +0,0 @@
/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Traits.h>
namespace Browser {
class CookieJar;
class Database;
struct CookieStorageKey;
}
namespace AK {
template<>
struct Traits<Browser::CookieStorageKey>;
}

View file

@ -9,7 +9,7 @@
namespace Browser {
void HistoryModel::set_items(AK::Vector<History::URLTitlePair> items)
void HistoryModel::set_items(AK::Vector<WebView::History::URLTitlePair> items)
{
begin_insert_rows({}, m_entries.size(), m_entries.size());
m_entries = items;

View file

@ -7,9 +7,9 @@
#pragma once
#include <AK/Vector.h>
#include <Applications/Browser/History.h>
#include <LibGUI/Model.h>
#include <LibGUI/Widget.h>
#include <LibWebView/History.h>
namespace Browser {
@ -21,7 +21,7 @@ public:
__Count,
};
void set_items(AK::Vector<History::URLTitlePair> items);
void set_items(AK::Vector<WebView::History::URLTitlePair> items);
void clear_items();
virtual int row_count(GUI::ModelIndex const&) const override;
virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override { return Column::__Count; }
@ -31,7 +31,7 @@ public:
virtual GUI::Model::MatchResult data_matches(GUI::ModelIndex const& index, GUI::Variant const& term) const override;
private:
AK::Vector<History::URLTitlePair> m_entries;
AK::Vector<WebView::History::URLTitlePair> m_entries;
};
}

View file

@ -31,7 +31,7 @@ HistoryWidget::HistoryWidget()
m_table_view->set_alternating_row_colors(true);
}
void HistoryWidget::set_history_entries(Vector<History::URLTitlePair> entries)
void HistoryWidget::set_history_entries(Vector<WebView::History::URLTitlePair> entries)
{
m_model->set_items(entries);
}

View file

@ -6,11 +6,11 @@
#pragma once
#include "../History.h"
#include "HistoryModel.h"
#include <LibGUI/FilteringProxyModel.h>
#include <LibGUI/TextBox.h>
#include <LibGUI/Widget.h>
#include <LibWebView/History.h>
namespace Browser {
@ -20,7 +20,7 @@ class HistoryWidget final : public GUI::Widget {
public:
virtual ~HistoryWidget() override = default;
void set_history_entries(Vector<History::URLTitlePair> entries);
void set_history_entries(Vector<WebView::History::URLTitlePair> entries);
void clear_history_entries();
private:

View file

@ -7,7 +7,6 @@
#pragma once
#include "History.h"
#include <AK/Optional.h>
#include <AK/URL.h>
#include <LibGUI/ActionGroup.h>
@ -15,6 +14,7 @@
#include <LibGfx/ShareableBitmap.h>
#include <LibHTTP/Job.h>
#include <LibWeb/Forward.h>
#include <LibWebView/History.h>
#include <LibWebView/ViewImplementation.h>
namespace WebView {
@ -122,7 +122,7 @@ private:
Optional<URL> url_from_location_bar(MayAppendTLD = MayAppendTLD::No);
History m_history;
WebView::History m_history;
RefPtr<WebView::OutOfProcessWebView> m_web_content_view;

View file

@ -8,8 +8,6 @@
#include <Applications/Browser/Browser.h>
#include <Applications/Browser/BrowserWindow.h>
#include <Applications/Browser/CookieJar.h>
#include <Applications/Browser/Database.h>
#include <Applications/Browser/Tab.h>
#include <Applications/Browser/WindowActions.h>
#include <Applications/BrowserSettings/Defaults.h>
@ -26,6 +24,8 @@
#include <LibGUI/TabWidget.h>
#include <LibMain/Main.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/Database.h>
#include <LibWebView/OutOfProcessWebView.h>
#include <LibWebView/RequestServerAdapter.h>
#include <unistd.h>
@ -140,7 +140,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Browser::g_icon_bag = TRY(Browser::IconBag::try_create());
auto database = TRY(Browser::Database::create());
auto database = TRY(WebView::Database::create());
TRY(load_content_filters());
TRY(load_autoplay_allowlist());
@ -169,7 +169,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (!specified_urls.is_empty())
first_url = TRY(url_from_argument_string(specified_urls.first()));
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
auto cookie_jar = TRY(WebView::CookieJar::create(*database));
auto window = Browser::BrowserWindow::construct(cookie_jar, first_url);
auto content_filters_watcher = TRY(Core::FileWatcher::create());

View file

@ -2,7 +2,10 @@ set(SOURCES
AccessibilityTreeModel.cpp
AriaPropertiesStateModel.cpp
ConsoleClient.cpp
CookieJar.cpp
Database.cpp
DOMTreeModel.cpp
History.cpp
RequestServerAdapter.cpp
SourceHighlighter.cpp
StylePropertiesModel.cpp
@ -36,7 +39,7 @@ set(GENERATED_SOURCES
)
serenity_lib(LibWebView webview)
target_link_libraries(LibWebView PRIVATE LibCore LibGfx LibGUI LibIPC LibProtocol LibJS LibWeb)
target_link_libraries(LibWebView PRIVATE LibCore LibGfx LibGUI LibIPC LibProtocol LibJS LibWeb LibSQL)
if (SERENITYOS)
target_link_libraries(LibWebView PRIVATE LibFileSystemAccessClient)

View file

@ -7,8 +7,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CookieJar.h"
#include "Database.h"
#include <AK/IPv4Address.h>
#include <AK/StringBuilder.h>
#include <AK/StringView.h>
@ -19,8 +17,10 @@
#include <LibSQL/TupleDescriptor.h>
#include <LibSQL/Value.h>
#include <LibWeb/Cookie/ParsedCookie.h>
#include <LibWebView/CookieJar.h>
#include <LibWebView/Database.h>
namespace Browser {
namespace WebView {
ErrorOr<CookieJar> CookieJar::create(Database& database)
{

View file

@ -6,7 +6,6 @@
#pragma once
#include "Forward.h"
#include <AK/DeprecatedString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
@ -16,10 +15,9 @@
#include <LibSQL/Type.h>
#include <LibWeb/Cookie/Cookie.h>
#include <LibWeb/Forward.h>
#include <LibWebView/Forward.h>
namespace Browser {
class Database;
namespace WebView {
struct CookieStorageKey {
bool operator==(CookieStorageKey const&) const = default;
@ -93,8 +91,8 @@ private:
}
template<>
struct AK::Traits<Browser::CookieStorageKey> : public AK::GenericTraits<Browser::CookieStorageKey> {
static unsigned hash(Browser::CookieStorageKey const& key)
struct AK::Traits<WebView::CookieStorageKey> : public AK::GenericTraits<WebView::CookieStorageKey> {
static unsigned hash(WebView::CookieStorageKey const& key)
{
unsigned hash = 0;
hash = pair_int_hash(hash, string_hash(key.name.characters(), key.name.length()));

View file

@ -1,13 +1,13 @@
/*
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2022-2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Database.h"
#include <AK/StringView.h>
#include <LibWebView/Database.h>
namespace Browser {
namespace WebView {
static constexpr auto database_name = "Browser"sv;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2022-2023, Tim Flynn <trflynn89@serenityos.org>
* Copyright (c) 2023, Jelle Raaijmakers <jelle@gmta.nl>
*
* SPDX-License-Identifier: BSD-2-Clause
@ -20,7 +20,7 @@
#include <LibSQL/Type.h>
#include <LibSQL/Value.h>
namespace Browser {
namespace WebView {
class Database : public RefCounted<Database> {
using OnResult = Function<void(ReadonlySpan<SQL::Value>)>;

View file

@ -6,11 +6,25 @@
#pragma once
#include <AK/Traits.h>
namespace WebView {
class ConsoleClient;
class CookieJar;
class Database;
class History;
class OutOfProcessWebView;
class ViewImplementation;
class WebContentClient;
struct CookieStorageKey;
}
namespace AK {
template<>
struct Traits<WebView::CookieStorageKey>;
}

View file

@ -4,9 +4,9 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "History.h"
#include <LibWebView/History.h>
namespace Browser {
namespace WebView {
void History::dump() const
{

View file

@ -9,7 +9,7 @@
#include <AK/URL.h>
#include <AK/Vector.h>
namespace Browser {
namespace WebView {
class History {
public: