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 "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" | 9 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
10 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" | 10 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
11 #include "chrome/browser/extensions/event_names.h" | 11 #include "chrome/browser/extensions/event_names.h" |
12 #include "chrome/browser/extensions/extension_function_registry.h" | 12 #include "chrome/browser/extensions/extension_function_registry.h" |
13 #include "chrome/browser/extensions/extension_system.h" | |
14 #include "chromeos/ime/input_method_manager.h" | 13 #include "chromeos/ime/input_method_manager.h" |
| 14 #include "extensions/browser/extension_system.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // Prefix, which is used by XKB. | 18 // Prefix, which is used by XKB. |
19 const char kXkbPrefix[] = "xkb:"; | 19 const char kXkbPrefix[] = "xkb:"; |
20 | 20 |
21 } // namespace | 21 } // namespace |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
24 | 24 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 chromeos::InputMethodEngineInterface* engine = | 56 chromeos::InputMethodEngineInterface* engine = |
57 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); | 57 InputImeEventRouter::GetInstance()->GetActiveEngine(extension_id()); |
58 if (engine) | 58 if (engine) |
59 engine->StartIme(); | 59 engine->StartIme(); |
60 return true; | 60 return true; |
61 #endif | 61 #endif |
62 } | 62 } |
63 | 63 |
64 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) | 64 InputMethodAPI::InputMethodAPI(content::BrowserContext* context) |
65 : context_(context) { | 65 : context_(context) { |
66 ExtensionSystem::GetForBrowserContext(context_)->event_router()-> | 66 ExtensionSystem::Get(context_)->event_router()-> |
67 RegisterObserver(this, event_names::kOnInputMethodChanged); | 67 RegisterObserver(this, event_names::kOnInputMethodChanged); |
68 ExtensionFunctionRegistry* registry = | 68 ExtensionFunctionRegistry* registry = |
69 ExtensionFunctionRegistry::GetInstance(); | 69 ExtensionFunctionRegistry::GetInstance(); |
70 registry->RegisterFunction<GetInputMethodFunction>(); | 70 registry->RegisterFunction<GetInputMethodFunction>(); |
71 registry->RegisterFunction<StartImeFunction>(); | 71 registry->RegisterFunction<StartImeFunction>(); |
72 } | 72 } |
73 | 73 |
74 InputMethodAPI::~InputMethodAPI() { | 74 InputMethodAPI::~InputMethodAPI() { |
75 } | 75 } |
76 | 76 |
77 // static | 77 // static |
78 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { | 78 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { |
79 size_t prefix_length = std::string(kXkbPrefix).length(); | 79 size_t prefix_length = std::string(kXkbPrefix).length(); |
80 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); | 80 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); |
81 return xkb_id.substr(prefix_length); | 81 return xkb_id.substr(prefix_length); |
82 } | 82 } |
83 | 83 |
84 void InputMethodAPI::Shutdown() { | 84 void InputMethodAPI::Shutdown() { |
85 // UnregisterObserver may have already been called in OnListenerAdded, | 85 // UnregisterObserver may have already been called in OnListenerAdded, |
86 // but it is safe to call it more than once. | 86 // but it is safe to call it more than once. |
87 ExtensionSystem::GetForBrowserContext(context_)->event_router()-> | 87 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); |
88 UnregisterObserver(this); | |
89 } | 88 } |
90 | 89 |
91 void InputMethodAPI::OnListenerAdded( | 90 void InputMethodAPI::OnListenerAdded( |
92 const extensions::EventListenerInfo& details) { | 91 const extensions::EventListenerInfo& details) { |
93 DCHECK(!input_method_event_router_.get()); | 92 DCHECK(!input_method_event_router_.get()); |
94 input_method_event_router_.reset( | 93 input_method_event_router_.reset( |
95 new chromeos::ExtensionInputMethodEventRouter(context_)); | 94 new chromeos::ExtensionInputMethodEventRouter(context_)); |
96 ExtensionSystem::GetForBrowserContext(context_)->event_router()-> | 95 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); |
97 UnregisterObserver(this); | |
98 } | 96 } |
99 | 97 |
100 static base::LazyInstance<ProfileKeyedAPIFactory<InputMethodAPI> > | 98 static base::LazyInstance<ProfileKeyedAPIFactory<InputMethodAPI> > |
101 g_factory = LAZY_INSTANCE_INITIALIZER; | 99 g_factory = LAZY_INSTANCE_INITIALIZER; |
102 | 100 |
103 // static | 101 // static |
104 ProfileKeyedAPIFactory<InputMethodAPI>* InputMethodAPI::GetFactoryInstance() { | 102 ProfileKeyedAPIFactory<InputMethodAPI>* InputMethodAPI::GetFactoryInstance() { |
105 return g_factory.Pointer(); | 103 return g_factory.Pointer(); |
106 } | 104 } |
107 | 105 |
108 } // namespace extensions | 106 } // namespace extensions |
OLD | NEW |