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

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

Issue 1552743003: Add chrome.inputMethodPrivate.onImeMenuActivationChanged API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 <stddef.h> 7 #include <stddef.h>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" 16 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h"
17 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h"
17 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 18 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
18 #include "chrome/browser/chromeos/input_method/input_method_util.h" 19 #include "chrome/browser/chromeos/input_method/input_method_util.h"
19 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" 20 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
21 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/spellchecker/spellcheck_factory.h" 22 #include "chrome/browser/spellchecker/spellcheck_factory.h"
21 #include "chrome/browser/spellchecker/spellcheck_service.h" 23 #include "chrome/browser/spellchecker/spellcheck_service.h"
22 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
23 #include "chrome/common/extensions/api/input_method_private.h" 25 #include "chrome/common/extensions/api/input_method_private.h"
26 #include "chrome/common/pref_names.h"
24 #include "chromeos/chromeos_switches.h" 27 #include "chromeos/chromeos_switches.h"
25 #include "components/browser_sync/browser/profile_sync_service.h" 28 #include "components/browser_sync/browser/profile_sync_service.h"
29 #include "components/prefs/pref_service.h"
26 #include "extensions/browser/extension_function_registry.h" 30 #include "extensions/browser/extension_function_registry.h"
27 #include "extensions/browser/extension_system.h" 31 #include "extensions/browser/extension_system.h"
28 #include "ui/base/ime/chromeos/extension_ime_util.h" 32 #include "ui/base/ime/chromeos/extension_ime_util.h"
29 #include "ui/base/ime/chromeos/ime_keyboard.h" 33 #include "ui/base/ime/chromeos/ime_keyboard.h"
30 #include "ui/base/ime/chromeos/input_method_descriptor.h" 34 #include "ui/base/ime/chromeos/input_method_descriptor.h"
31 #include "ui/base/ime/chromeos/input_method_manager.h" 35 #include "ui/base/ime/chromeos/input_method_manager.h"
32 #include "ui/keyboard/keyboard_util.h" 36 #include "ui/keyboard/keyboard_util.h"
33 37
34 namespace AddWordToDictionary = 38 namespace AddWordToDictionary =
35 extensions::api::input_method_private::AddWordToDictionary; 39 extensions::api::input_method_private::AddWordToDictionary;
36 namespace SetCurrentInputMethod = 40 namespace SetCurrentInputMethod =
37 extensions::api::input_method_private::SetCurrentInputMethod; 41 extensions::api::input_method_private::SetCurrentInputMethod;
38 namespace SetXkbLayout = extensions::api::input_method_private::SetXkbLayout; 42 namespace SetXkbLayout = extensions::api::input_method_private::SetXkbLayout;
39 namespace OnChanged = extensions::api::input_method_private::OnChanged; 43 namespace OnChanged = extensions::api::input_method_private::OnChanged;
40 namespace OnDictionaryChanged = 44 namespace OnDictionaryChanged =
41 extensions::api::input_method_private::OnDictionaryChanged; 45 extensions::api::input_method_private::OnDictionaryChanged;
42 namespace OnDictionaryLoaded = 46 namespace OnDictionaryLoaded =
43 extensions::api::input_method_private::OnDictionaryLoaded; 47 extensions::api::input_method_private::OnDictionaryLoaded;
48 namespace OnImeMenuActivationChanged =
49 extensions::api::input_method_private::OnImeMenuActivationChanged;
44 50
45 namespace { 51 namespace {
46 52
47 // Prefix, which is used by XKB. 53 // Prefix, which is used by XKB.
48 const char kXkbPrefix[] = "xkb:"; 54 const char kXkbPrefix[] = "xkb:";
49 55
50 } // namespace 56 } // namespace
51 57
52 namespace extensions { 58 namespace extensions {
53 59
54 ExtensionFunction::ResponseAction 60 ExtensionFunction::ResponseAction
55 InputMethodPrivateGetInputMethodConfigFunction::Run() { 61 InputMethodPrivateGetInputMethodConfigFunction::Run() {
56 #if !defined(OS_CHROMEOS) 62 #if !defined(OS_CHROMEOS)
57 EXTENSION_FUNCTION_VALIDATE(false); 63 EXTENSION_FUNCTION_VALIDATE(false);
58 #else 64 #else
59 base::DictionaryValue* output = new base::DictionaryValue(); 65 base::DictionaryValue* output = new base::DictionaryValue();
60 output->SetBoolean( 66 output->SetBoolean(
61 "isPhysicalKeyboardAutocorrectEnabled", 67 "isPhysicalKeyboardAutocorrectEnabled",
62 !base::CommandLine::ForCurrentProcess()->HasSwitch( 68 !base::CommandLine::ForCurrentProcess()->HasSwitch(
63 chromeos::switches::kDisablePhysicalKeyboardAutocorrect)); 69 chromeos::switches::kDisablePhysicalKeyboardAutocorrect));
70 output->SetBoolean(
71 "isImeMenuActivated",
72 chromeos::switches::IsImeMenuEnabled() &&
73 Profile::FromBrowserContext(browser_context())->GetPrefs()
74 ->GetBoolean(prefs::kLanguageImeMenuActivated));
64 return RespondNow(OneArgument(output)); 75 return RespondNow(OneArgument(output));
65 #endif 76 #endif
66 } 77 }
67 78
68 ExtensionFunction::ResponseAction 79 ExtensionFunction::ResponseAction
69 InputMethodPrivateGetCurrentInputMethodFunction::Run() { 80 InputMethodPrivateGetCurrentInputMethodFunction::Run() {
70 #if !defined(OS_CHROMEOS) 81 #if !defined(OS_CHROMEOS)
71 EXTENSION_FUNCTION_VALIDATE(false); 82 EXTENSION_FUNCTION_VALIDATE(false);
72 #else 83 #else
73 chromeos::input_method::InputMethodManager* manager = 84 chromeos::input_method::InputMethodManager* manager =
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 #endif 223 #endif
213 } 224 }
214 225
215 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) 226 InputMethodAPI::InputMethodAPI(content::BrowserContext* context)
216 : context_(context) { 227 : context_(context) {
217 EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName); 228 EventRouter::Get(context_)->RegisterObserver(this, OnChanged::kEventName);
218 EventRouter::Get(context_) 229 EventRouter::Get(context_)
219 ->RegisterObserver(this, OnDictionaryChanged::kEventName); 230 ->RegisterObserver(this, OnDictionaryChanged::kEventName);
220 EventRouter::Get(context_) 231 EventRouter::Get(context_)
221 ->RegisterObserver(this, OnDictionaryLoaded::kEventName); 232 ->RegisterObserver(this, OnDictionaryLoaded::kEventName);
233 EventRouter::Get(context_)
234 ->RegisterObserver(this, OnImeMenuActivationChanged::kEventName);
222 ExtensionFunctionRegistry* registry = 235 ExtensionFunctionRegistry* registry =
223 ExtensionFunctionRegistry::GetInstance(); 236 ExtensionFunctionRegistry::GetInstance();
224 registry->RegisterFunction<InputMethodPrivateGetInputMethodConfigFunction>(); 237 registry->RegisterFunction<InputMethodPrivateGetInputMethodConfigFunction>();
225 registry->RegisterFunction<InputMethodPrivateGetCurrentInputMethodFunction>(); 238 registry->RegisterFunction<InputMethodPrivateGetCurrentInputMethodFunction>();
226 registry->RegisterFunction<InputMethodPrivateSetCurrentInputMethodFunction>(); 239 registry->RegisterFunction<InputMethodPrivateSetCurrentInputMethodFunction>();
227 registry->RegisterFunction<InputMethodPrivateGetInputMethodsFunction>(); 240 registry->RegisterFunction<InputMethodPrivateGetInputMethodsFunction>();
228 registry 241 registry
229 ->RegisterFunction<InputMethodPrivateFetchAllDictionaryWordsFunction>(); 242 ->RegisterFunction<InputMethodPrivateFetchAllDictionaryWordsFunction>();
230 registry->RegisterFunction<InputMethodPrivateAddWordToDictionaryFunction>(); 243 registry->RegisterFunction<InputMethodPrivateAddWordToDictionaryFunction>();
231 registry->RegisterFunction<InputMethodPrivateGetEncryptSyncEnabledFunction>(); 244 registry->RegisterFunction<InputMethodPrivateGetEncryptSyncEnabledFunction>();
(...skipping 23 matching lines...) Expand all
255 new chromeos::ExtensionInputMethodEventRouter(context_)); 268 new chromeos::ExtensionInputMethodEventRouter(context_));
256 } else if (details.event_name == OnDictionaryChanged::kEventName || 269 } else if (details.event_name == OnDictionaryChanged::kEventName ||
257 details.event_name == OnDictionaryLoaded::kEventName) { 270 details.event_name == OnDictionaryLoaded::kEventName) {
258 if (!dictionary_event_router_.get()) { 271 if (!dictionary_event_router_.get()) {
259 dictionary_event_router_.reset( 272 dictionary_event_router_.reset(
260 new chromeos::ExtensionDictionaryEventRouter(context_)); 273 new chromeos::ExtensionDictionaryEventRouter(context_));
261 } 274 }
262 if (details.event_name == OnDictionaryLoaded::kEventName) { 275 if (details.event_name == OnDictionaryLoaded::kEventName) {
263 dictionary_event_router_->DispatchLoadedEventIfLoaded(); 276 dictionary_event_router_->DispatchLoadedEventIfLoaded();
264 } 277 }
278 } else if (details.event_name == OnImeMenuActivationChanged::kEventName &&
279 !ime_menu_event_router_.get()) {
280 ime_menu_event_router_.reset(
281 new chromeos::ExtensionImeMenuEventRouter(context_));
265 } 282 }
266 } 283 }
267 284
268 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > 285 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> >
269 g_factory = LAZY_INSTANCE_INITIALIZER; 286 g_factory = LAZY_INSTANCE_INITIALIZER;
270 287
271 // static 288 // static
272 BrowserContextKeyedAPIFactory<InputMethodAPI>* 289 BrowserContextKeyedAPIFactory<InputMethodAPI>*
273 InputMethodAPI::GetFactoryInstance() { 290 InputMethodAPI::GetFactoryInstance() {
274 return g_factory.Pointer(); 291 return g_factory.Pointer();
275 } 292 }
276 293
277 } // namespace extensions 294 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698