OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview 'settings-languages' handles Chrome's language and input | 6 * @fileoverview 'settings-languages' handles Chrome's language and input |
7 * method settings. The 'languages' property, which reflects the current | 7 * method settings. The 'languages' property, which reflects the current |
8 * language settings, must not be changed directly. Instead, changes to | 8 * language settings, must not be changed directly. Instead, changes to |
9 * language settings should be made using the LanguageHelper APIs provided by | 9 * language settings should be made using the LanguageHelper APIs provided by |
10 * this class via languageHelper. | 10 * this class via languageHelper. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 this.inputMethodPrivate_ = this.browserProxy_.getInputMethodPrivate(); | 173 this.inputMethodPrivate_ = this.browserProxy_.getInputMethodPrivate(); |
174 // </if> | 174 // </if> |
175 | 175 |
176 var promises = []; | 176 var promises = []; |
177 | 177 |
178 // Wait until prefs are initialized before creating the model, so we can | 178 // Wait until prefs are initialized before creating the model, so we can |
179 // include information about enabled languages. | 179 // include information about enabled languages. |
180 promises[0] = CrSettingsPrefs.initialized; | 180 promises[0] = CrSettingsPrefs.initialized; |
181 | 181 |
182 // Get the language list. | 182 // Get the language list. |
183 promises[1] = new Promise(function(resolve) { | 183 promises[1] = new Promise(resolve => { |
184 this.languageSettingsPrivate_.getLanguageList(resolve); | 184 this.languageSettingsPrivate_.getLanguageList(resolve); |
185 }.bind(this)); | 185 }); |
186 | 186 |
187 // Get the translate target language. | 187 // Get the translate target language. |
188 promises[2] = new Promise(function(resolve) { | 188 promises[2] = new Promise(resolve => { |
189 this.languageSettingsPrivate_.getTranslateTargetLanguage(resolve); | 189 this.languageSettingsPrivate_.getTranslateTargetLanguage(resolve); |
190 }.bind(this)); | 190 }); |
191 | 191 |
192 if (cr.isChromeOS) { | 192 if (cr.isChromeOS) { |
193 promises[3] = new Promise(function(resolve) { | 193 promises[3] = new Promise(resolve => { |
194 this.languageSettingsPrivate_.getInputMethodLists(function(lists) { | 194 this.languageSettingsPrivate_.getInputMethodLists(function(lists) { |
195 resolve(lists.componentExtensionImes.concat( | 195 resolve(lists.componentExtensionImes.concat( |
196 lists.thirdPartyExtensionImes)); | 196 lists.thirdPartyExtensionImes)); |
197 }); | 197 }); |
198 }.bind(this)); | 198 }); |
199 | 199 |
200 promises[4] = new Promise(function(resolve) { | 200 promises[4] = new Promise(resolve => { |
201 this.inputMethodPrivate_.getCurrentInputMethod(resolve); | 201 this.inputMethodPrivate_.getCurrentInputMethod(resolve); |
202 }.bind(this)); | 202 }); |
203 } | 203 } |
204 | 204 |
205 if (cr.isWindows || cr.isChromeOS) { | 205 if (cr.isWindows || cr.isChromeOS) { |
206 // Fetch the starting UI language, which affects which actions should be | 206 // Fetch the starting UI language, which affects which actions should be |
207 // enabled. | 207 // enabled. |
208 promises.push(this.browserProxy_.getProspectiveUILanguage().then( | 208 promises.push(this.browserProxy_.getProspectiveUILanguage().then( |
209 function(prospectiveUILanguage) { | 209 prospectiveUILanguage => { |
210 this.originalProspectiveUILanguage_ = | 210 this.originalProspectiveUILanguage_ = |
211 prospectiveUILanguage || window.navigator.language; | 211 prospectiveUILanguage || window.navigator.language; |
212 }.bind(this))); | 212 })); |
213 } | 213 } |
214 | 214 |
215 Promise.all(promises).then(function(results) { | 215 Promise.all(promises).then(results => { |
216 if (!this.isConnected) { | 216 if (!this.isConnected) { |
217 // Return early if this element was detached from the DOM before this | 217 // Return early if this element was detached from the DOM before this |
218 // async callback executes (can happen during testing). | 218 // async callback executes (can happen during testing). |
219 return; | 219 return; |
220 } | 220 } |
221 | 221 |
222 // TODO(dpapad): Cleanup this code. It uses results[3] and results[4] | 222 // TODO(dpapad): Cleanup this code. It uses results[3] and results[4] |
223 // which only exist for ChromeOS. | 223 // which only exist for ChromeOS. |
224 this.createModel_(results[1], results[2], results[3], results[4]); | 224 this.createModel_(results[1], results[2], results[3], results[4]); |
225 this.resolver_.resolve(); | 225 this.resolver_.resolve(); |
226 }.bind(this)); | 226 }); |
227 | 227 |
228 if (cr.isChromeOS) { | 228 if (cr.isChromeOS) { |
229 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this); | 229 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this); |
230 this.inputMethodPrivate_.onChanged.addListener( | 230 this.inputMethodPrivate_.onChanged.addListener( |
231 assert(this.boundOnInputMethodChanged_)); | 231 assert(this.boundOnInputMethodChanged_)); |
232 } | 232 } |
233 }, | 233 }, |
234 | 234 |
235 /** @override */ | 235 /** @override */ |
236 detached: function() { | 236 detached: function() { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 assert(CrSettingsPrefs.isInitialized); | 437 assert(CrSettingsPrefs.isInitialized); |
438 | 438 |
439 var enabledInputMethodIds = | 439 var enabledInputMethodIds = |
440 this.getPref('settings.language.preload_engines').value.split(','); | 440 this.getPref('settings.language.preload_engines').value.split(','); |
441 enabledInputMethodIds = enabledInputMethodIds.concat( | 441 enabledInputMethodIds = enabledInputMethodIds.concat( |
442 this.getPref('settings.language.enabled_extension_imes') | 442 this.getPref('settings.language.enabled_extension_imes') |
443 .value.split(',')); | 443 .value.split(',')); |
444 | 444 |
445 // Return only supported input methods. | 445 // Return only supported input methods. |
446 return enabledInputMethodIds | 446 return enabledInputMethodIds |
447 .map(function(id) { | 447 .map(id => this.supportedInputMethodMap_.get(id)) |
448 return this.supportedInputMethodMap_.get(id); | |
449 }.bind(this)) | |
450 .filter(function(inputMethod) { | 448 .filter(function(inputMethod) { |
451 return !!inputMethod; | 449 return !!inputMethod; |
452 }); | 450 }); |
453 }, | 451 }, |
454 | 452 |
455 /** @private */ | 453 /** @private */ |
456 updateEnabledInputMethods_: function() { | 454 updateEnabledInputMethods_: function() { |
457 assert(cr.isChromeOS); | 455 assert(cr.isChromeOS); |
458 var enabledInputMethods = this.getEnabledInputMethods_(); | 456 var enabledInputMethods = this.getEnabledInputMethods_(); |
459 var enabledInputMethodSet = this.makeSetFromArray_(enabledInputMethods); | 457 var enabledInputMethodSet = this.makeSetFromArray_(enabledInputMethods); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 assert(this.canDisableLanguage(languageCode)); | 556 assert(this.canDisableLanguage(languageCode)); |
559 | 557 |
560 // Remove the language from spell check. | 558 // Remove the language from spell check. |
561 this.deletePrefListItem('spellcheck.dictionaries', languageCode); | 559 this.deletePrefListItem('spellcheck.dictionaries', languageCode); |
562 | 560 |
563 if (cr.isChromeOS) { | 561 if (cr.isChromeOS) { |
564 // Remove input methods that don't support any other enabled language. | 562 // Remove input methods that don't support any other enabled language. |
565 var inputMethods = this.languageInputMethods_.get(languageCode) || []; | 563 var inputMethods = this.languageInputMethods_.get(languageCode) || []; |
566 for (var i = 0; i < inputMethods.length; i++) { | 564 for (var i = 0; i < inputMethods.length; i++) { |
567 var inputMethod = inputMethods[i]; | 565 var inputMethod = inputMethods[i]; |
568 var supportsOtherEnabledLanguages = | 566 var supportsOtherEnabledLanguages = inputMethod.languageCodes.some( |
569 inputMethod.languageCodes.some(function(otherLanguageCode) { | 567 otherLanguageCode => otherLanguageCode != languageCode && |
570 return otherLanguageCode != languageCode && | 568 this.isLanguageEnabled(otherLanguageCode)); |
571 this.isLanguageEnabled(otherLanguageCode); | |
572 }.bind(this)); | |
573 if (!supportsOtherEnabledLanguages) | 569 if (!supportsOtherEnabledLanguages) |
574 this.removeInputMethod(inputMethod.id); | 570 this.removeInputMethod(inputMethod.id); |
575 } | 571 } |
576 } | 572 } |
577 | 573 |
578 // Remove the language from preferred languages. | 574 // Remove the language from preferred languages. |
579 this.languageSettingsPrivate_.disableLanguage(languageCode); | 575 this.languageSettingsPrivate_.disableLanguage(languageCode); |
580 this.enableTranslateLanguage(languageCode); | 576 this.enableTranslateLanguage(languageCode); |
581 }, | 577 }, |
582 | 578 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 this.updateEnabledInputMethods_(); | 799 this.updateEnabledInputMethods_(); |
804 }, | 800 }, |
805 | 801 |
806 /** @param {string} id Removed input method ID. */ | 802 /** @param {string} id Removed input method ID. */ |
807 onInputMethodRemoved_: function(id) { | 803 onInputMethodRemoved_: function(id) { |
808 this.updateEnabledInputMethods_(); | 804 this.updateEnabledInputMethods_(); |
809 }, | 805 }, |
810 // </if> | 806 // </if> |
811 }); | 807 }); |
812 })(); | 808 })(); |
OLD | NEW |