Bug 656923 - Tab opened on command-line is in the background behind restored tabs [r=mfinkle]

This commit is contained in:
Matt Brubeck 2011-05-14 14:11:44 -07:00
parent 68f62f2dc5
commit 476633268b
3 changed files with 25 additions and 22 deletions

View File

@ -339,24 +339,26 @@ var Browser = {
// Should we restore the previous session (crash or some other event)
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
if (ss.shouldRestore()) {
// Initial window resizes call functions that assume a tab is in the tab list
// and restored tabs are added too late. We add a dummy to to satisfy the resize
// code and then remove the dummy after the session has been restored.
let dummy = this.addTab("about:blank");
let dummyCleanup = {
observe: function() {
Services.obs.removeObserver(dummyCleanup, "sessionstore-windows-restored");
dummy.chromeTab.ignoreUndo = true;
Browser.closeTab(dummy, { forceClose: true });
}
};
Services.obs.addObserver(dummyCleanup, "sessionstore-windows-restored", false);
ss.restoreLastSession();
// Also open any commandline URLs, except the homepage
if (commandURL && commandURL != this.getHomePage())
let bringFront = false;
// First open any commandline URLs, except the homepage
if (commandURL && commandURL != this.getHomePage()) {
this.addTab(commandURL, true);
} else {
bringFront = true;
// Initial window resizes call functions that assume a tab is in the tab list
// and restored tabs are added too late. We add a dummy to to satisfy the resize
// code and then remove the dummy after the session has been restored.
let dummy = this.addTab("about:blank");
let dummyCleanup = {
observe: function() {
Services.obs.removeObserver(dummyCleanup, "sessionstore-windows-restored");
dummy.chromeTab.ignoreUndo = true;
Browser.closeTab(dummy, { forceClose: true });
}
};
Services.obs.addObserver(dummyCleanup, "sessionstore-windows-restored", false);
}
ss.restoreLastSession(bringFront);
} else {
this.addTab(commandURL || this.getHomePage(), true);
}

View File

@ -47,7 +47,7 @@ interface nsIDOMNode;
* tabs contained in them.
*/
[scriptable, uuid(a0a52a85-4032-41d7-b183-9d21009e0a65)]
[scriptable, uuid(766a09c1-d21b-4bf8-9fe3-8b34b716251a)]
interface nsISessionStore : nsISupports
{
/**
@ -109,7 +109,8 @@ interface nsISessionStore : nsISupports
boolean shouldRestore();
/**
* Restores the previous browser session using a fast, lightweight strategy
* Restores the previous browser session using a fast, lightweight strategy
* @param aBringToFront should a restored tab be brought to the foreground?
*/
void restoreLastSession();
void restoreLastSession(in boolean aBringToFront);
};

View File

@ -634,7 +634,7 @@ SessionStore.prototype = {
return this._shouldRestore;
},
restoreLastSession: function ss_restoreLastSession() {
restoreLastSession: function ss_restoreLastSession(aBringToFront) {
// The previous session data has already been renamed to the backup file
let dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
let session = dirService.get("ProfD", Ci.nsILocalFile);
@ -690,7 +690,7 @@ SessionStore.prototype = {
// We must have selected tabs as soon as possible, so we let all tabs be selected
// until we get the real selected tab. Then we stop selecting tabs. The end result
// is that the right tab is selected, but we also don't get a bunch of errors
let bringToFront = (i + 1 <= selected);
let bringToFront = (i + 1 <= selected) && aBringToFront;
let tab = window.Browser.addTab(tabData.entries[0].url, bringToFront, null, params);
// Recreate the thumbnail if we are delay loading the tab