Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chrome/browser/resources/settings/languages_page/languages.js

Issue 2827553002: MD Settings: Use a browser proxy from the languages page. Re-enable test. (Closed)
Patch Set: Make inputMethodPrivate CrOS only Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 * PromiseResolver to be resolved when the singleton has been initialized. 71 * PromiseResolver to be resolved when the singleton has been initialized.
72 * @private {!PromiseResolver} 72 * @private {!PromiseResolver}
73 */ 73 */
74 resolver_: { 74 resolver_: {
75 type: Object, 75 type: Object,
76 value: function() { 76 value: function() {
77 return new PromiseResolver(); 77 return new PromiseResolver();
78 }, 78 },
79 }, 79 },
80 80
81 /** @type {!LanguageSettingsPrivate} */
82 languageSettingsPrivate: Object,
83
84 /** @type {!InputMethodPrivate} */
85 inputMethodPrivate: Object,
86
87 /** 81 /**
88 * Hash map of supported languages by language codes for fast lookup. 82 * Hash map of supported languages by language codes for fast lookup.
89 * @private {!Map<string, !chrome.languageSettingsPrivate.Language>} 83 * @private {!Map<string, !chrome.languageSettingsPrivate.Language>}
90 */ 84 */
91 supportedLanguageMap_: { 85 supportedLanguageMap_: {
92 type: Object, 86 type: Object,
93 value: function() { return new Map(); }, 87 value: function() { return new Map(); },
94 }, 88 },
95 89
96 /** 90 /**
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Observe Chrome OS prefs (ignored for non-Chrome OS). 135 // Observe Chrome OS prefs (ignored for non-Chrome OS).
142 'updateRemovableLanguages_(' + 136 'updateRemovableLanguages_(' +
143 'prefs.settings.language.preload_engines.value, ' + 137 'prefs.settings.language.preload_engines.value, ' +
144 'prefs.settings.language.enabled_extension_imes.value, ' + 138 'prefs.settings.language.enabled_extension_imes.value, ' +
145 'languages)', 139 'languages)',
146 ], 140 ],
147 141
148 /** @private {?Function} */ 142 /** @private {?Function} */
149 boundOnInputMethodChanged_: null, 143 boundOnInputMethodChanged_: null,
150 144
145 /** @private {?settings.LanguagesBrowserProxy} */
146 browserProxy_: null,
147
148 /** @type {?LanguageSettingsPrivate} */
149 languageSettingsPrivate: null,
150
151 /** @override */ 151 /** @override */
152 attached: function() { 152 attached: function() {
153 this.browserProxy_ = settings.LanguagesBrowserProxyImpl.getInstance();
153 this.languageSettingsPrivate = 154 this.languageSettingsPrivate =
154 settings.languageSettingsPrivateApiForTest || 155 this.browserProxy_.getLanguageSettingsPrivate();
155 /** @type {!LanguageSettingsPrivate} */(chrome.languageSettingsPrivate);
156
157 this.inputMethodPrivate =
158 settings.inputMethodPrivateApiForTest ||
159 /** @type {!InputMethodPrivate} */(chrome.inputMethodPrivate);
160 156
161 var promises = []; 157 var promises = [];
162 158
163 // Wait until prefs are initialized before creating the model, so we can 159 // Wait until prefs are initialized before creating the model, so we can
164 // include information about enabled languages. 160 // include information about enabled languages.
165 promises[0] = CrSettingsPrefs.initialized; 161 promises[0] = CrSettingsPrefs.initialized;
166 162
167 // Get the language list. 163 // Get the language list.
168 promises[1] = new Promise(function(resolve) { 164 promises[1] = new Promise(function(resolve) {
169 this.languageSettingsPrivate.getLanguageList(resolve); 165 this.languageSettingsPrivate.getLanguageList(resolve);
170 }.bind(this)); 166 }.bind(this));
171 167
172 // Get the translate target language. 168 // Get the translate target language.
173 promises[2] = new Promise(function(resolve) { 169 promises[2] = new Promise(function(resolve) {
174 this.languageSettingsPrivate.getTranslateTargetLanguage(resolve); 170 this.languageSettingsPrivate.getTranslateTargetLanguage(resolve);
175 }.bind(this)); 171 }.bind(this));
176 172
177 if (cr.isChromeOS) { 173 if (cr.isChromeOS) {
178 promises[3] = new Promise(function(resolve) { 174 promises[3] = new Promise(function(resolve) {
179 this.languageSettingsPrivate.getInputMethodLists(function(lists) { 175 this.languageSettingsPrivate.getInputMethodLists(function(lists) {
180 resolve(lists.componentExtensionImes.concat( 176 resolve(lists.componentExtensionImes.concat(
181 lists.thirdPartyExtensionImes)); 177 lists.thirdPartyExtensionImes));
182 }); 178 });
183 }.bind(this)); 179 }.bind(this));
184 180
185 promises[4] = new Promise(function(resolve) { 181 promises[4] = new Promise(function(resolve) {
186 this.inputMethodPrivate.getCurrentInputMethod(resolve); 182 this.browserProxy_.getInputMethodPrivate().
183 getCurrentInputMethod(resolve);
187 }.bind(this)); 184 }.bind(this));
188 } 185 }
189 186
190 if (cr.isWindows || cr.isChromeOS) { 187 if (cr.isWindows || cr.isChromeOS) {
191 // Fetch the starting UI language, which affects which actions should be 188 // Fetch the starting UI language, which affects which actions should be
192 // enabled. 189 // enabled.
193 promises.push(cr.sendWithPromise('getProspectiveUILanguage').then( 190 promises.push(this.browserProxy_.getProspectiveUILanguage().then(
194 function(prospectiveUILanguage) { 191 function(prospectiveUILanguage) {
195 this.originalProspectiveUILanguage_ = 192 this.originalProspectiveUILanguage_ =
196 prospectiveUILanguage || window.navigator.language; 193 prospectiveUILanguage || window.navigator.language;
197 }.bind(this))); 194 }.bind(this)));
198 } 195 }
199 196
200 Promise.all(promises).then(function(results) { 197 Promise.all(promises).then(function(results) {
201 if (!this.isConnected) { 198 if (!this.isConnected) {
202 // Return early if this element was detached from the DOM before this 199 // Return early if this element was detached from the DOM before this
203 // async callback executes (can happen during testing). 200 // async callback executes (can happen during testing).
204 return; 201 return;
205 } 202 }
206 203
207 this.createModel_(results[1], results[2], results[3], results[4]); 204 this.createModel_(results[1], results[2], results[3], results[4]);
208 this.resolver_.resolve(); 205 this.resolver_.resolve();
209 }.bind(this)); 206 }.bind(this));
210 207
211 if (cr.isChromeOS) { 208 if (cr.isChromeOS) {
212 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this); 209 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this);
213 this.inputMethodPrivate.onChanged.addListener( 210 this.browserProxy_.getInputMethodPrivate().onChanged.addListener(
214 assert(this.boundOnInputMethodChanged_)); 211 assert(this.boundOnInputMethodChanged_));
215 } 212 }
216 }, 213 },
217 214
218 /** @override */ 215 /** @override */
219 detached: function() { 216 detached: function() {
220 if (cr.isChromeOS) { 217 if (cr.isChromeOS) {
221 this.inputMethodPrivate.onChanged.removeListener( 218 this.browserProxy_.getInputMethodPrivate().onChanged.removeListener(
222 assert(this.boundOnInputMethodChanged_)); 219 assert(this.boundOnInputMethodChanged_));
223 this.boundOnInputMethodChanged_ = null; 220 this.boundOnInputMethodChanged_ = null;
224 } 221 }
225 }, 222 },
226 223
227 /** 224 /**
228 * Updates the prospective UI language based on the new pref value. 225 * Updates the prospective UI language based on the new pref value.
229 * @param {string} prospectiveUILanguage 226 * @param {string} prospectiveUILanguage
230 * @private 227 * @private
231 */ 228 */
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // TODO(michaelpg): replace duplicate docs with @override once b/24294625 475 // TODO(michaelpg): replace duplicate docs with @override once b/24294625
479 // is fixed. 476 // is fixed.
480 477
481 /** @return {!Promise} */ 478 /** @return {!Promise} */
482 whenReady: function() { 479 whenReady: function() {
483 return this.resolver_.promise; 480 return this.resolver_.promise;
484 }, 481 },
485 482
486 // <if expr="chromeos or is_win"> 483 // <if expr="chromeos or is_win">
487 /** 484 /**
488 * Sets the prospective UI language to the chosen language. This won't affect
489 * the actual UI language until a restart.
490 * @param {string} languageCode
491 */
492 setProspectiveUILanguage: function(languageCode) {
493 chrome.send('setProspectiveUILanguage', [languageCode]);
494 },
495
496 /**
497 * True if the prospective UI language was changed from its starting value. 485 * True if the prospective UI language was changed from its starting value.
498 * @return {boolean} 486 * @return {boolean}
499 */ 487 */
500 requiresRestart: function() { 488 requiresRestart: function() {
501 return this.originalProspectiveUILanguage_ != 489 return this.originalProspectiveUILanguage_ !=
502 this.languages.prospectiveUILanguage; 490 this.languages.prospectiveUILanguage;
503 }, 491 },
504 // </if> 492 // </if>
505 493
506 /** 494 /**
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 this.languageSettingsPrivate.addInputMethod(id); 723 this.languageSettingsPrivate.addInputMethod(id);
736 }, 724 },
737 725
738 /** @param {string} id */ 726 /** @param {string} id */
739 removeInputMethod: function(id) { 727 removeInputMethod: function(id) {
740 if (!this.supportedInputMethodMap_.has(id)) 728 if (!this.supportedInputMethodMap_.has(id))
741 return; 729 return;
742 this.languageSettingsPrivate.removeInputMethod(id); 730 this.languageSettingsPrivate.removeInputMethod(id);
743 }, 731 },
744 732
745 /** @param {string} id */
746 setCurrentInputMethod: function(id) {
747 this.inputMethodPrivate.setCurrentInputMethod(id);
748 },
749
750 /** 733 /**
751 * @param {string} languageCode 734 * @param {string} languageCode
752 * @return {!Array<!chrome.languageSettingsPrivate.InputMethod>} 735 * @return {!Array<!chrome.languageSettingsPrivate.InputMethod>}
753 */ 736 */
754 getInputMethodsForLanguage: function(languageCode) { 737 getInputMethodsForLanguage: function(languageCode) {
755 return this.languageInputMethods_.get(languageCode) || []; 738 return this.languageInputMethods_.get(languageCode) || [];
756 }, 739 },
757 740
758 /** 741 /**
759 * @param {!chrome.languageSettingsPrivate.InputMethod} inputMethod 742 * @param {!chrome.languageSettingsPrivate.InputMethod} inputMethod
760 * @return {boolean} 743 * @return {boolean}
761 */ 744 */
762 isComponentIme: function(inputMethod) { 745 isComponentIme: function(inputMethod) {
763 return inputMethod.id.startsWith('_comp_'); 746 return inputMethod.id.startsWith('_comp_');
764 }, 747 },
765 748
766 /** @param {string} id Input method ID. */
767 openInputMethodOptions: function(id) {
768 this.inputMethodPrivate.openOptionsPage(id);
769 },
770
771 /** @param {string} id New current input method ID. */ 749 /** @param {string} id New current input method ID. */
772 onInputMethodChanged_: function(id) { 750 onInputMethodChanged_: function(id) {
773 this.set('languages.inputMethods.currentId', id); 751 this.set('languages.inputMethods.currentId', id);
774 }, 752 },
775 753
776 /** @param {string} id Added input method ID. */ 754 /** @param {string} id Added input method ID. */
777 onInputMethodAdded_: function(id) { 755 onInputMethodAdded_: function(id) {
778 this.updateEnabledInputMethods_(); 756 this.updateEnabledInputMethods_();
779 }, 757 },
780 758
781 /** @param {string} id Removed input method ID. */ 759 /** @param {string} id Removed input method ID. */
782 onInputMethodRemoved_: function(id) { 760 onInputMethodRemoved_: function(id) {
783 this.updateEnabledInputMethods_(); 761 this.updateEnabledInputMethods_();
784 }, 762 },
785 // </if> 763 // </if>
786 }); 764 });
787 })(); 765 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698