[NAVIGATOR] Replace the unused Permissions Manager with a superior one and actually use it

Also, get rid of the obsolete Cookie Manager
custom-2020
Matt A. Tobin 4 years ago committed by Roy Tam
parent 7fbb69e462
commit f5853a8850
  1. 8
      navigator/base/content/navigatorOverlay.xul
  2. 657
      navigator/base/content/permissions/cookieViewer.js
  3. 207
      navigator/base/content/permissions/cookieViewer.xul
  4. 289
      navigator/base/content/permissions/permissionsManager.js
  5. 72
      navigator/base/content/permissions/permissionsManager.xul
  6. 146
      navigator/base/content/permissions/treeUtils.js
  7. 2
      navigator/base/content/pref/pref-images.xul
  8. 2
      navigator/base/content/pref/pref-offlineapps.xul
  9. 2
      navigator/base/content/pref/pref-popups.xul
  10. 2
      navigator/base/content/pref/pref-smartupdate.xul
  11. 28
      navigator/base/content/tasksOverlay.js
  12. 6
      navigator/base/jar.mn
  13. 15
      navigator/components/cookies/jar.mn
  14. 2
      navigator/components/moz.build
  15. 2
      navigator/components/nsSuiteGlue.js
  16. 0
      navigator/components/permissions/content/cookies.css
  17. 0
      navigator/components/permissions/content/cookies.js
  18. 8
      navigator/components/permissions/content/cookies.xul
  19. 15
      navigator/components/permissions/content/permissions.css
  20. 463
      navigator/components/permissions/content/permissions.js
  21. 85
      navigator/components/permissions/content/permissions.xul
  22. 20
      navigator/components/permissions/jar.mn
  23. 0
      navigator/components/permissions/locale/cookies.dtd
  24. 4
      navigator/components/permissions/locale/cookies.properties
  25. 28
      navigator/components/permissions/locale/permissions.dtd
  26. 36
      navigator/components/permissions/locale/permissions.properties
  27. 0
      navigator/components/permissions/moz.build
  28. 46
      navigator/locales/en-US/chrome/common/permissions/cookieViewer.dtd
  29. 30
      navigator/locales/en-US/chrome/common/permissions/cookieViewer.properties
  30. 19
      navigator/locales/en-US/chrome/common/permissions/permissionsManager.dtd
  31. 23
      navigator/locales/en-US/chrome/common/permissions/permissionsManager.properties
  32. 4
      navigator/locales/jar.mn

@ -509,6 +509,10 @@
accesskey="&cookieDisplayCookiesCmd.accesskey;"
oncommand="toCookieManager();
event.stopPropagation();"/>
<menuitem id="menuitem_cookiePermissions"
label="Manage Cookie Permissions"
oncommand="toPermissionsManager('cookie', hostUrl());
event.stopPropagation();"/>
</menupopup>
</menu>
<menu id="menu_imageManager"
@ -543,7 +547,7 @@
<menuitem id="menuitem_imageDisplay"
label="&cookieDisplayImagesCmd.label;"
accesskey="&cookieDisplayImagesCmd.accesskey;"
oncommand="toDataManager(hostUrl() + '|permissions|add|image');
oncommand="toPermissionsManager('image', hostUrl());
event.stopPropagation();"/>
</menupopup>
</menu>
@ -580,7 +584,7 @@
<menuitem id="menuitem_PopupsManage"
label="&popupsManage.label;"
accesskey="&popupsManage.accesskey;"
oncommand="toDataManager(hostUrl() + '|permissions|add|popup');
oncommand="toPermissionsManager('popup', hostUrl());
event.stopPropagation();"
hidden="true"/>
</menupopup>

@ -1,657 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/. */
var kObserverService;
// interface variables
var cookiemanager = null; // cookiemanager interface
var permissionmanager = null; // permissionmanager interface
var promptservice = null; // promptservice interface
var gDateService = null;
// cookies and permissions list
var cookies = [];
var permissions = [];
var allCookies = [];
var deletedCookies = [];
var deletedPermissions = [];
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
const nsICookiePermission = Components.interfaces.nsICookiePermission;
var cookieBundle;
var gUpdatingBatch = "";
function Startup() {
// arguments passed to this routine:
// cookieManager
// xpconnect to cookiemanager/permissionmanager/promptservice interfaces
cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager);
permissionmanager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
promptservice = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
// intialize gDateService
if (!gDateService) {
const nsScriptableDateFormat_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1";
const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat;
gDateService = Components.classes[nsScriptableDateFormat_CONTRACTID]
.getService(nsIScriptableDateFormat);
}
// intialize string bundle
cookieBundle = document.getElementById("cookieBundle");
// load in the cookies and permissions
cookiesTree = document.getElementById("cookiesTree");
permissionsTree = document.getElementById("permissionsTree");
loadCookies();
loadPermissions();
// be prepared to reload the display if anything changes
kObserverService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
kObserverService.addObserver(cookieReloadDisplay, "cookie-changed", false);
kObserverService.addObserver(cookieReloadDisplay, "perm-changed", false);
// filter the table if requested by caller
if (window.arguments &&
window.arguments[0] &&
window.arguments[0].filterString)
setFilter(window.arguments[0].filterString);
document.getElementById("filter").focus();
}
function Shutdown() {
kObserverService.removeObserver(cookieReloadDisplay, "cookie-changed");
kObserverService.removeObserver(cookieReloadDisplay, "perm-changed");
}
var cookieReloadDisplay = {
observe: function(subject, topic, state) {
if (topic == gUpdatingBatch)
return;
if (topic == "cookie-changed") {
allCookies.length = 0;
loadCookies();
} else if (topic == "perm-changed") {
permissions.length = 0;
loadPermissions();
}
}
}
function doSelectAll() {
var elem = document.commandDispatcher.focusedElement;
if (elem && "treeBoxObject" in elem)
elem.view.selection.selectAll();
}
/*** =================== COOKIES CODE =================== ***/
const nsICookie = Components.interfaces.nsICookie;
var cookiesTreeView = {
rowCount : 0,
setTree : function(tree){},
getImageSrc : function(row,column) {},
getProgressMode : function(row,column) {},
getCellValue : function(row,column) {},
getCellText : function(row,column){
var rv="";
switch (column.id) {
case "domainCol":
rv = cookies[row].rawHost;
break;
case "nameCol":
rv = cookies[row].name;
break;
case "expiresCol":
rv = cookies[row].expires;
break;
}
return rv;
},
isSeparator : function(index) {return false;},
isSorted: function() { return false; },
isContainer : function(index) {return false;},
cycleHeader : function(aCol) {},
getRowProperties : function(row) { return ""; },
getColumnProperties : function(column) { return ""; },
getCellProperties : function(row, column) { return ""; }
};
var cookiesTree;
function Cookie(id, host, name, path, originAttributes, value,
isDomain, rawHost, isSecure, expires) {
this.id = id;
this.host = host;
this.name = name;
this.path = path;
this.originAttributes = originAttributes;
this.value = value;
this.isDomain = isDomain;
this.rawHost = rawHost;
this.isSecure = isSecure;
this.expires = GetExpiresString(expires);
this.expiresSortValue = expires;
}
function loadCookies() {
// load cookies into a table
var enumerator = cookiemanager.enumerator;
var count = 0;
while (enumerator.hasMoreElements()) {
var nextCookie = enumerator.getNext();
if (!nextCookie) break;
nextCookie = nextCookie.QueryInterface(Components.interfaces.nsICookie);
var host = nextCookie.host;
allCookies[count] =
new Cookie(count++, host, nextCookie.name,
nextCookie.path, nextCookie.originAttributes,
nextCookie.value, nextCookie.isDomain,
host.charAt(0)=="." ? host.slice(1) : host,
nextCookie.isSecure, nextCookie.expires);
}
// filter, sort and display the table
cookiesTree.view = cookiesTreeView;
filter(document.getElementById("filter").value);
}
function GetExpiresString(expires) {
if (expires) {
var date = new Date(1000*expires);
// if a server manages to set a really long-lived cookie, the dateservice
// can't cope with it properly, so we'll just return a blank string
// see bug 238045 for details
var expiry = "";
try {
expiry = gDateService.FormatDateTime("", gDateService.dateFormatLong,
gDateService.timeFormatSeconds,
date.getFullYear(), date.getMonth()+1,
date.getDate(), date.getHours(),
date.getMinutes(), date.getSeconds());
} catch(ex) {
// do nothing
}
return expiry;
}
return cookieBundle.getString("expireAtEndOfSession");
}
function CookieSelected() {
var selections = GetTreeSelections(cookiesTree);
if (selections.length) {
document.getElementById("removeCookie").removeAttribute("disabled");
} else {
document.getElementById("removeCookie").setAttribute("disabled", "true");
ClearCookieProperties();
return true;
}
var idx = selections[0];
if (idx >= cookies.length) {
// Something got out of synch. See bug 119812 for details
dump("Tree and viewer state are out of sync! " +
"Help us figure out the problem in bug 119812");
return false;
}
var props = [
{id: "ifl_name", value: cookies[idx].name},
{id: "ifl_value", value: cookies[idx].value},
{id: "ifl_isDomain",
value: cookies[idx].isDomain ?
cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")},
{id: "ifl_host", value: cookies[idx].host},
{id: "ifl_path", value: cookies[idx].path},
{id: "ifl_isSecure",
value: cookies[idx].isSecure ?
cookieBundle.getString("forSecureOnly") :
cookieBundle.getString("forAnyConnection")},
{id: "ifl_expires", value: cookies[idx].expires}
];
var value;
var field;
for (let lProp of props)
{
field = document.getElementById(lProp.id);
if ((selections.length > 1) && (lProp.id != "ifl_isDomain")) {
value = ""; // clear field if multiple selections
} else {
value = lProp.value;
}
field.value = value;
}
return true;
}
function ClearCookieProperties() {
var properties =
["ifl_name","ifl_value","ifl_host","ifl_path","ifl_isSecure","ifl_expires"];
for (let prop of properties) {
document.getElementById(prop).value = "";
}
}
function DeleteCookie() {
if (cookiesTreeView.selection.count > 1) {
var title = cookieBundle.getString("deleteSelectedCookiesTitle");
var msg = cookieBundle.getString("deleteSelectedCookies");
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
promptservice.BUTTON_POS_1_DEFAULT)
var yes = cookieBundle.getString("deleteSelectedCookiesYes");
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
return;
}
DeleteSelectedItemFromTree(cookiesTree, cookiesTreeView,
cookies, deletedCookies,
"removeCookie", "removeAllCookies");
if (document.getElementById("filter").value) {
// remove selected cookies from unfiltered set
for (let cookie of deletedCookies) {
allCookies.splice(allCookies.indexOf(cookie), 1);
}
}
if (!cookies.length) {
ClearCookieProperties();
}
FinalizeCookieDeletions();
}
function DeleteAllCookies() {
var title = cookieBundle.getString("deleteAllCookiesTitle");
var msg = cookieBundle.getString("deleteAllCookies");
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
promptservice.BUTTON_POS_1_DEFAULT)
var yes = cookieBundle.getString("deleteAllCookiesYes");
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
return;
ClearCookieProperties();
DeleteAllFromTree(cookiesTree, cookiesTreeView,
cookies, deletedCookies,
"removeCookie", "removeAllCookies");
allCookies.length = 0;
FinalizeCookieDeletions();
}
function FinalizeCookieDeletions() {
gUpdatingBatch = "cookie-changed";
for (let delCookie of deletedCookies) {
cookiemanager.remove(delCookie.host,
delCookie.name,
delCookie.path,
document.getElementById("checkbox").checked,
delCookie.originAttributes);
}
deletedCookies.length = 0;
gUpdatingBatch = "";
}
function HandleCookieKeyPress(e) {
if (e.keyCode == KeyEvent.DOM_VK_DELETE) {
DeleteCookie();
}
}
var lastCookieSortColumn = "rawHost";
var lastCookieSortAscending = true;
function CookieColumnSort(column, updateSelection) {
lastCookieSortAscending =
SortTree(cookiesTree, cookiesTreeView, cookies,
column, lastCookieSortColumn, lastCookieSortAscending,
updateSelection);
lastCookieSortColumn = column;
// set the sortDirection attribute to get the styling going
// first we need to get the right element
var sortedCol;
switch (column) {
case "rawHost":
sortedCol = document.getElementById("domainCol");
break;
case "name":
sortedCol = document.getElementById("nameCol");
break;
case "expires":
sortedCol = document.getElementById("expiresCol");
break;
}
if (lastCookieSortAscending)
sortedCol.setAttribute("sortDirection", "ascending");
else
sortedCol.setAttribute("sortDirection", "descending");
// clear out the sortDirection attribute on the rest of the columns
var currentCol = sortedCol.parentNode.firstChild;
while (currentCol) {
if (currentCol != sortedCol && currentCol.localName == "treecol")
currentCol.removeAttribute("sortDirection");
currentCol = currentCol.nextSibling;
}
}
/*** =================== PERMISSIONS CODE =================== ***/
var permissionsTreeView = {
rowCount : 0,
setTree : function(tree){},
getImageSrc : function(row,column) {},
getProgressMode : function(row,column) {},
getCellValue : function(row,column) {},
getCellText : function(row,column) {
var rv = "";
switch (column.id) {
case "siteCol":
rv = permissions[row].host;
break;
case "siteCol2":
rv = permissions[row].scheme;
break;
case "capabilityCol":
rv = permissions[row].capability;
break;
}
return rv;
},
isSeparator : function(index) {return false;},
isSorted: function() { return false; },
isContainer : function(index) {return false;},
cycleHeader : function(aCol) {},
getRowProperties : function(row) { return ""; },
getColumnProperties : function(column) { return ""; },
getCellProperties : function(row, column) { return ""; }
};
var permissionsTree;
function Permission(id, principal, type, capability) {
this.id = id;
this.principal = principal;
this.host = principal.URI.hostPort;
this.scheme = principal.URI.scheme;
this.type = type;
this.capability = capability;
}
function loadPermissions() {
// load permissions into a table
var enumerator = permissionmanager.enumerator;
var canStr = cookieBundle.getString("can");
var canSessionStr = cookieBundle.getString("canSession");
var cannotStr = cookieBundle.getString("cannot");
while (enumerator.hasMoreElements()) {
var nextPermission = enumerator.getNext();
nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission);
// We are only interested in cookie permissions in this code.
if (nextPermission.type == "cookie") {
// It is currently possible to add a cookie permission for about:xxx and other internal pages.
// They are probably invalid and will be ignored for now.
// Test if the permission has a host.
try {
nextPermission.principal.URI.host;
}
catch (e) {
Components.utils.reportError("Invalid permission found: " +
nextPermission.principal.origin + " " +
nextPermission.type);
continue;
}
var capability;
switch (nextPermission.capability) {
case nsIPermissionManager.ALLOW_ACTION:
capability = canStr;
break;
case nsIPermissionManager.DENY_ACTION:
capability = cannotStr;
break;
case nsICookiePermission.ACCESS_SESSION:
capability = canSessionStr;
break;
default:
continue;
}
permissions.push(new Permission(permissions.length,
nextPermission.principal,
nextPermission.type,
capability));
}
}
permissionsTreeView.rowCount = permissions.length;
// sort and display the table
permissionsTree.view = permissionsTreeView;
permissionsTreeView.selection.select(-1);
SortTree(permissionsTree, permissionsTreeView, permissions,
lastPermissionSortColumn, lastPermissionSortColumn,
!lastPermissionSortAscending);
// disable "remove all" button if there are no cookies
if (permissions.length == 0) {
document.getElementById("removeAllPermissions").setAttribute("disabled", "true");
} else {
document.getElementById("removeAllPermissions").removeAttribute("disabled");
}
}
function PermissionSelected() {
var selections = GetTreeSelections(permissionsTree);
if (selections.length)
document.getElementById("removePermission").removeAttribute("disabled");
else
document.getElementById("removePermission").setAttribute("disabled", "true");
}
function DeletePermission() {
if (permissionsTreeView.selection.count > 1) {
var title = cookieBundle.getString("deleteSelectedSitesTitle");
var msg = cookieBundle.getString("deleteSelectedCookiesSites");
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
promptservice.BUTTON_POS_1_DEFAULT)
var yes = cookieBundle.getString("deleteSelectedSitesYes");
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
return;
}
DeleteSelectedItemFromTree(permissionsTree, permissionsTreeView,
permissions, deletedPermissions,
"removePermission", "removeAllPermissions");
FinalizePermissionDeletions();
}
function setCookiePermissions(action) {
var site = document.getElementById('cookie-site');
// let the backend do the validation
try {
var url = new URL(site.value);
} catch (e) {
// show an error if URL is invalid
window.alert(cookieBundle.getString("allowedURLSchemes"));
return;
}
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
try {
var uri = ioService.newURI(url, null, null);
} catch (e) {
// show an error if URI can not be constructed or adding it failed
window.alert(cookieBundle.getString("errorAddPermission"));
return;
}
// only allow a few schemes here
// others like file:// would produce an invalid entry in the database
if (uri.scheme != 'http' &&
uri.scheme != 'https') {
// show an error if uri uses invalid scheme
window.alert(uri.scheme + ": " + cookieBundle.getString("allowedURLSchemes"));
return;
}
if (permissionmanager.testPermission(uri, "cookie") != action)
permissionmanager.add(uri, "cookie", action);
site.focus();
site.value = "";
}
function buttonEnabling(textfield) {
// trim any leading space
var site = textfield.value.replace(/^\s*([-\w]*:\/+)?/, "");
var block = document.getElementById("btnBlock");
var session = document.getElementById("btnSession");
var allow = document.getElementById("btnAllow");
block.disabled = !site;
session.disabled = !site;
allow.disabled = !site;
}
function DeleteAllPermissions() {
var title = cookieBundle.getString("deleteAllSitesTitle");
var msg = cookieBundle.getString("deleteAllCookiesSites");
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
promptservice.BUTTON_POS_1_DEFAULT)
var yes = cookieBundle.getString("deleteAllSitesYes");
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
return;
DeleteAllFromTree(permissionsTree, permissionsTreeView,
permissions, deletedPermissions,
"removePermission", "removeAllPermissions");
FinalizePermissionDeletions();
}
function FinalizePermissionDeletions() {
if (!deletedPermissions.length)
return;
gUpdatingBatch = "perm-changed";
for (let permission of deletedPermissions)
permissionmanager.removeFromPrincipal(permission.principal, permission.type);
deletedPermissions.length = 0;
gUpdatingBatch = "";
}
function HandlePermissionKeyPress(e) {
if (e.keyCode == 46) {
DeletePermission();
}
}
var lastPermissionSortColumn = "host";
var lastPermissionSortAscending = true;
function PermissionColumnSort(column, updateSelection) {
lastPermissionSortAscending =
SortTree(permissionsTree, permissionsTreeView, permissions,
column, lastPermissionSortColumn, lastPermissionSortAscending,
updateSelection);
lastPermissionSortColumn = column;
// make sure sortDirection is set
var sortedCol;
switch (column) {
case "host":
sortedCol = document.getElementById("siteCol");
break;
case "scheme":
sortedCol = document.getElementById("siteCol2");
break;
case "capability":
sortedCol = document.getElementById("capabilityCol");
break;
}
if (lastPermissionSortAscending)
sortedCol.setAttribute("sortDirection", "ascending");
else
sortedCol.setAttribute("sortDirection", "descending");
// clear out the sortDirection attribute on the rest of the columns
var currentCol = sortedCol.parentNode.firstChild;
while (currentCol) {
if (currentCol != sortedCol && currentCol.localName == "treecol")
currentCol.removeAttribute("sortDirection");
currentCol = currentCol.nextSibling;
}
}
/*** ============ CODE FOR HELP BUTTON =================== ***/
function doHelpButton()
{
var selTab = document.getElementById('tabbox').selectedTab;
var key = selTab.getAttribute('help');
openHelp(key, 'chrome://communicator/locale/help/suitehelp.rdf');
}
/*** =================== FILTER CODE =================== ***/
function filterCookies(aFilterValue)
{
var filterSet = [];
for (let cookie of allCookies) {
if (cookie.rawHost.indexOf(aFilterValue) != -1 ||
cookie.name.indexOf(aFilterValue) != -1 ||
cookie.value.indexOf(aFilterValue) != -1)
filterSet.push(cookie);
}
return filterSet;
}
function filter(filter)
{
// clear the display
var oldCount = cookiesTreeView.rowCount;
cookiesTreeView.rowCount = 0;
cookiesTree.treeBoxObject.rowCountChanged(0, -oldCount);
// set up the display
cookies = filter ? filterCookies(filter) : allCookies;
cookiesTreeView.rowCount = cookies.length;
cookiesTree.treeBoxObject.rowCountChanged(0, cookiesTreeView.rowCount);
// sort the tree according to the last sort parameters
SortTree(cookiesTree, cookiesTreeView, cookies, lastCookieSortColumn,
lastCookieSortColumn, !lastCookieSortAscending);
// disable Remove All Cookies button if the view is filtered or there are no cookies
if (filter || !cookies.length)
document.getElementById("removeAllCookies").setAttribute("disabled", "true");
else
document.getElementById("removeAllCookies").removeAttribute("disabled");
// if the view is filtered and not empty then select the first item
if (filter && cookies.length)
cookiesTreeView.selection.select(0);
}
function setFilter(aFilterString)
{
document.getElementById("filter").value = aFilterString;
filter(aFilterString);
}
function focusFilterBox()
{
var filterBox = document.getElementById("filter");
filterBox.focus();
filterBox.select();
}

@ -1,207 +0,0 @@
<?xml version="1.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/. -->
<!-- CHANGE THIS WHEN MOVING FILES -->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<!-- CHANGE THIS WHEN MOVING FILES -->
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/permissions/cookieViewer.dtd" >
<dialog id="cookieviewer"
buttons="help"
title="&windowtitle.label;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
windowtype="mozilla:cookieviewer"
style="width: 65ch; height: 42em;"
onload="Startup()"
onunload="Shutdown()"
ondialoghelp="doHelpButton();"
persist="screenX screenY width height">
<script type="application/javascript"
src="chrome://communicator/content/permissions/cookieViewer.js"/>
<script type="application/javascript"
src="chrome://communicator/content/permissions/treeUtils.js"/>
<script type="application/javascript"
src="chrome://help/content/contextHelp.js" />
<keyset id="dialogKeys">
<key key="&focusSearch.key;"
modifiers="accel"
oncommand="focusFilterBox();"/>
<key key="&selectAll.key;"
modifiers="accel"
oncommand="doSelectAll();"/>
</keyset>
<stringbundle id="cookieBundle"
src="chrome://communicator/locale/permissions/cookieViewer.properties"/>
<tabbox id="tabbox" flex="1">
<tabs>
<tab id="cookiesTab" label="&tab.cookiesonsystem.label;" help="cookies_stored"/>
<tab id="permissionsTab" label="&tab.bannedservers.label;" help="cookie_sites"/>
</tabs>
<tabpanels id="panel" flex="1">
<vbox class="tabpanel" id="system" flex="1">
<vbox id="dummyContainer" flex="1">
<!-- filter -->
<hbox align="center">
<textbox id="filter"
flex="1"
type="search"
aria-controls="cookiesTree"
placeholder="&search.placeholder;"
oncommand="filter(this.value);"/>
</hbox>
<separator class="thin"/>
<label value="&div.cookiesonsystem.label;" control="cookiesTree"/>
<separator class="thin"/>
<tree id="cookiesTree" flex="1" style="height: 10em;"
onkeypress="HandleCookieKeyPress(event)"
onselect="CookieSelected();">
<treecols>
<treecol id="domainCol" label="&treehead.cookiedomain.label;" flex="5"
onclick="CookieColumnSort('rawHost', true);" persist="width hidden"
sortDirection="ascending"/>
<splitter class="tree-splitter"/>
<treecol id="nameCol" label="&treehead.cookiename.label;" flex="5"
onclick="CookieColumnSort('name', true);" persist="width hidden"/>
<splitter class="tree-splitter"/>
<treecol id="expiresCol" label="&treehead.cookieexpires.label;" flex="10"
hidden="true" onclick="CookieColumnSort('expires', true);" persist="width hidden"/>
</treecols>
<treechildren/>
</tree>
<groupbox>
<caption label="&treehead.infoselected.label;"/>
<!-- labels -->
<grid flex="1">
<columns>
<column/>
<column flex="1"/>
</columns>
<rows>
<row align="center">
<hbox align="center" pack="end">
<label value="&props.name.label;" control="ifl_name"/>
</hbox>
<textbox id="ifl_name" readonly="true" class="plain"/>
</row>
<row align="center">
<hbox align="center" pack="end">
<label value="&props.value.label;" control="ifl_value"/>
</hbox>
<textbox id="ifl_value" readonly="true" class="plain"/>
</row>
<row align="center">
<hbox align="center" pack="end">
<label id="ifl_isDomain" value="&props.domain.label;" control="ifl_host"/>
</hbox>
<textbox id="ifl_host" readonly="true" class="plain"/>
</row>
<row align="center">
<hbox align="center" pack="end">
<label value="&props.path.label;" control="ifl_path"/>
</hbox>
<textbox id="ifl_path" readonly="true" class="plain"/>
</row>
<row align="center">
<hbox align="center" pack="end">
<label value="&props.secure.label;" control="ifl_isSecure"/>
</hbox>
<textbox id="ifl_isSecure" readonly="true" class="plain"/>
</row>
<row align="center">
<hbox align="center" pack="end">
<label value="&props.expires.label;" control="ifl_expires"/>
</hbox>
<textbox id="ifl_expires" readonly="true" class="plain"/>
</row>
</rows>
</grid>
</groupbox>
<hbox>
<button id="removeCookie" disabled="true"
label="&button.removecookie.label;"
accesskey="&button.removecookie.accesskey;"
oncommand="DeleteCookie();"/>
<button id="removeAllCookies"
label="&button.removeallcookies.label;"
accesskey="&button.removeallcookies.accesskey;"
oncommand="DeleteAllCookies();"/>
<!-- todo: <button id="restoreCookies" class="dialog push" disabled="true" label="&button.restorecookie.label;" oncommand="RestoreCookies();"/> -->
</hbox>
<separator class="thin"/>
<hbox align="start">
<checkbox id="checkbox" label="&futureCookies.label;" accesskey="&futureCookies.accesskey;" persist="checked"/>
</hbox>
</vbox>
</vbox>
<vbox id="servers" flex="1">
<description id="permissionsText">&div.bannedservers.label;</description>
<separator class="thin"/>
<hbox>
<textbox id="cookie-site" flex="1" oninput="buttonEnabling(this);"/>
<button id="btnBlock" label="&blockSite.label;" disabled="true"
accesskey="&blockSite.accesskey;"
oncommand="setCookiePermissions(nsIPermissionManager.DENY_ACTION);"/>
<button id="btnSession" label="&allowSiteSession.label;" disabled="true"
accesskey="&allowSiteSession.accesskey;"
oncommand="setCookiePermissions(nsICookiePermission.ACCESS_SESSION);"/>
<button id="btnAllow" label="&allowSite.label;" disabled="true"
accesskey="&allowSite.accesskey;"
oncommand="setCookiePermissions(nsIPermissionManager.ALLOW_ACTION);"/>
</hbox>
<separator class="thin"/>
<tree id="permissionsTree"
flex="1"
style="height: 10em;"
hidecolumnpicker="true"
onkeypress="HandlePermissionKeyPress(event)"
onselect="PermissionSelected();">
<treecols>
<treecol id="siteCol"
label="&treehead.sitename.label;"
flex="5"
onclick="PermissionColumnSort('host', true);" persist="width"
sortDirection="ascending"/>
<splitter class="tree-splitter"/>
<treecol id="siteCol2" label="&treehead.scheme.label;"
flex="5"
onclick="PermissionColumnSort('scheme', true);"
persist="width"/>
<splitter class="tree-splitter"/>
<treecol id="capabilityCol"
label="&treehead.status.label;"
flex="5"
onclick="PermissionColumnSort('capability', true);"
persist="width"/>
</treecols>
<treechildren/>
</tree>
<hbox>
<button id="removePermission"
disabled="true"
label="&removepermission.label;"
accesskey="&removepermission.accesskey;"
oncommand="DeletePermission();"/>
<button id="removeAllPermissions"
label="&removeallpermissions.label;"
accesskey="&removeallpermissions.accesskey;"
oncommand="DeleteAllPermissions();"/>
</hbox>
</vbox>
</tabpanels>
</tabbox>
</dialog>

@ -1,289 +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/. */
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
const nsICookiePermission = Components.interfaces.nsICookiePermission;
var permissionManager;
var additions = [];
var removals = [];
var sortColumn;
var sortAscending;
var permissionsTreeView = {
rowCount: 0,
setTree: function(tree) {},
getImageSrc: function(row, column) {},
getProgressMode: function(row, column) {},
getCellValue: function(row, column) {},
getCellText: function(row, column) {
if (column.id == "siteCol")
return additions[row].rawHost;
else if (column.id == "statusCol")
return additions[row].capability;
return "";
},
isSeparator: function(index) { return false; },
isSorted: function() { return false; },
isContainer: function(index) { return false; },
cycleHeader: function(column) {},
getRowProperties: function(row, column) { return ""; },
getColumnProperties: function(column) { return ""; },
getCellProperties: function(row, column) { return ""; }
};
var permissionsTree;
var permissionType = "popup";
var gManageCapability;
var permissionsBundle;
function Startup() {
var introText, windowTitle;
permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(nsIPermissionManager);
permissionsTree = document.getElementById("permissionsTree");
permissionsBundle = document.getElementById("permissionsBundle");
sortAscending = (permissionsTree.getAttribute("sortAscending") == "true");
sortColumn = permissionsTree.getAttribute("sortColumn");
if (window.arguments && window.arguments[0]) {
var params = window.arguments[0];
document.getElementById("btnBlock").hidden = !params.blockVisible;
document.getElementById("btnSession").hidden = !params.sessionVisible;
document.getElementById("btnAllow").hidden = !params.allowVisible;
setHost(params.prefilledHost);
permissionType = params.permissionType;
gManageCapability = params.manageCapability;
introText = params.introText;
windowTitle = params.windowTitle;
}
document.getElementById("permissionsText").textContent = introText ||
permissionsBundle.getString(permissionType + "permissionstext");
document.title = windowTitle ||
permissionsBundle.getString(permissionType + "permissionstitle");
var dialogElement = document.getElementById("permissionsManager");
dialogElement.setAttribute("windowtype", "permissions-" + permissionType);
var urlFieldVisible = params.blockVisible ||
params.sessionVisible ||
params.allowVisible;
document.getElementById("url").hidden = !urlFieldVisible;
document.getElementById("urlLabel").hidden = !urlFieldVisible;
handleHostInput(document.getElementById("url"));
loadPermissions();
}
function onAccept() {
finalizeChanges();
permissionsTree.setAttribute("sortAscending", !sortAscending);
permissionsTree.setAttribute("sortColumn", sortColumn);
return true;
}
function setHost(aHost) {
document.getElementById("url").value = aHost;
}
function Permission(id, host, rawHost, type, capability, perm) {
this.id = id;
this.host = host;
this.rawHost = rawHost;
this.type = type;
this.capability = capability;
this.perm = perm;
}
function handleHostInput(aSiteField) {
// trim any leading and trailing spaces and scheme
// and set buttons appropiately
btnDisable(!trimSpacesAndScheme(aSiteField.value));
}
function trimSpacesAndScheme(aString) {
if (!aString)
return "";
return aString.trim().replace(/([-\w]*:\/+)?/, "");
}
function btnDisable(aDisabled) {
document.getElementById("btnSession").disabled = aDisabled;
document.getElementById("btnBlock").disabled = aDisabled;
document.getElementById("btnAllow").disabled = aDisabled;
}
function loadPermissions() {
var enumerator = permissionManager.enumerator;
var count = 0;
var permission;
try {
while (enumerator.hasMoreElements()) {
permission = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
if (permission.type == permissionType &&
(!gManageCapability || permission.capability == gManageCapability))
permissionPush(count++, permission.host, permission.type,
capabilityString(permission.capability), permission.capability);
}
} catch(ex) {
}
permissionsTreeView.rowCount = additions.length;
// sort and display the table
permissionsTree.view = permissionsTreeView;
permissionColumnSort(sortColumn, false);
// disable "remove all" button if there are none
document.getElementById("removeAllPermissions").disabled = additions.length == 0;
}
function capabilityString(aCapability) {
var capability = null;
switch (aCapability) {
case nsIPermissionManager.ALLOW_ACTION:
capability = "can";
break;
case nsIPermissionManager.DENY_ACTION:
capability = "cannot";
break;
// we should only ever hit this for cookies
case nsICookiePermission.ACCESS_SESSION:
capability = "canSession";
break;
default:
break;
}
return permissionsBundle.getString(capability);
}
function permissionPush(aId, aHost, aType, aString, aCapability) {
var rawHost = (aHost.charAt(0) == ".") ? aHost.substring(1, aHost.length) : aHost;
var p = new Permission(aId, aHost, rawHost, aType, aString, aCapability);
additions.push(p);
}
function permissionColumnSort(aColumn, aUpdateSelection) {
sortAscending =
SortTree(permissionsTree, permissionsTreeView, additions,
aColumn, sortColumn, sortAscending, aUpdateSelection);
sortColumn = aColumn;
}
function permissionSelected() {
if (permissionManager) {
var selections = GetTreeSelections(permissionsTree);
document.getElementById("removePermission").disabled = (selections.length < 1);
}
}
function deletePermissions() {
DeleteSelectedItemFromTree(permissionsTree, permissionsTreeView, additions, removals,
"removePermission", "removeAllPermissions");
}
function deleteAllPermissions() {
DeleteAllFromTree(permissionsTree, permissionsTreeView, additions, removals,
"removePermission", "removeAllPermissions");
}
function finalizeChanges() {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var i, p;
for (i in removals) {
p = removals[i];
try {
permissionManager.remove(p.host, p.type);
} catch(ex) {
}
}
for (i in additions) {
p = additions[i];
try {
var uri = ioService.newURI("http://" + p.host, null, null);
permissionManager.add(uri, p.type, p.perm);
} catch(ex) {
}
}
}
function handlePermissionKeyPress(e) {
if (e.keyCode == 46) {
deletePermissions();
}
}
function addPermission(aPermission) {
var textbox = document.getElementById("url");
// trim any leading and trailing spaces and scheme
var host = trimSpacesAndScheme(textbox.value);
try {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI("http://" + host, null, null);
host = uri.host;
} catch(ex) {
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var message = permissionsBundle.getFormattedString("alertInvalid", [host]);
var title = permissionsBundle.getString("alertInvalidTitle");
promptService.alert(window, title, message);
textbox.value = "";
textbox.focus();
handleHostInput(textbox);
return;
}
// we need this whether the perm exists or not
var stringCapability = capabilityString(aPermission);
// check whether the permission already exists, if not, add it
var exists = false;
for (var i in additions) {
if (additions[i].rawHost == host) {
// Avoid calling the permission manager if the capability settings are
// the same. Otherwise allow the call to the permissions manager to
// update the listbox for us.
exists = additions[i].perm == aPermission;
break;
}
}
if (!exists) {
permissionPush(additions.length, host, permissionType, stringCapability, aPermission);
permissionsTreeView.rowCount = additions.length;
permissionsTree.treeBoxObject.rowCountChanged(additions.length - 1, 1);
permissionsTree.treeBoxObject.ensureRowIsVisible(additions.length - 1);
}
textbox.value = "";
textbox.focus();
// covers a case where the site exists already, so the buttons don't disable
handleHostInput(textbox);
// enable "remove all" button as needed
document.getElementById("removeAllPermissions").disabled = additions.length == 0;
}
function doHelpButton() {
openHelp(permissionsBundle.getString(permissionType + "permissionshelp"), "chrome://communicator/locale/help/suitehelp.rdf");
return true;
}

@ -1,72 +0,0 @@
<?xml version="1.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/. -->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://communicator/locale/permissions/permissionsManager.dtd" >
<dialog id="permissionsManager"
buttons="accept,cancel,help"
windowtype="exceptions"
title="&windowtitle.label;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
style="width:32em; height:42em;"
persist="width height screenX screenY"
onload="Startup();"
ondialogaccept="return onAccept();"
ondialoghelp="return doHelpButton();">
<script type="application/javascript" src="chrome://communicator/content/permissions/permissionsManager.js"/>
<script type="application/javascript" src="chrome://communicator/content/permissions/treeUtils.js"/>
<script type="application/javascript" src="chrome://help/content/contextHelp.js"/>
<stringbundle id="permissionsBundle"
src="chrome://communicator/locale/permissions/permissionsManager.properties"/>
<description id="permissionsText"/>
<separator class="thin"/>
<label id="urlLabel"
value="&address.label;"
accesskey="&address.accesskey;"
control="url"/>
<hbox align="start">
<textbox id="url" flex="1" oninput="handleHostInput(event.target);"/>
</hbox>
<hbox pack="end">
<button id="btnBlock" disabled="true" accesskey="&block.accesskey;"
label="&block.label;" oncommand="addPermission(nsIPermissionManager.DENY_ACTION);"/>
<button id="btnSession" disabled="true" accesskey="&session.accesskey;"
label="&session.label;" oncommand="addPermission(nsICookiePermission.ACCESS_SESSION);"/>
<button id="btnAllow" disabled="true" accesskey="&allow.accesskey;"
label="&allow.label;" oncommand="addPermission(nsIPermissionManager.ALLOW_ACTION);"/>
</hbox>
<separator class="thin"/>
<tree id="permissionsTree" flex="1" style="height: 18em;"
hidecolumnpicker="true"
onkeypress="handlePermissionKeyPress(event)"
onselect="permissionSelected();"
sortAscending="false"
sortColumn="rawHost"
persist="sortAscending sortColumn">
<treecols>
<treecol id="siteCol" label="&treehead.sitename.label;" flex="3"
onclick="permissionColumnSort('rawHost', true);" persist="width"/>
<splitter class="tree-splitter"/>
<treecol id="statusCol" label="&treehead.status.label;" flex="1"
onclick="permissionColumnSort('capability', true);" persist="width"/>
</treecols>
<treechildren/>
</tree>
<separator class="thin"/>
<hbox>
<button id="removePermission" disabled="true"
label="&remove.label;" accesskey="&remove.accesskey;"
oncommand="deletePermissions();"/>
<button id="removeAllPermissions"
label="&removeall.label;" accesskey="&removeall.accesskey;"
oncommand="deleteAllPermissions();"/>
</hbox>
</dialog>

@ -1,146 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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/. */
function DeleteAllFromTree
(tree, view, table, deletedTable, removeButton, removeAllButton) {
// remove all items from table and place in deleted table
for (var i=0; i<table.length; i++) {
deletedTable[deletedTable.length] = table[i];
}
table.length = 0;
// redisplay
var oldCount = view.rowCount;
view.rowCount = 0;
tree.treeBoxObject.rowCountChanged(0, -oldCount);
// disable buttons
document.getElementById(removeButton).setAttribute("disabled", "true")
document.getElementById(removeAllButton).setAttribute("disabled","true");
}
function DeleteSelectedItemFromTree
(tree, view, table, deletedTable, removeButton, removeAllButton) {
// Turn off tree selection notifications during the deletion
tree.view.selection.selectEventsSuppressed = true;
// remove selected items from list (by setting them to null) and place in deleted list
var selections = GetTreeSelections(tree);
for (var s=selections.length-1; s>= 0; s--) {
var i = selections[s];
deletedTable[deletedTable.length] = table[i];
table[i] = null;
}
// collapse list by removing all the null entries
for (var j=0; j<table.length; j++) {
if (table[j] == null) {
var k = j;
while ((k < table.length) && (table[k] == null)) {
k++;
}
table.splice(j, k-j);
view.rowCount -= k - j;
tree.treeBoxObject.rowCountChanged(j, j - k);
}
}
// update selection and/or buttons
if (table.length) {
// update selection
var nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1;
tree.view.selection.select(nextSelection);
tree.treeBoxObject.ensureRowIsVisible(nextSelection);
} else {
// disable buttons
document.getElementById(removeButton).setAttribute("disabled", "true")
document.getElementById(removeAllButton).setAttribute("disabled","true");
}
tree.view.selection.selectEventsSuppressed = false;
}
function GetTreeSelections(tree) {
var selections = [];
var select = tree.view.selection;
if (select) {
var count = select.getRangeCount();
var min = new Object();
var max = new Object();
for (var i=0; i<count; i++) {
select.getRangeAt(i, min, max);
for (var k=min.value; k<=max.value; k++) {
if (k != -1) {
selections[selections.length] = k;
}
}
}
}
return selections;
}
function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, updateSelection) {
// remember which item was selected so we can restore it after the sort
var selections = GetTreeSelections(tree);
var selectedNumber = selections.length ? table[selections[0]].id : -1;
// determine if sort is to be ascending or descending
var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
// do the sort or re-sort
// this is a temporary hack for 1.7, we should implement
// display and sort variables here for trees in general
var compareFunc;
if (column == "expires") {
compareFunc = function compare(first, second) {
if (first.expiresSortValue > second.expiresSortValue)
return 1;
else if (first.expiresSortValue < second.expiresSortValue)
return -1;
else
return 0;
}
} else {
compareFunc = function compare(first, second) {
return first[column].toLowerCase().localeCompare(second[column].toLowerCase());
}
}
table.sort(compareFunc);
if (!ascending)
table.reverse();
// restore the selection
var selectedRow = -1;
if (selectedNumber>=0 && updateSelection) {
for (var s=0; s<table.length; s++) {
if (table[s].id == selectedNumber) {
// update selection