mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 01:41:59 -05:00
LibWebView: Define the list of built-in search engines in LibWebView
These engines and their query URLs are duplicated in several places. Before implementing search support in the AppKit chrome, let's move these engines to LibWebView.
This commit is contained in:
parent
10428fc7ce
commit
b770ed03ac
4 changed files with 74 additions and 0 deletions
|
@ -9,6 +9,7 @@ set(SOURCES
|
|||
DOMTreeModel.cpp
|
||||
History.cpp
|
||||
RequestServerAdapter.cpp
|
||||
SearchEngine.cpp
|
||||
SourceHighlighter.cpp
|
||||
StylePropertiesModel.cpp
|
||||
URL.cpp
|
||||
|
|
|
@ -19,6 +19,7 @@ class ViewImplementation;
|
|||
class WebContentClient;
|
||||
|
||||
struct CookieStorageKey;
|
||||
struct SearchEngine;
|
||||
|
||||
}
|
||||
|
||||
|
|
49
Userland/Libraries/LibWebView/SearchEngine.cpp
Normal file
49
Userland/Libraries/LibWebView/SearchEngine.cpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Find.h>
|
||||
#include <LibWebView/SearchEngine.h>
|
||||
|
||||
namespace WebView {
|
||||
|
||||
static constexpr auto builtin_search_engines = Array {
|
||||
SearchEngine { "Bing"sv, "https://www.bing.com/search?q={}"sv },
|
||||
SearchEngine { "Brave"sv, "https://search.brave.com/search?q={}"sv },
|
||||
SearchEngine { "DuckDuckGo"sv, "https://duckduckgo.com/?q={}"sv },
|
||||
SearchEngine { "GitHub"sv, "https://github.com/search?q={}"sv },
|
||||
SearchEngine { "Google"sv, "https://www.google.com/search?q={}"sv },
|
||||
SearchEngine { "Mojeek"sv, "https://www.mojeek.com/search?q={}"sv },
|
||||
SearchEngine { "Yahoo"sv, "https://search.yahoo.com/search?p={}"sv },
|
||||
SearchEngine { "Yandex"sv, "https://yandex.com/search/?text={}"sv },
|
||||
};
|
||||
|
||||
ReadonlySpan<SearchEngine> search_engines()
|
||||
{
|
||||
return builtin_search_engines;
|
||||
}
|
||||
|
||||
SearchEngine const& default_search_engine()
|
||||
{
|
||||
static auto default_engine = find_search_engine("Google"sv);
|
||||
VERIFY(default_engine.has_value());
|
||||
|
||||
return *default_engine;
|
||||
}
|
||||
|
||||
Optional<SearchEngine const&> find_search_engine(StringView name)
|
||||
{
|
||||
auto it = AK::find_if(builtin_search_engines.begin(), builtin_search_engines.end(),
|
||||
[&](auto const& engine) {
|
||||
return engine.name == name;
|
||||
});
|
||||
|
||||
if (it == builtin_search_engines.end())
|
||||
return {};
|
||||
|
||||
return *it;
|
||||
}
|
||||
|
||||
}
|
23
Userland/Libraries/LibWebView/SearchEngine.h
Normal file
23
Userland/Libraries/LibWebView/SearchEngine.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Span.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace WebView {
|
||||
|
||||
struct SearchEngine {
|
||||
StringView name;
|
||||
StringView query_url;
|
||||
};
|
||||
|
||||
ReadonlySpan<SearchEngine> search_engines();
|
||||
SearchEngine const& default_search_engine();
|
||||
Optional<SearchEngine const&> find_search_engine(StringView name);
|
||||
|
||||
}
|
Loading…
Reference in a new issue