Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/browser/spellchecker/spellcheck_service.cc

Issue 654653002: Enables the user to select multiple languages for spellchecking (UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/command_line.h"
7 #include "base/prefs/pref_member.h" 8 #include "base/prefs/pref_member.h"
8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
10 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
11 #include "chrome/browser/spellchecker/spellcheck_factory.h" 12 #include "chrome/browser/spellchecker/spellcheck_factory.h"
12 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 13 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
13 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" 14 #include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"
14 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" 15 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h"
15 #include "chrome/browser/spellchecker/spelling_service_client.h" 16 #include "chrome/browser/spellchecker/spelling_service_client.h"
17 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
17 #include "chrome/common/spellcheck_messages.h" 19 #include "chrome/common/spellcheck_messages.h"
18 #include "components/user_prefs/user_prefs.h" 20 #include "components/user_prefs/user_prefs.h"
19 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
24 #include "ipc/ipc_platform_file.h" 26 #include "ipc/ipc_platform_file.h"
25 27
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 70 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
69 content::NotificationService::AllSources()); 71 content::NotificationService::AllSources());
70 } 72 }
71 73
72 SpellcheckService::~SpellcheckService() { 74 SpellcheckService::~SpellcheckService() {
73 // Remove pref observers 75 // Remove pref observers
74 pref_change_registrar_.RemoveAll(); 76 pref_change_registrar_.RemoveAll();
75 } 77 }
76 78
77 // static 79 // static
78 int SpellcheckService::GetSpellCheckLanguages( 80 std::set<int> SpellcheckService::GetSpellCheckLanguages(
79 content::BrowserContext* context, 81 content::BrowserContext* context,
80 std::vector<std::string>* languages) { 82 std::vector<std::string>* languages) {
81 PrefService* prefs = user_prefs::UserPrefs::Get(context); 83 PrefService* prefs = user_prefs::UserPrefs::Get(context);
84 std::vector<std::string> dictionary_languages;
85
86 const base::CommandLine* command_line =
87 base::CommandLine::ForCurrentProcess();
88
89 StringPrefMember dictionary_languages_pref;
90 if (command_line->HasSwitch(switches::kEnableMultilingualSpellChecker)) {
91 dictionary_languages_pref.Init(prefs::kSpellCheckDictionaries, prefs);
92 base::SplitString(dictionary_languages_pref.GetValue(),
93 chrome::spellcheck_common::kDictionaryLanguagesSeparator,
94 &dictionary_languages);
95 } else {
96 dictionary_languages_pref.Init(prefs::kSpellCheckDictionary, prefs);
97 dictionary_languages.push_back(dictionary_languages_pref.GetValue());
98 }
99
100 std::vector<std::string> accept_languages;
82 StringPrefMember accept_languages_pref; 101 StringPrefMember accept_languages_pref;
83 StringPrefMember dictionary_language_pref;
84 accept_languages_pref.Init(prefs::kAcceptLanguages, prefs); 102 accept_languages_pref.Init(prefs::kAcceptLanguages, prefs);
85 dictionary_language_pref.Init(prefs::kSpellCheckDictionary, prefs);
86 std::string dictionary_language = dictionary_language_pref.GetValue();
87
88 // Now scan through the list of accept languages, and find possible mappings
89 // from this list to the existing list of spell check languages.
90 std::vector<std::string> accept_languages;
91 103
92 #if defined(OS_MACOSX) 104 #if defined(OS_MACOSX)
93 if (spellcheck_mac::SpellCheckerAvailable()) 105 if (spellcheck_mac::SpellCheckerAvailable())
94 spellcheck_mac::GetAvailableLanguages(&accept_languages); 106 spellcheck_mac::GetAvailableLanguages(&accept_languages);
95 else 107 else
96 base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages); 108 base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
97 #else 109 #else
98 base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages); 110 base::SplitString(accept_languages_pref.GetValue(), ',', &accept_languages);
99 #endif // !OS_MACOSX 111 #endif // !OS_MACOSX
100 112
101 GetSpellCheckLanguagesFromAcceptLanguages( 113 *languages = dictionary_languages;
102 accept_languages, dictionary_language, languages); 114 GetSpellCheckLanguagesFromAcceptLanguages(accept_languages, languages);
103 115
104 for (size_t i = 0; i < languages->size(); ++i) { 116 // |languages| vector begins with the entries from |dictionary_languages|,
105 if ((*languages)[i] == dictionary_language) 117 // therefore these indices are correct.
106 return i; 118 std::set<int> selected_language_indices;
107 } 119 for (size_t i = 0; i < dictionary_languages.size(); ++i)
108 return -1; 120 selected_language_indices.insert(i);
121
122 return selected_language_indices;
109 } 123 }
110 124
111 // static 125 // static
112 void SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages( 126 void SpellcheckService::GetSpellCheckLanguagesFromAcceptLanguages(
113 const std::vector<std::string>& accept_languages, 127 const std::vector<std::string>& accept_languages,
114 const std::string& dictionary_language,
115 std::vector<std::string>* languages) { 128 std::vector<std::string>* languages) {
116 // The current dictionary language should be there.
117 languages->push_back(dictionary_language);
118 129
119 for (std::vector<std::string>::const_iterator i = accept_languages.begin(); 130 for (std::vector<std::string>::const_iterator i = accept_languages.begin();
120 i != accept_languages.end(); ++i) { 131 i != accept_languages.end(); ++i) {
121 std::string language = 132 std::string language =
122 chrome::spellcheck_common::GetCorrespondingSpellCheckLanguage(*i); 133 chrome::spellcheck_common::GetCorrespondingSpellCheckLanguage(*i);
123 if (!language.empty() && 134 if (!language.empty() &&
124 std::find(languages->begin(), languages->end(), language) == 135 std::find(languages->begin(), languages->end(), language) ==
125 languages->end()) { 136 languages->end()) {
126 languages->push_back(language); 137 languages->push_back(language);
127 } 138 }
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 hunspell_dictionary_->AddObserver(this); 290 hunspell_dictionary_->AddObserver(this);
280 hunspell_dictionary_->Load(); 291 hunspell_dictionary_->Load();
281 } 292 }
282 293
283 void SpellcheckService::OnUseSpellingServiceChanged() { 294 void SpellcheckService::OnUseSpellingServiceChanged() {
284 bool enabled = pref_change_registrar_.prefs()->GetBoolean( 295 bool enabled = pref_change_registrar_.prefs()->GetBoolean(
285 prefs::kSpellCheckUseSpellingService); 296 prefs::kSpellCheckUseSpellingService);
286 if (metrics_) 297 if (metrics_)
287 metrics_->RecordSpellingServiceStats(enabled); 298 metrics_->RecordSpellingServiceStats(enabled);
288 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698