| 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" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 registry->RegisterFunction<GetInputMethodFunction>(); | 73 registry->RegisterFunction<GetInputMethodFunction>(); |
| 74 registry->RegisterFunction<StartImeFunction>(); | 74 registry->RegisterFunction<StartImeFunction>(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 InputMethodAPI::~InputMethodAPI() { | 77 InputMethodAPI::~InputMethodAPI() { |
| 78 } | 78 } |
| 79 | 79 |
| 80 // static | 80 // static |
| 81 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { | 81 std::string InputMethodAPI::GetInputMethodForXkb(const std::string& xkb_id) { |
| 82 std::string xkb_prefix = | 82 std::string xkb_prefix = |
| 83 chromeos::extension_ime_util::GetInputMethodIDByKeyboardLayout( | 83 chromeos::extension_ime_util::GetInputMethodIDByEngineID(kXkbPrefix); |
| 84 kXkbPrefix); | |
| 85 size_t prefix_length = xkb_prefix.length(); | 84 size_t prefix_length = xkb_prefix.length(); |
| 86 DCHECK(xkb_id.substr(0, prefix_length) == xkb_prefix); | 85 DCHECK(xkb_id.substr(0, prefix_length) == xkb_prefix); |
| 87 return xkb_id.substr(prefix_length); | 86 return xkb_id.substr(prefix_length); |
| 88 } | 87 } |
| 89 | 88 |
| 90 void InputMethodAPI::Shutdown() { | 89 void InputMethodAPI::Shutdown() { |
| 91 // UnregisterObserver may have already been called in OnListenerAdded, | 90 // UnregisterObserver may have already been called in OnListenerAdded, |
| 92 // but it is safe to call it more than once. | 91 // but it is safe to call it more than once. |
| 93 EventRouter::Get(context_)->UnregisterObserver(this); | 92 EventRouter::Get(context_)->UnregisterObserver(this); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void InputMethodAPI::OnListenerAdded( | 95 void InputMethodAPI::OnListenerAdded( |
| 97 const extensions::EventListenerInfo& details) { | 96 const extensions::EventListenerInfo& details) { |
| 98 DCHECK(!input_method_event_router_.get()); | 97 DCHECK(!input_method_event_router_.get()); |
| 99 input_method_event_router_.reset( | 98 input_method_event_router_.reset( |
| 100 new chromeos::ExtensionInputMethodEventRouter(context_)); | 99 new chromeos::ExtensionInputMethodEventRouter(context_)); |
| 101 EventRouter::Get(context_)->UnregisterObserver(this); | 100 EventRouter::Get(context_)->UnregisterObserver(this); |
| 102 } | 101 } |
| 103 | 102 |
| 104 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > | 103 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputMethodAPI> > |
| 105 g_factory = LAZY_INSTANCE_INITIALIZER; | 104 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 106 | 105 |
| 107 // static | 106 // static |
| 108 BrowserContextKeyedAPIFactory<InputMethodAPI>* | 107 BrowserContextKeyedAPIFactory<InputMethodAPI>* |
| 109 InputMethodAPI::GetFactoryInstance() { | 108 InputMethodAPI::GetFactoryInstance() { |
| 110 return g_factory.Pointer(); | 109 return g_factory.Pointer(); |
| 111 } | 110 } |
| 112 | 111 |
| 113 } // namespace extensions | 112 } // namespace extensions |
| OLD | NEW |