From f3c248ff76049b4ee51d37dec8914ae33eb9c9dc Mon Sep 17 00:00:00 2001
From: "morse%netscape.com"
Date: Sun, 26 Sep 1999 09:43:43 +0000
Subject: [PATCH] fix cookieviewer bugs 14703 and 14916, approved chofmann
---
.../wallet/cookieviewer/CookieViewer.dtd | 2 +-
.../wallet/cookieviewer/CookieViewer.js | 549 ++++++++----------
.../cookieviewer/CookieViewer.properties | 37 +-
.../wallet/cookieviewer/CookieViewer.xul | 189 ++++--
.../wallet/cookieviewer/nsCookieViewer.cpp | 16 -
5 files changed, 411 insertions(+), 382 deletions(-)
diff --git a/extensions/wallet/cookieviewer/CookieViewer.dtd b/extensions/wallet/cookieviewer/CookieViewer.dtd
index 70a4df4d473..f19df75e942 100644
--- a/extensions/wallet/cookieviewer/CookieViewer.dtd
+++ b/extensions/wallet/cookieviewer/CookieViewer.dtd
@@ -9,7 +9,7 @@
-
+
diff --git a/extensions/wallet/cookieviewer/CookieViewer.js b/extensions/wallet/cookieviewer/CookieViewer.js
index fef95a99cba..420f29ef494 100644
--- a/extensions/wallet/cookieviewer/CookieViewer.js
+++ b/extensions/wallet/cookieviewer/CookieViewer.js
@@ -1,313 +1,274 @@
- /* for localization */
- var Bundle = srGetStrBundle("chrome://wallet/locale/CookieViewer.properties");
- var siteCookiename = Bundle.GetStringFromName("siteCookiename");
- var cookiesTab = Bundle.GetStringFromName("cookiesTab");
- var permissionsTab = Bundle.GetStringFromName("permissionsTab");
- var cookiesStored = Bundle.GetStringFromName("cookiesStored");
- var name = Bundle.GetStringFromName("name");
- var value = Bundle.GetStringFromName("value");
- var path = Bundle.GetStringFromName("path");
- var secure = Bundle.GetStringFromName("secure");
- var expires = Bundle.GetStringFromName("expires");
- var permissionsStored = Bundle.GetStringFromName("permissionsStored");
- var removeCmdLabel = Bundle.GetStringFromName("removeCmdLabel");
- var okCmdLabel = Bundle.GetStringFromName("okCmdLabel");
- var cancelCmdLabel = Bundle.GetStringFromName("cancelCmdLabel");
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * The contents of this file are subject to the Netscape Public License
+ * Version 1.0 (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/NPL/
+ *
+ * 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 Mozilla Communicator client code, released March
+ * 31, 1998.
+ *
+ * The Initial Developer of the Original Code is Netscape Communications
+ * Corporation. Portions created by Netscape are Copyright (C) 1998
+ * Netscape Communications Corporation. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Ben Goodger
+ */
- /* for xpconnect */
- var cookieviewer =
- Components.classes
- ["component://netscape/cookieviewer/cookieviewer-world"].createInstance();
- cookieviewer = cookieviewer.QueryInterface(Components.interfaces.nsICookieViewer);
+/*
+ * The cookieList is a sequence of items separated by the BREAK character. These
+ * items are:
+ * empty
+ * number for first cookie
+ * name for first cookie
+ * value for first cookie
+ * domain indicator ("Domain" or "Host") for first cookie
+ * domain or host name for first cookie
+ * path for first cookie
+ * secure indicator ("Yes" or "No") for first cookie
+ * expiration for first cookie
+ * with the eight items above repeated for each successive cookie
+ */
- function DoGetCookieList()
- {
- return cookieviewer.GetCookieValue();
- }
+// global variables
+var cookieviewer = null; // cookieviewer interface
+var cookieList = []; // array of cookies (OLD STREAM)
+var cookies = []; // array of cookeis (NEW OBJECT)
+var permissionList = []; // array of permissions (OLD STREAM)
+var permissions = []; // array of permissions (NEW OBJECT)
+var deleted_cookies = [];
+var deleted_permissions = [];
+// for dealing with the interface:
+var gone_c = "";
+var gone_p = "";
+// string bundle
+var bundle = null;
+// CHANGE THIS WHEN MOVING FILES - strings localization file!
+var JS_STRINGS_FILE = "chrome://wallet/locale/CookieViewer.properties";
+
+// function : ::Startup();
+// purpose : initialises the cookie viewer dialog
+function Startup()
+{
+ // xpconnect to cookieviewer interface
+ cookieviewer = Components.classes["component://netscape/cookieviewer/cookieviewer-world"].createInstance();
+ cookieviewer = cookieviewer.QueryInterface(Components.interfaces.nsICookieViewer);
+ // intialise string bundle for
+ bundle = srGetStrBundle(JS_STRINGS_FILE);
+
+ loadCookies();
+ loadPermissions();
+ doSetOKCancel(onOK, null);
+}
- function DoGetPermissionList()
- {
- return cookieviewer.GetPermissionValue();
- }
+/*** =================== COOKIES CODE =================== ***/
- function DoSave(value)
- {
- cookieviewer.SetValue(value, window);
- }
- /* end of xpconnect stuff */
+// function : ::CreateCookieList();
+// purpose : creates an array of cookie objects from the cookie stream
+function CreateCookieList()
+{
+ count = 0;
+ for(i = 1; i < cookieList.length; i+=8)
+ {
+ cookies[count] = new Cookie();
+ cookies[count].number = cookieList[i+0];
+ cookies[count].name = cookieList[i+1];
+ cookies[count].value = cookieList[i+2];
+ cookies[count].domaintype = cookieList[i+3];
+ cookies[count].domain = cookieList[i+4];
+ cookies[count].path = cookieList[i+5];
+ cookies[count].secure = cookieList[i+6];
+ cookies[count].expire = cookieList[i+7];
+ count++;
+ }
+}
- index_frame = 0;
- title_frame = 1;
- spacer1_frame = 2;
- list_frame = 3;
- spacer2_frame = 4;
- prop_frame = 5;
- spacer3_frame = 6;
- button_frame = 7;
+// function : ::Cookie();
+// purpose : an home-brewed object that represents a individual cookie in the stream
+function Cookie(number,name,value,domaintype,domain,path,secure,expire)
+{
+ this.number = (arguments.length) ? number : null;
+ this.name = (arguments.length) ? name : null;
+ this.value = (arguments.length) ? value : null;
+ this.domaintype = (arguments.length) ? domaintype : null;
+ this.domain = (arguments.length) ? domain : null;
+ this.path = (arguments.length) ? path : null;
+ this.secure = (arguments.length) ? secure : null;
+ this.expire = (arguments.length) ? expire : null;
+}
- var cookie_mode;
- var cookieList = [];
- var permissionList = [];
- deleted_cookies = new Array;
- deleted_permissions = new Array;
- function DeleteItemSelected() {
- if (cookie_mode == 0) {
- DeleteCookieSelected();
- } else if (cookie_mode == 1) {
- DeletePermissionSelected();
+// function : ::loadCookies();
+// purpose : loads the list of cookies into the cookie list treeview
+function loadCookies()
+{
+ // get cookies into an array
+ list = cookieviewer.GetCookieValue();
+ BREAK = list[0];
+ cookieList = list.split(BREAK);
+ CreateCookieList(); // builds an object array from cookiestream
+ for(i = 0; i < cookies.length; i++)
+ {
+ var domain = cookies[i].domain;
+ if(domain.charAt(0) == ".") // get rid of the ugly dot on the start of some domains
+ domain = domain.substring(1,domain.length);
+ AddItem("cookielist", [domain,cookies[i].name], "tree_", cookies[i].number);
+ }
+}
+
+// function : ::ViewSelectedCookie();
+// purpose : displays information about the selected cookie in the info fieldset
+function ViewCookieSelected(node)
+{
+ var cookietree = document.getElementById("cookietree");
+ if(cookietree.nodeName != "tree")
+ return false;
+ if(cookietree.selectedItems.length > 1)
+ return false;
+ cookie = node;
+ if(cookie.getAttribute("id").indexOf("tree_") == -1)
+ return false;
+ var idx = parseInt(cookie.getAttribute("id").substring(5,cookie.getAttribute("id").length));
+ var props = [cookies[idx].number, cookies[idx].name, cookies[idx].value,
+ cookies[idx].domaintype, cookies[idx].domain, cookies[idx].path,
+ cookies[idx].secure, cookies[idx].expire];
+
+ rows =
+ [null,"ifl_name","ifl_value","ifl_domaintype","ifl_domain","ifl_path","ifl_secure","ifl_expires"];
+ for(i = 1; i < props.length; i++)
+ {
+ if(i == 3) {
+ var dtypecell = document.getElementById("ifl_domaintype");
+ if(dtypecell.hasChildNodes()) {
+ dtypecell.removeChild(dtypecell.lastChild);
}
+ var content = document.createTextNode(cookies[idx].domaintype+":");
+ dtypecell.appendChild(content);
+ continue;
}
+ var field = document.getElementById(rows[i]);
+ var content = props[i];
+ field.value = content;
+ if(rows[i] == "ifl_expires") break;
+ }
+}
- function DeleteCookieSelected() {
- selname = top.frames[list_frame].document.fSelectCookie.selname;
- goneC = top.frames[button_frame].document.buttons.goneC;
- var p;
- var i;
- for (i=selname.options.length; i>0; i--) {
- if (selname.options[i-1].selected) {
- selname.options[i-1].selected = 0;
- goneC.value = goneC.value + selname.options[i-1].value + ",";
- deleted_cookies[selname.options[i-1].value] = 1;
- selname.remove(i-1);
- }
- }
- top.frames[prop_frame].document.open();
- top.frames[prop_frame].document.close();
- }
+// function : ::DeleteCookieSelected();
+// purpose : deletes all the cookies that are selected
+function DeleteCookieSelected() {
+ // delete selected item
+ gone_c += DeleteItemSelected("cookietree", "tree_", "cookielist");
+ // set fields
+ rows = ["ifl_name","ifl_value","ifl_domain","ifl_path","ifl_secure","ifl_expires"];
+ for(k = 0; k < rows.length; k++)
+ {
+ var row = document.getElementById(rows[k]);
+ row.setAttribute("value","");
+ }
+}
- function DeletePermissionSelected() {
- selname = top.frames[list_frame].document.fSelectPermission.selname;
- goneP = top.frames[button_frame].document.buttons.goneP;
- var p;
- var i;
- for (i=selname.options.length; i>0; i--) {
- if (selname.options[i-1].selected) {
- selname.options[i-1].selected = 0;
- goneP.value = goneP.value + selname.options[i-1].value + ",";
- deleted_permissions[selname.options[i-1].value] = 1;
- selname.remove(i-1);
- }
- }
- }
+/*** =================== PERMISSIONS CODE =================== ***/
- function loadCookies(){
- cookie_mode = 0;
- top.frames[index_frame].document.open();
- top.frames[index_frame].document.write(
- "" +
- "" +
- ""
- );
- top.frames[index_frame].document.close();
+// function : ::CreatePermissionList();
+// purpose : creates an array of permission objects from the permission stream
+function CreatePermissionList()
+{
+ count = 0;
+ for(i = 1; i < permissionList.length; i+=2)
+ {
+ permissions[count] = new Permission();
+ permissions[count].number = permissionList[i];
+ permStr = permissionList[i+1];
+ permissions[count].type = permStr.substring(0,1);
+ permissions[count].domain = permStr.substring(1,permStr.length);
+ count++;
+ }
+}
- top.frames[title_frame].document.open();
- top.frames[title_frame].document.write
- (" " + cookiesStored);
- top.frames[title_frame].document.close();
+// function : ::Permission();
+// purpose : an home-brewed object that represents a individual permission in the stream
+function Permission(number,type,domain)
+{
+ this.number = (arguments.length) ? number : null;
+ this.type = (arguments.length) ? type : null;
+ this.domain = (arguments.length) ? domain : null;
+}
- top.frames[prop_frame].document.open();
- top.frames[prop_frame].document.close();
+// function : ::loadPermissions();
+// purpose : loads the list of permissions into the permission list treeview
+function loadPermissions()
+{
+ // get permissions into an array
+ list = cookieviewer.GetPermissionValue();
+ BREAK = list[0];
+ permissionList = list.split(BREAK);
+ CreatePermissionList(); // builds an object array from permissionstream
+ for(i = 0; i < permissions.length; i++)
+ {
+ var domain = permissions[i].domain;
+ if(domain.charAt(0) == ".") // get rid of the ugly dot on the start of some domains
+ domain = domain.substring(1,domain.length);
+ if(permissions[i].type == "+")
+ contentStr = bundle.GetStringFromName("can");
+ else if(permissions[i].type == "-")
+ contentStr = bundle.GetStringFromName("cannot");
+ AddItem("permissionslist",[domain,contentStr],"permtree_",permissions[i].number)
+ }
+}
- loadCookiesList();
- }
+/*** =================== GENERAL CODE =================== ***/
- function ViewCookieSelected() {
- index = 8*(top.frames[list_frame].document.fSelectCookie.selname.selectedIndex) + 1;
- top.frames[prop_frame].document.open();
- top.frames[prop_frame].document.write(
- "" + name + " " + cookieList[index+1] + "
" +
- "" + value + " " + cookieList[index+2] + "
" +
- "" + cookieList[index+3] + ": " + cookieList[index+4] + "
" +
- "" + path + " " + cookieList[index+5] + "
" +
- "" + secure + " " + cookieList[index+6] + "
" +
- "" + expires + " " + cookieList[index+7] + "
"
- );
- top.frames[prop_frame].document.close();
- }
+// function : ::doOKButton();
+// purpose : saves the changed settings and closes the dialog.
+function onOK(){
+ var result = "|goneC|" + gone_c + "|goneP|" + gone_p + "|";
+ cookieviewer.SetValue(result, window);
+ return true;
+}
- function loadCookiesList(){
- top.frames[list_frame].document.open();
- top.frames[list_frame].document.write(
- "
" +
- ""
- );
- top.frames[list_frame].document.close();
- }
+/*** =================== TREE MANAGEMENT CODE =================== ***/
- function loadPermissions(){
- cookie_mode = 1;
- top.frames[index_frame].document.open();
- top.frames[index_frame].document.write(
- "" +
- "" +
- ""
- );
- top.frames[index_frame].document.close();
-
- top.frames[title_frame].document.open();
- top.frames[title_frame].document.write
- (" " + permissionsStored + "");
- top.frames[title_frame].document.close();
-
- top.frames[prop_frame].document.open();
- top.frames[prop_frame].document.close();
-
- loadPermissionsList();
- }
-
- function loadPermissionsList(){
- top.frames[list_frame].document.open();
- top.frames[list_frame].document.write(
- ""
- );
- top.frames[list_frame].document.close();
- }
-
- function loadButtons(){
- top.frames[button_frame].document.open();
- top.frames[button_frame].document.write(
- ""
- );
- top.frames[button_frame].document.close();
- }
-
- function loadFrames(){
-
- /*
- * The cookieList is a sequence of items separated by the BREAK character. These
- * items are:
- * empty
- * number for first cookie
- * name for first cookie
- * value for first cookie
- * domain indicator ("Domain" or "Host") for first cookie
- * domain or host name for first cookie
- * path for first cookie
- * secure indicator ("Yes" or "No") for first cookie
- * expiration for first cookie
- * with the eight items above repeated for each successive cookie
- */
- list = DoGetCookieList();
- BREAK = list[0];
- cookieList = list.split(BREAK);
-
- /*
- * The permissionList is a sequence of items separated by the BREAK character. These
- * items are:
- * empty
- * number for first permission
- * +/- hostname for first permission
- * with the above two items repeated for each successive permission
- */
- list = DoGetPermissionList();
- BREAK = list[0];
- permissionList = list.split(BREAK);
- loadCookies();
- loadButtons();
- }
-
- function Save(){
- var goneC = top.frames[button_frame].document.buttons.goneC;
- var goneP = top.frames[button_frame].document.buttons.goneP;
- var result = "|goneC|"+goneC.value+"|goneP|"+goneP.value+"|";
- DoSave(result);
- }
-
- function Cancel(){
- var result = "|goneC||goneP||";
- DoSave(result);
- }
+// function : ::AddItem();
+// purpose : utility function for adding items to a tree.
+function AddItem(children,cells,prefix,idfier)
+{
+ var kids = document.getElementById(children);
+ var item = document.createElement("treeitem");
+ var row = document.createElement("treerow");
+ for(var i = 0; i < cells.length; i++)
+ {
+ var cell = document.createElement("treecell");
+ var text = document.createTextNode(cells[i]);
+ cell.appendChild(text);
+ row.appendChild(cell);
+ }
+ item.appendChild(row);
+ item.setAttribute("id",prefix + idfier);
+ kids.appendChild(item);
+}
+// function : ::DeleteItemSelected();
+// purpose : deletes all the signons that are selected
+function DeleteItemSelected(tree, prefix, kids) {
+ var delnarray = [];
+ var rv = "";
+ var cookietree = document.getElementById(tree);
+ selitems = cookietree.selectedItems;
+ for(var i = 0; i < selitems.length; i++)
+ {
+ delnarray[i] = document.getElementById(selitems[i].getAttribute("id"));
+ var itemid = parseInt(selitems[i].getAttribute("id").substring(prefix.length,selitems[i].getAttribute("id").length));
+ rv += (itemid + ",");
+ }
+ for(var i = 0; i < delnarray.length; i++)
+ {
+ document.getElementById(kids).removeChild(delnarray[i]);
+ }
+ return rv;
+}
\ No newline at end of file
diff --git a/extensions/wallet/cookieviewer/CookieViewer.properties b/extensions/wallet/cookieviewer/CookieViewer.properties
index 339716b7465..7831b4c5faf 100644
--- a/extensions/wallet/cookieviewer/CookieViewer.properties
+++ b/extensions/wallet/cookieviewer/CookieViewer.properties
@@ -1,13 +1,24 @@
-siteCookiename = site:cookie-name
-cookiesTab = View stored cookies
-permissionsTab = View sites that can or cannot store cookies
-cookiesStored = Cookies stored on your system
-permissionsStored = Sites that can(+) or cannot(-) store cookies
-name = Name:
-value = Value:
-path = Path:
-secure = Secure:
-expires = Expires:
-removeCmdLabel = Remove
-okCmdLabel = OK
-cancelCmdLabel = Cancel
\ No newline at end of file
+# The contents of this file are subject to the Netscape Public License
+# Version 1.0 (the "NPL"); you may not use this file except in
+# compliance with the NPL. You may obtain a copy of the NPL at
+# http://www.mozilla.org/NPL/
+#
+# Software distributed under the NPL is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
+# for the specific language governing rights and limitations under the
+# NPL.
+#
+# The Initial Developer of this code under the NPL is Netscape
+# Communications Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All Rights
+# Reserved.
+#
+# Contributor(s):
+# Ben Goodger
+
+# note this section of the code may require some tinkering in other languages =(
+# format in dialog: site [can/cannot] set cookies
+can=site can set cookies
+cannot=site cannot set cookies
+domain=Domain for which this cookie applies:
+host=Server which set the cookie:
\ No newline at end of file
diff --git a/extensions/wallet/cookieviewer/CookieViewer.xul b/extensions/wallet/cookieviewer/CookieViewer.xul
index 92503ce174b..3bde8caca3a 100644
--- a/extensions/wallet/cookieviewer/CookieViewer.xul
+++ b/extensions/wallet/cookieviewer/CookieViewer.xul
@@ -1,62 +1,135 @@
-
-
+
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+ &tab.cookiesonsystem.label;
+ &tab.bannedservers.label;
+
+
+
+ &div.cookiesonsystem.label;
+
+
+
+
+
+
+
+ &treehead.cookiedomain.label;
+ &treehead.cookiename.label;
+
+
+
+
+
+
+
+ &treehead.infoselected.label;
+
+
+
+
+ &props.name.label;
+
+
+
+ &props.value.label;
+
+
+
+ &props.domain.label;
+
+
+
+ &props.path.label;
+
+
+
+ &props.secure.label;
+
+
+
+ &props.expires.label;
+
+
+
+
+
+
+
+
+
+
+
+
+ &div.bannedservers.label;
+
+
+
+
+
+ &treehead.sitename.label;
+ &treehead.status.label;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/extensions/wallet/cookieviewer/nsCookieViewer.cpp b/extensions/wallet/cookieviewer/nsCookieViewer.cpp
index 48bfd16d3e9..e99b82392bb 100644
--- a/extensions/wallet/cookieviewer/nsCookieViewer.cpp
+++ b/extensions/wallet/cookieviewer/nsCookieViewer.cpp
@@ -175,22 +175,6 @@ static void DOMWindowToWebShellWindow(
NS_IMETHODIMP
CookieViewerImpl::SetValue(const char* aValue, nsIDOMWindow* win)
{
- /* close the window */
- if (!win) {
- return NS_ERROR_FAILURE;
- }
- nsIDOMWindow* top;
- win->GetTop(&top);
- if (!top) {
- return NS_ERROR_FAILURE;
- }
- nsCOMPtr parent;
- DOMWindowToWebShellWindow(top, &parent);
- if (parent) {
- parent->Close();
- }
- NS_IF_RELEASE(win);
-
/* process the value */
NS_PRECONDITION(aValue != nsnull, "null ptr");
if (! aValue) {