mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWebView: Store search engine names/URLs as String
In order to support custom search engines, we will need to store the engine properties as String to hold user-provided data. This also caused a compile error trying to assign Optional<SearchEngine> to Optional<SearchEngine const&>, so there's a bit of extra churn here.
This commit is contained in:
parent
7f37a8f60f
commit
cbee476dac
Notes:
github-actions[bot]
2025-04-06 11:46:16 +00:00
Author: https://github.com/trflynn89
Commit: cbee476dac
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4237
2 changed files with 19 additions and 19 deletions
|
@ -1,34 +1,33 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Find.h>
|
#include <AK/Find.h>
|
||||||
#include <AK/String.h>
|
|
||||||
#include <LibWebView/SearchEngine.h>
|
#include <LibWebView/SearchEngine.h>
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
|
||||||
static constexpr auto builtin_search_engines = Array {
|
static auto builtin_search_engines = to_array<SearchEngine>({
|
||||||
SearchEngine { "Bing"sv, "https://www.bing.com/search?q={}"sv },
|
{ "Bing"_string, "https://www.bing.com/search?q={}"_string },
|
||||||
SearchEngine { "Brave"sv, "https://search.brave.com/search?q={}"sv },
|
{ "Brave"_string, "https://search.brave.com/search?q={}"_string },
|
||||||
SearchEngine { "DuckDuckGo"sv, "https://duckduckgo.com/?q={}"sv },
|
{ "DuckDuckGo"_string, "https://duckduckgo.com/?q={}"_string },
|
||||||
SearchEngine { "Ecosia"sv, "https://ecosia.org/search?q={}"sv },
|
{ "Ecosia"_string, "https://ecosia.org/search?q={}"_string },
|
||||||
SearchEngine { "Google"sv, "https://www.google.com/search?q={}"sv },
|
{ "Google"_string, "https://www.google.com/search?q={}"_string },
|
||||||
SearchEngine { "Kagi"sv, "https://kagi.com/search?q={}"sv },
|
{ "Kagi"_string, "https://kagi.com/search?q={}"_string },
|
||||||
SearchEngine { "Mojeek"sv, "https://www.mojeek.com/search?q={}"sv },
|
{ "Mojeek"_string, "https://www.mojeek.com/search?q={}"_string },
|
||||||
SearchEngine { "Startpage"sv, "https://startpage.com/search?q={}"sv },
|
{ "Startpage"_string, "https://startpage.com/search?q={}"_string },
|
||||||
SearchEngine { "Yahoo"sv, "https://search.yahoo.com/search?p={}"sv },
|
{ "Yahoo"_string, "https://search.yahoo.com/search?p={}"_string },
|
||||||
SearchEngine { "Yandex"sv, "https://yandex.com/search/?text={}"sv },
|
{ "Yandex"_string, "https://yandex.com/search/?text={}"_string },
|
||||||
};
|
});
|
||||||
|
|
||||||
ReadonlySpan<SearchEngine> search_engines()
|
ReadonlySpan<SearchEngine> search_engines()
|
||||||
{
|
{
|
||||||
return builtin_search_engines;
|
return builtin_search_engines;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<SearchEngine const&> find_search_engine_by_name(StringView name)
|
Optional<SearchEngine> find_search_engine_by_name(StringView name)
|
||||||
{
|
{
|
||||||
return find_value(builtin_search_engines, [&](auto const& engine) {
|
return find_value(builtin_search_engines, [&](auto const& engine) {
|
||||||
return engine.name == name;
|
return engine.name == name;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,17 +7,18 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Span.h>
|
#include <AK/Span.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
|
||||||
struct SearchEngine {
|
struct SearchEngine {
|
||||||
StringView name;
|
String name;
|
||||||
StringView query_url;
|
String query_url;
|
||||||
};
|
};
|
||||||
|
|
||||||
ReadonlySpan<SearchEngine> search_engines();
|
ReadonlySpan<SearchEngine> search_engines();
|
||||||
Optional<SearchEngine const&> find_search_engine_by_name(StringView name);
|
Optional<SearchEngine> find_search_engine_by_name(StringView name);
|
||||||
Optional<SearchEngine const&> find_search_engine_by_query_url(StringView query_url);
|
Optional<SearchEngine const&> find_search_engine_by_query_url(StringView query_url);
|
||||||
String format_search_query_for_display(StringView query_url, StringView query);
|
String format_search_query_for_display(StringView query_url, StringView query);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue