gecko-dev/browser/components/sessionstore/TabStateCache.jsm
Birunthan Mohanathas da44ab0e02 Bug 1038458 - Part 6: Flatten browser/components/sessionstore/src/ directory. r=mak
--HG--
rename : browser/components/sessionstore/src/ContentRestore.jsm => browser/components/sessionstore/ContentRestore.jsm
rename : browser/components/sessionstore/src/DocShellCapabilities.jsm => browser/components/sessionstore/DocShellCapabilities.jsm
rename : browser/components/sessionstore/src/FrameTree.jsm => browser/components/sessionstore/FrameTree.jsm
rename : browser/components/sessionstore/src/GlobalState.jsm => browser/components/sessionstore/GlobalState.jsm
rename : browser/components/sessionstore/src/PageStyle.jsm => browser/components/sessionstore/PageStyle.jsm
rename : browser/components/sessionstore/src/PrivacyFilter.jsm => browser/components/sessionstore/PrivacyFilter.jsm
rename : browser/components/sessionstore/src/PrivacyLevel.jsm => browser/components/sessionstore/PrivacyLevel.jsm
rename : browser/components/sessionstore/src/RecentlyClosedTabsAndWindowsMenuUtils.jsm => browser/components/sessionstore/RecentlyClosedTabsAndWindowsMenuUtils.jsm
rename : browser/components/sessionstore/src/SessionCookies.jsm => browser/components/sessionstore/SessionCookies.jsm
rename : browser/components/sessionstore/src/SessionFile.jsm => browser/components/sessionstore/SessionFile.jsm
rename : browser/components/sessionstore/src/SessionHistory.jsm => browser/components/sessionstore/SessionHistory.jsm
rename : browser/components/sessionstore/src/SessionMigration.jsm => browser/components/sessionstore/SessionMigration.jsm
rename : browser/components/sessionstore/src/SessionSaver.jsm => browser/components/sessionstore/SessionSaver.jsm
rename : browser/components/sessionstore/src/SessionStorage.jsm => browser/components/sessionstore/SessionStorage.jsm
rename : browser/components/sessionstore/src/SessionStore.jsm => browser/components/sessionstore/SessionStore.jsm
rename : browser/components/sessionstore/src/SessionWorker.js => browser/components/sessionstore/SessionWorker.js
rename : browser/components/sessionstore/src/SessionWorker.jsm => browser/components/sessionstore/SessionWorker.jsm
rename : browser/components/sessionstore/src/TabAttributes.jsm => browser/components/sessionstore/TabAttributes.jsm
rename : browser/components/sessionstore/src/TabState.jsm => browser/components/sessionstore/TabState.jsm
rename : browser/components/sessionstore/src/TabStateCache.jsm => browser/components/sessionstore/TabStateCache.jsm
rename : browser/components/sessionstore/src/Utils.jsm => browser/components/sessionstore/Utils.jsm
rename : browser/components/sessionstore/src/nsSessionStartup.js => browser/components/sessionstore/nsSessionStartup.js
rename : browser/components/sessionstore/src/nsSessionStore.js => browser/components/sessionstore/nsSessionStore.js
rename : browser/components/sessionstore/src/nsSessionStore.manifest => browser/components/sessionstore/nsSessionStore.manifest
2014-07-26 09:32:08 -07:00

83 lines
2.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
this.EXPORTED_SYMBOLS = ["TabStateCache"];
/**
* A cache for tabs data.
*
* This cache implements a weak map from tabs (as XUL elements)
* to tab data (as objects).
*
* Note that we should never cache private data, as:
* - that data is used very seldom by SessionStore;
* - caching private data in addition to public data is memory consuming.
*/
this.TabStateCache = Object.freeze({
/**
* Retrieves cached data for a given |browser|.
*
* @param browser (xul:browser)
* The browser to retrieve cached data for.
* @return (object)
* The cached data stored for the given |browser|.
*/
get: function (browser) {
return TabStateCacheInternal.get(browser);
},
/**
* Updates cached data for a given |browser|.
*
* @param browser (xul:browser)
* The browser belonging to the given tab data.
* @param newData (object)
* The new data to be stored for the given |browser|.
*/
update: function (browser, newData) {
TabStateCacheInternal.update(browser, newData);
}
});
let TabStateCacheInternal = {
_data: new WeakMap(),
/**
* Retrieves cached data for a given |browser|.
*
* @param browser (xul:browser)
* The browser to retrieve cached data for.
* @return (object)
* The cached data stored for the given |browser|.
*/
get: function (browser) {
return this._data.get(browser.permanentKey);
},
/**
* Updates cached data for a given |browser|.
*
* @param browser (xul:browser)
* The browser belonging to the given tab data.
* @param newData (object)
* The new data to be stored for the given |browser|.
*/
update: function (browser, newData) {
let data = this._data.get(browser.permanentKey) || {};
for (let key of Object.keys(newData)) {
let value = newData[key];
if (value === null) {
delete data[key];
} else {
data[key] = value;
}
}
this._data.set(browser.permanentKey, data);
}
};