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