summaryrefslogtreecommitdiffstats
path: root/application/basilisk/components/sessionstore/TabStateCache.jsm
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-02 05:06:10 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-02 05:06:10 -0500
commit6d614170cbfa958564eb5f824234ad5a9e484344 (patch)
tree3e1eb384382f30987cb2e64bd654afa8b74fd06b /application/basilisk/components/sessionstore/TabStateCache.jsm
parent2a6b605d64b19411a300efdbbd7f78c349f90206 (diff)
downloadUXP-6d614170cbfa958564eb5f824234ad5a9e484344.tar
UXP-6d614170cbfa958564eb5f824234ad5a9e484344.tar.gz
UXP-6d614170cbfa958564eb5f824234ad5a9e484344.tar.lz
UXP-6d614170cbfa958564eb5f824234ad5a9e484344.tar.xz
UXP-6d614170cbfa958564eb5f824234ad5a9e484344.zip
Revert "Add Basilisk"
This reverts commit e72ef92b5bdc43cd2584198e2e54e951b70299e8.
Diffstat (limited to 'application/basilisk/components/sessionstore/TabStateCache.jsm')
-rw-r--r--application/basilisk/components/sessionstore/TabStateCache.jsm167
1 files changed, 0 insertions, 167 deletions
diff --git a/application/basilisk/components/sessionstore/TabStateCache.jsm b/application/basilisk/components/sessionstore/TabStateCache.jsm
deleted file mode 100644
index d2c07ac73..000000000
--- a/application/basilisk/components/sessionstore/TabStateCache.jsm
+++ /dev/null
@@ -1,167 +0,0 @@
-/* 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 |tab| or associated |browser|.
- *
- * @param browserOrTab (xul:tab or xul:browser)
- * The tab or browser to retrieve cached data for.
- * @return (object)
- * The cached data stored for the given |tab|
- * or associated |browser|.
- */
- get: function (browserOrTab) {
- return TabStateCacheInternal.get(browserOrTab);
- },
-
- /**
- * Updates cached data for a given |tab| or associated |browser|.
- *
- * @param browserOrTab (xul:tab or xul:browser)
- * The tab or browser belonging to the given tab data.
- * @param newData (object)
- * The new data to be stored for the given |tab|
- * or associated |browser|.
- */
- update: function (browserOrTab, newData) {
- TabStateCacheInternal.update(browserOrTab, newData);
- }
-});
-
-var TabStateCacheInternal = {
- _data: new WeakMap(),
-
- /**
- * Retrieves cached data for a given |tab| or associated |browser|.
- *
- * @param browserOrTab (xul:tab or xul:browser)
- * The tab or browser to retrieve cached data for.
- * @return (object)
- * The cached data stored for the given |tab|
- * or associated |browser|.
- */
- get: function (browserOrTab) {
- return this._data.get(browserOrTab.permanentKey);
- },
-
- /**
- * Helper function used by update (see below). For message size
- * optimization sometimes we don't update the whole session storage
- * only the values that have been changed.
- *
- * @param data (object)
- * The cached data where we want to update the changes.
- * @param change (object)
- * The actual changed values per domain.
- */
- updatePartialStorageChange: function (data, change) {
- if (!data.storage) {
- data.storage = {};
- }
-
- let storage = data.storage;
- for (let domain of Object.keys(change)) {
- for (let key of Object.keys(change[domain])) {
- let value = change[domain][key];
- if (value === null) {
- if (storage[domain] && storage[domain][key]) {
- delete storage[domain][key];
- }
- } else {
- if (!storage[domain]) {
- storage[domain] = {};
- }
- storage[domain][key] = value;
- }
- }
- }
- },
-
- /**
- * Helper function used by update (see below). For message size
- * optimization sometimes we don't update the whole browser history
- * only the current index and the tail of the history from a certain
- * index (specified by change.fromIdx)
- *
- * @param data (object)
- * The cached data where we want to update the changes.
- * @param change (object)
- * Object containing the tail of the history array, and
- * some additional metadata.
- */
- updatePartialHistoryChange: function (data, change) {
- const kLastIndex = Number.MAX_SAFE_INTEGER - 1;
-
- if (!data.history) {
- data.history = { entries: [] };
- }
-
- let history = data.history;
- let toIdx = history.entries.length;
- if ("toIdx" in change) {
- toIdx = Math.min(toIdx, change.toIdx + 1);
- }
-
- for (let key of Object.keys(change)) {
- if (key == "entries") {
- if (change.fromIdx != kLastIndex) {
- let start = change.fromIdx + 1;
- history.entries.splice.apply(
- history.entries, [start, toIdx - start].concat(change.entries));
- }
- } else if (key != "fromIdx" && key != "toIdx") {
- history[key] = change[key];
- }
- }
- },
-
- /**
- * Updates cached data for a given |tab| or associated |browser|.
- *
- * @param browserOrTab (xul:tab or xul:browser)
- * The tab or browser belonging to the given tab data.
- * @param newData (object)
- * The new data to be stored for the given |tab|
- * or associated |browser|.
- */
- update: function (browserOrTab, newData) {
- let data = this._data.get(browserOrTab.permanentKey) || {};
-
- for (let key of Object.keys(newData)) {
- if (key == "storagechange") {
- this.updatePartialStorageChange(data, newData.storagechange);
- continue;
- }
-
- if (key == "historychange") {
- this.updatePartialHistoryChange(data, newData.historychange);
- continue;
- }
-
- let value = newData[key];
- if (value === null) {
- delete data[key];
- } else {
- data[key] = value;
- }
- }
-
- this._data.set(browserOrTab.permanentKey, data);
- }
-};