From 952e65590368931781327d1662061d46fa15ddd2 Mon Sep 17 00:00:00 2001 From: Ascrod <32915892+Ascrod@users.noreply.github.com> Date: Thu, 25 Apr 2019 20:31:18 -0400 Subject: Replace explicit pref observer with lazy preference getters. Tag #361. --- toolkit/components/reader/ReaderMode.jsm | 14 +++++--------- toolkit/components/reader/Readerable.js | 30 ++++++------------------------ 2 files changed, 11 insertions(+), 33 deletions(-) (limited to 'toolkit/components') diff --git a/toolkit/components/reader/ReaderMode.jsm b/toolkit/components/reader/ReaderMode.jsm index ebc333495..030205446 100644 --- a/toolkit/components/reader/ReaderMode.jsm +++ b/toolkit/components/reader/ReaderMode.jsm @@ -38,15 +38,6 @@ this.ReaderMode = { DEBUG: 0, - // Don't try to parse the page if it has too many elements (for memory and - // performance reasons) - get maxElemsToParse() { - delete this.parseNodeLimit; - - Services.prefs.addObserver("reader.parse-node-limit", this, false); - return this.parseNodeLimit = Services.prefs.getIntPref("reader.parse-node-limit"); - }, - /** * Enter the reader mode by going forward one step in history if applicable, * if not, append the about:reader page in the history instead. @@ -548,3 +539,8 @@ this.ReaderMode = { return readingSpeed.get(lang) || readingSpeed.get("en"); }, }; + +// Don't try to parse the page if it has too many elements (for memory and +// performance reasons) +XPCOMUtils.defineLazyPreferenceGetter( + ReaderMode, "maxElemsToParse", "reader.parse-node-limit", 0); diff --git a/toolkit/components/reader/Readerable.js b/toolkit/components/reader/Readerable.js index 71c23eb5b..cee8adc08 100644 --- a/toolkit/components/reader/Readerable.js +++ b/toolkit/components/reader/Readerable.js @@ -23,30 +23,7 @@ var Readerable = { DEBUG: 0, get isEnabledForParseOnLoad() { - delete this.isEnabledForParseOnLoad; - - // Listen for future pref changes. - Services.prefs.addObserver("reader.parse-on-load.", this, false); - - return this.isEnabledForParseOnLoad = this._getStateForParseOnLoad(); - }, - - _getStateForParseOnLoad() { - let isEnabled = Services.prefs.getBoolPref("reader.parse-on-load.enabled"); - let isForceEnabled = Services.prefs.getBoolPref("reader.parse-on-load.force-enabled"); - return isForceEnabled || isEnabled; - }, - - observe(aMessage, aTopic, aData) { - switch (aTopic) { - case "nsPref:changed": - if (aData.startsWith("reader.parse-on-load.")) { - this.isEnabledForParseOnLoad = this._getStateForParseOnLoad(); - } else if (aData === "reader.parse-node-limit") { - this.parseNodeLimit = Services.prefs.getIntPref(aData); - } - break; - } + return this.isEnabled || this.isForceEnabled; }, log(msg) { @@ -112,3 +89,8 @@ var Readerable = { return true; }, }; + +XPCOMUtils.defineLazyPreferenceGetter( + Readerable, "isEnabled", "reader.parse-on-load.enabled", true); +XPCOMUtils.defineLazyPreferenceGetter( + Readerable, "isForceEnabled", "reader.parse-on-load.force-enabled", false); -- cgit v1.2.3