Bug 1052387 - Don't save session history if clearing history on exit. r=bnicholson

This commit is contained in:
Wes Johnston 2014-08-21 11:35:16 -07:00
parent 5c9e9bd1fd
commit d04881178e
4 changed files with 49 additions and 7 deletions

View File

@ -450,11 +450,29 @@ public abstract class GeckoApp
try {
clearObj.put(clear, true);
} catch(JSONException ex) {
Log.i(LOGTAG, "Error adding clear object " + clear);
Log.e(LOGTAG, "Error adding clear object " + clear, ex);
}
}
GeckoAppShell.notifyGeckoOfEvent(GeckoEvent.createBroadcastEvent("Browser:Quit", clearObj.toString()));
final JSONObject res = new JSONObject();
try {
res.put("sanitize", clearObj);
} catch(JSONException ex) {
Log.e(LOGTAG, "Error adding sanitize object", ex);
}
// If the user has opted out of session restore, and does want to clear history
// we also want to prevent the current session info from being saved.
if (clearObj.has("private.data.history")) {
final String sessionRestore = getSessionRestorePreference();
try {
res.put("dontSaveSession", "quit".equals(sessionRestore));
} catch(JSONException ex) {
Log.e(LOGTAG, "Error adding session restore data", ex);
}
}
GeckoAppShell.notifyGeckoOfEvent(GeckoEvent.createBroadcastEvent("Browser:Quit", res.toString()));
} else {
GeckoAppShell.systemExit();
}

View File

@ -1124,7 +1124,7 @@ var BrowserApp = {
aTab.browser.dispatchEvent(evt);
},
quit: function quit(aClear = {}) {
quit: function quit(aClear = { sanitize: {}, dontSaveSession: false }) {
// Figure out if there's at least one other browser window around.
let lastBrowser = true;
let e = Services.wm.getEnumerator("navigator:browser");
@ -1144,7 +1144,13 @@ var BrowserApp = {
Services.obs.notifyObservers(null, "browser-lastwindow-close-granted", null);
}
BrowserApp.sanitize(aClear, function() {
// Tell session store to forget about this window
if (aClear.dontSaveSession) {
let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
ss.removeWindow(window);
}
BrowserApp.sanitize(aClear.sanitize, function() {
window.QueryInterface(Ci.nsIDOMChromeWindow).minimize();
window.close();
});

View File

@ -14,7 +14,7 @@ interface nsIDOMNode;
* tabs contained in them.
*/
[scriptable, uuid(5497d9a1-c378-47a9-9488-4c47a644131a)]
[scriptable, uuid(da9ffc70-d444-47d4-b4ab-df3fb0fd24d0)]
interface nsISessionStore : nsISupports
{
/**
@ -76,4 +76,11 @@ interface nsISessionStore : nsISupports
* backup session file is read from.
*/
void restoreLastSession(in AString aSessionString);
/**
* Removes a window from the current session history. Data from this window
* won't be saved when its closed.
* @param aWindow The window to remove
*/
void removeWindow(in nsIDOMWindow aWindow);
};

View File

@ -453,7 +453,7 @@ SessionStore.prototype = {
// indicate that there is no private data
sendMessageToJava({
type: "PrivateBrowsing:Data",
session: (privateData.windows[0].tabs.length > 0) ? JSON.stringify(privateData) : null
session: (privateData.windows.length > 0 && privateData.windows[0].tabs.length > 0) ? JSON.stringify(privateData) : null
});
this._lastSaveTime = Date.now();
@ -997,7 +997,18 @@ SessionStore.prototype = {
}
Services.obs.notifyObservers(null, "sessionstore-windows-restored", notifyMessage);
})
}),
removeWindow: function ss_removeWindow(aWindow) {
if (!aWindow || !aWindow.__SSID || !this._windows[aWindow.__SSID])
return;
delete this._windows[aWindow.__SSID];
delete aWindow.__SSID;
this.saveState();
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SessionStore]);