Truly independent web browser
LibWebView: Use OpenSearch parser for Yahoo autocomplete
Timothy Flynn60c0cf5ff9f9
diff --git a/Libraries/LibWebView/Autocomplete.cpp b/Libraries/LibWebView/Autocomplete.cppindex 30860c5462d..a5a469846c4 100644--- a/Libraries/LibWebView/Autocomplete.cpp+++ b/Libraries/LibWebView/Autocomplete.cpp@@ -652,34 +652,7 @@ static ErrorOr<Vector<String>> parse_opensearch_autocomplete(JsonValue const& jsreturn results;}-static ErrorOr<Vector<String>> parse_yahoo_autocomplete(JsonValue const& json)-{- if (!json.is_object())- return Error::from_string_literal("Expected Yahoo autocomplete response to be a JSON array");-- auto suggestions = json.as_object().get_array("r"sv);- if (!suggestions.has_value())- return Error::from_string_literal("Invalid Yahoo autocomplete response, expected \"r\" to be an object");-- Vector<String> results;- results.ensure_capacity(suggestions->size());-- TRY(suggestions->try_for_each([&](JsonValue const& suggestion) -> ErrorOr<void> {- if (!suggestion.is_object())- return Error::from_string_literal("Invalid Yahoo autocomplete response, expected value to be an object");-- auto result = suggestion.as_object().get_string("k"sv);- if (!result.has_value())- return Error::from_string_literal("Invalid Yahoo autocomplete response, expected \"k\" to be a string");-- results.unchecked_append(*result);- return {};- }));-- return results;-}--ErrorOr<Vector<String>> Autocomplete::received_autocomplete_response(SearchSuggestions const& provider, Optional<ByteString const&> content_type, StringView response)+ErrorOr<Vector<String>> Autocomplete::received_autocomplete_response(SearchSuggestions const&, Optional<ByteString const&> content_type, StringView response){auto decoder = [&]() -> Optional<TextCodec::Decoder> {if (!content_type.has_value())@@ -702,13 +675,7 @@ ErrorOr<Vector<String>> Autocomplete::received_autocomplete_response(SearchSuggeauto decoded_response = TRY(TextCodec::decode_to_utf8(response.bytes(), *decoder));auto json = TRY(JsonValue::from_string(decoded_response));- switch (provider.response_format) {- case SearchSuggestionsFormat::OpenSearch:- return parse_opensearch_autocomplete(json);- case SearchSuggestionsFormat::Yahoo:- return parse_yahoo_autocomplete(json);- }- VERIFY_NOT_REACHED();+ return parse_opensearch_autocomplete(json);}void Autocomplete::invoke_autocomplete_query_complete(AutocompleteQueryID query_id, Vector<AutocompleteSuggestion> suggestions, AutocompleteResultKind result_kind) constdiff --git a/Libraries/LibWebView/SearchEngine.cpp b/Libraries/LibWebView/SearchEngine.cppindex 36b5b23c24a..05bea1240da 100644--- a/Libraries/LibWebView/SearchEngine.cpp+++ b/Libraries/LibWebView/SearchEngine.cpp@@ -20,7 +20,7 @@ static auto const& s_builtin_search_engines = *new auto(to_array<SearchEngine>({{ "Kagi"_string, "https://kagi.com/search?q=%s"_string, SearchSuggestions { "https://kagisuggest.com/api/autosuggest?q=%s"_string } },{ "Mojeek"_string, "https://www.mojeek.com/search?q=%s"_string },{ "Startpage"_string, "https://startpage.com/search?q=%s"_string, SearchSuggestions { "https://www.startpage.com/osuggestions?q=%s"_string } },- { "Yahoo"_string, "https://search.yahoo.com/search?p=%s"_string, SearchSuggestions { "https://search.yahoo.com/sugg/gossip/gossip-us-ura/?output=sd1&command=%s"_string, SearchSuggestionsFormat::Yahoo } },+ { "Yahoo"_string, "https://search.yahoo.com/search?p=%s"_string, SearchSuggestions { "https://search.yahoo.com/sugg/gossip/gossip-us-ura/?output=fxjson&command=%s"_string } },{ "Yandex"_string, "https://yandex.com/search/?text=%s"_string, SearchSuggestions { "https://suggest.yandex.com/suggest-ff.cgi?part=%s&uil=en&v=3"_string } },}));diff --git a/Libraries/LibWebView/SearchEngine.h b/Libraries/LibWebView/SearchEngine.hindex 8c853db197e..6697c0e1196 100644--- a/Libraries/LibWebView/SearchEngine.h+++ b/Libraries/LibWebView/SearchEngine.h@@ -15,14 +15,8 @@namespace WebView {-enum class SearchSuggestionsFormat : u8 {- OpenSearch,- Yahoo,-};-struct SearchSuggestions {String query_url;- SearchSuggestionsFormat response_format { SearchSuggestionsFormat::OpenSearch };};struct SearchEngine {