Skip to content

Commit

Permalink
Simplify: override PrivacyFilter.filterPrivateWindowsAndTabs()
Browse files Browse the repository at this point in the history
Note: frozen PrivacyFilter cannot be changed, so we alter link to PrivacyFilter in PrivacyFilter.jsm scope
(#146)
  • Loading branch information
Infocatcher committed Aug 11, 2014
1 parent b529a91 commit 5bc5caf
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1586,34 +1586,22 @@ var privateTab = {
// -> SessionStore.getCurrentState()
// -> PrivacyFilter.filterPrivateWindowsAndTabs()
// -> SessionSaverInternal._writeState()
// 1. We can't modify frozen PrivacyFilter object.
// 2. We can override PrivacyFilter in SessionSaver scope, but any change around
// windowState._closedTabs also change real undo close list.
// 3. So, we can alter SessionStoreInternal.getCurrentState() function (and return
// modified shallow copy of state object).

var ssGlobal = Components.utils.import("resource://app/modules/sessionstore/SessionSaver.jsm", {});
// Note: we can't modify frozen PrivacyFilter object!
_log("dontSaveClosedPrivateTabs(" + dontSave + ")");
var {SessionStoreInternal} = Components.utils.import("resource://app/modules/sessionstore/SessionStore.jsm", {});
var meth = "getCurrentState";
var key = "SessionStoreInternal.getCurrentState";
if(dontSave) {
var _this = this;
var getCurrentState = SessionStoreInternal.getCurrentState;
patcher.wrapFunction(
SessionStoreInternal, meth, key,
function before() {
var state = getCurrentState.apply(this, arguments);
if(!state.windows) {
_dbgv && _log("dontSaveClosedPrivateTabs(): missing state.windows!");
return { value: state };
}
var PrivacyFilter = ssGlobal._privateTabOrigPrivacyFilter = ssGlobal.PrivacyFilter;
ssGlobal.PrivacyFilter = {
__proto__: PrivacyFilter,
filterPrivateWindowsAndTabs: function(browserState) {
function shallowCopy(o) {
var out = {};
for(var p in o)
out[p] = o[p];
return out;
}
state.windows.forEach(function(windowState, i) {
browserState.windows.forEach(function(windowState, i) {
if(!windowState.isPrivate && windowState._closedTabs) {
var windowChanged = false;
var closedTabs = windowState._closedTabs.filter(function(closedTabState) {
Expand All @@ -1626,17 +1614,18 @@ var privateTab = {
if(windowChanged) {
var clonedWindowState = shallowCopy(windowState);
clonedWindowState._closedTabs = closedTabs;
state.windows[i] = clonedWindowState;
browserState.windows[i] = clonedWindowState;
_dbgv && _log("dontSaveClosedPrivateTabs(): cleanup windowState._closedTabs");
}
}
});
return { value: state };
return PrivacyFilter.filterPrivateWindowsAndTabs.apply(this, arguments);
}
);
};
}
else {
patcher.unwrapFunction(SessionStoreInternal, meth, key, true);
ssGlobal.PrivacyFilter = ssGlobal._privateTabOrigPrivacyFilter;
delete ssGlobal._privateTabOrigPrivacyFilter;
}
},
tabSelectHandler: function(e) {
Expand Down

0 comments on commit 5bc5caf

Please sign in to comment.