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

http://github.com/zpao/v8monkey · JavaScript · 134 lines · 79 code · 15 blank · 40 comment · 4 complexity · 62540737cefac6d56ff27ad1a1fa603e MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is mozilla.org code.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * Netscape Communications Corporation.
  20. * Portions created by the Initial Developer are Copyright (C) 1998
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. * Javier Delgadillo <javi@netscape.com>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either the GNU General Public License Version 2 or later (the "GPL"), or
  28. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
  40. var dialogParams;
  41. var itemCount = 0;
  42. var rememberBox;
  43. function onLoad()
  44. {
  45. var cn;
  46. var org;
  47. var issuer;
  48. dialogParams = window.arguments[0].QueryInterface(nsIDialogParamBlock);
  49. cn = dialogParams.GetString(0);
  50. org = dialogParams.GetString(1);
  51. issuer = dialogParams.GetString(2);
  52. // added with bug 431819. reuse string from caps in order to avoid string changes
  53. var capsBundle = srGetStrBundle("chrome://global/locale/security/caps.properties");
  54. var rememberString = capsBundle.GetStringFromName("CheckMessage");
  55. var rememberSetting = true;
  56. var pref = Components.classes['@mozilla.org/preferences-service;1']
  57. .getService(Components.interfaces.nsIPrefService);
  58. if (pref) {
  59. pref = pref.getBranch(null);
  60. try {
  61. rememberSetting =
  62. pref.getBoolPref("security.remember_cert_checkbox_default_setting");
  63. }
  64. catch(e) {
  65. // pref is missing
  66. }
  67. }
  68. rememberBox = document.getElementById("rememberBox");
  69. rememberBox.label = rememberString;
  70. rememberBox.checked = rememberSetting;
  71. var bundle = srGetStrBundle("chrome://pippki/locale/pippki.properties");
  72. var message1 = bundle.formatStringFromName("clientAuthMessage1",
  73. [org],
  74. 1);
  75. var message2 = bundle.formatStringFromName("clientAuthMessage2",
  76. [issuer],
  77. 1);
  78. setText("hostname", cn);
  79. setText("organization", message1);
  80. setText("issuer", message2);
  81. var selectElement = document.getElementById("nicknames");
  82. itemCount = dialogParams.GetInt(0);
  83. for (var i=0; i < itemCount; i++) {
  84. var menuItemNode = document.createElement("menuitem");
  85. var nick = dialogParams.GetString(i+3);
  86. menuItemNode.setAttribute("value", i);
  87. menuItemNode.setAttribute("label", nick); // this is displayed
  88. selectElement.firstChild.appendChild(menuItemNode);
  89. if (i == 0) {
  90. selectElement.selectedItem = menuItemNode;
  91. }
  92. }
  93. setDetails();
  94. }
  95. function setDetails()
  96. {
  97. var index = parseInt(document.getElementById("nicknames").value);
  98. var details = dialogParams.GetString(index+itemCount+3);
  99. document.getElementById("details").value = details;
  100. }
  101. function onCertSelected()
  102. {
  103. setDetails();
  104. }
  105. function doOK()
  106. {
  107. dialogParams.SetInt(0,1);
  108. var index = parseInt(document.getElementById("nicknames").value);
  109. dialogParams.SetInt(1, index);
  110. dialogParams.SetInt(2, rememberBox.checked);
  111. return true;
  112. }
  113. function doCancel()
  114. {
  115. dialogParams.SetInt(0,0);
  116. dialogParams.SetInt(1, -1); // invalid value
  117. dialogParams.SetInt(2, rememberBox.checked);
  118. return true;
  119. }