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/ui/webui/options/language_dictionary_overlay_handler.h" | 5 #include "chrome/browser/ui/webui/options/language_dictionary_overlay_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 10 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
11 #include "chrome/browser/spellchecker/spellcheck_service.h" | 11 #include "chrome/browser/spellchecker/spellcheck_service.h" |
12 #include "content/public/browser/web_ui.h" | 12 #include "content/public/browser/web_ui.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 | 15 |
16 namespace options { | 16 namespace options { |
17 | 17 |
18 namespace { | |
19 bool StringCompare(const std::string& a, const std::string& b) { | |
20 return a.compare(b) < 0; | |
21 } | |
22 } // namespace | |
23 | |
24 LanguageDictionaryOverlayHandler::LanguageDictionaryOverlayHandler() | 18 LanguageDictionaryOverlayHandler::LanguageDictionaryOverlayHandler() |
25 : overlay_initialized_(false), | 19 : overlay_initialized_(false), |
26 dictionary_(NULL) { | 20 dictionary_(NULL) { |
27 } | 21 } |
28 | 22 |
29 LanguageDictionaryOverlayHandler::~LanguageDictionaryOverlayHandler() { | 23 LanguageDictionaryOverlayHandler::~LanguageDictionaryOverlayHandler() { |
30 } | 24 } |
31 | 25 |
32 void LanguageDictionaryOverlayHandler::GetLocalizedValues( | 26 void LanguageDictionaryOverlayHandler::GetLocalizedValues( |
33 base::DictionaryValue* localized_strings) { | 27 base::DictionaryValue* localized_strings) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void LanguageDictionaryOverlayHandler::ResetDictionaryWords() { | 86 void LanguageDictionaryOverlayHandler::ResetDictionaryWords() { |
93 if (!overlay_initialized_) | 87 if (!overlay_initialized_) |
94 return; | 88 return; |
95 | 89 |
96 if (!dictionary_) { | 90 if (!dictionary_) { |
97 dictionary_ = SpellcheckServiceFactory::GetForProfile( | 91 dictionary_ = SpellcheckServiceFactory::GetForProfile( |
98 Profile::FromWebUI(web_ui()))->GetCustomDictionary(); | 92 Profile::FromWebUI(web_ui()))->GetCustomDictionary(); |
99 dictionary_->AddObserver(this); | 93 dictionary_->AddObserver(this); |
100 } | 94 } |
101 | 95 |
102 std::vector<std::string> words = dictionary_->GetWords(); | |
103 std::sort(words.begin(), words.end(), StringCompare); | |
104 ListValue list_value; | 96 ListValue list_value; |
105 list_value.AppendStrings(words); | 97 list_value.AppendStrings(dictionary_->GetWords()); |
106 web_ui()->CallJavascriptFunction("EditDictionaryOverlay.setWordList", | 98 web_ui()->CallJavascriptFunction("EditDictionaryOverlay.setWordList", |
107 list_value); | 99 list_value); |
108 } | 100 } |
109 | 101 |
110 void LanguageDictionaryOverlayHandler::RefreshWords(const ListValue* args) { | 102 void LanguageDictionaryOverlayHandler::RefreshWords(const ListValue* args) { |
111 overlay_initialized_ = true; | 103 overlay_initialized_ = true; |
112 ResetDictionaryWords(); | 104 ResetDictionaryWords(); |
113 } | 105 } |
114 | 106 |
115 void LanguageDictionaryOverlayHandler::AddWord(const ListValue* args) { | 107 void LanguageDictionaryOverlayHandler::AddWord(const ListValue* args) { |
116 std::string new_word; | 108 std::string new_word; |
117 if (!args->GetString(0, &new_word) || new_word.empty() || !dictionary_) { | 109 if (!args->GetString(0, &new_word) || new_word.empty() || !dictionary_) { |
118 NOTREACHED(); | 110 NOTREACHED(); |
119 return; | 111 return; |
120 } | 112 } |
121 dictionary_->AddWord(new_word); | 113 dictionary_->AddWord(new_word); |
122 } | 114 } |
123 | 115 |
124 void LanguageDictionaryOverlayHandler::RemoveWord(const ListValue* args) { | 116 void LanguageDictionaryOverlayHandler::RemoveWord(const ListValue* args) { |
125 std::string old_word; | 117 std::string old_word; |
126 if (!args->GetString(0, &old_word) || old_word.empty() || !dictionary_) { | 118 if (!args->GetString(0, &old_word) || old_word.empty() || !dictionary_) { |
127 NOTREACHED(); | 119 NOTREACHED(); |
128 return; | 120 return; |
129 } | 121 } |
130 dictionary_->RemoveWord(old_word); | 122 dictionary_->RemoveWord(old_word); |
131 } | 123 } |
132 | 124 |
133 } // namespace options | 125 } // namespace options |
OLD | NEW |