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

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_api.cc

Issue 11611004: Move the InputComponents out of extensions entirely. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
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/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
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
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 const std::vector<InputComponentInfo>* input_components =
856 extension->input_components().begin(); 874 extensions::InputComponents::GetInputComponents(extension);
857 component != extension->input_components().end(); 875 if (!input_components)
858 ++component) { 876 return;
859 if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) { 877 for (std::vector<extensions::InputComponentInfo>::const_iterator component =
878 input_components->begin(); component != input_components->end();
879 ++component) {
880 if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) {
860 input_ime_event_router()->RegisterIme( 881 input_ime_event_router()->RegisterIme(
861 profile_, extension->id(), *component); 882 profile_, extension->id(), *component);
862 } 883 }
863 } 884 }
864 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { 885 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
865 const Extension* extension = 886 const Extension* extension =
866 content::Details<const UnloadedExtensionInfo>(details)->extension; 887 content::Details<const UnloadedExtensionInfo>(details)->extension;
867 if (extension->input_components().size() > 0) { 888 const std::vector<InputComponentInfo>* input_components =
889 extensions::InputComponents::GetInputComponents(extension);
890 if (!input_components)
891 return;
892 if (input_components->size() > 0) {
868 input_ime_event_router()->UnregisterAllImes(profile_, extension->id()); 893 input_ime_event_router()->UnregisterAllImes(profile_, extension->id());
869 } 894 }
870 } 895 }
871 } 896 }
872 897
873 InputImeEventRouter* InputImeAPI::input_ime_event_router() { 898 InputImeEventRouter* InputImeAPI::input_ime_event_router() {
874 return InputImeEventRouter::GetInstance(); 899 return InputImeEventRouter::GetInstance();
875 } 900 }
876 901
902 static base::LazyInstance<ProfileKeyedAPIFactory<InputImeAPI> >
903 g_factory = LAZY_INSTANCE_INITIALIZER;
904
905 template <>
906 ProfileKeyedAPIFactory<InputImeAPI>*
907 ProfileKeyedAPIFactory<InputImeAPI>::GetInstance() {
908 return &g_factory.Get();
909 }
910
877 } // namespace extensions 911 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698