/security/manager/pki/resources/content/crlImportDialog.js

http://github.com/zpao/v8monkey · JavaScript · 117 lines · 69 code · 12 blank · 36 comment · 10 complexity · 52feeb3d8b163bcda678f87f123cccbf MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is mozilla.org code.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Netscape Communications Corporation.
  18. * Portions created by the Initial Developer are Copyright (C) 2001
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Rangan Sen <rangansen@netscape.com>
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. const nsPKIParamBlock = "@mozilla.org/security/pkiparamblock;1";
  38. const nsIPKIParamBlock = Components.interfaces.nsIPKIParamBlock;
  39. const nsIX509Cert = Components.interfaces.nsIX509Cert;
  40. const nsICRLInfo = Components.interfaces.nsICRLInfo;
  41. const nsIPrefService = Components.interfaces.nsIPrefService
  42. var pkiParams;
  43. var cert;
  44. var crl;
  45. function onLoad()
  46. {
  47. pkiParams = window.arguments[0].QueryInterface(nsIPKIParamBlock);
  48. isupport = pkiParams.getISupportAtIndex(1);
  49. if (isupport) {
  50. crl = isupport.QueryInterface(nsICRLInfo);
  51. }
  52. var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  53. var yesButton = bundle.GetStringFromName("yesButton");
  54. var noButton = bundle.GetStringFromName("noButton");
  55. document.documentElement.getButton("accept").label = yesButton;
  56. document.documentElement.getButton("cancel").label = noButton;
  57. var nextUpdateStr;
  58. var orgStr;
  59. var orgUnitStr;
  60. if(crl != null) {
  61. nextUpdateStr = crl.nextUpdateLocale;
  62. if( (nextUpdateStr == null) || (nextUpdateStr.length == 0) ){
  63. nextUpdateStr = bundle.GetStringFromName("undefinedValStr");
  64. }
  65. var nextUpdate = document.getElementById("nextUpdate");
  66. nextUpdate.setAttribute("value",nextUpdateStr);
  67. var org = document.getElementById("orgText");
  68. org.setAttribute("value", crl.organization);
  69. var orgUnit = document.getElementById("orgUnitText");
  70. orgUnit.setAttribute("value", crl.organizationalUnit);
  71. var autoupdateEnabledString = "security.crl.autoupdate.enable." + crl.nameInDb;
  72. var updateEnabled = false;
  73. try {
  74. var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(nsIPrefService);
  75. var prefBranch = prefService.getBranch(null);
  76. updateEnabled = prefBranch.getBoolPref(autoupdateEnabledString);
  77. if(updateEnabled) {
  78. var autoupdateURLString = "security.crl.autoupdate.url." + crl.nameInDb;
  79. prefBranch.setCharPref(autoupdateURLString, crl.lastFetchURL);
  80. prefService.savePrefFile(null);
  81. }
  82. }catch(exception){}
  83. var statement = document.getElementById("status");
  84. var question = document.getElementById("question");
  85. if(updateEnabled) {
  86. statement.setAttribute("value",bundle.GetStringFromName("enabledStatement"));
  87. question.setAttribute("value",bundle.GetStringFromName("crlAutoupdateQuestion2"));
  88. } else {
  89. statement.setAttribute("value",bundle.GetStringFromName("disabledStatement"));
  90. question.setAttribute("value",bundle.GetStringFromName("crlAutoupdateQuestion1"));
  91. }
  92. }
  93. }
  94. function onCancel()
  95. {
  96. return true;
  97. }
  98. function onAccept()
  99. {
  100. var params = Components.classes[nsPKIParamBlock].createInstance(nsIPKIParamBlock);
  101. params.setISupportAtIndex(1, crl);
  102. window.openDialog("chrome://pippki/content/pref-crlupdate.xul","",
  103. "chrome,centerscreen,modal",params);
  104. return true;
  105. }