Bug 943339 - Part 1: Only store a subset of session history entries to file. r=Yoric

This commit is contained in:
Emanuel Hoogeveen 2014-02-06 20:15:59 -05:00
parent 2e3a80c115
commit d786f24933
4 changed files with 35 additions and 3 deletions

View File

@ -858,6 +858,10 @@ pref("browser.sessionstore.max_windows_undo", 3);
// number of crashes that can occur before the about:sessionrestore page is displayed
// (this pref has no effect if more than 6 hours have passed since the last crash)
pref("browser.sessionstore.max_resumed_crashes", 1);
// number of back button session history entries to restore (-1 = all of them)
pref("browser.sessionstore.max_serialize_back", 10);
// number of forward button session history entries to restore (-1 = all of them)
pref("browser.sessionstore.max_serialize_forward", -1);
// restore_on_demand overrides MAX_CONCURRENT_TAB_RESTORES (sessionstore constant)
// and restore_hidden_tabs. When true, tabs will not be restored until they are
// focused (also applies to tabs that aren't visible). When false, the values

View File

@ -70,8 +70,26 @@ let SessionHistoryInternal = {
let history = webNavigation.sessionHistory;
if (history && history.count > 0) {
let oldest;
let maxSerializeBack =
Services.prefs.getIntPref("browser.sessionstore.max_serialize_back");
if (maxSerializeBack >= 0) {
oldest = Math.max(0, history.index - maxSerializeBack);
} else { // History.getEntryAtIndex(0, ...) is the oldest.
oldest = 0;
}
let newest;
let maxSerializeFwd =
Services.prefs.getIntPref("browser.sessionstore.max_serialize_forward");
if (maxSerializeFwd >= 0) {
newest = Math.min(history.count - 1, history.index + maxSerializeFwd);
} else { // History.getEntryAtIndex(history.count - 1, ...) is the newest.
newest = history.count - 1;
}
try {
for (let i = 0; i < history.count; i++) {
for (let i = oldest; i <= newest; i++) {
let shEntry = history.getEntryAtIndex(i, false);
let entry = this.serializeEntry(shEntry, isPinned);
data.entries.push(entry);
@ -85,8 +103,9 @@ let SessionHistoryInternal = {
"for the focused window/tab. See bug 669196.");
}
// Ensure the index isn't out of bounds if an exception was thrown above.
data.index = Math.min(history.index + 1, data.entries.length);
// Set the one-based index of the currently active tab,
// ensuring it isn't out of bounds if an exception was thrown above.
data.index = Math.min(history.index - oldest + 1, data.entries.length);
}
// If either the session history isn't available yet or doesn't have any

View File

@ -9,6 +9,14 @@ function test() {
const baseURL = "http://mochi.test:8888/browser/" +
"browser/components/sessionstore/test/browser_447951_sample.html#";
// Make sure the functionality added in bug 943339 doesn't affect the results
gPrefService.setIntPref("browser.sessionstore.max_serialize_back", -1);
gPrefService.setIntPref("browser.sessionstore.max_serialize_forward", -1);
registerCleanupFunction(function () {
gPrefService.clearUserPref("browser.sessionstore.max_serialize_back");
gPrefService.clearUserPref("browser.sessionstore.max_serialize_forward");
});
let tab = gBrowser.addTab();
whenBrowserLoaded(tab.linkedBrowser, function() {
let tabState = { entries: [] };

View File

@ -63,6 +63,7 @@ interface nsISHistory: nsISupports
* given index.
*
* @param index The index value whose entry is requested.
* The oldest entry is located at index == 0.
* @param modifyIndex A boolean flag that indicates if the current
* index of session history should be modified
* to the parameter index.