gecko/mobile/android/chrome/content/sanitize.js

190 lines
5.0 KiB
JavaScript
Raw Normal View History

// -*- 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 ()
{
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_ANYWHERE);
} catch(er) {}
let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
.getImgCacheForDocument(null);
try {
imageCache.clearCache(false); // true=chrome, false=content
2008-09-06 23:54:06 -07:00
} catch(er) {}
},
2008-09-06 23:54:06 -07:00
get canClear()
{
return true;
}
},
2008-09-06 23:54:06 -07:00
cookies: {
clear: function ()
{
Services.cookies.removeAll();
// clear any network geolocation provider sessions
try {
var branch = Services.prefs.getBranch("geo.wifi.access_token.");
branch.deleteBranch("");
} catch (e) {dump(e);}
},
get canClear()
{
return true;
}
},
siteSettings: {
clear: function ()
{
// Clear site-specific permissions like "Allow this site to open popups"
Services.perms.removeAll();
// Clear site-specific settings like page-zoom level
Services.contentPrefs.removeGroupedPrefs(null);
// Clear "Never remember passwords for this site", which is not handled by
// the permission manager
var hosts = Services.logins.getAllDisabledHosts({})
for each (var host in hosts) {
Services.logins.setLoginSavingEnabled(host, true);
}
},
get canClear()
{
return true;
}
},
2008-09-06 23:54:06 -07:00
offlineApps: {
clear: function ()
{
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 ()
{
sendMessageToJava({ type: "Sanitize:ClearHistory" });
2008-09-06 23:54:06 -07:00
try {
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
2008-09-06 23:54:06 -07:00
}
catch (e) { }
2008-09-06 23:54:06 -07:00
// Clear last URL of the Open Web Location dialog
try {
Services.prefs.clearUserPref("general.open_location.last_url");
2008-09-06 23:54:06 -07:00
}
catch (e) { }
},
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;
}
},
2008-09-06 23:54:06 -07:00
formdata: {
clear: function ()
{
//Clear undo history of all searchBars
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();
}
}
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
2008-09-06 23:54:06 -07:00
formHistory.removeAllEntries();
},
2008-09-06 23:54:06 -07:00
get canClear()
{
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
2008-09-06 23:54:06 -07:00
return formHistory.hasEntries;
}
},
2008-09-06 23:54:06 -07:00
downloads: {
clear: function ()
{
var dlMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
2008-09-06 23:54:06 -07:00
dlMgr.cleanUp();
},
get canClear()
{
var dlMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
2008-09-06 23:54:06 -07:00
return dlMgr.canCleanUp;
}
},
2008-09-06 23:54:06 -07:00
passwords: {
clear: function ()
{
Services.logins.removeAllLogins();
2008-09-06 23:54:06 -07:00
},
2008-09-06 23:54:06 -07:00
get canClear()
{
let count = Services.logins.countLogins("", "", ""); // count all logins
2008-09-06 23:54:06 -07:00
return (count > 0);
}
},
2008-09-06 23:54:06 -07:00
sessions: {
clear: function ()
{
// clear all auth tokens
var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
2008-09-06 23:54:06 -07:00
sdr.logoutAndTeardown();
// 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
},
2008-09-06 23:54:06 -07:00
get canClear()
{
return true;
}
}
}
};