1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Libraries/LibWebView/Autocomplete.h
Timothy Flynn 5e9a11b13d LibWebView: Respect autocomplete response Content-Encoding headers
For example, Google uses ISO-8859-1 encoding. This patch allows us to
decode such responses, falling back to UTF-8 if a Content-Type was not
specified or could not be parsed. We should also now handle if decoding
fails, rather than crashing inside JsonParser.
2025-04-17 07:51:43 -04:00

44 lines
1.1 KiB
C++

/*
* Copyright (c) 2023, Cameron Youell <cameronyouell@gmail.com>
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Error.h>
#include <AK/Function.h>
#include <AK/RefPtr.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibRequests/Forward.h>
namespace WebView {
struct AutocompleteEngine {
StringView name;
StringView query_url;
};
ReadonlySpan<AutocompleteEngine> autocomplete_engines();
Optional<AutocompleteEngine const&> find_autocomplete_engine_by_name(StringView name);
class Autocomplete {
public:
Autocomplete();
~Autocomplete();
Function<void(Vector<String>)> on_autocomplete_query_complete;
void query_autocomplete_engine(String);
private:
static ErrorOr<Vector<String>> received_autocomplete_respsonse(AutocompleteEngine const&, Optional<ByteString const&> content_type, StringView response);
void invoke_autocomplete_query_complete(Vector<String> suggestions) const;
String m_query;
RefPtr<Requests::Request> m_request;
};
}