2010-07-13 07:12:39 -07:00
|
|
|
// -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Firefox Sanitizer.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Ben Goodger.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Goodger <ben@mozilla.org>
|
|
|
|
* Giorgio Maone <g.maone@informaction.com>
|
|
|
|
* Matt Brubeck <mbrubeck@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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;
|
|
|
|
},
|
|
|
|
|
|
|
|
_prefDomain: "privacy.item.",
|
|
|
|
getNameFromPreference: function (aPreferenceName)
|
|
|
|
{
|
|
|
|
return aPreferenceName.substr(this._prefDomain.length);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
// to sanitize as much as possible, we catch and store them,
|
|
|
|
// 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) {
|
|
|
|
if (!errors)
|
|
|
|
errors = {};
|
|
|
|
errors[itemName] = er;
|
|
|
|
dump("Error sanitizing " + itemName + ": " + er + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {}
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cookies: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var cookieMgr = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager);
|
2008-09-06 23:54:06 -07:00
|
|
|
cookieMgr.removeAll();
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2009-05-29 18:28:12 -07:00
|
|
|
|
|
|
|
geolocation: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
// 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("");
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
branch = Services.prefs.getBranch("geo.request.remember.");
|
2009-05-29 18:28:12 -07:00
|
|
|
branch.deleteBranch("");
|
|
|
|
} catch (e) {dump(e);}
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
2010-07-13 07:36:09 -07:00
|
|
|
var cps = Cc["@mozilla.org/content-pref/service;1"].getService(Ci.nsIContentPrefService);
|
2009-05-29 18:28:12 -07:00
|
|
|
cps.removeGroupedPrefs();
|
|
|
|
|
|
|
|
// Clear "Never remember passwords for this site", which is not handled by
|
|
|
|
// the permission manager
|
2010-07-13 07:36:09 -07:00
|
|
|
var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
2009-05-29 18:28:12 -07:00
|
|
|
var hosts = pwmgr.getAllDisabledHosts({})
|
|
|
|
for each (var host in hosts) {
|
|
|
|
pwmgr.setLoginSavingEnabled(host, true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {}
|
|
|
|
|
2010-07-13 07:36:09 -07:00
|
|
|
var storage = Cc["@mozilla.org/dom/storagemanager;1"].getService(Ci.nsIDOMStorageManager);
|
|
|
|
storage.clearOfflineApps();
|
2008-09-06 23:54:06 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
history: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var globalHistory = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
|
2008-09-06 23:54:06 -07:00
|
|
|
globalHistory.removeAllPages();
|
|
|
|
|
|
|
|
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) { }
|
|
|
|
|
|
|
|
// 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) { }
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
// bug 347231: Always allow clearing history due to dependencies on
|
|
|
|
// the browser:purge-session-history notification. (like error console)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
passwords: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
2008-09-06 23:54:06 -07:00
|
|
|
pwmgr.removeAllLogins();
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2010-07-13 07:36:09 -07:00
|
|
|
var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
2008-09-06 23:54:06 -07:00
|
|
|
var count = pwmgr.countLogins("", "", ""); // count all logins
|
|
|
|
return (count > 0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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();
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// "Static" members
|
|
|
|
Sanitizer.prefDomain = "privacy.sanitize.";
|
|
|
|
Sanitizer.prefShutdown = "sanitizeOnShutdown";
|
|
|
|
Sanitizer.prefDidShutdown = "didShutdownSanitize";
|
|
|
|
|
|
|
|
Sanitizer._prefs = null;
|
|
|
|
Sanitizer.__defineGetter__("prefs", function()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes privacy sensitive data in a batch, optionally showing the
|
|
|
|
* 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
|
|
|
|
*/
|
2010-07-13 07:12:39 -07:00
|
|
|
Sanitizer.sanitize = function()
|
2008-09-06 23:54:06 -07:00
|
|
|
{
|
|
|
|
return new Sanitizer().sanitize();
|
|
|
|
};
|
|
|
|
|
|
|
|
Sanitizer.onStartup = function()
|
|
|
|
{
|
|
|
|
// we check for unclean exit with pending sanitization
|
|
|
|
Sanitizer._checkAndSanitize();
|
|
|
|
};
|
|
|
|
|
|
|
|
Sanitizer.onShutdown = function()
|
|
|
|
{
|
|
|
|
// we check if sanitization is needed and perform it
|
|
|
|
Sanitizer._checkAndSanitize();
|
|
|
|
};
|
|
|
|
|
|
|
|
// this is called on startup and shutdown, to perform pending sanitizations
|
|
|
|
Sanitizer._checkAndSanitize = function()
|
|
|
|
{
|
|
|
|
const prefs = Sanitizer.prefs;
|
|
|
|
if (prefs.getBoolPref(Sanitizer.prefShutdown) &&
|
|
|
|
!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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|