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

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

Issue 2779873003: MD Settings: Prevent <settings-languages> running init code after is detached. (Closed)
Patch Set: Fix 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 'prefs.translate_blocked_languages.value.*, languages)', 138 'prefs.translate_blocked_languages.value.*, languages)',
139 'updateRemovableLanguages_(' + 139 'updateRemovableLanguages_(' +
140 'prefs.intl.app_locale.value, languages.enabled)', 140 'prefs.intl.app_locale.value, languages.enabled)',
141 // Observe Chrome OS prefs (ignored for non-Chrome OS). 141 // Observe Chrome OS prefs (ignored for non-Chrome OS).
142 'updateRemovableLanguages_(' + 142 'updateRemovableLanguages_(' +
143 'prefs.settings.language.preload_engines.value, ' + 143 'prefs.settings.language.preload_engines.value, ' +
144 'prefs.settings.language.enabled_extension_imes.value, ' + 144 'prefs.settings.language.enabled_extension_imes.value, ' +
145 'languages)', 145 'languages)',
146 ], 146 ],
147 147
148 /** @private {?Function} */
149 boundOnInputMethodChanged_: null,
150
148 /** @override */ 151 /** @override */
149 created: function() { 152 attached: function() {
michaelpg 2017/03/28 20:30:10 Is there a way to do this without waiting for |att
150 this.languageSettingsPrivate = 153 this.languageSettingsPrivate =
151 settings.languageSettingsPrivateApiForTest || 154 settings.languageSettingsPrivateApiForTest ||
152 /** @type {!LanguageSettingsPrivate} */(chrome.languageSettingsPrivate); 155 /** @type {!LanguageSettingsPrivate} */(chrome.languageSettingsPrivate);
153 156
154 this.inputMethodPrivate = 157 this.inputMethodPrivate =
155 settings.inputMethodPrivateApiForTest || 158 settings.inputMethodPrivateApiForTest ||
156 /** @type {!InputMethodPrivate} */(chrome.inputMethodPrivate); 159 /** @type {!InputMethodPrivate} */(chrome.inputMethodPrivate);
157 160
158 var promises = []; 161 var promises = [];
159 162
(...skipping 28 matching lines...) Expand all
188 // Fetch the starting UI language, which affects which actions should be 191 // Fetch the starting UI language, which affects which actions should be
189 // enabled. 192 // enabled.
190 promises.push(cr.sendWithPromise('getProspectiveUILanguage').then( 193 promises.push(cr.sendWithPromise('getProspectiveUILanguage').then(
191 function(prospectiveUILanguage) { 194 function(prospectiveUILanguage) {
192 this.originalProspectiveUILanguage_ = 195 this.originalProspectiveUILanguage_ =
193 prospectiveUILanguage || window.navigator.language; 196 prospectiveUILanguage || window.navigator.language;
194 }.bind(this))); 197 }.bind(this)));
195 } 198 }
196 199
197 Promise.all(promises).then(function(results) { 200 Promise.all(promises).then(function(results) {
201 if (!this.isConnected) {
202 // Return early if this element was detached from the DOM before this
203 // async callback executes (can happen during testing).
204 return;
205 }
206
198 this.createModel_(results[1], results[2], results[3], results[4]); 207 this.createModel_(results[1], results[2], results[3], results[4]);
199 this.resolver_.resolve(); 208 this.resolver_.resolve();
200 }.bind(this)); 209 }.bind(this));
201 210
202 if (cr.isChromeOS) { 211 if (cr.isChromeOS) {
212 this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this);
203 this.inputMethodPrivate.onChanged.addListener( 213 this.inputMethodPrivate.onChanged.addListener(
204 this.onInputMethodChanged_.bind(this)); 214 assert(this.boundOnInputMethodChanged_));
205 } 215 }
206 }, 216 },
207 217
218 /** @override */
219 detached: function() {
220 if (cr.isChromeOS) {
221 this.inputMethodPrivate.onChanged.removeListener(
222 assert(this.boundOnInputMethodChanged_));
223 this.boundOnInputMethodChanged_ = null;
224 }
225 },
226
208 /** 227 /**
209 * Updates the prospective UI language based on the new pref value. 228 * Updates the prospective UI language based on the new pref value.
210 * @param {string} prospectiveUILanguage 229 * @param {string} prospectiveUILanguage
211 * @private 230 * @private
212 */ 231 */
213 prospectiveUILanguageChanged_: function(prospectiveUILanguage) { 232 prospectiveUILanguageChanged_: function(prospectiveUILanguage) {
214 this.set('languages.prospectiveUILanguage', 233 this.set('languages.prospectiveUILanguage',
215 prospectiveUILanguage || this.originalProspectiveUILanguage_); 234 prospectiveUILanguage || this.originalProspectiveUILanguage_);
216 }, 235 },
217 236
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 this.updateEnabledInputMethods_(); 792 this.updateEnabledInputMethods_();
774 }, 793 },
775 794
776 /** @param {string} id Removed input method ID. */ 795 /** @param {string} id Removed input method ID. */
777 onInputMethodRemoved_: function(id) { 796 onInputMethodRemoved_: function(id) {
778 assert(cr.isChromeOS); 797 assert(cr.isChromeOS);
779 this.updateEnabledInputMethods_(); 798 this.updateEnabledInputMethods_();
780 }, 799 },
781 }); 800 });
782 })(); 801 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698