2010-07-13 14:12:39 +00:00
|
|
|
// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00: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-07 06:54:06 +00:00
|
|
|
|
2013-02-06 00:08:02 +00:00
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
|
|
|
|
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
function dump(a) {
|
|
|
|
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendMessageToJava(aMessage) {
|
|
|
|
return Cc["@mozilla.org/android/bridge;1"]
|
|
|
|
.getService(Ci.nsIAndroidBridge)
|
|
|
|
.handleGeckoMessage(JSON.stringify(aMessage));
|
|
|
|
}
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["Sanitizer"];
|
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
function Sanitizer() {}
|
|
|
|
Sanitizer.prototype = {
|
|
|
|
clearItem: function (aItemName)
|
|
|
|
{
|
|
|
|
if (this.items[aItemName].canClear)
|
|
|
|
this.items[aItemName].clear();
|
|
|
|
},
|
|
|
|
|
|
|
|
items: {
|
|
|
|
cache: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 14:36:09 +00:00
|
|
|
var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
|
2008-09-07 06:54:06 +00:00
|
|
|
try {
|
2010-07-13 14:12:39 +00:00
|
|
|
cacheService.evictEntries(Ci.nsICache.STORE_ANYWHERE);
|
|
|
|
} catch(er) {}
|
|
|
|
|
2012-09-17 16:18:40 +00:00
|
|
|
let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
|
|
|
|
.getImgCacheForDocument(null);
|
2010-07-13 14:12:39 +00:00
|
|
|
try {
|
|
|
|
imageCache.clearCache(false); // true=chrome, false=content
|
2008-09-07 06:54:06 +00:00
|
|
|
} catch(er) {}
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
cookies: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2012-01-09 23:59:14 +00:00
|
|
|
Services.cookies.removeAll();
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2009-05-30 01:28:12 +00:00
|
|
|
// clear any network geolocation provider sessions
|
|
|
|
try {
|
2010-07-13 14:36:09 +00:00
|
|
|
var branch = Services.prefs.getBranch("geo.wifi.access_token.");
|
2009-05-30 01:28:12 +00:00
|
|
|
branch.deleteBranch("");
|
|
|
|
} catch (e) {dump(e);}
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2009-05-30 01:28:12 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
siteSettings: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
// Clear site-specific permissions like "Allow this site to open popups"
|
2010-07-13 14:36:09 +00:00
|
|
|
Services.perms.removeAll();
|
2009-05-30 01:28:12 +00:00
|
|
|
|
|
|
|
// Clear site-specific settings like page-zoom level
|
2012-06-30 14:50:07 +00:00
|
|
|
Services.contentPrefs.removeGroupedPrefs(null);
|
2009-05-30 01:28:12 +00:00
|
|
|
|
|
|
|
// Clear "Never remember passwords for this site", which is not handled by
|
|
|
|
// the permission manager
|
2012-01-09 23:59:14 +00:00
|
|
|
var hosts = Services.logins.getAllDisabledHosts({})
|
2009-05-30 01:28:12 +00:00
|
|
|
for each (var host in hosts) {
|
2012-01-09 23:59:14 +00:00
|
|
|
Services.logins.setLoginSavingEnabled(host, true);
|
2009-05-30 01:28:12 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
offlineApps: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 14:36:09 +00:00
|
|
|
var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
|
2008-09-07 06:54:06 +00:00
|
|
|
try {
|
|
|
|
cacheService.evictEntries(Ci.nsICache.STORE_OFFLINE);
|
|
|
|
} catch(er) {}
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
history: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2013-02-02 01:36:38 +00:00
|
|
|
sendMessageToJava({ type: "Sanitize:ClearHistory" });
|
2012-07-06 16:22:57 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
try {
|
2010-07-13 14:36:09 +00:00
|
|
|
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
|
2008-09-07 06:54:06 +00:00
|
|
|
}
|
|
|
|
catch (e) { }
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
// Clear last URL of the Open Web Location dialog
|
|
|
|
try {
|
2010-07-13 14:36:09 +00:00
|
|
|
Services.prefs.clearUserPref("general.open_location.last_url");
|
2008-09-07 06:54:06 +00:00
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00: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 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
formdata: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
//Clear undo history of all searchBars
|
2010-07-13 14:36:09 +00:00
|
|
|
var windows = Services.wm.getEnumerator("navigator:browser");
|
2008-09-07 06:54:06 +00:00
|
|
|
while (windows.hasMoreElements()) {
|
|
|
|
var searchBar = windows.getNext().document.getElementById("searchbar");
|
|
|
|
if (searchBar) {
|
|
|
|
searchBar.value = "";
|
|
|
|
searchBar.textbox.editor.transactionManager.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-13 14:36:09 +00:00
|
|
|
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
|
2008-09-07 06:54:06 +00:00
|
|
|
formHistory.removeAllEntries();
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
2010-07-13 14:36:09 +00:00
|
|
|
var formHistory = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
|
2008-09-07 06:54:06 +00:00
|
|
|
return formHistory.hasEntries;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
downloads: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 14:36:09 +00:00
|
|
|
var dlMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
2008-09-07 06:54:06 +00:00
|
|
|
dlMgr.cleanUp();
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2010-07-13 14:36:09 +00:00
|
|
|
var dlMgr = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
2008-09-07 06:54:06 +00:00
|
|
|
return dlMgr.canCleanUp;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
passwords: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2012-01-09 23:59:14 +00:00
|
|
|
Services.logins.removeAllLogins();
|
2008-09-07 06:54:06 +00:00
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
2012-03-19 23:51:29 +00:00
|
|
|
let count = Services.logins.countLogins("", "", ""); // count all logins
|
2008-09-07 06:54:06 +00:00
|
|
|
return (count > 0);
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
sessions: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
// clear all auth tokens
|
2010-07-13 14:36:09 +00:00
|
|
|
var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
|
2008-09-07 06:54:06 +00:00
|
|
|
sdr.logoutAndTeardown();
|
|
|
|
|
2012-10-29 20:20:03 +00:00
|
|
|
// clear FTP and plain HTTP auth sessions
|
2013-02-06 00:08:02 +00:00
|
|
|
Services.obs.notifyObservers(null, "net:clear-active-logins", null);
|
2008-09-07 06:54:06 +00:00
|
|
|
},
|
2012-04-20 19:49:47 +00:00
|
|
|
|
2008-09-07 06:54:06 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-06 00:08:02 +00:00
|
|
|
this.Sanitizer = new Sanitizer();
|