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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/languages_page/languages.js
diff --git a/chrome/browser/resources/settings/languages_page/languages.js b/chrome/browser/resources/settings/languages_page/languages.js
index e713a9642280fe49613e9ef812ae238b7a5a628a..40d9eb021d8466609e68b61b6c0b6cf7abe29262 100644
--- a/chrome/browser/resources/settings/languages_page/languages.js
+++ b/chrome/browser/resources/settings/languages_page/languages.js
@@ -145,8 +145,11 @@ Polymer({
'languages)',
],
+ /** @private {?Function} */
+ boundOnInputMethodChanged_: null,
+
/** @override */
- created: function() {
+ attached: function() {
michaelpg 2017/03/28 20:30:10 Is there a way to do this without waiting for |att
this.languageSettingsPrivate =
settings.languageSettingsPrivateApiForTest ||
/** @type {!LanguageSettingsPrivate} */(chrome.languageSettingsPrivate);
@@ -195,13 +198,29 @@ Polymer({
}
Promise.all(promises).then(function(results) {
+ if (!this.isConnected) {
+ // Return early if this element was detached from the DOM before this
+ // async callback executes (can happen during testing).
+ return;
+ }
+
this.createModel_(results[1], results[2], results[3], results[4]);
this.resolver_.resolve();
}.bind(this));
if (cr.isChromeOS) {
+ this.boundOnInputMethodChanged_ = this.onInputMethodChanged_.bind(this);
this.inputMethodPrivate.onChanged.addListener(
- this.onInputMethodChanged_.bind(this));
+ assert(this.boundOnInputMethodChanged_));
+ }
+ },
+
+ /** @override */
+ detached: function() {
+ if (cr.isChromeOS) {
+ this.inputMethodPrivate.onChanged.removeListener(
+ assert(this.boundOnInputMethodChanged_));
+ this.boundOnInputMethodChanged_ = null;
}
},
« 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