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();
|
|
|
|
},
|
|
|
|
|
|
|
|
canClearItem: function (aItemName)
|
|
|
|
{
|
|
|
|
return this.items[aItemName].canClear;
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
_prefDomain: "privacy.item.",
|
|
|
|
getNameFromPreference: function (aPreferenceName)
|
|
|
|
{
|
|
|
|
return aPreferenceName.substr(this._prefDomain.length);
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
/**
|
|
|
|
* Deletes privacy sensitive data in a batch, according to user preferences
|
|
|
|
*
|
|
|
|
* @returns null if everything's fine; an object in the form
|
|
|
|
* { itemName: error, ... } on (partial) failure
|
|
|
|
*/
|
|
|
|
sanitize: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var branch = Services.prefs.getBranch(this._prefDomain);
|
2008-09-06 23:54:06 -07:00
|
|
|
var errors = null;
|
|
|
|
for (var itemName in this.items) {
|
|
|
|
var item = this.items[itemName];
|
|
|
|
if ("clear" in item && item.canClear && branch.getBoolPref(itemName)) {
|
|
|
|
// Some of these clear() may raise exceptions (see bug #265028)
|
2012-04-20 12:49:47 -07:00
|
|
|
// to sanitize as much as possible, we catch and store them,
|
2008-09-06 23:54:06 -07:00
|
|
|
// rather than fail fast.
|
|
|
|
// Callers should check returned errors and give user feedback
|
|
|
|
// about items that could not be sanitized
|
|
|
|
try {
|
|
|
|
item.clear();
|
|
|
|
} catch(er) {
|
2012-04-20 12:49:47 -07:00
|
|
|
if (!errors)
|
2008-09-06 23:54:06 -07:00
|
|
|
errors = {};
|
|
|
|
errors[itemName] = er;
|
|
|
|
dump("Error sanitizing " + itemName + ": " + er + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
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) {}
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
let imageCache = Cc["@mozilla.org/image/cache;1"].getService(Ci.imgICache);
|
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-01-09 15:59:14 -08:00
|
|
|
Services.contentPrefs.removeGroupedPrefs();
|
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 ()
|
|
|
|
{
|
2012-07-06 09:22:57 -07:00
|
|
|
sendMessageToJava({ gecko: { type: "Sanitize:ClearHistory" } });
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// clear plain HTTP auth sessions
|
2010-07-13 07:36:09 -07:00
|
|
|
var authMgr = Cc['@mozilla.org/network/http-auth-manager;1'].getService(Ci.nsIHttpAuthManager);
|
2008-09-06 23:54:06 -07:00
|
|
|
authMgr.clearAll();
|
|
|
|
},
|
2012-04-20 12:49:47 -07:00
|
|
|
|
2008-09-06 23:54:06 -07:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// "Static" members
|
|
|
|
Sanitizer.prefDomain = "privacy.sanitize.";
|
|
|
|
Sanitizer.prefShutdown = "sanitizeOnShutdown";
|
|
|
|
Sanitizer.prefDidShutdown = "didShutdownSanitize";
|
|
|
|
|
|
|
|
Sanitizer._prefs = null;
|
2012-04-20 12:49:47 -07:00
|
|
|
Sanitizer.__defineGetter__("prefs", function()
|
2008-09-06 23:54:06 -07:00
|
|
|
{
|
|
|
|
return Sanitizer._prefs ? Sanitizer._prefs
|
2010-07-13 07:36:09 -07:00
|
|
|
: Sanitizer._prefs = Cc["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Ci.nsIPrefService)
|
2008-09-06 23:54:06 -07:00
|
|
|
.getBranch(Sanitizer.prefDomain);
|
|
|
|
});
|
|
|
|
|
2012-04-20 12:49:47 -07:00
|
|
|
/**
|
|
|
|
* Deletes privacy sensitive data in a batch, optionally showing the
|
2008-09-06 23:54:06 -07:00
|
|
|
* sanitize UI, according to user preferences
|
|
|
|
*
|
2010-07-13 07:12:39 -07:00
|
|
|
* @returns null if everything's fine
|
2008-09-06 23:54:06 -07:00
|
|
|
* an object in the form { itemName: error, ... } on (partial) failure
|
|
|
|
*/
|
2012-04-20 12:49:47 -07:00
|
|
|
Sanitizer.sanitize = function()
|
2008-09-06 23:54:06 -07:00
|
|
|
{
|
|
|
|
return new Sanitizer().sanitize();
|
|
|
|
};
|
|
|
|
|
2012-04-20 12:49:47 -07:00
|
|
|
Sanitizer.onStartup = function()
|
2008-09-06 23:54:06 -07:00
|
|
|
{
|
|
|
|
// we check for unclean exit with pending sanitization
|
|
|
|
Sanitizer._checkAndSanitize();
|
|
|
|
};
|
|
|
|
|
2012-04-20 12:49:47 -07:00
|
|
|
Sanitizer.onShutdown = function()
|
2008-09-06 23:54:06 -07:00
|
|
|
{
|
|
|
|
// we check if sanitization is needed and perform it
|
|
|
|
Sanitizer._checkAndSanitize();
|
|
|
|
};
|
|
|
|
|
|
|
|
// this is called on startup and shutdown, to perform pending sanitizations
|
2012-04-20 12:49:47 -07:00
|
|
|
Sanitizer._checkAndSanitize = function()
|
2008-09-06 23:54:06 -07:00
|
|
|
{
|
|
|
|
const prefs = Sanitizer.prefs;
|
2012-04-20 12:49:47 -07:00
|
|
|
if (prefs.getBoolPref(Sanitizer.prefShutdown) &&
|
2008-09-06 23:54:06 -07:00
|
|
|
!prefs.prefHasUserValue(Sanitizer.prefDidShutdown)) {
|
|
|
|
// this is a shutdown or a startup after an unclean exit
|
2010-07-13 07:12:39 -07:00
|
|
|
Sanitizer.sanitize() || // sanitize() returns null on full success
|
2008-09-06 23:54:06 -07:00
|
|
|
prefs.setBoolPref(Sanitizer.prefDidShutdown, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|