Bug 807606 - Add a native UI implementation of the NSS dialog service in Fennec. r=mfinkle

This commit is contained in:
Kartikaya Gupta 2013-01-24 15:41:35 -05:00
parent 407b7a7820
commit 8fc64379a4
6 changed files with 164 additions and 0 deletions

View File

@ -37,6 +37,7 @@ EXTRA_COMPONENTS = \
FormAutoComplete.js \ FormAutoComplete.js \
LoginManagerPrompter.js \ LoginManagerPrompter.js \
BlocklistPrompt.js \ BlocklistPrompt.js \
NSSDialogService.js \
$(NULL) $(NULL)
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk

View File

@ -90,3 +90,6 @@ contract @mozilla.org/login-manager/prompter;1 {97d12931-abe2-11df-94e2-0800200c
component {4e6ea350-b09a-11df-94e2-0800200c9a66} BlocklistPrompt.js component {4e6ea350-b09a-11df-94e2-0800200c9a66} BlocklistPrompt.js
contract @mozilla.org/addons/blocklist-prompt;1 {4e6ea350-b09a-11df-94e2-0800200c9a66} contract @mozilla.org/addons/blocklist-prompt;1 {4e6ea350-b09a-11df-94e2-0800200c9a66}
# NSSDialogService.js
component {cbc08081-49b6-4561-9c18-a7707a50bda1} NSSDialogService.js
contract @mozilla.org/nsCertificateDialogs;1 {cbc08081-49b6-4561-9c18-a7707a50bda1}

View File

@ -0,0 +1,127 @@
/* 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 Ci = Components.interfaces;
const Cu = Components.utils;
const Cc = Components.classes;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
// -----------------------------------------------------------------------
// NSS Dialog Service
// -----------------------------------------------------------------------
function dump(a) {
Components.classes["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
}
function NSSDialogs() { }
NSSDialogs.prototype = {
classID: Components.ID("{cbc08081-49b6-4561-9c18-a7707a50bda1}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsICertificateDialogs]),
getString: function(aName) {
if (!this.bundle) {
this.bundle = Services.strings.createBundle("chrome://browser/locale/pippki.properties");
}
return this.bundle.GetStringFromName(aName);
},
showPrompt: function(aTitle, aText, aButtons, aInputs) {
let msg = {
type: "Prompt:Show",
title: aTitle,
text: aText,
buttons: aButtons,
inputs: aInputs
};
let data = Cc["@mozilla.org/android/bridge;1"].getService(Ci.nsIAndroidBridge).handleGeckoMessage(JSON.stringify({ gecko: msg }));
return JSON.parse(data);
},
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 }
]);
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) {
return false;
}
aTrust.value = Ci.nsIX509CertDB.UNTRUSTED;
if (response.trustSSL == "true") aTrust.value |= Ci.nsIX509CertDB.TRUSTED_SSL;
if (response.trustEmail == "true") aTrust.value |= Ci.nsIX509CertDB.TRUSTED_EMAIL;
if (response.trustSign == "true") aTrust.value |= Ci.nsIX509CertDB.TRUSTED_OBJSIGN;
return true;
}
},
notifyCACertExists: function(aCtx) {
this.showPrompt(this.getString("caCertExists.title"), this.getString("caCertExists.message"), [], []);
},
setPKCS12FilePassword: function(aCtx, aPassword) {
// this dialog is never shown in Fennec; in Desktop it is shown while backing up a personal
// certificate to a file via Preferences->Advanced->Encryption->View Certificates->Your Certificates
throw "Unimplemented";
},
getPKCS12FilePassword: function(aCtx, aPassword) {
// this dialog is never shown in Fennec; in Desktop it is shown while backing up a personal
// certificate to a file via Preferences->Advanced->Encryption->View Certificates->Your Certificates
throw "Unimplemented";
},
certInfoSection: function(aHeading, aDataPairs, aTrailingNewline = true) {
var str = "<big>" + this.getString(aHeading) + "</big><br/>";
for (var i = 0; i < aDataPairs.length; i += 2) {
str += this.getString(aDataPairs[i]) + ": " + aDataPairs[i+1] + "<br/>";
}
return str + (aTrailingNewline ? "<br/>" : "");
},
viewCert: function(aCtx, aCert) {
this.showPrompt(this.getString("certmgr.title"),
"",
[ this.getString("nssdialogs.ok.label") ],
[ { type: "label", 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.cn", aCert.issuerCommonName,
"certmgr.certdetail.o", aCert.issuerOrganization,
"certmgr.certdetail.ou", aCert.issuerOrganizationUnit]) +
this.certInfoSection("certmgr.validity.label",
["certmgr.issued", aCert.validity.notBeforeLocalDay,
"certmgr.expires", aCert.validity.notAfterLocalDay]) +
this.certInfoSection("certmgr.fingerprints.label",
["certmgr.certdetail.sha1fingerprint", aCert.sha1Fingerprint,
"certmgr.certdetail.md5fingerprint", aCert.md5Fingerprint], false) }
]);
},
crlImportStatusDialog: function(aCtx, aCrl) {
// this dialog is never shown in Fennec; in Desktop it is shown after importing a CRL
// via Preferences->Advanced->Encryption->Revocation Lists->Import.
throw "Unimplemented";
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NSSDialogs]);

View File

@ -541,6 +541,7 @@ bin/components/@DLL_PREFIX@nkgnomevfs@DLL_SUFFIX@
@BINPATH@/components/LoginManagerPrompter.js @BINPATH@/components/LoginManagerPrompter.js
@BINPATH@/components/MobileComponents.manifest @BINPATH@/components/MobileComponents.manifest
@BINPATH@/components/MobileComponents.xpt @BINPATH@/components/MobileComponents.xpt
@BINPATH@/components/NSSDialogService.js
@BINPATH@/components/PromptService.js @BINPATH@/components/PromptService.js
@BINPATH@/components/SessionStore.js @BINPATH@/components/SessionStore.js
@BINPATH@/components/Sidebar.js @BINPATH@/components/Sidebar.js

View File

@ -0,0 +1,31 @@
# 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/.
nssdialogs.ok.label=OK
nssdialogs.cancel.label=Cancel
# These strings are stolen from security/manager/locales/en-US/chrome/pippki/pippki.dtd
downloadCert.title=Downloading Certificate
downloadCert.message1=You have been asked to trust a new Certificate Authority (CA).
downloadCert.viewCert.label=View
downloadCert.trustSSL=Trust to identify websites.
downloadCert.trustEmail=Trust to identify email users.
downloadCert.trustObjSign=Trust to identify software developers.
caCertExists.title=Certificate Exists
caCertExists.message=The Certificate already exists.
certmgr.title=Certificate Details
# These strings are stolen from security/manager/locales/en-US/chrome/pippki/certManager.dtd
certmgr.subjectinfo.label=Issued To
certmgr.issuerinfo.label=Issued By
certmgr.validity.label=Validity
certmgr.fingerprints.label=Fingerprints
certmgr.certdetail.cn=Common Name (CN)
certmgr.certdetail.o=Organization (O)
certmgr.certdetail.ou=Organizational Unit (OU)
certmgr.certdetail.serialnumber=Serial Number
certmgr.certdetail.sha1fingerprint=SHA1 Fingerprint
certmgr.certdetail.md5fingerprint=MD5 Fingerprint
certmgr.issued=Issued On
certmgr.expires=Expires On

View File

@ -22,6 +22,7 @@
locale/@AB_CD@/browser/localepicker.properties (%chrome/localepicker.properties) locale/@AB_CD@/browser/localepicker.properties (%chrome/localepicker.properties)
locale/@AB_CD@/browser/checkbox.dtd (%chrome/checkbox.dtd) locale/@AB_CD@/browser/checkbox.dtd (%chrome/checkbox.dtd)
locale/@AB_CD@/browser/notification.dtd (%chrome/notification.dtd) locale/@AB_CD@/browser/notification.dtd (%chrome/notification.dtd)
locale/@AB_CD@/browser/pippki.properties (%chrome/pippki.properties)
locale/@AB_CD@/browser/sync.dtd (%chrome/sync.dtd) locale/@AB_CD@/browser/sync.dtd (%chrome/sync.dtd)
locale/@AB_CD@/browser/sync.properties (%chrome/sync.properties) locale/@AB_CD@/browser/sync.properties (%chrome/sync.properties)
locale/@AB_CD@/browser/prompt.dtd (%chrome/prompt.dtd) locale/@AB_CD@/browser/prompt.dtd (%chrome/prompt.dtd)