Skip to content

Truly independent web browser

LibWebView: Back the reworked browser chrome

Andreas Kling2ee47fdac89c
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 6b400deb8a9..586b7ad6e1d 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -2661,22 +2661,19 @@ void Application::initialize_actions()
m_zoom_menu->add_action(zoom_out_action());
m_zoom_menu->add_action(reset_zoom_action());
- auto set_color_scheme = [this](auto color_scheme) {
+ auto set_website_color_scheme = [this](auto color_scheme) {
return [this, color_scheme]() {
- m_color_scheme = color_scheme;
-
- ViewImplementation::for_each_view([&](ViewImplementation& view) {
- view.set_preferred_color_scheme(m_color_scheme);
- return IterationDecision::Continue;
- });
+ auto appearance = m_settings->appearance();
+ appearance.website_color_scheme = color_scheme;
+ m_settings->set_appearance(appearance);
};
};
m_color_scheme_menu = Menu::create_group("Color Scheme"sv);
- m_color_scheme_menu->add_action(Action::create_checkable("Auto"sv, ActionID::PreferredColorScheme, set_color_scheme(Web::CSS::PreferredColorScheme::Auto)));
- m_color_scheme_menu->add_action(Action::create_checkable("Dark"sv, ActionID::PreferredColorScheme, set_color_scheme(Web::CSS::PreferredColorScheme::Dark)));
- m_color_scheme_menu->add_action(Action::create_checkable("Light"sv, ActionID::PreferredColorScheme, set_color_scheme(Web::CSS::PreferredColorScheme::Light)));
- m_color_scheme_menu->items().first().get<NonnullRefPtr<Action>>()->set_checked(true);
+ m_color_scheme_menu->add_action(Action::create_checkable("Auto"sv, ActionID::PreferredColorScheme, set_website_color_scheme(ThemePreference::System)));
+ m_color_scheme_menu->add_action(Action::create_checkable("Dark"sv, ActionID::PreferredColorScheme, set_website_color_scheme(ThemePreference::Dark)));
+ m_color_scheme_menu->add_action(Action::create_checkable("Light"sv, ActionID::PreferredColorScheme, set_website_color_scheme(ThemePreference::Light)));
+ update_website_color_scheme();
auto set_contrast = [this](auto contrast) {
return [this, contrast]() {
@@ -2747,7 +2744,7 @@ void Application::initialize_actions()
m_show_bookmarks_bar_menu = Menu::create_group("Show Bookmarks Bar"sv);
m_show_bookmarks_bar_always_action = add_show_bookmarks_bar_option("Always"sv, ShowBookmarksBar::Always);
m_show_bookmarks_bar_never_action = add_show_bookmarks_bar_option("Never"sv, ShowBookmarksBar::Never);
- m_show_bookmarks_bar_on_hover_action = add_show_bookmarks_bar_option("Only when hovering the navigation toolbar"sv, ShowBookmarksBar::OnHover);
+ m_show_bookmarks_bar_on_hover_action = add_show_bookmarks_bar_option("Only When Hovering the Navigation Toolbar"sv, ShowBookmarksBar::OnHover);
m_bookmarks_menu->add_submenu(*m_show_bookmarks_bar_menu);
m_bookmarks_menu->add_separator();
@@ -2761,7 +2758,7 @@ void Application::initialize_actions()
m_bookmarks_menu->add_action(*m_toggle_bookmark_action);
update_bookmark_action_for_current_web_view();
- m_bookmarks_menu->add_action(Action::create("Bookmark All Tabs..."sv, ActionID::AddBookmarkAllTabs, [this]() {
+ m_bookmarks_menu->add_action(Action::create("Bookmark All Tabs…"sv, ActionID::AddBookmarkAllTabs, [this]() {
auto bookmarks = bookmarks_for_all_tabs_in_current_window();
if (bookmarks.is_empty())
return;
@@ -2784,6 +2781,7 @@ void Application::initialize_actions()
: WebView::ShowBookmarksBar::Always;
m_settings->set_appearance(appearance);
});
+ m_toggle_bookmark_bar_action->set_checked(m_settings->appearance().show_bookmarks_bar == ShowBookmarksBar::Always);
m_bookmarks_menu->add_separator();
m_bookmarks_menu_static_size = m_bookmarks_menu->size();
@@ -2802,7 +2800,7 @@ void Application::initialize_actions()
m_inspect_menu = Menu::create("Inspect"sv);
- m_view_source_action = Action::create("View Source"sv, ActionID::ViewSource, [this]() {
+ m_view_source_action = Action::create("View Page Source"sv, ActionID::ViewSource, [this]() {
if (auto view = active_web_view(); view.has_value())
view->get_source();
});
@@ -2814,7 +2812,7 @@ void Application::initialize_actions()
});
m_inspect_menu->add_action(*m_toggle_devtools_action);
- m_report_website_issue_action = Action::create("Report Website Issue..."sv, ActionID::ReportWebsiteIssue, [this]() {
+ m_report_website_issue_action = Action::create("Report Website Issue…"sv, ActionID::ReportWebsiteIssue, [this]() {
if (auto view = active_web_view(); view.has_value())
view->report_website_issue();
});
@@ -2834,7 +2832,7 @@ void Application::initialize_actions()
m_debug_menu->add_action(Action::create("Dump Cookies"sv, ActionID::DumpCookies, [this]() { m_default_session->cookie_jar->dump_cookies(); }));
m_debug_menu->add_action(Action::create("Dump Local Storage"sv, ActionID::DumpLocalStorage, debug_request("dump-local-storage"sv)));
m_debug_menu->add_action(Action::create("Dump Session Storage"sv, ActionID::DumpSessionStorage, debug_request("dump-session-storage"sv)));
- m_debug_menu->add_action(Action::create("Dump GC graph"sv, ActionID::DumpGCGraph, [this]() {
+ m_debug_menu->add_action(Action::create("Dump GC Graph"sv, ActionID::DumpGCGraph, [this]() {
if (auto view = active_web_view(); view.has_value()) {
auto gc_graph_path = view->dump_gc_graph();
if (gc_graph_path.is_error()) {
@@ -2939,12 +2937,51 @@ void Application::update_vertical_tabs_action()
auto const& settings = m_settings->tab_settings();
m_toggle_vertical_tabs_expanded_action->set_visible(settings.vertical_tabs_enabled);
m_toggle_vertical_tabs_expanded_action->set_engaged(settings.vertical_tabs_expanded);
- m_toggle_vertical_tabs_expanded_action->set_tooltip(settings.vertical_tabs_expanded ? "Minimize Tabs"sv : "Expand Tabs"sv);
+ m_toggle_vertical_tabs_expanded_action->set_tooltip(settings.vertical_tabs_expanded ? "Hide Sidebar"sv : "Show Sidebar"sv);
+}
+
+static Web::CSS::PreferredColorScheme preferred_color_scheme_for(ThemePreference preference)
+{
+ switch (preference) {
+ case ThemePreference::System:
+ return Web::CSS::PreferredColorScheme::Auto;
+ case ThemePreference::Light:
+ return Web::CSS::PreferredColorScheme::Light;
+ case ThemePreference::Dark:
+ return Web::CSS::PreferredColorScheme::Dark;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+Web::CSS::PreferredColorScheme Application::interface_color_scheme() const
+{
+ return preferred_color_scheme_for(m_settings->appearance().interface_theme);
+}
+
+void Application::update_website_color_scheme()
+{
+ auto preference = m_settings->appearance().website_color_scheme;
+ auto actions = m_color_scheme_menu->items();
+ auto action_index = preference == ThemePreference::System ? 0 : preference == ThemePreference::Dark ? 1
+ : 2;
+ actions[action_index].get<NonnullRefPtr<Action>>()->set_checked(true);
+
+ auto color_scheme = preferred_color_scheme_for(preference);
+ if (color_scheme == m_color_scheme)
+ return;
+ m_color_scheme = color_scheme;
+
+ ViewImplementation::for_each_view([&](ViewImplementation& view) {
+ view.set_preferred_color_scheme(m_color_scheme);
+ return IterationDecision::Continue;
+ });
}
void Application::appearance_changed(Badge<ApplicationSettingsObserver>)
{
m_toggle_menu_bar_action->set_checked(m_settings->appearance().show_menu_bar);
+ m_toggle_bookmark_bar_action->set_checked(m_settings->appearance().show_bookmarks_bar == ShowBookmarksBar::Always);
+ update_website_color_scheme();
switch (m_settings->appearance().show_bookmarks_bar) {
case ShowBookmarksBar::Always:
@@ -3180,6 +3217,17 @@ void Application::create_bookmark_menu_items(Optional<MenuData> data)
.target_folder_id = item.id,
});
+ // A folder's menu ends with a way to open every bookmark in it at once.
+ size_t bookmark_count = 0;
+ for (auto const& child : folder.children)
+ bookmark_count += child.is_bookmark() ? 1 : 0;
+ if (bookmark_count > 0) {
+ submenu->add_separator();
+ submenu->add_action(Action::create(MUST(String::formatted("Open All in Tabs ({})", bookmark_count)), ActionID::OpenAllBookmarksInTabs, [this, folder_id = item.id]() {
+ open_bookmark_folder_in_new_tabs(folder_id);
+ }));
+ }
+
submenu->add_property("id"sv, item.id);
submenu->add_property("type"sv, "folder"_string);
submenu->add_property("target_folder_id"sv, item.id);
diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h
index 745d65fbdd1..0b99140acd5 100644
--- a/Libraries/LibWebView/Application.h
+++ b/Libraries/LibWebView/Application.h
@@ -114,6 +114,9 @@ public:
virtual Optional<String> system_font_family() const { return {}; }
virtual Optional<String> ui_font_family() const { return {}; }
+ // The browser's own pages, such as about:settings, are part of its interface, so they follow the interface theme
+ // rather than the website color scheme.
+ virtual Web::CSS::PreferredColorScheme interface_color_scheme() const;
static RequestServerManager& request_server_manager() { return *the().m_request_server_manager; }
// The UI process's own client of the session's RequestServer with no site.
@@ -123,7 +126,6 @@ public:
virtual bool supports_system_menu_bar() const { return false; }
virtual bool supports_vertical_tabs() const { return false; }
- virtual bool supports_content_blocking_controls() const { return false; }
virtual bool supports_private_browsing_windows() const { return false; }
virtual bool supports_client_side_window_decorations() const { return false; }
virtual bool supports_picture_in_picture() const;
@@ -378,7 +380,7 @@ public:
Action& toggle_menu_bar_action() { return *m_toggle_menu_bar_action; }
Menu& bookmarks_menu() { return *m_bookmarks_menu; }
- void toggle_bookmark_for_view(ViewImplementation&);
+ virtual void toggle_bookmark_for_view(ViewImplementation&);
Action& toggle_bookmark_bar_action() { return *m_toggle_bookmark_bar_action; }
Menu& history_menu() { return *m_history_menu; }
@@ -446,6 +448,7 @@ protected:
private:
ErrorOr<void> create_profile(Optional<StringView> profile_name, Optional<StringView> profile_path, bool force_new_process, bool temporary_profile);
void create_mach_port_server(ByteString const& profile_identity);
+ void update_website_color_scheme();
ErrorOr<NonnullRefPtr<WebContentClient>> create_web_content_client(IsPrivate, Web::PageId initial_page_id, Optional<Web::HTML::CrossProcessId> navigable_to_adopt = {}, Optional<Web::HTML::CrossProcessId> initial_document_state_id = {}, Vector<Web::HTML::RemoteNavigableDescriptor> remote_navigables = {}, Optional<Web::HTML::SessionHistoryEntryDescriptor> canonical_initial_history_entry = {}, Web::HTML::VisibilityState system_visibility_state = Web::HTML::VisibilityState::Hidden);
ErrorOr<void> launch_services();
diff --git a/Libraries/LibWebView/Autocomplete.cpp b/Libraries/LibWebView/Autocomplete.cpp
index 283f8deb9c1..66264d5b137 100644
--- a/Libraries/LibWebView/Autocomplete.cpp
+++ b/Libraries/LibWebView/Autocomplete.cpp
@@ -87,6 +87,9 @@ String autocomplete_suggestion_display_text(AutocompleteSuggestion const& sugges
{
if (suggestion.source == AutocompleteSuggestionSource::Search)
return suggestion.text;
+ // NB: Choosing a search engine leaves the query in the field, rather than the address of the settings.
+ if (suggestion.source == AutocompleteSuggestionSource::ChooseSearchEngine)
+ return suggestion.highlight_input.is_empty() ? suggestion.text : suggestion.highlight_input;
auto url = classify_user_input(suggestion.text).url;
if (!url.has_value())
@@ -186,19 +189,30 @@ static Optional<AutocompleteSuggestion> search_for_query_suggestion(StringView q
if (query.is_empty())
return {};
- auto const& search_engine = Application::settings().search_engine_settings().engine;
- if (!search_engine.has_value())
- return {};
-
auto query_string = MUST(String::from_utf8(query));
- auto subtitle = MUST(String::formatted("Search with {}", search_engine->name));
auto contains_whitespace = any_of(query, [](auto code_unit) { return is_ascii_space(code_unit); });
+ auto const& search_engine = Application::settings().search_engine_settings().engine;
+ if (!search_engine.has_value()) {
+ return AutocompleteSuggestion {
+ .source = AutocompleteSuggestionSource::ChooseSearchEngine,
+ .text = "about:settings#search"_string,
+ .title = "Choose a search engine…"_string,
+ .subtitle = MUST(String::formatted("to search for “{}”", query_string)),
+ .favicon_png = {},
+ .highlight_input = {},
+ .relevance = contains_whitespace ? 1000 : 900,
+ .is_verbatim = true,
+ .can_be_automatically_selected = true,
+ .can_be_inline_completed = false,
+ };
+ }
+
return AutocompleteSuggestion {
.source = AutocompleteSuggestionSource::Search,
.text = query_string,
.title = query_string,
- .subtitle = move(subtitle),
+ .subtitle = {},
.favicon_png = {},
.highlight_input = {},
.relevance = contains_whitespace ? 1000 : 900,
diff --git a/Libraries/LibWebView/Autocomplete.h b/Libraries/LibWebView/Autocomplete.h
index 84e5ae9f3da..2a06f595872 100644
--- a/Libraries/LibWebView/Autocomplete.h
+++ b/Libraries/LibWebView/Autocomplete.h
@@ -42,6 +42,8 @@ enum class AutocompleteSuggestionSource {
Bookmark,
Adaptive,
Search,
+ // Without a search engine, a query that would be searched for offers to choose one instead.
+ ChooseSearchEngine,
};
enum class AutocompleteMatchClass {
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 5a6ff53a696..55d9013af56 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -819,8 +819,11 @@ ErrorOr<NonnullRefPtr<WebContentPage>> CanonicalNavigable::obtain_page_to_host(C
auto page = TRY(obtain_page_to_host_in(process_to_host(document, initiator_origin)));
if (document.is_local_file_content())
page->client().set_has_hosted_local_file_content();
- if (auto const& web_ui_host = document.web_ui_host(); web_ui_host.has_value())
+ if (auto const& web_ui_host = document.web_ui_host(); web_ui_host.has_value()) {
page->client().set_hosted_web_ui(*web_ui_host);
+ // NB: The page took the view's preferences before it hosted the WebUI, so it now takes the interface theme.
+ page->async_set_preferred_color_scheme(Application::the().interface_color_scheme());
+ }
return page;
}
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 8d043834966..d1fcfc21f3b 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -1425,7 +1425,7 @@ bool CanonicalTraversable::run_changing_navigable_history_step_job(ApplyHistoryS
if (!operation.parameters.has<Web::ReloadHistoryOperationParameters>()
&& changing_navigable.target_entry->document_state->document.ptr() != &navigable.active_document()) {
if (auto view = this->view(); view.has_value())
- view->reset_blocked_request_count();
+ view->reset_blocked_resources();
}
if (operation.is_browser_traversal()) {
if (auto callback = move(operation.browser_traversal().on_ready))
diff --git a/Libraries/LibWebView/ContentBlocking.h b/Libraries/LibWebView/ContentBlocking.h
index 39398b2deb2..14b25f7d6c8 100644
--- a/Libraries/LibWebView/ContentBlocking.h
+++ b/Libraries/LibWebView/ContentBlocking.h
@@ -9,6 +9,7 @@
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/Types.h>
+#include <AK/Vector.h>
namespace WebView {
@@ -20,10 +21,17 @@ enum class ContentBlockingState : u8 {
NoRules,
};
+// A resource the content blocker kept the page from loading, named by its host and what kind of resource it was, such as
+// a script or an image.
+struct BlockedResource {
+ String host;
+ StringView kind;
+};
+
struct ContentBlockingSnapshot {
Optional<String> site;
ContentBlockingState state { ContentBlockingState::Unavailable };
- u64 blocked_request_count { 0 };
+ Vector<BlockedResource> blocked_resources;
bool enabled() const { return state == ContentBlockingState::Enabled || state == ContentBlockingState::NoRules; }
bool can_toggle() const { return site.has_value() && (enabled() || state == ContentBlockingState::SiteDisabled); }
diff --git a/Libraries/LibWebView/DownloadPresentation.cpp b/Libraries/LibWebView/DownloadPresentation.cpp
index 4b7c540386e..08169b2c18c 100644
--- a/Libraries/LibWebView/DownloadPresentation.cpp
+++ b/Libraries/LibWebView/DownloadPresentation.cpp
@@ -14,7 +14,7 @@ namespace WebView {
static constexpr auto max_visible_downloads_in_popover = 5uz;
-static String download_count_text(size_t count, StringView singular, StringView plural)
+static String download_count_text(u64 count, StringView singular, StringView plural)
{
return MUST(String::formatted("{} {}", count, count == 1 ? singular : plural));
}
@@ -34,17 +34,23 @@ struct SizeUnit {
StringView suffix;
};
+// Sizes are given in the decimal units the system's file browser shows them in.
static SizeUnit unit_for_download_size(u64 size)
{
- if (size < KiB)
- return { 1, "B"sv };
- if (size < MiB)
- return { KiB, "KiB"sv };
- if (size < GiB)
- return { MiB, "MiB"sv };
- if (size < TiB)
- return { GiB, "GiB"sv };
- return { TiB, "TiB"sv };
+ static constexpr u64 kilobyte = 1000;
+ static constexpr u64 megabyte = kilobyte * 1000;
+ static constexpr u64 gigabyte = megabyte * 1000;
+ static constexpr u64 terabyte = gigabyte * 1000;
+
+ if (size < kilobyte)
+ return { 1, "bytes"sv };
+ if (size < megabyte)
+ return { kilobyte, "KB"sv };
+ if (size < gigabyte)
+ return { megabyte, "MB"sv };
+ if (size < terabyte)
+ return { gigabyte, "GB"sv };
+ return { terabyte, "TB"sv };
}
static String unitless_download_size_text(u64 size, SizeUnit unit)
@@ -61,39 +67,37 @@ static String download_size_text(u64 size)
return MUST(String::formatted("{} {}", unitless_download_size_text(size, unit), unit.suffix));
}
-String download_rate_text(u64 bytes_per_second)
-{
- return MUST(String::formatted("{}/s", download_size_text(bytes_per_second)));
-}
-
String download_time_remaining_text(AK::Duration time_remaining)
{
auto seconds = time_remaining.to_seconds();
if (seconds < 60)
- return MUST(String::formatted("{} sec left", max(seconds, static_cast<i64>(1))));
+ return MUST(String::formatted("{} left", download_count_text(max(seconds, static_cast<i64>(1)), "second"sv, "seconds"sv)));
auto total_minutes = (seconds + 59) / 60;
if (total_minutes < 60)
- return MUST(String::formatted("{} min left", total_minutes));
+ return MUST(String::formatted("{} left", download_count_text(total_minutes, "minute"sv, "minutes"sv)));
auto hours = total_minutes / 60;
auto minutes = total_minutes % 60;
- return MUST(String::formatted("{} hr {} min left", hours, minutes));
+ if (minutes == 0)
+ return MUST(String::formatted("{} left", download_count_text(hours, "hour"sv, "hours"sv)));
+ return MUST(String::formatted("{} {} left", download_count_text(hours, "hour"sv, "hours"sv), download_count_text(minutes, "minute"sv, "minutes"sv)));
}
String download_status_text(FileDownloader::Download const& download)
{
using DownloadStatus = FileDownloader::DownloadStatus;
+ // The progress bar beside the status shows how far along a download is, so the status says only how much of
+ // it has arrived, such as "12.4 of 19.3 MB".
auto downloaded_size_text = [&]() {
- if (auto progress = download.progress(); progress.has_value()) {
+ if (download.total_size.has_value() && *download.total_size > 0) {
auto unit = unit_for_download_size(*download.total_size);
- return MUST(String::formatted("{}/{} {} - {}",
- unitless_download_size_text(download.downloaded_size, unit),
+ return MUST(String::formatted("{} of {} {}",
+ unitless_download_size_text(min(download.downloaded_size, *download.total_size), unit),
unitless_download_size_text(*download.total_size, unit),
- unit.suffix,
- download_percent_text(*progress)));
+ unit.suffix));
}
return MUST(String::formatted("{} downloaded", download_size_text(download.downloaded_size)));
};
@@ -101,29 +105,27 @@ String download_status_text(FileDownloader::Download const& download)
switch (download.status) {
case DownloadStatus::InProgress: {
if (download.is_waiting_to_retry)
- return MUST(String::formatted("Waiting to retry - {}", downloaded_size_text()));
+ return MUST(String::formatted("Waiting to retry · {}", downloaded_size_text()));
StringBuilder builder;
builder.append(downloaded_size_text());
-
- if (download.bytes_per_second.has_value() && *download.bytes_per_second > 0)
- builder.appendff(" - {}", download_rate_text(*download.bytes_per_second));
if (auto time_remaining = download.estimated_time_remaining(); time_remaining.has_value())
- builder.appendff(" - {}", download_time_remaining_text(*time_remaining));
+ builder.appendff(" · {}", download_time_remaining_text(*time_remaining));
return MUST(builder.to_string());
}
case DownloadStatus::Paused:
if (download.error.has_value() && !download.error->is_empty())
- return MUST(String::formatted("Paused - {}", *download.error));
- return MUST(String::formatted("Paused - {}", downloaded_size_text()));
+ return MUST(String::formatted("Paused · {}", *download.error));
+ return MUST(String::formatted("Paused · {}", downloaded_size_text()));
case DownloadStatus::Completed:
- return MUST(String::formatted("Completed - {}", download_size_text(download.downloaded_size)));
+ // NB: A finished download is the one with nothing else to say, so its status is just its size.
+ return download_size_text(download.downloaded_size);
case DownloadStatus::Canceled:
return "Canceled"_string;
case DownloadStatus::Failed:
if (download.error.has_value() && !download.error->is_empty())
- return MUST(String::formatted("Failed - {}", *download.error));
+ return MUST(String::formatted("Failed · {}", *download.error));
return "Failed"_string;
}
VERIFY_NOT_REACHED();
@@ -164,6 +166,8 @@ DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Downloa
++state.paused_download_count;
break;
case FileDownloader::DownloadStatus::Completed:
+ ++state.completed_download_count;
+ break;
case FileDownloader::DownloadStatus::Canceled:
break;
case FileDownloader::DownloadStatus::Failed:
@@ -178,9 +182,9 @@ DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Downloa
if (state.active_download_count > 0) {
if (state.active_download_progress.has_value() && unknown_active_download_count == 0) {
if (state.active_download_count == 1)
- state.tooltip = MUST(String::formatted("Downloading - {}", download_percent_text(*state.active_download_progress)));
+ state.tooltip = MUST(String::formatted("Downloading · {}", download_percent_text(*state.active_download_progress)));
else
- state.tooltip = MUST(String::formatted("{} downloads - {}", state.active_download_count, download_percent_text(*state.active_download_progress)));
+ state.tooltip = MUST(String::formatted("{} downloads · {}", state.active_download_count, download_percent_text(*state.active_download_progress)));
} else {
state.tooltip = download_count_text(state.active_download_count, "download in progress"sv, "downloads in progress"sv);
}
diff --git a/Libraries/LibWebView/DownloadPresentation.h b/Libraries/LibWebView/DownloadPresentation.h
index 8c613b5a51c..a51f8775094 100644
--- a/Libraries/LibWebView/DownloadPresentation.h
+++ b/Libraries/LibWebView/DownloadPresentation.h
@@ -20,13 +20,13 @@ struct WEBVIEW_API DownloadsButtonState {
bool has_downloads { false };
size_t active_download_count { 0 };
size_t paused_download_count { 0 };
+ size_t completed_download_count { 0 };
size_t failed_download_count { 0 };
Optional<double> active_download_progress;
String tooltip;
};
WEBVIEW_API String download_status_text(FileDownloader::Download const&);
-WEBVIEW_API String download_rate_text(u64 bytes_per_second);
WEBVIEW_API String download_time_remaining_text(AK::Duration time_remaining);
WEBVIEW_API Vector<FileDownloader::Download const*> recent_downloads_for_popover(ReadonlySpan<FileDownloader::Download>);
WEBVIEW_API DownloadsButtonState downloads_button_state(ReadonlySpan<FileDownloader::Download>);
diff --git a/Libraries/LibWebView/Omnibox.cpp b/Libraries/LibWebView/Omnibox.cpp
index 30b550376bc..f2f498ebc68 100644
--- a/Libraries/LibWebView/Omnibox.cpp
+++ b/Libraries/LibWebView/Omnibox.cpp
@@ -661,7 +661,8 @@ void Omnibox::commit_suggestion(size_t suggestion_index, bool should_record_enga
auto destination_kind = suggestion.source == AutocompleteSuggestionSource::Search
? OmniboxDestinationKind::Search
: OmniboxDestinationKind::URL;
- if (should_record_engagement) {
+ // NB: Going to choose a search engine is not where the query leads, so it is not learned from.
+ if (should_record_engagement && suggestion.source != AutocompleteSuggestionSource::ChooseSearchEngine) {
m_provider->record_engagement({
.input = m_retained_engagement_input.value_or(m_query),
.destination_kind = destination_kind,
@@ -719,6 +720,17 @@ void Omnibox::apply_completion(String suggestion_text, String completion_text)
set_display(move(completion_text), completion_start);
}
+Optional<String> Omnibox::completion_title() const
+{
+ if (m_provenance != TextProvenance::InlineCompleted || !m_completion_suggestion.has_value())
+ return {};
+ for (auto const& suggestion : m_suggestions) {
+ if (suggestion.text == *m_completion_suggestion && suggestion.title.has_value() && !suggestion.title->is_empty())
+ return suggestion.title;
+ }
+ return {};
+}
+
void Omnibox::apply_preview(String suggestion_text)
{
m_provenance = TextProvenance::RowPreview;
diff --git a/Libraries/LibWebView/Omnibox.h b/Libraries/LibWebView/Omnibox.h
index 522a7b3b312..f4c765b8aed 100644
--- a/Libraries/LibWebView/Omnibox.h
+++ b/Libraries/LibWebView/Omnibox.h
@@ -104,6 +104,9 @@ public:
return m_selection.map([](auto const& selection) { return selection.index; });
}
+ // The title of the page the text on display is inline completed to, if it has one.
+ Optional<String> completion_title() const;
+
// Callbacks to the chrome:
Function<void(Display const&)> on_display_change;
Function<void()> on_suggestions_change;
diff --git a/Libraries/LibWebView/SearchEngine.cpp b/Libraries/LibWebView/SearchEngine.cpp
index 58cb88eaa5e..d64d6119fa7 100644
--- a/Libraries/LibWebView/SearchEngine.cpp
+++ b/Libraries/LibWebView/SearchEngine.cpp
@@ -31,11 +31,11 @@ String SearchEngine::format_search_query_for_display(StringView query) const
{
static constexpr auto MAX_SEARCH_STRING_LENGTH = 32;
- return MUST(String::formatted("Search {} for \"{:.{}}{}\"",
+ return MUST(String::formatted("Search {} for “{:.{}}{}”",
name,
query,
MAX_SEARCH_STRING_LENGTH,
- query.length() > MAX_SEARCH_STRING_LENGTH ? "..."sv : ""sv));
+ query.length() > MAX_SEARCH_STRING_LENGTH ? "…"sv : ""sv));
}
String SearchEngine::format_search_query_for_navigation(StringView query) const
diff --git a/Libraries/LibWebView/SessionStore.cpp b/Libraries/LibWebView/SessionStore.cpp
index 8d02ed134a1..c25454d88c2 100644
--- a/Libraries/LibWebView/SessionStore.cpp
+++ b/Libraries/LibWebView/SessionStore.cpp
@@ -577,14 +577,13 @@ void SessionStore::TransientStorage::append_closed_unit(ClosedUnit unit)
m_closed_units.insert(insertion_index, move(unit));
}
-SessionStore::ClosedUnit const* SessionStore::TransientStorage::last_closed_unit() const
+Optional<SessionStore::ClosedUnit> SessionStore::TransientStorage::take_closed_unit(SessionWindowId unit_id)
{
- return m_closed_units.is_empty() ? nullptr : &m_closed_units.last();
-}
-
-SessionStore::ClosedUnit SessionStore::TransientStorage::take_last_closed_unit()
-{
- return m_closed_units.take_last();
+ for (size_t i = 0; i < m_closed_units.size(); ++i) {
+ if (m_closed_units[i].session_id == unit_id)
+ return m_closed_units.take(i);
+ }
+ return {};
}
void SessionStore::TransientStorage::prune_closed_units(UnitKind kind, u32 max_units)
@@ -1986,6 +1985,9 @@ ErrorOr<void> SessionStore::tab_closed(TabClosed closed)
return {};
};
+ if (closed.keep_for_reopening == KeepForReopening::No)
+ return discard_without_undo();
+
auto close_sequence = m_close_sequence_allocator.allocate();
if (close_sequence.is_error()) {
auto result = discard_without_undo();
@@ -2220,8 +2222,37 @@ Optional<SessionHistorySnapshot> SessionStore::load_tab_history(SessionTabId tab
ErrorOr<Optional<ClosedSessionUnit>> SessionStore::take_most_recently_closed()
{
- auto const* unit = m_transient_storage.last_closed_unit();
- if (!unit)
+ auto const& closed_units = m_transient_storage.closed_units();
+ if (closed_units.is_empty())
+ return Optional<ClosedSessionUnit> {};
+ return take_closed_unit(closed_units.last().session_id);
+}
+
+Vector<RecentlyClosedSessionUnit> SessionStore::recently_closed_units(size_t limit) const
+{
+ Vector<RecentlyClosedSessionUnit> units;
+ auto const& closed_units = m_transient_storage.closed_units();
+ for (size_t i = closed_units.size(); i > 0 && units.size() < limit; --i) {
+ auto const& unit = closed_units[i - 1];
+ if (unit.tabs.is_empty())
+ continue;
+ auto active_tab_index = clamp(unit.active_tab_index, 0, index_as_i64(unit.tabs.size() - 1));
+ units.append({
+ .id = unit.session_id,
+ .active_url = unit.tabs[active_tab_index].active_url,
+ .tab_count = unit.tabs.size(),
+ .was_window = unit.kind == UnitKind::ClosedWindow,
+ .from_startup_recovery = unit.origin == ClosedSessionUnit::Origin::StartupRecovery,
+ .closed_at = unit.closed_time,
+ });
+ }
+ return units;
+}
+
+ErrorOr<Optional<ClosedSessionUnit>> SessionStore::take_closed_unit(SessionWindowId unit_id)
+{
+ auto unit = m_transient_storage.closed_units().first_matching([&](auto const& unit) { return unit.session_id == unit_id; });
+ if (!unit.has_value())
return Optional<ClosedSessionUnit> {};
ClosedSessionUnit result {
@@ -2235,10 +2266,10 @@ ErrorOr<Optional<ClosedSessionUnit>> SessionStore::take_most_recently_closed()
};
if (m_persisted_storage.has_value()) {
- result.tabs = TRY(m_persisted_storage->take_closed_unit(unit->session_id));
- (void)m_transient_storage.take_last_closed_unit();
+ result.tabs = TRY(m_persisted_storage->take_closed_unit(unit_id));
+ (void)m_transient_storage.take_closed_unit(unit_id);
} else {
- auto taken = m_transient_storage.take_last_closed_unit();
+ auto taken = m_transient_storage.take_closed_unit(unit_id).release_value();
for (auto& tab : taken.tabs)
result.tabs.append({ .active_url = move(tab.active_url), .history = move(tab.history), .pinned = tab.pinned });
}
diff --git a/Libraries/LibWebView/SessionStore.h b/Libraries/LibWebView/SessionStore.h
index 14ef778459f..6ef2470fee0 100644
--- a/Libraries/LibWebView/SessionStore.h
+++ b/Libraries/LibWebView/SessionStore.h
@@ -58,6 +58,17 @@ struct ClosedSessionUnit {
Optional<SessionWindowGeometry> geometry;
};
+// A closed tab or window as a list of them shows it: the page its active tab was on, and when it closed.
+struct RecentlyClosedSessionUnit {
+ SessionWindowId id { 0 };
+ URL::URL active_url;
+ size_t tab_count { 0 };
+ bool was_window { false };
+ // Left open by a run that ended without closing it, rather than closed by the user.
+ bool from_startup_recovery { false };
+ UnixDateTime closed_at;
+};
+
// What startup recovery does with the windows the last run left open.
enum class SessionLaunchPolicy : u8 {
// Every leftover window becomes a closed unit on the Reopen Closed Window stack.
@@ -110,9 +121,15 @@ public:
URL::URL url;
};
+ enum class KeepForReopening : u8 {
+ No,
+ Yes,
+ };
+
struct TabClosed {
SessionTabId tab_id { 0 };
UnixDateTime closed_at;
+ KeepForReopening keep_for_reopening { KeepForReopening::Yes };
};
struct TabMoved {
@@ -169,6 +186,9 @@ public:
bool has_closed_units() const;
ErrorOr<Optional<ClosedSessionUnit>> take_most_recently_closed();
+ // The closed units, most recently closed first.
+ Vector<RecentlyClosedSessionUnit> recently_closed_units(size_t limit) const;
+ ErrorOr<Optional<ClosedSessionUnit>> take_closed_unit(SessionWindowId);
ErrorOr<void> remove_entries_accessed_since(UnixDateTime);
// The windows startup recovery kept open, in activation order with the frontmost last. It's handed over once.
@@ -496,8 +516,8 @@ private:
bool has_closed_units() const { return !m_closed_units.is_empty(); }
void set_closed_units(Vector<ClosedUnit>);
void append_closed_unit(ClosedUnit);
- ClosedUnit const* last_closed_unit() const;
- ClosedUnit take_last_closed_unit();
+ Vector<ClosedUnit> const& closed_units() const { return m_closed_units; }
+ Optional<ClosedUnit> take_closed_unit(SessionWindowId);
void prune_closed_units(UnitKind, u32 max_units);
Vector<SessionWindowId> remove_closed_units_since(UnixDateTime);
diff --git a/Libraries/LibWebView/Settings.cpp b/Libraries/LibWebView/Settings.cpp
index ca9bdfbc635..2b5d8bd8b94 100644
--- a/Libraries/LibWebView/Settings.cpp
+++ b/Libraries/LibWebView/Settings.cpp
@@ -33,6 +33,8 @@ static constexpr auto LANGUAGES_KEY = "languages"sv;
static constexpr auto APPEARANCE_KEY = "appearance"sv;
static constexpr auto SHOW_MENU_BAR_KEY = "showMenuBar"sv;
static constexpr auto SHOW_BOOKMARKS_BAR_KEY = "showBookmarksBar"sv;
+static constexpr auto INTERFACE_THEME_KEY = "interfaceTheme"sv;
+static constexpr auto WEBSITE_COLOR_SCHEME_KEY = "websiteColorScheme"sv;
static constexpr auto WINDOW_SETTINGS_KEY = "window"sv;
static constexpr auto WINDOW_POSITION_KEY = "position"sv;
@@ -86,7 +88,6 @@ static constexpr auto BACKGROUND_NETWORKING_FEATURES_KEY = "features"sv;
static constexpr auto CONTENT_BLOCKERS_KEY = "contentBlockers"sv;
static constexpr auto CONTENT_BLOCKER_SUBSCRIPTION_UPDATES_KEY = "contentBlockerSubscriptionUpdates"sv;
-static constexpr auto CONTENT_BLOCKER_SHOW_BLOCKED_COUNT_KEY = "showBlockedCount"sv;
static constexpr auto CONTENT_BLOCKER_DISABLED_SITES_KEY = "disabledSites"sv;
static constexpr auto CONTENT_BLOCKER_BUILT_IN_LISTS_KEY = "builtInLists"sv;
static constexpr auto CONTENT_BLOCKER_CUSTOM_SUBSCRIPTIONS_KEY = "customSubscriptions"sv;
@@ -226,6 +227,30 @@ static constexpr Optional<ShowBookmarksBar> bookmarks_bar_position_from_string(S
return {};
}
+static constexpr StringView theme_preference_to_string(ThemePreference preference)
+{
+ switch (preference) {
+ case ThemePreference::System:
+ return "system"sv;
+ case ThemePreference::Light:
+ return "light"sv;
+ case ThemePreference::Dark:
+ return "dark"sv;
+ }
+ VERIFY_NOT_REACHED();
+}
+
+static constexpr Optional<ThemePreference> theme_preference_from_string(StringView preference)
+{
+ if (preference == "system"sv)
+ return ThemePreference::System;
+ if (preference == "light"sv)
+ return ThemePreference::Light;
+ if (preference == "dark"sv)
+ return ThemePreference::Dark;
+ return {};
+}
+
static constexpr StringView vertical_tabs_position_to_string(VerticalTabsPosition position)
{
switch (position) {
@@ -420,8 +445,6 @@ Settings Settings::create(ByteString settings_path, Vector<String> platform_lang
if (auto content_blockers = settings_json.value().get_object(CONTENT_BLOCKERS_KEY); content_blockers.has_value()) {
if (auto content_blocker_enabled = content_blockers->get_bool(CONTENT_BLOCKER_ENABLED_KEY); content_blocker_enabled.has_value())
settings.m_content_blocker_enabled = *content_blocker_enabled;
- if (auto show_content_blocker_count = content_blockers->get_bool(CONTENT_BLOCKER_SHOW_BLOCKED_COUNT_KEY); show_content_blocker_count.has_value())
- settings.m_show_content_blocker_count = *show_content_blocker_count;
if (auto sites = content_blockers->get_array(CONTENT_BLOCKER_DISABLED_SITES_KEY); sites.has_value()) {
sites->for_each([&](JsonValue const& entry) {
@@ -480,7 +503,7 @@ Settings Settings::create(ByteString settings_path, Vector<String> platform_lang
Settings::Settings(ByteString settings_path)
: m_settings_path(move(settings_path))
- , m_new_tab_page_url(URL::about_newtab())
+ , m_new_tab_page_url(URL::about_blank())
, m_languages(Web::default_preferred_languages())
{
for (auto const& variable : config_variable_definitions()) {
@@ -555,6 +578,8 @@ JsonValue Settings::serialize_json() const
JsonObject appearance;
appearance.set(SHOW_MENU_BAR_KEY, m_appearance.show_menu_bar);
appearance.set(SHOW_BOOKMARKS_BAR_KEY, show_bookmarks_bar_to_string(m_appearance.show_bookmarks_bar));
+ appearance.set(INTERFACE_THEME_KEY, theme_preference_to_string(m_appearance.interface_theme));
+ appearance.set(WEBSITE_COLOR_SCHEME_KEY, theme_preference_to_string(m_appearance.website_color_scheme));
settings.set(APPEARANCE_KEY, move(appearance));
JsonObject zoom_per_host;
@@ -664,7 +689,6 @@ JsonValue Settings::serialize_json() const
JsonObject content_blockers;
content_blockers.set(CONTENT_BLOCKER_ENABLED_KEY, m_content_blocker_enabled);
- content_blockers.set(CONTENT_BLOCKER_SHOW_BLOCKED_COUNT_KEY, m_show_content_blocker_count);
content_blockers.set(CONTENT_BLOCKER_DISABLED_SITES_KEY, move(disabled_sites));
content_blockers.set(CONTENT_BLOCKER_BUILT_IN_LISTS_KEY, move(built_in_content_blocker_lists));
content_blockers.set(CONTENT_BLOCKER_CUSTOM_SUBSCRIPTIONS_KEY, move(custom_content_blocker_subscriptions));
@@ -825,6 +849,14 @@ Appearance Settings::parse_appearance(JsonValue const& settings)
if (auto parsed = bookmarks_bar_position_from_string(*show_bookmarks_bar); parsed.has_value())
appearance.show_bookmarks_bar = *parsed;
}
+ if (auto interface_theme = settings.as_object().get_string(INTERFACE_THEME_KEY); interface_theme.has_value()) {
+ if (auto parsed = theme_preference_from_string(*interface_theme); parsed.has_value())
+ appearance.interface_theme = *parsed;
+ }
+ if (auto website_color_scheme = settings.as_object().get_string(WEBSITE_COLOR_SCHEME_KEY); website_color_scheme.has_value()) {
+ if (auto parsed = theme_preference_from_string(*website_color_scheme); parsed.has_value())
+ appearance.website_color_scheme = *parsed;
+ }
return appearance;
}
@@ -1220,16 +1252,6 @@ void Settings::set_content_blocker_enabled(bool enabled)
observer.content_blocker_settings_changed();
}
-void Settings::set_show_content_blocker_count(bool show)
-{
- if (m_show_content_blocker_count == show)
- return;
- m_show_content_blocker_count = show;
- persist_settings();
- for (auto& observer : m_observers)
- observer.content_blocker_count_visibility_changed();
-}
-
void Settings::set_content_blocker_list_enabled(StringView identifier, bool enabled)
{
for (auto& list : m_content_blocker_lists) {
diff --git a/Libraries/LibWebView/Settings.h b/Libraries/LibWebView/Settings.h
index 8bea550d008..0ac45597ffd 100644
--- a/Libraries/LibWebView/Settings.h
+++ b/Libraries/LibWebView/Settings.h
@@ -37,9 +37,18 @@ enum class ShowBookmarksBar : u8 {
OnHover,
};
+// Whether something follows the system's light or dark appearance, or always uses one of them.
+enum class ThemePreference : u8 {
+ System,
+ Light,
+ Dark,
+};
+
struct Appearance {
bool show_menu_bar { false };
ShowBookmarksBar show_bookmarks_bar { ShowBookmarksBar::Always };
+ ThemePreference interface_theme { ThemePreference::System };
+ ThemePreference website_color_scheme { ThemePreference::System };
};
struct ContentSettings {
@@ -145,7 +154,6 @@ public:
virtual void geolocation_settings_changed() { }
virtual void background_networking_settings_changed() { }
virtual void content_blocker_settings_changed() { }
- virtual void content_blocker_count_visibility_changed() { }
private:
WeakPtr<Settings> m_settings;
@@ -230,9 +238,6 @@ public:
bool content_blocker_enabled() const { return m_content_blocker_enabled; }
void set_content_blocker_enabled(bool);
- bool show_content_blocker_count() const { return m_show_content_blocker_count; }
- void set_show_content_blocker_count(bool);
-
HashTable<String> const& content_blocker_disabled_sites() const { return m_content_blocker_disabled_sites; }
bool content_blocker_enabled_for_site(StringView) const;
ErrorOr<void> set_content_blocker_enabled_for_site(StringView, bool enabled);
@@ -298,7 +303,6 @@ private:
bool m_background_networking_enabled { true };
bool m_filter_list_updates_enabled { false };
bool m_content_blocker_enabled { false };
- bool m_show_content_blocker_count { false };
HashTable<String> m_content_blocker_disabled_sites;
Vector<ContentBlockerList> m_content_blocker_lists;
String m_custom_content_blocker_filters;
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index d6d38c96823..33d7343eab8 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -727,16 +727,6 @@ void ViewImplementation::set_frame_rate_capped(bool capped)
});
}
-void ViewImplementation::set_viewport_corner_radius(double radius)
-{
- if (m_viewport_corner_radius == radius)
- return;
- m_viewport_corner_radius = radius;
- traversable().for_each_hosting_page([&](WebContentPage& page) {
- page.async_set_viewport_corner_radius(m_viewport_corner_radius);
- });
-}
-
void ViewImplementation::update_compositor_display_metadata(WebContentPage& page)
{
Application::the().update_compositor_display_metadata(page.compositor_context_id(), m_display_id, m_maximum_frames_per_second);
@@ -1291,13 +1281,29 @@ void ViewImplementation::discard_input_events_routed_through_lost_compositor(Bad
send_queued_input_events();
}
+// A process that hosts a WebUI hosts only the browser's own pages, which follow the interface theme.
+Web::CSS::PreferredColorScheme ViewImplementation::preferred_color_scheme_for_page(WebContentPage const& page) const
+{
+ if (page.client().hosted_web_ui().has_value())
+ return Application::the().interface_color_scheme();
+ return m_preferred_color_scheme;
+}
+
void ViewImplementation::set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme)
{
m_preferred_color_scheme = color_scheme;
set_page_background_color(preferred_canvas_background_color());
traversable().for_each_hosting_page([&](WebContentPage& page) {
- page.async_set_preferred_color_scheme(color_scheme);
+ page.async_set_preferred_color_scheme(preferred_color_scheme_for_page(page));
+ });
+}
+
+void ViewImplementation::update_interface_color_scheme()
+{
+ traversable().for_each_hosting_page([&](WebContentPage& page) {
+ if (page.client().hosted_web_ui().has_value())
+ page.async_set_preferred_color_scheme(preferred_color_scheme_for_page(page));
});
}
@@ -1355,7 +1361,7 @@ static void send_force_dark(WebContentPage const& page)
void ViewImplementation::send_preferences_to_page(WebContentPage& page)
{
send_system_theme_to_page(page);
- page.async_set_preferred_color_scheme(m_preferred_color_scheme);
+ page.async_set_preferred_color_scheme(preferred_color_scheme_for_page(page));
page.async_set_preferred_contrast(m_preferred_contrast);
page.async_set_preferred_motion(m_preferred_motion);
page.async_set_preferred_languages(Application::settings().languages());
@@ -1650,7 +1656,6 @@ void ViewImplementation::report_website_issue()
void ViewImplementation::update_report_website_issue_action()
{
- m_report_website_issue_action->set_enabled(can_report_website_issue());
Application::the().update_report_website_issue_action();
}
@@ -2359,16 +2364,38 @@ void ViewImplementation::request_style_sheet_source(Web::CSS::StyleSheetIdentifi
page().async_request_style_sheet_source(identifier);
}
-void ViewImplementation::did_block_resource(Badge<WebContentPage>)
+// The page names what it blocked, so its kind is taken only from those the content blocker names, and the list of what
+// was blocked is kept short, each host and kind listed once.
+static constexpr size_t MAX_BLOCKED_RESOURCES = 100;
+
+static StringView known_blocked_resource_kind(StringView kind)
{
- if (m_blocked_request_count != NumericLimits<u64>::max())
- ++m_blocked_request_count;
+ static constexpr Array kinds { "Script"sv, "Image"sv, "Stylesheet"sv, "Font"sv, "Media"sv, "Frame"sv, "Request"sv };
+ for (auto known_kind : kinds) {
+ if (kind == known_kind)
+ return known_kind;
+ }
+ return "Request"sv;
+}
+
+void ViewImplementation::did_block_resource(Badge<WebContentPage>, URL::URL const& url, StringView kind)
+{
+ if (m_blocked_resources.size() >= MAX_BLOCKED_RESOURCES)
+ return;
+
+ auto host = MUST(String::from_utf8(url.serialized_host()));
+ auto resource_kind = known_blocked_resource_kind(kind);
+ auto is_listed = any_of(m_blocked_resources, [&](auto const& resource) { return resource.host == host && resource.kind == resource_kind; });
+ if (host.is_empty() || is_listed)
+ return;
+
+ m_blocked_resources.append({ move(host), resource_kind });
notify_content_blocking_changed();
}
-void ViewImplementation::reset_blocked_request_count()
+void ViewImplementation::reset_blocked_resources()
{
- m_blocked_request_count = 0;
+ m_blocked_resources.clear();
notify_content_blocking_changed();
}
@@ -2381,7 +2408,7 @@ void ViewImplementation::notify_content_blocking_changed()
ContentBlockingSnapshot ViewImplementation::content_blocking_snapshot() const
{
ContentBlockingSnapshot snapshot;
- snapshot.blocked_request_count = m_blocked_request_count;
+ snapshot.blocked_resources = m_blocked_resources;
if (m_crash_state.has_value() || !traversable().active_document().host())
return snapshot;
@@ -2958,7 +2985,7 @@ void ViewImplementation::cancel_all_native_geolocation_requests()
void ViewImplementation::did_start_navigation()
{
- reset_blocked_request_count();
+ reset_blocked_resources();
set_loading_state(true);
dump_session_history("did-start-navigation"sv);
}
@@ -2983,7 +3010,6 @@ void ViewImplementation::did_cancel_loading(Badge<CanonicalNavigable>, bool canc
void ViewImplementation::did_finish_navigation()
{
- m_last_load_finished = true;
set_loading_state(false);
if (!m_webdriver_navigation_observation.has_value())
@@ -3005,8 +3031,6 @@ void ViewImplementation::did_finish_navigation()
void ViewImplementation::set_loading_state(bool is_loading)
{
- if (is_loading)
- m_last_load_finished = false;
if (m_is_loading == is_loading)
return;
m_is_loading = is_loading;
@@ -3153,7 +3177,6 @@ void ViewImplementation::prepare_page_for_navigable(WebContentPage& page)
page.async_set_maximum_frames_per_second(m_maximum_frames_per_second);
if (m_frame_rate_capped)
page.async_set_frame_rate_capped(true);
- page.async_set_viewport_corner_radius(m_viewport_corner_radius);
page.async_set_has_focus(traversable().has_system_focus());
if (auto focused_navigable_id = traversable().focused_navigable_id(); focused_navigable_id.has_value())
page.async_set_focused_navigable(*focused_navigable_id);
@@ -4294,10 +4317,10 @@ void ViewImplementation::initialize_context_menus()
{
auto& application = Application::the();
- m_navigate_back_action = Action::create("Go Back"sv, ActionID::NavigateBack, [this]() {
+ m_navigate_back_action = Action::create("Back"sv, ActionID::NavigateBack, [this]() {
traverse_the_history_by_delta(-1);
});
- m_navigate_forward_action = Action::create("Go Forward"sv, ActionID::NavigateForward, [this]() {
+ m_navigate_forward_action = Action::create("Forward"sv, ActionID::NavigateForward, [this]() {
traverse_the_history_by_delta(+1);
});
m_navigate_back_action->set_enabled(false);
@@ -4348,11 +4371,6 @@ void ViewImplementation::initialize_context_menus()
on_request_screenshot();
});
- m_report_website_issue_action = Action::create("Report Website Issue..."sv, ActionID::ReportWebsiteIssue, [this]() {
- report_website_issue();
- });
- m_report_website_issue_action->set_enabled(false);
-
// A URL from the context menu is the page's — a link's or an image's — so it's navigated to from the page, unless
// the user selected it as text. Blink also starts a selected URL with no initiator (IDC_CONTENT_CONTEXT_GOTOURL).
m_open_in_new_tab_action = Action::create("Open in New Tab"sv, ActionID::OpenInNewTab, [this]() {
@@ -4362,7 +4380,7 @@ void ViewImplementation::initialize_context_menus()
open_url_in_new_tab(m_context_menu_url, Web::HTML::ActivateTab::No);
});
if (m_is_private == IsPrivate::No) {
- m_open_in_new_window_action = Action::create("Open in New Window"sv, ActionID::OpenInNewWindow, [this]() {
+ m_open_in_new_window_action = Action::create("Open Link in New Window"sv, ActionID::OpenInNewWindow, [this]() {
if (m_context_menu_navigation.has_value())
open_navigation_in_new_window(*m_context_menu_navigation, IsPrivate::No);
else
@@ -4370,7 +4388,7 @@ void ViewImplementation::initialize_context_menus()
});
}
if (application.supports_private_browsing_windows()) {
- m_open_in_new_private_window_action = Action::create("Open in New Private Window"sv, ActionID::OpenInNewPrivateWindow, [this]() {
+ m_open_in_new_private_window_action = Action::create("Open Link in Private Window"sv, ActionID::OpenInNewPrivateWindow, [this]() {
if (!m_context_menu_navigation.has_value()) {
open_url_in_new_window(m_context_menu_url, IsPrivate::Yes);
return;
@@ -4385,7 +4403,7 @@ void ViewImplementation::initialize_context_menus()
m_download_linked_file_action = Action::create("Download Linked File"sv, ActionID::DownloadLinkedFile, [this]() {
download_context_menu_url(PromptForPath::No);
});
- m_download_linked_file_as_action = Action::create("Download Linked File As..."sv, ActionID::DownloadLinkedFileAs, [this]() {
+ m_download_linked_file_as_action = Action::create("Save Link As…"sv, ActionID::DownloadLinkedFileAs, [this]() {
download_context_menu_url(PromptForPath::Yes);
});
m_copy_url_action = Action::create("Copy URL"sv, ActionID::CopyURL, [this]() {
@@ -4395,7 +4413,7 @@ void ViewImplementation::initialize_context_menus()
m_open_image_action = Action::create("Open Image"sv, ActionID::OpenImage, [this]() {
load(*m_context_menu_navigation);
});
- m_save_image_action = Action::create("Save Image As..."sv, ActionID::SaveImage, [this]() {
+ m_save_image_action = Action::create("Save Image As…"sv, ActionID::SaveImage, [this]() {
download_context_menu_url(PromptForPath::Yes);
});
m_copy_image_action = Action::create("Copy Image"sv, ActionID::CopyImage, [this]() {
@@ -4446,10 +4464,10 @@ void ViewImplementation::initialize_context_menus()
m_media_exit_fullscreen_action = Action::create("Exit Full Screen"sv, ActionID::ExitFullscreen, [this]() {
send_to_media_context_menu_page([](auto& page) { page.async_toggle_media_fullscreen_state(); });
});
- m_media_enter_picture_in_picture_action = Action::create("Picture-in-Picture"sv, ActionID::EnterPictureInPicture, [this]() {
+ m_media_enter_picture_in_picture_action = Action::create("Picture in Picture"sv, ActionID::EnterPictureInPicture, [this]() {
send_to_media_context_menu_page([](auto& page) { page.async_toggle_media_picture_in_picture_state(); });
});
- m_media_exit_picture_in_picture_action = Action::create("Exit Picture-in-Picture"sv, ActionID::ExitPictureInPicture, [this]() {
+ m_media_exit_picture_in_picture_action = Action::create("Exit Picture in Picture"sv, ActionID::ExitPictureInPicture, [this]() {
send_to_media_context_menu_page([](auto& page) { page.async_toggle_media_picture_in_picture_state(); });
});
@@ -4503,18 +4521,17 @@ void ViewImplementation::initialize_context_menus()
m_page_context_menu->add_action(*m_search_selected_text_action);
m_page_context_menu->add_action(*m_copy_link_to_highlight_action);
m_page_context_menu->add_separator();
- m_page_context_menu->add_action(*m_take_screenshot_action);
- m_page_context_menu->add_separator();
m_page_context_menu->add_action(application.view_source_action());
- m_page_context_menu->add_action(*m_report_website_issue_action);
+ m_page_context_menu->add_action(application.report_website_issue_action());
+ m_page_context_menu->add_separator();
+ m_page_context_menu->add_action(*m_take_screenshot_action);
m_link_context_menu = Menu::create("Link Context Menu"sv);
add_open_url_actions(*m_link_context_menu);
m_link_context_menu->add_separator();
+ m_link_context_menu->add_action(*m_copy_url_action);
m_link_context_menu->add_action(*m_download_linked_file_action);
m_link_context_menu->add_action(*m_download_linked_file_as_action);
- m_link_context_menu->add_separator();
- m_link_context_menu->add_action(*m_copy_url_action);
m_link_context_menu->add_action(*m_copy_link_to_highlight_action);
m_selected_text_link_context_menu = Menu::create("Selected Text Link Context Menu"sv);
@@ -4530,10 +4547,9 @@ void ViewImplementation::initialize_context_menus()
m_image_context_menu->add_action(*m_open_in_new_tab_action);
m_image_context_menu->add_action(*m_open_image_action);
m_image_context_menu->add_separator();
- m_image_context_menu->add_action(*m_save_image_action);
- m_image_context_menu->add_separator();
m_image_context_menu->add_action(*m_copy_image_action);
m_image_context_menu->add_action(*m_copy_url_action);
+ m_image_context_menu->add_action(*m_save_image_action);
m_media_context_menu = Menu::create("Media Context Menu"sv);
m_media_context_menu->add_action(*m_media_play_action);
@@ -4543,18 +4559,18 @@ void ViewImplementation::initialize_context_menus()
m_media_context_menu->add_action(*m_media_show_controls_action);
m_media_context_menu->add_action(*m_media_hide_controls_action);
m_media_context_menu->add_action(*m_media_loop_action);
- m_media_context_menu->add_action(*m_media_enter_fullscreen_action);
- m_media_context_menu->add_action(*m_media_exit_fullscreen_action);
+ m_media_context_menu->add_separator();
m_media_context_menu->add_action(*m_media_enter_picture_in_picture_action);
m_media_context_menu->add_action(*m_media_exit_picture_in_picture_action);
+ m_media_context_menu->add_action(*m_media_enter_fullscreen_action);
+ m_media_context_menu->add_action(*m_media_exit_fullscreen_action);
m_media_context_menu->add_separator();
m_media_context_menu->add_action(*m_open_in_new_tab_action);
m_media_context_menu->add_action(*m_open_audio_action);
m_media_context_menu->add_action(*m_open_video_action);
- m_media_context_menu->add_separator();
m_media_context_menu->add_action(*m_copy_url_action);
- auto add_bookmark_action = Action::create("Add Bookmark..."sv, ActionID::AddBookmark, []() {
+ auto add_bookmark_action = Action::create("Add Bookmark…"sv, ActionID::AddBookmark, []() {
auto& application = Application::the();
auto bookmark_id = application.bookmark_item_id_for_context_menu();
@@ -4567,7 +4583,7 @@ void ViewImplementation::initialize_context_menus()
Application::bookmark_store().add_bookmark(move(bookmark.url), move(bookmark.title), move(bookmark.favicon_hash), result.target_folder_id);
});
});
- auto add_bookmark_folder_action = Action::create("Add Folder..."sv, ActionID::AddBookmarkFolder, []() {
+ auto add_bookmark_folder_action = Action::create("New Folder…"sv, ActionID::AddBookmarkFolder, []() {
auto& application = Application::the();
auto bookmark_id = application.bookmark_item_id_for_context_menu();
@@ -4584,6 +4600,8 @@ void ViewImplementation::initialize_context_menus()
m_bookmarks_bar_context_menu = Menu::create("Bookmarks Bar Context Menu"sv);
m_bookmarks_bar_context_menu->add_action(add_bookmark_action);
m_bookmarks_bar_context_menu->add_action(add_bookmark_folder_action);
+ m_bookmarks_bar_context_menu->add_separator();
+ m_bookmarks_bar_context_menu->add_action(application.toggle_bookmark_bar_action());
m_bookmark_context_menu = Menu::create("Bookmark Context Menu"sv);
m_bookmark_context_menu->add_action(Action::create("Open in New Tab"sv, ActionID::OpenInNewTab, []() {
@@ -4601,7 +4619,7 @@ void ViewImplementation::initialize_context_menus()
}));
}
if (application.supports_private_browsing_windows()) {
- m_bookmark_context_menu->add_action(Action::create("Open in New Private Window"sv, ActionID::OpenInNewPrivateWindow, []() {
+ m_bookmark_context_menu->add_action(Action::create("Open in Private Window"sv, ActionID::OpenInNewPrivateWindow, []() {
auto& application = Application::the();
if (auto bookmark_id = application.bookmark_item_id_for_context_menu(); bookmark_id.has_value())
@@ -4609,21 +4627,7 @@ void ViewImplementation::initialize_context_menus()
}));
}
m_bookmark_context_menu->add_separator();
- m_bookmark_context_menu->add_action(Action::create("Copy URL"sv, ActionID::CopyURL, []() {
- auto& application = Application::the();
-
- auto bookmark_id = application.bookmark_item_id_for_context_menu();
- if (!bookmark_id.has_value())
- return;
-
- auto bookmark = Application::bookmark_store().find_item_by_id(bookmark_id->id);
- if (!bookmark.has_value() || !bookmark->is_bookmark())
- return;
-
- application.insert_clipboard_entry({ "text/plain"_string, url_text_to_copy(bookmark->bookmark().url) });
- }));
- m_bookmark_context_menu->add_separator();
- m_bookmark_context_menu->add_action(Action::create("Edit Bookmark..."sv, ActionID::EditBookmark, []() {
+ m_bookmark_context_menu->add_action(Action::create("Edit…"sv, ActionID::EditBookmark, []() {
auto& application = Application::the();
auto bookmark_id = application.bookmark_item_id_for_context_menu();
@@ -4643,13 +4647,27 @@ void ViewImplementation::initialize_context_menus()
store.move_item(bookmark_id.id, result.target_folder_id, NumericLimits<size_t>::max());
});
}));
- m_bookmark_context_menu->add_action(Action::create("Delete Bookmark"sv, ActionID::DeleteBookmark, []() {
+ m_bookmark_context_menu->add_action(Action::create("Copy Link"sv, ActionID::CopyURL, []() {
+ auto& application = Application::the();
+
+ auto bookmark_id = application.bookmark_item_id_for_context_menu();
+ if (!bookmark_id.has_value())
+ return;
+
+ auto bookmark = Application::bookmark_store().find_item_by_id(bookmark_id->id);
+ if (!bookmark.has_value() || !bookmark->is_bookmark())
+ return;
+
+ application.insert_clipboard_entry({ "text/plain"_string, url_text_to_copy(bookmark->bookmark().url) });
+ }));
+ m_bookmark_context_menu->add_action(Action::create("Delete"sv, ActionID::DeleteBookmark, []() {
if (auto bookmark_id = Application::the().bookmark_item_id_for_context_menu(); bookmark_id.has_value())
Application::bookmark_store().remove_item(bookmark_id->id);
}));
m_bookmark_context_menu->add_separator();
- m_bookmark_context_menu->add_action(add_bookmark_action);
m_bookmark_context_menu->add_action(add_bookmark_folder_action);
+ m_bookmark_context_menu->add_separator();
+ m_bookmark_context_menu->add_action(application.toggle_bookmark_bar_action());
m_bookmark_folder_context_menu = Menu::create("Bookmark Folder Context Menu"sv);
m_bookmark_folder_context_menu->add_action(Action::create("Open All in Tabs"sv, ActionID::OpenAllBookmarksInTabs, []() {
@@ -4659,7 +4677,7 @@ void ViewImplementation::initialize_context_menus()
application.open_bookmark_folder_in_new_tabs(bookmark_id->id);
}));
m_bookmark_folder_context_menu->add_separator();
- m_bookmark_folder_context_menu->add_action(Action::create("Edit Folder..."sv, ActionID::EditBookmarkFolder, []() {
+ m_bookmark_folder_context_menu->add_action(Action::create("Edit Folder…"sv, ActionID::EditBookmarkFolder, []() {
auto& application = Application::the();
auto bookmark_id = application.bookmark_item_id_for_context_menu();
@@ -4686,6 +4704,8 @@ void ViewImplementation::initialize_context_menus()
m_bookmark_folder_context_menu->add_separator();
m_bookmark_folder_context_menu->add_action(add_bookmark_action);
m_bookmark_folder_context_menu->add_action(add_bookmark_folder_action);
+ m_bookmark_folder_context_menu->add_separator();
+ m_bookmark_folder_context_menu->add_action(application.toggle_bookmark_bar_action());
}
void ViewImplementation::update_look_up_selected_text_action(Optional<DictionaryLookup> const& lookup, Gfx::IntPoint content_position)
@@ -4917,8 +4937,20 @@ void ViewImplementation::did_request_page_context_menu(Badge<WebContentPage>, We
if (!weak_this || request_id != weak_this->m_context_menu_request_id)
return;
- auto& cut_selection_action = Application::the().cut_selection_action();
- cut_selection_action.set_visible(for_input_events_target == Web::ContextMenuForInputEventsTarget::Yes);
+ // Text can be edited only in a field, and copied only where there is some. The page's own items are left out
+ // where the menu is about the text.
+ auto& application = Application::the();
+ auto is_editable = for_input_events_target == Web::ContextMenuForInputEventsTarget::Yes;
+ auto is_about_page = !is_editable && !selected_text.has_value();
+ application.cut_selection_action().set_visible(is_editable);
+ application.copy_selection_action().set_visible(is_editable || selected_text.has_value());
+ application.paste_action().set_visible(is_editable);
+ application.select_all_action().set_visible(is_editable);
+ weak_this->m_navigate_back_action->set_visible(is_about_page);
+ weak_this->m_navigate_forward_action->set_visible(is_about_page);
+ application.reload_action().set_visible(is_about_page);
+ application.view_source_action().set_visible(is_about_page);
+ weak_this->m_take_screenshot_action->set_visible(is_about_page);
auto const& search_engine = Application::settings().search_engine_settings().engine;
weak_this->m_search_text = search_engine.has_value() ? selected_text : OptionalNone {};
@@ -4926,7 +4958,19 @@ void ViewImplementation::did_request_page_context_menu(Badge<WebContentPage>, We
weak_this->update_look_up_selected_text_action(lookup, content_position);
ScopeGuard guard { [&]() {
- cut_selection_action.set_visible(true);
+ // NB: The application's actions are shared with its other menus.
+ application.cut_selection_action().set_visible(true);
+ application.copy_selection_action().set_visible(true);
+ application.paste_action().set_visible(true);
+ application.select_all_action().set_visible(true);
+ application.reload_action().set_visible(true);
+ application.view_source_action().set_visible(true);
+ // NB: The view can be gone once the menu closes, as when its tab was closed while the menu was open.
+ if (!weak_this)
+ return;
+ weak_this->m_navigate_back_action->set_visible(true);
+ weak_this->m_navigate_forward_action->set_visible(true);
+ weak_this->m_take_screenshot_action->set_visible(true);
weak_this->m_search_text.clear();
} };
@@ -4941,7 +4985,7 @@ void ViewImplementation::did_request_page_context_menu(Badge<WebContentPage>, We
weak_this->set_context_menu_url_actions_enabled(true);
weak_this->m_context_menu_url = selected_text_url.release_value();
weak_this->m_context_menu_navigation.clear();
- weak_this->m_open_in_new_tab_action->set_text("Open in New Tab"sv);
+ weak_this->m_open_in_new_tab_action->set_text("Open Link in New Tab"sv);
weak_this->m_selected_text_link_context_menu->on_activation(weak_this->to_widget_position(content_position));
return;
}
@@ -4970,7 +5014,7 @@ void ViewImplementation::did_request_link_context_menu(Badge<WebContentPage>, Gf
m_context_menu_url = navigation.url;
m_context_menu_navigation = move(navigation);
- m_open_in_new_tab_action->set_text("Open in New Tab"sv);
+ m_open_in_new_tab_action->set_text("Open Link in New Tab"sv);
switch (url_type(m_context_menu_url)) {
case URLType::Email:
@@ -4980,7 +5024,7 @@ void ViewImplementation::did_request_link_context_menu(Badge<WebContentPage>, Gf
m_copy_url_action->set_text("Copy Phone Number"sv);
break;
case URLType::Other:
- m_copy_url_action->set_text("Copy Link Address"sv);
+ m_copy_url_action->set_text("Copy Link"sv);
break;
}
@@ -5016,7 +5060,7 @@ void ViewImplementation::did_request_image_context_menu(Badge<WebContentPage>, G
m_image_context_menu_bitmap = move(bitmap);
m_open_in_new_tab_action->set_text("Open Image in New Tab"sv);
- m_copy_url_action->set_text("Copy Image URL"sv);
+ m_copy_url_action->set_text("Copy Image Address"sv);
m_copy_image_action->set_enabled(m_image_context_menu_bitmap.has_value());
@@ -5049,8 +5093,8 @@ void ViewImplementation::did_request_media_context_menu(Badge<WebContentPage>, W
m_context_menu_url = move(menu.media_url).value_or({});
m_context_menu_navigation = move(navigation);
- m_open_in_new_tab_action->set_text(menu.is_video ? "Open Video in New Tab"sv : "Open Audio in new Tab"sv);
- m_copy_url_action->set_text(menu.is_video ? "Copy Video URL"sv : "Copy Audio URL"sv);
+ m_open_in_new_tab_action->set_text(menu.is_video ? "Open Video in New Tab"sv : "Open Audio in New Tab"sv);
+ m_copy_url_action->set_text(menu.is_video ? "Copy Video Address"sv : "Copy Audio Address"sv);
m_open_audio_action->set_visible(!menu.is_video);
m_open_video_action->set_visible(menu.is_video);
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 45e48cf3344..129afacfbd9 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -165,8 +165,6 @@ public:
void reload_for_webdriver_bidi(BypassCache, Utf16String navigation_id);
void stop_loading();
bool is_loading() const { return m_is_loading; }
- // Whether the most recent load ran to completion, rather than being stopped or canceled.
- bool last_load_finished() const { return m_last_load_finished; }
bool crash_overlay_active() const { return m_crash_state.has_value(); }
String crash_overlay_failed_url() const;
@@ -210,8 +208,6 @@ public:
// Sends the display metadata to every page hosting documents of the tab.
void set_display_metadata(Optional<u64> display_id, double maximum_frames_per_second);
void set_frame_rate_capped(bool);
- double viewport_corner_radius() const { return m_viewport_corner_radius; }
- void set_viewport_corner_radius(double);
struct ScreenRects {
Vector<Web::DevicePixelRect> rects;
@@ -257,6 +253,8 @@ public:
}
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
+ // Sends the interface theme to the pages showing the browser's own pages, which follow it.
+ void update_interface_color_scheme();
void set_preferred_contrast(Web::CSS::PreferredContrast);
void set_preferred_motion(Web::CSS::PreferredMotion);
// A page created to host documents of the tab in another process takes the preferences the view's page has.
@@ -375,8 +373,8 @@ public:
void list_style_sheets();
void request_style_sheet_source(Web::CSS::StyleSheetIdentifier const&);
- void did_block_resource(Badge<WebContentPage>);
- void reset_blocked_request_count();
+ void did_block_resource(Badge<WebContentPage>, URL::URL const&, StringView kind);
+ void reset_blocked_resources();
void notify_content_blocking_changed();
ContentBlockingSnapshot content_blocking_snapshot() const;
@@ -708,6 +706,7 @@ protected:
void set_page_background_color_to_system_canvas(bool dark);
void set_page_background_color(Gfx::Color);
Gfx::Color preferred_canvas_background_color() const;
+ Web::CSS::PreferredColorScheme preferred_color_scheme_for_page(WebContentPage const&) const;
void initialize_tab(Web::HTML::VisibilityState, Optional<CanonicalTraversable&> = {});
void display_traversable(CanonicalTraversable&, Web::HTML::VisibilityState);
@@ -806,7 +805,6 @@ protected:
Optional<u64> m_display_id;
double m_maximum_frames_per_second { 60.0 };
bool m_frame_rate_capped { false };
- double m_viewport_corner_radius { 0 };
bool m_scales_frames_to_fit { false };
RefPtr<Menu> m_page_context_menu;
@@ -848,7 +846,6 @@ protected:
HashMap<u64, NonnullRefPtr<Core::Promise<ByteString>>> m_pending_cut_selected_text_requests;
RefPtr<Action> m_take_screenshot_action;
- RefPtr<Action> m_report_website_issue_action;
RefPtr<Action> m_open_in_new_tab_action;
RefPtr<Action> m_open_in_new_window_action;
@@ -954,7 +951,6 @@ protected:
bool m_can_undo { false };
bool m_can_redo { false };
bool m_is_loading { false };
- bool m_last_load_finished { false };
// WebDriver's observation of the top-level navigation completion state. The navigation itself is the
// canonical traversable's ongoing navigation record.
struct WebDriverNavigationObservation {
@@ -1108,7 +1104,7 @@ protected:
HashMap<u64, NavigationListener> m_navigation_listeners;
u64 m_next_navigation_listener_id { 1 };
- u64 m_blocked_request_count { 0 };
+ Vector<BlockedResource> m_blocked_resources;
enum class NodePickerRequestType : u8 {
Hovered,
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index c2a0c831373..79cdb121cb6 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -137,6 +137,12 @@ static bool is_download_in_progress(FileDownloader const& file_downloader, u64 d
return download.has_value() && download->status == FileDownloader::DownloadStatus::InProgress;
}
+// An error page's title is about the failure, not the page it couldn't load, so it's never recorded in history.
+static bool shows_error_page(ViewImplementation const& view)
+{
+ return view.has_traversable() && view.traversable().active_document().creation_url() == URL::about_error();
+}
+
static Optional<String> history_title(Utf16String const& title, URL::URL const& url)
{
if (title.is_empty())
@@ -1221,9 +1227,9 @@ void WebContentPage::did_output_js_console_message(ConsoleOutput console_output)
}
}
-void WebContentPage::did_block_resource()
+void WebContentPage::did_block_resource(URL::URL url, String kind)
{
- view().did_block_resource({});
+ view().did_block_resource({}, url, kind);
}
void WebContentPage::did_start_network_request(u64 request_id, URL::URL url, ByteString method, Vector<HTTP::Header> request_headers, ByteBuffer request_body, Optional<String> initiator_type, String referrer_policy, bool is_navigation_request, Web::Fetch::Infrastructure::RequestPriority priority)
@@ -2402,7 +2408,7 @@ void WebContentPage::did_finish_loading(Web::HTML::CrossProcessId navigable_id,
m_web_ui = nullptr;
}
- auto title = history_title(view().title(), committed_url);
+ auto title = shows_error_page(view()) ? Optional<String> {} : history_title(view().title(), committed_url);
dbgln_if(WEBVIEW_HISTORY_DEBUG, "[History] Load finished for page {} at '{}' with title '{}'",
m_id,
@@ -2433,7 +2439,7 @@ void WebContentPage::did_change_title(Utf16String title)
process->set_title(title);
if (displays_tab()) {
- if (!title.is_empty()) {
+ if (!title.is_empty() && !shows_error_page(view())) {
auto title_utf8 = title.to_utf8();
maybe_record_history_visit_for_current_load(view().url(), title_utf8, "title change"sv);
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 927fee235f3..314b27ba993 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -229,7 +229,7 @@ private:
virtual void did_cut_selected_text(u64 request_id, ByteString selection) override;
virtual void did_execute_js_console_input(JsonValue result) override;
virtual void did_output_js_console_message(ConsoleOutput console_output) override;
- virtual void did_block_resource() override;
+ virtual void did_block_resource(URL::URL url, String kind) override;
virtual void did_start_network_request(u64 request_id, URL::URL url, ByteString method, Vector<HTTP::Header> request_headers, ByteBuffer request_body, Optional<String> initiator_type, String referrer_policy, bool is_navigation_request, Web::Fetch::Infrastructure::RequestPriority priority) override;
virtual void did_receive_network_response_body(u64 request_id, ByteBuffer data) override;
virtual void did_finish_network_request(u64 request_id, u64 body_size, Requests::RequestTimingInfo timing_info, Optional<Requests::NetworkError> network_error) override;
diff --git a/Libraries/LibWebView/WebUI/BookmarksUI.cpp b/Libraries/LibWebView/WebUI/BookmarksUI.cpp
index 5316b480f73..406b37d9635 100644
--- a/Libraries/LibWebView/WebUI/BookmarksUI.cpp
+++ b/Libraries/LibWebView/WebUI/BookmarksUI.cpp
@@ -5,6 +5,7 @@
*/
#include <LibCore/File.h>
+#include <LibCore/Promise.h>
#include <LibWebView/Application.h>
#include <LibWebView/BookmarkStore.h>
#include <LibWebView/WebUI/BookmarksUI.h>
@@ -19,6 +20,9 @@ void BookmarksUI::register_interfaces()
register_interface("moveItem"sv, [this](auto const& data) {
move_item(data);
});
+ register_interface("newFolder"sv, [this](auto const& data) {
+ new_folder(data);
+ });
register_interface("showContextMenu"sv, [this](auto const& data) {
show_context_menu(data);
});
@@ -55,6 +59,20 @@ void BookmarksUI::move_item(JsonValue const& data)
Application::bookmark_store().move_item(*id, target_folder_id, *index);
}
+void BookmarksUI::new_folder(JsonValue const& data)
+{
+ Optional<String> target_folder_id;
+ if (data.is_object()) {
+ if (auto folder_id = data.as_object().get_string("targetFolderId"sv); folder_id.has_value())
+ target_folder_id = *folder_id;
+ }
+
+ Application::the().display_add_bookmark_folder_dialog({}, target_folder_id)->when_resolved([](Application::BookmarkDialogResult result) {
+ auto& folder = result.data.get<BookmarkItem::Folder>();
+ Application::bookmark_store().add_folder(move(folder.title), result.target_folder_id);
+ });
+}
+
void BookmarksUI::import_bookmarks(JsonValue const& data)
{
if (!data.is_array())
@@ -102,7 +120,9 @@ void BookmarksUI::show_context_menu(JsonValue const& data)
Application::the().show_bookmark_context_menu({ *client_x, *client_y }, item, target_folder_id, parent_folder_id);
} else {
- Application::the().show_bookmark_context_menu({ *client_x, *client_y }, {}, {}, {});
+ // NB: Empty space shows the menu for the folder being shown.
+ auto target_folder_id = object.get_string("targetFolderId"sv);
+ Application::the().show_bookmark_context_menu({ *client_x, *client_y }, {}, target_folder_id, {});
}
}
diff --git a/Libraries/LibWebView/WebUI/BookmarksUI.h b/Libraries/LibWebView/WebUI/BookmarksUI.h
index 199a4e37ea4..5639c7ad611 100644
--- a/Libraries/LibWebView/WebUI/BookmarksUI.h
+++ b/Libraries/LibWebView/WebUI/BookmarksUI.h
@@ -22,6 +22,7 @@ private:
void load_bookmarks();
void move_item(JsonValue const&);
+ void new_folder(JsonValue const&);
void import_bookmarks(JsonValue const&);
void export_bookmarks(JsonValue const&);
void show_context_menu(JsonValue const&);
diff --git a/Libraries/LibWebView/WebUI/SettingsUI.cpp b/Libraries/LibWebView/WebUI/SettingsUI.cpp
index 2830f255ad9..2b20d1cd5fd 100644
--- a/Libraries/LibWebView/WebUI/SettingsUI.cpp
+++ b/Libraries/LibWebView/WebUI/SettingsUI.cpp
@@ -73,6 +73,9 @@ void SettingsUI::register_interfaces()
register_interface("setContentBlockerEnabled"sv, [this](auto const& data) {
set_content_blocker_enabled(data);
});
+ register_interface("setContentBlockerEnabledForSite"sv, [this](auto const& data) {
+ set_content_blocker_enabled_for_site(data);
+ });
register_interface("setContentBlockerListEnabled"sv, [this](auto const& data) {
set_content_blocker_list_enabled(data);
});
@@ -163,9 +166,6 @@ void SettingsUI::register_interfaces()
register_interface("updateContentBlockerLists"sv, [this](auto const& data) {
update_content_blocker_lists(data);
});
- register_interface("setShowContentBlockerCount"sv, [this](auto const& data) {
- set_show_content_blocker_count(data);
- });
register_interface("addCustomContentBlockerSubscription"sv, [this](auto const& data) {
add_custom_content_blocker_subscription(data);
});
@@ -193,7 +193,6 @@ void SettingsUI::load_features()
features.set("primaryPaste"_string, application.supports_clipboard_type(Application::ClipboardType::Selection));
features.set("verticalTabs"_string, application.supports_vertical_tabs());
features.set("geolocation"_string, Core::GeolocationProvider::is_available());
- features.set("contentBlockingControls"_string, application.supports_content_blocking_controls());
async_send_message("loadFeatures"sv, move(features));
}
@@ -645,12 +644,18 @@ void SettingsUI::set_content_blocker_enabled(JsonValue const& enabled)
}
}
-void SettingsUI::set_show_content_blocker_count(JsonValue const& show)
+void SettingsUI::set_content_blocker_enabled_for_site(JsonValue const& value)
{
- if (!show.is_bool() || !Application::the().supports_content_blocking_controls())
+ if (!value.is_object())
+ return;
+
+ auto site = value.as_object().get_string("site"sv);
+ auto enabled = value.as_object().get_bool("enabled"sv);
+ if (!site.has_value() || !enabled.has_value())
return;
- Application::settings().set_show_content_blocker_count(show.as_bool());
+ if (auto result = Application::settings().set_content_blocker_enabled_for_site(*site, *enabled); result.is_error())
+ dbgln("Unable to change content blocking for {}: {}", *site, result.error());
}
void SettingsUI::set_content_blocker_list_enabled(JsonValue const& value)
diff --git a/Libraries/LibWebView/WebUI/SettingsUI.h b/Libraries/LibWebView/WebUI/SettingsUI.h
index 29359f8f7e4..f8a84fbfb1b 100644
--- a/Libraries/LibWebView/WebUI/SettingsUI.h
+++ b/Libraries/LibWebView/WebUI/SettingsUI.h
@@ -37,7 +37,6 @@ private:
virtual void geolocation_settings_changed() override { broadcast_settings_change(); }
virtual void background_networking_settings_changed() override { broadcast_settings_change(); }
virtual void content_blocker_settings_changed() override { broadcast_settings_change(); }
- virtual void content_blocker_count_visibility_changed() override { broadcast_settings_change(); }
void load_features();
@@ -77,7 +76,7 @@ private:
void set_filter_list_updates_enabled(JsonValue const&);
void update_content_blocker_lists(JsonValue const&);
void set_content_blocker_enabled(JsonValue const&);
- void set_show_content_blocker_count(JsonValue const&);
+ void set_content_blocker_enabled_for_site(JsonValue const&);
void set_content_blocker_list_enabled(JsonValue const&);
void add_custom_content_blocker_subscription(JsonValue const&);
void remove_content_blocker_list(JsonValue const&);
diff --git a/Tests/LibWebView/TestAutocomplete.cpp b/Tests/LibWebView/TestAutocomplete.cpp
index 0305b81280b..2b288818f62 100644
--- a/Tests/LibWebView/TestAutocomplete.cpp
+++ b/Tests/LibWebView/TestAutocomplete.cpp
@@ -228,12 +228,15 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
autocomplete.on_autocomplete_query_complete = [&](auto, auto const& suggestions, WebView::AutocompleteResultKind kind) {
if (kind != WebView::AutocompleteResultKind::Final)
return;
- VERIFY(!suggestions.is_empty());
- VERIFY(suggestions.first().text == "https://github.com/LadybirdBrowser/ladybird"sv);
- VERIFY(suggestions.first().title == "GH"sv);
- VERIFY(suggestions.first().match_class == WebView::AutocompleteMatchClass::ExactTitle);
- VERIFY(!suggestions.first().can_be_automatically_selected);
- VERIFY(!suggestions.first().can_be_inline_completed);
+ // NB: Without a search engine, the offer to choose one comes first, where the search would be.
+ VERIFY(suggestions.size() >= 2);
+ VERIFY(suggestions[0].source == WebView::AutocompleteSuggestionSource::ChooseSearchEngine);
+ auto const& bookmark = suggestions[1];
+ VERIFY(bookmark.text == "https://github.com/LadybirdBrowser/ladybird"sv);
+ VERIFY(bookmark.title == "GH"sv);
+ VERIFY(bookmark.match_class == WebView::AutocompleteMatchClass::ExactTitle);
+ VERIFY(!bookmark.can_be_automatically_selected);
+ VERIFY(!bookmark.can_be_inline_completed);
autocomplete.cancel_pending_query();
short_bookmark_query_completed = true;
};
@@ -241,6 +244,26 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
Core::EventLoop::current().spin_until([&]() { return short_bookmark_query_completed; });
}
+ auto choose_search_engine_query_completed = false;
+ {
+ WebView::Autocomplete autocomplete { WebView::IsPrivate::No };
+ autocomplete.on_autocomplete_query_complete = [&](auto, auto const& suggestions, WebView::AutocompleteResultKind kind) {
+ if (kind != WebView::AutocompleteResultKind::Final)
+ return;
+ VERIFY(!suggestions.is_empty());
+ auto const& suggestion = suggestions.first();
+ VERIFY(suggestion.source == WebView::AutocompleteSuggestionSource::ChooseSearchEngine);
+ VERIFY(suggestion.text == "about:settings#search"sv);
+ VERIFY(suggestion.subtitle == "to search for “ladybird beetle”"sv);
+ VERIFY(suggestion.can_be_automatically_selected);
+ VERIFY(WebView::autocomplete_suggestion_display_text(suggestion) == "ladybird beetle"sv);
+ autocomplete.cancel_pending_query();
+ choose_search_engine_query_completed = true;
+ };
+ autocomplete.query_autocomplete_engine(6, "ladybird beetle"_string);
+ Core::EventLoop::current().spin_until([&]() { return choose_search_engine_query_completed; });
+ }
+
WebView::Application::settings().set_search_engine_settings({
.engine = WebView::Application::settings().find_search_engine_by_name("Google"sv),
});
diff --git a/Tests/LibWebView/TestDownloadSegmentation.cpp b/Tests/LibWebView/TestDownloadSegmentation.cpp
index 8dcf9554199..902ddcb28cf 100644
--- a/Tests/LibWebView/TestDownloadSegmentation.cpp
+++ b/Tests/LibWebView/TestDownloadSegmentation.cpp
@@ -245,23 +245,50 @@ TEST_CASE(time_remaining_text)
return WebView::download_time_remaining_text(AK::Duration::from_seconds(seconds));
};
- EXPECT_EQ(text(0), "1 sec left"_string);
- EXPECT_EQ(text(45), "45 sec left"_string);
- EXPECT_EQ(text(59), "59 sec left"_string);
-
- EXPECT_EQ(text(60), "1 min left"_string);
- EXPECT_EQ(text(61), "2 min left"_string);
- EXPECT_EQ(text(59 * 60), "59 min left"_string);
-
- EXPECT_EQ(text(60 * 60), "1 hr 0 min left"_string);
- EXPECT_EQ(text(90 * 60), "1 hr 30 min left"_string);
- EXPECT_EQ(text(7199), "2 hr 0 min left"_string);
- EXPECT_EQ(text(25 * 60 * 60), "25 hr 0 min left"_string);
+ EXPECT_EQ(text(0), "1 second left"_string);
+ EXPECT_EQ(text(45), "45 seconds left"_string);
+ EXPECT_EQ(text(59), "59 seconds left"_string);
+
+ EXPECT_EQ(text(60), "1 minute left"_string);
+ EXPECT_EQ(text(61), "2 minutes left"_string);
+ EXPECT_EQ(text(59 * 60), "59 minutes left"_string);
+
+ EXPECT_EQ(text(60 * 60), "1 hour left"_string);
+ EXPECT_EQ(text(61 * 60), "1 hour 1 minute left"_string);
+ EXPECT_EQ(text(90 * 60), "1 hour 30 minutes left"_string);
+ EXPECT_EQ(text(7199), "2 hours left"_string);
+ EXPECT_EQ(text(25 * 60 * 60), "25 hours left"_string);
}
-TEST_CASE(rate_text)
+TEST_CASE(status_text)
{
- EXPECT_EQ(WebView::download_rate_text(512), "512 B/s"_string);
- EXPECT_EQ(WebView::download_rate_text(1536), "1.5 KiB/s"_string);
- EXPECT_EQ(WebView::download_rate_text(3 * MiB), "3.0 MiB/s"_string);
+ WebView::FileDownloader::Download download {
+ .id = 1,
+ .is_private = WebView::IsPrivate::No,
+ .url = URL::about_blank(),
+ .destination = LexicalPath { "/tmp/file"sv },
+ .status = WebView::FileDownloader::DownloadStatus::InProgress,
+ .downloaded_size = 12'400'000,
+ .total_size = 19'300'000,
+ .error = {},
+ .can_resume = true,
+ .connection_count = 1,
+ .bytes_per_second = 862'500,
+ .is_waiting_to_retry = false,
+ .created_time = {},
+ };
+ EXPECT_EQ(WebView::download_status_text(download), "12.4 of 19.3 MB · 8 seconds left"_string);
+
+ download.total_size = {};
+ EXPECT_EQ(WebView::download_status_text(download), "12.4 MB downloaded"_string);
+
+ download.status = WebView::FileDownloader::DownloadStatus::Completed;
+ download.downloaded_size = 4'200'000;
+ EXPECT_EQ(WebView::download_status_text(download), "4.2 MB"_string);
+ download.downloaded_size = 512;
+ EXPECT_EQ(WebView::download_status_text(download), "512 bytes"_string);
+
+ download.status = WebView::FileDownloader::DownloadStatus::Failed;
+ download.error = "The connection was interrupted"_string;
+ EXPECT_EQ(WebView::download_status_text(download), "Failed · The connection was interrupted"_string);
}
diff --git a/Tests/LibWebView/TestPictureInPictureWindowControls.cpp b/Tests/LibWebView/TestPictureInPictureWindowControls.cpp
index e8b1de1227f..391fa3bb5d1 100644
--- a/Tests/LibWebView/TestPictureInPictureWindowControls.cpp
+++ b/Tests/LibWebView/TestPictureInPictureWindowControls.cpp
@@ -170,12 +170,12 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
view->enable_picture_in_picture_controls();
- // The page logs where it is pressed, released and dragged, and its top-right corner has a cursor and tooltip of its
+ // The page logs where it is pressed, released and dragged, and its top-left corner has a cursor and tooltip of its
// own.
view->load_html(R"~~~(<!DOCTYPE html>
<title>page saw</title>
<body style="margin:0">
-<div title="Page tooltip" style="position:fixed;top:0;right:0;width:100px;height:100px;cursor:crosshair"></div>
+<div title="Page tooltip" style="position:fixed;top:0;left:0;width:100px;height:100px;cursor:crosshair"></div>
<script>
function log(name, event) { document.title += " " + name + " " + event.clientX; }
addEventListener("pointerdown", event => log("down", event));
@@ -186,11 +186,11 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)
Core::EventLoop::current().spin_until([&]() { return loads_finished >= 2; });
VERIFY(last_title == "page saw"sv);
- // The Close button is centred at (778, 22) and Back to tab at (22, 22). (790, 10) is in the corner of Close's bounds,
+ // The Close button is centred at (24, 24) and Back to tab at (776, 24). (11, 11) is in the corner of Close's bounds,
// over the page's corner but outside the round button.
- Web::DevicePixelPoint close_button { 778, 22 };
- Web::DevicePixelPoint back_to_tab_button { 22, 22 };
- Web::DevicePixelPoint corner_beside_close_button { 790, 10 };
+ Web::DevicePixelPoint close_button { 24, 24 };
+ Web::DevicePixelPoint back_to_tab_button { 776, 24 };
+ Web::DevicePixelPoint corner_beside_close_button { 11, 11 };
Web::DevicePixelPoint middle_of_page { 400, 300 };
move_mouse_to(*view, close_button);
@@ -230,7 +230,7 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)
click_at(*view, middle_of_page);
Core::EventLoop::current().spin_until([&]() { return last_title.ends_with(" up 400"sv); });
- VERIFY(last_title == "page saw down 790 up 790 down 778 up 778 down 400 up 400"sv);
+ VERIFY(last_title == "page saw down 11 up 11 down 24 up 24 down 400 up 400"sv);
outln("the page sees only the presses off the shown controls");
signal_renderers(SIGSTOP);
@@ -266,9 +266,11 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)
auto& window_view = WebView::ViewImplementation::find_view_by_handle(app->picture_in_picture_window_handle).value();
window_view.enable_picture_in_picture_controls();
auto window_size = app->picture_in_picture_window_size;
- Web::DevicePixelPoint player_control_bar { window_size.width() / 2, window_size.height() - 10 };
- Web::DevicePixelPoint window_close_button { window_size.width() - 22, 22 };
- Web::DevicePixelPoint middle_of_window { window_size.width() / 2, window_size.height() / 2 };
+ // The player's timeline is in the middle of the row along its bottom, inside 12 px of padding.
+ Web::DevicePixelPoint player_control_bar { window_size.width() / 2, window_size.height() - 23 };
+ Web::DevicePixelPoint window_close_button { 24, 24 };
+ // The player's play button is in the middle of the window, so the page is pressed and rested on beside it.
+ Web::DevicePixelPoint beside_play_button { window_size.width() / 4, window_size.height() / 2 };
// The player's control bar shows on the first move and is hovered from the next.
move_mouse_to(window_view, player_control_bar);
@@ -284,7 +286,7 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)
VERIFY(window_view.picture_in_picture_player_controls_are_shown_for_testing());
outln("the player's controls stay shown while a window control is hovered");
- move_mouse_to(window_view, middle_of_window);
+ move_mouse_to(window_view, beside_play_button);
Core::EventLoop::current().spin_until([&]() { return !window_view.picture_in_picture_controls_are_shown_for_testing(); });
VERIFY(!window_view.picture_in_picture_player_controls_are_shown_for_testing());
outln("both fade once the pointer rests away from them");
@@ -295,8 +297,8 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)
Optional<ByteString> window_tooltip;
window_view.on_enter_tooltip_area = [&](auto const& text) { window_tooltip = text; };
window_view.on_leave_tooltip_area = [&]() { window_tooltip.clear(); };
- move_mouse_to(window_view, middle_of_window);
- press_mouse_at(window_view, middle_of_window);
+ move_mouse_to(window_view, beside_play_button);
+ press_mouse_at(window_view, beside_play_button);
move_mouse_to(window_view, window_close_button, Web::UIEvents::MouseButton::Primary);
VERIFY(is_cursor(window_cursor, Gfx::StandardCursor::Hand));
VERIFY(window_tooltip == "Close"sv);
@@ -311,21 +313,21 @@ addEventListener("pointermove", event => { if (event.buttons) log("drag", event)
// The page sees none of a press on a control, even once the press moves off it.
move_mouse_to(window_view, window_close_button);
press_mouse_at(window_view, window_close_button);
- move_mouse_to(window_view, middle_of_window, Web::UIEvents::MouseButton::Primary);
+ move_mouse_to(window_view, beside_play_button, Web::UIEvents::MouseButton::Primary);
wait_for(1500);
VERIFY(window_view.picture_in_picture_player_controls_are_shown_for_testing());
- release_mouse_at(window_view, middle_of_window);
+ release_mouse_at(window_view, beside_play_button);
Core::EventLoop::current().spin_until([&]() {
return !window_view.picture_in_picture_controls_are_shown_for_testing() && !window_view.picture_in_picture_player_controls_are_shown_for_testing();
});
outln("the player's controls stay shown for the rest of a press on a window control");
// The controls are where the displayed frame shows them, at the pixel ratio it was painted at, until a frame at a new
- // ratio replaces it. (W - 18, 18) is inside Close at 1x but outside it at 2x, and (W - 44, 44) is the reverse.
+ // ratio replaces it. (16, 16) is inside Close at 1x but outside it at 2x, and (48, 48) is the reverse.
Vector<Compositing::PictureInPictureControl> window_activated_controls;
window_view.on_picture_in_picture_control_activated = [&](auto control) { window_activated_controls.append(control); };
- Web::DevicePixelPoint close_button_at_1x { window_size.width() - 18, 18 };
- Web::DevicePixelPoint close_button_at_2x { window_size.width() - 44, 44 };
+ Web::DevicePixelPoint close_button_at_1x { 16, 16 };
+ Web::DevicePixelPoint close_button_at_2x { 48, 48 };
signal_renderers(SIGSTOP);
window_view.set_device_pixel_ratio_for_testing(window_view.page(), 2.0);
diff --git a/Tests/LibWebView/TestSessionStore.cpp b/Tests/LibWebView/TestSessionStore.cpp
index d5c90765fba..bee91fd8f6b 100644
--- a/Tests/LibWebView/TestSessionStore.cpp
+++ b/Tests/LibWebView/TestSessionStore.cpp
@@ -824,6 +824,40 @@ TEST_CASE(retried_closes_keep_reopen_order)
EXPECT_EQ(older->tabs[0].active_url.serialize(), "https://a.example/"sv);
}
+TEST_CASE(any_recently_closed_unit_can_be_reopened)
+{
+ auto database = create_session_database();
+ auto store = TRY_OR_FAIL(SessionStore::create(*database));
+
+ auto window = TRY_OR_FAIL(store->window_opened());
+ Vector<StringView> urls { "https://a.example/"sv, "https://b.example/"sv, "https://c.example/"sv };
+ for (size_t i = 0; i < urls.size(); ++i) {
+ auto tab = TRY_OR_FAIL(store->tab_opened({ .window_id = window, .initial_url = parse_url("about:blank"sv), .insertion_index = {}, .is_active = SessionStore::IsActive::No }));
+ store->update_tab_state({ .tab_id = tab, .history = make_snapshot({ urls[i] }), .url = parse_url(urls[i]) });
+ TRY_OR_FAIL(store->tab_closed({ .tab_id = tab, .closed_at = UnixDateTime::from_seconds_since_epoch(100 + static_cast<i64>(i)) }));
+ }
+ store->flush_dirty_state();
+
+ auto closed = store->recently_closed_units(10);
+ EXPECT_EQ(closed.size(), 3u);
+ EXPECT_EQ(closed[0].active_url.serialize(), "https://c.example/"sv);
+ EXPECT_EQ(closed[1].active_url.serialize(), "https://b.example/"sv);
+ EXPECT_EQ(closed[2].active_url.serialize(), "https://a.example/"sv);
+ EXPECT_EQ(closed[0].closed_at, UnixDateTime::from_seconds_since_epoch(102));
+ EXPECT_EQ(store->recently_closed_units(2).size(), 2u);
+
+ auto middle = TRY_OR_FAIL(store->take_closed_unit(closed[1].id));
+ EXPECT(middle.has_value());
+ EXPECT_EQ(middle->tabs[0].active_url.serialize(), "https://b.example/"sv);
+ EXPECT(!TRY_OR_FAIL(store->take_closed_unit(closed[1].id)).has_value());
+
+ auto newest = TRY_OR_FAIL(store->take_most_recently_closed());
+ EXPECT_EQ(newest->tabs[0].active_url.serialize(), "https://c.example/"sv);
+ auto oldest = TRY_OR_FAIL(store->take_most_recently_closed());
+ EXPECT_EQ(oldest->tabs[0].active_url.serialize(), "https://a.example/"sv);
+ EXPECT(!store->has_closed_units());
+}
+
TEST_CASE(crashed_pending_close_recovers_a_contiguous_window)
{
auto database = create_session_database();
diff --git a/Tests/LibWebView/test-webdriver-content-blockers.py b/Tests/LibWebView/test-webdriver-content-blockers.py
index 062bd6a4d42..ad0d1d24779 100755
--- a/Tests/LibWebView/test-webdriver-content-blockers.py
+++ b/Tests/LibWebView/test-webdriver-content-blockers.py
@@ -144,53 +144,22 @@ with tempfile.TemporaryDirectory() as directory:
assert command("execute/sync", {"script": "return location.href", "args": []}) == "about:about"
command("url", {"url": "about:blocking"})
state = settings()
- assert state["contentBlockers"]["showBlockedCount"] is False
- features = command(
- "execute/async",
- {
- "script": """
- const done = arguments[arguments.length - 1];
- document.addEventListener('WebUIMessage', function receive(event) {
- if (event.detail.name !== 'loadFeatures') return;
- document.removeEventListener('WebUIMessage', receive);
- done(event.detail.data);
- });
- ladybird.sendMessage('loadFeatures');
- """,
- "args": [],
- },
- )
- display = command(
- "execute/sync",
- {
- "script": "return getComputedStyle(document.querySelector('#show-content-blocker-count-setting')).display",
- "args": [],
- },
- )
- assert (display != "none") == features["contentBlockingControls"]
- command("execute/sync", {"script": "ladybird.sendMessage('setShowContentBlockerCount', false)", "args": []})
- assert settings()["contentBlockers"]["showBlockedCount"] == (not features["contentBlockingControls"])
assert command(
"execute/sync",
{
"script": """
const tab = document.querySelector('[aria-selected="true"]');
const panel = document.querySelector('#tab-blocking');
- const description = panel.querySelector('#custom-content-blocker-subscription-url')
- .closest('.card-body').querySelector('.description');
- const form = description.nextElementSibling;
- const lists = panel.querySelector('#built-in-content-blocker-lists');
- const heading = panel.querySelector('.filter-list-header .card-title');
- const details = lists.querySelector('.description');
- const metadata = lists.querySelector('.filter-list-metadata');
- return location.hash === '#blocking' && tab.textContent === 'Blocking'
+ const lists = panel.querySelector('#content-blocker-lists');
+ const heading = panel.querySelector('.list-section .list-heading');
+ const details = lists.querySelector('.item-name .description');
+ const form = panel.querySelector('#add-filter-list-form');
+ return location.hash === '#blocking' && tab.textContent.trim() === 'Content blocking'
&& heading.getBoundingClientRect().left === lists.getBoundingClientRect().left
- && metadata.getBoundingClientRect().top >= details.getBoundingClientRect().bottom
- && getComputedStyle(metadata).fontSize === '12px'
- && metadata.textContent.includes('easylist.to') && !details.textContent.includes('easylist.to')
- && ['label', '.description', 'summary', 'textarea'].every(selector =>
- getComputedStyle(panel.querySelector(selector)).fontSize === '14px')
- && form.getBoundingClientRect().top - description.getBoundingClientRect().bottom >= 16;
+ && getComputedStyle(details).fontSize === '12px' && !details.textContent.includes('easylist.to')
+ && form.hidden
+ && ['label', 'summary', 'textarea'].every(selector =>
+ getComputedStyle(panel.querySelector(selector)).fontSize === '13px');
""",
"args": [],
},
diff --git a/Tests/LibWebView/test-webdriver-search-engine-settings.py b/Tests/LibWebView/test-webdriver-search-engine-settings.py
index 95b621c8abf..513b653676d 100755
--- a/Tests/LibWebView/test-webdriver-search-engine-settings.py
+++ b/Tests/LibWebView/test-webdriver-search-engine-settings.py
@@ -77,9 +77,8 @@ def run_test(webdriver_binary, graphical):
def select_engine(name):
change_settings(
"""
- const select = document.querySelector('#search-engine');
- select.value = parameters[0];
- select.dispatchEvent(new Event('change'));
+ [...document.querySelectorAll('#search-engine input')]
+ .find(radio => radio.value === parameters[0]).click();
""",
"(settings.searchEngine.engine || '') === parameters[0]",
name,
@@ -107,15 +106,18 @@ def run_test(webdriver_binary, graphical):
"script": """
const expectedEngine = arguments[0];
const done = arguments[1];
- const select = document.querySelector('#search-engine');
- function ready() { return select.value === expectedEngine && select.options.length > 10; }
+ const list = document.querySelector('#search-engine');
+ function ready() {
+ const radios = list.querySelectorAll('input');
+ return list.querySelector('input:checked')?.value === expectedEngine && radios.length > 10;
+ }
if (ready()) return done();
const observer = new MutationObserver(() => {
if (!ready()) return;
observer.disconnect();
done();
});
- observer.observe(select, {childList: true});
+ observer.observe(list, {childList: true});
""",
"args": [expected_engine],
},
diff --git a/Tests/LibWebView/test-webdriver-settings-changes.py b/Tests/LibWebView/test-webdriver-settings-changes.py
index d277cdf6fbf..f2787724df4 100644
--- a/Tests/LibWebView/test-webdriver-settings-changes.py
+++ b/Tests/LibWebView/test-webdriver-settings-changes.py
@@ -174,14 +174,14 @@ def run_test(webdriver_binary):
{
"script": """
const done = arguments[0];
- const button = document.querySelector('#start-browsing');
- if (!button.disabled) return done();
+ const options = document.querySelector('#setup-options');
+ if (!options.disabled) return done();
const observer = new MutationObserver(() => {
- if (button.disabled) return;
+ if (options.disabled) return;
observer.disconnect();
done();
});
- observer.observe(button, {attributes: true, attributeFilter: ['disabled']});
+ observer.observe(options, {attributes: true, attributeFilter: ['disabled']});
""",
"args": [],
},
@@ -189,8 +189,8 @@ def run_test(webdriver_binary):
changes = change("setSearchEngineSettings", {"engine": "Google", "suggestions": True})
assert set(changes) == {"searchEngine"}, changes
assert script("""
- return document.querySelector('#search-engine').value === 'Google'
- && document.querySelector('#search-suggestions-enabled').checked;
+ return document.querySelector('input[name="search-engine"]:checked')?.value === 'Google'
+ && !document.querySelector('#start-browsing').disabled;
"""), "The welcome page did not apply a partial search setting"
changes = change("setContentBlockerEnabled", False)
assert set(changes) == {"contentBlockers"}, changes