Chromium Code Reviews| Index: chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc |
| diff --git a/chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc b/chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc |
| index db2ad970f82df0cc7c23f70e2ea121c094bc6eb5..75f11737675f481b496d080aed01052b6d5fa3a0 100644 |
| --- a/chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc |
| +++ b/chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc |
| @@ -16,7 +16,6 @@ |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/common/extensions/api/input_ime.h" |
| -#include "chrome/common/extensions/api/input_ime/input_components_handler.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/common/manifest_handlers/background_info.h" |
| #include "ui/base/ime/chromeos/component_extension_ime_manager.h" |
| @@ -286,9 +285,14 @@ class ImeObserverChromeOS : public ui::ImeObserver { |
| namespace extensions { |
| +InputImeEventRouter::InputImeEventRouter(Profile* profile) |
| + : InputImeEventRouterBase(profile) {} |
| + |
| +InputImeEventRouter::~InputImeEventRouter() {} |
| + |
| bool InputImeEventRouter::RegisterImeExtension( |
| const std::string& extension_id, |
| - const std::vector<extensions::InputComponentInfo>& input_components) { |
| + const std::vector<InputComponentInfo>& input_components) { |
| VLOG(1) << "RegisterImeExtension: " << extension_id; |
| if (engine_map_[extension_id]) |
| @@ -303,12 +307,12 @@ bool InputImeEventRouter::RegisterImeExtension( |
| // Only creates descriptors for 3rd party IME extension, because the |
| // descriptors for component IME extensions are managed by InputMethodUtil. |
| if (!comp_ext_ime_manager->IsWhitelistedExtension(extension_id)) { |
| - for (std::vector<extensions::InputComponentInfo>::const_iterator it = |
| + for (std::vector<InputComponentInfo>::const_iterator it = |
| input_components.begin(); |
| it != input_components.end(); |
| ++it) { |
| - const extensions::InputComponentInfo& component = *it; |
| - DCHECK(component.type == extensions::INPUT_COMPONENT_TYPE_IME); |
| + const InputComponentInfo& component = *it; |
| + DCHECK(component.type == INPUT_COMPONENT_TYPE_IME); |
| std::vector<std::string> layouts; |
| layouts.assign(component.layouts.begin(), component.layouts.end()); |
| @@ -331,12 +335,12 @@ bool InputImeEventRouter::RegisterImeExtension( |
| } |
| scoped_ptr<ui::IMEEngineObserver> observer( |
| - new ImeObserverChromeOS(extension_id, profile_)); |
| + new ImeObserverChromeOS(extension_id, profile())); |
| chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine(); |
| - engine->Initialize(std::move(observer), extension_id.c_str(), profile_); |
| + engine->Initialize(std::move(observer), extension_id.c_str(), profile()); |
| engine_map_[extension_id] = engine; |
| chromeos::UserSessionManager::GetInstance() |
| - ->GetDefaultIMEState(profile_) |
| + ->GetDefaultIMEState(profile()) |
| ->AddInputMethodExtension(extension_id, descriptors, engine); |
| return true; |
| @@ -354,6 +358,25 @@ void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) { |
| } |
| } |
| +IMEEngineHandlerInterface* InputImeEventRouter::GetEngine( |
| + const std::string& extension_id, |
| + const std::string& component_id) { |
| + std::map<std::string, IMEEngineHandlerInterface*>::iterator it = |
| + engine_map_.find(extension_id); |
| + if (it != engine_map_.end()) |
|
Devlin
2016/01/11 22:18:57
ternary
Azure Wei
2016/01/12 01:55:53
Done.
|
| + return it->second; |
| + return NULL; |
|
Devlin
2016/01/11 22:18:57
prefer nullptr
Azure Wei
2016/01/12 01:55:53
Done.
|
| +} |
| + |
| +IMEEngineHandlerInterface* InputImeEventRouter::GetActiveEngine( |
| + const std::string& extension_id) { |
| + std::map<std::string, IMEEngineHandlerInterface*>::iterator it = |
| + engine_map_.find(extension_id); |
| + if (it != engine_map_.end() && it->second->IsActive()) |
|
Devlin
2016/01/11 22:18:57
same as above
Azure Wei
2016/01/12 01:55:53
Done.
|
| + return it->second; |
| + return NULL; |
| +} |
| + |
| bool InputImeSetCompositionFunction::RunSync() { |
| IMEEngineHandlerInterface* engine = |
| GetInputImeEventRouter(Profile::FromBrowserContext(browser_context())) |
| @@ -692,4 +715,36 @@ bool InputImeDeleteSurroundingTextFunction::RunSync() { |
| return true; |
| } |
| +void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, |
| + const Extension* extension) { |
| + const std::vector<InputComponentInfo>* input_components = |
| + InputComponents::GetInputComponents(extension); |
| + if (input_components) |
| + GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)) |
| + ->RegisterImeExtension(extension->id(), *input_components); |
| +} |
| + |
| +void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, |
| + const Extension* extension, |
| + UnloadedExtensionInfo::Reason reason) { |
| + const std::vector<InputComponentInfo>* input_components = |
| + InputComponents::GetInputComponents(extension); |
| + if (input_components && !input_components->empty()) { |
| + GetInputImeEventRouter(Profile::FromBrowserContext(browser_context)) |
| + ->UnregisterAllImes(extension->id()); |
| + } |
| +} |
| + |
| +void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { |
| + if (!details.browser_context) |
| + return; |
| + IMEEngineHandlerInterface* engine = |
| + GetInputImeEventRouter( |
| + Profile::FromBrowserContext(details.browser_context)) |
| + ->GetActiveEngine(details.extension_id); |
| + // Notifies the IME extension for IME ready with onActivate/onFocus events. |
| + if (engine) |
| + engine->Enable(engine->GetActiveComponentId()); |
| +} |
| + |
| } // namespace extensions |