mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-25 06:10:35 +00:00
Bug 878848 - Use Prompt.jsm for NSS prompts. r=kats
This commit is contained in:
parent
f769d0cfb4
commit
0aeaa1ffa3
@ -8,6 +8,7 @@ const Cc = Components.classes;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Prompt.jsm");
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// NSS Dialog Service
|
||||
@ -37,32 +38,44 @@ NSSDialogs.prototype = {
|
||||
return this.bundle.formatStringFromName(aName, argList, 1);
|
||||
},
|
||||
|
||||
showPrompt: function(aTitle, aText, aButtons, aInputs) {
|
||||
let msg = {
|
||||
type: "Prompt:Show",
|
||||
getPrompt: function(aTitle, aText, aButtons) {
|
||||
return new Prompt({
|
||||
title: aTitle,
|
||||
text: aText,
|
||||
buttons: aButtons,
|
||||
inputs: aInputs
|
||||
};
|
||||
let data = Cc["@mozilla.org/android/bridge;1"].getService(Ci.nsIAndroidBridge).handleGeckoMessage(JSON.stringify(msg));
|
||||
return JSON.parse(data);
|
||||
});
|
||||
},
|
||||
|
||||
showPrompt: function(aPrompt) {
|
||||
let response = null;
|
||||
aPrompt.show(function(data) {
|
||||
response = data;
|
||||
});
|
||||
|
||||
// Spin this thread while we wait for a result
|
||||
let thread = Services.tm.currentThread;
|
||||
while (response === null)
|
||||
thread.processNextEvent(true);
|
||||
|
||||
return response;
|
||||
},
|
||||
|
||||
confirmDownloadCACert: function(aCtx, aCert, aTrust) {
|
||||
while (true) {
|
||||
let response = this.showPrompt(this.getString("downloadCert.title"),
|
||||
this.getString("downloadCert.message1"),
|
||||
[ this.getString("nssdialogs.ok.label"),
|
||||
this.getString("downloadCert.viewCert.label"),
|
||||
this.getString("nssdialogs.cancel.label")
|
||||
],
|
||||
[ { type: "checkbox", id: "trustSSL", label: this.getString("downloadCert.trustSSL"), checked: false },
|
||||
{ type: "checkbox", id: "trustEmail", label: this.getString("downloadCert.trustEmail"), checked: false },
|
||||
{ type: "checkbox", id: "trustSign", label: this.getString("downloadCert.trustObjSign"), checked: false }
|
||||
]);
|
||||
let prompt = this.getPrompt(this.getString("downloadCert.title"),
|
||||
this.getString("downloadCert.message1"),
|
||||
[ this.getString("nssdialogs.ok.label"),
|
||||
this.getString("downloadCert.viewCert.label"),
|
||||
this.getString("nssdialogs.cancel.label")
|
||||
]);
|
||||
|
||||
prompt.addCheckbox({ id: "trustSSL", label: this.getString("downloadCert.trustSSL"), checked: false })
|
||||
.addCheckbox({ id: "trustEmail", label: this.getString("downloadCert.trustEmail"), checked: false })
|
||||
.addCheckbox({ id: "trustSign", label: this.getString("downloadCert.trustObjSign"), checked: false });
|
||||
let response = this.showPrompt(prompt);
|
||||
|
||||
// they hit the "view cert" button, so show the cert and try again
|
||||
if (response.button == 1) {
|
||||
// they hit the "view cert" button, so show the cert and try again
|
||||
this.viewCert(aCtx, aCert);
|
||||
continue;
|
||||
} else if (response.button != 0) {
|
||||
@ -78,7 +91,8 @@ NSSDialogs.prototype = {
|
||||
},
|
||||
|
||||
notifyCACertExists: function(aCtx) {
|
||||
this.showPrompt(this.getString("caCertExists.title"), this.getString("caCertExists.message"), [], []);
|
||||
let p = this.getPrompt(this.getString("caCertExists.title"), this.getString("caCertExists.message"));
|
||||
this.showPrompt(p);
|
||||
},
|
||||
|
||||
setPKCS12FilePassword: function(aCtx, aPassword) {
|
||||
@ -88,15 +102,16 @@ NSSDialogs.prototype = {
|
||||
},
|
||||
|
||||
getPKCS12FilePassword: function(aCtx, aPassword) {
|
||||
let response = this.showPrompt(this.getString("pkcs12.getpassword.title"),
|
||||
this.getString("pkcs12.getpassword.message"),
|
||||
[ this.getString("nssdialogs.ok.label"),
|
||||
this.getString("nssdialogs.cancel.label")
|
||||
],
|
||||
[ { type: "password", id: "pw" } ]);
|
||||
let prompt = this.getPrompt(this.getString("pkcs12.getpassword.title"),
|
||||
this.getString("pkcs12.getpassword.message"),
|
||||
[ this.getString("nssdialogs.ok.label"),
|
||||
this.getString("nssdialogs.cancel.label")
|
||||
]).addPassword({id: "pw"});
|
||||
let response = this.showPrompt(prompt);
|
||||
if (response.button != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aPassword.value = response.pw;
|
||||
return true;
|
||||
},
|
||||
@ -110,26 +125,25 @@ NSSDialogs.prototype = {
|
||||
},
|
||||
|
||||
viewCert: function(aCtx, aCert) {
|
||||
this.showPrompt(this.getString("certmgr.title"),
|
||||
let p = this.getPrompt(this.getString("certmgr.title"),
|
||||
"",
|
||||
[ this.getString("nssdialogs.ok.label") ],
|
||||
[ { type: "label", label:
|
||||
this.certInfoSection("certmgr.subjectinfo.label",
|
||||
[ this.getString("nssdialogs.ok.label") ])
|
||||
p.addLabel({ label: this.certInfoSection("certmgr.subjectinfo.label",
|
||||
["certmgr.certdetail.cn", aCert.commonName,
|
||||
"certmgr.certdetail.o", aCert.organization,
|
||||
"certmgr.certdetail.ou", aCert.organizationalUnit,
|
||||
"certmgr.certdetail.serialnumber", aCert.serialNumber]) +
|
||||
this.certInfoSection("certmgr.issuerinfo.label",
|
||||
"certmgr.certdetail.serialnumber", aCert.serialNumber])})
|
||||
.addLabel({ label: this.certInfoSection("certmgr.issuerinfo.label",
|
||||
["certmgr.certdetail.cn", aCert.issuerCommonName,
|
||||
"certmgr.certdetail.o", aCert.issuerOrganization,
|
||||
"certmgr.certdetail.ou", aCert.issuerOrganizationUnit]) +
|
||||
this.certInfoSection("certmgr.validity.label",
|
||||
"certmgr.certdetail.ou", aCert.issuerOrganizationUnit])})
|
||||
.addLabel({ label: this.certInfoSection("certmgr.validity.label",
|
||||
["certmgr.issued", aCert.validity.notBeforeLocalDay,
|
||||
"certmgr.expires", aCert.validity.notAfterLocalDay]) +
|
||||
this.certInfoSection("certmgr.fingerprints.label",
|
||||
"certmgr.expires", aCert.validity.notAfterLocalDay])})
|
||||
.addLabel({ label: this.certInfoSection("certmgr.fingerprints.label",
|
||||
["certmgr.certdetail.sha1fingerprint", aCert.sha1Fingerprint,
|
||||
"certmgr.certdetail.md5fingerprint", aCert.md5Fingerprint], false) }
|
||||
]);
|
||||
"certmgr.certdetail.md5fingerprint", aCert.md5Fingerprint], false) });
|
||||
this.showPrompt(p);
|
||||
},
|
||||
|
||||
crlImportStatusDialog: function(aCtx, aCrl) {
|
||||
@ -139,12 +153,11 @@ NSSDialogs.prototype = {
|
||||
},
|
||||
|
||||
viewCertDetails: function(details) {
|
||||
this.showPrompt(this.getString("clientAuthAsk.message3"),
|
||||
let p = this.getPrompt(this.getString("clientAuthAsk.message3"),
|
||||
'',
|
||||
[ this.getString("nssdialogs.ok.label") ],
|
||||
[ { type: "label", label: details
|
||||
}
|
||||
]);
|
||||
[ this.getString("nssdialogs.ok.label") ]);
|
||||
p.addLabel({ label: details });
|
||||
this.showPrompt(p);
|
||||
},
|
||||
|
||||
ChooseCertificate: function(aCtx, cn, organization, issuer, certNickList, certDetailsList, count, selectedIndex, canceled) {
|
||||
@ -168,16 +181,23 @@ NSSDialogs.prototype = {
|
||||
|
||||
selectedIndex = 0;
|
||||
while (true) {
|
||||
let response = this.showPrompt(this.getString("clientAuthAsk.title"),
|
||||
let prompt = this.getPrompt(this.getString("clientAuthAsk.title"),
|
||||
this.getString("clientAuthAsk.message1"),
|
||||
[ this.getString("nssdialogs.ok.label"),
|
||||
this.getString("clientAuthAsk.viewCert.label"),
|
||||
this.getString("nssdialogs.cancel.label")
|
||||
],
|
||||
[ { type: "label", id: "requestedDetails", label: serverRequestedDetails },
|
||||
{ type: "menulist", id: "nicknames", label: this.getString("clientAuthAsk.message2"), values: certNickList, selected: selectedIndex },
|
||||
{ type: "checkbox", id: "rememberBox", label: this.getString("clientAuthAsk.remember.label"), checked: rememberSetting },
|
||||
]);
|
||||
])
|
||||
.addLabel({ id: "requestedDetails", label: serverRequestedDetails } )
|
||||
.addMenuList({
|
||||
id: "nicknames",
|
||||
label: this.getString("clientAuthAsk.message2"),
|
||||
values: certNickList, selected: selectedIndex
|
||||
}).addCheckbox({
|
||||
id: "rememberBox",
|
||||
label: this.getString("clientAuthAsk.remember.label"),
|
||||
checked: rememberSetting
|
||||
});
|
||||
let response = this.showPrompt(prompt);
|
||||
selectedIndex = response.nicknames;
|
||||
if (response.button == 1) {
|
||||
this.viewCertDetails(certDetailsList[selectedIndex]);
|
||||
|
@ -87,6 +87,15 @@ Prompt.prototype = {
|
||||
return this._addInput({
|
||||
type: aOptions.type || "date",
|
||||
value: aOptions.value,
|
||||
id: aOptions.id
|
||||
});
|
||||
},
|
||||
|
||||
addLabel: function(aOptions) {
|
||||
return this._addInput({
|
||||
type: "label",
|
||||
label: aOptions.label,
|
||||
id: aOptions.id
|
||||
});
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user