#include "components/spellcheck/renderer/spellcheck.h"
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <string_view>
#include <utility>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/spellcheck/common/spellcheck_common.h"
#include "components/spellcheck/common/spellcheck_features.h"
#include "components/spellcheck/common/spellcheck_result.h"
#include "components/spellcheck/renderer/spellcheck_language.h"
#include "components/spellcheck/renderer/spellcheck_provider.h"
#include "components/spellcheck/renderer/spellcheck_renderer_metrics.h"
#include "components/spellcheck/spellcheck_buildflags.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_visitor.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_text_checking_completion.h"
#include "third_party/blink/public/web/web_text_checking_result.h"
#include "third_party/blink/public/web/web_text_decoration_type.h"
WebVector;
WebString;
WebTextCheckingResult;
WebTextDecorationType;
namespace {
class UpdateSpellcheckEnabled : public content::RenderFrameVisitor { … };
bool UpdateSpellcheckEnabled::Visit(content::RenderFrame* render_frame) { … }
WebVector<WebString> ConvertToWebStringFromUtf8(
const std::set<std::string>& words) { … }
bool IsApostrophe(char16_t c) { … }
void PreserveOriginalApostropheTypes(const std::u16string& misspelled_word,
std::u16string* spelling_suggestion) { … }
std::vector<WebString> FilterReplacementSuggestions(
const std::u16string& misspelled_word,
const std::vector<std::u16string>& replacements) { … }
}
class SpellCheck::SpellcheckRequest { … };
SpellCheck::SpellCheck(
service_manager::LocalInterfaceProvider* embedder_provider)
: … { … }
SpellCheck::~SpellCheck() = default;
void SpellCheck::BindReceiver(
mojo::PendingReceiver<spellcheck::mojom::SpellChecker> receiver) { … }
void SpellCheck::Initialize(
std::vector<spellcheck::mojom::SpellCheckBDictLanguagePtr> dictionaries,
const std::vector<std::string>& custom_words,
bool enable) { … }
void SpellCheck::CustomDictionaryChanged(
const std::vector<std::string>& words_added,
const std::vector<std::string>& words_removed) { … }
void SpellCheck::AddSpellcheckLanguage(base::File file,
const std::string& language) { … }
bool SpellCheck::SpellCheckWord(std::u16string_view text,
spellcheck::mojom::SpellCheckHost& host,
size_t* misspelling_start,
size_t* misspelling_len,
std::nullptr_t null_suggestions_ptr) { … }
bool SpellCheck::SpellCheckWord(
std::u16string_view text,
spellcheck::mojom::SpellCheckHost& host,
size_t* misspelling_start,
size_t* misspelling_len,
std::vector<std::u16string>* optional_suggestions) { … }
bool SpellCheck::SpellCheckWord(
std::u16string_view text,
spellcheck::mojom::SpellCheckHost& host,
size_t* misspelling_start,
size_t* misspelling_len,
spellcheck::PerLanguageSuggestions* optional_per_language_suggestions) { … }
#if BUILDFLAG(USE_RENDERER_SPELLCHECKER)
bool SpellCheck::SpellCheckParagraph(
const std::u16string& text,
spellcheck::mojom::SpellCheckHost& host,
WebVector<WebTextCheckingResult>* results) { … }
void SpellCheck::RequestTextChecking(
const std::u16string& text,
std::unique_ptr<blink::WebTextCheckingCompletion> completion,
base::WeakPtr<SpellCheckProvider> provider) { … }
#endif
bool SpellCheck::InitializeIfNeeded() { … }
#if BUILDFLAG(USE_RENDERER_SPELLCHECKER)
void SpellCheck::PostDelayedSpellCheckTask(SpellcheckRequest* request) { … }
#endif
#if BUILDFLAG(USE_RENDERER_SPELLCHECKER)
void SpellCheck::PerformSpellCheck(SpellcheckRequest* param) { … }
#endif
void SpellCheck::CreateTextCheckingResults(
ResultFilter filter,
spellcheck::mojom::SpellCheckHost& host,
int line_offset,
const std::u16string& line_text,
const std::vector<SpellCheckResult>& spellcheck_results,
WebVector<WebTextCheckingResult>* textcheck_results) { … }
bool SpellCheck::IsSpellcheckEnabled() { … }
void SpellCheck::AddDictionaryUpdateObserver(
DictionaryUpdateObserver* observer) { … }
void SpellCheck::RemoveDictionaryUpdateObserver(
DictionaryUpdateObserver* observer) { … }
size_t SpellCheck::LanguageCount() { … }
size_t SpellCheck::EnabledLanguageCount() { … }
void SpellCheck::NotifyDictionaryObservers(
const WebVector<WebString>& words_added) { … }
bool SpellCheck::IsWordInSupportedScript(const std::u16string& word) const { … }