mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 11:26:09 +00:00
Bug 938093 - Swap TabStateCache contents when docShells are swapped r=billm
From ca18aa2560b9380aa67ccfb6b90f4bbe8d38fc57 Mon Sep 17 00:00:00 2001
This commit is contained in:
parent
9b4d040efe
commit
f0ba7c168c
@ -648,6 +648,7 @@ let SessionStoreInternal = {
|
||||
browser = aEvent.currentTarget;
|
||||
let otherBrowser = aEvent.detail;
|
||||
TabState.onSwapDocShells(browser, otherBrowser);
|
||||
TabStateCache.onSwapDocShells(browser, otherBrowser);
|
||||
break;
|
||||
case "TabOpen":
|
||||
this.onTabAdd(win, aEvent.originalTarget);
|
||||
|
@ -96,6 +96,18 @@ this.TabStateCache = Object.freeze({
|
||||
return TabStateCacheInternal.removeField(aKey, aField);
|
||||
},
|
||||
|
||||
/**
|
||||
* Swap cached data for two given browsers.
|
||||
*
|
||||
* @param {xul:browser} browser
|
||||
* The first of the two browsers that swapped docShells.
|
||||
* @param {xul:browser} otherBrowser
|
||||
* The second of the two browsers that swapped docShells.
|
||||
*/
|
||||
onSwapDocShells: function(browser, otherBrowser) {
|
||||
TabStateCacheInternal.onSwapDocShells(browser, otherBrowser);
|
||||
},
|
||||
|
||||
/**
|
||||
* Total number of cache hits during the session.
|
||||
*/
|
||||
@ -213,6 +225,37 @@ let TabStateCacheInternal = {
|
||||
TabStateCacheTelemetry.recordAccess(!!data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Swap cached data for two given browsers.
|
||||
*
|
||||
* @param {xul:browser} browser
|
||||
* The first of the two browsers that swapped docShells.
|
||||
* @param {xul:browser} otherBrowser
|
||||
* The second of the two browsers that swapped docShells.
|
||||
*/
|
||||
onSwapDocShells: function(browser, otherBrowser) {
|
||||
// Make sure that one or the other of these has cached data,
|
||||
// and let it be |browser|.
|
||||
if (!this._data.has(browser)) {
|
||||
[browser, otherBrowser] = [otherBrowser, browser];
|
||||
if (!this._data.has(browser)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// At this point, |browser| is guaranteed to have cached data,
|
||||
// although |otherBrowser| may not. Perform the swap.
|
||||
let data = this._data.get(browser);
|
||||
if (this._data.has(otherBrowser)) {
|
||||
let otherData = this._data.get(otherBrowser);
|
||||
this._data.set(browser, otherData);
|
||||
this._data.set(otherBrowser, data);
|
||||
} else {
|
||||
this._data.set(otherBrowser, data);
|
||||
this._data.delete(browser);
|
||||
}
|
||||
},
|
||||
|
||||
_normalizeToBrowser: function(aKey) {
|
||||
let nodeName = aKey.localName;
|
||||
if (nodeName == "tab") {
|
||||
|
Loading…
Reference in New Issue
Block a user