| 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..8b5e5cdfb3b9fcb08ddb1af753867bb4efee9b9e 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,22 @@ 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);
|
| + return (it != engine_map_.end()) ? it->second : nullptr;
|
| +}
|
| +
|
| +IMEEngineHandlerInterface* InputImeEventRouter::GetActiveEngine(
|
| + const std::string& extension_id) {
|
| + std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
|
| + engine_map_.find(extension_id);
|
| + return (it != engine_map_.end() && it->second->IsActive()) ? it->second
|
| + : nullptr;
|
| +}
|
| +
|
| bool InputImeSetCompositionFunction::RunSync() {
|
| IMEEngineHandlerInterface* engine =
|
| GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
|
| @@ -692,4 +712,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
|
|
|