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/extensions/api/input_ime/input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/lazy_instance.h" | |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 12 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
12 #include "chrome/browser/extensions/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
14 #include "chrome/browser/extensions/extension_function_registry.h" | |
13 #include "chrome/browser/extensions/extension_input_module_constants.h" | 15 #include "chrome/browser/extensions/extension_input_module_constants.h" |
14 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/extensions/extension_manifest_constants.h" | |
16 | 19 |
17 namespace keys = extension_input_module_constants; | 20 namespace keys = extension_input_module_constants; |
18 | 21 |
19 namespace { | 22 namespace { |
20 | 23 |
21 const char kStyleNone[] = "none"; | 24 const char kStyleNone[] = "none"; |
22 const char kStyleCheck[] = "check"; | 25 const char kStyleCheck[] = "check"; |
23 const char kStyleRadio[] = "radio"; | 26 const char kStyleRadio[] = "radio"; |
24 const char kStyleSeparator[] = "separator"; | 27 const char kStyleSeparator[] = "separator"; |
25 | 28 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 | 315 |
313 InputImeEventRouter* | 316 InputImeEventRouter* |
314 InputImeEventRouter::GetInstance() { | 317 InputImeEventRouter::GetInstance() { |
315 return Singleton<InputImeEventRouter>::get(); | 318 return Singleton<InputImeEventRouter>::get(); |
316 } | 319 } |
317 | 320 |
318 #if defined(OS_CHROMEOS) | 321 #if defined(OS_CHROMEOS) |
319 bool InputImeEventRouter::RegisterIme( | 322 bool InputImeEventRouter::RegisterIme( |
320 Profile* profile, | 323 Profile* profile, |
321 const std::string& extension_id, | 324 const std::string& extension_id, |
322 const extensions::Extension::InputComponentInfo& component) { | 325 const extensions::InputComponentInfo& component) { |
323 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; | 326 VLOG(1) << "RegisterIme: " << extension_id << " id: " << component.id; |
324 | 327 |
325 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = | 328 std::map<std::string, chromeos::InputMethodEngine*>& engine_map = |
326 engines_[extension_id]; | 329 engines_[extension_id]; |
327 | 330 |
328 std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = | 331 std::map<std::string, chromeos::InputMethodEngine*>::iterator engine_ix = |
329 engine_map.find(component.id); | 332 engine_map.find(component.id); |
330 if (engine_ix != engine_map.end()) { | 333 if (engine_ix != engine_map.end()) { |
331 return false; | 334 return false; |
332 } | 335 } |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
830 | 833 |
831 InputImeEventRouter::GetInstance()->OnKeyEventHandled( | 834 InputImeEventRouter::GetInstance()->OnKeyEventHandled( |
832 extension_id(), request_id_str, handled); | 835 extension_id(), request_id_str, handled); |
833 | 836 |
834 return true; | 837 return true; |
835 } | 838 } |
836 #endif | 839 #endif |
837 | 840 |
838 InputImeAPI::InputImeAPI(Profile* profile) | 841 InputImeAPI::InputImeAPI(Profile* profile) |
839 : profile_(profile) { | 842 : profile_(profile) { |
843 ManifestHandler::Register(extension_manifest_keys::kInputComponents, | |
844 new InputComponentsHandler); | |
845 | |
840 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 846 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
841 content::Source<Profile>(profile)); | 847 content::Source<Profile>(profile)); |
842 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 848 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
843 content::Source<Profile>(profile)); | 849 content::Source<Profile>(profile)); |
850 | |
851 ExtensionFunctionRegistry* registry = | |
852 ExtensionFunctionRegistry::GetInstance(); | |
853 registry->RegisterFunction<SetCompositionFunction>(); | |
854 registry->RegisterFunction<ClearCompositionFunction>(); | |
855 registry->RegisterFunction<CommitTextFunction>(); | |
856 registry->RegisterFunction<SetCandidateWindowPropertiesFunction>(); | |
857 registry->RegisterFunction<SetCandidatesFunction>(); | |
858 registry->RegisterFunction<SetCursorPositionFunction>(); | |
859 registry->RegisterFunction<SetMenuItemsFunction>(); | |
860 registry->RegisterFunction<UpdateMenuItemsFunction>(); | |
861 registry->RegisterFunction<KeyEventHandled>(); | |
844 } | 862 } |
845 | 863 |
846 InputImeAPI::~InputImeAPI() { | 864 InputImeAPI::~InputImeAPI() { |
847 } | 865 } |
848 | 866 |
849 void InputImeAPI::Observe(int type, | 867 void InputImeAPI::Observe(int type, |
850 const content::NotificationSource& source, | 868 const content::NotificationSource& source, |
851 const content::NotificationDetails& details) { | 869 const content::NotificationDetails& details) { |
852 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 870 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
853 const Extension* extension = | 871 const Extension* extension = |
854 content::Details<const Extension>(details).ptr(); | 872 content::Details<const Extension>(details).ptr(); |
855 for (std::vector<Extension::InputComponentInfo>::const_iterator component = | 873 if (extensions::InputComponents::GetInputComponents(extension) == NULL) |
Yoyo Zhou
2012/12/28 21:04:28
You should assign the InputComponents to a tempora
SanjoyPal
2012/12/28 22:38:30
Done.
| |
856 extension->input_components().begin(); | 874 return; |
857 component != extension->input_components().end(); | 875 for (std::vector<extensions::InputComponentInfo>::const_iterator component = |
858 ++component) { | 876 extensions::InputComponents::GetInputComponents(extension)-> |
859 if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) { | 877 input_components.begin(); component != extensions::InputComponents:: |
878 GetInputComponents(extension)->input_components.end(); ++component) { | |
879 if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) { | |
860 input_ime_event_router()->RegisterIme( | 880 input_ime_event_router()->RegisterIme( |
861 profile_, extension->id(), *component); | 881 profile_, extension->id(), *component); |
862 } | 882 } |
863 } | 883 } |
864 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 884 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
865 const Extension* extension = | 885 const Extension* extension = |
866 content::Details<const UnloadedExtensionInfo>(details)->extension; | 886 content::Details<const UnloadedExtensionInfo>(details)->extension; |
867 if (extension->input_components().size() > 0) { | 887 if (extensions::InputComponents::GetInputComponents(extension)-> |
888 input_components.size() > 0) { | |
868 input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); | 889 input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); |
869 } | 890 } |
870 } | 891 } |
871 } | 892 } |
872 | 893 |
873 InputImeEventRouter* InputImeAPI::input_ime_event_router() { | 894 InputImeEventRouter* InputImeAPI::input_ime_event_router() { |
874 return InputImeEventRouter::GetInstance(); | 895 return InputImeEventRouter::GetInstance(); |
875 } | 896 } |
876 | 897 |
898 static base::LazyInstance<ProfileKeyedAPIFactory<InputImeAPI> > | |
899 g_factory = LAZY_INSTANCE_INITIALIZER; | |
900 | |
901 template <> | |
902 ProfileKeyedAPIFactory<InputImeAPI>* | |
903 ProfileKeyedAPIFactory<InputImeAPI>::GetInstance() { | |
904 return &g_factory.Get(); | |
905 } | |
906 | |
877 } // namespace extensions | 907 } // namespace extensions |
OLD | NEW |