2012-08-10 13:20:25 -07:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsICookie = Components.interfaces.nsICookie;
|
|
|
|
|
|
|
|
var gCookiesWindow = {
|
|
|
|
_cm : Components.classes["@mozilla.org/cookiemanager;1"]
|
|
|
|
.getService(Components.interfaces.nsICookieManager),
|
|
|
|
_ds : Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
|
|
|
|
.getService(Components.interfaces.nsIScriptableDateFormat),
|
|
|
|
_hosts : {},
|
|
|
|
_hostOrder : [],
|
|
|
|
_tree : null,
|
|
|
|
_bundle : null,
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
init: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
os.addObserver(this, "cookie-changed", false);
|
|
|
|
os.addObserver(this, "perm-changed", false);
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._bundle = document.getElementById("bundlePreferences");
|
|
|
|
this._tree = document.getElementById("cookiesList");
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2008-10-19 14:12:53 -07:00
|
|
|
this._populateList(true);
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
document.getElementById("filter").focus();
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
uninit: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
os.removeObserver(this, "cookie-changed");
|
|
|
|
os.removeObserver(this, "perm-changed");
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_populateList: function (aInitialLoad) {
|
2008-10-19 14:12:53 -07:00
|
|
|
this._loadCookies();
|
|
|
|
this._tree.treeBoxObject.view = this._view;
|
|
|
|
if (aInitialLoad)
|
|
|
|
this.sort("rawHost");
|
2009-03-14 06:32:36 -07:00
|
|
|
if (this._view.rowCount > 0)
|
2008-10-19 14:12:53 -07:00
|
|
|
this._tree.view.selection.select(0);
|
|
|
|
|
|
|
|
if (aInitialLoad) {
|
2009-03-17 06:08:07 -07:00
|
|
|
if ("arguments" in window &&
|
|
|
|
window.arguments[0] &&
|
|
|
|
window.arguments[0].filterString)
|
|
|
|
this.setFilter(window.arguments[0].filterString);
|
2008-10-19 14:12:53 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (document.getElementById("filter").value != "")
|
|
|
|
this.filter();
|
|
|
|
}
|
|
|
|
|
2012-02-05 07:09:52 -08:00
|
|
|
this._updateRemoveAllButton();
|
2011-10-19 08:18:29 -07:00
|
|
|
|
2008-10-19 14:12:53 -07:00
|
|
|
this._saveState();
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_cookieEquals: function (aCookieA, aCookieB, aStrippedHost) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return aCookieA.rawHost == aStrippedHost &&
|
|
|
|
aCookieA.name == aCookieB.name &&
|
|
|
|
aCookieA.path == aCookieB.path;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
observe: function (aCookie, aTopic, aData) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aTopic != "cookie-changed")
|
|
|
|
return;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aCookie instanceof Components.interfaces.nsICookie) {
|
|
|
|
var strippedHost = this._makeStrippedHost(aCookie.host);
|
|
|
|
if (aData == "changed")
|
|
|
|
this._handleCookieChanged(aCookie, strippedHost);
|
|
|
|
else if (aData == "added")
|
|
|
|
this._handleCookieAdded(aCookie, strippedHost);
|
|
|
|
}
|
|
|
|
else if (aData == "cleared") {
|
|
|
|
this._hosts = {};
|
|
|
|
this._hostOrder = [];
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var oldRowCount = this._view._rowCount;
|
|
|
|
this._view._rowCount = 0;
|
|
|
|
this._tree.treeBoxObject.rowCountChanged(0, -oldRowCount);
|
|
|
|
this._view.selection.clearSelection();
|
2012-02-05 07:09:52 -08:00
|
|
|
this._updateRemoveAllButton();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-19 14:12:53 -07:00
|
|
|
else if (aData == "reload") {
|
|
|
|
// first, clear any existing entries
|
|
|
|
this.observe(aCookie, aTopic, "cleared");
|
|
|
|
|
|
|
|
// then, reload the list
|
|
|
|
this._populateList(false);
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We don't yet handle aData == "deleted" - it's a less common case
|
|
|
|
// and is rather complicated as selection tracking is difficult
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_handleCookieChanged: function (changedCookie, strippedHost) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var rowIndex = 0;
|
|
|
|
var cookieItem = null;
|
|
|
|
if (!this._view._filtered) {
|
|
|
|
for (var i = 0; i < this._hostOrder.length; ++i) { // (var host in this._hosts) {
|
|
|
|
++rowIndex;
|
|
|
|
var hostItem = this._hosts[this._hostOrder[i]]; // var hostItem = this._hosts[host];
|
|
|
|
if (this._hostOrder[i] == strippedHost) { // host == strippedHost) {
|
|
|
|
// Host matches, look for the cookie within this Host collection
|
|
|
|
// and update its data
|
|
|
|
for (var j = 0; j < hostItem.cookies.length; ++j) {
|
|
|
|
++rowIndex;
|
|
|
|
var currCookie = hostItem.cookies[j];
|
|
|
|
if (this._cookieEquals(currCookie, changedCookie, strippedHost)) {
|
|
|
|
currCookie.value = changedCookie.value;
|
|
|
|
currCookie.isSecure = changedCookie.isSecure;
|
|
|
|
currCookie.isDomain = changedCookie.isDomain;
|
|
|
|
currCookie.expires = changedCookie.expires;
|
|
|
|
cookieItem = currCookie;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (hostItem.open)
|
|
|
|
rowIndex += hostItem.cookies.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Just walk the filter list to find the item. It doesn't matter that
|
|
|
|
// we don't update the main Host collection when we do this, because
|
|
|
|
// when the filter is reset the Host collection is rebuilt anyway.
|
|
|
|
for (rowIndex = 0; rowIndex < this._view._filterSet.length; ++rowIndex) {
|
|
|
|
currCookie = this._view._filterSet[rowIndex];
|
|
|
|
if (this._cookieEquals(currCookie, changedCookie, strippedHost)) {
|
|
|
|
currCookie.value = changedCookie.value;
|
|
|
|
currCookie.isSecure = changedCookie.isSecure;
|
|
|
|
currCookie.isDomain = changedCookie.isDomain;
|
|
|
|
currCookie.expires = changedCookie.expires;
|
|
|
|
cookieItem = currCookie;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure the tree display is up to date...
|
|
|
|
this._tree.treeBoxObject.invalidateRow(rowIndex);
|
|
|
|
// ... and if the cookie is selected, update the displayed metadata too
|
|
|
|
if (cookieItem != null && this._view.selection.currentIndex == rowIndex)
|
2009-03-14 06:32:36 -07:00
|
|
|
this._updateCookieData(cookieItem);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_handleCookieAdded: function (changedCookie, strippedHost) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var rowCountImpact = 0;
|
|
|
|
var addedHost = { value: 0 };
|
|
|
|
this._addCookie(strippedHost, changedCookie, addedHost);
|
|
|
|
if (!this._view._filtered) {
|
2009-03-14 06:32:36 -07:00
|
|
|
// The Host collection for this cookie already exists, and it's not open,
|
2007-03-22 10:30:00 -07:00
|
|
|
// so don't increment the rowCountImpact becaues the user is not going to
|
2009-03-14 06:32:36 -07:00
|
|
|
// see the additional rows as they're hidden.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (addedHost.value || this._hosts[strippedHost].open)
|
|
|
|
++rowCountImpact;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// We're in search mode, and the cookie being added matches
|
2009-03-14 06:32:36 -07:00
|
|
|
// the search condition, so add it to the list.
|
2007-03-22 10:30:00 -07:00
|
|
|
var c = this._makeCookieObject(strippedHost, changedCookie);
|
|
|
|
if (this._cookieMatchesFilter(c)) {
|
|
|
|
this._view._filterSet.push(this._makeCookieObject(strippedHost, changedCookie));
|
|
|
|
++rowCountImpact;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Now update the tree display at the end (we could/should re run the sort
|
|
|
|
// if any to get the position correct.)
|
|
|
|
var oldRowCount = this._rowCount;
|
|
|
|
this._view._rowCount += rowCountImpact;
|
|
|
|
this._tree.treeBoxObject.rowCountChanged(oldRowCount - 1, rowCountImpact);
|
|
|
|
|
2012-02-05 07:09:52 -08:00
|
|
|
this._updateRemoveAllButton();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
_view: {
|
|
|
|
_filtered : false,
|
|
|
|
_filterSet : [],
|
|
|
|
_filterValue: "",
|
|
|
|
_rowCount : 0,
|
|
|
|
_cacheValid : 0,
|
|
|
|
_cacheItems : [],
|
2009-03-14 06:32:36 -07:00
|
|
|
get rowCount() {
|
|
|
|
return this._rowCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_getItemAtIndex: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this._filtered)
|
|
|
|
return this._filterSet[aIndex];
|
|
|
|
|
|
|
|
var start = 0;
|
|
|
|
var count = 0, hostIndex = 0;
|
|
|
|
|
|
|
|
var cacheIndex = Math.min(this._cacheValid, aIndex);
|
|
|
|
if (cacheIndex > 0) {
|
|
|
|
var cacheItem = this._cacheItems[cacheIndex];
|
|
|
|
start = cacheItem['start'];
|
|
|
|
count = hostIndex = cacheItem['count'];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = start; i < gCookiesWindow._hostOrder.length; ++i) { // var host in gCookiesWindow._hosts) {
|
|
|
|
var currHost = gCookiesWindow._hosts[gCookiesWindow._hostOrder[i]]; // gCookiesWindow._hosts[host];
|
|
|
|
if (!currHost) continue;
|
|
|
|
if (count == aIndex)
|
|
|
|
return currHost;
|
|
|
|
hostIndex = count;
|
|
|
|
|
|
|
|
var cacheEntry = { 'start' : i, 'count' : count };
|
|
|
|
var cacheStart = count;
|
|
|
|
|
|
|
|
if (currHost.open) {
|
|
|
|
if (count < aIndex && aIndex <= (count + currHost.cookies.length)) {
|
2009-03-14 06:32:36 -07:00
|
|
|
// We are looking for an entry within this host's children,
|
|
|
|
// enumerate them looking for the index.
|
2007-03-22 10:30:00 -07:00
|
|
|
++count;
|
|
|
|
for (var i = 0; i < currHost.cookies.length; ++i) {
|
|
|
|
if (count == aIndex) {
|
|
|
|
var cookie = currHost.cookies[i];
|
|
|
|
cookie.parentIndex = hostIndex;
|
|
|
|
return cookie;
|
|
|
|
}
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// A host entry was open, but we weren't looking for an index
|
|
|
|
// within that host entry's children, so skip forward over the
|
|
|
|
// entry's children. We need to add one to increment for the
|
2009-03-14 06:32:36 -07:00
|
|
|
// host value too.
|
2007-03-22 10:30:00 -07:00
|
|
|
count += currHost.cookies.length + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++count;
|
|
|
|
|
|
|
|
for (var j = cacheStart; j < count; j++)
|
|
|
|
this._cacheItems[j] = cacheEntry;
|
|
|
|
this._cacheValid = count - 1;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
_removeItemAtIndex: function (aIndex, aCount) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var removeCount = aCount === undefined ? 1 : aCount;
|
|
|
|
if (this._filtered) {
|
2008-01-24 22:58:09 -08:00
|
|
|
// remove the cookies from the unfiltered set so that they
|
|
|
|
// don't reappear when the filter is changed. See bug 410863.
|
|
|
|
for (var i = aIndex; i < aIndex + removeCount; ++i) {
|
|
|
|
var item = this._filterSet[i];
|
|
|
|
var parent = gCookiesWindow._hosts[item.rawHost];
|
|
|
|
for (var j = 0; j < parent.cookies.length; ++j) {
|
|
|
|
if (item == parent.cookies[j]) {
|
|
|
|
parent.cookies.splice(j, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
this._filterSet.splice(aIndex, removeCount);
|
|
|
|
return;
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return;
|
|
|
|
this._invalidateCache(aIndex - 1);
|
|
|
|
if (item.container)
|
|
|
|
gCookiesWindow._hosts[item.rawHost] = null;
|
|
|
|
else {
|
|
|
|
var parent = this._getItemAtIndex(item.parentIndex);
|
|
|
|
for (var i = 0; i < parent.cookies.length; ++i) {
|
|
|
|
var cookie = parent.cookies[i];
|
|
|
|
if (item.rawHost == cookie.rawHost &&
|
|
|
|
item.name == cookie.name && item.path == cookie.path)
|
|
|
|
parent.cookies.splice(i, removeCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
_invalidateCache: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._cacheValid = Math.min(this._cacheValid, aIndex);
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
getCellText: function (aIndex, aColumn) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
2009-03-14 06:32:36 -07:00
|
|
|
if (!item)
|
2007-03-22 10:30:00 -07:00
|
|
|
return "";
|
|
|
|
if (aColumn.id == "domainCol")
|
|
|
|
return item.rawHost;
|
|
|
|
else if (aColumn.id == "nameCol")
|
|
|
|
return item.name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (aColumn.id == "domainCol")
|
|
|
|
return this._filterSet[aIndex].rawHost;
|
|
|
|
else if (aColumn.id == "nameCol")
|
|
|
|
return this._filterSet[aIndex].name;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
},
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
_selection: null,
|
2007-03-22 10:30:00 -07:00
|
|
|
get selection () { return this._selection; },
|
|
|
|
set selection (val) { this._selection = val; return val; },
|
2013-01-06 16:54:42 -08:00
|
|
|
getRowProperties: function (aIndex) { return ""; },
|
|
|
|
getCellProperties: function (aIndex, aColumn) { return ""; },
|
|
|
|
getColumnProperties: function (aColumn) { return ""; },
|
2009-03-14 06:32:36 -07:00
|
|
|
isContainer: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return false;
|
|
|
|
return item.container;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
isContainerOpen: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return false;
|
|
|
|
return item.open;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
isContainerEmpty: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return false;
|
|
|
|
return item.cookies.length == 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
isSeparator: function (aIndex) { return false; },
|
|
|
|
isSorted: function (aIndex) { return false; },
|
|
|
|
canDrop: function (aIndex, aOrientation) { return false; },
|
|
|
|
drop: function (aIndex, aOrientation) {},
|
|
|
|
getParentIndex: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
2009-03-14 06:32:36 -07:00
|
|
|
// If an item has no parent index (i.e. it is at the top level) this
|
|
|
|
// function MUST return -1 otherwise we will go into an infinite loop.
|
|
|
|
// Containers are always top level items in the cookies tree, so make
|
|
|
|
// sure to return the appropriate value here.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!item || item.container) return -1;
|
|
|
|
return item.parentIndex;
|
|
|
|
}
|
|
|
|
return -1;
|
2009-03-14 06:32:36 -07:00
|
|
|
},
|
|
|
|
hasNextSibling: function (aParentIndex, aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
// |aParentIndex| appears to be bogus, but we can get the real
|
|
|
|
// parent index by getting the entry for |aIndex| and reading the
|
2009-03-14 06:32:36 -07:00
|
|
|
// parentIndex field.
|
|
|
|
// The index of the last item in this host collection is the
|
2007-03-22 10:30:00 -07:00
|
|
|
// index of the parent + the size of the host collection, and
|
|
|
|
// aIndex has a next sibling if it is less than this value.
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (item) {
|
|
|
|
if (item.container) {
|
|
|
|
for (var i = aIndex + 1; i < this.rowCount; ++i) {
|
|
|
|
var subsequent = this._getItemAtIndex(i);
|
2009-03-14 06:32:36 -07:00
|
|
|
if (subsequent.container)
|
2007-03-22 10:30:00 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var parent = this._getItemAtIndex(item.parentIndex);
|
|
|
|
if (parent && parent.container)
|
|
|
|
return aIndex < item.parentIndex + parent.cookies.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aIndex < this.rowCount - 1;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
hasPreviousSibling: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return false;
|
|
|
|
var parent = this._getItemAtIndex(item.parentIndex);
|
|
|
|
if (parent && parent.container)
|
|
|
|
return aIndex > item.parentIndex + 1;
|
|
|
|
}
|
|
|
|
return aIndex > 0;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
getLevel: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return 0;
|
|
|
|
return item.level;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
getImageSrc: function (aIndex, aColumn) {},
|
|
|
|
getProgressMode: function (aIndex, aColumn) {},
|
2007-03-22 10:30:00 -07:00
|
|
|
getCellValue: function (aIndex, aColumn) {},
|
2009-03-14 06:32:36 -07:00
|
|
|
setTree: function (aTree) {},
|
|
|
|
toggleOpenState: function (aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!this._filtered) {
|
|
|
|
var item = this._getItemAtIndex(aIndex);
|
|
|
|
if (!item) return;
|
|
|
|
this._invalidateCache(aIndex);
|
|
|
|
var multiplier = item.open ? -1 : 1;
|
|
|
|
var delta = multiplier * item.cookies.length;
|
|
|
|
this._rowCount += delta;
|
|
|
|
item.open = !item.open;
|
|
|
|
gCookiesWindow._tree.treeBoxObject.rowCountChanged(aIndex + 1, delta);
|
|
|
|
gCookiesWindow._tree.treeBoxObject.invalidateRow(aIndex);
|
|
|
|
}
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
cycleHeader: function (aColumn) {},
|
|
|
|
selectionChanged: function () {},
|
|
|
|
cycleCell: function (aIndex, aColumn) {},
|
|
|
|
isEditable: function (aIndex, aColumn) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
isSelectable: function (aIndex, aColumn) {
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
setCellValue: function (aIndex, aColumn, aValue) {},
|
|
|
|
setCellText: function (aIndex, aColumn, aValue) {},
|
|
|
|
performAction: function (aAction) {},
|
|
|
|
performActionOnRow: function (aAction, aIndex) {},
|
2007-03-22 10:30:00 -07:00
|
|
|
performActionOnCell: function (aAction, aindex, aColumn) {}
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_makeStrippedHost: function (aHost) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var formattedHost = aHost.charAt(0) == "." ? aHost.substring(1, aHost.length) : aHost;
|
|
|
|
return formattedHost.substring(0, 4) == "www." ? formattedHost.substring(4, formattedHost.length) : formattedHost;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_addCookie: function (aStrippedHost, aCookie, aHostCount) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(aStrippedHost in this._hosts) || !this._hosts[aStrippedHost]) {
|
2009-03-14 06:32:36 -07:00
|
|
|
this._hosts[aStrippedHost] = { cookies : [],
|
2007-03-22 10:30:00 -07:00
|
|
|
rawHost : aStrippedHost,
|
|
|
|
level : 0,
|
|
|
|
open : false,
|
|
|
|
container : true };
|
|
|
|
this._hostOrder.push(aStrippedHost);
|
|
|
|
++aHostCount.value;
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
var c = this._makeCookieObject(aStrippedHost, aCookie);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._hosts[aStrippedHost].cookies.push(c);
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_makeCookieObject: function (aStrippedHost, aCookie) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var host = aCookie.host;
|
|
|
|
var formattedHost = host.charAt(0) == "." ? host.substring(1, host.length) : host;
|
|
|
|
var c = { name : aCookie.name,
|
|
|
|
value : aCookie.value,
|
|
|
|
isDomain : aCookie.isDomain,
|
|
|
|
host : aCookie.host,
|
|
|
|
rawHost : aStrippedHost,
|
|
|
|
path : aCookie.path,
|
|
|
|
isSecure : aCookie.isSecure,
|
|
|
|
expires : aCookie.expires,
|
|
|
|
level : 1,
|
|
|
|
container : false };
|
|
|
|
return c;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_loadCookies: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
var e = this._cm.enumerator;
|
|
|
|
var hostCount = { value: 0 };
|
|
|
|
this._hosts = {};
|
|
|
|
this._hostOrder = [];
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
var cookie = e.getNext();
|
|
|
|
if (cookie && cookie instanceof Components.interfaces.nsICookie) {
|
|
|
|
var strippedHost = this._makeStrippedHost(cookie.host);
|
|
|
|
this._addCookie(strippedHost, cookie, hostCount);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this._view._rowCount = hostCount.value;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
formatExpiresString: function (aExpires) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aExpires) {
|
|
|
|
var date = new Date(1000 * aExpires);
|
|
|
|
return this._ds.FormatDateTime("", this._ds.dateFormatLong,
|
|
|
|
this._ds.timeFormatSeconds,
|
|
|
|
date.getFullYear(),
|
|
|
|
date.getMonth() + 1,
|
|
|
|
date.getDate(),
|
|
|
|
date.getHours(),
|
|
|
|
date.getMinutes(),
|
|
|
|
date.getSeconds());
|
|
|
|
}
|
2009-02-11 20:16:02 -08:00
|
|
|
return this._bundle.getString("expireAtEndOfSession");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_updateCookieData: function (aItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var seln = this._view.selection;
|
|
|
|
var ids = ["name", "value", "host", "path", "isSecure", "expires"];
|
|
|
|
var properties;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aItem && !aItem.container && seln.count > 0) {
|
|
|
|
properties = { name: aItem.name, value: aItem.value, host: aItem.host,
|
|
|
|
path: aItem.path, expires: this.formatExpiresString(aItem.expires),
|
|
|
|
isDomain: aItem.isDomain ? this._bundle.getString("domainColon")
|
|
|
|
: this._bundle.getString("hostColon"),
|
|
|
|
isSecure: aItem.isSecure ? this._bundle.getString("forSecureOnly")
|
|
|
|
: this._bundle.getString("forAnyConnection") };
|
|
|
|
for (var i = 0; i < ids.length; ++i)
|
|
|
|
document.getElementById(ids[i]).disabled = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var noneSelected = this._bundle.getString("noCookieSelected");
|
|
|
|
properties = { name: noneSelected, value: noneSelected, host: noneSelected,
|
2009-03-14 06:32:36 -07:00
|
|
|
path: noneSelected, expires: noneSelected,
|
2007-03-22 10:30:00 -07:00
|
|
|
isSecure: noneSelected };
|
|
|
|
for (i = 0; i < ids.length; ++i)
|
|
|
|
document.getElementById(ids[i]).disabled = true;
|
|
|
|
}
|
|
|
|
for (var property in properties)
|
|
|
|
document.getElementById(property).value = properties[property];
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
onCookieSelected: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
var properties, item;
|
|
|
|
var seln = this._tree.view.selection;
|
2009-03-14 06:32:36 -07:00
|
|
|
if (!this._view._filtered)
|
2007-03-22 10:30:00 -07:00
|
|
|
item = this._view._getItemAtIndex(seln.currentIndex);
|
|
|
|
else
|
|
|
|
item = this._view._filterSet[seln.currentIndex];
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updateCookieData(item);
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var rangeCount = seln.getRangeCount();
|
|
|
|
var selectedCookieCount = 0;
|
|
|
|
for (var i = 0; i < rangeCount; ++i) {
|
|
|
|
var min = {}; var max = {};
|
|
|
|
seln.getRangeAt(i, min, max);
|
|
|
|
for (var j = min.value; j <= max.value; ++j) {
|
|
|
|
item = this._view._getItemAtIndex(j);
|
|
|
|
if (!item) continue;
|
|
|
|
if (item.container && !item.open)
|
|
|
|
selectedCookieCount += item.cookies.length;
|
|
|
|
else if (!item.container)
|
|
|
|
++selectedCookieCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var item = this._view._getItemAtIndex(seln.currentIndex);
|
|
|
|
if (item && seln.count == 1 && item.container && item.open)
|
|
|
|
selectedCookieCount += 2;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2010-01-24 05:48:56 -08:00
|
|
|
var removeCookie = document.getElementById("removeCookie");
|
|
|
|
var removeCookies = document.getElementById("removeCookies");
|
|
|
|
removeCookie.parentNode.selectedPanel =
|
|
|
|
selectedCookieCount == 1 ? removeCookie : removeCookies;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2010-01-24 05:48:56 -08:00
|
|
|
removeCookie.disabled = removeCookies.disabled = !(seln.count > 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2012-02-05 07:09:52 -08:00
|
|
|
performDeletion: function gCookiesWindow_performDeletion(deleteItems) {
|
|
|
|
var psvc = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
var blockFutureCookies = false;
|
|
|
|
if (psvc.prefHasUserValue("network.cookie.blockFutureCookies"))
|
|
|
|
blockFutureCookies = psvc.getBoolPref("network.cookie.blockFutureCookies");
|
|
|
|
for (var i = 0; i < deleteItems.length; ++i) {
|
|
|
|
var item = deleteItems[i];
|
|
|
|
this._cm.remove(item.host, item.name, item.path, blockFutureCookies);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
deleteCookie: function () {
|
2012-08-10 13:20:25 -07:00
|
|
|
// Selection Notes
|
|
|
|
// - Selection always moves to *NEXT* adjacent item unless item
|
|
|
|
// is last child at a given level in which case it moves to *PREVIOUS*
|
|
|
|
// item
|
|
|
|
//
|
|
|
|
// Selection Cases (Somewhat Complicated)
|
|
|
|
//
|
|
|
|
// 1) Single cookie selected, host has single child
|
|
|
|
// v cnn.com
|
|
|
|
// //// cnn.com ///////////// goksdjf@ ////
|
|
|
|
// > atwola.com
|
|
|
|
//
|
|
|
|
// Before SelectedIndex: 1 Before RowCount: 3
|
|
|
|
// After SelectedIndex: 0 After RowCount: 1
|
|
|
|
//
|
|
|
|
// 2) Host selected, host open
|
|
|
|
// v goats.com ////////////////////////////
|
|
|
|
// goats.com sldkkfjl
|
|
|
|
// goat.scom flksj133
|
|
|
|
// > atwola.com
|
|
|
|
//
|
|
|
|
// Before SelectedIndex: 0 Before RowCount: 4
|
|
|
|
// After SelectedIndex: 0 After RowCount: 1
|
|
|
|
//
|
|
|
|
// 3) Host selected, host closed
|
|
|
|
// > goats.com ////////////////////////////
|
|
|
|
// > atwola.com
|
|
|
|
//
|
|
|
|
// Before SelectedIndex: 0 Before RowCount: 2
|
|
|
|
// After SelectedIndex: 0 After RowCount: 1
|
|
|
|
//
|
|
|
|
// 4) Single cookie selected, host has many children
|
|
|
|
// v goats.com
|
|
|
|
// goats.com sldkkfjl
|
|
|
|
// //// goats.com /////////// flksjl33 ////
|
|
|
|
// > atwola.com
|
|
|
|
//
|
|
|
|
// Before SelectedIndex: 2 Before RowCount: 4
|
|
|
|
// After SelectedIndex: 1 After RowCount: 3
|
|
|
|
//
|
|
|
|
// 5) Single cookie selected, host has many children
|
|
|
|
// v goats.com
|
|
|
|
// //// goats.com /////////// flksjl33 ////
|
|
|
|
// goats.com sldkkfjl
|
|
|
|
// > atwola.com
|
|
|
|
//
|
|
|
|
// Before SelectedIndex: 1 Before RowCount: 4
|
|
|
|
// After SelectedIndex: 1 After RowCount: 3
|
2007-03-22 10:30:00 -07:00
|
|
|
var seln = this._view.selection;
|
|
|
|
var tbo = this._tree.treeBoxObject;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (seln.count < 1) return;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var nextSelected = 0;
|
|
|
|
var rowCountImpact = 0;
|
|
|
|
var deleteItems = [];
|
|
|
|
if (!this._view._filtered) {
|
|
|
|
var ci = seln.currentIndex;
|
|
|
|
nextSelected = ci;
|
|
|
|
var invalidateRow = -1;
|
|
|
|
var item = this._view._getItemAtIndex(ci);
|
|
|
|
if (item.container) {
|
|
|
|
rowCountImpact -= (item.open ? item.cookies.length : 0) + 1;
|
|
|
|
deleteItems = deleteItems.concat(item.cookies);
|
2009-03-14 06:32:36 -07:00
|
|
|
if (!this._view.hasNextSibling(-1, ci))
|
2007-03-22 10:30:00 -07:00
|
|
|
--nextSelected;
|
|
|
|
this._view._removeItemAtIndex(ci);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var parent = this._view._getItemAtIndex(item.parentIndex);
|
|
|
|
--rowCountImpact;
|
|
|
|
if (parent.cookies.length == 1) {
|
|
|
|
--rowCountImpact;
|
|
|
|
deleteItems.push(item);
|
|
|
|
if (!this._view.hasNextSibling(-1, ci))
|
|
|
|
--nextSelected;
|
2009-03-14 06:32:36 -07:00
|
|
|
if (!this._view.hasNextSibling(-1, item.parentIndex))
|
2007-03-22 10:30:00 -07:00
|
|
|
--nextSelected;
|
|
|
|
this._view._removeItemAtIndex(item.parentIndex);
|
|
|
|
invalidateRow = item.parentIndex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
deleteItems.push(item);
|
2009-03-14 06:32:36 -07:00
|
|
|
if (!this._view.hasNextSibling(-1, ci))
|
2007-03-22 10:30:00 -07:00
|
|
|
--nextSelected;
|
|
|
|
this._view._removeItemAtIndex(ci);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._view._rowCount += rowCountImpact;
|
|
|
|
tbo.rowCountChanged(ci, rowCountImpact);
|
|
|
|
if (invalidateRow != -1)
|
|
|
|
tbo.invalidateRow(invalidateRow);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var rangeCount = seln.getRangeCount();
|
2012-02-01 07:49:32 -08:00
|
|
|
// Traverse backwards through selections to avoid messing
|
|
|
|
// up the indices when they are deleted.
|
|
|
|
// See bug 388079.
|
|
|
|
for (var i = rangeCount - 1; i >= 0; --i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var min = {}; var max = {};
|
|
|
|
seln.getRangeAt(i, min, max);
|
2009-03-14 06:32:36 -07:00
|
|
|
nextSelected = min.value;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var j = min.value; j <= max.value; ++j) {
|
|
|
|
deleteItems.push(this._view._getItemAtIndex(j));
|
|
|
|
if (!this._view.hasNextSibling(-1, max.value))
|
|
|
|
--nextSelected;
|
|
|
|
}
|
|
|
|
var delta = max.value - min.value + 1;
|
|
|
|
this._view._removeItemAtIndex(min.value, delta);
|
|
|
|
rowCountImpact = -1 * delta;
|
|
|
|
this._view._rowCount += rowCountImpact;
|
|
|
|
tbo.rowCountChanged(min.value, rowCountImpact);
|
|
|
|
}
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2012-02-05 07:09:52 -08:00
|
|
|
this.performDeletion(deleteItems);
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nextSelected < 0)
|
|
|
|
seln.clearSelection();
|
|
|
|
else {
|
|
|
|
seln.select(nextSelected);
|
|
|
|
this._tree.focus();
|
|
|
|
}
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
deleteAllCookies: function () {
|
2012-02-05 07:09:52 -08:00
|
|
|
if (this._view._filtered) {
|
|
|
|
var rowCount = this._view.rowCount;
|
|
|
|
var deleteItems = [];
|
|
|
|
for (var index = 0; index < rowCount; index++) {
|
|
|
|
deleteItems.push(this._view._getItemAtIndex(index));
|
|
|
|
}
|
|
|
|
this._view._removeItemAtIndex(0, rowCount);
|
|
|
|
this._view._rowCount = 0;
|
|
|
|
this._tree.treeBoxObject.rowCountChanged(0, -rowCount);
|
|
|
|
this.performDeletion(deleteItems);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._cm.removeAll();
|
|
|
|
}
|
|
|
|
this._updateRemoveAllButton();
|
|
|
|
this.focusFilterBox();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
onCookieKeyPress: function (aEvent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aEvent.keyCode == 46)
|
|
|
|
this.deleteCookie();
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
_lastSortProperty : "",
|
|
|
|
_lastSortAscending: false,
|
2009-03-14 06:32:36 -07:00
|
|
|
sort: function (aProperty) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var ascending = (aProperty == this._lastSortProperty) ? !this._lastSortAscending : true;
|
|
|
|
// Sort the Non-Filtered Host Collections
|
|
|
|
if (aProperty == "rawHost") {
|
2009-03-14 06:32:36 -07:00
|
|
|
function sortByHost(a, b) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
|
|
}
|
|
|
|
this._hostOrder.sort(sortByHost);
|
|
|
|
if (!ascending)
|
|
|
|
this._hostOrder.reverse();
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
function sortByProperty(a, b) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return a[aProperty].toLowerCase().localeCompare(b[aProperty].toLowerCase());
|
|
|
|
}
|
|
|
|
for (var host in this._hosts) {
|
|
|
|
var cookies = this._hosts[host].cookies;
|
|
|
|
cookies.sort(sortByProperty);
|
|
|
|
if (!ascending)
|
|
|
|
cookies.reverse();
|
|
|
|
}
|
|
|
|
// Sort the Filtered List, if in Filtered mode
|
2009-03-14 06:32:36 -07:00
|
|
|
if (this._view._filtered) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._view._filterSet.sort(sortByProperty);
|
|
|
|
if (!ascending)
|
|
|
|
this._view._filterSet.reverse();
|
|
|
|
}
|
|
|
|
|
2010-10-24 02:05:16 -07:00
|
|
|
// Adjust the Sort Indicator
|
|
|
|
var domainCol = document.getElementById("domainCol");
|
|
|
|
var nameCol = document.getElementById("nameCol");
|
|
|
|
var sortOrderString = ascending ? "ascending" : "descending";
|
|
|
|
if (aProperty == "rawHost") {
|
|
|
|
domainCol.setAttribute("sortDirection", sortOrderString);
|
|
|
|
nameCol.removeAttribute("sortDirection");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nameCol.setAttribute("sortDirection", sortOrderString);
|
|
|
|
domainCol.removeAttribute("sortDirection");
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
this._view._invalidateCache(0);
|
|
|
|
this._view.selection.clearSelection();
|
|
|
|
this._view.selection.select(0);
|
|
|
|
this._tree.treeBoxObject.invalidate();
|
|
|
|
this._tree.treeBoxObject.ensureRowIsVisible(0);
|
|
|
|
|
|
|
|
this._lastSortAscending = ascending;
|
|
|
|
this._lastSortProperty = aProperty;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
clearFilter: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Revert to single-select in the tree
|
|
|
|
this._tree.setAttribute("seltype", "single");
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2008-09-07 09:00:46 -07:00
|
|
|
// Clear the Tree Display
|
2007-03-22 10:30:00 -07:00
|
|
|
this._view._filtered = false;
|
|
|
|
this._view._rowCount = 0;
|
|
|
|
this._tree.treeBoxObject.rowCountChanged(0, -this._view._filterSet.length);
|
|
|
|
this._view._filterSet = [];
|
|
|
|
|
|
|
|
// Just reload the list to make sure deletions are respected
|
|
|
|
this._loadCookies();
|
|
|
|
this._tree.treeBoxObject.view = this._view;
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-11-22 17:43:15 -08:00
|
|
|
// Restore sort order
|
|
|
|
var sortby = this._lastSortProperty;
|
|
|
|
if (sortby == "") {
|
|
|
|
this._lastSortAscending = false;
|
|
|
|
this.sort("rawHost");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._lastSortAscending = !this._lastSortAscending;
|
|
|
|
this.sort(sortby);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Restore open state
|
|
|
|
for (var i = 0; i < this._openIndices.length; ++i)
|
|
|
|
this._view.toggleOpenState(this._openIndices[i]);
|
|
|
|
this._openIndices = [];
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Restore selection
|
|
|
|
this._view.selection.clearSelection();
|
|
|
|
for (i = 0; i < this._lastSelectedRanges.length; ++i) {
|
|
|
|
var range = this._lastSelectedRanges[i];
|
|
|
|
this._view.selection.rangedSelect(range.min, range.max, true);
|
|
|
|
}
|
|
|
|
this._lastSelectedRanges = [];
|
|
|
|
|
|
|
|
document.getElementById("cookiesIntro").value = this._bundle.getString("cookiesAll");
|
2012-02-05 07:09:52 -08:00
|
|
|
this._updateRemoveAllButton();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_cookieMatchesFilter: function (aCookie) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return aCookie.rawHost.indexOf(this._view._filterValue) != -1 ||
|
2009-03-14 06:32:36 -07:00
|
|
|
aCookie.name.indexOf(this._view._filterValue) != -1 ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aCookie.value.indexOf(this._view._filterValue) != -1;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
|
|
|
_filterCookies: function (aFilterValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._view._filterValue = aFilterValue;
|
|
|
|
var cookies = [];
|
|
|
|
for (var i = 0; i < gCookiesWindow._hostOrder.length; ++i) { //var host in gCookiesWindow._hosts) {
|
|
|
|
var currHost = gCookiesWindow._hosts[gCookiesWindow._hostOrder[i]]; // gCookiesWindow._hosts[host];
|
|
|
|
if (!currHost) continue;
|
|
|
|
for (var j = 0; j < currHost.cookies.length; ++j) {
|
|
|
|
var cookie = currHost.cookies[j];
|
|
|
|
if (this._cookieMatchesFilter(cookie))
|
|
|
|
cookies.push(cookie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cookies;
|
|
|
|
},
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
_lastSelectedRanges: [],
|
|
|
|
_openIndices: [],
|
2009-03-14 06:32:36 -07:00
|
|
|
_saveState: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Save selection
|
|
|
|
var seln = this._view.selection;
|
|
|
|
this._lastSelectedRanges = [];
|
|
|
|
var rangeCount = seln.getRangeCount();
|
|
|
|
for (var i = 0; i < rangeCount; ++i) {
|
|
|
|
var min = {}; var max = {};
|
|
|
|
seln.getRangeAt(i, min, max);
|
|
|
|
this._lastSelectedRanges.push({ min: min.value, max: max.value });
|
|
|
|
}
|
2009-03-14 06:32:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Save open states
|
|
|
|
this._openIndices = [];
|
|
|
|
for (i = 0; i < this._view.rowCount; ++i) {
|
|
|
|
var item = this._view._getItemAtIndex(i);
|
|
|
|
if (item && item.container && item.open)
|
|
|
|
this._openIndices.push(i);
|
|
|
|
}
|
|
|
|
},
|
2008-09-07 15:30:29 -07:00
|
|
|
|
2012-02-05 07:09:52 -08:00
|
|
|
_updateRemoveAllButton: function gCookiesWindow__updateRemoveAllButton() {
|
|
|
|
document.getElementById("removeAllCookies").disabled = this._view._rowCount == 0;
|
|
|
|
},
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
filter: function () {
|
2008-09-07 15:30:29 -07:00
|
|
|
var filter = document.getElementById("filter").value;
|
|
|
|
if (filter == "") {
|
|
|
|
gCookiesWindow.clearFilter();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var view = gCookiesWindow._view;
|
|
|
|
view._filterSet = gCookiesWindow._filterCookies(filter);
|
|
|
|
if (!view._filtered) {
|
|
|
|
// Save Display Info for the Non-Filtered mode when we first
|
|
|
|
// enter Filtered mode.
|
|
|
|
gCookiesWindow._saveState();
|
|
|
|
view._filtered = true;
|
|
|
|
}
|
|
|
|
// Move to multi-select in the tree
|
|
|
|
gCookiesWindow._tree.setAttribute("seltype", "multiple");
|
|
|
|
|
|
|
|
// Clear the display
|
|
|
|
var oldCount = view._rowCount;
|
|
|
|
view._rowCount = 0;
|
|
|
|
gCookiesWindow._tree.treeBoxObject.rowCountChanged(0, -oldCount);
|
|
|
|
// Set up the filtered display
|
|
|
|
view._rowCount = view._filterSet.length;
|
|
|
|
gCookiesWindow._tree.treeBoxObject.rowCountChanged(0, view.rowCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-09-07 15:30:29 -07:00
|
|
|
// if the view is not empty then select the first item
|
|
|
|
if (view.rowCount > 0)
|
|
|
|
view.selection.select(0);
|
|
|
|
|
|
|
|
document.getElementById("cookiesIntro").value = gCookiesWindow._bundle.getString("cookiesFiltered");
|
2012-02-05 07:09:52 -08:00
|
|
|
this._updateRemoveAllButton();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
2008-09-07 15:30:29 -07:00
|
|
|
|
2009-03-17 06:08:07 -07:00
|
|
|
setFilter: function (aFilterString) {
|
|
|
|
document.getElementById("filter").value = aFilterString;
|
|
|
|
this.filter();
|
|
|
|
},
|
|
|
|
|
2009-03-14 06:32:36 -07:00
|
|
|
focusFilterBox: function () {
|
2007-03-22 10:30:00 -07:00
|
|
|
var filter = document.getElementById("filter");
|
|
|
|
filter.focus();
|
|
|
|
filter.select();
|
2011-05-14 16:11:48 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onWindowKeyPress: function (aEvent) {
|
|
|
|
if (aEvent.keyCode == KeyEvent.DOM_VK_ESCAPE)
|
|
|
|
window.close();
|
2008-09-07 15:30:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|