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

Side by Side Diff: chrome/browser/chromeos/extensions/input_method_api.cc

Issue 973213003: Adds extension events for custom dictionary load/change. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Use weakptr. 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/chromeos/extensions/input_method_api.h" 5 #include "chrome/browser/chromeos/extensions/input_method_api.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h"
10 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 11 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
11 #include "chrome/browser/chromeos/input_method/input_method_util.h" 12 #include "chrome/browser/chromeos/input_method/input_method_util.h"
12 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" 13 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
13 #include "chrome/browser/spellchecker/spellcheck_factory.h" 14 #include "chrome/browser/spellchecker/spellcheck_factory.h"
14 #include "chrome/browser/spellchecker/spellcheck_service.h" 15 #include "chrome/browser/spellchecker/spellcheck_service.h"
15 #include "chromeos/chromeos_switches.h" 16 #include "chromeos/chromeos_switches.h"
16 #include "extensions/browser/extension_function_registry.h" 17 #include "extensions/browser/extension_function_registry.h"
17 #include "extensions/browser/extension_system.h" 18 #include "extensions/browser/extension_system.h"
18 #include "extensions/common/value_builder.h" 19 #include "extensions/common/value_builder.h"
19 #include "ui/base/ime/chromeos/extension_ime_util.h" 20 #include "ui/base/ime/chromeos/extension_ime_util.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // - Already in the dictionary. 151 // - Already in the dictionary.
151 // - Not a UTF8 string. 152 // - Not a UTF8 string.
152 // - Longer than 99 bytes (MAX_CUSTOM_DICTIONARY_WORD_BYTES). 153 // - Longer than 99 bytes (MAX_CUSTOM_DICTIONARY_WORD_BYTES).
153 // - Leading/trailing whitespace. 154 // - Leading/trailing whitespace.
154 // - Empty. 155 // - Empty.
155 return RespondNow(Error("Unable to add invalid word to dictionary.")); 156 return RespondNow(Error("Unable to add invalid word to dictionary."));
156 #endif 157 #endif
157 } 158 }
158 159
159 // static 160 // static
161 const char InputMethodAPI::kOnDictionaryChanged[] =
162 "inputMethodPrivate.onDictionaryChanged";
163
164 // static
165 const char InputMethodAPI::kOnDictionaryLoaded[] =
166 "inputMethodPrivate.onDictionaryLoaded";
167
168 // static
160 const char InputMethodAPI::kOnInputMethodChanged[] = 169 const char InputMethodAPI::kOnInputMethodChanged[] =
161 "inputMethodPrivate.onChanged"; 170 "inputMethodPrivate.onChanged";
162 171
163 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) 172 InputMethodAPI::InputMethodAPI(content::BrowserContext* context)
164 : context_(context) { 173 : context_(context) {
165 EventRouter::Get(context_)->RegisterObserver(this, kOnInputMethodChanged); 174 EventRouter::Get(context_)->RegisterObserver(this, kOnInputMethodChanged);
175 EventRouter::Get(context_)->RegisterObserver(this, kOnDictionaryChanged);
176 EventRouter::Get(context_)->RegisterObserver(this, kOnDictionaryLoaded);
166 ExtensionFunctionRegistry* registry = 177 ExtensionFunctionRegistry* registry =
167 ExtensionFunctionRegistry::GetInstance(); 178 ExtensionFunctionRegistry::GetInstance();
168 registry->RegisterFunction<GetInputMethodConfigFunction>(); 179 registry->RegisterFunction<GetInputMethodConfigFunction>();
169 registry->RegisterFunction<GetCurrentInputMethodFunction>(); 180 registry->RegisterFunction<GetCurrentInputMethodFunction>();
170 registry->RegisterFunction<SetCurrentInputMethodFunction>(); 181 registry->RegisterFunction<SetCurrentInputMethodFunction>();
171 registry->RegisterFunction<GetInputMethodsFunction>(); 182 registry->RegisterFunction<GetInputMethodsFunction>();
172 registry->RegisterFunction<FetchAllDictionaryWordsFunction>(); 183 registry->RegisterFunction<FetchAllDictionaryWordsFunction>();
173 registry->RegisterFunction<AddWordToDictionaryFunction>(); 184 registry->RegisterFunction<AddWordToDictionaryFunction>();
174 } 185 }
175 186
(...skipping 10 matching lines...) Expand all
186 } 197 }
187 198
188 void InputMethodAPI::Shutdown() { 199 void InputMethodAPI::Shutdown() {
189 // UnregisterObserver may have already been called in OnListenerAdded, 200 // UnregisterObserver may have already been called in OnListenerAdded,
190 // but it is safe to call it more than once. 201 // but it is safe to call it more than once.
191 EventRouter::Get(context_)->UnregisterObserver(this); 202 EventRouter::Get(context_)->UnregisterObserver(this);
192 } 203 }
193 204
194 void InputMethodAPI::OnListenerAdded( 205 void InputMethodAPI::OnListenerAdded(
195 const extensions::EventListenerInfo& details) { 206 const extensions::EventListenerInfo& details) {
196 DCHECK(!input_method_event_router_.get()); 207 if (details.event_name == kOnInputMethodChanged) {
197 input_method_event_router_.reset( 208 if (!input_method_event_router_.get()) {
198 new chromeos::ExtensionInputMethodEventRouter(context_)); 209 input_method_event_router_.reset(
199 EventRouter::Get(context_)->UnregisterObserver(this); 210 new chromeos::ExtensionInputMethodEventRouter(context_));
211 }
212 } else if (details.event_name == kOnDictionaryChanged ||
213 details.event_name == kOnDictionaryLoaded) {
214 if (!dictionary_event_router_.get()) {
215 dictionary_event_router_.reset(
216 new chromeos::ExtensionDictionaryEventRouter(context_));
217 }
218 }
200 } 219 }
201 220
202 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > 221 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> >
203 g_factory = LAZY_INSTANCE_INITIALIZER; 222 g_factory = LAZY_INSTANCE_INITIALIZER;
204 223
205 // static 224 // static
206 BrowserContextKeyedAPIFactory<InputMethodAPI>* 225 BrowserContextKeyedAPIFactory<InputMethodAPI>*
207 InputMethodAPI::GetFactoryInstance() { 226 InputMethodAPI::GetFactoryInstance() {
208 return g_factory.Pointer(); 227 return g_factory.Pointer();
209 } 228 }
210 229
211 } // namespace extensions 230 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698