Commit 13ed66f7 authored by yusukes's avatar yusukes Committed by Commit Bot

Update the list of supported IMEs when an IME is added or removed

This allows chrome://settings/inputMethods to show up-to-date IME
information without closing and reopening the settings window. For
example, when the language X is enabled on the device and a new
Chrome OS IME extension for the language X is installed, it'll
instantly show up in chrome://settings/inputMethods. The same happens
for Android IMEs installed via Play Store too.

BUG=867795,845079
TEST=Add 'Japanese' to the language list, open chrome://settings/inputMethods,
 install 'SKK Japanese Input' (extension IME) from Chrome Web Store, verify
 the IME entry ('SKK') shows up in the settings page immediately.
TEST=Go to extensions page, disable the SKK IME, verify 'SKK' disappears
 immediately.

Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I20f7586cd58e7d6c6f92f37c1f0b697d57d17d32
Reviewed-on: https://chromium-review.googlesource.com/1198106
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588233}
parent 4d599a4b
...@@ -432,25 +432,7 @@ Polymer({ ...@@ -432,25 +432,7 @@ Polymer({
} }
if (supportedInputMethods) { if (supportedInputMethods) {
// Populate the hash map of supported input methods. this.createInputMethodModel_(supportedInputMethods);
for (let j = 0; j < supportedInputMethods.length; j++) {
const inputMethod = supportedInputMethods[j];
inputMethod.enabled = !!inputMethod.enabled;
inputMethod.isProhibitedByPolicy = !!inputMethod.isProhibitedByPolicy;
// Add the input method to the map of IDs.
this.supportedInputMethodMap_.set(inputMethod.id, inputMethod);
// Add the input method to the list of input methods for each language
// it supports.
for (let k = 0; k < inputMethod.languageCodes.length; k++) {
const languageCode = inputMethod.languageCodes[k];
if (!this.supportedLanguageMap_.has(languageCode))
continue;
if (!this.languageInputMethods_.has(languageCode))
this.languageInputMethods_.set(languageCode, [inputMethod]);
else
this.languageInputMethods_.get(languageCode).push(inputMethod);
}
}
} }
let prospectiveUILanguage; let prospectiveUILanguage;
...@@ -492,6 +474,37 @@ Polymer({ ...@@ -492,6 +474,37 @@ Polymer({
this._setLanguages(model); this._setLanguages(model);
}, },
/**
* Constructs the input method part of the languages model.
* @param {!Array<!chrome.languageSettingsPrivate.InputMethod>}
* supportedInputMethods Input methods.
* @private
*/
createInputMethodModel_: function(supportedInputMethods) {
assert(cr.isChromeOS);
// Populate the hash map of supported input methods.
this.supportedInputMethodMap_.clear();
this.languageInputMethods_.clear();
for (let j = 0; j < supportedInputMethods.length; j++) {
const inputMethod = supportedInputMethods[j];
inputMethod.enabled = !!inputMethod.enabled;
inputMethod.isProhibitedByPolicy = !!inputMethod.isProhibitedByPolicy;
// Add the input method to the map of IDs.
this.supportedInputMethodMap_.set(inputMethod.id, inputMethod);
// Add the input method to the list of input methods for each language
// it supports.
for (let k = 0; k < inputMethod.languageCodes.length; k++) {
const languageCode = inputMethod.languageCodes[k];
if (!this.supportedLanguageMap_.has(languageCode))
continue;
if (!this.languageInputMethods_.has(languageCode))
this.languageInputMethods_.set(languageCode, [inputMethod]);
else
this.languageInputMethods_.get(languageCode).push(inputMethod);
}
}
},
/** /**
* Returns a list of LanguageStates for each enabled language in the supported * Returns a list of LanguageStates for each enabled language in the supported
* languages list. * languages list.
...@@ -606,6 +619,23 @@ Polymer({ ...@@ -606,6 +619,23 @@ Polymer({
}); });
}, },
/** @private */
updateSupportedInputMethods_: function() {
assert(cr.isChromeOS);
const promise = new Promise(resolve => {
this.languageSettingsPrivate_.getInputMethodLists(function(lists) {
resolve(
lists.componentExtensionImes.concat(lists.thirdPartyExtensionImes));
});
});
promise.then(result => {
const supportedInputMethods = result;
this.createInputMethodModel_(supportedInputMethods);
this.set('languages.inputMethods.supported', supportedInputMethods);
this.updateEnabledInputMethods_();
});
},
/** @private */ /** @private */
updateEnabledInputMethods_: function() { updateEnabledInputMethods_: function() {
assert(cr.isChromeOS); assert(cr.isChromeOS);
...@@ -950,12 +980,12 @@ Polymer({ ...@@ -950,12 +980,12 @@ Polymer({
/** @param {string} id Added input method ID. */ /** @param {string} id Added input method ID. */
onInputMethodAdded_: function(id) { onInputMethodAdded_: function(id) {
this.updateEnabledInputMethods_(); this.updateSupportedInputMethods_();
}, },
/** @param {string} id Removed input method ID. */ /** @param {string} id Removed input method ID. */
onInputMethodRemoved_: function(id) { onInputMethodRemoved_: function(id) {
this.updateEnabledInputMethods_(); this.updateSupportedInputMethods_();
}, },
// </if> // </if>
}); });
......
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