Bug 903388 - [Session Restore] Collect cookie hosts *after* serializing session history; r=yoric

This commit is contained in:
Tim Taubert 2013-08-10 05:33:07 +02:00
Родитель 1a0e8052c0
Коммит 4402f26b24
1 изменённых файлов: 28 добавлений и 58 удалений

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

@ -304,10 +304,6 @@ let SessionStoreInternal = {
// states for all currently opened windows
_windows: {},
// internal states for all open windows (data we need to associate,
// but not write to disk)
_internalWindows: {},
// states for all recently closed windows
_closedWindows: [],
@ -719,9 +715,6 @@ let SessionStoreInternal = {
// and create its data object
this._windows[aWindow.__SSi] = { tabs: [], selected: 0, _closedTabs: [], busy: false };
// and create its internal data object
this._internalWindows[aWindow.__SSi] = { hosts: {} }
let isPrivateWindow = false;
if (PrivateBrowsingUtils.isWindowPrivate(aWindow))
this._windows[aWindow.__SSi].isPrivate = isPrivateWindow = true;
@ -935,9 +928,7 @@ let SessionStoreInternal = {
winData.title = aWindow.content.document.title || tabbrowser.selectedTab.label;
winData.title = this._replaceLoadingTitle(winData.title, tabbrowser,
tabbrowser.selectedTab);
let windows = {};
windows[aWindow.__SSi] = winData;
this._updateCookies(windows);
this._updateCookies([winData]);
}
#ifndef XP_MACOSX
@ -959,7 +950,6 @@ let SessionStoreInternal = {
// clear this window from the list
delete this._windows[aWindow.__SSi];
delete this._internalWindows[aWindow.__SSi];
// save the state without this window to disk
this.saveStateDelayed();
@ -1055,7 +1045,6 @@ let SessionStoreInternal = {
delete aTab.linkedBrowser.__SS_data;
delete aTab.linkedBrowser.__SS_tabStillLoading;
delete aTab.linkedBrowser.__SS_formDataSaved;
delete aTab.linkedBrowser.__SS_hostSchemeData;
if (aTab.linkedBrowser.__SS_restoreState)
this._resetTabRestoringState(aTab);
});
@ -1065,10 +1054,8 @@ let SessionStoreInternal = {
for (let ix in this._windows) {
if (ix in openWindows) {
this._windows[ix]._closedTabs = [];
}
else {
} else {
delete this._windows[ix];
delete this._internalWindows[ix];
}
}
// also clear all data about closed windows
@ -1225,7 +1212,6 @@ let SessionStoreInternal = {
delete browser.__SS_data;
delete browser.__SS_tabStillLoading;
delete browser.__SS_formDataSaved;
delete browser.__SS_hostSchemeData;
// If this tab was in the middle of restoring or still needs to be restored,
// we need to reset that state. If the tab was restoring, we will attempt to
@ -1981,11 +1967,10 @@ let SessionStoreInternal = {
tabData.index = history.index + 1;
}
else if (history && history.count > 0) {
browser.__SS_hostSchemeData = [];
try {
for (var j = 0; j < history.count; j++) {
let entry = this._serializeHistoryEntry(history.getEntryAtIndex(j, false),
includePrivateData, aTab.pinned, browser.__SS_hostSchemeData);
includePrivateData, aTab.pinned);
tabData.entries.push(entry);
}
// If we make it through the for loop, then we're ok and we should clear
@ -2077,23 +2062,12 @@ let SessionStoreInternal = {
* always return privacy sensitive data (use with care)
* @param aIsPinned
* the tab is pinned and should be treated differently for privacy
* @param aHostSchemeData
* an array of objects with host & scheme keys
* @returns object
*/
_serializeHistoryEntry:
function ssi_serializeHistoryEntry(aEntry, aIncludePrivateData, aIsPinned, aHostSchemeData) {
function ssi_serializeHistoryEntry(aEntry, aIncludePrivateData, aIsPinned) {
var entry = { url: aEntry.URI.spec };
try {
// throwing is expensive, we know that about: pages will throw
if (entry.url.indexOf("about:") != 0)
aHostSchemeData.push({ host: aEntry.URI.host, scheme: aEntry.URI.scheme });
}
catch (ex) {
// We just won't attempt to get cookies for this entry.
}
if (aEntry.title && aEntry.title != entry.url) {
entry.title = aEntry.title;
}
@ -2204,7 +2178,7 @@ let SessionStoreInternal = {
}
children.push(this._serializeHistoryEntry(child, aIncludePrivateData,
aIsPinned, aHostSchemeData));
aIsPinned));
}
}
@ -2425,8 +2399,8 @@ let SessionStoreInternal = {
/**
* Serialize cookie data
* @param aWindows
* JS object containing window data references
* { id: winData, etc. }
* An array of window data objects
* { tabs: [ ... ], etc. }
*/
_updateCookies: function ssi_updateCookies(aWindows) {
function addCookieToHash(aHash, aHost, aPath, aName, aCookie) {
@ -2444,12 +2418,18 @@ let SessionStoreInternal = {
// MAX_EXPIRY should be 2^63-1, but JavaScript can't handle that precision
var MAX_EXPIRY = Math.pow(2, 62);
for (let [id, window] in Iterator(aWindows)) {
for (let window of aWindows) {
window.cookies = [];
let internalWindow = this._internalWindows[id];
if (!internalWindow.hosts)
return;
for (var [host, isPinned] in Iterator(internalWindow.hosts)) {
// Collect all hosts for the current window.
let hosts = {};
window.tabs.forEach(function(tab) {
tab.entries.forEach(function(entry) {
this._extractHostsForCookiesFromEntry(entry, hosts, true, tab.pinned);
}, this);
}, this);
for (var [host, isPinned] in Iterator(hosts)) {
let list;
try {
list = Services.cookies.getCookiesFromHost(host);
@ -2542,20 +2522,24 @@ let SessionStoreInternal = {
DirtyWindows.clear();
}
// collect the data for all windows
var total = [], windows = {}, ids = [];
// An array that at the end will hold all current window data.
var total = [];
// The ids of all windows contained in 'total' in the same order.
var ids = [];
// The number of window that are _not_ popups.
var nonPopupCount = 0;
var ix;
// collect the data for all windows
for (ix in this._windows) {
if (this._windows[ix]._restoring) // window data is still in _statesToRestore
continue;
total.push(this._windows[ix]);
ids.push(ix);
windows[ix] = this._windows[ix];
if (!this._windows[ix].isPopup)
nonPopupCount++;
}
this._updateCookies(windows);
this._updateCookies(total);
// collect the data for all windows yet to be restored
for (ix in this._statesToRestore) {
@ -2627,12 +2611,10 @@ let SessionStoreInternal = {
this._collectWindowData(aWindow);
}
var winData = this._windows[aWindow.__SSi];
let windows = {};
windows[aWindow.__SSi] = winData;
let windows = [this._windows[aWindow.__SSi]];
this._updateCookies(windows);
return { windows: [winData] };
return { windows: windows };
},
_collectWindowData: function ssi_collectWindowData(aWindow) {
@ -2643,22 +2625,10 @@ let SessionStoreInternal = {
let tabs = tabbrowser.tabs;
let winData = this._windows[aWindow.__SSi];
let tabsData = winData.tabs = [];
let hosts = this._internalWindows[aWindow.__SSi].hosts = {};
// update the internal state data for this window
for (let tab of tabs) {
tabsData.push(this._collectTabData(tab));
// Since we are only ever called for open
// windows during a session, we can call into
// _extractHostsForCookiesFromHostScheme directly using data
// that is attached to each browser.
let hostSchemeData = tab.linkedBrowser.__SS_hostSchemeData || [];
for (let j = 0; j < hostSchemeData.length; j++) {
this._extractHostsForCookiesFromHostScheme(hostSchemeData[j].host,
hostSchemeData[j].scheme,
hosts, true, tab.pinned);
}
}
winData.selected = tabbrowser.mTabBox.selectedIndex + 1;