Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Unified Diff: chrome/browser/extensions/api/input_ime/input_ime_api_chromeos.cc

Issue 1554983002: Build chrome.input.ime.* API in GN mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove class InputImeEventRouter from input_ime_api.h to input_ime_api_chromeos/nonchromeos.h Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..517d3379edc0072faf166facb65af8652f0c9f5a 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
@@ -286,74 +286,6 @@ class ImeObserverChromeOS : public ui::ImeObserver {
namespace extensions {
-bool InputImeEventRouter::RegisterImeExtension(
- const std::string& extension_id,
- const std::vector<extensions::InputComponentInfo>& input_components) {
- VLOG(1) << "RegisterImeExtension: " << extension_id;
-
- if (engine_map_[extension_id])
- return false;
-
- chromeos::input_method::InputMethodManager* manager =
- chromeos::input_method::InputMethodManager::Get();
- chromeos::ComponentExtensionIMEManager* comp_ext_ime_manager =
- manager->GetComponentExtensionIMEManager();
-
- chromeos::input_method::InputMethodDescriptors descriptors;
- // 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 =
- input_components.begin();
- it != input_components.end();
- ++it) {
- const extensions::InputComponentInfo& component = *it;
- DCHECK(component.type == extensions::INPUT_COMPONENT_TYPE_IME);
-
- std::vector<std::string> layouts;
- layouts.assign(component.layouts.begin(), component.layouts.end());
- std::vector<std::string> languages;
- languages.assign(component.languages.begin(), component.languages.end());
-
- const std::string& input_method_id =
- chromeos::extension_ime_util::GetInputMethodID(extension_id,
- component.id);
- descriptors.push_back(chromeos::input_method::InputMethodDescriptor(
- input_method_id,
- component.name,
- std::string(), // TODO(uekawa): Set short name.
- layouts,
- languages,
- false, // 3rd party IMEs are always not for login.
- component.options_page_url,
- component.input_view_url));
- }
- }
-
- scoped_ptr<ui::IMEEngineObserver> observer(
- new ImeObserverChromeOS(extension_id, profile_));
- chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine();
- engine->Initialize(std::move(observer), extension_id.c_str(), profile_);
- engine_map_[extension_id] = engine;
- chromeos::UserSessionManager::GetInstance()
- ->GetDefaultIMEState(profile_)
- ->AddInputMethodExtension(extension_id, descriptors, engine);
-
- return true;
-}
-
-void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) {
- std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
- engine_map_.find(extension_id);
- if (it != engine_map_.end()) {
- chromeos::input_method::InputMethodManager::Get()
- ->GetActiveIMEState()
- ->RemoveInputMethodExtension(extension_id);
- delete it->second;
- engine_map_.erase(it);
- }
-}
-
bool InputImeSetCompositionFunction::RunSync() {
IMEEngineHandlerInterface* engine =
GetInputImeEventRouter(Profile::FromBrowserContext(browser_context()))
@@ -692,4 +624,125 @@ bool InputImeDeleteSurroundingTextFunction::RunSync() {
return true;
}
+bool InputImeEventRouter::RegisterImeExtension(
+ const std::string& extension_id,
+ const std::vector<extensions::InputComponentInfo>& input_components) {
+ VLOG(1) << "RegisterImeExtension: " << extension_id;
+
+ if (engine_map_[extension_id])
+ return false;
+
+ chromeos::input_method::InputMethodManager* manager =
+ chromeos::input_method::InputMethodManager::Get();
+ chromeos::ComponentExtensionIMEManager* comp_ext_ime_manager =
+ manager->GetComponentExtensionIMEManager();
+
+ chromeos::input_method::InputMethodDescriptors descriptors;
+ // 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 =
+ input_components.begin();
+ it != input_components.end();
+ ++it) {
+ const extensions::InputComponentInfo& component = *it;
+ DCHECK(component.type == extensions::INPUT_COMPONENT_TYPE_IME);
+
+ std::vector<std::string> layouts;
+ layouts.assign(component.layouts.begin(), component.layouts.end());
+ std::vector<std::string> languages;
+ languages.assign(component.languages.begin(), component.languages.end());
+
+ const std::string& input_method_id =
+ chromeos::extension_ime_util::GetInputMethodID(extension_id,
+ component.id);
+ descriptors.push_back(chromeos::input_method::InputMethodDescriptor(
+ input_method_id,
+ component.name,
+ std::string(), // TODO(uekawa): Set short name.
+ layouts,
+ languages,
+ false, // 3rd party IMEs are always not for login.
+ component.options_page_url,
+ component.input_view_url));
+ }
+ }
+
+ scoped_ptr<ui::IMEEngineObserver> observer(
+ new ImeObserverChromeOS(extension_id, profile_));
+ chromeos::InputMethodEngine* engine = new chromeos::InputMethodEngine();
+ engine->Initialize(std::move(observer), extension_id.c_str(), profile_);
+ engine_map_[extension_id] = engine;
+ chromeos::UserSessionManager::GetInstance()
+ ->GetDefaultIMEState(profile_)
+ ->AddInputMethodExtension(extension_id, descriptors, engine);
+
+ return true;
+}
+
+void InputImeEventRouter::UnregisterAllImes(const std::string& extension_id) {
+ std::map<std::string, IMEEngineHandlerInterface*>::iterator it =
+ engine_map_.find(extension_id);
+ if (it != engine_map_.end()) {
+ chromeos::input_method::InputMethodManager::Get()
+ ->GetActiveIMEState()
+ ->RemoveInputMethodExtension(extension_id);
+ delete it->second;
+ engine_map_.erase(it);
+ }
+}
+
+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())
+ return it->second;
+ return NULL;
+}
+
+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())
+ return it->second;
+ return NULL;
+}
+
+void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context,
+ const Extension* extension) {
+ const std::vector<InputComponentInfo>* input_components =
+ extensions::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 =
+ extensions::InputComponents::GetInputComponents(extension);
+ if (!input_components)
+ return;
+ if (input_components->size() > 0) {
+ 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

Powered by Google App Engine
This is Rietveld 408576698