LibWebView: Support custom search engines

This allows the user to store custom search engines via about:settings.
Custom engines will be displayed below the builtin engines in the drop-
down to select the default engine.

A couple of edge cases here:

1. We currently reject a custom engine if one with the same name already
   exists. In the future, we should allow editing custom engines.

2. If a custom engine which was the default engine is removed, we will
   disable search rather than falling back to any other engine.
This commit is contained in:
Timothy Flynn 2025-04-04 18:12:32 -04:00 committed by Andreas Kling
commit 2810071a9c
Notes: github-actions[bot] 2025-04-06 11:46:03 +00:00
7 changed files with 317 additions and 28 deletions

View file

@ -4,13 +4,12 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Find.h>
#include <LibURL/URL.h>
#include <LibWebView/SearchEngine.h>
namespace WebView {
static auto builtin_search_engines = to_array<SearchEngine>({
static auto s_builtin_search_engines = to_array<SearchEngine>({
{ "Bing"_string, "https://www.bing.com/search?q=%s"_string },
{ "Brave"_string, "https://search.brave.com/search?q=%s"_string },
{ "DuckDuckGo"_string, "https://duckduckgo.com/?q=%s"_string },
@ -23,16 +22,9 @@ static auto builtin_search_engines = to_array<SearchEngine>({
{ "Yandex"_string, "https://yandex.com/search/?text=%s"_string },
});
ReadonlySpan<SearchEngine> search_engines()
ReadonlySpan<SearchEngine> builtin_search_engines()
{
return builtin_search_engines;
}
Optional<SearchEngine> find_search_engine_by_name(StringView name)
{
return find_value(builtin_search_engines, [&](auto const& engine) {
return engine.name == name;
});
return s_builtin_search_engines;
}
String SearchEngine::format_search_query_for_display(StringView query) const