Commit ff659a20 authored by rouslan's avatar rouslan Committed by Commit bot

[mac] Send the system spellchecker language to the renderer.

The browser process sends the system spellchecker language to the
renderer to initialize its text breaker. The text breaker is used when
providing suggestions in the context menu. If the text breaker is not
initialized, the menu has no suggestions.

The browser saves the system spellchecker language into the unsynced
preference prefs::kSpellCheckDictionaries. This preference is also used
by the spelling service client. If the preference is empty, then the
client is disabled.

BUG=577835

Review URL: https://codereview.chromium.org/1602303002

Cr-Commit-Position: refs/heads/master@{#371605}
parent 9fdef293
...@@ -31,6 +31,9 @@ typedef base::Callback<void( ...@@ -31,6 +31,9 @@ typedef base::Callback<void(
// 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);
// Returns the language used for spellchecking on the platform.
std::string GetSpellCheckerLanguage();
// Returns true if there is a platform-specific spellchecker that can be used. // Returns true if there is a platform-specific spellchecker that can be used.
bool SpellCheckerAvailable(); bool SpellCheckerAvailable();
......
...@@ -13,6 +13,10 @@ namespace spellcheck_platform { ...@@ -13,6 +13,10 @@ namespace spellcheck_platform {
void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) {
} }
std::string GetSpellCheckerLanguage() {
return std::string();
}
bool SpellCheckerAvailable() { bool SpellCheckerAvailable() {
return base::CommandLine::ForCurrentProcess()->HasSwitch( return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableAndroidSpellChecker); switches::kEnableAndroidSpellChecker);
......
...@@ -109,6 +109,10 @@ void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) { ...@@ -109,6 +109,10 @@ void GetAvailableLanguages(std::vector<std::string>* spellcheck_languages) {
} }
} }
std::string GetSpellCheckerLanguage() {
return ConvertLanguageCodeFromMac([SharedSpellChecker() language]);
}
bool SpellCheckerAvailable() { bool SpellCheckerAvailable() {
// If this file was compiled, then we know that we are on OS X 10.5 at least // If this file was compiled, then we know that we are on OS X 10.5 at least
// and can safely return true here. // and can safely return true here.
......
...@@ -48,15 +48,27 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) ...@@ -48,15 +48,27 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context)
StringListPrefMember dictionaries_pref; StringListPrefMember dictionaries_pref;
dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs); dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs);
std::string first_of_dictionaries; std::string first_of_dictionaries;
if (!dictionaries_pref.GetValue().empty())
first_of_dictionaries = dictionaries_pref.GetValue().front();
// For preference migration, set the new preference kSpellCheckDictionaries #if defined(USE_BROWSER_SPELLCHECKER)
// to be the same as the old kSpellCheckDictionary. // Ensure that the renderer always knows the platform spellchecking language.
// This language is used for initialization of the text iterator. If the
// iterator is not initialized, then the context menu does not show spellcheck
// suggestions.
//
// No migration is necessary, because the spellcheck language preference is
// not user visible or modifiable in Chrome on Mac.
dictionaries_pref.SetValue(std::vector<std::string>(
1, spellcheck_platform::GetSpellCheckerLanguage()));
first_of_dictionaries = dictionaries_pref.GetValue().front();
#else
// Migrate preferences from single-language to multi-language schema.
StringPrefMember single_dictionary_pref; StringPrefMember single_dictionary_pref;
single_dictionary_pref.Init(prefs::kSpellCheckDictionary, prefs); single_dictionary_pref.Init(prefs::kSpellCheckDictionary, prefs);
std::string single_dictionary = single_dictionary_pref.GetValue(); std::string single_dictionary = single_dictionary_pref.GetValue();
if (!dictionaries_pref.GetValue().empty())
first_of_dictionaries = dictionaries_pref.GetValue().front();
if (first_of_dictionaries.empty() && !single_dictionary.empty()) { if (first_of_dictionaries.empty() && !single_dictionary.empty()) {
first_of_dictionaries = single_dictionary; first_of_dictionaries = single_dictionary;
dictionaries_pref.SetValue( dictionaries_pref.SetValue(
...@@ -67,6 +79,8 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) ...@@ -67,6 +79,8 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context)
// If a user goes from single language to multi-language spellchecking with // If a user goes from single language to multi-language spellchecking with
// spellchecking disabled the dictionaries preference should be blanked. // spellchecking disabled the dictionaries preference should be blanked.
// TODO(krb): Remove this block of code when allowing to disable multi-lingual
// spellcheck.
if (!prefs->GetBoolean(prefs::kEnableContinuousSpellcheck) && if (!prefs->GetBoolean(prefs::kEnableContinuousSpellcheck) &&
chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) { chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) {
dictionaries_pref.SetValue(std::vector<std::string>()); dictionaries_pref.SetValue(std::vector<std::string>());
...@@ -75,11 +89,14 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context) ...@@ -75,11 +89,14 @@ SpellcheckService::SpellcheckService(content::BrowserContext* context)
// If a user goes back to single language spellchecking make sure there is // If a user goes back to single language spellchecking make sure there is
// only one language in the dictionaries preference. // only one language in the dictionaries preference.
// TODO(krb): Remove this block of code when disabling single-language
// spellcheck.
if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled() && if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled() &&
dictionaries_pref.GetValue().size() > 1) { dictionaries_pref.GetValue().size() > 1) {
dictionaries_pref.SetValue( dictionaries_pref.SetValue(
std::vector<std::string>(1, first_of_dictionaries)); std::vector<std::string>(1, first_of_dictionaries));
} }
#endif // defined(USE_BROWSER_SPELLCHECKER)
std::string language_code; std::string language_code;
std::string country_code; std::string country_code;
......
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