gecko-dev/browser/base/content/tabview/storage.js

214 lines
6.6 KiB
JavaScript
Raw Normal View History

/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is storage.js.
*
* The Initial Developer of the Original Code is
* Ehsan Akhgari <ehsan@mozilla.com>
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ian Gilman <ian@iangilman.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// **********
2010-07-18 15:58:10 +00:00
// Title: storage.js
// ##########
// Class: Storage
Bug 583044 - Rename code references of TabCandy to TabView Move files and update references to tabview from tabcandy. Only remaining candy reference is the link to aza's webm video. --HG-- rename : browser/base/content/browser-tabcandy.js => browser/base/content/browser-tabview.js rename : browser/base/content/tabcandy/app/drag.js => browser/base/content/tabview/drag.js rename : browser/base/content/tabcandy/app/groups.js => browser/base/content/tabview/groups.js rename : browser/base/content/tabcandy/app/infoitems.js => browser/base/content/tabview/infoitems.js rename : browser/base/content/tabcandy/core/iq.js => browser/base/content/tabview/iq.js rename : browser/base/content/tabcandy/app/items.js => browser/base/content/tabview/items.js rename : browser/base/content/tabcandy/core/profile.js => browser/base/content/tabview/profile.js rename : browser/base/content/tabcandy/app/storage.js => browser/base/content/tabview/storage.js rename : browser/base/content/tabcandy/app/tabitems.js => browser/base/content/tabview/tabitems.js rename : browser/base/content/tabcandy/tabcandy.css => browser/base/content/tabview/tabview.css rename : browser/base/content/tabcandy/tabcandy.html => browser/base/content/tabview/tabview.html rename : browser/base/content/tabcandy/tabcandy.js => browser/base/content/tabview/tabview.js rename : browser/base/content/tabcandy/app/trench.js => browser/base/content/tabview/trench.js rename : browser/base/content/tabcandy/app/ui.js => browser/base/content/tabview/ui.js rename : browser/themes/gnomestripe/browser/tabcandy/edit-light.png => browser/themes/gnomestripe/browser/tabview/edit-light.png rename : browser/themes/gnomestripe/browser/tabcandy/edit.png => browser/themes/gnomestripe/browser/tabview/edit.png rename : browser/themes/gnomestripe/browser/tabcandy/new-tab.png => browser/themes/gnomestripe/browser/tabview/new-tab.png rename : browser/themes/gnomestripe/browser/tabcandy/platform.css => browser/themes/gnomestripe/browser/tabview/platform.css rename : browser/themes/gnomestripe/browser/tabcandy/stack-expander.png => browser/themes/gnomestripe/browser/tabview/stack-expander.png rename : browser/themes/gnomestripe/browser/tabcandy/tabcandy.png => browser/themes/gnomestripe/browser/tabview/tabview.png rename : browser/themes/pinstripe/browser/tabcandy/edit-light.png => browser/themes/pinstripe/browser/tabview/edit-light.png rename : browser/themes/pinstripe/browser/tabcandy/edit.png => browser/themes/pinstripe/browser/tabview/edit.png rename : browser/themes/pinstripe/browser/tabcandy/new-tab.png => browser/themes/pinstripe/browser/tabview/new-tab.png rename : browser/themes/pinstripe/browser/tabcandy/platform.css => browser/themes/pinstripe/browser/tabview/platform.css rename : browser/themes/pinstripe/browser/tabcandy/stack-expander.png => browser/themes/pinstripe/browser/tabview/stack-expander.png rename : browser/themes/pinstripe/browser/tabcandy/tabcandy.png => browser/themes/pinstripe/browser/tabview/tabview.png rename : browser/themes/winstripe/browser/tabcandy/edit-light.png => browser/themes/winstripe/browser/tabview/edit-light.png rename : browser/themes/winstripe/browser/tabcandy/edit.png => browser/themes/winstripe/browser/tabview/edit.png rename : browser/themes/winstripe/browser/tabcandy/new-tab.png => browser/themes/winstripe/browser/tabview/new-tab.png rename : browser/themes/winstripe/browser/tabcandy/platform.css => browser/themes/winstripe/browser/tabview/platform.css rename : browser/themes/winstripe/browser/tabcandy/stack-expander.png => browser/themes/winstripe/browser/tabview/stack-expander.png rename : browser/themes/winstripe/browser/tabcandy/tabcandy.png => browser/themes/winstripe/browser/tabview/tabview.png
2010-07-29 19:37:25 +00:00
// Singleton for permanent storage of TabView data.
Storage = {
Bug 583044 - Rename code references of TabCandy to TabView Move files and update references to tabview from tabcandy. Only remaining candy reference is the link to aza's webm video. --HG-- rename : browser/base/content/browser-tabcandy.js => browser/base/content/browser-tabview.js rename : browser/base/content/tabcandy/app/drag.js => browser/base/content/tabview/drag.js rename : browser/base/content/tabcandy/app/groups.js => browser/base/content/tabview/groups.js rename : browser/base/content/tabcandy/app/infoitems.js => browser/base/content/tabview/infoitems.js rename : browser/base/content/tabcandy/core/iq.js => browser/base/content/tabview/iq.js rename : browser/base/content/tabcandy/app/items.js => browser/base/content/tabview/items.js rename : browser/base/content/tabcandy/core/profile.js => browser/base/content/tabview/profile.js rename : browser/base/content/tabcandy/app/storage.js => browser/base/content/tabview/storage.js rename : browser/base/content/tabcandy/app/tabitems.js => browser/base/content/tabview/tabitems.js rename : browser/base/content/tabcandy/tabcandy.css => browser/base/content/tabview/tabview.css rename : browser/base/content/tabcandy/tabcandy.html => browser/base/content/tabview/tabview.html rename : browser/base/content/tabcandy/tabcandy.js => browser/base/content/tabview/tabview.js rename : browser/base/content/tabcandy/app/trench.js => browser/base/content/tabview/trench.js rename : browser/base/content/tabcandy/app/ui.js => browser/base/content/tabview/ui.js rename : browser/themes/gnomestripe/browser/tabcandy/edit-light.png => browser/themes/gnomestripe/browser/tabview/edit-light.png rename : browser/themes/gnomestripe/browser/tabcandy/edit.png => browser/themes/gnomestripe/browser/tabview/edit.png rename : browser/themes/gnomestripe/browser/tabcandy/new-tab.png => browser/themes/gnomestripe/browser/tabview/new-tab.png rename : browser/themes/gnomestripe/browser/tabcandy/platform.css => browser/themes/gnomestripe/browser/tabview/platform.css rename : browser/themes/gnomestripe/browser/tabcandy/stack-expander.png => browser/themes/gnomestripe/browser/tabview/stack-expander.png rename : browser/themes/gnomestripe/browser/tabcandy/tabcandy.png => browser/themes/gnomestripe/browser/tabview/tabview.png rename : browser/themes/pinstripe/browser/tabcandy/edit-light.png => browser/themes/pinstripe/browser/tabview/edit-light.png rename : browser/themes/pinstripe/browser/tabcandy/edit.png => browser/themes/pinstripe/browser/tabview/edit.png rename : browser/themes/pinstripe/browser/tabcandy/new-tab.png => browser/themes/pinstripe/browser/tabview/new-tab.png rename : browser/themes/pinstripe/browser/tabcandy/platform.css => browser/themes/pinstripe/browser/tabview/platform.css rename : browser/themes/pinstripe/browser/tabcandy/stack-expander.png => browser/themes/pinstripe/browser/tabview/stack-expander.png rename : browser/themes/pinstripe/browser/tabcandy/tabcandy.png => browser/themes/pinstripe/browser/tabview/tabview.png rename : browser/themes/winstripe/browser/tabcandy/edit-light.png => browser/themes/winstripe/browser/tabview/edit-light.png rename : browser/themes/winstripe/browser/tabcandy/edit.png => browser/themes/winstripe/browser/tabview/edit.png rename : browser/themes/winstripe/browser/tabcandy/new-tab.png => browser/themes/winstripe/browser/tabview/new-tab.png rename : browser/themes/winstripe/browser/tabcandy/platform.css => browser/themes/winstripe/browser/tabview/platform.css rename : browser/themes/winstripe/browser/tabcandy/stack-expander.png => browser/themes/winstripe/browser/tabview/stack-expander.png rename : browser/themes/winstripe/browser/tabcandy/tabcandy.png => browser/themes/winstripe/browser/tabview/tabview.png
2010-07-29 19:37:25 +00:00
GROUP_DATA_IDENTIFIER: "tabview-group",
GROUPS_DATA_IDENTIFIER: "tabview-groups",
TAB_DATA_IDENTIFIER: "tabview-tab",
UI_DATA_IDENTIFIER: "tabview-ui",
VISIBILITY_DATA_IDENTIFIER: "tabview-visibility",
// ----------
// Function: init
2010-07-18 15:58:10 +00:00
// Sets up the object.
init: function() {
2010-07-03 04:33:33 +00:00
this._sessionStore =
Components.classes["@mozilla.org/browser/sessionstore;1"]
.getService(Components.interfaces.nsISessionStore);
},
// ----------
// Function: wipe
2010-07-18 15:58:10 +00:00
// Cleans out all the stored data, leaving empty objects.
wipe: function() {
try {
var self = this;
2010-07-18 15:58:10 +00:00
// ___ Tabs
AllTabs.tabs.forEach(function(tab) {
if (tab.ownerDocument.defaultView != gWindow)
return;
self.saveTab(tab, null);
});
2010-07-18 15:58:10 +00:00
// ___ Other
this.saveGroupItemsData(gWindow, {});
this.saveUIData(gWindow, {});
2010-07-18 15:58:10 +00:00
this._sessionStore.setWindowValue(gWindow, this.GROUP_DATA_IDENTIFIER,
JSON.stringify({}));
} catch (e) {
Utils.log("Error in wipe: "+e);
}
},
2010-07-18 15:58:10 +00:00
// ----------
// Function: saveTab
2010-07-18 15:58:10 +00:00
// Saves the data for a single tab.
saveTab: function(tab, data) {
Utils.assert('tab', tab);
this._sessionStore.setTabValue(tab, this.TAB_DATA_IDENTIFIER,
JSON.stringify(data));
},
// ----------
// Function: getTabData
// Returns the data object associated with a single tab.
getTabData: function(tab) {
Utils.assert('tab', tab);
var existingData = null;
try {
/* Utils.log("readTabData: " + this._sessionStore.getTabValue(tab, this.TAB_DATA_IDENTIFIER)); */
var tabData = this._sessionStore.getTabValue(tab, this.TAB_DATA_IDENTIFIER);
if (tabData != "") {
existingData = JSON.parse(tabData);
}
} catch (e) {
// getWindowValue will fail if the property doesn't exist
Utils.log(e);
}
2010-07-18 15:58:10 +00:00
/* Utils.log('tab', existingData); */
return existingData;
},
// ----------
// Function: saveGroupItem
// Saves the data for a single groupItem, associated with a specific window.
saveGroupItem: function(win, data) {
var id = data.id;
var existingData = this.readGroupItemData(win);
existingData[id] = data;
this._sessionStore.setWindowValue(win, this.GROUP_DATA_IDENTIFIER,
JSON.stringify(existingData));
},
// ----------
// Function: deleteGroupItem
// Deletes the data for a single groupItem from the given window.
deleteGroupItem: function(win, id) {
var existingData = this.readGroupItemData(win);
delete existingData[id];
this._sessionStore.setWindowValue(win, this.GROUP_DATA_IDENTIFIER,
JSON.stringify(existingData));
},
// ----------
// Function: readGroupItemData
// Returns the data for all groupItems associated with the given window.
readGroupItemData: function(win) {
var existingData = {};
try {
/* Utils.log("readGroupItemData" + this._sessionStore.getWindowValue(win, this.GROUP_DATA_IDENTIFIER)); */
existingData = JSON.parse(
this._sessionStore.getWindowValue(win, this.GROUP_DATA_IDENTIFIER)
);
} catch (e) {
// getWindowValue will fail if the property doesn't exist
Utils.log("Error in readGroupItemData: "+e);
}
return existingData;
},
// ----------
// Function: saveGroupItemsData
// Saves the global data for the <GroupItems> singleton for the given window.
saveGroupItemsData: function(win, data) {
this.saveData(win, this.GROUPS_DATA_IDENTIFIER, data);
},
// ----------
// Function: readGroupItemsData
// Reads the global data for the <GroupItems> singleton for the given window.
readGroupItemsData: function(win) {
return this.readData(win, this.GROUPS_DATA_IDENTIFIER);
},
2010-07-18 15:58:10 +00:00
// ----------
// Function: saveUIData
2010-07-23 07:03:40 +00:00
// Saves the global data for the <UIManager> singleton for the given window.
saveUIData: function(win, data) {
this.saveData(win, this.UI_DATA_IDENTIFIER, data);
},
// ----------
// Function: readUIData
2010-07-23 07:03:40 +00:00
// Reads the global data for the <UIManager> singleton for the given window.
readUIData: function(win) {
return this.readData(win, this.UI_DATA_IDENTIFIER);
},
// ----------
// Function: saveData
2010-07-18 15:58:10 +00:00
// Generic routine for saving data to a window.
saveData: function(win, id, data) {
try {
this._sessionStore.setWindowValue(win, id, JSON.stringify(data));
} catch (e) {
Utils.log("Error in saveData: "+e);
}
2010-07-18 15:58:10 +00:00
/* Utils.log('save data', id, data); */
},
// ----------
// Function: readData
2010-07-18 15:58:10 +00:00
// Generic routine for reading data from a window.
readData: function(win, id) {
var existingData = {};
try {
var data = this._sessionStore.getWindowValue(win, id);
if (data)
existingData = JSON.parse(data);
} catch (e) {
Utils.log("Error in readData: "+e);
}
2010-07-18 15:58:10 +00:00
/* Utils.log('read data', id, existingData); */
return existingData;
}
};