1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
15 # The Original Code is the Firefox Sanitizer.
17 # The Initial Developer of the Original Code is
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
23 # Ben Goodger <ben@mozilla.org>
24 # Giorgio Maone <g.maone@informaction.com>
25 # Johnathan Nightingale <johnath@mozilla.com>
26 # Ehsan Akhgari <ehsan.akhgari@gmail.com>
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.
40 # ***** END LICENSE BLOCK *****
45 clearItem:
function (aItemName)
47 if (this.items[aItemName].canClear)
48 this.items[aItemName].clear();
51 canClearItem:
function (aItemName)
53 return this.items[aItemName].canClear;
58 getNameFromPreference:
function (aPreferenceName)
60 return aPreferenceName.substr(this.
prefDomain.length);
71 var psvc = Components.classes[
"@mozilla.org/preferences-service;1"]
72 .getService(Components.interfaces.nsIPrefService);
77 if (this.ignoreTimespan)
80 range = this.range ||
Sanitizer.getClearRange();
82 for (var itemName in this.items) {
83 var item = this.items[itemName];
85 if (
"clear" in item && item.canClear && branch.getBoolPref(itemName)) {
96 errors[itemName] = er;
97 dump(
"Error sanitizing " + itemName +
": " + er +
"\n");
109 ignoreTimespan :
true,
116 const Cc = Components.classes;
117 const Ci = Components.interfaces;
123 cacheService.evictEntries(
Ci.nsICache.STORE_ANYWHERE);
136 const Ci = Components.interfaces;
137 var cookieMgr = Components.classes[
"@mozilla.org/cookiemanager;1"]
138 .getService(
Ci.nsICookieManager);
141 var cookiesEnum = cookieMgr.enumerator;
142 while (cookiesEnum.hasMoreElements()) {
143 var cookie = cookiesEnum.getNext().QueryInterface(
Ci.nsICookie2);
145 if (cookie.creationTime >
this.range[0])
147 cookieMgr.remove(cookie.host, cookie.name, cookie.path,
false);
152 cookieMgr.removeAll();
156 var psvc = Components.classes[
"@mozilla.org/preferences-service;1"]
157 .getService(Components.interfaces.nsIPrefService);
159 var branch = psvc.getBranch(
"geo.wifi.access_token.");
160 branch.deleteBranch(
"");
174 const Cc = Components.classes;
175 const Ci = Components.interfaces;
181 cacheService.evictEntries(
Ci.nsICache.STORE_OFFLINE);
184 var storageManagerService =
Cc[
"@mozilla.org/dom/storagemanager;1"].
186 storageManagerService.clearOfflineApps();
198 var globalHistory = Components.classes[
"@mozilla.org/browser/global-history;2"]
199 .getService(Components.interfaces.nsIBrowserHistory);
201 globalHistory.removeVisitsByTimeframe(this.
range[0], this.
range[1]);
203 globalHistory.removeAllPages();
206 var
os = Components.classes[
"@mozilla.org/observer-service;1"]
207 .getService(Components.interfaces.nsIObserverService);
208 os.notifyObservers(
null,
"browser:purge-session-history",
"");
213 var
prefs = Components.classes[
"@mozilla.org/preferences-service;1"]
214 .getService(Components.interfaces.nsIPrefBranch2);
216 prefs.clearUserPref(
"general.open_location.last_url");
233 var windowManager = Components.classes[
'@mozilla.org/appshell/window-mediator;1']
234 .getService(Components.interfaces.nsIWindowMediator);
235 var
windows = windowManager.getEnumerator(
"navigator:browser");
236 while (windows.hasMoreElements()) {
237 var searchBar = windows.getNext().document.getElementById(
"searchbar");
239 searchBar.textbox.reset();
242 var formHistory = Components.classes[
"@mozilla.org/satchel/form-history;1"]
243 .getService(Components.interfaces.nsIFormHistory2);
245 formHistory.removeEntriesByTimeframe(this.
range[0], this.
range[1]);
247 formHistory.removeAllEntries();
252 var windowManager = Components.classes[
'@mozilla.org/appshell/window-mediator;1']
253 .getService(Components.interfaces.nsIWindowMediator);
254 var
windows = windowManager.getEnumerator(
"navigator:browser");
255 while (windows.hasMoreElements()) {
256 var searchBar = windows.getNext().document.getElementById(
"searchbar");
258 var transactionMgr = searchBar.textbox.editor.transactionManager;
259 if (searchBar.value ||
260 transactionMgr.numberOfUndoItems ||
261 transactionMgr.numberOfRedoItems)
266 var formHistory = Components.classes[
"@mozilla.org/satchel/form-history;1"]
267 .getService(Components.interfaces.nsIFormHistory2);
268 return formHistory.hasEntries;
275 var dlMgr = Components.classes[
"@mozilla.org/download-manager;1"]
276 .getService(Components.interfaces.nsIDownloadManager);
278 var dlIDsToRemove = [];
281 dlMgr.removeDownloadsByTimeframe(this.
range[0], this.
range[1]);
284 var dlsEnum = dlMgr.activeDownloads;
285 while(dlsEnum.hasMoreElements()) {
286 var dl = dlsEnum.next();
287 if(dl.startTime >=
this.range[0])
288 dlIDsToRemove.push(dl.id);
296 var dlsEnum = dlMgr.activeDownloads;
297 while(dlsEnum.hasMoreElements()) {
298 dlIDsToRemove.push(dlsEnum.next().id);
303 dlIDsToRemove.forEach(
function(
id) {
304 dlMgr.removeDownload(
id);
310 var dlMgr = Components.classes[
"@mozilla.org/download-manager;1"]
311 .getService(Components.interfaces.nsIDownloadManager);
312 return dlMgr.canCleanUp;
319 var pwmgr = Components.classes[
"@mozilla.org/login-manager;1"]
320 .getService(Components.interfaces.nsILoginManager);
322 pwmgr.removeAllLogins();
327 var pwmgr = Components.classes[
"@mozilla.org/login-manager;1"]
328 .getService(Components.interfaces.nsILoginManager);
329 var
count = pwmgr.countLogins(
"",
"",
"");
338 var sdr = Components.classes[
"@mozilla.org/security/sdr;1"]
339 .getService(Components.interfaces.nsISecretDecoderRing);
340 sdr.logoutAndTeardown();
343 var
os = Components.classes[
"@mozilla.org/observer-service;1"]
344 .getService(Components.interfaces.nsIObserverService);
345 os.notifyObservers(
null,
"net:clear-active-logins",
null);
358 var pm = Components.classes[
"@mozilla.org/permissionmanager;1"]
359 .getService(Components.interfaces.nsIPermissionManager);
363 var cps = Components.classes[
"@mozilla.org/content-pref/service;1"]
364 .getService(Components.interfaces.nsIContentPrefService);
365 cps.removeGroupedPrefs();
369 var pwmgr = Components.classes[
"@mozilla.org/login-manager;1"]
370 .getService(Components.interfaces.nsILoginManager);
371 var hosts = pwmgr.getAllDisabledHosts({})
372 for each (var host in hosts) {
373 pwmgr.setLoginSavingEnabled(host,
true);
405 if (
ts === undefined)
411 var
endDate = Date.now() * 1000;
414 var startDate = endDate - 3600000000;
417 startDate = endDate - 7200000000;
420 startDate = endDate - 14400000000;
427 startDate = d.valueOf() * 1000;
430 throw "Invalid time span for clear private data: " +
ts;
436 Sanitizer.__defineGetter__(
"prefs",
function()
439 :
Sanitizer._prefs = Components.classes[
"@mozilla.org/preferences-service;1"]
440 .getService(Components.interfaces.nsIPrefService)
447 var
ww = Components.classes[
"@mozilla.org/embedcomp/window-watcher;1"]
448 .getService(Components.interfaces.nsIWindowWatcher);
452 ww.openWindow(aParentWindow,
454 "chrome://browser/content/sanitize.xul",
456 "chrome,titlebar,dialog,centerscreen,modal",
489 s.prefDomain =
"privacy.clearOnShutdown.";
getService(Ci.sbIFaceplateManager)
_setDateDatepicker endDate