Commit 35cc5976 authored by Bruce Long's avatar Bruce Long Committed by Commit Bot

Spellcheck: Remove unused method GetSupportedWindowsPreferredLanguages

WindowsSpellChecker::GetSupportedWindowsPreferredLanguages is only
used in a unit test. The plan to support toggling on spellchecking
for languages such as Arabic that have Windows spellcheck dictionaries
but not Hunspell dictionaries has changed. We will now use the
ISpellCheckerFactory::get_SupportedLanguages spellchecker API to get a
list of installed Windows dictionaries, which will supplement the
hardcoded list of Hunspell languages (future CL).

See following for discussion:

Windows Spellcheck: Should only be performed for the preferred
languages listed in Windows settings
https://bugs.chromium.org/p/chromium/issues/detail?id=1000443#c20

Bug: 1000443
Change-Id: I49c220ca76ff2991ee79b6184bc0616724a97267
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079651Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Bruce Long <brlong@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#745448}
parent c4a91231
...@@ -14,6 +14,5 @@ buildflag_header("buildflags") { ...@@ -14,6 +14,5 @@ buildflag_header("buildflags") {
"USE_WIN_HYBRID_SPELLCHECKER=$use_win_hybrid_spellchecker", "USE_WIN_HYBRID_SPELLCHECKER=$use_win_hybrid_spellchecker",
"ENABLE_SPELLING_SERVICE=$enable_spelling_service", "ENABLE_SPELLING_SERVICE=$enable_spelling_service",
"HAS_SPELLCHECK_PANEL=$has_spellcheck_panel", "HAS_SPELLCHECK_PANEL=$has_spellcheck_panel",
"USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK=$use_windows_preferred_languages_for_spellcheck",
] ]
} }
...@@ -38,24 +38,11 @@ typedef base::OnceCallback<void(const spellcheck::PerLanguageSuggestions&)> ...@@ -38,24 +38,11 @@ typedef base::OnceCallback<void(const spellcheck::PerLanguageSuggestions&)>
GetSuggestionsCallback; GetSuggestionsCallback;
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
typedef base::OnceCallback<void(const std::vector<std::string>& /* results */)>
GetSupportedLanguagesCompleteCallback;
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
// Get the languages supported by the platform spellchecker and store them in // Get the languages supported by the platform spellchecker and store them in
// |spellcheck_languages|. Note that they must be converted to // |spellcheck_languages|. Note that they must be converted to
// Chromium style codes (en-US not en_US). See spellchecker.cc for a full list. // Chromium style codes (en-US not en_US). See spellchecker.cc for a full list.
void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages); void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages);
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
// Retrieve language tags for installed Windows language packs that also have
// spellchecking support.
void GetSupportedWindowsPreferredLanguages(
PlatformSpellChecker* spell_checker_instance,
GetSupportedLanguagesCompleteCallback callback);
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
// Returns the language used for spellchecking on the platform. // Returns the language used for spellchecking on the platform.
std::string GetSpellCheckerLanguage(); std::string GetSpellCheckerLanguage();
......
...@@ -92,15 +92,6 @@ void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { ...@@ -92,15 +92,6 @@ void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) {
// Not used in Windows // Not used in Windows
} }
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void GetSupportedWindowsPreferredLanguages(
PlatformSpellChecker* spell_checker_instance,
GetSupportedLanguagesCompleteCallback callback) {
reinterpret_cast<WindowsSpellChecker*>(spell_checker_instance)
->GetSupportedWindowsPreferredLanguages(std::move(callback));
}
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
int GetDocumentTag() { int GetDocumentTag() {
return 1; // Not used in Windows return 1; // Not used in Windows
} }
......
...@@ -258,83 +258,6 @@ bool WindowsSpellChecker::BackgroundHelper::IsLanguageSupported( ...@@ -258,83 +258,6 @@ bool WindowsSpellChecker::BackgroundHelper::IsLanguageSupported(
return SUCCEEDED(hr) && is_language_supported; return SUCCEEDED(hr) && is_language_supported;
} }
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
std::vector<std::string>
WindowsSpellChecker::BackgroundHelper::GetSupportedWindowsPreferredLanguages() {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
std::vector<std::string> supported_languages;
if (IsSpellCheckerFactoryInitialized() &&
// IGlobalizationPreferencesStatics is only available on Win8 and above.
spellcheck::WindowsVersionSupportsSpellchecker() &&
// Using WinRT and HSTRING.
base::win::ResolveCoreWinRTDelayload() &&
base::win::ScopedHString::ResolveCoreWinRTStringDelayload()) {
Microsoft::WRL::ComPtr<
ABI::Windows::System::UserProfile::IGlobalizationPreferencesStatics>
globalization_preferences;
HRESULT hr = base::win::GetActivationFactory<
ABI::Windows::System::UserProfile::IGlobalizationPreferencesStatics,
RuntimeClass_Windows_System_UserProfile_GlobalizationPreferences>(
&globalization_preferences);
// Should always succeed under same conditions for which
// WindowsVersionSupportsSpellchecker returns true.
DCHECK(SUCCEEDED(hr));
// Retrieve a vector of Windows preferred languages (that is, installed
// language packs listed under system Language Settings).
Microsoft::WRL::ComPtr<
ABI::Windows::Foundation::Collections::IVectorView<HSTRING>>
preferred_languages;
hr = globalization_preferences->get_Languages(&preferred_languages);
DCHECK(SUCCEEDED(hr));
uint32_t count = 0;
hr = preferred_languages->get_Size(&count);
DCHECK(SUCCEEDED(hr));
// Expect at least one language pack to be installed by default.
DCHECK_GE(count, 0u);
for (uint32_t i = 0; i < count; ++i) {
HSTRING language;
hr = preferred_languages->GetAt(i, &language);
DCHECK(SUCCEEDED(hr));
base::win::ScopedHString language_scoped(language);
// Language tags obtained using Windows.Globalization API
// (zh-Hans-CN e.g.) need to be converted to locale names via
// ResolveLocaleName before being passed to spell checker API.
wchar_t locale_name[LOCALE_NAME_MAX_LENGTH];
const wchar_t* preferred_language =
base::as_wcstr(base::AsStringPiece16(language_scoped.Get()));
// ResolveLocaleName should only fail if buffer size insufficient, but
// it can succeed yet return an empty string for certain language tags
// such as ht.
if (!::ResolveLocaleName(preferred_language, locale_name,
LOCALE_NAME_MAX_LENGTH) ||
!*locale_name) {
DVLOG(1) << "ResolveLocaleName failed or returned empty string for "
"preferred language "
<< preferred_language
<< ", will try unresolved language name.";
base::wcslcpy(locale_name, preferred_language, LOCALE_NAME_MAX_LENGTH);
}
// See if the language has a dictionary available. Some preferred
// languages have no spellchecking support (zh-CN e.g.).
BOOL is_language_supported = FALSE;
hr = spell_checker_factory_->IsSupported(locale_name,
&is_language_supported);
DCHECK(SUCCEEDED(hr));
if (is_language_supported) {
supported_languages.push_back(base::WideToUTF8(locale_name));
} else {
DVLOG(2) << "No platform spellchecking support for locale name "
<< locale_name;
}
}
}
return supported_languages;
}
#endif // #if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
LocalesSupportInfo LocalesSupportInfo
WindowsSpellChecker::BackgroundHelper::DetermineLocalesSupport( WindowsSpellChecker::BackgroundHelper::DetermineLocalesSupport(
const std::vector<std::string>& locales) { const std::vector<std::string>& locales) {
...@@ -519,14 +442,3 @@ void WindowsSpellChecker::RecordSpellcheckLocalesStats( ...@@ -519,14 +442,3 @@ void WindowsSpellChecker::RecordSpellcheckLocalesStats(
base::Unretained(background_helper_.get()), base::Unretained(background_helper_.get()),
std::move(spellcheck_locales), metrics)); std::move(spellcheck_locales), metrics));
} }
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void WindowsSpellChecker::GetSupportedWindowsPreferredLanguages(
spellcheck_platform::GetSupportedLanguagesCompleteCallback callback) {
base::PostTaskAndReplyWithResult(
background_task_runner_.get(), FROM_HERE,
base::BindOnce(&BackgroundHelper::GetSupportedWindowsPreferredLanguages,
base::Unretained(background_helper_.get())),
std::move(callback));
}
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
...@@ -66,11 +66,6 @@ class WindowsSpellChecker : public PlatformSpellChecker { ...@@ -66,11 +66,6 @@ class WindowsSpellChecker : public PlatformSpellChecker {
void IsLanguageSupported(const std::string& lang_tag, void IsLanguageSupported(const std::string& lang_tag,
base::OnceCallback<void(bool)> callback); base::OnceCallback<void(bool)> callback);
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void GetSupportedWindowsPreferredLanguages(
spellcheck_platform::GetSupportedLanguagesCompleteCallback callback);
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
private: private:
// Private inner class that handles calls to the native Windows APIs. All // Private inner class that handles calls to the native Windows APIs. All
// invocations of these methods must be posted to the same COM // invocations of these methods must be posted to the same COM
...@@ -153,13 +148,6 @@ class WindowsSpellChecker : public PlatformSpellChecker { ...@@ -153,13 +148,6 @@ class WindowsSpellChecker : public PlatformSpellChecker {
const std::vector<std::string> spellcheck_locales, const std::vector<std::string> spellcheck_locales,
SpellCheckHostMetrics* metrics); SpellCheckHostMetrics* metrics);
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
// Gets the user's preferred languages from the OS settings, filters out
// languages for which a native spell checker isn't available, and invokes
// the given callback with the results.
std::vector<std::string> GetSupportedWindowsPreferredLanguages();
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
// Sorts the given locales into four buckets based on spell check support // Sorts the given locales into four buckets based on spell check support
// (both native and Hunspell, Hunspell only, native only, none). // (both native and Hunspell, Hunspell only, native only, none).
LocalesSupportInfo DetermineLocalesSupport( LocalesSupportInfo DetermineLocalesSupport(
......
...@@ -82,21 +82,6 @@ class WindowsSpellCheckerTest : public testing::Test { ...@@ -82,21 +82,6 @@ class WindowsSpellCheckerTest : public testing::Test {
} }
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
void GetSupportedWindowsPreferredLanguagesCallback(
const std::vector<std::string>& preferred_languages) {
callback_finished_ = true;
preferred_languages_ = preferred_languages;
for (const auto& preferred_language : preferred_languages_) {
DLOG(INFO) << "GetSupportedWindowsPreferredLanguagesCallback: "
"Dictionary supported for locale: "
<< preferred_language;
}
if (quit_)
std::move(quit_).Run();
}
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
protected: protected:
std::unique_ptr<WindowsSpellChecker> win_spell_checker_; std::unique_ptr<WindowsSpellChecker> win_spell_checker_;
...@@ -109,9 +94,6 @@ class WindowsSpellCheckerTest : public testing::Test { ...@@ -109,9 +94,6 @@ class WindowsSpellCheckerTest : public testing::Test {
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
spellcheck::PerLanguageSuggestions per_language_suggestions_; spellcheck::PerLanguageSuggestions per_language_suggestions_;
#endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #endif // BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
std::vector<std::string> preferred_languages_;
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::MainThreadType::UI}; base::test::TaskEnvironment::MainThreadType::UI};
...@@ -167,27 +149,6 @@ TEST_F(WindowsSpellCheckerTest, RequestTextCheck) { ...@@ -167,27 +149,6 @@ TEST_F(WindowsSpellCheckerTest, RequestTextCheck) {
} }
} }
#if BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK)
TEST_F(WindowsSpellCheckerTest, GetSupportedWindowsPreferredLanguages) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
return;
}
ASSERT_TRUE(set_language_result_);
win_spell_checker_->GetSupportedWindowsPreferredLanguages(base::BindOnce(
&WindowsSpellCheckerTest::GetSupportedWindowsPreferredLanguagesCallback,
base::Unretained(this)));
RunUntilResultReceived();
ASSERT_LE(1u, preferred_languages_.size());
ASSERT_NE(preferred_languages_.end(),
std::find(preferred_languages_.begin(), preferred_languages_.end(),
"en-US"));
}
#endif // BUILDFLAG(USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK
#if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER) #if BUILDFLAG(USE_WIN_HYBRID_SPELLCHECKER)
TEST_F(WindowsSpellCheckerTest, GetPerLanguageSuggestions) { TEST_F(WindowsSpellCheckerTest, GetPerLanguageSuggestions) {
if (!spellcheck::WindowsVersionSupportsSpellchecker()) { if (!spellcheck::WindowsVersionSupportsSpellchecker()) {
......
...@@ -58,8 +58,4 @@ mojom("interfaces") { ...@@ -58,8 +58,4 @@ mojom("interfaces") {
if (use_win_hybrid_spellchecker) { if (use_win_hybrid_spellchecker) {
enabled_features += [ "USE_WIN_HYBRID_SPELLCHECKER" ] enabled_features += [ "USE_WIN_HYBRID_SPELLCHECKER" ]
} }
if (use_windows_preferred_languages_for_spellcheck) {
enabled_features += [ "USE_WINDOWS_PREFERRED_LANGUAGES_FOR_SPELLCHECK" ]
}
} }
...@@ -36,12 +36,3 @@ use_win_hybrid_spellchecker is used. In addition, for experiment purposes, a ...@@ -36,12 +36,3 @@ use_win_hybrid_spellchecker is used. In addition, for experiment purposes, a
feature flag kWinUseHybridSpellChecker is used to control this behavior at feature flag kWinUseHybridSpellChecker is used to control this behavior at
runtime. Finally, this fallback logic requires the platform spell checker to be runtime. Finally, this fallback logic requires the platform spell checker to be
available, so it also uses the browser spell checker checks described above. available, so it also uses the browser spell checker checks described above.
## Note on use_windows_preferred_languages_for_spellcheck
TODO(https://crbug.com/1000443): Use Windows preferred languages to help
populate spellcheck settings.
Use union of Chromium preferred languages (from Language settings) and
the Windows preferred languages (from system language settings) as the
source of the spellcheck languages in the "Spell check" section of the
Chromium language settings, provided they are supported for spellcheck.
...@@ -21,14 +21,6 @@ use_renderer_spellchecker = !use_browser_spellchecker || is_win ...@@ -21,14 +21,6 @@ use_renderer_spellchecker = !use_browser_spellchecker || is_win
use_win_hybrid_spellchecker = use_win_hybrid_spellchecker =
is_win && use_browser_spellchecker && use_renderer_spellchecker is_win && use_browser_spellchecker && use_renderer_spellchecker
# TODO(https://crbug.com/1000443): Use Windows preferred languages to help populate spellcheck settings.
# Use union of Chromium preferred languages (from Language settings) and
# the Windows preferred languages (from system language settings) as the
# source of the spellcheck languages in the "Spell check" section of the
# Chromium language settings, provided they are supported for spellcheck.
use_windows_preferred_languages_for_spellcheck =
use_browser_spellchecker && is_win
# Whether the enhanced spellcheck service is available on the platform. This is # Whether the enhanced spellcheck service is available on the platform. This is
# effectively equal to all desktop platforms. # effectively equal to all desktop platforms.
enable_spelling_service = use_renderer_spellchecker || is_mac enable_spelling_service = use_renderer_spellchecker || is_mac
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment