OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/spellchecker/spellcheck_service.h" | 5 #include "chrome/browser/spellchecker/spellcheck_service.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/prefs/pref_member.h" | 8 #include "base/prefs/pref_member.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 SpellcheckService::SpellcheckService(content::BrowserContext* context) | 42 SpellcheckService::SpellcheckService(content::BrowserContext* context) |
43 : context_(context), | 43 : context_(context), |
44 weak_ptr_factory_(this) { | 44 weak_ptr_factory_(this) { |
45 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
46 PrefService* prefs = user_prefs::UserPrefs::Get(context); | 46 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
47 pref_change_registrar_.Init(prefs); | 47 pref_change_registrar_.Init(prefs); |
48 StringListPrefMember dictionaries_pref; | 48 StringListPrefMember dictionaries_pref; |
49 dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs); | 49 dictionaries_pref.Init(prefs::kSpellCheckDictionaries, prefs); |
50 std::string first_of_dictionaries; | 50 std::string first_of_dictionaries; |
51 if (!dictionaries_pref.GetValue().empty()) | |
52 first_of_dictionaries = dictionaries_pref.GetValue().front(); | |
53 | 51 |
54 // For preference migration, set the new preference kSpellCheckDictionaries | 52 #if defined(USE_BROWSER_SPELLCHECKER) |
55 // to be the same as the old kSpellCheckDictionary. | 53 // Ensure that the renderer always knows the platform spellchecking language. |
| 54 // This language is used for initialization of the text iterator. If the |
| 55 // iterator is not initialized, then the context menu does not show spellcheck |
| 56 // suggestions. |
| 57 // |
| 58 // No migration is necessary, because the spellcheck language preference is |
| 59 // not user visible or modifiable in Chrome on Mac. |
| 60 dictionaries_pref.SetValue(std::vector<std::string>( |
| 61 1, spellcheck_platform::GetSpellCheckerLanguage())); |
| 62 first_of_dictionaries = dictionaries_pref.GetValue().front(); |
| 63 #else |
| 64 // Migrate preferences from single-language to multi-language schema. |
56 StringPrefMember single_dictionary_pref; | 65 StringPrefMember single_dictionary_pref; |
57 single_dictionary_pref.Init(prefs::kSpellCheckDictionary, prefs); | 66 single_dictionary_pref.Init(prefs::kSpellCheckDictionary, prefs); |
58 std::string single_dictionary = single_dictionary_pref.GetValue(); | 67 std::string single_dictionary = single_dictionary_pref.GetValue(); |
59 | 68 |
| 69 if (!dictionaries_pref.GetValue().empty()) |
| 70 first_of_dictionaries = dictionaries_pref.GetValue().front(); |
| 71 |
60 if (first_of_dictionaries.empty() && !single_dictionary.empty()) { | 72 if (first_of_dictionaries.empty() && !single_dictionary.empty()) { |
61 first_of_dictionaries = single_dictionary; | 73 first_of_dictionaries = single_dictionary; |
62 dictionaries_pref.SetValue( | 74 dictionaries_pref.SetValue( |
63 std::vector<std::string>(1, first_of_dictionaries)); | 75 std::vector<std::string>(1, first_of_dictionaries)); |
64 } | 76 } |
65 | 77 |
66 single_dictionary_pref.SetValue(""); | 78 single_dictionary_pref.SetValue(""); |
67 | 79 |
68 // If a user goes from single language to multi-language spellchecking with | 80 // If a user goes from single language to multi-language spellchecking with |
69 // spellchecking disabled the dictionaries preference should be blanked. | 81 // spellchecking disabled the dictionaries preference should be blanked. |
| 82 // TODO(krb): Remove this block of code when allowing to disable multi-lingual |
| 83 // spellcheck. |
70 if (!prefs->GetBoolean(prefs::kEnableContinuousSpellcheck) && | 84 if (!prefs->GetBoolean(prefs::kEnableContinuousSpellcheck) && |
71 chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) { | 85 chrome::spellcheck_common::IsMultilingualSpellcheckEnabled()) { |
72 dictionaries_pref.SetValue(std::vector<std::string>()); | 86 dictionaries_pref.SetValue(std::vector<std::string>()); |
73 prefs->SetBoolean(prefs::kEnableContinuousSpellcheck, true); | 87 prefs->SetBoolean(prefs::kEnableContinuousSpellcheck, true); |
74 } | 88 } |
75 | 89 |
76 // If a user goes back to single language spellchecking make sure there is | 90 // If a user goes back to single language spellchecking make sure there is |
77 // only one language in the dictionaries preference. | 91 // only one language in the dictionaries preference. |
| 92 // TODO(krb): Remove this block of code when disabling single-language |
| 93 // spellcheck. |
78 if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled() && | 94 if (!chrome::spellcheck_common::IsMultilingualSpellcheckEnabled() && |
79 dictionaries_pref.GetValue().size() > 1) { | 95 dictionaries_pref.GetValue().size() > 1) { |
80 dictionaries_pref.SetValue( | 96 dictionaries_pref.SetValue( |
81 std::vector<std::string>(1, first_of_dictionaries)); | 97 std::vector<std::string>(1, first_of_dictionaries)); |
82 } | 98 } |
| 99 #endif // defined(USE_BROWSER_SPELLCHECKER) |
83 | 100 |
84 std::string language_code; | 101 std::string language_code; |
85 std::string country_code; | 102 std::string country_code; |
86 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( | 103 chrome::spellcheck_common::GetISOLanguageCountryCodeFromLocale( |
87 first_of_dictionaries, | 104 first_of_dictionaries, |
88 &language_code, | 105 &language_code, |
89 &country_code); | 106 &country_code); |
90 feedback_sender_.reset(new spellcheck::FeedbackSender( | 107 feedback_sender_.reset(new spellcheck::FeedbackSender( |
91 context->GetRequestContext(), language_code, country_code)); | 108 context->GetRequestContext(), language_code, country_code)); |
92 | 109 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 352 } |
336 | 353 |
337 void SpellcheckService::UpdateFeedbackSenderState() { | 354 void SpellcheckService::UpdateFeedbackSenderState() { |
338 if (SpellingServiceClient::IsAvailable( | 355 if (SpellingServiceClient::IsAvailable( |
339 context_, SpellingServiceClient::SPELLCHECK)) { | 356 context_, SpellingServiceClient::SPELLCHECK)) { |
340 feedback_sender_->StartFeedbackCollection(); | 357 feedback_sender_->StartFeedbackCollection(); |
341 } else { | 358 } else { |
342 feedback_sender_->StopFeedbackCollection(); | 359 feedback_sender_->StopFeedbackCollection(); |
343 } | 360 } |
344 } | 361 } |
OLD | NEW |