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 "chromeos/ime/extension_ime_util.h" |
12 #include "chromeos/ime/input_method_manager.h" | 13 #include "chromeos/ime/input_method_manager.h" |
13 #include "extensions/browser/extension_function_registry.h" | 14 #include "extensions/browser/extension_function_registry.h" |
14 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Prefix, which is used by XKB. | 19 // Prefix, which is used by XKB. |
19 const char kXkbPrefix[] = "xkb:"; | 20 const char kXkbPrefix[] = "xkb:"; |
20 | 21 |
21 } // namespace | 22 } // namespace |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 ExtensionFunctionRegistry::GetInstance(); | 70 ExtensionFunctionRegistry::GetInstance(); |
70 registry->RegisterFunction<GetInputMethodFunction>(); | 71 registry->RegisterFunction<GetInputMethodFunction>(); |
71 registry->RegisterFunction<StartImeFunction>(); | 72 registry->RegisterFunction<StartImeFunction>(); |
72 } | 73 } |
73 | 74 |
74 InputMethodAPI::~InputMethodAPI() { | 75 InputMethodAPI::~InputMethodAPI() { |
75 } | 76 } |
76 | 77 |
77 // static | 78 // static |
78 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { | 79 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { |
79 size_t prefix_length = std::string(kXkbPrefix).length(); | 80 std::string xkb_prefix = |
80 DCHECK(xkb_id.substr(0, prefix_length) == kXkbPrefix); | 81 chromeos::extension_ime_util::GetInputMethodIDByKeyboardLayout( |
| 82 kXkbPrefix); |
| 83 size_t prefix_length = xkb_prefix.length(); |
| 84 DCHECK(xkb_id.substr(0, prefix_length) == xkb_prefix); |
81 return xkb_id.substr(prefix_length); | 85 return xkb_id.substr(prefix_length); |
82 } | 86 } |
83 | 87 |
84 void InputMethodAPI::Shutdown() { | 88 void InputMethodAPI::Shutdown() { |
85 // UnregisterObserver may have already been called in OnListenerAdded, | 89 // UnregisterObserver may have already been called in OnListenerAdded, |
86 // but it is safe to call it more than once. | 90 // but it is safe to call it more than once. |
87 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); | 91 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); |
88 } | 92 } |
89 | 93 |
90 void InputMethodAPI::OnListenerAdded( | 94 void InputMethodAPI::OnListenerAdded( |
91 const extensions::EventListenerInfo& details) { | 95 const extensions::EventListenerInfo& details) { |
92 DCHECK(!input_method_event_router_.get()); | 96 DCHECK(!input_method_event_router_.get()); |
93 input_method_event_router_.reset( | 97 input_method_event_router_.reset( |
94 new chromeos::ExtensionInputMethodEventRouter(context_)); | 98 new chromeos::ExtensionInputMethodEventRouter(context_)); |
95 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); | 99 ExtensionSystem::Get(context_)->event_router()->UnregisterObserver(this); |
96 } | 100 } |
97 | 101 |
98 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 102 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
99 g_factory = LAZY_INSTANCE_INITIALIZER; | 103 g_factory = LAZY_INSTANCE_INITIALIZER; |
100 | 104 |
101 // static | 105 // static |
102 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 106 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
103 InputMethodAPI::GetFactoryInstance() { | 107 InputMethodAPI::GetFactoryInstance() { |
104 return g_factory.Pointer(); | 108 return g_factory.Pointer(); |
105 } | 109 } |
106 | 110 |
107 } // namespace extensions | 111 } // namespace extensions |
OLD | NEW |