summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-c30a6232df03e1efbd9f3b226777b07e087a1122.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc')
-rw-r--r--chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc82
1 files changed, 48 insertions, 34 deletions
diff --git a/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc b/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
index 25feeebf536..5272b99db1d 100644
--- a/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
+++ b/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc
@@ -90,48 +90,54 @@ bool SaveDictionaryData(std::unique_ptr<std::string> data,
} // namespace
-SpellcheckHunspellDictionary::DictionaryFile::DictionaryFile() {
-}
+SpellcheckHunspellDictionary::DictionaryFile::DictionaryFile(
+ base::TaskRunner* task_runner) : task_runner_(task_runner) {}
SpellcheckHunspellDictionary::DictionaryFile::~DictionaryFile() {
+ if (file.IsValid()) {
+ task_runner_->PostTask(FROM_HERE,
+ base::BindOnce(&CloseDictionary, std::move(file)));
+ }
}
SpellcheckHunspellDictionary::DictionaryFile::DictionaryFile(
DictionaryFile&& other)
- : path(other.path), file(std::move(other.file)) {}
+ : path(other.path),
+ file(std::move(other.file)),
+ task_runner_(std::move(other.task_runner_)) {}
SpellcheckHunspellDictionary::DictionaryFile&
SpellcheckHunspellDictionary::DictionaryFile::operator=(
DictionaryFile&& other) {
path = other.path;
file = std::move(other.file);
+ task_runner_ = std::move(other.task_runner_);
return *this;
}
SpellcheckHunspellDictionary::SpellcheckHunspellDictionary(
const std::string& language,
+ const std::string& platform_spellcheck_language,
content::BrowserContext* browser_context,
SpellcheckService* spellcheck_service)
: task_runner_(
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})),
language_(language),
+ platform_spellcheck_language_(platform_spellcheck_language),
use_browser_spellchecker_(false),
browser_context_(browser_context),
spellcheck_service_(spellcheck_service),
- download_status_(DOWNLOAD_NONE) {}
+ download_status_(DOWNLOAD_NONE),
+ dictionary_file_(task_runner_.get()) {}
SpellcheckHunspellDictionary::~SpellcheckHunspellDictionary() {
- if (dictionary_file_.file.IsValid()) {
- task_runner_->PostTask(
- FROM_HERE,
- base::BindOnce(&CloseDictionary, std::move(dictionary_file_.file)));
- }
-
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Disable the language from platform spellchecker.
- if (spellcheck::UseBrowserSpellChecker())
+ if (spellcheck::UseBrowserSpellChecker() && HasPlatformSupport()) {
spellcheck_platform::DisableLanguage(
- spellcheck_service_->platform_spell_checker(), language_);
+ spellcheck_service_->platform_spell_checker(),
+ GetPlatformSpellcheckLanguage());
+ }
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
}
@@ -140,9 +146,10 @@ void SpellcheckHunspellDictionary::Load() {
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
if (spellcheck::UseBrowserSpellChecker() &&
- spellcheck_platform::SpellCheckerAvailable()) {
+ spellcheck_platform::SpellCheckerAvailable() && HasPlatformSupport()) {
spellcheck_platform::PlatformSupportsLanguage(
- spellcheck_service_->platform_spell_checker(), language_,
+ spellcheck_service_->platform_spell_checker(),
+ GetPlatformSpellcheckLanguage(),
base::BindOnce(
&SpellcheckHunspellDictionary::PlatformSupportsLanguageComplete,
weak_ptr_factory_.GetWeakPtr()));
@@ -177,6 +184,21 @@ const std::string& SpellcheckHunspellDictionary::GetLanguage() const {
return language_;
}
+const std::string& SpellcheckHunspellDictionary::GetPlatformSpellcheckLanguage()
+ const {
+#if defined(OS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+ // Currently the platform spellcheck language is only distinguished for
+ // Windows.
+ return platform_spellcheck_language_;
+#else
+ return language_;
+#endif // defined(OS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
+}
+
+bool SpellcheckHunspellDictionary::HasPlatformSupport() const {
+ return !GetPlatformSpellcheckLanguage().empty();
+}
+
bool SpellcheckHunspellDictionary::IsUsingPlatformChecker() const {
return use_browser_spellchecker_;
}
@@ -308,13 +330,14 @@ void SpellcheckHunspellDictionary::DownloadDictionary(GURL url) {
base::Unretained(this)));
// Attempt downloading the dictionary only once.
- browser_context_ = NULL;
+ browser_context_ = nullptr;
}
#if !defined(OS_ANDROID)
// static
SpellcheckHunspellDictionary::DictionaryFile
-SpellcheckHunspellDictionary::OpenDictionaryFile(const base::FilePath& path) {
+SpellcheckHunspellDictionary::OpenDictionaryFile(base::TaskRunner* task_runner,
+ const base::FilePath& path) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
@@ -325,7 +348,7 @@ SpellcheckHunspellDictionary::OpenDictionaryFile(const base::FilePath& path) {
// For systemwide installations on Windows, the default directory may not
// have permissions for download. In that case, the alternate directory for
// download is chrome::DIR_USER_DATA.
- DictionaryFile dictionary;
+ DictionaryFile dictionary(task_runner);
#if defined(OS_WIN)
// Check if the dictionary exists in the fallback location. If so, use it
@@ -367,7 +390,7 @@ SpellcheckHunspellDictionary::OpenDictionaryFile(const base::FilePath& path) {
// static
SpellcheckHunspellDictionary::DictionaryFile
SpellcheckHunspellDictionary::InitializeDictionaryLocation(
- const std::string& language) {
+ base::TaskRunner* task_runner, const std::string& language) {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
@@ -382,7 +405,7 @@ SpellcheckHunspellDictionary::InitializeDictionaryLocation(
base::FilePath dict_path =
spellcheck::GetVersionedFileName(language, dict_dir);
- return OpenDictionaryFile(dict_path);
+ return OpenDictionaryFile(task_runner, dict_path);
}
void SpellcheckHunspellDictionary::InitializeDictionaryLocationComplete(
@@ -396,7 +419,7 @@ void SpellcheckHunspellDictionary::InitializeDictionaryLocationComplete(
// TODO(rouslan): Remove this test-only case.
if (spellcheck_service_->SignalStatusEvent(
SpellcheckService::BDICT_CORRUPTED)) {
- browser_context_ = NULL;
+ browser_context_ = nullptr;
}
if (browser_context_) {
@@ -443,9 +466,10 @@ void SpellcheckHunspellDictionary::PlatformSupportsLanguageComplete(
if (platform_supports_language) {
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
- if (spellcheck::UseBrowserSpellChecker()) {
+ if (spellcheck::UseBrowserSpellChecker() && HasPlatformSupport()) {
spellcheck_platform::SetLanguage(
- spellcheck_service_->platform_spell_checker(), language_,
+ spellcheck_service_->platform_spell_checker(),
+ GetPlatformSpellcheckLanguage(),
base::BindOnce(&SpellcheckHunspellDictionary::
SpellCheckPlatformSetLanguageComplete,
weak_ptr_factory_.GetWeakPtr()));
@@ -454,24 +478,14 @@ void SpellcheckHunspellDictionary::PlatformSupportsLanguageComplete(
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
NOTREACHED();
} else {
-#if defined(OS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
- // The platform spellchecker doesn't support this language. Fall back to
- // Hunspell, unless the hybrid spellchecker is disabled.
- if (spellcheck::UseBrowserSpellChecker() &&
- !spellcheck::UseWinHybridSpellChecker()) {
- // Can't fall back to Hunspell, because the hybrid spellchecker is not
- // enabled. We can't spellcheck this language, so there's no further
- // processing to do.
- return;
- }
-#endif // defined(OS_WIN) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Either the platform spellchecker is unavailable / disabled, or it doesn't
// support this language. In either case, we must use Hunspell for this
// language, unless we are on Android, which doesn't support Hunspell.
#if !defined(OS_ANDROID) && BUILDFLAG(USE_RENDERER_SPELLCHECKER)
base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE,
- base::BindOnce(&InitializeDictionaryLocation, language_),
+ base::BindOnce(&InitializeDictionaryLocation,
+ base::RetainedRef(task_runner_.get()), language_),
base::BindOnce(
&SpellcheckHunspellDictionary::InitializeDictionaryLocationComplete,
weak_ptr_factory_.GetWeakPtr()));