diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-09-28 20:35:32 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-05-23 13:31:33 +0200 |
commit | 47367aedbd841c86480f74fa35fcffe438b36723 (patch) | |
tree | 61b3155c4f20e56463d9c983a52cd6973f440b41 | |
parent | 2d634f3f77b3e42d6d35ce785c9c2fc0478a3917 (diff) | |
download | qtwebengine-chromium-47367aedbd841c86480f74fa35fcffe438b36723.tar.gz |
Integrate spell checker sources, fix compilation issues
Change-Id: Idb2b4b4fc746f0c1967f50b7715a94200fbbb009
Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
10 files changed, 82 insertions, 6 deletions
diff --git a/chromium/base/base_paths.h b/chromium/base/base_paths.h index 36b649b24a5..29962f36363 100644 --- a/chromium/base/base_paths.h +++ b/chromium/base/base_paths.h @@ -48,7 +48,8 @@ enum BasePathKey { DIR_TEST_DATA, // Used only for testing. DIR_QT_LIBRARY_DATA, - + DIR_APP_DICTIONARIES, + DIR_USER_DATA, PATH_END }; diff --git a/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.cc b/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.cc index ea6619d7e91..05f3b47e66e 100644 --- a/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.cc +++ b/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.cc @@ -15,7 +15,7 @@ #include "content/public/browser/browser_thread.h" #include "mojo/public/cpp/bindings/strong_binding.h" -#if !defined(OS_MACOSX) +#if !(defined(OS_MACOSX) && BUILDFLAG(USE_BROWSER_SPELLCHECKER)) // Mac needs different constructor and destructor for Mac-only members. SpellCheckHostChromeImpl::SpellCheckHostChromeImpl( diff --git a/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.h b/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.h index be996ad2b8f..9defd6b9df5 100644 --- a/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.h +++ b/chromium/chrome/browser/spellchecker/spell_check_host_chrome_impl.h @@ -55,7 +55,7 @@ class SpellCheckHostChromeImpl : public SpellCheckHostImpl { const std::vector<SpellCheckResult>& service_results); #endif -#if defined(OS_MACOSX) +#if defined(OS_MACOSX) && BUILDFLAG(USE_BROWSER_SPELLCHECKER) // Non-Mac (i.e., Android) implementations of the following APIs are in the // base class SpellCheckHostImpl. void CheckSpelling(const base::string16& word, diff --git a/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc b/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc index 5ad42fc6183..5aad22c9ff2 100644 --- a/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc +++ b/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.cc @@ -19,12 +19,21 @@ #include "base/task_runner_util.h" #include "base/task_scheduler/post_task.h" #include "base/threading/thread_restrictions.h" +#ifndef TOOLKIT_QT #include "chrome/common/chrome_constants.h" +#endif #include "components/spellcheck/browser/spellcheck_host_metrics.h" #include "components/spellcheck/common/spellcheck_common.h" +#ifndef TOOLKIT_QT #include "components/sync/model/sync_change.h" #include "components/sync/model/sync_error_factory.h" #include "components/sync/protocol/sync.pb.h" +#else +#include "base/stl_util.h" +namespace chrome { + const base::FilePath::CharType kCustomDictionaryFileName[] = FILE_PATH_LITERAL("Custom Dictionary.txt"); +} +#endif #include "content/public/browser/browser_thread.h" using content::BrowserThread; @@ -235,7 +244,9 @@ bool SpellcheckCustomDictionary::AddWord(const std::string& word) { int result = dictionary_change->Sanitize(GetWords()); Apply(*dictionary_change); Notify(*dictionary_change); +#ifndef TOOLKIT_QT Sync(*dictionary_change); +#endif Save(std::move(dictionary_change)); return result == VALID_CHANGE; } @@ -247,7 +258,9 @@ bool SpellcheckCustomDictionary::RemoveWord(const std::string& word) { int result = dictionary_change->Sanitize(GetWords()); Apply(*dictionary_change); Notify(*dictionary_change); +#ifndef TOOLKIT_QT Sync(*dictionary_change); +#endif Save(std::move(dictionary_change)); return result == VALID_CHANGE; } @@ -273,10 +286,12 @@ bool SpellcheckCustomDictionary::IsLoaded() { return is_loaded_; } +#ifndef TOOLKIT_QT bool SpellcheckCustomDictionary::IsSyncing() { DCHECK_CURRENTLY_ON(BrowserThread::UI); return !!sync_processor_.get(); } +#endif void SpellcheckCustomDictionary::Load() { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -288,6 +303,7 @@ void SpellcheckCustomDictionary::Load() { weak_ptr_factory_.GetWeakPtr())); } +#ifndef TOOLKIT_QT syncer::SyncMergeResult SpellcheckCustomDictionary::MergeDataAndStartSyncing( syncer::ModelType type, const syncer::SyncDataList& initial_sync_data, @@ -382,6 +398,7 @@ syncer::SyncError SpellcheckCustomDictionary::ProcessSyncChanges( return syncer::SyncError(); } +#endif SpellcheckCustomDictionary::LoadFileResult::LoadFileResult() : is_valid_file(false) {} @@ -427,7 +444,9 @@ void SpellcheckCustomDictionary::OnLoaded( dictionary_change.AddWords(result->words); dictionary_change.Sanitize(GetWords()); Apply(dictionary_change); +#ifndef TOOLKIT_QT Sync(dictionary_change); +#endif is_loaded_ = true; for (Observer& observer : observers_) observer.OnCustomDictionaryLoaded(); @@ -471,6 +490,7 @@ void SpellcheckCustomDictionary::Save( std::move(dictionary_change), custom_dictionary_path_)); } +#ifndef TOOLKIT_QT syncer::SyncError SpellcheckCustomDictionary::Sync( const Change& dictionary_change) { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -522,6 +542,7 @@ syncer::SyncError SpellcheckCustomDictionary::Sync( return error; } +#endif void SpellcheckCustomDictionary::Notify(const Change& dictionary_change) { DCHECK_CURRENTLY_ON(BrowserThread::UI); diff --git a/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.h b/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.h index e5cb273e8d6..499cb1a35cc 100644 --- a/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.h +++ b/chromium/chrome/browser/spellchecker/spellcheck_custom_dictionary.h @@ -17,10 +17,12 @@ #include "base/observer_list.h" #include "base/sequenced_task_runner.h" #include "components/spellcheck/browser/spellcheck_dictionary.h" +#ifndef TOOLKIT_QT #include "components/sync/model/sync_data.h" #include "components/sync/model/sync_error.h" #include "components/sync/model/sync_merge_result.h" #include "components/sync/model/syncable_service.h" +#endif namespace base { class Location; @@ -40,8 +42,13 @@ class SyncChangeProcessor; // foo // checksum_v1 = ec3df4034567e59e119fcf87f2d9bad4 // +#ifndef TOOLKIT_QT class SpellcheckCustomDictionary : public SpellcheckDictionary, public syncer::SyncableService { +#else +class SpellcheckCustomDictionary : public SpellcheckDictionary { +#endif + public: // A change to the dictionary. class Change { @@ -140,12 +147,15 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary, // Returns true if the dictionary has been loaded. Otherwise returns false. bool IsLoaded(); +#ifndef TOOLKIT_QT // Returns true if the dictionary is being synced. Otherwise returns false. bool IsSyncing(); +#endif // Overridden from SpellcheckDictionary: void Load() override; +#ifndef TOOLKIT_QT // Overridden from syncer::SyncableService: syncer::SyncMergeResult MergeDataAndStartSyncing( syncer::ModelType type, @@ -157,6 +167,7 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary, syncer::SyncError ProcessSyncChanges( const base::Location& from_here, const syncer::SyncChangeList& change_list) override; +#endif private: friend class DictionarySyncIntegrationTestHelper; @@ -189,10 +200,12 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary, // |dictionary_change| to pass it to the FILE thread. void Save(std::unique_ptr<Change> dictionary_change); +#ifndef TOOLKIT_QT // Notifies the sync service of the |dictionary_change|. Syncs up to the // maximum syncable words on the server. Disables syncing of this dictionary // if the server contains the maximum number of syncable words. syncer::SyncError Sync(const Change& dictionary_change); +#endif // Notifies observers of the dictionary change if the dictionary has been // changed. @@ -210,11 +223,13 @@ class SpellcheckCustomDictionary : public SpellcheckDictionary, // Observers for dictionary load and content changes. base::ObserverList<Observer> observers_; +#ifndef TOOLKIT_QT // Used to send local changes to the sync infrastructure. std::unique_ptr<syncer::SyncChangeProcessor> sync_processor_; // Used to send sync-related errors to the sync infrastructure. std::unique_ptr<syncer::SyncErrorFactory> sync_error_handler_; +#endif // True if the dictionary has been loaded. Otherwise false. bool is_loaded_; diff --git a/chromium/chrome/browser/spellchecker/spellcheck_factory.cc b/chromium/chrome/browser/spellchecker/spellcheck_factory.cc index 64b5243d510..5e3abf577da 100644 --- a/chromium/chrome/browser/spellchecker/spellcheck_factory.cc +++ b/chromium/chrome/browser/spellchecker/spellcheck_factory.cc @@ -4,9 +4,13 @@ #include "chrome/browser/spellchecker/spellcheck_factory.h" +#ifndef TOOLKIT_QT #include "chrome/browser/profiles/incognito_helpers.h" +#endif #include "chrome/browser/spellchecker/spellcheck_service.h" +#ifndef TOOLKIT_QT #include "chrome/grit/locale_settings.h" +#endif #include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/pref_registry/pref_registry_syncable.h" #include "components/prefs/pref_service.h" @@ -73,9 +77,11 @@ void SpellcheckServiceFactory::RegisterProfilePrefs( std::make_unique<base::ListValue>()); // Continue registering kSpellCheckDictionary for preference migration. // TODO(estade): remove: crbug.com/751275 +#ifndef TOOLKIT_QT user_prefs->RegisterStringPref( spellcheck::prefs::kSpellCheckDictionary, l10n_util::GetStringUTF8(IDS_SPELLCHECK_DICTIONARY)); +#endif user_prefs->RegisterBooleanPref( spellcheck::prefs::kSpellCheckUseSpellingService, false); #if defined(OS_ANDROID) @@ -89,7 +95,11 @@ void SpellcheckServiceFactory::RegisterProfilePrefs( content::BrowserContext* SpellcheckServiceFactory::GetBrowserContextToUse( content::BrowserContext* context) const { +#ifndef TOOLKIT_QT return chrome::GetBrowserContextRedirectedInIncognito(context); +#else + return context; +#endif } bool SpellcheckServiceFactory::ServiceIsNULLWhileTesting() const { diff --git a/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc b/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc index aeb5838a2a9..fc6c6a98b7c 100644 --- a/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc +++ b/chromium/chrome/browser/spellchecker/spellcheck_hunspell_dictionary.cc @@ -20,8 +20,10 @@ #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" #include "chrome/browser/spellchecker/spellcheck_service.h" +#ifndef TOOLKIT_QT #include "chrome/common/chrome_paths.h" #include "components/data_use_measurement/core/data_use_user_data.h" +#endif #include "components/spellcheck/browser/spellcheck_platform.h" #include "components/spellcheck/common/spellcheck_common.h" #include "components/spellcheck/spellcheck_buildflags.h" @@ -65,7 +67,7 @@ bool SaveDictionaryData(std::unique_ptr<std::string> data, bool success = false; #if defined(OS_WIN) base::FilePath dict_dir; - PathService::Get(chrome::DIR_USER_DATA, &dict_dir); + PathService::Get(base::DIR_USER_DATA, &dict_dir); base::FilePath fallback_file_path = dict_dir.Append(path.BaseName()); bytes_written = @@ -333,7 +335,7 @@ SpellcheckHunspellDictionary::OpenDictionaryFile(const base::FilePath& path) { // Check if the dictionary exists in the fallback location. If so, use it // rather than downloading anew. base::FilePath user_dir; - PathService::Get(chrome::DIR_USER_DATA, &user_dir); + PathService::Get(base::DIR_USER_DATA, &user_dir); base::FilePath fallback = user_dir.Append(path.BaseName()); if (!base::PathExists(path) && base::PathExists(fallback)) dictionary.path = fallback; @@ -379,7 +381,7 @@ SpellcheckHunspellDictionary::InitializeDictionaryLocation( // sequence because it checks if there is a "Dictionaries" directory and // create it. base::FilePath dict_dir; - PathService::Get(chrome::DIR_APP_DICTIONARIES, &dict_dir); + PathService::Get(base::DIR_APP_DICTIONARIES, &dict_dir); base::FilePath dict_path = spellcheck::GetVersionedFileName(language, dict_dir); diff --git a/chromium/chrome/common/pref_names.cc b/chromium/chrome/common/pref_names.cc new file mode 100644 index 00000000000..9ec3446d6eb --- /dev/null +++ b/chromium/chrome/common/pref_names.cc @@ -0,0 +1,9 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/pref_names.h" + +namespace prefs { +const char kAcceptLanguages[] = "intl.accept_languages"; +} // namespace prefs diff --git a/chromium/chrome/common/pref_names.h b/chromium/chrome/common/pref_names.h new file mode 100644 index 00000000000..2d9e40d61f6 --- /dev/null +++ b/chromium/chrome/common/pref_names.h @@ -0,0 +1,14 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Constants for the names of various preferences, for easier changing. + +#ifndef CHROME_COMMON_PREF_NAMES_H_ +#define CHROME_COMMON_PREF_NAMES_H_ + +namespace prefs { +extern const char kAcceptLanguages[]; +} // namespace prefs + +#endif // CHROME_COMMON_PREF_NAMES_H_ diff --git a/chromium/components/spellcheck/browser/spelling_service_client.cc b/chromium/components/spellcheck/browser/spelling_service_client.cc index e8afa352631..bbea5be5d3d 100644 --- a/chromium/components/spellcheck/browser/spelling_service_client.cc +++ b/chromium/components/spellcheck/browser/spelling_service_client.cc @@ -18,7 +18,9 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" +#ifndef TOOLKIT_QT #include "components/data_use_measurement/core/data_use_user_data.h" +#endif #include "components/prefs/pref_service.h" #include "components/spellcheck/browser/pref_names.h" #include "components/spellcheck/common/spellcheck_common.h" @@ -102,6 +104,7 @@ bool SpellingServiceClient::RequestTextCheck( kSpellingRequest, type, encoded_text.c_str(), language_code.c_str(), country_code.c_str(), api_key.c_str()); +#ifndef TOOLKIT_QT GURL url = GURL(kSpellingServiceURL); // Create traffic annotation tag. @@ -151,6 +154,7 @@ bool SpellingServiceClient::RequestTextCheck( spellcheck_fetchers_[fetcher] = std::make_unique<TextCheckCallbackData>( base::WrapUnique(fetcher), std::move(callback), text); fetcher->Start(); +#endif return true; } |