home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2005 December / maximum-cd-2005-12.iso / Software / Apps / FirefoxSetup1.0.7.exe / browser.xpi / bin / chrome / browser.jar / content / browser / pref / pref-privacy.js < prev    next >
Encoding:
Text File  |  2004-08-14  |  14.3 KB  |  367 lines

  1.  
  2.  
  3. var _elementIDs = ["histDay", "browserCacheDiskCache", "cookieBehavior", "enableCookies",
  4.                    "enableCookiesForOriginatingSiteOnly", "networkCookieLifetime",
  5.                    "enableFormFill", "enablePasswords", 
  6.                    "downloadsRetentionPolicy"];
  7.  
  8. function Startup() {
  9.  
  10.   // Initially disable the clear buttons when needed
  11.   var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory);
  12.   document.getElementById("history").setAttribute("cleardisabled", globalHistory.count == 0);
  13.   
  14.   var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"].getService();
  15.   cookieMgr = cookieMgr.QueryInterface(Components.interfaces.nsICookieManager);
  16.   var e = cookieMgr.enumerator;
  17.   document.getElementById("cookies").setAttribute("cleardisabled", !e.hasMoreElements());
  18.  
  19.   var passwdMgr = Components.classes["@mozilla.org/passwordmanager;1"].getService();
  20.   passwdMgr = passwdMgr.QueryInterface(Components.interfaces.nsIPasswordManager);
  21.   e = passwdMgr.enumerator;
  22.   document.getElementById("passwords").setAttribute("cleardisabled", !e.hasMoreElements());
  23.  
  24.   try {
  25.     e = PrivacyPanel.getDownloads();
  26.     var hasDownloads = e.hasMoreElements();
  27.   }
  28.   catch (e) {
  29.     hasDownloads = false;
  30.   }
  31.   document.getElementById("downloads").setAttribute("cleardisabled", !hasDownloads);
  32.   
  33.   var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
  34.                               .getService(Components.interfaces.nsIFormHistory);
  35.   document.getElementById("formfill").setAttribute("cleardisabled", formHistory.rowCount == 0);
  36.   
  37.   // set up the pref checkboxes according to the network.cookie.cookieBehavior pref
  38.   // 0: enabled
  39.   // 1: enabled for originating website only
  40.   // 2: disabled
  41.   var cookieBehavior = document.getElementById("cookieBehavior").getAttribute("value");
  42.   document.getElementById("enableCookies").checked = cookieBehavior != 2;
  43.   document.getElementById("enableCookiesForOriginatingSiteOnly").checked = cookieBehavior == 1;
  44.   updateCookieBroadcaster();
  45.  
  46.   var categories = document.getElementById("privacyCategories");
  47.   categories.addEventListener("clear", PrivacyPanel.clear, false);
  48.  
  49.   // XXXben - we do this because of a bug with the download retention window menulist. 
  50.   // The bug is that when the Options dialog opens, or you switch from another panel to
  51.   // this panel, style is incompletely resolved on the menulist's display area anonymous
  52.   // content - it is resolved on the all a/c subcomponents *except* menulist-label (the
  53.   // text nodes)... and (as a result, I think) when style is resolved later as the menulist
  54.   // goes from visbility: collapse to being visible, the menulist-label has the wrong parent
  55.   // style context which causes the style context parent checking to complain heartily. The
  56.   // symptom is that the menulist is not initialized with the currently selected value from
  57.   // preferences. I suspect this is related to the fact that the menulist is inserted into
  58.   // an XBL insertion point, as this problem does not occur when the menulist is placed outside
  59.   // the bound element. dbaron is helping me with this with a reduced test case, but in 
  60.   // the meantime, I'm working around this bug by placing the menulist outside the bound element
  61.   // until it is completely initialized and then scooting it in, which is what this code does. 
  62.   var drb = document.getElementById("downloadsRetentionBox");
  63.   var drp = document.getElementById("downloadsRetentionPolicy");
  64.   drp.removeAttribute("hidden");
  65.   document.documentElement.removeChild(drp);
  66.   drb.appendChild(drp);
  67.   
  68.   setMasterPasswordButtonLabel();
  69. }
  70.  
  71. function unload()
  72. {
  73.   var categories = document.getElementById("privacyCategories");
  74.   for (var i = 0; i < categories.childNodes.length; ++i) {
  75.     var expander = categories.childNodes[i];
  76.     document.persist(expander.id, "open");
  77.   }  
  78. }
  79.  
  80. function cookieViewerOnPrefsOK()
  81. {
  82.   var dataObject = parent.hPrefWindow.wsm.dataManager.pageData["chrome://browser/content/cookieviewer/CookieViewer.xul"].userData;
  83.   if ('deletedCookies' in dataObject) {
  84.     var cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"].getService();
  85.     cookiemanager = cookiemanager.QueryInterface(Components.interfaces.nsICookieManager);
  86.  
  87.     for (var p = 0; p < dataObject.deletedCookies.length; ++p) {
  88.       cookiemanager.remove(dataObject.deletedCookies[p].host,
  89.                            dataObject.deletedCookies[p].name,
  90.                            dataObject.deletedCookies[p].path,
  91.                            dataObject.cookieBool);
  92.     }
  93.   }
  94. }
  95.  
  96. var PrivacyPanel = {
  97.   confirm: function (aTitle, aMessage, aActionButtonLabel)
  98.   {
  99.     var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  100.  
  101.     var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0;
  102.     flags += promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1;
  103.  
  104.     rv = promptService.confirmEx(window, aTitle, aMessage, flags, aActionButtonLabel, null, null, null, { value: 0 });
  105.     return rv == 0;
  106.   },
  107.  
  108.   clear: function (aEvent) {
  109.     if (aEvent.target.localName != "expander") 
  110.       return;
  111.       
  112.     var rv = PrivacyPanel.clearData[aEvent.target.id](true);
  113.     if (rv)
  114.       aEvent.target.setAttribute("cleardisabled", "true");
  115.   },
  116.   
  117.   clearAll: function () {
  118.     var privacyBundle = document.getElementById("privacyBundle");
  119.     var title = privacyBundle.getString("prefRemoveAllTitle");
  120.     var msg = privacyBundle.getString("prefRemoveAllMsg");
  121.     var button = privacyBundle.getString("prefRemoveAllRemoveButton");
  122.     
  123.     if (PrivacyPanel.confirm(title, msg, button)) {
  124.       for (var fn in PrivacyPanel.clearData) {
  125.         PrivacyPanel.clearData[fn](false);
  126.         document.getElementById(fn).setAttribute("cleardisabled", "true");
  127.       }
  128.     }
  129.   },
  130.   
  131.   getDownloads: function() {
  132.     var dlMgr = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager);
  133.     var ds = dlMgr.datasource;
  134.     
  135.     var rdfs = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  136.     var root = rdfs.GetResource("NC:DownloadsRoot");
  137.     
  138.     var rdfc = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
  139.     rdfc.Init(ds, root);
  140.   
  141.     return rdfc.GetElements();
  142.   },
  143.   
  144.   clearData: { 
  145.     // The names of these functions match the id of the expander in the XUL file that correspond
  146.     // to them. 
  147.     history: function ()
  148.     {
  149.       var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"]
  150.                                     .getService(Components.interfaces.nsIBrowserHistory);
  151.       globalHistory.removeAllPages();
  152.       
  153.       var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  154.       os.notifyObservers(null, "browser:purge-session-history", "");
  155.       
  156.       return true;
  157.     },
  158.     
  159.     cache: function ()
  160.     {
  161.       function clearCacheOfType(aType)
  162.       {
  163.         var classID = Components.classes["@mozilla.org/network/cache-service;1"];
  164.         var cacheService = classID.getService(Components.interfaces.nsICacheService);
  165.         cacheService.evictEntries(aType);
  166.       }
  167.     
  168.       clearCacheOfType(Components.interfaces.nsICache.STORE_ON_DISK);
  169.       clearCacheOfType(Components.interfaces.nsICache.STORE_IN_MEMORY);
  170.       
  171.       return true;
  172.     },
  173.     
  174.     cookies: function ()
  175.     { 
  176.       var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"].getService();
  177.       cookieMgr = cookieMgr.QueryInterface(Components.interfaces.nsICookieManager);
  178.  
  179.       var e = cookieMgr.enumerator;
  180.       var cookies = [];
  181.       while (e.hasMoreElements()) {
  182.         var cookie = e.getNext().QueryInterface(Components.interfaces.nsICookie);
  183.         cookies.push(cookie);
  184.       }
  185.  
  186.       for (var i = 0; i < cookies.length; ++i)
  187.         cookieMgr.remove(cookies[i].host, cookies[i].name, cookies[i].path, false);
  188.       
  189.       return true;
  190.     },
  191.     
  192.     formfill: function ()
  193.     {
  194.       var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
  195.                                   .getService(Components.interfaces.nsIFormHistory);
  196.       formHistory.removeAllEntries();
  197.       
  198.       return true;
  199.     },
  200.     
  201.     downloads: function ()
  202.     {
  203.       var dlMgr = Components.classes["@mozilla.org/download-manager;1"].getService(Components.interfaces.nsIDownloadManager);
  204.       try {
  205.         var downloads = PrivacyPanel.getDownloads();
  206.       }
  207.       catch (e) {
  208.         return true;
  209.       }
  210.  
  211.       var rdfs = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  212.       var state = rdfs.GetResource("http://home.netscape.com/NC-rdf#DownloadState");
  213.       var ds = dlMgr.datasource;
  214.       var dls = [];
  215.       
  216.       while (downloads.hasMoreElements()) {
  217.         var download = downloads.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
  218.         dls.push(download);
  219.       }
  220.       dlMgr.startBatchUpdate();
  221.       for (var i = 0; i < dls.length; ++i) {
  222.         try {
  223.           dlMgr.removeDownload(dls[i].Value);
  224.         }
  225.         catch (e) {
  226.         }
  227.       }
  228.       dlMgr.endBatchUpdate();  
  229.       
  230.       return true;
  231.     },
  232.     
  233.     passwords: function (aShowPrompt)
  234.     {
  235.       var privacyBundle = document.getElementById("privacyBundle");
  236.       var title = privacyBundle.getString("prefRemovePasswdsTitle");
  237.       var msg = privacyBundle.getString("prefRemovePasswdsMsg");
  238.       var button = privacyBundle.getString("prefRemovePasswdsRemoveButton");
  239.       
  240.       if (!aShowPrompt || PrivacyPanel.confirm(title, msg, button)) {
  241.         var passwdMgr = Components.classes["@mozilla.org/passwordmanager;1"].getService();
  242.         passwdMgr = passwdMgr.QueryInterface(Components.interfaces.nsIPasswordManager);
  243.  
  244.         var e = passwdMgr.enumerator;
  245.         var passwds = [];
  246.         while (e.hasMoreElements()) {
  247.           var passwd = e.getNext().QueryInterface(Components.interfaces.nsIPassword);
  248.           passwds.push(passwd);
  249.         }
  250.         
  251.         for (var i = 0; i < passwds.length; ++i)
  252.           passwdMgr.removeUser(passwds[i].host, passwds[i].user);
  253.  
  254.         return true;
  255.       }
  256.       return false;
  257.     }
  258.   }  
  259. }
  260.  
  261. function viewCookies() 
  262. {
  263.   window.openDialog("chrome://browser/content/cookieviewer/CookieViewer.xul","_blank",
  264.                     "chrome,resizable=yes", "cookieManager");
  265. }
  266.  
  267. function viewCookieExceptions()
  268. {
  269.   var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  270.                      .getService(Components.interfaces.nsIWindowMediator);
  271.   var existingWindow = wm.getMostRecentWindow("exceptions");
  272.   if (existingWindow) {
  273.     existingWindow.setHost("");
  274.     existingWindow.focus();
  275.   }
  276.   else {
  277.     var params = { blockVisible   : true,
  278.                    sessionVisible : true,
  279.                    allowVisible   : true,
  280.                    prefilledHost  : "",
  281.                    permissionType : "cookie" };
  282.     window.openDialog("chrome://browser/content/cookieviewer/CookieExceptions.xul",
  283.                       "_blank", "chrome,modal,resizable=yes", params);
  284.   }
  285. }
  286.  
  287. function viewSignons() 
  288. {
  289.   window.openDialog("chrome://passwordmgr/content/passwordManager.xul","_blank",
  290.                     "chrome,resizable=yes", "8");
  291. }
  292.  
  293. function updateCookieBehavior()
  294. {
  295.   var cookiesEnabled = document.getElementById("enableCookies").checked;
  296.   var cookiesOriginating = document.getElementById("enableCookiesForOriginatingSiteOnly").checked;
  297.   document.getElementById("cookieBehavior").setAttribute("value", cookiesEnabled ? (cookiesOriginating ? 1 : 0) : 2);
  298. }
  299.  
  300. function updateCookieBroadcaster()
  301. {
  302.   cookieBehaviorIsLocked = parent.hPrefWindow.getPrefIsLocked("network.cookie.cookieBehavior");
  303.   cookieLifetimeIsLocked = parent.hPrefWindow.getPrefIsLocked("network.cookie.lifetimePolicy");
  304.  
  305.   var broadcaster = document.getElementById("cookieBroadcaster");
  306.   var checkbox    = document.getElementById("enableCookies");
  307.   var radiogroup  = document.getElementById("networkCookieLifetime");
  308.   if (!checkbox.checked) {
  309.     broadcaster.setAttribute("disabled", "true");
  310.     document.getElementById("enableCookiesForOriginatingSiteOnly").checked = false;
  311.     radiogroup.setAttribute("disabled", "true");
  312.   }
  313.   else {
  314.     broadcaster.removeAttribute("disabled");
  315.     if (!cookieLifetimeIsLocked)
  316.       radiogroup.removeAttribute("disabled");
  317.   }
  318.   if (cookieBehaviorIsLocked) {
  319.     checkbox.setAttribute("disabled", "true");
  320.     broadcaster.setAttribute("disabled", "true");
  321.   }
  322. }
  323.  
  324. function unexpandOld(event)
  325. {
  326.   var box = document.getElementById("privacyCategories");
  327.   var newExpander = event.originalTarget.parentNode.parentNode;
  328.   for (var i = 0; i < box.childNodes.length; ++i) {
  329.     if (box.childNodes[i] != newExpander && box.childNodes[i].getAttribute("open"))
  330.       box.childNodes[i].open = false;
  331.   }
  332. }
  333.  
  334. function changeMasterPassword()
  335. {
  336.   window.openDialog("chrome://browser/content/pref/pref-masterpass.xul","",
  337.                     "chrome,centerscreen,modal,resizable=yes");
  338.   setMasterPasswordButtonLabel();
  339. }
  340.  
  341. function setMasterPasswordButtonLabel()
  342. {
  343.   // see if there's a master password and set the button label accordingly
  344.   const nsPKCS11ModuleDB = "@mozilla.org/security/pkcs11moduledb;1";
  345.   const nsIPKCS11ModuleDB = Components.interfaces.nsIPKCS11ModuleDB;
  346.   const nsIPKCS11Slot = Components.interfaces.nsIPKCS11Slot;
  347.  
  348.   var secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
  349.   var slot = secmoddb.findSlotByName("");
  350.  
  351.   if (slot) {
  352.     var status = slot.status;
  353.     var masterPasswordBtn = document.getElementById("masterPasswordBtn");
  354.     var privacyBundle = document.getElementById("privacyBundle");
  355.     var buttonLabel = "";
  356.     if (status == nsIPKCS11Slot.SLOT_UNINITIALIZED
  357.       || status == nsIPKCS11Slot.SLOT_READY) {
  358.  
  359.       buttonLabel = privacyBundle.getString("setMasterPassword");
  360.       masterPasswordBtn.setAttribute("label",buttonLabel);
  361.     } else {
  362.       buttonLabel = privacyBundle.getString("changeMasterPassword");
  363.       masterPasswordBtn.setAttribute("label",buttonLabel);
  364.     }
  365.   }
  366. }
  367.