home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / comm.jar / content / cookie / cookieAcceptDialog.js < prev    next >
Text File  |  2002-09-29  |  6KB  |  152 lines

  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 cookie manager code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Michiel van Leeuwen.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
  38. const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
  39.  
  40. var params; 
  41. var cookieBundle;
  42. var gDateService = null;
  43.  
  44. var showDetails = "";
  45. var hideDetails = "";
  46.  
  47. function onload()
  48. {
  49.   var dialog = document.documentElement;
  50.  
  51.   if (!gDateService) {
  52.     const nsScriptableDateFormat_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1";
  53.     const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat;
  54.     gDateService = Components.classes[nsScriptableDateFormat_CONTRACTID]
  55.                              .getService(nsIScriptableDateFormat);
  56.   }
  57.  
  58.   cookieBundle = document.getElementById("cookieBundle");
  59.  
  60.   //cache strings
  61.   if (!showDetails) {
  62.     showDetails = cookieBundle.getString('showDetails');
  63.   }
  64.   if (!hideDetails) {
  65.     hideDetails = cookieBundle.getString('hideDetails');
  66.   }
  67.  
  68.   if (document.getElementById('infobox').hidden) {
  69.     document.getElementById('disclosureButton').setAttribute("label",showDetails);
  70.   } else {
  71.     document.getElementById('disclosureButton').setAttribute("label",hideDetails);
  72.   }
  73.  
  74.   if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
  75.     try {
  76.       params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
  77.  
  78.       var messageText = params.GetString(nsICookieAcceptDialog.MESSAGETEXT);
  79.       var messageParent = document.getElementById("info.box");
  80.       var messageParagraphs = messageText.split("\n");
  81.  
  82.       for (var i = 0; i < messageParagraphs.length; i++) {
  83.         var descriptionNode = document.createElement("description");
  84.         var text = document.createTextNode(messageParagraphs[i]);
  85.         descriptionNode.appendChild(text);
  86.         messageParent.appendChild(descriptionNode);
  87.       }
  88.  
  89.       document.getElementById('persistDomainAcceptance').checked = params.GetInt(nsICookieAcceptDialog.REMEMBER_DECISION) > 0;
  90.  
  91.       document.getElementById('ifl_name').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_NAME));
  92.       document.getElementById('ifl_value').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_VALUE));
  93.       document.getElementById('ifl_host').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_HOST));
  94.       document.getElementById('ifl_path').setAttribute("value",params.GetString(nsICookieAcceptDialog.COOKIE_PATH));
  95.       document.getElementById('ifl_isSecure').setAttribute("value",
  96.                                                            params.GetInt(nsICookieAcceptDialog.COOKIE_IS_SECURE) ?
  97.                                                                   cookieBundle.getString("yes") : cookieBundle.getString("no")
  98.                                                           );
  99.       document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(params.GetInt(nsICookieAcceptDialog.COOKIE_EXPIRES)));
  100.       document.getElementById('ifl_isDomain').setAttribute("value",
  101.                                                            params.GetInt(nsICookieAcceptDialog.COOKIE_IS_DOMAIN) ?
  102.                                                                   cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
  103.                                                           );
  104.  
  105.       // set default result to cancelled
  106.       params.SetInt(eAcceptCookie, 0); 
  107.  
  108.     } catch (e) {
  109.     }
  110.   }
  111. }
  112.  
  113. function showhideinfo()
  114. {
  115.   var infobox=document.getElementById('infobox');
  116.  
  117.   if (infobox.hidden) {
  118.     infobox.setAttribute("hidden","false");
  119.     document.getElementById('disclosureButton').setAttribute("label",hideDetails);
  120.   } else {
  121.     infobox.setAttribute("hidden","true");
  122.     document.getElementById('disclosureButton').setAttribute("label",showDetails);
  123.   }
  124.   sizeToContent();
  125. }
  126.  
  127. function onChangePersitence()
  128. {
  129.   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
  130. }
  131.  
  132. function cookieAccept()
  133. {
  134.   params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 1); // say that ok was pressed
  135. }
  136.  
  137. function GetExpiresString(secondsUntilExpires) {
  138.   if (secondsUntilExpires) {
  139.     var expireDate = new Date(1000*secondsUntilExpires);
  140.     return gDateService.FormatDateTime("", gDateService.dateFormatLong,
  141.                                        gDateService.timeFormatSeconds, 
  142.                                        expireDate.getFullYear(),
  143.                                        expireDate.getMonth()+1, 
  144.                                        expireDate.getDate(), 
  145.                                        expireDate.getHours(),
  146.                                        expireDate.getMinutes(), 
  147.                                        expireDate.getSeconds());
  148.   }
  149.   return cookieBundle.getString("atEndOfSession");
  150. }
  151.  
  152.