Bug 648683 - Expose tabs on-demand preference [r=dietrich, r=gavin, ui-r=boriss]

This removes the browser.sessionstore.max_concurrent_tabs integer preference in favor of a boolean preference. This disables the hidden way of disabling cascaded restore.
The new browser.sessionstore.restore_on_demand preference is exposed in the "General" pref pane.
This commit is contained in:
Paul O’Shannessy 2011-08-15 23:24:25 -07:00
Родитель 715befd2db
Коммит 16b4efc787
11 изменённых файлов: 85 добавлений и 59 удалений

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

@ -783,12 +783,12 @@ 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);
// The number of tabs that can restore concurrently:
// < 0 = All tabs can restore at the same time
// 0 = Only the selected tab in each window will be restored
// Other tabs won't be restored until they are selected
// N = The number of tabs to restore at the same time
pref("browser.sessionstore.max_concurrent_tabs", 3);
// 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
// for MAX_CONCURRENT_TAB_RESTORES and restore_hidden_tabs are respected.
// Selected tabs are always restored regardless of this pref.
pref("browser.sessionstore.restore_on_demand", false);
// Whether to automatically restore hidden tabs (i.e., tabs in other tab groups) or not
pref("browser.sessionstore.restore_hidden_tabs", false);

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

@ -35,14 +35,11 @@ function test() {
registerCleanupFunction(function () {
TabsProgressListener.uninit();
Services.prefs.clearUserPref("browser.sessionstore.max_concurrent_tabs");
Services.prefs.clearUserPref("browser.sessionstore.restore_hidden_tabs");
ss.setBrowserState(stateBackup);
});
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 3);
TabView._initFrame(function () {
executeSoon(testRestoreWithHiddenTabs);
});

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

@ -53,6 +53,7 @@ var gMainPane = {
window.addEventListener("focus", this._updateUseCurrentButton, false);
this.updateBrowserStartupLastSession();
this.startupPagePrefChanged();
// Notify observers that the UI is now ready
Components.classes["@mozilla.org/observer-service;1"]
@ -81,6 +82,16 @@ var gMainPane = {
* option is preserved.
*/
/**
* Enables/Disables the restore on demand checkbox.
*/
startupPagePrefChanged: function ()
{
let startupPref = document.getElementById("browser.startup.page");
let restoreOnDemandPref = document.getElementById("browser.sessionstore.restore_on_demand");
restoreOnDemandPref.disabled = startupPref.value != 3;
},
syncFromHomePref: function ()
{
let homePref = document.getElementById("browser.startup.homepage");

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

@ -64,7 +64,11 @@
<!-- Startup -->
<preference id="browser.startup.page"
name="browser.startup.page"
type="int"/>
type="int"
onchange="gMainPane.startupPagePrefChanged();"/>
<preference id="browser.sessionstore.restore_on_demand"
name="browser.sessionstore.restore_on_demand"
type="bool"/>
<preference id="browser.startup.homepage"
name="browser.startup.homepage"
type="wstring"/>
@ -120,6 +124,13 @@
</menupopup>
</menulist>
</hbox>
<hbox align="center">
<checkbox id="restoreOnDemand"
label="&restoreOnDemand.label;"
accesskey="&restoreOnDemand.accesskey;"
class="indent"
preference="browser.sessionstore.restore_on_demand"/>
</hbox>
<separator class="thin"/>
<hbox align="center">
<label value="&homepage.label;" accesskey="&homepage.accesskey;" control="browserHomePage"/>

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

@ -75,6 +75,10 @@ const PRIVACY_FULL = 2;
const NOTIFY_WINDOWS_RESTORED = "sessionstore-windows-restored";
const NOTIFY_BROWSER_STATE_RESTORED = "sessionstore-browser-state-restored";
// Maximum number of tabs to restore simultaneously. Previously controlled by
// the browser.sessionstore.max_concurrent_tabs pref.
const MAX_CONCURRENT_TAB_RESTORES = 3;
// global notifications observed
const OBSERVING = [
"domwindowopened", "domwindowclosed",
@ -229,9 +233,9 @@ SessionStoreService.prototype = {
_tabsToRestore: { visible: [], hidden: [] },
_tabsRestoringCount: 0,
// number of tabs to restore concurrently, pref controlled.
_maxConcurrentTabRestores: null,
// overrides MAX_CONCURRENT_TAB_RESTORES and _restoreHiddenTabs when true
_restoreOnDemand: false,
// whether to restore hidden tabs or not, pref controlled.
_restoreHiddenTabs: null,
@ -281,7 +285,10 @@ SessionStoreService.prototype = {
var pbs = Cc["@mozilla.org/privatebrowsing;1"].
getService(Ci.nsIPrivateBrowsingService);
this._inPrivateBrowsing = pbs.privateBrowsingEnabled;
// Do pref migration before we store any values and start observing changes
this._migratePrefs();
// observe prefs changes so we can modify stored data to match
this._prefBranch.addObserver("sessionstore.max_tabs_undo", this, true);
this._prefBranch.addObserver("sessionstore.max_windows_undo", this, true);
@ -290,9 +297,9 @@ SessionStoreService.prototype = {
this._sessionhistory_max_entries =
this._prefBranch.getIntPref("sessionhistory.max_entries");
this._maxConcurrentTabRestores =
this._prefBranch.getIntPref("sessionstore.max_concurrent_tabs");
this._prefBranch.addObserver("sessionstore.max_concurrent_tabs", this, true);
this._restoreOnDemand =
this._prefBranch.getBoolPref("sessionstore.restore_on_demand");
this._prefBranch.addObserver("sessionstore.restore_on_demand", this, true);
this._restoreHiddenTabs =
this._prefBranch.getBoolPref("sessionstore.restore_hidden_tabs");
@ -443,6 +450,19 @@ SessionStoreService.prototype = {
}
},
_migratePrefs: function sss__migratePrefs() {
// Added For Firefox 8
// max_concurrent_tabs is going away. We're going to hard code a max value
// (MAX_CONCURRENT_TAB_RESTORES) and start using a boolean pref restore_on_demand.
if (this._prefBranch.prefHasUserValue("sessionstore.max_concurrent_tabs") &&
!this._prefBranch.prefHasUserValue("sessionstore.restore_on_demand")) {
let maxConcurrentTabs =
this._prefBranch.getIntPref("sessionstore.max_concurrent_tabs");
this._prefBranch.setBoolPref("sessionstore.restore_on_demand", maxConcurrentTabs == 0);
this._prefBranch.clearUserPref("sessionstore.max_concurrent_tabs");
}
},
/**
* Handle notifications
*/
@ -632,9 +652,9 @@ SessionStoreService.prototype = {
this._clearDisk();
this.saveState(true);
break;
case "sessionstore.max_concurrent_tabs":
this._maxConcurrentTabRestores =
this._prefBranch.getIntPref("sessionstore.max_concurrent_tabs");
case "sessionstore.restore_on_demand":
this._restoreOnDemand =
this._prefBranch.getBoolPref("sessionstore.restore_on_demand");
break;
case "sessionstore.restore_hidden_tabs":
this._restoreHiddenTabs =
@ -2906,7 +2926,7 @@ SessionStoreService.prototype = {
_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap, aDocIdentMap);
}, 0);
// This could cause us to ignore the max_concurrent_tabs pref a bit, but
// This could cause us to ignore MAX_CONCURRENT_TAB_RESTORES a bit, but
// it ensures each window will have its selected tab loaded.
if (aWindow.gBrowser.selectedBrowser == browser) {
this.restoreTab(tab);
@ -3042,8 +3062,8 @@ SessionStoreService.prototype = {
return;
// If it's not possible to restore anything, then just bail out.
if (this._maxConcurrentTabRestores >= 0 &&
this._tabsRestoringCount >= this._maxConcurrentTabRestores)
if (this._restoreOnDemand ||
this._tabsRestoringCount >= MAX_CONCURRENT_TAB_RESTORES)
return;
// Look in visible, then hidden

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

@ -60,7 +60,7 @@ let tests = [test_cascade, test_select, test_multiWindowState,
function runNextTest() {
// Reset the pref
try {
Services.prefs.clearUserPref("browser.sessionstore.max_concurrent_tabs");
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
} catch (e) {}
// set an empty state & run the next test, or finish
@ -88,9 +88,6 @@ function runNextTest() {
function test_cascade() {
// Set the pref to 1 so we know exactly how many tabs should be restoring at any given time
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 1);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {
onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
@ -118,11 +115,11 @@ function test_cascade() {
// before sessionstore has marked the tab as finished restoring and before it
// starts restoring the next tab
let expectedCounts = [
[5, 1, 0],
[4, 1, 1],
[3, 1, 2],
[2, 1, 3],
[1, 1, 4],
[3, 3, 0],
[2, 3, 1],
[1, 3, 2],
[0, 3, 3],
[0, 2, 4],
[0, 1, 5]
];
@ -149,9 +146,9 @@ function test_cascade() {
function test_select() {
// Set the pref to 0 so we know exactly how many tabs should be restoring at
// Set the pref to true so we know exactly how many tabs should be restoring at
// any given time. This guarantees that a finishing load won't start another.
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 0);
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {
@ -298,9 +295,6 @@ function test_multiWindowState() {
function test_setWindowStateNoOverwrite() {
// Set the pref to 1 so we know exactly how many tabs should be restoring at any given time
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 1);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {
onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
@ -370,9 +364,6 @@ function test_setWindowStateNoOverwrite() {
function test_setWindowStateOverwrite() {
// Set the pref to 1 so we know exactly how many tabs should be restoring at any given time
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 1);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {
onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
@ -442,9 +433,6 @@ function test_setWindowStateOverwrite() {
function test_setBrowserStateInterrupted() {
// Set the pref to 1 so we know exactly how many tabs should be restoring at any given time
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 1);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {
onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
@ -561,9 +549,9 @@ function test_setBrowserStateInterrupted() {
function test_reload() {
// Set the pref to 0 so we know exactly how many tabs should be restoring at
// Set the pref to true so we know exactly how many tabs should be restoring at
// any given time. This guarantees that a finishing load won't start another.
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 0);
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {

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

@ -21,7 +21,6 @@ function test() {
waitForExplicitFinish();
registerCleanupFunction(function () {
Services.prefs.clearUserPref("browser.sessionstore.max_concurrent_tabs");
Services.prefs.clearUserPref("browser.sessionstore.restore_hidden_tabs");
TabsProgressListener.uninit();
@ -31,8 +30,6 @@ function test() {
TabsProgressListener.init();
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 3);
// First stage: restoreHiddenTabs = true
// Second stage: restoreHiddenTabs = false
test_loadTabs(true, function () {

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

@ -43,7 +43,7 @@ let stateBackup = ss.getBrowserState();
function cleanup() {
// Reset the pref
try {
Services.prefs.clearUserPref("browser.sessionstore.max_concurrent_tabs");
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
} catch (e) {}
ss.setBrowserState(stateBackup);
executeSoon(finish);
@ -53,9 +53,9 @@ function test() {
/** Bug 599909 - to-be-reloaded tabs don't show up in switch-to-tab **/
waitForExplicitFinish();
// Set the pref to 0 so we know exactly how many tabs should be restoring at
// Set the pref to true so we know exactly how many tabs should be restoring at
// any given time. This guarantees that a finishing load won't start another.
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 0);
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org/#1" }] },

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

@ -43,7 +43,7 @@ let stateBackup = ss.getBrowserState();
function cleanup() {
// Reset the pref
try {
Services.prefs.clearUserPref("browser.sessionstore.max_concurrent_tabs");
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
} catch (e) {}
ss.setBrowserState(stateBackup);
executeSoon(finish);
@ -53,9 +53,9 @@ function test() {
/** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
waitForExplicitFinish();
// Set the pref to 0 so we know exactly how many tabs should be restoring at
// Set the pref to true so we know exactly how many tabs should be restoring at
// any given time. This guarantees that a finishing load won't start another.
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 0);
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
// We have our own progress listener for this test, which we'll attach before our state is set
let progressListener = {

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

@ -13,19 +13,18 @@ let statePinned = {windows:[{tabs:[
let state = {windows:[{tabs:[
{entries:[{url:"http://example.com#1"}]},
{entries:[{url:"http://example.com#2"}]},
{entries:[{url:"http://example.com#3"}]}
{entries:[{url:"http://example.com#3"}]},
{entries:[{url:"http://example.com#4"}]},
]}]};
function test() {
waitForExplicitFinish();
registerCleanupFunction(function () {
Services.prefs.clearUserPref("browser.sessionstore.max_concurrent_tabs");
TabsProgressListener.uninit();
ss.setBrowserState(stateBackup);
});
Services.prefs.setIntPref("browser.sessionstore.max_concurrent_tabs", 2);
TabsProgressListener.init();
@ -37,9 +36,9 @@ function test() {
TabsProgressListener.setCallback(function (needsRestore, isRestoring) {
if (firstProgress) {
firstProgress = false;
is(isRestoring, 2, "restoring 2 tabs concurrently");
is(isRestoring, 3, "restoring 3 tabs concurrently");
} else {
ok(isRestoring < 3, "restoring max. 2 tabs concurrently");
ok(isRestoring <= 3, "restoring max. 2 tabs concurrently");
}
if (0 == needsRestore) {

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

@ -5,6 +5,9 @@
<!ENTITY startupHomePage.label "Show my home page">
<!ENTITY startupBlankPage.label "Show a blank page">
<!ENTITY startupLastSession.label "Show my windows and tabs from last time">
<!ENTITY restoreOnDemand.label "Dont load tabs until selected">
<!ENTITY restoreOnDemand.accesskey "d">
<!ENTITY homepage.label "Home Page:">
<!ENTITY homepage.accesskey "P">
<!ENTITY useCurrentPage.label "Use Current Page">