Commit 6a5a7670 authored by shuchen@chromium.org's avatar shuchen@chromium.org

Refactoring for InputMethodEngine and InputMethodEventRouter.

1) Makes InputMethodEngine extension based instead of input component based.
2) Makes InputMethodEngine independent to user profile.
3) Makes InputMethodEventRouter independent to user profile, except
   forwarding events to extension.

BUG=342336
TEST=Verified on sandbox.

Review URL: https://codereview.chromium.org/433163005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287781 0039d316-1c4b-4281-b951-d872f2087c98
parent 049136ba
...@@ -40,20 +40,11 @@ class InputMethodEngine : public InputMethodEngineInterface { ...@@ -40,20 +40,11 @@ class InputMethodEngine : public InputMethodEngineInterface {
virtual ~InputMethodEngine(); virtual ~InputMethodEngine();
void Initialize(Profile* profile, void Initialize(scoped_ptr<InputMethodEngineInterface::Observer> observer,
scoped_ptr<InputMethodEngineInterface::Observer> observer, const char* extension_id);
const char* engine_name,
const char* extension_id,
const char* engine_id,
const std::vector<std::string>& languages,
const std::vector<std::string>& layouts,
const GURL& options_page,
const GURL& input_view);
// InputMethodEngineInterface overrides. // InputMethodEngineInterface overrides.
virtual const input_method::InputMethodDescriptor& GetDescriptor() virtual const std::string& GetActiveComponentId() const OVERRIDE;
const OVERRIDE;
virtual void NotifyImeReady() OVERRIDE;
virtual bool SetComposition(int context_id, virtual bool SetComposition(int context_id,
const char* text, const char* text,
int selection_start, int selection_start,
...@@ -89,7 +80,7 @@ class InputMethodEngine : public InputMethodEngineInterface { ...@@ -89,7 +80,7 @@ class InputMethodEngine : public InputMethodEngineInterface {
virtual void FocusIn( virtual void FocusIn(
const IMEEngineHandlerInterface::InputContext& input_context) OVERRIDE; const IMEEngineHandlerInterface::InputContext& input_context) OVERRIDE;
virtual void FocusOut() OVERRIDE; virtual void FocusOut() OVERRIDE;
virtual void Enable() OVERRIDE; virtual void Enable(const std::string& component_id) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual void PropertyActivate(const std::string& property_name) OVERRIDE; virtual void PropertyActivate(const std::string& property_name) OVERRIDE;
virtual void Reset() OVERRIDE; virtual void Reset() OVERRIDE;
...@@ -107,32 +98,23 @@ class InputMethodEngine : public InputMethodEngineInterface { ...@@ -107,32 +98,23 @@ class InputMethodEngine : public InputMethodEngineInterface {
void MenuItemToProperty(const MenuItem& item, void MenuItemToProperty(const MenuItem& item,
ash::ime::InputMethodMenuItem* property); ash::ime::InputMethodMenuItem* property);
// Enables or disables overriding input view page to Virtual Keyboard window. // Enables overriding input view page to Virtual Keyboard window.
void EnableInputView(bool enabled); void EnableInputView();
// Descriptor of this input method.
input_method::InputMethodDescriptor descriptor_;
ui::TextInputType current_input_type_; ui::TextInputType current_input_type_;
// True if this engine is active.
bool active_;
// ID that is used for the current input context. False if there is no focus. // ID that is used for the current input context. False if there is no focus.
int context_id_; int context_id_;
// Next id that will be assigned to a context. // Next id that will be assigned to a context.
int next_context_id_; int next_context_id_;
// This IME ID in Chrome Extension. // The input_component ID in IME extension's manifest.
std::string engine_id_; std::string active_component_id_;
// This IME's Chrome Extension ID. // The IME extension ID.
std::string extension_id_; std::string extension_id_;
// This IME ID in InputMethodManager.
std::string imm_id_;
// The observer object recieving events for this IME. // The observer object recieving events for this IME.
scoped_ptr<InputMethodEngineInterface::Observer> observer_; scoped_ptr<InputMethodEngineInterface::Observer> observer_;
...@@ -155,9 +137,6 @@ class InputMethodEngine : public InputMethodEngineInterface { ...@@ -155,9 +137,6 @@ class InputMethodEngine : public InputMethodEngineInterface {
// Mapping of candidate id to index. // Mapping of candidate id to index.
std::map<int, int> candidate_indexes_; std::map<int, int> candidate_indexes_;
// Used for input view window.
GURL input_view_url_;
// Used with SendKeyEvents and ProcessKeyEvent to check if the key event // Used with SendKeyEvents and ProcessKeyEvent to check if the key event
// sent to ProcessKeyEvent is sent by SendKeyEvents. // sent to ProcessKeyEvent is sent by SendKeyEvents.
const ui::KeyEvent* sent_key_event_; const ui::KeyEvent* sent_key_event_;
...@@ -165,9 +144,6 @@ class InputMethodEngine : public InputMethodEngineInterface { ...@@ -165,9 +144,6 @@ class InputMethodEngine : public InputMethodEngineInterface {
// The start & end time of using this input method. This is for UMA. // The start & end time of using this input method. This is for UMA.
base::Time start_time_; base::Time start_time_;
base::Time end_time_; base::Time end_time_;
// User profile that owns this method.
Profile* profile_;
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chromeos/ime/input_method_manager.h" #include "chromeos/ime/input_method_manager.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/manifest_handlers/background_info.h" #include "extensions/common/manifest_handlers/background_info.h"
#include "ui/base/ime/chromeos/ime_bridge.h" #include "ui/base/ime/chromeos/ime_bridge.h"
#include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h" #include "ui/base/ime/chromeos/mock_ime_candidate_window_handler.h"
...@@ -160,7 +161,7 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest, ...@@ -160,7 +161,7 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
// onActivate event should be fired if Enable function is called. // onActivate event should be fired if Enable function is called.
ExtensionTestMessageListener activated_listener("onActivate", false); ExtensionTestMessageListener activated_listener("onActivate", false);
engine_handler->Enable(); engine_handler->Enable("IdentityIME");
ASSERT_TRUE(activated_listener.WaitUntilSatisfied()); ASSERT_TRUE(activated_listener.WaitUntilSatisfied());
ASSERT_TRUE(activated_listener.was_satisfied()); ASSERT_TRUE(activated_listener.was_satisfied());
...@@ -238,12 +239,13 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest, ...@@ -238,12 +239,13 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
IMEBridge::Get()->GetCurrentEngineHandler(); IMEBridge::Get()->GetCurrentEngineHandler();
ASSERT_TRUE(engine_handler); ASSERT_TRUE(engine_handler);
extensions::ExtensionHost* host = FindHostWithPath( extensions::ExtensionHost* host =
extensions::ExtensionSystem::Get(profile())->process_manager(), extensions::ExtensionSystem::Get(profile())
extensions::BackgroundInfo::GetBackgroundURL(extension_).path(), ->process_manager()
1); ->GetBackgroundHostForExtension(extension_->id());
ASSERT_TRUE(host);
engine_handler->Enable(); engine_handler->Enable("APIArgumentIME");
IMEEngineHandlerInterface::InputContext context(ui::TEXT_INPUT_TYPE_TEXT, IMEEngineHandlerInterface::InputContext context(ui::TEXT_INPUT_TYPE_TEXT,
ui::TEXT_INPUT_MODE_DEFAULT); ui::TEXT_INPUT_MODE_DEFAULT);
engine_handler->FocusIn(context); engine_handler->FocusIn(context);
......
...@@ -172,11 +172,6 @@ class InputMethodEngineInterface : public IMEEngineHandlerInterface { ...@@ -172,11 +172,6 @@ class InputMethodEngineInterface : public IMEEngineHandlerInterface {
virtual ~InputMethodEngineInterface() {} virtual ~InputMethodEngineInterface() {}
virtual const input_method::InputMethodDescriptor& GetDescriptor() const = 0;
// Called when the input metho initialization is done.
virtual void NotifyImeReady() = 0;
// Set the current composition and associated properties. // Set the current composition and associated properties.
virtual bool SetComposition(int context_id, virtual bool SetComposition(int context_id,
const char* text, const char* text,
...@@ -231,6 +226,9 @@ class InputMethodEngineInterface : public IMEEngineHandlerInterface { ...@@ -231,6 +226,9 @@ class InputMethodEngineInterface : public IMEEngineHandlerInterface {
// Returns true if this IME is active, false if not. // Returns true if this IME is active, false if not.
virtual bool IsActive() const = 0; virtual bool IsActive() const = 0;
// Returns the current active input_component id.
virtual const std::string& GetActiveComponentId() const = 0;
// Deletes |number_of_chars| unicode characters as the basis of |offset| from // Deletes |number_of_chars| unicode characters as the basis of |offset| from
// the surrounding text. The |offset| is relative position based on current // the surrounding text. The |offset| is relative position based on current
// caret. // caret.
......
...@@ -22,7 +22,7 @@ namespace { ...@@ -22,7 +22,7 @@ namespace {
const char kTestExtensionId[] = "mppnpdlheglhdfmldimlhpnegondlapf"; const char kTestExtensionId[] = "mppnpdlheglhdfmldimlhpnegondlapf";
const char kTestExtensionId2[] = "dmpipdbjkoajgdeppkffbjhngfckdloi"; const char kTestExtensionId2[] = "dmpipdbjkoajgdeppkffbjhngfckdloi";
const char kTestImeEngineId[] = "test_engine_id"; const char kTestImeComponentId[] = "test_engine_id";
const char* kHistogramNames[] = { const char* kHistogramNames[] = {
"InputMethod.Enable.test_engine_id", "InputMethod.Commit.test_engine_id", "InputMethod.Enable.test_engine_id", "InputMethod.Commit.test_engine_id",
...@@ -55,7 +55,7 @@ void InitInputMethod() { ...@@ -55,7 +55,7 @@ void InitInputMethod() {
ext1.id = kTestExtensionId; ext1.id = kTestExtensionId;
ComponentExtensionEngine ext1_engine1; ComponentExtensionEngine ext1_engine1;
ext1_engine1.engine_id = kTestImeEngineId; ext1_engine1.engine_id = kTestImeComponentId;
ext1_engine1.language_codes.push_back("en-US"); ext1_engine1.language_codes.push_back("en-US");
ext1_engine1.layouts.push_back("us"); ext1_engine1.layouts.push_back("us");
ext1.engines.push_back(ext1_engine1); ext1.engines.push_back(ext1_engine1);
...@@ -175,15 +175,8 @@ class InputMethodEngineTest : public testing::Test { ...@@ -175,15 +175,8 @@ class InputMethodEngineTest : public testing::Test {
engine_.reset(new InputMethodEngine()); engine_.reset(new InputMethodEngine());
observer_ = new TestObserver(); observer_ = new TestObserver();
scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_); scoped_ptr<InputMethodEngineInterface::Observer> observer_ptr(observer_);
engine_->Initialize(NULL /* profile */, engine_->Initialize(observer_ptr.Pass(),
observer_ptr.Pass(), whitelisted ? kTestExtensionId : kTestExtensionId2);
"",
whitelisted ? kTestExtensionId : kTestExtensionId2,
kTestImeEngineId,
languages_,
layouts_,
options_page_,
input_view_);
} }
void FocusIn(ui::TextInputType input_type) { void FocusIn(ui::TextInputType input_type) {
...@@ -218,19 +211,19 @@ TEST_F(InputMethodEngineTest, TestSwitching) { ...@@ -218,19 +211,19 @@ TEST_F(InputMethodEngineTest, TestSwitching) {
// Enable/disable with focus. // Enable/disable with focus.
FocusIn(ui::TEXT_INPUT_TYPE_URL); FocusIn(ui::TEXT_INPUT_TYPE_URL);
EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset());
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->Disable(); engine_->Disable();
EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset());
// Enable/disable without focus. // Enable/disable without focus.
engine_->FocusOut(); engine_->FocusOut();
EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset());
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->Disable(); engine_->Disable();
EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset());
// Focus change when enabled. // Focus change when enabled.
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->FocusOut(); engine_->FocusOut();
EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset());
...@@ -248,12 +241,12 @@ TEST_F(InputMethodEngineTest, TestSwitching_Password_3rd_Party) { ...@@ -248,12 +241,12 @@ TEST_F(InputMethodEngineTest, TestSwitching_Password_3rd_Party) {
// Enable/disable with focus. // Enable/disable with focus.
FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD);
EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset());
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->Disable(); engine_->Disable();
EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset());
// Focus change when enabled. // Focus change when enabled.
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->FocusOut(); engine_->FocusOut();
EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset());
...@@ -268,12 +261,12 @@ TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) { ...@@ -268,12 +261,12 @@ TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) {
// Enable/disable with focus. // Enable/disable with focus.
FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD); FocusIn(ui::TEXT_INPUT_TYPE_PASSWORD);
EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(NONE, observer_->GetCallsBitmapAndReset());
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->Disable(); engine_->Disable();
EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(DEACTIVATED, observer_->GetCallsBitmapAndReset());
// Focus change when enabled. // Focus change when enabled.
engine_->Enable(); engine_->Enable(kTestImeComponentId);
EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ACTIVATE | ONFOCUS, observer_->GetCallsBitmapAndReset());
engine_->FocusOut(); engine_->FocusOut();
EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset()); EXPECT_EQ(ONBLUR, observer_->GetCallsBitmapAndReset());
...@@ -286,7 +279,7 @@ TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) { ...@@ -286,7 +279,7 @@ TEST_F(InputMethodEngineTest, TestSwitching_Password_Whitelisted) {
TEST_F(InputMethodEngineTest, TestHistograms) { TEST_F(InputMethodEngineTest, TestHistograms) {
CreateEngine(true); CreateEngine(true);
FocusIn(ui::TEXT_INPUT_TYPE_TEXT); FocusIn(ui::TEXT_INPUT_TYPE_TEXT);
engine_->Enable(); engine_->Enable(kTestImeComponentId);
std::string error; std::string error;
ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1); ExpectNewSample("InputMethod.Enable.test_engine_id", 1, 1, 1);
engine_->CommitText(1, "input", &error); engine_->CommitText(1, "input", &error);
......
...@@ -331,26 +331,6 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -331,26 +331,6 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
if (candidate_window_controller_.get()) if (candidate_window_controller_.get())
candidate_window_controller_->Hide(); candidate_window_controller_->Hide();
// Disable the current engine handler.
IMEEngineHandlerInterface* engine =
IMEBridge::Get()->GetCurrentEngineHandler();
if (engine)
engine->Disable();
// Configure the next engine handler.
if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) &&
!extension_ime_util::IsKeyboardLayoutExtension(
input_method_id_to_switch)) {
IMEBridge::Get()->SetCurrentEngineHandler(NULL);
} else {
IMEEngineHandlerInterface* next_engine =
profile_engine_map_[GetProfile()][input_method_id_to_switch];
if (next_engine) {
IMEBridge::Get()->SetCurrentEngineHandler(next_engine);
next_engine->Enable();
}
}
// TODO(komatsu): Check if it is necessary to perform the above routine // TODO(komatsu): Check if it is necessary to perform the above routine
// when the current input method is equal to |input_method_id_to_swich|. // when the current input method is equal to |input_method_id_to_swich|.
if (current_input_method_.id() != input_method_id_to_switch) { if (current_input_method_.id() != input_method_id_to_switch) {
...@@ -381,6 +361,26 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( ...@@ -381,6 +361,26 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal(
current_input_method_ = *descriptor; current_input_method_ = *descriptor;
} }
// Disable the current engine handler.
IMEEngineHandlerInterface* engine =
IMEBridge::Get()->GetCurrentEngineHandler();
if (engine)
engine->Disable();
// Configure the next engine handler.
// This must be after |current_input_method_| has been set to new input
// method, because engine's Enable() method needs to access it.
const std::string& extension_id =
extension_ime_util::GetExtensionIDFromInputMethodID(
input_method_id_to_switch);
const std::string& component_id =
extension_ime_util::GetComponentIDByInputMethodID(
input_method_id_to_switch);
engine = engine_map_[extension_id];
IMEBridge::Get()->SetCurrentEngineHandler(engine);
if (engine)
engine->Enable(component_id);
// Change the keyboard layout to a preferred layout for the input method. // Change the keyboard layout to a preferred layout for the input method.
if (!keyboard_->SetCurrentKeyboardLayoutByName( if (!keyboard_->SetCurrentKeyboardLayoutByName(
current_input_method_.GetPreferredKeyboardLayout())) { current_input_method_.GetPreferredKeyboardLayout())) {
...@@ -433,58 +433,70 @@ void InputMethodManagerImpl::ActivateInputMethodMenuItem( ...@@ -433,58 +433,70 @@ void InputMethodManagerImpl::ActivateInputMethodMenuItem(
} }
void InputMethodManagerImpl::AddInputMethodExtension( void InputMethodManagerImpl::AddInputMethodExtension(
Profile* profile, const std::string& extension_id,
const std::string& id, const InputMethodDescriptors& descriptors,
InputMethodEngineInterface* engine) { InputMethodEngineInterface* engine) {
if (state_ == STATE_TERMINATING) if (state_ == STATE_TERMINATING)
return; return;
DCHECK(engine); DCHECK(engine);
profile_engine_map_[profile][id] = engine; engine_map_[extension_id] = engine;
if (id == current_input_method_.id()) { if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID(
current_input_method_.id())) {
IMEBridge::Get()->SetCurrentEngineHandler(engine); IMEBridge::Get()->SetCurrentEngineHandler(engine);
engine->Enable(); engine->Enable(extension_ime_util::GetComponentIDByInputMethodID(
} current_input_method_.id()));
}
if (extension_ime_util::IsComponentExtensionIME(id))
return; bool contain = false;
for (size_t i = 0; i < descriptors.size(); i++) {
CHECK(extension_ime_util::IsExtensionIME(id)) const InputMethodDescriptor& descriptor = descriptors[i];
<< id << "is not a valid extension input method ID"; const std::string& id = descriptor.id();
extra_input_methods_[id] = descriptor;
const InputMethodDescriptor& descriptor = engine->GetDescriptor(); if (Contains(enabled_extension_imes_, id)) {
extra_input_methods_[id] = descriptor; if (!Contains(active_input_method_ids_, id)) {
active_input_method_ids_.push_back(id);
if (Contains(enabled_extension_imes_, id)) { } else {
if (!Contains(active_input_method_ids_, id)) { DVLOG(1) << "AddInputMethodExtension: already added: " << id << ", "
active_input_method_ids_.push_back(id); << descriptor.name();
} else { }
DVLOG(1) << "AddInputMethodExtension: alread added: " contain = true;
<< id << ", " << descriptor.name();
} }
}
// Ensure that the input method daemon is running. // Ensure that the input method daemon is running.
if (contain)
MaybeInitializeCandidateWindowController(); MaybeInitializeCandidateWindowController();
}
} }
void InputMethodManagerImpl::RemoveInputMethodExtension(Profile* profile, void InputMethodManagerImpl::RemoveInputMethodExtension(
const std::string& id) { const std::string& extension_id) {
if (!extension_ime_util::IsExtensionIME(id)) // Remove the active input methods with |extension_id|.
DVLOG(1) << id << " is not a valid extension input method ID."; std::vector<std::string> new_active_input_method_ids;
for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
if (extension_id != extension_ime_util::GetExtensionIDFromInputMethodID(
active_input_method_ids_[i]))
new_active_input_method_ids.push_back(active_input_method_ids_[i]);
}
active_input_method_ids_.swap(new_active_input_method_ids);
std::vector<std::string>::iterator i = std::find( // Remove the extra input methods with |extension_id|.
active_input_method_ids_.begin(), active_input_method_ids_.end(), id); std::map<std::string, InputMethodDescriptor> new_extra_input_methods;
if (i != active_input_method_ids_.end()) for (std::map<std::string, InputMethodDescriptor>::iterator i =
active_input_method_ids_.erase(i); extra_input_methods_.begin();
extra_input_methods_.erase(id); i != extra_input_methods_.end();
++i) {
if (extension_id !=
extension_ime_util::GetExtensionIDFromInputMethodID(i->first))
new_extra_input_methods[i->first] = i->second;
}
extra_input_methods_.swap(new_extra_input_methods);
EngineMap& engine_map = profile_engine_map_[profile]; if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id])
if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map[id])
IMEBridge::Get()->SetCurrentEngineHandler(NULL); IMEBridge::Get()->SetCurrentEngineHandler(NULL);
engine_map.erase(id); engine_map_.erase(extension_id);
// No need to switch input method when terminating. // No need to switch input method when terminating.
if (state_ != STATE_TERMINATING) { if (state_ != STATE_TERMINATING) {
...@@ -867,9 +879,5 @@ void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { ...@@ -867,9 +879,5 @@ void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
candidate_window_controller_->AddObserver(this); candidate_window_controller_->AddObserver(this);
} }
Profile* InputMethodManagerImpl::GetProfile() const {
return ProfileManager::GetActiveUserProfile();
}
} // namespace input_method } // namespace input_method
} // namespace chromeos } // namespace chromeos
...@@ -65,11 +65,11 @@ class InputMethodManagerImpl : public InputMethodManager, ...@@ -65,11 +65,11 @@ class InputMethodManagerImpl : public InputMethodManager,
virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE; virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE; virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
virtual void AddInputMethodExtension( virtual void AddInputMethodExtension(
Profile* profile, const std::string& extension_id,
const std::string& id, const InputMethodDescriptors& descriptors,
InputMethodEngineInterface* instance) OVERRIDE; InputMethodEngineInterface* instance) OVERRIDE;
virtual void RemoveInputMethodExtension(Profile* profile, virtual void RemoveInputMethodExtension(
const std::string& id) OVERRIDE; const std::string& extension_id) OVERRIDE;
virtual void GetInputMethodExtensions( virtual void GetInputMethodExtensions(
InputMethodDescriptors* result) OVERRIDE; InputMethodDescriptors* result) OVERRIDE;
virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE; virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE;
...@@ -156,12 +156,6 @@ class InputMethodManagerImpl : public InputMethodManager, ...@@ -156,12 +156,6 @@ class InputMethodManagerImpl : public InputMethodManager,
// (after list of enabled input methods has been updated) // (after list of enabled input methods has been updated)
void ReconfigureIMFramework(); void ReconfigureIMFramework();
// Gets the current active user profile.
// Note: this method is deprecated as ActiveUserProfile might change
// during asynchronous operations that leads to strange crashes.
// Use with caution!
Profile* GetProfile() const;
scoped_ptr<InputMethodDelegate> delegate_; scoped_ptr<InputMethodDelegate> delegate_;
// The current browser status. // The current browser status.
...@@ -210,12 +204,8 @@ class InputMethodManagerImpl : public InputMethodManager, ...@@ -210,12 +204,8 @@ class InputMethodManagerImpl : public InputMethodManager,
base::WeakPtrFactory<InputMethodManagerImpl> weak_ptr_factory_; base::WeakPtrFactory<InputMethodManagerImpl> weak_ptr_factory_;
// The engine map: // The engine map from extension_id to an engine.
// { Profile : { input_method_id : Engine } }. std::map<std::string, InputMethodEngineInterface*> engine_map_;
typedef std::map<std::string, InputMethodEngineInterface*>
EngineMap;
typedef std::map<Profile*, EngineMap, ProfileCompare> ProfileEngineMap;
ProfileEngineMap profile_engine_map_;
DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl);
}; };
......
...@@ -43,6 +43,8 @@ const char kNaclMozcJpId[] = "nacl_mozc_jp"; ...@@ -43,6 +43,8 @@ const char kNaclMozcJpId[] = "nacl_mozc_jp";
const char kExt2Engine1Id[] = "ext2_engine1-t-i0-engine_id"; const char kExt2Engine1Id[] = "ext2_engine1-t-i0-engine_id";
const char kExt2Engine2Id[] = "ext2_engine2-t-i0-engine_id"; const char kExt2Engine2Id[] = "ext2_engine2-t-i0-engine_id";
const char kPinyinImeId[] = "zh-t-i0-pinyin"; const char kPinyinImeId[] = "zh-t-i0-pinyin";
const char kExtensionId1[] = "00000000000000000000000000000000";
const char kExtensionId2[] = "11111111111111111111111111111111";
// Returns true if |descriptors| contain |target|. // Returns true if |descriptors| contain |target|.
bool Contain(const InputMethodDescriptors& descriptors, bool Contain(const InputMethodDescriptors& descriptors,
...@@ -135,8 +137,7 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest { ...@@ -135,8 +137,7 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
candidate_window_controller_); candidate_window_controller_);
keyboard_ = new FakeImeKeyboard; keyboard_ = new FakeImeKeyboard;
manager_->SetImeKeyboardForTesting(keyboard_); manager_->SetImeKeyboardForTesting(keyboard_);
mock_engine_handler_.reset( mock_engine_handler_.reset(new MockInputMethodEngine());
new MockInputMethodEngine(InputMethodDescriptor()));
IMEBridge::Initialize(); IMEBridge::Initialize();
IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get()); IMEBridge::Get()->SetCurrentEngineHandler(mock_engine_handler_.get());
...@@ -161,27 +162,26 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest { ...@@ -161,27 +162,26 @@ class InputMethodManagerImplTest : public BrowserWithTestWindowTest {
} }
protected: protected:
Profile* GetProfile() { return manager_->GetProfile(); }
// Helper function to initialize component extension stuff for testing. // Helper function to initialize component extension stuff for testing.
void InitComponentExtension() { void InitComponentExtension() {
mock_delegate_ = new MockComponentExtIMEManagerDelegate(); mock_delegate_ = new MockComponentExtIMEManagerDelegate();
mock_delegate_->set_ime_list(ime_list_); mock_delegate_->set_ime_list(ime_list_);
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_); scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate(mock_delegate_);
std::vector<std::string> layouts;
layouts.push_back("us");
std::vector<std::string> languages;
languages.push_back("en-US");
// Note, for production, these SetEngineHandler are called when // Note, for production, these SetEngineHandler are called when
// IMEEngineHandlerInterface is initialized via // IMEEngineHandlerInterface is initialized via
// InitializeComponentextension. // InitializeComponentextension.
manager_->AddInputMethodExtension(GetProfile(), InputMethodDescriptors descriptors;
ImeIdFromEngineId(kNaclMozcUsId), manager_->AddInputMethodExtension(ImeIdFromEngineId(kNaclMozcUsId),
mock_engine_handler_.get()); descriptors,
manager_->AddInputMethodExtension(GetProfile(),
ImeIdFromEngineId(kNaclMozcJpId),
mock_engine_handler_.get());
manager_->AddInputMethodExtension(GetProfile(),
ImeIdFromEngineId(kExt2Engine1Id),
mock_engine_handler_.get()); mock_engine_handler_.get());
manager_->AddInputMethodExtension(GetProfile(), manager_->AddInputMethodExtension(ImeIdFromEngineId(kExt2Engine1Id),
ImeIdFromEngineId(kExt2Engine2Id), descriptors,
mock_engine_handler_.get()); mock_engine_handler_.get());
manager_->InitializeComponentExtensionForTesting(delegate.Pass()); manager_->InitializeComponentExtensionForTesting(delegate.Pass());
} }
...@@ -1125,7 +1125,7 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { ...@@ -1125,7 +1125,7 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
languages.push_back("en-US"); languages.push_back("en-US");
const std::string ext1_id = const std::string ext1_id =
extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id");
const InputMethodDescriptor descriptor1(ext1_id, const InputMethodDescriptor descriptor1(ext1_id,
"deadbeef input method", "deadbeef input method",
"DB", "DB",
...@@ -1134,8 +1134,10 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { ...@@ -1134,8 +1134,10 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
false, // is_login_keyboard false, // is_login_keyboard
GURL(), GURL(),
GURL()); GURL());
MockInputMethodEngine engine(descriptor1); MockInputMethodEngine engine;
manager_->AddInputMethodExtension(GetProfile(), ext1_id, &engine); InputMethodDescriptors descriptors;
descriptors.push_back(descriptor1);
manager_->AddInputMethodExtension(kExtensionId1, descriptors, &engine);
// Extension IMEs are not enabled by default. // Extension IMEs are not enabled by default.
EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
...@@ -1154,7 +1156,7 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { ...@@ -1154,7 +1156,7 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
} }
const std::string ext2_id = const std::string ext2_id =
extension_ime_util::GetInputMethodID("cafebabe", "engine_id"); extension_ime_util::GetInputMethodID(kExtensionId2, "engine_id");
const InputMethodDescriptor descriptor2(ext2_id, const InputMethodDescriptor descriptor2(ext2_id,
"cafebabe input method", "cafebabe input method",
"CB", "CB",
...@@ -1163,8 +1165,10 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { ...@@ -1163,8 +1165,10 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
false, // is_login_keyboard false, // is_login_keyboard
GURL(), GURL(),
GURL()); GURL());
MockInputMethodEngine engine2(descriptor2); descriptors.clear();
manager_->AddInputMethodExtension(GetProfile(), ext2_id, &engine2); descriptors.push_back(descriptor2);
MockInputMethodEngine engine2;
manager_->AddInputMethodExtension(kExtensionId2, descriptors, &engine2);
EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
extension_ime_ids.push_back(ext2_id); extension_ime_ids.push_back(ext2_id);
...@@ -1180,9 +1184,9 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { ...@@ -1180,9 +1184,9 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) {
} }
// Remove them. // Remove them.
manager_->RemoveInputMethodExtension(GetProfile(), ext1_id); manager_->RemoveInputMethodExtension(kExtensionId1);
EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods());
manager_->RemoveInputMethodExtension(GetProfile(), ext2_id); manager_->RemoveInputMethodExtension(kExtensionId2);
EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
} }
...@@ -1206,7 +1210,7 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { ...@@ -1206,7 +1210,7 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) {
languages.push_back("en-US"); languages.push_back("en-US");
const std::string ext_id = const std::string ext_id =
extension_ime_util::GetInputMethodID("deadbeef", "engine_id"); extension_ime_util::GetInputMethodID(kExtensionId1, "engine_id");
const InputMethodDescriptor descriptor(ext_id, const InputMethodDescriptor descriptor(ext_id,
"deadbeef input method", "deadbeef input method",
"DB", "DB",
...@@ -1215,8 +1219,10 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { ...@@ -1215,8 +1219,10 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) {
false, // is_login_keyboard false, // is_login_keyboard
GURL(), GURL(),
GURL()); GURL());
MockInputMethodEngine engine(descriptor); MockInputMethodEngine engine;
manager_->AddInputMethodExtension(GetProfile(), ext_id, &engine); InputMethodDescriptors descriptors;
descriptors.push_back(descriptor);
manager_->AddInputMethodExtension(kExtensionId1, descriptors, &engine);
// Extension IME is not enabled by default. // Extension IME is not enabled by default.
EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods());
......
...@@ -8,18 +8,12 @@ ...@@ -8,18 +8,12 @@
namespace chromeos { namespace chromeos {
MockInputMethodEngine::MockInputMethodEngine( MockInputMethodEngine::MockInputMethodEngine() {}
const input_method::InputMethodDescriptor& descriptor)
: descriptor_(descriptor) {}
MockInputMethodEngine::~MockInputMethodEngine() {} MockInputMethodEngine::~MockInputMethodEngine() {}
const input_method::InputMethodDescriptor& const std::string& MockInputMethodEngine::GetActiveComponentId() const {
MockInputMethodEngine::GetDescriptor() const { return active_component_id_;
return descriptor_;
}
void MockInputMethodEngine::NotifyImeReady() {
} }
bool MockInputMethodEngine::SetComposition( bool MockInputMethodEngine::SetComposition(
...@@ -107,10 +101,12 @@ void MockInputMethodEngine::FocusIn( ...@@ -107,10 +101,12 @@ void MockInputMethodEngine::FocusIn(
void MockInputMethodEngine::FocusOut() { void MockInputMethodEngine::FocusOut() {
} }
void MockInputMethodEngine::Enable() { void MockInputMethodEngine::Enable(const std::string& component_id) {
active_component_id_ = component_id;
} }
void MockInputMethodEngine::Disable() { void MockInputMethodEngine::Disable() {
active_component_id_.clear();
} }
void MockInputMethodEngine::PropertyActivate(const std::string& property_name) { void MockInputMethodEngine::PropertyActivate(const std::string& property_name) {
......
...@@ -32,14 +32,11 @@ struct KeyEventHandle; ...@@ -32,14 +32,11 @@ struct KeyEventHandle;
class MockInputMethodEngine : public InputMethodEngineInterface { class MockInputMethodEngine : public InputMethodEngineInterface {
public: public:
explicit MockInputMethodEngine( explicit MockInputMethodEngine();
const input_method::InputMethodDescriptor& descriptor);
virtual ~MockInputMethodEngine(); virtual ~MockInputMethodEngine();
// InputMethodEngineInterface overrides. // InputMethodEngineInterface overrides.
virtual const input_method::InputMethodDescriptor& GetDescriptor() virtual const std::string& GetActiveComponentId() const OVERRIDE;
const OVERRIDE;
virtual void NotifyImeReady() OVERRIDE;
virtual bool SetComposition(int context_id, virtual bool SetComposition(int context_id,
const char* text, const char* text,
int selection_start, int selection_start,
...@@ -75,7 +72,7 @@ class MockInputMethodEngine : public InputMethodEngineInterface { ...@@ -75,7 +72,7 @@ class MockInputMethodEngine : public InputMethodEngineInterface {
virtual void FocusIn( virtual void FocusIn(
const IMEEngineHandlerInterface::InputContext& input_context) OVERRIDE; const IMEEngineHandlerInterface::InputContext& input_context) OVERRIDE;
virtual void FocusOut() OVERRIDE; virtual void FocusOut() OVERRIDE;
virtual void Enable() OVERRIDE; virtual void Enable(const std::string& component_id) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual void PropertyActivate(const std::string& property_name) OVERRIDE; virtual void PropertyActivate(const std::string& property_name) OVERRIDE;
virtual void Reset() OVERRIDE; virtual void Reset() OVERRIDE;
...@@ -91,8 +88,7 @@ class MockInputMethodEngine : public InputMethodEngineInterface { ...@@ -91,8 +88,7 @@ class MockInputMethodEngine : public InputMethodEngineInterface {
} }
private: private:
// Descriptor of this input method. std::string active_component_id_;
input_method::InputMethodDescriptor descriptor_;
// The current candidate window property. // The current candidate window property.
CandidateWindowProperty candidate_window_property_; CandidateWindowProperty candidate_window_property_;
......
...@@ -100,13 +100,13 @@ void MockInputMethodManager::ActivateInputMethodMenuItem( ...@@ -100,13 +100,13 @@ void MockInputMethodManager::ActivateInputMethodMenuItem(
} }
void MockInputMethodManager::AddInputMethodExtension( void MockInputMethodManager::AddInputMethodExtension(
Profile* profile, const std::string& extension_id,
const std::string& id, const InputMethodDescriptors& descriptors,
InputMethodEngineInterface* instance) { InputMethodEngineInterface* instance) {
} }
void MockInputMethodManager::RemoveInputMethodExtension(Profile* profile, void MockInputMethodManager::RemoveInputMethodExtension(
const std::string& id) { const std::string& extension_id) {
} }
void MockInputMethodManager::GetInputMethodExtensions( void MockInputMethodManager::GetInputMethodExtensions(
......
...@@ -48,11 +48,11 @@ class MockInputMethodManager : public InputMethodManager { ...@@ -48,11 +48,11 @@ class MockInputMethodManager : public InputMethodManager {
virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE; virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE;
virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE; virtual void ActivateInputMethodMenuItem(const std::string& key) OVERRIDE;
virtual void AddInputMethodExtension( virtual void AddInputMethodExtension(
Profile* profile, const std::string& extension_id,
const std::string& id, const InputMethodDescriptors& descriptors,
InputMethodEngineInterface* instance) OVERRIDE; InputMethodEngineInterface* instance) OVERRIDE;
virtual void RemoveInputMethodExtension(Profile* profile, virtual void RemoveInputMethodExtension(
const std::string& id) OVERRIDE; const std::string& extension_id) OVERRIDE;
virtual void GetInputMethodExtensions( virtual void GetInputMethodExtensions(
InputMethodDescriptors* result) OVERRIDE; InputMethodDescriptors* result) OVERRIDE;
virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE; virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE;
......
...@@ -36,13 +36,14 @@ class InputImeEventRouter { ...@@ -36,13 +36,14 @@ class InputImeEventRouter {
public: public:
static InputImeEventRouter* GetInstance(); static InputImeEventRouter* GetInstance();
bool RegisterIme(Profile*, bool RegisterImeExtension(
const std::string& extension_id, const std::string& extension_id,
const extensions::InputComponentInfo& component); const std::vector<extensions::InputComponentInfo>& input_components);
void UnregisterAllImes(const std::string& extension_id); void UnregisterAllImes(const std::string& extension_id);
chromeos::InputMethodEngineInterface* GetEngine( chromeos::InputMethodEngineInterface* GetEngine(
const std::string& extension_id, const std::string& extension_id,
const std::string& engine_id); const std::string& component_id);
chromeos::InputMethodEngineInterface* GetActiveEngine( chromeos::InputMethodEngineInterface* GetActiveEngine(
const std::string& extension_id); const std::string& extension_id);
...@@ -52,7 +53,7 @@ class InputImeEventRouter { ...@@ -52,7 +53,7 @@ class InputImeEventRouter {
const std::string& request_id, const std::string& request_id,
bool handled); bool handled);
std::string AddRequest(const std::string& engine_id, std::string AddRequest(const std::string& component_id,
chromeos::input_method::KeyEventHandle* key_data); chromeos::input_method::KeyEventHandle* key_data);
private: private:
...@@ -63,15 +64,8 @@ class InputImeEventRouter { ...@@ -63,15 +64,8 @@ class InputImeEventRouter {
InputImeEventRouter(); InputImeEventRouter();
~InputImeEventRouter(); ~InputImeEventRouter();
// The engine map for event routing. // The engine map from extension_id to an engine.
// { Profile : { extension_id : { engine_id : Engine } } }. std::map<std::string, chromeos::InputMethodEngineInterface*> engine_map_;
// TODO(shuchen): reuse the engine map in InputMethodManagerImpl.
typedef std::map<std::string, chromeos::InputMethodEngineInterface*>
EngineMap;
typedef std::map<std::string, EngineMap> ExtensionMap;
typedef std::map<Profile*, ExtensionMap, ProfileCompare>
ProfileEngineMap;
ProfileEngineMap profile_engine_map_;
unsigned int next_request_id_; unsigned int next_request_id_;
RequestMap request_map_; RequestMap request_map_;
......
...@@ -54,6 +54,16 @@ std::string GetExtensionIDFromInputMethodID( ...@@ -54,6 +54,16 @@ std::string GetExtensionIDFromInputMethodID(
return ""; return "";
} }
std::string GetComponentIDByInputMethodID(const std::string& input_method_id) {
if (IsComponentExtensionIME(input_method_id))
return input_method_id.substr(kComponentExtensionIMEPrefixLength +
kExtensionIdLength);
if (IsExtensionIME(input_method_id))
return input_method_id.substr(kExtensionIMEPrefixLength +
kExtensionIdLength);
return input_method_id;
}
std::string GetInputMethodIDByEngineID(const std::string& engine_id) { std::string GetInputMethodIDByEngineID(const std::string& engine_id) {
if (StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) || if (StartsWithASCII(engine_id, kComponentExtensionIMEPrefix, true) ||
StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) { StartsWithASCII(engine_id, kExtensionIMEPrefix, true)) {
...@@ -111,11 +121,8 @@ bool IsKeyboardLayoutExtension(const std::string& input_method_id) { ...@@ -111,11 +121,8 @@ bool IsKeyboardLayoutExtension(const std::string& input_method_id) {
} }
std::string MaybeGetLegacyXkbId(const std::string& input_method_id) { std::string MaybeGetLegacyXkbId(const std::string& input_method_id) {
if (IsKeyboardLayoutExtension(input_method_id)) { if (IsKeyboardLayoutExtension(input_method_id))
size_t pos = input_method_id.find("xkb:"); return GetComponentIDByInputMethodID(input_method_id);
if (pos != std::string::npos)
return input_method_id.substr(pos);
}
return input_method_id; return input_method_id;
} }
......
...@@ -81,6 +81,12 @@ bool CHROMEOS_EXPORT IsMemberOfExtension(const std::string& input_method_id, ...@@ -81,6 +81,12 @@ bool CHROMEOS_EXPORT IsMemberOfExtension(const std::string& input_method_id,
bool CHROMEOS_EXPORT IsKeyboardLayoutExtension( bool CHROMEOS_EXPORT IsKeyboardLayoutExtension(
const std::string& input_method_id); const std::string& input_method_id);
// Returns input method component id from the extension-based InputMethodID
// for component IME extensions. This function does not check that
// |input_method_id| is installed.
std::string CHROMEOS_EXPORT
GetComponentIDByInputMethodID(const std::string& input_method_id);
// Gets legacy xkb id (e.g. xkb:us::eng) from the new extension based xkb id // Gets legacy xkb id (e.g. xkb:us::eng) from the new extension based xkb id
// (e.g. _comp_ime_...xkb:us::eng). If the given id is not prefixed with // (e.g. _comp_ime_...xkb:us::eng). If the given id is not prefixed with
// 'xkb:', just return the same as the given id. // 'xkb:', just return the same as the given id.
......
...@@ -144,13 +144,12 @@ class CHROMEOS_EXPORT InputMethodManager { ...@@ -144,13 +144,12 @@ class CHROMEOS_EXPORT InputMethodManager {
// Adds an input method extension. This function does not takes ownership of // Adds an input method extension. This function does not takes ownership of
// |instance|. // |instance|.
virtual void AddInputMethodExtension( virtual void AddInputMethodExtension(
Profile* profile, const std::string& extension_id,
const std::string& imm_id, const InputMethodDescriptors& descriptors,
InputMethodEngineInterface* instance) = 0; InputMethodEngineInterface* instance) = 0;
// Removes an input method extension. // Removes an input method extension.
virtual void RemoveInputMethodExtension(Profile* profile, virtual void RemoveInputMethodExtension(const std::string& extension_id) = 0;
const std::string& id) = 0;
// Returns a list of descriptors for all Input Method Extensions. // Returns a list of descriptors for all Input Method Extensions.
virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0; virtual void GetInputMethodExtensions(InputMethodDescriptors* result) = 0;
......
...@@ -72,7 +72,7 @@ class UI_BASE_EXPORT IMEEngineHandlerInterface { ...@@ -72,7 +72,7 @@ class UI_BASE_EXPORT IMEEngineHandlerInterface {
virtual void FocusOut() = 0; virtual void FocusOut() = 0;
// Called when the IME is enabled. // Called when the IME is enabled.
virtual void Enable() = 0; virtual void Enable(const std::string& component_id) = 0;
// Called when the IME is disabled. // Called when the IME is disabled.
virtual void Disable() = 0; virtual void Disable() = 0;
......
...@@ -33,7 +33,7 @@ void MockIMEEngineHandler::FocusOut() { ...@@ -33,7 +33,7 @@ void MockIMEEngineHandler::FocusOut() {
last_text_input_context_.type = ui::TEXT_INPUT_TYPE_NONE; last_text_input_context_.type = ui::TEXT_INPUT_TYPE_NONE;
} }
void MockIMEEngineHandler::Enable() { void MockIMEEngineHandler::Enable(const std::string& component_id) {
} }
void MockIMEEngineHandler::Disable() { void MockIMEEngineHandler::Disable() {
......
...@@ -18,7 +18,7 @@ class UI_BASE_EXPORT MockIMEEngineHandler : public IMEEngineHandlerInterface { ...@@ -18,7 +18,7 @@ class UI_BASE_EXPORT MockIMEEngineHandler : public IMEEngineHandlerInterface {
virtual void FocusIn(const InputContext& input_context) OVERRIDE; virtual void FocusIn(const InputContext& input_context) OVERRIDE;
virtual void FocusOut() OVERRIDE; virtual void FocusOut() OVERRIDE;
virtual void Enable() OVERRIDE; virtual void Enable(const std::string& component_id) OVERRIDE;
virtual void Disable() OVERRIDE; virtual void Disable() OVERRIDE;
virtual void PropertyActivate(const std::string& property_name) OVERRIDE; virtual void PropertyActivate(const std::string& property_name) OVERRIDE;
virtual void Reset() OVERRIDE; virtual void Reset() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment