change cert mgr to use outliner

This commit is contained in:
mcgreer%netscape.com 2001-03-27 00:18:21 +00:00
Родитель 304475914c
Коммит da4fac0e50
4 изменённых файлов: 205 добавлений и 149 удалений

Просмотреть файл

@ -33,41 +33,13 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<box id="CACerts" orient="vertical">
<tree id="ca_treeset" debug="false" flex="0" multiple="true"
height="100" onselect="ca_enableButtons()">
<treecolgroup>
<treecol flex="1"/>
<treecol collapsed="true" flex="1"/>
</treecolgroup>
<treechildren>
<treeitem container="true" open="true" flex="1">
<!--
<treehead>
-->
<treerow>
<treecell label="&certmgr.ca.builtins;" flex="1"/>
<treecell collapsed="true" flex="1"/>
</treerow>
<!--
</treehead>
-->
<treechildren id="builtins" flex="1" />
</treeitem>
<treeitem container="true" open="true" flex="1">
<!--
<treehead>
-->
<treerow>
<treecell label="&certmgr.ca.mycas;" flex="1"/>
<treecell collapsed="true" flex="1"/>
</treerow>
<!--
</treehead>
-->
<treechildren id="mycas" flex="1" />
</treeitem>
</treechildren>
</tree>
<outliner id="ca-outliner" multiple="true"
onselect="ca_enableButtons()" flex="1">
<outlinercol id="certcol" label="Certificate Name" flex="1"/>
<splitter/>
<outlinercol id="tokencol" label="Token Name" flex="1"/>
<outlinerbody flex="1"/>
</outliner>
<box>
<button id="ca_viewButton" class="normal"
label="&certmgr.view.label;" orient="horizontal"

Просмотреть файл

@ -33,16 +33,15 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<box id="myCerts" orient="vertical">
<box><html>&certmgr.mine;</html></box>
<html>&certmgr.mine;</html>
<separator class="thin"/>
<tree id="mine_treeset" debug="false" flex="0" multiple="true"
height="100" onselect="mine_enableButtons()">
<treecolgroup>
<treecol flex="1"/>
<treecol collapsed="true" flex="1"/>
</treecolgroup>
<treechildren id="mine" flex="1" />
</tree>
<outliner id="user-outliner" multiple="true"
onselect="mine_enableButtons()" flex="1">
<outlinercol id="certcol" label="Certificate Name" flex="1"/>
<splitter/>
<outlinercol id="tokencol" label="Token Name" flex="1"/>
<outlinerbody flex="1"/>
</outliner>
<box>
<button id="mine_viewButton" class="normal"
label="&certmgr.view.label;" orient="horizontal"

Просмотреть файл

@ -33,16 +33,15 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<box id="webCerts" orient="vertical">
<box><html>&certmgr.websites;</html></box>
<html>&certmgr.websites;</html>
<separator class="thin"/>
<tree id="websites_treeset" debug="false" flex="0" multiple="true"
height="100" onselect="websites_enableButtons()">
<treecolgroup>
<treecol flex="1"/>
<treecol collapsed="true" flex="1"/>
</treecolgroup>
<treechildren id="servers" flex="1" />
</tree>
<outliner id="server-outliner" multiple="true"
onselect="websites_enableButtons()" flex="1">
<outlinercol id="certcol" label="Certificate Name" flex="1"/>
<splitter/>
<outlinercol id="tokencol" label="Token Name" flex="1"/>
<outlinerbody flex="1"/>
</outliner>
<box>
<button id="websites_viewButton" class="normal"
label="&certmgr.view.label;" orient="horizontal"

Просмотреть файл

@ -25,67 +25,131 @@ const nsIFilePicker = Components.interfaces.nsIFilePicker;
const nsFilePicker = "@mozilla.org/filepicker;1";
const nsIX509CertDB = Components.interfaces.nsIX509CertDB;
const nsX509CertDB = "@mozilla.org/security/x509certdb;1";
const nsIX509Cert = Components.interfaces.nsIX509Cert;
var selected_certs = [];
var certdb;
var caCertNameList;
var serverCertNameList;
//var emailCertNameList;
var userCertNameList;
var caOutlinerView = {
rowCount : 50,
setOutliner : function(outliner) {},
getCellText : function(row, column) {
if (row >= caCertNameList.length) return "";
var certname = caCertNameList[row];
var ti = certname.indexOf(":");
var tokenname = "PSM Certificate Database";
if (ti > 0) {
tokenname = certname.substring(0, ti);
certname = certname.substring(ti+1, certname.length);
}
if (column=="certcol") return certname;
else return tokenname;
},
getRowProperties : function(row, prop) {},
getColumnProperties : function(column, prop) {},
getCellProperties : function(cell, prop) {},
isContainer : function(index) { return false; }
};
var serverOutlinerView = {
rowCount : 10,
setOutliner : function(outliner) {},
getCellText : function(row, column) {
if (row >= serverCertNameList.length) return "";
var certname = serverCertNameList[row];
var ti = certname.indexOf(":");
var tokenname = "PSM Certificate Database";
if (ti > 0) {
tokenname = certname.substring(0, ti);
certname = certname.substring(ti+1, certname.length);
}
if (column=="certcol") return certname;
else return tokenname;
},
getRowProperties : function(row, prop) {},
getColumnProperties : function(column, prop) {},
getCellProperties : function(cell, prop) {},
isContainer : function(index) { return false; }
};
/*
var emailOutlinerView = {
rowCount : 10,
setOutliner : function(outliner) {},
getCellText : function(row, column) {
if (row >= emailCertNameList.length) return "";
var certname = emailCertertNameList[row];
var ti = certname.indexOf(":");
var tokenname = "PSM Certificate Database";
if (ti > 0) {
tokenname = certname.substring(0, ti);
certname = certname.substring(ti+1, certname.length);
}
if (column=="certcol") return certname;
else return tokenname;
},
getRowProperties : function(row, prop) {},
getColumnProperties : function(column, prop) {},
getCellProperties : function(cell, prop) {},
isContainer : function(index) { return false; }
};
*/
var userOutlinerView = {
rowCount : 10,
setOutliner : function(outliner) {},
getCellText : function(row, column) {
if (row >= userCertNameList.length) return "";
var certname = userCertNameList[row];
var ti = certname.indexOf(":");
var tokenname = "PSM Certificate Database";
if (ti > 0) {
tokenname = certname.substring(0, ti);
certname = certname.substring(ti+1, certname.length);
}
if (column=="certcol") return certname;
else return tokenname;
},
getRowProperties : function(row, prop) {},
getColumnProperties : function(column, prop) {},
getCellProperties : function(cell, prop) {},
isContainer : function(index) { return false; }
};
function getSelectedCerts()
{
var mine_tab = document.getElementById("mine_tab");
//var others_tab = document.getElementById("others_tab");
var websites_tab = document.getElementById("websites_tab");
var tree = document.getElementById('ca_treeset');
var items = caOutlinerView.selection;
if (mine_tab.selected) {
tree = document.getElementById('mine_treeset');
items = userOutlinerView.selection;
} else if (websites_tab.selected) {
tree = document.getElementById('websites_treeset');
items = serverOutlinerView.selection;
}
var items = tree.selectedItems;
if (items.length > 0) {
var nr = items.getRangeCount();
if (nr > 0) {
selected_certs = [];
for (var t=0; t<items.length; t++) {
var tokenName = items[t].firstChild.lastChild.getAttribute('label');
var certName = items[t].firstChild.firstChild.getAttribute('label');
selected_certs[selected_certs.length] = [tokenName, certName];
for (var i=0; i<nr; i++) {
var o1 = {};
var o2 = {};
items.getRangeAt(i, o1, o2);
var min = o1.value;
var max = o2.value;
for (var j=min; j<=max; j++) {
var tokenName = items.outliner.view.getCellText(j, "tokencol");
var certName = items.outliner.view.getCellText(j, "certcol");
selected_certs[selected_certs.length] = [tokenName, certName];
}
}
}
}
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");
cell.setAttribute("class", "propertylist");
cell.setAttribute("label", cells[i]);
row.appendChild(cell);
}
item.appendChild(row);
item.setAttribute("id", prefix + idfier);
kids.appendChild(item);
}
function AddNameWithToken(children, cells, prefix, idfier)
{
var kids = document.getElementById(children);
var item = document.createElement("treeitem");
var row = document.createElement("treerow");
for (var i=0; i<2; i++) {
var cell = document.createElement("treecell");
cell.setAttribute("class", "propertylist");
cell.setAttribute("label", cells[i]);
if (i==1) {
cell.setAttribute("collapsed", "true");
}
row.appendChild(cell);
}
item.appendChild(row);
item.setAttribute("id", prefix + idfier);
kids.appendChild(item);
}
function GetNameList(type, node)
{
var obj1 = {};
@ -108,63 +172,86 @@ function GetNameList(type, node)
}
}
function LoadCertNamesByType(type)
{
var obj1 = {};
var obj2 = {};
certdb.getCertNicknames(null, type, obj1, obj2);
var count = obj1.value;
if (type == nsIX509Cert.CA_CERT) {
caCertNameList = obj2.value;
caCertNameList.sort();
} else if (type == nsIX509Cert.SERVER_CERT) {
serverCertNameList = obj2.value;
serverCertNameList.sort();
/*
} else if (type == nsIX509Cert.EMAIL_CERT) {
emailCertNameList = obj2.value;
emailCertNameList.sort();
*/
} else { /* if (type == nsIX509Cert.USER_CERT) */
userCertNameList = obj2.value;
userCertNameList.sort();
}
}
function LoadCertNames()
{
certdb = Components.classes[nsX509CertDB].getService(nsIX509CertDB);
var obj1 = {};
var obj2 = {};
certdb.getCertNicknames(null,
Components.interfaces.nsIX509Cert.CA_CERT,
obj1, obj2);
var count = obj1.value;
var certNameList = obj2.value;
if (certNameList.length > 0) {
certNameList.sort();
var nb = 0;
var nm = 0;
for (var i=0; i<certNameList.length; i++) {
var certname = certNameList[i];
var ti = certname.indexOf(":");
var token = "";
if (ti > 0) {
token = certname.substring(0, ti);
certname = certname.substring(ti+1, certname.length);
}
if (token == "Builtin Object Token") {
AddNameWithToken("builtins", [certname, token], "builtin_", nb);
nb++;
} else {
AddNameWithToken("mycas", [certname, token], "myca_", nm);
nm++;
}
}
}
GetNameList(Components.interfaces.nsIX509Cert.USER_CERT, "mine");
GetNameList(Components.interfaces.nsIX509Cert.SERVER_CERT, "servers");
LoadCertNamesByType(nsIX509Cert.CA_CERT);
LoadCertNamesByType(nsIX509Cert.SERVER_CERT);
//LoadCertNamesByType(nsIX509Cert.EMAIL_CERT);
LoadCertNamesByType(nsIX509Cert.USER_CERT);
document.getElementById('ca-outliner')
.outlinerBoxObject.view = caOutlinerView;
document.getElementById('server-outliner')
.outlinerBoxObject.view = serverOutlinerView;
/*document.getElementById('email-outliner')
.outlinerBoxObject.view = emailOutlinerView; */
document.getElementById('user-outliner')
.outlinerBoxObject.view = userOutlinerView;
}
function ca_enableButtons()
{
var tree = document.getElementById('ca_treeset');
var items = tree.selectedItems;
var items = caOutlinerView.selection;
var nr = items.getRangeCount();
var toggle="false";
if (items.length == 0) {
if (nr == 0) {
toggle="true";
}
var edit_toggle="true";
if (nr > 0) {
for (var i=0; i<nr; i++) {
var o1 = {};
var o2 = {};
items.getRangeAt(i, o1, o2);
var min = o1.value;
var max = o2.value;
var stop = false;
for (var j=min; j<=max; j++) {
var tokenName = items.outliner.view.getCellText(j, "tokencol");
if (tokenName == "Builtin Object Token") { stop = true; } break;
}
if (stop) break;
}
if (i == nr) {
edit_toggle="false";
}
}
var enableViewButton=document.getElementById('ca_viewButton');
enableViewButton.setAttribute("disabled",toggle);
var enableEditButton=document.getElementById('ca_editButton');
enableEditButton.setAttribute("disabled",toggle);
enableEditButton.setAttribute("disabled",edit_toggle);
var enableDeleteButton=document.getElementById('ca_deleteButton');
enableDeleteButton.setAttribute("disabled",toggle);
}
function mine_enableButtons()
{
var tree = document.getElementById('mine_treeset');
var items = tree.selectedItems;
var items = userOutlinerView.selection;
var toggle="false";
if (items.length == 0) {
if (items.getRangeCount() == 0) {
toggle="true";
}
var enableViewButton=document.getElementById('mine_viewButton');
@ -177,10 +264,9 @@ function mine_enableButtons()
function websites_enableButtons()
{
var tree = document.getElementById('websites_treeset');
var items = tree.selectedItems;
var items = serverOutlinerView.selection;
var toggle="false";
if (items.length == 0) {
if (items.getRangeCount() == 0) {
toggle="true";
}
var enableViewButton=document.getElementById('websites_viewButton');
@ -198,7 +284,8 @@ function backupCerts()
var certs = [];
var windowName = "";
for (var t=0; t<numcerts; t++) {
if (selected_certs[t][0]) { // token name
if (selected_certs[t][0] &&
selected_certs[t][0] != "PSM Certificate Database") { // token name
windowName = selected_certs[t].join(":");
} else {
windowName = selected_certs[t][1];
@ -223,14 +310,8 @@ function backupCerts()
function backupAllCerts()
{
// Select all rows, then call doBackup()
var tree = document.getElementById('mine_treeset');
// XXX need to catch this in UI
if (tree.getRowCount() == 0) {
alert("You have no certs to backup");
} else {
tree.selectAll();
backupCerts();
}
var items = userOutlinerView.selection.selectAll();
backupCerts();
}
function editCerts()
@ -238,7 +319,8 @@ function editCerts()
getSelectedCerts();
var windowName = "";
for (var t=0; t<selected_certs.length; t++) {
if (selected_certs[t][0]) { // token name
if (selected_certs[t][0] &&
selected_certs[t][0] != "PSM Certificate Database") { // token name
windowName = selected_certs[t].join(":");
} else {
windowName = selected_certs[t][1];
@ -263,6 +345,7 @@ function restoreCerts()
}
// don't really know it was successful...
alert(bundle.GetStringFromName("SuccessfulP12Restore"));
LoadCertNames();
}
function deleteCerts()
@ -270,7 +353,8 @@ function deleteCerts()
getSelectedCerts();
var windowName = "";
for (var t=0; t<selected_certs.length; t++) {
if (selected_certs[t][0]) { // token name
if (selected_certs[t][0] &&
selected_certs[t][0] != "PSM Certificate Database") { // token name
windowName = selected_certs[t].join(":");
} else {
windowName = selected_certs[t][1];
@ -281,6 +365,7 @@ function deleteCerts()
'chrome,width=500,height=400,resizable=1');
*/
}
LoadCertNames();
}
function viewCerts()
@ -288,7 +373,8 @@ function viewCerts()
getSelectedCerts();
var windowName = "";
for (var t=0; t<selected_certs.length; t++) {
if (selected_certs[t][0]) { // token name
if (selected_certs[t][0] &&
selected_certs[t][0] != "PSM Certificate Database") { // token name
windowName = selected_certs[t].join(":");
} else {
windowName = selected_certs[t][1];