home *** CD-ROM | disk | FTP | other *** search
/ PC Advisor 2010 April / PCA177.iso / ESSENTIALS / Firefox Setup.exe / nonlocalized / chrome / browser.jar / content / browser / sanitizeDialog.js < prev    next >
Encoding:
Text File  |  2009-07-15  |  7.8 KB  |  245 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is the Firefox Sanitizer.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Ben Goodger.
  19.  * Portions created by the Initial Developer are Copyright (C) 2005
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Ben Goodger <ben@mozilla.org>
  24.  *   Giorgio Maone <g.maone@informaction.com>
  25.  *   Johnathan Nightingale <johnath@mozilla.com>
  26.  *   Drew Willcoxon <adw@mozilla.com>
  27.  *
  28.  * Alternatively, the contents of this file may be used under the terms of
  29.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  30.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  31.  * in which case the provisions of the GPL or the LGPL are applicable instead
  32.  * of those above. If you wish to allow use of your version of this file only
  33.  * under the terms of either the GPL or the LGPL, and not to allow others to
  34.  * use your version of this file under the terms of the MPL, indicate your
  35.  * decision by deleting the provisions above and replace them with the notice
  36.  * and other provisions required by the GPL or the LGPL. If you do not delete
  37.  * the provisions above, a recipient may use your version of this file under
  38.  * the terms of any one of the MPL, the GPL or the LGPL.
  39.  *
  40.  * ***** END LICENSE BLOCK ***** */
  41.  
  42. const Cc = Components.classes;
  43. const Ci = Components.interfaces;
  44.  
  45. var gSanitizePromptDialog = {
  46.  
  47.   get bundleBrowser()
  48.   {
  49.     if (!this._bundleBrowser)
  50.       this._bundleBrowser = document.getElementById("bundleBrowser");
  51.     return this._bundleBrowser;
  52.   },
  53.  
  54.   get selectedTimespan()
  55.   {
  56.     var durList = document.getElementById("sanitizeDurationChoice");
  57.     return parseInt(durList.value);
  58.   },
  59.  
  60.   get sanitizePreferences()
  61.   {
  62.     if (!this._sanitizePreferences) {
  63.       this._sanitizePreferences =
  64.         document.getElementById("sanitizePreferences");
  65.     }
  66.     return this._sanitizePreferences;
  67.   },
  68.  
  69.   get warningBox()
  70.   {
  71.     return document.getElementById("sanitizeEverythingWarningBox");
  72.   },
  73.  
  74.   init: function ()
  75.   {
  76.     // This is used by selectByTimespan() to determine if the window has loaded.
  77.     this._inited = true;
  78.  
  79.     var s = new Sanitizer();
  80.     s.prefDomain = "privacy.cpd.";
  81.     for (let i = 0; i < this.sanitizePreferences.childNodes.length; ++i) {
  82.       var preference = this.sanitizePreferences.childNodes[i];
  83.       var name = s.getNameFromPreference(preference.name);
  84.       if (!s.canClearItem(name)) 
  85.         preference.disabled = true;
  86.     }
  87.  
  88.     document.documentElement.getButton("accept").label =
  89.       this.bundleBrowser.getString("sanitizeButtonOK");
  90.  
  91.     if (this.selectedTimespan === Sanitizer.TIMESPAN_EVERYTHING) {
  92.       this.ensureWarningIsInited();
  93.       this.warningBox.hidden = false;
  94.     }
  95.     else
  96.       this.warningBox.hidden = true;
  97.   },
  98.  
  99.   selectByTimespan: function ()
  100.   {
  101.     // This method is the onselect handler for the duration dropdown.  As a
  102.     // result it's called a couple of times before onload calls init().
  103.     if (!this._inited)
  104.       return;
  105.  
  106.     var warningBox = this.warningBox;
  107.  
  108.     // If clearing everything
  109.     if (this.selectedTimespan === Sanitizer.TIMESPAN_EVERYTHING) {
  110.       this.ensureWarningIsInited();
  111.       if (warningBox.hidden) {
  112.         warningBox.hidden = false;
  113.         window.resizeBy(0, warningBox.boxObject.height);
  114.       }
  115.       window.document.title =
  116.         this.bundleBrowser.getString("sanitizeDialog2.everything.title");
  117.       return;
  118.     }
  119.  
  120.     // If clearing a specific time range
  121.     if (!warningBox.hidden) {
  122.       window.resizeBy(0, -warningBox.boxObject.height);
  123.       warningBox.hidden = true;
  124.     }
  125.     window.document.title =
  126.       window.document.documentElement.getAttribute("noneverythingtitle");
  127.   },
  128.  
  129.   sanitize: function ()
  130.   {
  131.     // Update pref values before handing off to the sanitizer (bug 453440)
  132.     this.updatePrefs();
  133.     var s = new Sanitizer();
  134.     s.prefDomain = "privacy.cpd.";
  135.  
  136.     s.range = Sanitizer.getClearRange(this.selectedTimespan);
  137.     s.ignoreTimespan = !s.range;
  138.  
  139.     try {
  140.       s.sanitize();
  141.     } catch (er) {
  142.       Components.utils.reportError("Exception during sanitize: " + er);
  143.     }
  144.     return true;
  145.   },
  146.  
  147.   /**
  148.    * If the panel that displays a warning when the duration is "Everything" is
  149.    * not set up, sets it up.  Otherwise does nothing.
  150.    */
  151.   ensureWarningIsInited: function ()
  152.   {
  153.     if (this._warningIsInited)
  154.       return;
  155.  
  156.     this._warningIsInited = true;
  157.  
  158.     // If the date and time-aware locale warning string is ever used again,
  159.     // initialize it here.  Currently we use the no-visits warning string,
  160.     // which does not include date and time.  See bug 480169 comment 48.
  161.  
  162.     var warningDesc = document.getElementById("sanitizeEverythingWarning");
  163.     warningDesc.textContent =
  164.       this.bundleBrowser.getString("sanitizeEverythingNoVisitsWarning");
  165.   },
  166.  
  167.   /**
  168.    * Called when the value of a preference element is synced from the actual
  169.    * pref.  Enables or disables the OK button appropriately.
  170.    */
  171.   onReadGeneric: function ()
  172.   {
  173.     var found = false;
  174.  
  175.     // Find any other pref that's checked and enabled.
  176.     var i = 0;
  177.     while (!found && i < this.sanitizePreferences.childNodes.length) {
  178.       var preference = this.sanitizePreferences.childNodes[i];
  179.  
  180.       found = !!preference.value &&
  181.               !preference.disabled;
  182.       i++;
  183.     }
  184.  
  185.     try {
  186.       document.documentElement.getButton("accept").disabled = !found;
  187.     }
  188.     catch (e) { }
  189.     return undefined;
  190.   },
  191.  
  192.   /**
  193.    * Sanitizer.prototype.sanitize() requires the prefs to be up-to-date.
  194.    * Because the type of this prefwindow is "child" -- and that's needed because
  195.    * without it the dialog has no OK and Cancel buttons -- the prefs are not
  196.    * updated on dialogaccept on platforms that don't support instant-apply
  197.    * (i.e., Windows).  We must therefore manually set the prefs from their
  198.    * corresponding preference elements.
  199.    */
  200.   updatePrefs : function ()
  201.   {
  202.     var tsPref = document.getElementById("privacy.sanitize.timeSpan");
  203.     Sanitizer.prefs.setIntPref("timeSpan", this.selectedTimespan);
  204.  
  205.     // Keep the pref for the download history in sync with the history pref.
  206.     document.getElementById("privacy.cpd.downloads").value =
  207.       document.getElementById("privacy.cpd.history").value;
  208.  
  209.     // Now manually set the prefs from their corresponding preference
  210.     // elements.
  211.     var prefs = this.sanitizePreferences.rootBranch;
  212.     for (let i = 0; i < this.sanitizePreferences.childNodes.length; ++i) {
  213.       var p = this.sanitizePreferences.childNodes[i];
  214.       prefs.setBoolPref(p.name, p.value);
  215.     }
  216.   },
  217.  
  218.   /**
  219.    * Called by the item list expander button to toggle the list's visibility.
  220.    */
  221.   toggleItemList: function ()
  222.   {
  223.     var itemList = document.getElementById("itemList");
  224.     var expanderButton = document.getElementById("detailsExpander");
  225.  
  226.     // Showing item list
  227.     if (itemList.collapsed) {
  228.       expanderButton.className = "expander-up";
  229.       itemList.setAttribute("collapsed", "false");
  230.       window.resizeBy(0, itemList.boxObject.height);
  231.     }
  232.     // Hiding item list
  233.     else {
  234.       expanderButton.className = "expander-down";
  235.       window.resizeBy(0, -itemList.boxObject.height);
  236.       itemList.setAttribute("collapsed", "true");
  237.     }
  238.   }
  239.  
  240. //@line 525 "e:\builds\moz2_slave\win32_build\build\browser\base\content\sanitizeDialog.js"
  241.  
  242. };
  243.  
  244.  
  245.