Bug 845375 - Implement the nsIClientAuthDialogs interface for android. r=kats
authorAaron Moses <zebardy@gmail.com>
Thu, 07 Mar 2013 18:08:03 +0000
changeset 124137 ffe335c066f6d7b73adc36a72b4f28cc0e92cb41
parent 124136 356116f81c8808fb456195fa92e4adcaaf8da85c
child 124138 894268df2c2577ed86fe89699871b405c93addea
push id24408
push userryanvm@gmail.com
push dateFri, 08 Mar 2013 04:58:11 +0000
treeherdermozilla-central@cb432984d5ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs845375
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 845375 - Implement the nsIClientAuthDialogs interface for android. r=kats
mobile/android/base/PromptService.java
mobile/android/components/MobileComponents.manifest
mobile/android/components/NSSDialogService.js
mobile/android/locales/en-US/chrome/pippki.properties
--- a/mobile/android/base/PromptService.java
+++ b/mobile/android/base/PromptService.java
@@ -199,16 +199,18 @@ public class PromptService implements On
                 mView = (View)input;
             } else if (mType.equals("menulist")) {
                 Spinner spinner = new Spinner(GeckoApp.mAppContext);
                 try {
                     String[] listitems = getStringArray(mJSONInput, "values");
                     if (listitems.length > 0) {
                         ArrayAdapter<String> adapter = new ArrayAdapter<String>(GeckoApp.mAppContext, android.R.layout.simple_dropdown_item_1line, listitems);
                         spinner.setAdapter(adapter);
+                        int selectedIndex = getSafeInt(mJSONInput, "selected");
+                        spinner.setSelection(selectedIndex);
                     }
                 } catch(Exception ex) { }
                 mView = (View)spinner;
             } else if (mType.equals("label")) {
                 // not really an input, but a way to add labels and such to the dialog
                 TextView view = new TextView(GeckoApp.mAppContext);
                 view.setText(Html.fromHtml(mLabel));
                 mView = view;
--- a/mobile/android/components/MobileComponents.manifest
+++ b/mobile/android/components/MobileComponents.manifest
@@ -88,12 +88,13 @@ contract @mozilla.org/login-manager/prom
 
 # BlocklistPrompt.js
 component {4e6ea350-b09a-11df-94e2-0800200c9a66} BlocklistPrompt.js
 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}
+contract @mozilla.org/nsClientAuthDialogs;1 {cbc08081-49b6-4561-9c18-a7707a50bda1}
 
 # SiteSpecificUserAgent.js
 component {d5234c9d-0ee2-4b3c-9da3-18be9e5cf7e6} SiteSpecificUserAgent.js
 contract @mozilla.org/dom/site-specific-user-agent;1 {d5234c9d-0ee2-4b3c-9da3-18be9e5cf7e6}
--- a/mobile/android/components/NSSDialogService.js
+++ b/mobile/android/components/NSSDialogService.js
@@ -16,25 +16,32 @@ Cu.import("resource://gre/modules/Servic
 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]),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsICertificateDialogs, Ci.nsIClientAuthDialogs]),
 
   getString: function(aName) {
     if (!this.bundle) {
         this.bundle = Services.strings.createBundle("chrome://browser/locale/pippki.properties");
     }
     return this.bundle.GetStringFromName(aName);
   },
 
+  formatString: function(aName, argList) {
+    if (!this.bundle) {
+      this.bundle = Services.strings.createBundle("chrome://browser/locale/pippki.properties");
+    }
+    return this.bundle.formatStringFromName(aName, argList, 1);
+  },
+
   showPrompt: function(aTitle, aText, aButtons, aInputs) {
     let msg = {
       type: "Prompt:Show",
       title: aTitle,
       text: aText,
       buttons: aButtons,
       inputs: aInputs
     };
@@ -124,12 +131,68 @@ NSSDialogs.prototype = {
                            "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";
+  },
+
+  viewCertDetails: function(details) {
+    this.showPrompt(this.getString("clientAuthAsk.message3"),
+                    '',
+                    [ this.getString("nssdialogs.ok.label") ],
+                    [ { type: "label", label: details
+                      }
+                    ]);
+  },
+
+  ChooseCertificate: function(aCtx, cn, organization, issuer, certNickList, certDetailsList, count, selectedIndex, canceled) {
+    let rememberSetting = true;
+    var pref = Cc['@mozilla.org/preferences-service;1']
+               .getService(Components.interfaces.nsIPrefService);
+    if (pref) {
+      pref = pref.getBranch(null);
+      try {
+        rememberSetting = pref.getBoolPref("security.remember_cert_checkbox_default_setting");
+      } catch (e) {
+        // pref is missing
+      }
+    }
+
+    let organizationString = this.formatString("clientAuthAsk.organization",
+                                               [organization]);
+    let issuerString = this.formatString("clientAuthAsk.issuer",
+                                         [issuer]);
+    let serverRequestedDetails = cn + '<br/>' + organizationString + '<br/>' + issuerString;
+
+    selectedIndex = 0;
+    while (true) {
+      let response = this.showPrompt(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 },
+                                     ]);
+      selectedIndex = response.nicknames;
+      if (response.button == 1) {
+        this.viewCertDetails(certDetailsList[selectedIndex]);
+        continue;
+      } else if (response.button == 0) {
+        canceled.value = false;
+        if (response.rememberBox == "true") {
+          aCtx.QueryInterface(Ci.nsIClientAuthUserDecision).rememberClientAuthCertificate = true;
+        }
+        return true;
+      }
+      canceled.value = true;
+      return false;
+    }
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NSSDialogs]);
--- a/mobile/android/locales/en-US/chrome/pippki.properties
+++ b/mobile/android/locales/en-US/chrome/pippki.properties
@@ -11,16 +11,24 @@ downloadCert.message1=You have been aske
 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.
 pkcs12.getpassword.title=Password Entry Dialog
 pkcs12.getpassword.message=Please enter the password that was used to encrypt this certificate backup.
+clientAuthAsk.title=User Identification Request
+clientAuthAsk.message1=This site has requested that you identify yourself with a certificate:
+clientAuthAsk.message2=Choose a certificate to present as identification:
+clientAuthAsk.message3=Details of selected certificate:
+clientAuthAsk.remember.label=Remember this decision
+clientAuthAsk.organization=Organization: "%S"
+clientAuthAsk.issuer=Issued Under: "%S"
+clientAuthAsk.viewCert.label=View
 
 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)