diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-09 04:50:23 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-09 04:50:23 +0000 |
commit | aef1af4b193560aa51e9aaa858ae41a7e92b5c3a (patch) | |
tree | 996057f591a6168fb9da0512fa9c5fd0b082594a /chrome/browser | |
parent | 6e536cdf138d65ede0844654966a0c0ed0cfd430 (diff) | |
download | chromium_src-aef1af4b193560aa51e9aaa858ae41a7e92b5c3a.zip chromium_src-aef1af4b193560aa51e9aaa858ae41a7e92b5c3a.tar.gz chromium_src-aef1af4b193560aa51e9aaa858ae41a7e92b5c3a.tar.bz2 |
Do not enable extension IME just after installation.
This CL inverts the meaning of filtered extension IMEs preferences.
With this CL any extension IME won't be enabled just after it's installed.
This is preparation of dropping Extension IME button from language options.
After that, I will introduce better extension IME selection based on user's preferred languages.
BUG=180094
TEST=Manually checked
Review URL: https://chromiumcodereview.appspot.com/14870004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
9 files changed, 148 insertions, 76 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc b/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc index b2ede41..4b1b684 100644 --- a/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc +++ b/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc @@ -135,6 +135,13 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineIBusBrowserTest, // component. Here, there is two engine, thus expectation is at least twice. EXPECT_LE(3, ibus_client->register_component_call_count()); + // Extension IMEs are not enabled by default. + std::vector<std::string> extension_ime_ids; + extension_ime_ids.push_back(kIdentityIMEID); + extension_ime_ids.push_back(kToUpperIMEID); + extension_ime_ids.push_back(kEchoBackIMEID); + GetInputMethodManager()->SetEnabledExtensionImes(&extension_ime_ids); + InputMethodDescriptors extension_imes; GetInputMethodManager()->GetInputMethodExtensions(&extension_imes); 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 089dedf..802b065 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc @@ -424,7 +424,7 @@ void InputMethodManagerImpl::AddInputMethodExtension( // crbug.com/156283. extra_input_methods_[id] = InputMethodDescriptor(id, name, layouts, language, ""); - if (!Contains(filtered_extension_imes_, id) && + if (Contains(enabled_extension_imes_, id) && !ComponentExtensionIMEManager::IsComponentExtensionIMEId(id)) { if (!Contains(active_input_method_ids_, id)) { active_input_method_ids_.push_back(id); @@ -487,12 +487,12 @@ void InputMethodManagerImpl::GetInputMethodExtensions( } } -void InputMethodManagerImpl::SetFilteredExtensionImes( +void InputMethodManagerImpl::SetEnabledExtensionImes( std::vector<std::string>* ids) { - filtered_extension_imes_.clear(); - filtered_extension_imes_.insert(filtered_extension_imes_.end(), - ids->begin(), - ids->end()); + enabled_extension_imes_.clear(); + enabled_extension_imes_.insert(enabled_extension_imes_.end(), + ids->begin(), + ids->end()); bool active_imes_changed = false; @@ -507,15 +507,15 @@ void InputMethodManagerImpl::SetFilteredExtensionImes( extra_iter->first); bool active = active_iter != active_input_method_ids_.end(); - bool filtered = Contains(filtered_extension_imes_, extra_iter->first); + bool enabled = Contains(enabled_extension_imes_, extra_iter->first); - if (active && filtered) + if (active && !enabled) active_input_method_ids_.erase(active_iter); - if (!active && !filtered) + if (!active && enabled) active_input_method_ids_.push_back(extra_iter->first); - if (active == filtered) + if (active == !enabled) active_imes_changed = true; } @@ -673,7 +673,7 @@ void InputMethodManagerImpl::OnConnected() { extra_input_method_instances_.begin(); ite != extra_input_method_instances_.end(); ite++) { - if (!Contains(filtered_extension_imes_, ite->first)) + if (Contains(enabled_extension_imes_, ite->first)) ite->second->OnConnected(); } @@ -690,7 +690,7 @@ void InputMethodManagerImpl::OnDisconnected() { extra_input_method_instances_.begin(); ite != extra_input_method_instances_.end(); ite++) { - if (!Contains(filtered_extension_imes_, ite->first)) + if (Contains(enabled_extension_imes_, ite->first)) ite->second->OnDisconnected(); } } 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 57ee61c..53a6961 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h @@ -80,7 +80,7 @@ class InputMethodManagerImpl : public InputMethodManager, virtual void RemoveInputMethodExtension(const std::string& id) OVERRIDE; virtual void GetInputMethodExtensions( InputMethodDescriptors* result) OVERRIDE; - virtual void SetFilteredExtensionImes(std::vector<std::string>* ids) OVERRIDE; + virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE; virtual bool SwitchToNextInputMethod() OVERRIDE; virtual bool SwitchToPreviousInputMethod() OVERRIDE; virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE; @@ -171,8 +171,8 @@ class InputMethodManagerImpl : public InputMethodManager, // The active input method ids cache. std::vector<std::string> active_input_method_ids_; - // The list of IMEs that are filtered from the IME list. - std::vector<std::string> filtered_extension_imes_; + // The list of enabled extension IMEs. + std::vector<std::string> enabled_extension_imes_; // For screen locker. When the screen is locked, |previous_input_method_|, // |current_input_method_|, and |active_input_method_ids_| above are copied 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 a9e7f7c..0b85347 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 @@ -978,6 +978,14 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { layouts, "en-US", NULL); + + // Extension IMEs are not enabled by default. + EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); + + std::vector<std::string> extension_ime_ids; + extension_ime_ids.push_back( + extension_ime_util::GetInputMethodID("deadbeef", "engine_id")); + manager_->SetEnabledExtensionImes(&extension_ime_ids); EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); // should be started. @@ -996,6 +1004,11 @@ TEST_F(InputMethodManagerImplTest, TestAddRemoveExtensionInputMethods) { layouts, "en-US", NULL); + EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); + + extension_ime_ids.push_back( + extension_ime_util::GetInputMethodID("cafebabe", "engine_id")); + manager_->SetEnabledExtensionImes(&extension_ime_ids); EXPECT_EQ(3U, manager_->GetNumActiveInputMethods()); { scoped_ptr<InputMethodDescriptors> methods( @@ -1042,12 +1055,19 @@ TEST_F(InputMethodManagerImplTest, TestAddExtensionInputThenLockScreen) { layouts, "en-US", NULL); - EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); + // Extension IME is not enabled by default. + EXPECT_EQ(1U, manager_->GetNumActiveInputMethods()); EXPECT_EQ(1, observer.input_method_changed_count_); + std::vector<std::string> extension_ime_ids; + extension_ime_ids.push_back( + extension_ime_util::GetInputMethodID("deadbeef", "engine_id")); + manager_->SetEnabledExtensionImes(&extension_ime_ids); + EXPECT_EQ(2U, manager_->GetNumActiveInputMethods()); + // Switch to the IME. manager_->SwitchToNextInputMethod(); - EXPECT_EQ(2, observer.input_method_changed_count_); + EXPECT_EQ(3, observer.input_method_changed_count_); EXPECT_EQ(extension_ime_util::GetInputMethodID("deadbeef", "engine_id"), manager_->GetCurrentInputMethod().id()); EXPECT_EQ("us(dvorak)", xkeyboard_->last_layout_); 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 22e4498..b5f0c00 100644 --- a/chrome/browser/chromeos/input_method/mock_input_method_manager.cc +++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.cc @@ -98,7 +98,7 @@ void MockInputMethodManager::GetInputMethodExtensions( InputMethodDescriptors* result) { } -void MockInputMethodManager::SetFilteredExtensionImes( +void MockInputMethodManager::SetEnabledExtensionImes( std::vector<std::string>* ids) { } 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 0099ad7..acf05b7 100644 --- a/chrome/browser/chromeos/input_method/mock_input_method_manager.h +++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.h @@ -53,7 +53,7 @@ class MockInputMethodManager : public InputMethodManager { virtual void RemoveInputMethodExtension(const std::string& id) OVERRIDE; virtual void GetInputMethodExtensions( InputMethodDescriptors* result) OVERRIDE; - virtual void SetFilteredExtensionImes(std::vector<std::string>* ids) OVERRIDE; + virtual void SetEnabledExtensionImes(std::vector<std::string>* ids) OVERRIDE; virtual bool SwitchToNextInputMethod() OVERRIDE; virtual bool SwitchToPreviousInputMethod() OVERRIDE; virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE; diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index be518a9..1aefed4 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -177,7 +177,7 @@ void Preferences::RegisterUserPrefs( hardware_keyboard_id, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( - prefs::kLanguageFilteredExtensionImes, + prefs::kLanguageEnabledExtensionImes, "", user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) { @@ -427,8 +427,8 @@ void Preferences::InitUserPrefs(PrefServiceSyncable* prefs) { preferred_languages_.Init(prefs::kLanguagePreferredLanguages, prefs, callback); preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, callback); - filtered_extension_imes_.Init(prefs::kLanguageFilteredExtensionImes, - prefs, callback); + enabled_extension_imes_.Init(prefs::kLanguageEnabledExtensionImes, + prefs, callback); current_input_method_.Init(prefs::kLanguageCurrentInputMethod, prefs, callback); previous_input_method_.Init(prefs::kLanguagePreviousInputMethod, @@ -697,14 +697,14 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) { preload_engines_.GetValue()); } - if (!pref_name || *pref_name == prefs::kLanguageFilteredExtensionImes) { - std::string value(filtered_extension_imes_.GetValue()); + if (!pref_name || *pref_name == prefs::kLanguageEnabledExtensionImes) { + std::string value(enabled_extension_imes_.GetValue()); std::vector<std::string> split_values; if (!value.empty()) base::SplitString(value, ',', &split_values); - input_method_manager_->SetFilteredExtensionImes(&split_values); + input_method_manager_->SetEnabledExtensionImes(&split_values); } // Do not check |*pref_name| of the prefs for remembering current/previous diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index c1bab86..464c3b1 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -136,7 +136,7 @@ class Preferences : public PrefServiceSyncableObserver { StringPrefMember preload_engines_; StringPrefMember current_input_method_; StringPrefMember previous_input_method_; - StringPrefMember filtered_extension_imes_; + StringPrefMember enabled_extension_imes_; BooleanPrefMember chewing_boolean_prefs_[ language_prefs::kNumChewingBooleanPrefs]; diff --git a/chrome/browser/resources/options/language_options.js b/chrome/browser/resources/options/language_options.js index 49da7e3..10ac1ad 100644 --- a/chrome/browser/resources/options/language_options.js +++ b/chrome/browser/resources/options/language_options.js @@ -71,6 +71,71 @@ cr.define('options', function() { spellcheckDictionaryDownloadFailures_: 0, /** + * The preference is a boolean that enables/disables spell checking. + * @type {string} + * @private + * @const + */ + enableSpellCheckPref_: 'browser.enable_spellchecking', + + /** + * The preference is a CSV string that describes preload engines + * (i.e. active input methods). + * @type {string} + * @private + * @const + */ + preloadEnginesPref_: 'settings.language.preload_engines', + + /** + * The list of preload engines, like ['mozc', 'pinyin']. + * @type {Array} + * @private + */ + preloadEngines_: [], + + /** + * The preference that lists the extension IMEs that are enabled in the + * language menu. + * @type {string} + * @private + * @const + */ + enabledExtensionImePref_: 'settings.language.enabled_extension_imes', + + /** + * The list of extension IMEs that are enabled out of the language menu. + * @type {Array} + * @private + */ + enabledExtensionImes_: [], + + /** + * The preference key that is a string that describes the spell check + * dictionary language, like "en-US". + * @type {string} + * @private + * @const + */ + spellCheckDictionaryPref_: 'spellcheck.dictionary', + + /** + * The preference is a string that describes the spell check dictionary + * language, like "en-US". + * @type {string} + * @private + */ + spellCheckDictionary_: '', + + /** + * The map of language code to input method IDs, like: + * {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} + * @type {Object} + * @private + */ + languageCodeToInputMethodIdsMap_: {}, + + /** * Initializes LanguageOptions page. * Calls base class implementation to start preference initialization. */ @@ -98,7 +163,7 @@ cr.define('options', function() { this.initializeInputMethodList_(); this.initializeLanguageCodeToInputMethodIdsMap_(); } - Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref, + Preferences.getInstance().addEventListener(this.spellCheckDictionaryPref_, this.handleSpellCheckDictionaryPrefChange_.bind(this)); // Set up add button. @@ -157,7 +222,7 @@ cr.define('options', function() { // Handle spell check enable/disable. if (!cr.isMac) { Preferences.getInstance().addEventListener( - this.enableSpellCheckPref, + this.enableSpellCheckPref_, this.updateEnableSpellCheck_.bind(this)); } } @@ -181,26 +246,6 @@ cr.define('options', function() { OptionsPage.closeOverlay.bind(OptionsPage); }, - // The preference is a boolean that enables/disables spell checking. - enableSpellCheckPref: 'browser.enable_spellchecking', - // The preference is a CSV string that describes preload engines - // (i.e. active input methods). - preloadEnginesPref: 'settings.language.preload_engines', - // The list of preload engines, like ['mozc', 'pinyin']. - preloadEngines_: [], - // The preference that lists the extension IMEs that are filtered out of - // the language menu. - filteredExtensionImesPref: 'settings.language.filtered_extension_imes', - // The list of extension IMEs that are filtered out of the language menu. - filteredExtensionImes_: [], - // The preference is a string that describes the spell check - // dictionary language, like "en-US". - spellCheckDictionaryPref: 'spellcheck.dictionary', - spellCheckDictionary_: '', - // The map of language code to input method IDs, like: - // {'ja': ['mozc', 'mozc-jp'], 'zh-CN': ['pinyin'], ...} - languageCodeToInputMethodIdsMap_: {}, - /** * Initializes the input method list. */ @@ -237,11 +282,11 @@ cr.define('options', function() { // Listen to pref change once the input method list is initialized. Preferences.getInstance().addEventListener( - this.preloadEnginesPref, + this.preloadEnginesPref_, this.handlePreloadEnginesPrefChange_.bind(this)); Preferences.getInstance().addEventListener( - this.filteredExtensionImesPref, - this.handleFilteredExtensionsPrefChange_.bind(this)); + this.enabledExtensionImePref_, + this.handleEnabledExtensionsPrefChange_.bind(this)); }, /** @@ -683,14 +728,14 @@ cr.define('options', function() { }, /** - * Handles filteredExtensionImesPref change. + * Handles enabledExtensionImePref change. * @param {Event} e Change event. * @private */ - handleFilteredExtensionsPrefChange_: function(e) { + handleEnabledExtensionsPrefChange_: function(e) { var value = e.value.value; - this.filteredExtensionImes_ = value.split(','); - this.updateCheckboxesFromFilteredExtensions_(); + this.enabledExtensionImes_ = value.split(','); + this.updateCheckboxesFromEnabledExtensions_(); }, /** @@ -725,8 +770,8 @@ cr.define('options', function() { */ handleExtensionCheckboxClick_: function(e) { var checkbox = e.target; - this.updateFilteredExtensionsFromCheckboxes_(); - this.saveFilteredExtensionPref_(); + this.updateEnabledExtensionsFromCheckboxes_(); + this.saveEnabledExtensionPref_(); }, /** @@ -818,7 +863,7 @@ cr.define('options', function() { handleSpellCheckLanguageButtonClick_: function(e) { var languageCode = e.target.languageCode; // Save the preference. - Preferences.setStringPref(this.spellCheckDictionaryPref, + Preferences.setStringPref(this.spellCheckDictionaryPref_, languageCode, true); chrome.send('spellCheckLanguageChange', [languageCode]); }, @@ -883,46 +928,46 @@ cr.define('options', function() { }, /** - * Saves the filtered extension preference. + * Saves the enabled extension preference. * @private */ - saveFilteredExtensionPref_: function() { - Preferences.setStringPref(this.filteredExtensionImesPref, - this.filteredExtensionImes_.join(','), true); + saveEnabledExtensionPref_: function() { + Preferences.setStringPref(this.enabledExtensionImePref_, + this.enabledExtensionImes_.join(','), true); }, /** - * Updates the checkboxes in the input method list from the filtered + * Updates the checkboxes in the input method list from the enabled * extensions preference. * @private */ - updateCheckboxesFromFilteredExtensions_: function() { + updateCheckboxesFromEnabledExtensions_: function() { // Convert the list into a dictonary for simpler lookup. var dictionary = {}; - for (var i = 0; i < this.filteredExtensionImes_.length; i++) - dictionary[this.filteredExtensionImes_[i]] = true; + for (var i = 0; i < this.enabledExtensionImes_.length; i++) + dictionary[this.enabledExtensionImes_[i]] = true; var inputMethodList = $('language-options-input-method-list'); var checkboxes = inputMethodList.querySelectorAll('input'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].inputMethodId.match(/^_ext_ime_/)) - checkboxes[i].checked = !(checkboxes[i].inputMethodId in dictionary); + checkboxes[i].checked = (checkboxes[i].inputMethodId in dictionary); } }, /** - * Updates the filtered extensions preference from the checkboxes in the + * Updates the enabled extensions preference from the checkboxes in the * input method list. * @private */ - updateFilteredExtensionsFromCheckboxes_: function() { - this.filteredExtensionImes_ = []; + updateEnabledExtensionsFromCheckboxes_: function() { + this.enabledExtensionImes_ = []; var inputMethodList = $('language-options-input-method-list'); var checkboxes = inputMethodList.querySelectorAll('input'); for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].inputMethodId.match(/^_ext_ime_/)) { - if (!checkboxes[i].checked) - this.filteredExtensionImes_.push(checkboxes[i].inputMethodId); + if (checkboxes[i].checked) + this.enabledExtensionImes_.push(checkboxes[i].inputMethodId); } } }, @@ -932,7 +977,7 @@ cr.define('options', function() { * @private */ savePreloadEnginesPref_: function() { - Preferences.setStringPref(this.preloadEnginesPref, + Preferences.setStringPref(this.preloadEnginesPref_, this.preloadEngines_.join(','), true); }, @@ -989,7 +1034,7 @@ cr.define('options', function() { dictionary[list[i].id] = true; } - var filteredPreloadEngines = []; + var enabledPreloadEngines = []; var seen = {}; for (var i = 0; i < preloadEngines.length; i++) { // Check if the preload engine is present in the @@ -998,11 +1043,11 @@ cr.define('options', function() { // "_comp_" is the special prefix of its ID. if ((preloadEngines[i] in dictionary && !(preloadEngines[i] in seen)) || /^_comp_/.test(preloadEngines[i])) { - filteredPreloadEngines.push(preloadEngines[i]); + enabledPreloadEngines.push(preloadEngines[i]); seen[preloadEngines[i]] = true; } } - return filteredPreloadEngines; + return enabledPreloadEngines; }, // TODO(kochi): This is an adapted copy from new_tab.js. |