2010-07-13 07:12:39 -07:00
|
|
|
// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-09-06 23:54:06 -07:00
|
|
|
|
|
|
|
function Sanitizer() {}
|
|
|
|
Sanitizer.prototype = {
|
|
|
|
// warning to the caller: this one may raise an exception (e.g. bug #265028)
|
|
|
|
clearItem: function (aItemName)
|
|
|
|
{
|
|
|
|
if (this.items[aItemName].canClear)
|
|
|
|
this.items[aItemName].clear();
|
|
|
|
},
|
|
|
|
|
|
|
|
items: {
|
|
|
|
cache: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
|
2008-09-06 23:54:06 -07:00
|
|
|
try {
|
2010-07-13 07:12:39 -07:00
|
|
|
cacheService.evictEntries(Ci.nsICache.STORE_ANYWHERE);
|
|
|
|
} catch(er) {}
|
|
|
|
|
2012-09-17 09:18:40 -07:00
|
|
|
let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
|
|
|
|
.getImgCacheForDocument(null);
|
2010-07-13 07:12:39 -07:00
|
|
|
try {
|
|
|
|
imageCache.clearCache(false); // true=chrome, false=content
|
2008-09-06 23:54:06 -07:00
|
|
|
} catch(er) {}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
cookies: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2012-01-09 15:59:14 -08:00
|
|
|
Services.cookies.removeAll();
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2009-05-29 18:28:12 -07:00
|
|
|
// clear any network geolocation provider sessions
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
var branch = Services.prefs.getBranch("geo.wifi.access_token.");
|
2009-05-29 18:28:12 -07:00
|
|
|
branch.deleteBranch("");
|
|
|
|
} catch (e) {dump(e);}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2009-05-29 18:28:12 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
siteSettings: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
// Clear site-specific permissions like "Allow this site to open popups"
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.perms.removeAll();
|
2009-05-29 18:28:12 -07:00
|
|
|
|
|
|
|
// Clear site-specific settings like page-zoom level
|
2012-06-30 07:50:07 -07:00
|
|
|
Services.contentPrefs.removeGroupedPrefs(null);
|
2009-05-29 18:28:12 -07:00
|
|
|
|
|
|
|
// Clear "Never remember passwords for this site", which is not handled by
|
|
|
|
// the permission manager
|
2012-01-09 15:59:14 -08:00
|
|
|
var hosts = Services.logins.getAllDisabledHosts({})
|
2009-05-29 18:28:12 -07:00
|
|
|
for each (var host in hosts) {
|
2012-01-09 15:59:14 -08:00
|
|
|
Services.logins.setLoginSavingEnabled(host, true);
|
2009-05-29 18:28:12 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
offlineApps: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
|
2008-09-06 23:54:06 -07:00
|
|
|
try {
|
|
|
|
cacheService.evictEntries(Ci.nsICache.STORE_OFFLINE);
|
|
|
|
} catch(er) {}
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
history: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2013-02-01 17:36:38 -08:00
|
|
|
sendMessageToJava({ type: "Sanitize:ClearHistory" });
|
2012-07-06 09:22:57 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
|
2008-09-06 23:54:06 -07:00
|
|
|
}
|
|
|
|
catch (e) { }
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
// Clear last URL of the Open Web Location dialog
|
|
|
|
try {
|
2010-07-13 07:36:09 -07:00
|
|
|
Services.prefs.clearUserPref("general.open_location.last_url");
|
2008-09-06 23:54:06 -07:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
// bug 347231: Always allow clearing history due to dependencies on
|
|
|
|
// the browser:purge-session-history notification. (like error console)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
formdata: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
//Clear undo history of all searchBars
|
2010-07-13 07:36:09 -07:00
|
|
|
var windows = Services.wm.getEnumerator("navigator:browser");
|
2008-09-06 23:54:06 -07:00
|
|
|
while (windows.hasMoreElements()) {
|
|
|
|
var searchBar = windows.getNext().document.getElementById("searchbar");
|
|
|
|
if (searchBar) {
|
|
|
|
searchBar.value = "";
|
|
|
|
searchBar.textbox.editor.transactionManager.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
|
2008-09-06 23:54:06 -07:00
|
|
|
formHistory.removeAllEntries();
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
|
2008-09-06 23:54:06 -07:00
|
|
|
return formHistory.hasEntries;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
downloads: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var dlMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
2008-09-06 23:54:06 -07:00
|
|
|
dlMgr.cleanUp();
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var dlMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
2008-09-06 23:54:06 -07:00
|
|
|
return dlMgr.canCleanUp;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
passwords: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2012-01-09 15:59:14 -08:00
|
|
|
Services.logins.removeAllLogins();
|
2008-09-06 23:54:06 -07:00
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
2012-03-19 16:51:29 -07:00
|
|
|
let count = Services.logins.countLogins("", "", ""); // count all logins
|
2008-09-06 23:54:06 -07:00
|
|
|
return (count > 0);
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
sessions: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
// clear all auth tokens
|
2010-07-13 07:36:09 -07:00
|
|
|
var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
|
2008-09-06 23:54:06 -07:00
|
|
|
sdr.logoutAndTeardown();
|
|
|
|
|
2012-10-29 13:20:03 -07:00
|
|
|
// clear FTP and plain HTTP auth sessions
|
|
|
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
os.notifyObservers(null, "net:clear-active-logins", null);
|
2008-09-06 23:54:06 -07:00
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|