diff options
Diffstat (limited to 'chrome/browser/chromeos')
10 files changed, 328 insertions, 93 deletions
diff --git a/chrome/browser/chromeos/extensions/input_method_apitest_chromeos.cc b/chrome/browser/chromeos/extensions/input_method_apitest_chromeos.cc index aa8506c..a0b3f48 100644 --- a/chrome/browser/chromeos/extensions/input_method_apitest_chromeos.cc +++ b/chrome/browser/chromeos/extensions/input_method_apitest_chromeos.cc @@ -13,6 +13,7 @@ #include "chrome/browser/chromeos/extensions/input_method_event_router.h" #include "chrome/browser/extensions/api/test/test_api.h" #include "chrome/common/chrome_switches.h" +#include "chromeos/ime/extension_ime_util.h" #include "chromeos/ime/input_method_manager.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -81,6 +82,9 @@ class ExtensionInputMethodApiTest : public ExtensionApiTest { } // namespace IN_PROC_BROWSER_TEST_F(ExtensionInputMethodApiTest, Basic) { + chromeos::extension_ime_util::ScopedUseExtensionKeyboardFlagForTesting + scoped_flag(false); + // Two test, two calls. See JS code for more info. SetInputMethodListener listener(2); diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc index 8fda319..8d3fcc6 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc @@ -50,6 +50,11 @@ bool InputMethodManagerImpl::IsLoginKeyboard( return util_.IsLoginKeyboard(layout); } +bool InputMethodManagerImpl::MigrateXkbInputMethods( + std::vector<std::string>* input_method_ids) { + return util_.MigrateXkbInputMethods(input_method_ids); +} + InputMethodManagerImpl::InputMethodManagerImpl( scoped_ptr<InputMethodDelegate> delegate) : delegate_(delegate.Pass()), @@ -208,6 +213,7 @@ void InputMethodManagerImpl::EnableLoginLayouts( layouts.push_back(candidate); } + MigrateXkbInputMethods(&layouts); active_input_method_ids_.swap(layouts); // Initialize candidate window controller and widgets such as @@ -217,7 +223,9 @@ void InputMethodManagerImpl::EnableLoginLayouts( MaybeInitializeCandidateWindowController(); // you can pass empty |initial_layout|. - ChangeInputMethod(initial_layouts.empty() ? "" : initial_layouts[0]); + ChangeInputMethod(initial_layouts.empty() ? "" : + extension_ime_util::GetInputMethodIDByKeyboardLayout( + initial_layouts[0])); } // Adds new input method to given list. @@ -285,6 +293,7 @@ bool InputMethodManagerImpl::ReplaceEnabledInputMethods( new_active_input_method_ids_filtered.push_back(input_method_id); } active_input_method_ids_.swap(new_active_input_method_ids_filtered); + MigrateXkbInputMethods(&active_input_method_ids_); ReconfigureIMFramework(); @@ -320,7 +329,9 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( } if (!component_extension_ime_manager_->IsInitialized() && - !InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { + (!InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) || + extension_ime_util::IsKeyboardLayoutExtension( + input_method_id_to_switch))) { // We can't change input method before the initialization of // component extension ime manager. ChangeInputMethod will be // called with |pending_input_method_| when the initialization is @@ -660,6 +671,8 @@ bool InputMethodManagerImpl::SwitchInputMethod( return false; } + MigrateXkbInputMethods(&input_method_ids_to_switch); + // Obtain the intersection of input_method_ids_to_switch and // active_input_method_ids_. The order of IDs in active_input_method_ids_ is // preserved. diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h index 1969083..7d6447e 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h @@ -88,6 +88,9 @@ class InputMethodManagerImpl : public InputMethodManager, GetComponentExtensionIMEManager() OVERRIDE; virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE; + virtual bool MigrateXkbInputMethods( + std::vector<std::string>* input_method_ids) OVERRIDE; + // Sets |candidate_window_controller_|. void SetCandidateWindowControllerForTesting( CandidateWindowController* candidate_window_controller); diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc index 4eed0cb..7fb81c4 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl_unittest.cc @@ -51,6 +51,10 @@ bool Contain(const InputMethodDescriptors& descriptors, return false; } +std::string XkbId(const std::string& id) { + return extension_ime_util::GetInputMethodIDByKeyboardLayout(id); +} + class InputMethodManagerImplTest : public testing::Test { public: InputMethodManagerImplTest() @@ -78,6 +82,83 @@ class InputMethodManagerImplTest : public testing::Test { ime_list_.clear(); + ComponentExtensionIME ext_xkb; + ext_xkb.id = "fgoepimhcoialccpbmpnnblemnepkkao"; + ext_xkb.description = "ext_xkb_description"; + ext_xkb.path = base::FilePath("ext_xkb_file_path"); + + ComponentExtensionEngine ext_xkb_engine_us; + ext_xkb_engine_us.engine_id = "xkb:us::eng"; + ext_xkb_engine_us.display_name = "xkb:us::eng"; + ext_xkb_engine_us.language_codes.push_back("en-US"); + ext_xkb_engine_us.layouts.push_back("us"); + ext_xkb.engines.push_back(ext_xkb_engine_us); + + ComponentExtensionEngine ext_xkb_engine_dvorak; + ext_xkb_engine_dvorak.engine_id = "xkb:us:dvorak:eng"; + ext_xkb_engine_dvorak.display_name = "xkb:us:dvorak:eng"; + ext_xkb_engine_dvorak.language_codes.push_back("en-US"); + ext_xkb_engine_dvorak.layouts.push_back("us(dvorak)"); + ext_xkb.engines.push_back(ext_xkb_engine_dvorak); + + ComponentExtensionEngine ext_xkb_engine_intl; + ext_xkb_engine_intl.engine_id = "xkb:us:intl:eng"; + ext_xkb_engine_intl.display_name = "xkb:us:intl:eng"; + ext_xkb_engine_intl.language_codes.push_back("en-US"); + ext_xkb_engine_intl.layouts.push_back("us(intl)"); + ext_xkb.engines.push_back(ext_xkb_engine_intl); + + ComponentExtensionEngine ext_xkb_engine_altgr_intl; + ext_xkb_engine_altgr_intl.engine_id = "xkb:us:altgr-intl:eng"; + ext_xkb_engine_altgr_intl.display_name = "xkb:us:altgr-intl:eng"; + ext_xkb_engine_altgr_intl.language_codes.push_back("en-US"); + ext_xkb_engine_altgr_intl.layouts.push_back("us(altgr-intl)"); + ext_xkb.engines.push_back(ext_xkb_engine_altgr_intl); + + ComponentExtensionEngine ext_xkb_engine_fr; + ext_xkb_engine_fr.engine_id = "xkb:fr::fra"; + ext_xkb_engine_fr.display_name = "xkb:fr::fra"; + ext_xkb_engine_fr.language_codes.push_back("fr"); + ext_xkb_engine_fr.layouts.push_back("fr"); + ext_xkb.engines.push_back(ext_xkb_engine_fr); + + ComponentExtensionEngine ext_xkb_engine_colemak; + ext_xkb_engine_colemak.engine_id = "xkb:us:colemak:eng"; + ext_xkb_engine_colemak.display_name = "xkb:us:colemak:eng"; + ext_xkb_engine_colemak.language_codes.push_back("en-US"); + ext_xkb_engine_colemak.layouts.push_back("us(colemak)"); + ext_xkb.engines.push_back(ext_xkb_engine_colemak); + + ComponentExtensionEngine ext_xkb_engine_se; + ext_xkb_engine_se.engine_id = "xkb:se::swe"; + ext_xkb_engine_se.display_name = "xkb:se::swe"; + ext_xkb_engine_se.language_codes.push_back("sv"); + ext_xkb_engine_se.layouts.push_back("se"); + ext_xkb.engines.push_back(ext_xkb_engine_se); + + ComponentExtensionEngine ext_xkb_engine_jp; + ext_xkb_engine_jp.engine_id = "xkb:jp::jpn"; + ext_xkb_engine_jp.display_name = "xkb:jp::jpn"; + ext_xkb_engine_jp.language_codes.push_back("ja"); + ext_xkb_engine_jp.layouts.push_back("jp"); + ext_xkb.engines.push_back(ext_xkb_engine_jp); + + ComponentExtensionEngine ext_xkb_engine_ru; + ext_xkb_engine_ru.engine_id = "xkb:ru::rus"; + ext_xkb_engine_ru.display_name = "xkb:ru::rus"; + ext_xkb_engine_ru.language_codes.push_back("ru"); + ext_xkb_engine_ru.layouts.push_back("ru"); + ext_xkb.engines.push_back(ext_xkb_engine_ru); + + ComponentExtensionEngine ext_xkb_engine_hu; + ext_xkb_engine_hu.engine_id = "xkb:hu::hun"; + ext_xkb_engine_hu.display_name = "xkb:hu::hun"; + ext_xkb_engine_hu.language_codes.push_back("hu"); + ext_xkb_engine_hu.layouts.push_back("hu"); + ext_xkb.engines.push_back(ext_xkb_engine_hu); + + ime_list_.push_back(ext_xkb); + ComponentExtensionIME ext1; ext1.id = "fpfbhcjppmaeaijcidgiibchfbnhbelj"; ext1.description = "ext1_description"; @@ -250,13 +331,14 @@ TEST_F(InputMethodManagerImplTest, TestObserver) { menu_manager_->AddObserver(&observer); EXPECT_EQ(0, observer.input_method_changed_count_); manager_->EnableLoginLayouts("en-US", keyboard_layouts); + EXPECT_EQ(5U, manager_->GetActiveInputMethods()->size()); EXPECT_EQ(1, observer.input_method_changed_count_); EXPECT_EQ(1, observer.input_method_menu_item_changed_count_); - manager_->ChangeInputMethod("xkb:us:dvorak:eng"); + manager_->ChangeInputMethod(XkbId("xkb:us:dvorak:eng")); EXPECT_FALSE(observer.last_show_message_); EXPECT_EQ(2, observer.input_method_changed_count_); EXPECT_EQ(2, observer.input_method_menu_item_changed_count_); - manager_->ChangeInputMethod("xkb:us:dvorak:eng"); + manager_->ChangeInputMethod(XkbId("xkb:us:dvorak:eng")); EXPECT_FALSE(observer.last_show_message_); // The observer is always notified even when the same input method ID is @@ -301,8 +383,6 @@ TEST_F(InputMethodManagerImplTest, TestEnableLayouts) { InitComponentExtension(); manager_->EnableLoginLayouts("en-US", keyboard_layouts); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); - for (size_t i = 0; i < manager_->GetActiveInputMethodIds().size(); ++i) - LOG(ERROR) << manager_->GetActiveInputMethodIds().at(i); // For http://crbug.com/19655#c11 - (5) // The hardware keyboard layout "xkb:us::eng" is always active, hence 2U. @@ -315,12 +395,14 @@ TEST_F(InputMethodManagerImplTest, TestEnableLayoutsAndCurrentInputMethod) { std::vector<std::string> keyboard_layouts; keyboard_layouts.push_back("xkb:se::swe"); + InitComponentExtension(); manager_->EnableLoginLayouts("en-US", keyboard_layouts); const std::string im_id = manager_->GetCurrentInputMethod().id(); - EXPECT_EQ("xkb:se::swe", im_id); + EXPECT_EQ(XkbId("xkb:se::swe"), im_id); } TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { + InitComponentExtension(); // The physical layout is French. manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( "xkb:fr::fra"); @@ -345,10 +427,12 @@ TEST_F(InputMethodManagerImplTest, TestEnableLayoutsNonUsHardwareKeyboard) { manager_->GetInputMethodUtil()->GetHardwareLoginInputMethodIds()); // "xkb:us::eng" only. EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ("xkb:us::eng", manager_->GetActiveInputMethodIds().front()); + EXPECT_EQ(XkbId("xkb:us::eng"), + manager_->GetActiveInputMethodIds().front()); } TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout) { + InitComponentExtension(); // The physical layouts are French and Hungarian. manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( "xkb:fr::fra,xkb:hu::hun"); @@ -361,6 +445,7 @@ TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout) { TEST_F(InputMethodManagerImplTest, TestEnableMultipleHardwareKeyboardLayout_NoLoginKeyboard) { + InitComponentExtension(); // The physical layouts are English (US) and Russian. manager_->GetInputMethodUtil()->SetHardwareKeyboardLayoutForTesting( "xkb:us::eng,xkb:ru::rus"); @@ -372,6 +457,7 @@ TEST_F(InputMethodManagerImplTest, } TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { + InitComponentExtension(); std::vector<std::string> keyboard_layouts; manager_->EnableLoginLayouts("ja", keyboard_layouts); // Japanese EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); @@ -381,11 +467,11 @@ TEST_F(InputMethodManagerImplTest, TestActiveInputMethods) { EXPECT_EQ(2U, methods->size()); const InputMethodDescriptor* id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( - "xkb:us::eng"); - EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); + XkbId("xkb:us::eng")); + EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); id_to_find = manager_->GetInputMethodUtil()->GetInputMethodDescriptorFromId( - "xkb:jp::jpn"); - EXPECT_TRUE(Contain(*methods.get(), *id_to_find)); + XkbId("xkb:jp::jpn")); + EXPECT_TRUE(id_to_find && Contain(*methods.get(), *id_to_find)); } TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) { @@ -402,14 +488,14 @@ TEST_F(InputMethodManagerImplTest, TestEnableTwoLayouts) { // Since all the IDs added avobe are keyboard layouts, Start() should not be // called. EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Disable Dvorak. ids.erase(ids.begin()); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(2, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], // colemak + EXPECT_EQ(XkbId(ids[0]), // colemak manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -428,19 +514,19 @@ TEST_F(InputMethodManagerImplTest, TestEnableThreeLayouts) { EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Switch to Dvorak. manager_->SwitchToNextInputMethod(); EXPECT_EQ(2, observer.input_method_changed_count_); - EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Disable Dvorak. ids.erase(ids.begin() + 1); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(3, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], // US Qwerty + EXPECT_EQ(XkbId(ids[0]), // US Qwerty manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -457,18 +543,18 @@ TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme) { ids.push_back(kNaclMozcUsId); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Switch to Mozc manager_->SwitchToNextInputMethod(); EXPECT_EQ(2, observer.input_method_changed_count_); - EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Disable Mozc. ids.erase(ids.begin() + 1); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); } @@ -483,14 +569,14 @@ TEST_F(InputMethodManagerImplTest, TestEnableLayoutAndIme2) { ids.push_back(kNaclMozcUsId); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Disable Dvorak. ids.erase(ids.begin()); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ(ids[0], // Mozc + EXPECT_EQ(XkbId(ids[0]), // Mozc manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -506,7 +592,7 @@ TEST_F(InputMethodManagerImplTest, TestEnableImes) { ids.push_back("mozc-dv"); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); } @@ -539,30 +625,30 @@ TEST_F(InputMethodManagerImplTest, TestEnableLayoutsThenLock) { EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Switch to Dvorak. manager_->SwitchToNextInputMethod(); EXPECT_EQ(2, observer.input_method_changed_count_); - EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Lock screen manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ(ids[1], // still Dvorak + EXPECT_EQ(XkbId(ids[1]), // still Dvorak manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Switch back to Qwerty. manager_->SwitchToNextInputMethod(); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Unlock screen. The original state, Dvorak, is restored. manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -581,30 +667,30 @@ TEST_F(InputMethodManagerImplTest, SwitchInputMethodTest) { EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Switch to Mozc. manager_->SwitchToNextInputMethod(); EXPECT_EQ(2, observer.input_method_changed_count_); - EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); // Lock screen manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); // Qwerty+Dvorak. - EXPECT_EQ("xkb:us:dvorak:eng", + EXPECT_EQ(XkbId("xkb:us:dvorak:eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); manager_->SwitchToNextInputMethod(); - EXPECT_EQ("xkb:us::eng", // The hardware keyboard layout. + EXPECT_EQ(XkbId("xkb:us::eng"), // The hardware keyboard layout. manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Unlock screen. The original state, pinyin-dv, is restored. manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); // Dvorak and 2 IMEs. - EXPECT_EQ(ids[1], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[1]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -731,27 +817,30 @@ TEST_F(InputMethodManagerImplTest, TestNextInputMethod) { // For http://crbug.com/19655#c11 - (1) manager_->EnableLoginLayouts("en-US", keyboard_layouts); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); manager_->SwitchToNextInputMethod(); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); manager_->SwitchToNextInputMethod(); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:altgr-intl:eng"), + manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_); manager_->SwitchToNextInputMethod(); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:dvorak:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:dvorak:eng"), + manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); manager_->SwitchToNextInputMethod(); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:colemak:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:colemak:eng"), + manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(colemak)", xkeyboard_->last_layout_); manager_->SwitchToNextInputMethod(); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -771,44 +860,47 @@ TEST_F(InputMethodManagerImplTest, TestPreviousInputMethod) { keyboard_layouts.push_back("xkb:us::eng"); manager_->EnableLoginLayouts("en-US", keyboard_layouts); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToNextInputMethod()); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:intl:eng"), + manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToNextInputMethod()); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToNextInputMethod()); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:altgr-intl:eng"), + manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:intl:eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(intl)", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); EXPECT_TRUE(observer.last_show_message_); - EXPECT_EQ("xkb:us:altgr-intl:eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us:altgr-intl:eng"), + manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(altgr-intl)", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -839,6 +931,7 @@ TEST_F(InputMethodManagerImplTest, } TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { + std::string expect_id = XkbId("xkb:us::eng"); TestObserver observer; manager_->AddObserver(&observer); InitComponentExtension(); @@ -846,7 +939,7 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { keyboard_layouts.push_back("xkb:us::eng"); manager_->EnableLoginLayouts("en-US", keyboard_layouts); EXPECT_EQ(5U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Henkan, Muhenkan, ZenkakuHankaku should be ignored when no Japanese IMEs @@ -854,19 +947,19 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithUsLayouts) { EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); EXPECT_FALSE(observer.last_show_message_); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_FALSE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(expect_id, manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); manager_->RemoveObserver(&observer); @@ -885,27 +978,27 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpLayout) { keyboard_layouts.push_back("xkb:us::eng"); manager_->EnableLoginLayouts("ja", keyboard_layouts); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keydown_accelerator)); EXPECT_TRUE(manager_->SwitchToPreviousInputMethod(keyup_accelerator)); - EXPECT_EQ("xkb:us::eng", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); } @@ -916,7 +1009,7 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { ids.push_back("xkb:jp::jpn"); ids.push_back(kNaclMozcJpId); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); @@ -924,7 +1017,7 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_DBCSCHAR, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_CONVERT, ui::EF_NONE))); @@ -936,17 +1029,17 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_NONCONVERT, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); // Add Dvorak. ids.push_back("xkb:us:dvorak:eng"); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); @@ -954,7 +1047,7 @@ TEST_F(InputMethodManagerImplTest, TestSwitchInputMethodWithJpIme) { EXPECT_EQ("jp", xkeyboard_->last_layout_); EXPECT_TRUE(manager_->SwitchInputMethod( ui::Accelerator(ui::VKEY_DBE_SBCSCHAR, ui::EF_NONE))); - EXPECT_EQ("xkb:jp::jpn", manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId("xkb:jp::jpn"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("jp", xkeyboard_->last_layout_); } @@ -968,7 +1061,7 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); @@ -1050,7 +1143,7 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1, observer.input_method_changed_count_); - EXPECT_EQ(ids[0], manager_->GetCurrentInputMethod().id()); + EXPECT_EQ(XkbId(ids[0]), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); // Add an Extension IME. @@ -1090,7 +1183,7 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { // Lock the screen. This is for crosbug.com/27049. manager_->SetState(InputMethodManager::STATE_LOCK_SCREEN); EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); // Qwerty. No Ext. IME - EXPECT_EQ("xkb:us::eng", + EXPECT_EQ(XkbId("xkb:us::eng"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us", xkeyboard_->last_layout_); @@ -1142,8 +1235,8 @@ TEST_F(InputMethodManagerImplTest, ChangeInputMethodBeforeComponentExtensionInitialization_CompOneIME) { manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); const std::string ext_id = extension_ime_util::GetComponentInputMethodID( - ime_list_[0].id, - ime_list_[0].engines[0].engine_id); + ime_list_[1].id, + ime_list_[1].engines[0].engine_id); std::vector<std::string> ids; ids.push_back(ext_id); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); @@ -1158,11 +1251,11 @@ TEST_F(InputMethodManagerImplTest, ChangeInputMethodBeforeComponentExtensionInitialization_CompTwoIME) { manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID( - ime_list_[0].id, - ime_list_[0].engines[0].engine_id); - const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( ime_list_[1].id, ime_list_[1].engines[0].engine_id); + const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( + ime_list_[2].id, + ime_list_[2].engines[0].engine_id); std::vector<std::string> ids; ids.push_back(ext_id1); ids.push_back(ext_id2); @@ -1180,8 +1273,8 @@ TEST_F(InputMethodManagerImplTest, InitComponentExtension(); manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); const std::string ext_id = extension_ime_util::GetComponentInputMethodID( - ime_list_[0].id, - ime_list_[0].engines[0].engine_id); + ime_list_[1].id, + ime_list_[1].engines[0].engine_id); std::vector<std::string> ids; ids.push_back(ext_id); EXPECT_TRUE(manager_->ReplaceEnabledInputMethods(ids)); @@ -1194,11 +1287,11 @@ TEST_F(InputMethodManagerImplTest, InitComponentExtension(); manager_->SetState(InputMethodManager::STATE_BROWSER_SCREEN); const std::string ext_id1 = extension_ime_util::GetComponentInputMethodID( - ime_list_[0].id, - ime_list_[0].engines[0].engine_id); - const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( ime_list_[1].id, ime_list_[1].engines[0].engine_id); + const std::string ext_id2 = extension_ime_util::GetComponentInputMethodID( + ime_list_[2].id, + ime_list_[2].engines[0].engine_id); std::vector<std::string> ids; ids.push_back(ext_id1); ids.push_back(ext_id2); @@ -1209,5 +1302,53 @@ TEST_F(InputMethodManagerImplTest, EXPECT_EQ(ext_id2, manager_->GetCurrentInputMethod().id()); } +TEST_F(InputMethodManagerImplTest, MigrateXkbInputMethodTest_1) { + extension_ime_util::ScopedUseExtensionKeyboardFlagForTesting + scoped_flag(true); + + std::vector<std::string> input_method_ids; + input_method_ids.push_back("xkb:us::eng"); + input_method_ids.push_back("xkb:fr::fra"); + input_method_ids.push_back( + "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:us::eng"); + input_method_ids.push_back("xkb:fr::fra"); + input_method_ids.push_back( + "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:us::eng"); + input_method_ids.push_back("_comp_ime_asdf_pinyin"); + + manager_->MigrateXkbInputMethods(&input_method_ids); + + ASSERT_EQ(3U, input_method_ids.size()); + + EXPECT_EQ("_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:us::eng", + input_method_ids[0]); + EXPECT_EQ("_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:fr::fra", + input_method_ids[1]); + EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); +} + +TEST_F(InputMethodManagerImplTest, MigrateXkbInputMethodTest_2) { + extension_ime_util::ScopedUseExtensionKeyboardFlagForTesting + scoped_flag(false); + + std::vector<std::string> input_method_ids; + input_method_ids.push_back("xkb:us::eng"); + input_method_ids.push_back("xkb:fr::fra"); + input_method_ids.push_back( + "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:us::eng"); + input_method_ids.push_back("xkb:fr::fra"); + input_method_ids.push_back( + "_comp_ime_fgoepimhcoialccpbmpnnblemnepkkaoxkb:us::eng"); + input_method_ids.push_back("_comp_ime_asdf_pinyin"); + + manager_->MigrateXkbInputMethods(&input_method_ids); + + ASSERT_EQ(3U, input_method_ids.size()); + + EXPECT_EQ("xkb:us::eng", input_method_ids[0]); + EXPECT_EQ("xkb:fr::fra", input_method_ids[1]); + EXPECT_EQ("_comp_ime_asdf_pinyin", input_method_ids[2]); +} + } // namespace input_method } // namespace chromeos diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc index e11dd25..920ff98 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.cc +++ b/chrome/browser/chromeos/input_method/input_method_util.cc @@ -459,7 +459,12 @@ base::string16 InputMethodUtil::GetInputMethodLongName( DCHECK(!input_method.language_codes().empty()); const std::string language_code = input_method.language_codes().at(0); - base::string16 text = TranslateString(input_method.id()); + // Before translate the string, convert the input method id to legacy xkb id + // if possible. + // TODO(shuchen): the GetInputMethodLongName() method should be removed when + // finish the wrapping of xkb to extension. + base::string16 text = TranslateString( + extension_ime_util::MaybeGetLegacyXkbId(input_method.id())); if (text == standard_input_method_text || language_code == "de" || language_code == "fr" || @@ -478,7 +483,20 @@ const InputMethodDescriptor* InputMethodUtil::GetInputMethodDescriptorFromId( const std::string& input_method_id) const { InputMethodIdToDescriptorMap::const_iterator iter = id_to_descriptor_.find(input_method_id); - return (iter == id_to_descriptor_.end()) ? NULL : &(iter->second); + if (iter == id_to_descriptor_.end()) { + // If failed to find the descriptor for given id, it may because of the id + // is a component extension xkb id (_comp_ime_...xkb:...). + // So try to convert it to legacy xkb id and find again. + // This hack is mainly for OOBE session, which requires a sync call to get + // the input method descriptor for extension xkb id. + // TODO(shuchen): need to support async wait for component extension + // loading in OOBE session. This hack won't be needed when it's been done. + iter = id_to_descriptor_.find( + extension_ime_util::MaybeGetLegacyXkbId(input_method_id)); + if (iter == id_to_descriptor_.end()) + return NULL; + } + return &(iter->second); } bool InputMethodUtil::GetInputMethodIdsFromLanguageCode( @@ -611,11 +629,36 @@ std::string InputMethodUtil::GetLanguageDefaultInputMethodId( return std::string(); } +bool InputMethodUtil::MigrateXkbInputMethods( + std::vector<std::string>* input_method_ids) { + bool rewritten = false; + std::vector<std::string>& ids = *input_method_ids; + for (size_t i = 0; i < ids.size(); ++i) { + std::string id = + extension_ime_util::GetInputMethodIDByKeyboardLayout(ids[i]); + if (id != ids[i]) { + ids[i] = id; + rewritten = true; + } + } + if (rewritten) { + // Removes the duplicates. + std::vector<std::string> new_ids; + for (size_t i = 0; i < ids.size(); ++i) { + if (std::find(new_ids.begin(), new_ids.end(), ids[i]) == new_ids.end()) + new_ids.push_back(ids[i]); + } + ids.swap(new_ids); + } + return rewritten; +} + void InputMethodUtil::UpdateHardwareLayoutCache() { DCHECK(thread_checker_.CalledOnValidThread()); hardware_layouts_.clear(); hardware_login_layouts_.clear(); Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", &hardware_layouts_); + MigrateXkbInputMethods(&hardware_layouts_); for (size_t i = 0; i < hardware_layouts_.size(); ++i) { if (IsLoginKeyboard(hardware_layouts_[i])) @@ -682,14 +725,15 @@ InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { layouts.push_back("us"); std::vector<std::string> languages; languages.push_back("en-US"); - return InputMethodDescriptor("xkb:us::eng", - "", - "US", - layouts, - languages, - true, // login keyboard. - GURL(), // options page, not available. - GURL()); // input view page, not available. + return InputMethodDescriptor( + extension_ime_util::GetInputMethodIDByKeyboardLayout("xkb:us::eng"), + "", + "US", + layouts, + languages, + true, // login keyboard. + GURL(), // options page, not available. + GURL()); // input view page, not available. } void InputMethodUtil::ReloadInternalMaps() { diff --git a/chrome/browser/chromeos/input_method/input_method_util.h b/chrome/browser/chromeos/input_method/input_method_util.h index a89ebd7..eea2d9e 100644 --- a/chrome/browser/chromeos/input_method/input_method_util.h +++ b/chrome/browser/chromeos/input_method/input_method_util.h @@ -40,6 +40,9 @@ class InputMethodUtil { // into Chrome's string ID, then pulls internationalized resource string from // the resource bundle and returns it. These functions are not thread-safe. // Non-UI threads are not allowed to call them. + // The english_string to should be a xkb id with "xkb:...:...:..." format. + // TODO(shuchen): this method should be removed when finish the wrapping of + // xkb to extension. base::string16 TranslateString(const std::string& english_string) const; // Converts an input method ID to a language code of the IME. Returns "Eng" @@ -98,6 +101,14 @@ class InputMethodUtil { // Returns empty string on error. std::string GetLanguageDefaultInputMethodId(const std::string& language_code); + // Migrates the legacy xkb id to extension based xkb id. + // Returns true if the given input method id list is modified, + // returns false otherwise. + // TODO(shuchen): Remove this function after few milestones are passed. + // See: http://crbug.com/345604 + bool MigrateXkbInputMethods( + std::vector<std::string>* input_method_ids); + // Updates the internal cache of hardware layouts. void UpdateHardwareLayoutCache(); diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc index beb0d28..95142a3 100644 --- a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc +++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc @@ -165,5 +165,11 @@ bool MockInputMethodManager::IsLoginKeyboard( const std::string& layout) const { return true; } + +bool MockInputMethodManager::MigrateXkbInputMethods( + std::vector<std::string>* input_method_ids) { + return false; +} + } // namespace input_method } // namespace chromeos diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.h b/chrome/browser/chromeos/input_method/mock_input_method_manager.h index b6a757e..25f21c0 100644 --- a/chrome/browser/chromeos/input_method/mock_input_method_manager.h +++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.h @@ -63,6 +63,8 @@ class MockInputMethodManager : public InputMethodManager { virtual ComponentExtensionIMEManager* GetComponentExtensionIMEManager() OVERRIDE; virtual bool IsLoginKeyboard(const std::string& layout) const OVERRIDE; + virtual bool MigrateXkbInputMethods( + std::vector<std::string>* input_method_ids) OVERRIDE; // Sets an input method ID which will be returned by GetCurrentInputMethod(). void SetCurrentInputMethodId(const std::string& input_method_id) { diff --git a/chrome/browser/chromeos/login/login_display_host_impl.cc b/chrome/browser/chromeos/login/login_display_host_impl.cc index 1174979..3729797 100644 --- a/chrome/browser/chromeos/login/login_display_host_impl.cc +++ b/chrome/browser/chromeos/login/login_display_host_impl.cc @@ -16,6 +16,7 @@ #include "base/debug/trace_event.h" #include "base/logging.h" #include "base/prefs/pref_service.h" +#include "base/strings/string_split.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" #include "base/time/time.h" @@ -60,6 +61,7 @@ #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/session_manager_client.h" +#include "chromeos/ime/extension_ime_util.h" #include "chromeos/ime/input_method_manager.h" #include "chromeos/login/login_state.h" #include "chromeos/settings/timezone_settings.h" @@ -123,13 +125,13 @@ const int64 kPolicyServiceInitializationDelayMilliseconds = 100; // The information will be used in InputMethodUtil::GetHardwareInputMethodId(). void DetermineAndSaveHardwareKeyboard(const std::string& locale, const std::string& oem_layout) { + chromeos::input_method::InputMethodManager* manager = + chromeos::input_method::InputMethodManager::Get(); std::string layout; if (!oem_layout.empty()) { // If the OEM layout information is provided, use it. layout = oem_layout; } else { - chromeos::input_method::InputMethodManager* manager = - chromeos::input_method::InputMethodManager::Get(); // Otherwise, determine the hardware keyboard from the locale. std::vector<std::string> input_method_ids; if (manager->GetInputMethodUtil()->GetInputMethodIdsFromLanguageCode( @@ -144,8 +146,12 @@ void DetermineAndSaveHardwareKeyboard(const std::string& locale, } if (!layout.empty()) { + std::vector<std::string> layouts; + base::SplitString(layout, ',', &layouts); + manager->MigrateXkbInputMethods(&layouts); + PrefService* prefs = g_browser_process->local_state(); - prefs->SetString(prefs::kHardwareKeyboardLayout, layout); + prefs->SetString(prefs::kHardwareKeyboardLayout, JoinString(layouts, ",")); // This asks the file thread to save the prefs (i.e. doesn't block). // The latest values of Local State reside in memory so we can safely @@ -153,8 +159,6 @@ void DetermineAndSaveHardwareKeyboard(const std::string& locale, // yet saved to disk. prefs->CommitPendingWrite(); - chromeos::input_method::InputMethodManager* manager = - chromeos::input_method::InputMethodManager::Get(); manager->GetInputMethodUtil()->UpdateHardwareLayoutCache(); manager->SetInputMethodLoginDefault(); } diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 16566b8..44048d6 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -33,6 +33,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chromeos/chromeos_switches.h" +#include "chromeos/ime/extension_ime_util.h" #include "chromeos/ime/input_method_manager.h" #include "chromeos/ime/xkeyboard.h" #include "chromeos/system/statistics_provider.h" @@ -582,6 +583,12 @@ void Preferences::SetLanguageConfigStringListAsCSV(const char* section, if (!value.empty()) base::SplitString(value, ',', &split_values); + // TODO(shuchen): migration of the xkb id to extension-xkb id. + // Remove this function after few milestones are passed. + // See: http://crbug.com/345604 + if (input_method_manager_->MigrateXkbInputMethods(&split_values)) + preload_engines_.SetValue(JoinString(split_values, ',')); + if (section == std::string(language_prefs::kGeneralSectionName) && name == std::string(language_prefs::kPreloadEnginesConfigName)) { input_method_manager_->ReplaceEnabledInputMethods(split_values); |