Bug 867875 - Add the pref to toggle reader mode parsing on load. r=mfinkle

This commit is contained in:
Tetsuharu OHZEKI 2013-05-06 12:19:23 -04:00
Родитель f73325c4ae
Коммит 607166e555
2 изменённых файлов: 29 добавлений и 4 удалений

Просмотреть файл

@ -649,8 +649,12 @@ pref("network.manage-offline-status", true);
// increase the timeout clamp for background tabs to 15 minutes
pref("dom.min_background_timeout_value", 900000);
// The default state of reader mode works on loaded a page.
pref("reader.parse-on-load.enabled", true);
// Force to enable reader mode to parse on loaded a page.
// Allow reader mode even on low-memory platforms
pref("reader.force_allow", false);
pref("reader.parse-on-load.force-enabled", false);
// The default of font size in reader (1-7)
pref("reader.font_size", 4);

Просмотреть файл

@ -3277,9 +3277,7 @@ Tab.prototype = {
tabID: this.id
});
// For low-memory devices, don't allow reader mode since it takes up a lot of memory.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=792603 for details.
if (BrowserApp.isOnLowMemoryPlatform && !Services.prefs.getBoolPref("reader.force_allow"))
if (!Reader.isEnabledForParseOnLoad)
return;
// Once document is fully loaded, parse it
@ -6600,12 +6598,18 @@ let Reader = {
// performance reasons)
MAX_ELEMS_TO_PARSE: 3000,
isEnabledForParseOnLoad: false,
init: function Reader_init() {
this.log("Init()");
this._requests = {};
this.isEnabledForParseOnLoad = this.getStateForParseOnLoad();
Services.obs.addObserver(this, "Reader:Add", false);
Services.obs.addObserver(this, "Reader:Remove", false);
Services.prefs.addObserver("reader.parse-on-load.", this, false);
},
observe: function(aMessage, aTopic, aData) {
@ -6681,9 +6685,24 @@ let Reader = {
}.bind(this));
break;
}
case "nsPref:changed": {
if (aData.startsWith("reader.parse-on-load.")) {
this.isEnabledForParseOnLoad = this.getStateForParseOnLoad();
}
break;
}
}
},
getStateForParseOnLoad: function Reader_getStateForParseOnLoad() {
let isEnabled = Services.prefs.getBoolPref("reader.parse-on-load.enabled");
let isForceEnabled = Services.prefs.getBoolPref("reader.parse-on-load.force-enabled");
// For low-memory devices, don't allow reader mode since it takes up a lot of memory.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=792603 for details.
return isForceEnabled || (isEnabled && !BrowserApp.isOnLowMemoryPlatform);
},
parseDocumentFromURL: function Reader_parseDocumentFromURL(url, callback) {
// If there's an on-going request for the same URL, simply append one
// more callback to it to be called when the request is done.
@ -6845,6 +6864,8 @@ let Reader = {
},
uninit: function Reader_uninit() {
Services.prefs.removeObserver("reader.parse-on-load.", this);
Services.obs.removeObserver(this, "Reader:Add");
Services.obs.removeObserver(this, "Reader:Remove");