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/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/prefs/pref_service.h" | |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" | 17 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" |
18 #include "chrome/browser/chromeos/extensions/ime_menu_event_router.h" | |
17 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 19 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
18 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 20 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
19 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 21 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
22 #include "chrome/browser/profiles/profile.h" | |
20 #include "chrome/browser/spellchecker/spellcheck_factory.h" | 23 #include "chrome/browser/spellchecker/spellcheck_factory.h" |
21 #include "chrome/browser/spellchecker/spellcheck_service.h" | 24 #include "chrome/browser/spellchecker/spellcheck_service.h" |
22 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
23 #include "chrome/common/extensions/api/input_method_private.h" | 26 #include "chrome/common/extensions/api/input_method_private.h" |
27 #include "chrome/common/pref_names.h" | |
24 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
25 #include "components/browser_sync/browser/profile_sync_service.h" | 29 #include "components/browser_sync/browser/profile_sync_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/input_method_descriptor.h" | 33 #include "ui/base/ime/chromeos/input_method_descriptor.h" |
30 #include "ui/base/ime/chromeos/input_method_manager.h" | 34 #include "ui/base/ime/chromeos/input_method_manager.h" |
31 #include "ui/keyboard/keyboard_util.h" | 35 #include "ui/keyboard/keyboard_util.h" |
32 | 36 |
33 namespace AddWordToDictionary = | 37 namespace AddWordToDictionary = |
34 extensions::api::input_method_private::AddWordToDictionary; | 38 extensions::api::input_method_private::AddWordToDictionary; |
35 namespace SetCurrentInputMethod = | 39 namespace SetCurrentInputMethod = |
36 extensions::api::input_method_private::SetCurrentInputMethod; | 40 extensions::api::input_method_private::SetCurrentInputMethod; |
37 namespace OnChanged = extensions::api::input_method_private::OnChanged; | 41 namespace OnChanged = extensions::api::input_method_private::OnChanged; |
38 namespace OnDictionaryChanged = | 42 namespace OnDictionaryChanged = |
39 extensions::api::input_method_private::OnDictionaryChanged; | 43 extensions::api::input_method_private::OnDictionaryChanged; |
40 namespace OnDictionaryLoaded = | 44 namespace OnDictionaryLoaded = |
41 extensions::api::input_method_private::OnDictionaryLoaded; | 45 extensions::api::input_method_private::OnDictionaryLoaded; |
46 namespace OnImeMenuActivationChanged = | |
47 extensions::api::input_method_private::OnImeMenuActivationChanged; | |
42 | 48 |
43 namespace { | 49 namespace { |
44 | 50 |
45 // Prefix, which is used by XKB. | 51 // Prefix, which is used by XKB. |
46 const char kXkbPrefix[] = "xkb:"; | 52 const char kXkbPrefix[] = "xkb:"; |
47 | 53 |
48 } // namespace | 54 } // namespace |
49 | 55 |
50 namespace extensions { | 56 namespace extensions { |
51 | 57 |
52 ExtensionFunction::ResponseAction | 58 ExtensionFunction::ResponseAction |
53 InputMethodPrivateGetInputMethodConfigFunction::Run() { | 59 InputMethodPrivateGetInputMethodConfigFunction::Run() { |
54 #if !defined(OS_CHROMEOS) | 60 #if !defined(OS_CHROMEOS) |
55 EXTENSION_FUNCTION_VALIDATE(false); | 61 EXTENSION_FUNCTION_VALIDATE(false); |
56 #else | 62 #else |
57 base::DictionaryValue* output = new base::DictionaryValue(); | 63 base::DictionaryValue* output = new base::DictionaryValue(); |
58 output->SetBoolean( | 64 output->SetBoolean( |
59 "isPhysicalKeyboardAutocorrectEnabled", | 65 "isPhysicalKeyboardAutocorrectEnabled", |
60 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 66 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
61 chromeos::switches::kDisablePhysicalKeyboardAutocorrect)); | 67 chromeos::switches::kDisablePhysicalKeyboardAutocorrect)); |
68 output->SetBoolean("isImeMenuActivated", | |
69 chromeos::switches::IsImeMenuEnabled() && | |
70 Profile::FromBrowserContext(browser_context()) | |
michaelpg
2016/01/20 21:06:28
nit: align w/ previous line
Azure Wei
2016/01/21 10:25:07
Done.
| |
71 ->GetPrefs() | |
72 ->GetBoolean(prefs::kLangugaeImeMenuActivated)); | |
62 return RespondNow(OneArgument(output)); | 73 return RespondNow(OneArgument(output)); |
63 #endif | 74 #endif |
64 } | 75 } |
65 | 76 |
66 ExtensionFunction::ResponseAction | 77 ExtensionFunction::ResponseAction |
67 InputMethodPrivateGetCurrentInputMethodFunction::Run() { | 78 InputMethodPrivateGetCurrentInputMethodFunction::Run() { |
68 #if !defined(OS_CHROMEOS) | 79 #if !defined(OS_CHROMEOS) |
69 EXTENSION_FUNCTION_VALIDATE(false); | 80 EXTENSION_FUNCTION_VALIDATE(false); |
70 #else | 81 #else |
71 chromeos::input_method::InputMethodManager* manager = | 82 chromeos::input_method::InputMethodManager* manager = |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 new chromeos::ExtensionInputMethodEventRouter(context_)); | 249 new chromeos::ExtensionInputMethodEventRouter(context_)); |
239 } else if (details.event_name == OnDictionaryChanged::kEventName || | 250 } else if (details.event_name == OnDictionaryChanged::kEventName || |
240 details.event_name == OnDictionaryLoaded::kEventName) { | 251 details.event_name == OnDictionaryLoaded::kEventName) { |
241 if (!dictionary_event_router_.get()) { | 252 if (!dictionary_event_router_.get()) { |
242 dictionary_event_router_.reset( | 253 dictionary_event_router_.reset( |
243 new chromeos::ExtensionDictionaryEventRouter(context_)); | 254 new chromeos::ExtensionDictionaryEventRouter(context_)); |
244 } | 255 } |
245 if (details.event_name == OnDictionaryLoaded::kEventName) { | 256 if (details.event_name == OnDictionaryLoaded::kEventName) { |
246 dictionary_event_router_->DispatchLoadedEventIfLoaded(); | 257 dictionary_event_router_->DispatchLoadedEventIfLoaded(); |
247 } | 258 } |
259 } else if (details.event_name == OnImeMenuActivationChanged::kEventName && | |
260 !ime_menu_event_router_.get()) { | |
261 ime_menu_event_router_.reset( | |
262 new chromeos::ExtensionImeMenuEventRouter(context_)); | |
248 } | 263 } |
249 } | 264 } |
250 | 265 |
251 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 266 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
252 g_factory = LAZY_INSTANCE_INITIALIZER; | 267 g_factory = LAZY_INSTANCE_INITIALIZER; |
253 | 268 |
254 // static | 269 // static |
255 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 270 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
256 InputMethodAPI::GetFactoryInstance() { | 271 InputMethodAPI::GetFactoryInstance() { |
257 return g_factory.Pointer(); | 272 return g_factory.Pointer(); |
258 } | 273 } |
259 | 274 |
260 } // namespace extensions | 275 } // namespace extensions |
OLD | NEW |