Skip to content

Truly independent web browser

LibWebView: Use OpenSearch parser for DuckDuckGo autocomplete

Timothy Flynndc648797fef0
diff --git a/Libraries/LibWebView/Autocomplete.cpp b/Libraries/LibWebView/Autocomplete.cpp
index 9c97add7a35..30860c5462d 100644
--- a/Libraries/LibWebView/Autocomplete.cpp
+++ b/Libraries/LibWebView/Autocomplete.cpp
@@ -629,27 +629,6 @@ void Autocomplete::deliver_current_result()
invoke_autocomplete_query_complete(*m_query_id, move(merged_suggestions), result_kind);
}
-static ErrorOr<Vector<String>> parse_duckduckgo_autocomplete(JsonValue const& json)
-{
- if (!json.is_array())
- return Error::from_string_literal("Expected DuckDuckGo autocomplete response to be a JSON array");
-
- Vector<String> results;
- results.ensure_capacity(json.as_array().size());
-
- TRY(json.as_array().try_for_each([&](JsonValue const& suggestion) -> ErrorOr<void> {
- if (!suggestion.is_object())
- return Error::from_string_literal("Invalid DuckDuckGo autocomplete response, expected value to be an object");
-
- if (auto value = suggestion.as_object().get_string("phrase"sv); value.has_value())
- results.unchecked_append(*value);
-
- return {};
- }));
-
- return results;
-}
-
static ErrorOr<Vector<String>> parse_opensearch_autocomplete(JsonValue const& json)
{
if (!json.is_array())
@@ -724,8 +703,6 @@ ErrorOr<Vector<String>> Autocomplete::received_autocomplete_response(SearchSugge
auto json = TRY(JsonValue::from_string(decoded_response));
switch (provider.response_format) {
- case SearchSuggestionsFormat::DuckDuckGo:
- return parse_duckduckgo_autocomplete(json);
case SearchSuggestionsFormat::OpenSearch:
return parse_opensearch_autocomplete(json);
case SearchSuggestionsFormat::Yahoo:
diff --git a/Libraries/LibWebView/SearchEngine.cpp b/Libraries/LibWebView/SearchEngine.cpp
index c587ae049a4..36b5b23c24a 100644
--- a/Libraries/LibWebView/SearchEngine.cpp
+++ b/Libraries/LibWebView/SearchEngine.cpp
@@ -14,7 +14,7 @@ namespace WebView {
static auto const& s_builtin_search_engines = *new auto(to_array<SearchEngine>({
{ "Bing"_string, "https://www.bing.com/search?q=%s"_string, SearchSuggestions { "https://www.bing.com/osjson.aspx?query=%s"_string } },
{ "Brave"_string, "https://search.brave.com/search?q=%s"_string, SearchSuggestions { "https://search.brave.com/api/suggest?q=%s"_string } },
- { "DuckDuckGo"_string, "https://duckduckgo.com/?q=%s"_string, SearchSuggestions { "https://duckduckgo.com/ac/?q=%s"_string, SearchSuggestionsFormat::DuckDuckGo } },
+ { "DuckDuckGo"_string, "https://duckduckgo.com/?q=%s"_string, SearchSuggestions { "https://duckduckgo.com/ac/?q=%s&type=list"_string } },
{ "Ecosia"_string, "https://ecosia.org/search?q=%s"_string, SearchSuggestions { "https://ac.ecosia.org/autocomplete?q=%s&type=list"_string } },
{ "Google"_string, "https://www.google.com/search?q=%s"_string, SearchSuggestions { "https://www.google.com/complete/search?client=chrome&q=%s"_string } },
{ "Kagi"_string, "https://kagi.com/search?q=%s"_string, SearchSuggestions { "https://kagisuggest.com/api/autosuggest?q=%s"_string } },
diff --git a/Libraries/LibWebView/SearchEngine.h b/Libraries/LibWebView/SearchEngine.h
index 2bab7486f7b..8c853db197e 100644
--- a/Libraries/LibWebView/SearchEngine.h
+++ b/Libraries/LibWebView/SearchEngine.h
@@ -17,7 +17,6 @@ namespace WebView {
enum class SearchSuggestionsFormat : u8 {
OpenSearch,
- DuckDuckGo,
Yahoo,
};