home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / preferences / privacy.js < prev    next >
Encoding:
JavaScript  |  2008-07-01  |  9.4 KB  |  270 lines

  1. /*
  2. //@line 40 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/preferences/privacy.js"
  3. */
  4.  
  5. var gPrivacyPane = {
  6.  
  7.   /**
  8.    * Sets up the UI for the number of days of history to keep, and updates the
  9.    * label of the "Clear Now..." button.
  10.    */
  11.   init: function ()
  12.   {
  13.     this._updateHistoryDaysUI();
  14.     this.updateClearNowButtonLabel();
  15.   },
  16.  
  17.   // HISTORY
  18.  
  19.   /*
  20.    * Preferences:
  21.    *
  22.    * NOTE: These first two are no longer shown in the UI. They're controlled
  23.    *       via the checkbox, which uses the zero state of the pref to turn
  24.    *       history off.
  25.    * browser.history_expire_days
  26.    * - the number of days of history to remember
  27.    * browser.history_expire_days.mirror
  28.    * - a preference whose value mirrors that of browser.history_expire_days, to
  29.    *   make the "days of history" checkbox easier to code
  30.    *
  31.    * browser.history_expire_days_min
  32.    * - the mininum number of days of history to remember
  33.    * browser.history_expire_days_min.mirror
  34.    * - a preference whose value mirrors that of browser.history_expire_days_min
  35.    *   to make the "days of history" checkbox easier to code
  36.    * browser.formfill.enable
  37.    * - true if entries in forms and the search bar should be saved, false
  38.    *   otherwise
  39.    * browser.download.manager.retention
  40.    * - determines when downloads are automatically removed from the download
  41.    *   manager:
  42.    *
  43.    *     0 means remove downloads when they finish downloading
  44.    *     1 means downloads will be removed when the browser quits
  45.    *     2 means never remove downloads
  46.    */
  47.  
  48.   /**
  49.    * Initializes the days-of-history mirror preference and connects it to the
  50.    * days-of-history checkbox so that updates to the textbox are transmitted to
  51.    * the real days-of-history preference.
  52.    */
  53.   _updateHistoryDaysUI: function ()
  54.   {
  55.     var pref = document.getElementById("browser.history_expire_days");
  56.     var mirror = document.getElementById("browser.history_expire_days.mirror");
  57.     var pref_min = document.getElementById("browser.history_expire_days_min");
  58.     var textbox = document.getElementById("historyDays");
  59.     var checkbox = document.getElementById("rememberHistoryDays");
  60.  
  61.     // handle mirror non-existence or mirror/pref unsync
  62.     if (mirror.value === null || mirror.value != pref.value || 
  63.         (mirror.value == pref.value && mirror.value == 0) )
  64.       mirror.value = pref.value ? pref.value : pref.defaultValue;
  65.  
  66.     checkbox.checked = (pref.value > 0);
  67.     textbox.disabled = !checkbox.checked;
  68.   },
  69.  
  70.   /**
  71.    * Responds to the checking or unchecking of the days-of-history UI, storing
  72.    * the appropriate value to the days-of-history preference and enabling or
  73.    * disabling the number textbox as appropriate.
  74.    */
  75.   onchangeHistoryDaysCheck: function ()
  76.   {
  77.     var pref = document.getElementById("browser.history_expire_days");
  78.     var mirror = document.getElementById("browser.history_expire_days.mirror");
  79.     var textbox = document.getElementById("historyDays");
  80.     var checkbox = document.getElementById("rememberHistoryDays");
  81.  
  82.     pref.value = checkbox.checked ? mirror.value : 0;
  83.     textbox.disabled = !checkbox.checked;
  84.   },
  85.  
  86.   /**
  87.    * Responds to changes in the days-of-history textbox,
  88.    * unchecking the history-enabled checkbox if the days
  89.    * value is zero.
  90.    */
  91.   onkeyupHistoryDaysText: function ()
  92.   {
  93.     var textbox = document.getElementById("historyDays");
  94.     var checkbox = document.getElementById("rememberHistoryDays");
  95.     
  96.     checkbox.checked = textbox.value != 0;
  97.   },
  98.  
  99.   /**
  100.    * Converts the value of the browser.download.manager.retention preference
  101.    * into a Boolean value.  "remove on close" and "don't remember" both map
  102.    * to an unchecked checkbox, while "remember" maps to a checked checkbox.
  103.    */
  104.   readDownloadRetention: function ()
  105.   {
  106.     var pref = document.getElementById("browser.download.manager.retention");
  107.     return (pref.value == 2);
  108.   },
  109.  
  110.   /**
  111.    * Returns the appropriate value of the browser.download.manager.retention
  112.    * preference for the current UI.
  113.    */
  114.   writeDownloadRetention: function ()
  115.   {
  116.     var checkbox = document.getElementById("rememberDownloads");
  117.     return checkbox.checked ? 2 : 0;
  118.   },
  119.  
  120.   // COOKIES
  121.  
  122.   /*
  123.    * Preferences:
  124.    *
  125.    * network.cookie.cookieBehavior
  126.    * - determines how the browser should handle cookies:
  127.    *     0   means enable all cookies
  128.    *     1   means reject third party cookies; see
  129.    *         netwerk/cookie/src/nsCookieService.cpp for a hairier definition
  130.    *     2   means disable all cookies
  131.    * network.cookie.lifetimePolicy
  132.    * - determines how long cookies are stored:
  133.    *     0   means keep cookies until they expire
  134.    *     1   means ask how long to keep each cookie
  135.    *     2   means keep cookies until the browser is closed
  136.    */
  137.  
  138.   /**
  139.    * Reads the network.cookie.cookieBehavior preference value and
  140.    * enables/disables the rest of the cookie UI accordingly, returning true
  141.    * if cookies are enabled.
  142.    */
  143.   readAcceptCookies: function ()
  144.   {
  145.     var pref = document.getElementById("network.cookie.cookieBehavior");
  146.     var acceptThirdParty = document.getElementById("acceptThirdParty");
  147.     var keepUntil = document.getElementById("keepUntil");
  148.     var menu = document.getElementById("keepCookiesUntil");
  149.  
  150.     // enable the rest of the UI for anything other than "disable all cookies"
  151.     var acceptCookies = (pref.value != 2);
  152.  
  153.     keepUntil.disabled = menu.disabled = acceptThirdParty.disabled = !acceptCookies;
  154.     
  155.     return acceptCookies;
  156.   },
  157.  
  158.   readAcceptThirdPartyCookies: function ()
  159.   {
  160.     var pref = document.getElementById("network.cookie.cookieBehavior");
  161.     return pref.value == 0;
  162.   },
  163.  
  164.   /**
  165.    * Enables/disables the "keep until" label and menulist in response to the
  166.    * "accept cookies" checkbox being checked or unchecked.
  167.    */
  168.   writeAcceptCookies: function ()
  169.   {
  170.     var accept = document.getElementById("acceptCookies");
  171.     var acceptThirdParty = document.getElementById("acceptThirdParty");
  172.  
  173.     // if we're enabling cookies, automatically check 'accept third party'
  174.     if (accept.checked)
  175.       acceptThirdParty.checked = true;
  176.  
  177.     return accept.checked ? (acceptThirdParty.checked ? 0 : 1) : 2;
  178.   },
  179.  
  180.   writeAcceptThirdPartyCookies: function ()
  181.   {
  182.     var accept = document.getElementById("acceptCookies");
  183.     var acceptThirdParty = document.getElementById("acceptThirdParty");
  184.     return accept.checked ? (acceptThirdParty.checked ? 0 : 1) : 2;
  185.   },
  186.  
  187.   /**
  188.    * Displays fine-grained, per-site preferences for cookies.
  189.    */
  190.   showCookieExceptions: function ()
  191.   {
  192.     var bundlePreferences = document.getElementById("bundlePreferences");
  193.     var params = { blockVisible   : true, 
  194.                    sessionVisible : true, 
  195.                    allowVisible   : true, 
  196.                    prefilledHost  : "", 
  197.                    permissionType : "cookie",
  198.                    windowTitle    : bundlePreferences.getString("cookiepermissionstitle"),
  199.                    introText      : bundlePreferences.getString("cookiepermissionstext") };
  200.     document.documentElement.openWindow("Browser:Permissions",
  201.                                         "chrome://browser/content/preferences/permissions.xul",
  202.                                         "", params);
  203.   },
  204.  
  205.   /**
  206.    * Displays all the user's cookies in a dialog.
  207.    */  
  208.   showCookies: function (aCategory)
  209.   {
  210.     document.documentElement.openWindow("Browser:Cookies",
  211.                                         "chrome://browser/content/preferences/cookies.xul",
  212.                                         "", null);
  213.   },
  214.  
  215.   // CLEAR PRIVATE DATA
  216.  
  217.   /*
  218.    * Preferences:
  219.    *
  220.    * privacy.sanitize.sanitizeOnShutdown
  221.    * - true if the user's private data is cleared on startup according to the
  222.    *   Clear Private Data settings, false otherwise
  223.    * privacy.sanitize.promptOnSanitize
  224.    * - true if sanitizing forces the user to accept a dialog, false otherwise
  225.    */
  226.  
  227.   /**
  228.    * Sets the label of the "Clear Now..." button according to the
  229.    * privacy.sanitize.promptOnSanitize preference. Read valueFromPreferences to
  230.    * only change the button when the underlying pref changes, since in the case
  231.    * of instantApply=false, the call to clearPrivateDataNow would result in the
  232.    * dialog appearing when the user just unchecked the "Ask me" checkbox.
  233.    */
  234.   updateClearNowButtonLabel: function ()
  235.   {
  236.     var pref = document.getElementById("privacy.sanitize.promptOnSanitize");
  237.     var clearNowButton = document.getElementById("clearDataNow");
  238.  
  239.     if (pref.valueFromPreferences)
  240.       clearNowButton.label = clearNowButton.getAttribute("label1"); // "Clear Now..."
  241.     else
  242.       clearNowButton.label = clearNowButton.getAttribute("label2"); // "Clear Now"
  243.   },
  244.  
  245.   /**
  246.    * Displays the Clear Private Data settings dialog.
  247.    */
  248.   showClearPrivateDataSettings: function ()
  249.   {
  250.     document.documentElement.openSubDialog("chrome://browser/content/preferences/sanitize.xul",
  251.                                            "", null);
  252.     this.updateClearNowButtonLabel();
  253.   },
  254.  
  255.   /**
  256.    * Either displays a dialog from which individual parts of private data may be
  257.    * cleared, or automatically clears private data according to current
  258.    * CPD settings.  The former happens if privacy.sanitize.promptOnSanitize is
  259.    * true, and the latter happens otherwise.
  260.    */
  261.   clearPrivateDataNow: function ()
  262.   {
  263.     const Cc = Components.classes, Ci = Components.interfaces;
  264.     var glue = Cc["@mozilla.org/browser/browserglue;1"]
  265.                  .getService(Ci.nsIBrowserGlue);
  266.     glue.sanitize(window || null);
  267.   }
  268.  
  269. };
  270.