2005-02-25 09:07:58 +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/.
|
2005-02-25 09:07:58 +00:00
|
|
|
|
2013-03-20 17:09:41 +00:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
|
|
|
|
"resource://gre/modules/PlacesUtils.jsm");
|
2013-04-19 22:21:30 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
|
|
|
|
"resource://gre/modules/FormHistory.jsm");
|
2013-08-17 13:19:55 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
|
|
|
|
"resource://gre/modules/Downloads.jsm");
|
2013-05-08 23:08:07 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
|
|
|
"resource://gre/modules/commonjs/sdk/core/promise.js");
|
2013-08-17 13:19:55 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
|
|
|
"resource://gre/modules/Task.jsm");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
|
|
|
"resource:///modules/DownloadsCommon.jsm");
|
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
function Sanitizer() {}
|
|
|
|
Sanitizer.prototype = {
|
2005-08-23 16:38:28 +00:00
|
|
|
// warning to the caller: this one may raise an exception (e.g. bug #265028)
|
2005-02-25 09:07:58 +00:00
|
|
|
clearItem: function (aItemName)
|
|
|
|
{
|
|
|
|
if (this.items[aItemName].canClear)
|
|
|
|
this.items[aItemName].clear();
|
|
|
|
},
|
|
|
|
|
2013-04-19 22:21:30 +00:00
|
|
|
canClearItem: function (aItemName, aCallback, aArg)
|
2005-02-25 09:07:58 +00:00
|
|
|
{
|
2013-04-19 22:21:30 +00:00
|
|
|
let canClear = this.items[aItemName].canClear;
|
|
|
|
if (typeof canClear == "function") {
|
|
|
|
canClear(aCallback, aArg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aCallback(aItemName, canClear, aArg);
|
|
|
|
return canClear;
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
2009-05-21 09:51:56 +00:00
|
|
|
prefDomain: "",
|
2008-11-06 03:57:00 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
getNameFromPreference: function (aPreferenceName)
|
|
|
|
{
|
2008-11-06 03:57:00 +00:00
|
|
|
return aPreferenceName.substr(this.prefDomain.length);
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
2005-08-23 16:38:28 +00:00
|
|
|
/**
|
2013-05-08 23:08:07 +00:00
|
|
|
* Deletes privacy sensitive data in a batch, according to user preferences.
|
|
|
|
* Returns a promise which is resolved if no errors occurred. If an error
|
|
|
|
* occurs, a message is reported to the console and all other items are still
|
|
|
|
* cleared before the promise is finally rejected.
|
2005-08-23 16:38:28 +00:00
|
|
|
*/
|
2013-05-08 23:08:07 +00:00
|
|
|
sanitize: function ()
|
2005-02-25 09:07:58 +00:00
|
|
|
{
|
2013-05-08 23:08:07 +00:00
|
|
|
var deferred = Promise.defer();
|
2005-02-25 09:07:58 +00:00
|
|
|
var psvc = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService);
|
2008-11-06 03:57:00 +00:00
|
|
|
var branch = psvc.getBranch(this.prefDomain);
|
2013-05-08 23:08:07 +00:00
|
|
|
var seenError = false;
|
2008-11-06 03:57:00 +00:00
|
|
|
|
|
|
|
// Cache the range of times to clear
|
|
|
|
if (this.ignoreTimespan)
|
|
|
|
var range = null; // If we ignore timespan, clear everything
|
|
|
|
else
|
2009-04-15 17:59:07 +00:00
|
|
|
range = this.range || Sanitizer.getClearRange();
|
2013-04-19 22:21:30 +00:00
|
|
|
|
2013-05-08 23:08:07 +00:00
|
|
|
let itemCount = Object.keys(this.items).length;
|
|
|
|
let onItemComplete = function() {
|
|
|
|
if (!--itemCount) {
|
|
|
|
seenError ? deferred.reject() : deferred.resolve();
|
|
|
|
}
|
|
|
|
};
|
2005-02-25 09:07:58 +00:00
|
|
|
for (var itemName in this.items) {
|
2013-04-19 22:21:30 +00:00
|
|
|
let item = this.items[itemName];
|
2008-11-06 03:57:00 +00:00
|
|
|
item.range = range;
|
2013-04-19 22:21:30 +00:00
|
|
|
if ("clear" in item && branch.getBoolPref(itemName)) {
|
|
|
|
let clearCallback = (itemName, aCanClear) => {
|
|
|
|
// 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
|
|
|
|
let item = this.items[itemName];
|
|
|
|
try {
|
|
|
|
if (aCanClear)
|
|
|
|
item.clear();
|
|
|
|
} catch(er) {
|
2013-05-08 23:08:07 +00:00
|
|
|
seenError = true;
|
|
|
|
Cu.reportError("Error sanitizing " + itemName + ": " + er + "\n");
|
2013-04-19 22:21:30 +00:00
|
|
|
}
|
2013-05-08 23:08:07 +00:00
|
|
|
onItemComplete();
|
2013-04-19 22:21:30 +00:00
|
|
|
};
|
|
|
|
this.canClearItem(itemName, clearCallback);
|
2013-05-08 23:08:07 +00:00
|
|
|
} else {
|
|
|
|
onItemComplete();
|
2005-08-23 16:38:28 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
}
|
2013-04-19 22:21:30 +00:00
|
|
|
|
2013-05-08 23:08:07 +00:00
|
|
|
return deferred.promise;
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
2008-11-06 03:57:00 +00:00
|
|
|
// Time span only makes sense in certain cases. Consumers who want
|
2009-04-15 17:59:07 +00:00
|
|
|
// to only clear some private data can opt in by setting this to false,
|
|
|
|
// and can optionally specify a specific range. If timespan is not ignored,
|
|
|
|
// and range is not set, sanitize() will use the value of the timespan
|
|
|
|
// pref to determine a range
|
2008-11-06 03:57:00 +00:00
|
|
|
ignoreTimespan : true,
|
2009-04-15 17:59:07 +00:00
|
|
|
range : null,
|
2008-11-06 03:57:00 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
items: {
|
|
|
|
cache: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2008-11-06 03:57:00 +00:00
|
|
|
var cacheService = Cc["@mozilla.org/network/cache-service;1"].
|
|
|
|
getService(Ci.nsICacheService);
|
2005-10-05 19:42:00 +00:00
|
|
|
try {
|
2008-11-06 03:57:00 +00:00
|
|
|
// Cache doesn't consult timespan, nor does it have the
|
|
|
|
// facility for timespan-based eviction. Wipe it.
|
|
|
|
cacheService.evictEntries(Ci.nsICache.STORE_ANYWHERE);
|
2005-10-05 19:42:00 +00:00
|
|
|
} catch(er) {}
|
2010-07-12 01:01:53 +00:00
|
|
|
|
2012-09-17 16:18:40 +00:00
|
|
|
var imageCache = Cc["@mozilla.org/image/tools;1"].
|
|
|
|
getService(Ci.imgITools).getImgCacheForDocument(null);
|
2010-07-12 01:01:53 +00:00
|
|
|
try {
|
|
|
|
imageCache.clearCache(false); // true=chrome, false=content
|
|
|
|
} catch(er) {}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cookies: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
|
2008-11-06 03:57:00 +00:00
|
|
|
.getService(Ci.nsICookieManager);
|
|
|
|
if (this.range) {
|
|
|
|
// Iterate through the cookies and delete any created after our cutoff.
|
|
|
|
var cookiesEnum = cookieMgr.enumerator;
|
|
|
|
while (cookiesEnum.hasMoreElements()) {
|
|
|
|
var cookie = cookiesEnum.getNext().QueryInterface(Ci.nsICookie2);
|
|
|
|
|
|
|
|
if (cookie.creationTime > this.range[0])
|
|
|
|
// This cookie was created after our cutoff, clear it
|
|
|
|
cookieMgr.remove(cookie.host, cookie.name, cookie.path, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Remove everything
|
|
|
|
cookieMgr.removeAll();
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:16:09 +00:00
|
|
|
// Clear plugin data.
|
2011-04-11 20:00:30 +00:00
|
|
|
const phInterface = Ci.nsIPluginHost;
|
2011-02-08 22:16:09 +00:00
|
|
|
const FLAG_CLEAR_ALL = phInterface.FLAG_CLEAR_ALL;
|
2011-08-22 18:29:20 +00:00
|
|
|
let ph = Cc["@mozilla.org/plugin/host;1"].getService(phInterface);
|
2011-02-08 22:16:09 +00:00
|
|
|
|
|
|
|
// Determine age range in seconds. (-1 means clear all.) We don't know
|
|
|
|
// that this.range[1] is actually now, so we compute age range based
|
|
|
|
// on the lower bound. If this.range results in a negative age, do
|
|
|
|
// nothing.
|
|
|
|
let age = this.range ? (Date.now() / 1000 - this.range[0] / 1000000)
|
|
|
|
: -1;
|
|
|
|
if (!this.range || age >= 0) {
|
|
|
|
let tags = ph.getPluginTags();
|
|
|
|
for (let i = 0; i < tags.length; i++) {
|
|
|
|
try {
|
|
|
|
ph.clearSiteData(tags[i], null, FLAG_CLEAR_ALL, age);
|
|
|
|
} catch (e) {
|
|
|
|
// If the plugin doesn't support clearing by age, clear everything.
|
|
|
|
if (e.result == Components.results.
|
|
|
|
NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED) {
|
|
|
|
try {
|
|
|
|
ph.clearSiteData(tags[i], null, FLAG_CLEAR_ALL, -1);
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore errors from the plugin
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2011-08-22 18:29:20 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
2006-09-15 21:28:48 +00:00
|
|
|
return true;
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2011-08-22 18:29:20 +00:00
|
|
|
|
2008-01-23 04:06:36 +00:00
|
|
|
offlineApps: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2011-12-16 22:36:09 +00:00
|
|
|
Components.utils.import("resource:///modules/offlineAppCache.jsm");
|
|
|
|
OfflineAppCacheHelper.clear();
|
2008-01-23 04:06:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2011-12-16 22:36:09 +00:00
|
|
|
return true;
|
2008-01-23 04:06:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
history: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2008-11-06 03:57:00 +00:00
|
|
|
if (this.range)
|
2013-03-20 17:09:41 +00:00
|
|
|
PlacesUtils.history.removeVisitsByTimeframe(this.range[0], this.range[1]);
|
2008-11-06 03:57:00 +00:00
|
|
|
else
|
2013-03-20 17:09:41 +00:00
|
|
|
PlacesUtils.history.removeAllPages();
|
2005-02-25 09:07:58 +00:00
|
|
|
|
|
|
|
try {
|
2005-08-23 16:38:28 +00:00
|
|
|
var os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
2005-02-25 09:07:58 +00:00
|
|
|
os.notifyObservers(null, "browser:purge-session-history", "");
|
|
|
|
}
|
|
|
|
catch (e) { }
|
2007-10-03 21:47:37 +00:00
|
|
|
|
|
|
|
// Clear last URL of the Open Web Location dialog
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
2012-01-17 01:34:51 +00:00
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
2007-10-10 05:11:17 +00:00
|
|
|
try {
|
|
|
|
prefs.clearUserPref("general.open_location.last_url");
|
|
|
|
}
|
|
|
|
catch (e) { }
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2006-08-07 22:43:29 +00:00
|
|
|
// bug 347231: Always allow clearing history due to dependencies on
|
|
|
|
// the browser:purge-session-history notification. (like error console)
|
|
|
|
return true;
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
formdata: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2008-09-15 13:21:28 +00:00
|
|
|
// Clear undo history of all searchBars
|
|
|
|
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
var windows = windowManager.getEnumerator("navigator:browser");
|
2006-02-01 15:22:15 +00:00
|
|
|
while (windows.hasMoreElements()) {
|
2013-07-06 00:56:36 +00:00
|
|
|
let currentWindow = windows.getNext();
|
|
|
|
let currentDocument = currentWindow.document;
|
2012-10-22 11:42:53 +00:00
|
|
|
let searchBar = currentDocument.getElementById("searchbar");
|
2008-11-28 20:51:16 +00:00
|
|
|
if (searchBar)
|
|
|
|
searchBar.textbox.reset();
|
2013-07-06 00:56:36 +00:00
|
|
|
let tabBrowser = currentWindow.gBrowser;
|
|
|
|
for (let tab of tabBrowser.tabs) {
|
|
|
|
if (tabBrowser.isFindBarInitialized(tab))
|
|
|
|
tabBrowser.getFindBar(tab).clear();
|
|
|
|
}
|
|
|
|
// Clear any saved find value
|
|
|
|
tabBrowser._lastFindValue = "";
|
2006-02-01 15:22:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 22:21:30 +00:00
|
|
|
let change = { op: "remove" };
|
|
|
|
if (this.range) {
|
|
|
|
[ change.firstUsedStart, change.firstUsedEnd ] = this.range;
|
|
|
|
}
|
|
|
|
FormHistory.update(change);
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2008-09-15 13:21:28 +00:00
|
|
|
|
2013-04-19 22:21:30 +00:00
|
|
|
canClear : function(aCallback, aArg)
|
2005-02-25 09:07:58 +00:00
|
|
|
{
|
2008-09-15 13:21:28 +00:00
|
|
|
var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
var windows = windowManager.getEnumerator("navigator:browser");
|
|
|
|
while (windows.hasMoreElements()) {
|
2013-07-06 00:56:36 +00:00
|
|
|
let currentWindow = windows.getNext();
|
|
|
|
let currentDocument = currentWindow.document;
|
2012-10-22 11:42:53 +00:00
|
|
|
let searchBar = currentDocument.getElementById("searchbar");
|
2008-09-15 13:21:28 +00:00
|
|
|
if (searchBar) {
|
2012-10-22 11:42:53 +00:00
|
|
|
let transactionMgr = searchBar.textbox.editor.transactionManager;
|
2008-09-15 13:21:28 +00:00
|
|
|
if (searchBar.value ||
|
|
|
|
transactionMgr.numberOfUndoItems ||
|
2013-04-19 22:21:30 +00:00
|
|
|
transactionMgr.numberOfRedoItems) {
|
|
|
|
aCallback("formdata", true, aArg);
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-15 13:21:28 +00:00
|
|
|
}
|
2013-07-06 00:56:36 +00:00
|
|
|
let tabBrowser = currentWindow.gBrowser;
|
|
|
|
let findBarCanClear = Array.some(tabBrowser.tabs, function (aTab) {
|
|
|
|
return tabBrowser.isFindBarInitialized(aTab) &&
|
|
|
|
tabBrowser.getFindBar(aTab).canClear;
|
|
|
|
});
|
|
|
|
if (findBarCanClear) {
|
2013-04-19 22:21:30 +00:00
|
|
|
aCallback("formdata", true, aArg);
|
|
|
|
return false;
|
|
|
|
}
|
2008-09-15 13:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 22:21:30 +00:00
|
|
|
let count = 0;
|
|
|
|
let countDone = {
|
|
|
|
handleResult : function(aResult) count = aResult,
|
|
|
|
handleError : function(aError) Components.utils.reportError(aError),
|
|
|
|
handleCompletion :
|
|
|
|
function(aReason) { aCallback("formdata", aReason == 0 && count > 0, aArg); }
|
|
|
|
};
|
|
|
|
FormHistory.count({}, countDone);
|
|
|
|
return false;
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
downloads: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2013-08-17 13:19:55 +00:00
|
|
|
if (DownloadsCommon.useJSTransfer) {
|
|
|
|
Task.spawn(function () {
|
|
|
|
let filterByTime = this.range ?
|
|
|
|
(download => download.startTime >= this.range[0] &&
|
|
|
|
download.startTime <= this.range[1]) : null;
|
2008-11-06 03:57:00 +00:00
|
|
|
|
2013-08-17 13:19:55 +00:00
|
|
|
// Clear all completed/cancelled downloads
|
|
|
|
let publicList = yield Downloads.getPublicDownloadList();
|
|
|
|
publicList.removeFinished(filterByTime);
|
2012-05-25 11:24:35 +00:00
|
|
|
|
2013-08-17 13:19:55 +00:00
|
|
|
let privateList = yield Downloads.getPrivateDownloadList();
|
|
|
|
privateList.removeFinished(filterByTime);
|
|
|
|
}.bind(this)).then(null, Cu.reportError);
|
2008-11-06 03:57:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-17 13:19:55 +00:00
|
|
|
var dlMgr = Components.classes["@mozilla.org/download-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIDownloadManager);
|
|
|
|
|
|
|
|
if (this.range) {
|
|
|
|
// First, remove the completed/cancelled downloads
|
|
|
|
dlMgr.removeDownloadsByTimeframe(this.range[0], this.range[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Clear all completed/cancelled downloads
|
|
|
|
dlMgr.cleanUp();
|
|
|
|
dlMgr.cleanUpPrivate();
|
2008-11-06 03:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
2013-08-17 13:19:55 +00:00
|
|
|
canClear : function(aCallback, aArg)
|
2005-02-25 09:07:58 +00:00
|
|
|
{
|
2013-08-17 13:19:55 +00:00
|
|
|
if (DownloadsCommon.useJSTransfer) {
|
|
|
|
aCallback("downloads", true, aArg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var dlMgr = Components.classes["@mozilla.org/download-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIDownloadManager);
|
|
|
|
aCallback("downloads", dlMgr.canCleanUp || dlMgr.canCleanUpPrivate, aArg);
|
|
|
|
}
|
|
|
|
return false;
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
passwords: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2007-05-16 10:02:45 +00:00
|
|
|
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsILoginManager);
|
2008-11-06 03:57:00 +00:00
|
|
|
// Passwords are timeless, and don't respect the timeSpan setting
|
2007-05-16 10:02:45 +00:00
|
|
|
pwmgr.removeAllLogins();
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2007-05-16 10:02:45 +00:00
|
|
|
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsILoginManager);
|
2008-01-01 03:16:51 +00:00
|
|
|
var count = pwmgr.countLogins("", "", ""); // count all logins
|
|
|
|
return (count > 0);
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
2005-07-26 21:38:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sessions: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
|
|
|
// clear all auth tokens
|
|
|
|
var sdr = Components.classes["@mozilla.org/security/sdr;1"]
|
|
|
|
.getService(Components.interfaces.nsISecretDecoderRing);
|
|
|
|
sdr.logoutAndTeardown();
|
|
|
|
|
2009-02-23 18:28:17 +00: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);
|
2005-07-26 21:38:23 +00:00
|
|
|
},
|
|
|
|
|
2009-01-20 15:59:49 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
siteSettings: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2009-02-04 19:08:06 +00:00
|
|
|
// Clear site-specific permissions like "Allow this site to open popups"
|
2009-01-20 15:59:49 +00:00
|
|
|
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
2009-11-08 09:22:11 +00:00
|
|
|
.getService(Components.interfaces.nsIPermissionManager);
|
2009-01-20 15:59:49 +00:00
|
|
|
pm.removeAll();
|
|
|
|
|
2009-02-04 19:08:06 +00:00
|
|
|
// Clear site-specific settings like page-zoom level
|
2009-01-20 15:59:49 +00:00
|
|
|
var cps = Components.classes["@mozilla.org/content-pref/service;1"]
|
2013-03-30 02:08:49 +00:00
|
|
|
.getService(Components.interfaces.nsIContentPrefService2);
|
|
|
|
cps.removeAllDomains(null);
|
2009-02-04 19:08:06 +00:00
|
|
|
|
|
|
|
// Clear "Never remember passwords for this site", which is not handled by
|
|
|
|
// the permission manager
|
|
|
|
var pwmgr = Components.classes["@mozilla.org/login-manager;1"]
|
2009-11-08 09:22:11 +00:00
|
|
|
.getService(Components.interfaces.nsILoginManager);
|
|
|
|
var hosts = pwmgr.getAllDisabledHosts();
|
2009-02-04 19:08:06 +00:00
|
|
|
for each (var host in hosts) {
|
|
|
|
pwmgr.setLoginSavingEnabled(host, true);
|
|
|
|
}
|
2009-01-20 15:59:49 +00:00
|
|
|
},
|
|
|
|
|
2005-07-26 21:38:23 +00:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
};
|
|
|
|
|
2005-08-23 16:38:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// "Static" members
|
|
|
|
Sanitizer.prefDomain = "privacy.sanitize.";
|
|
|
|
Sanitizer.prefShutdown = "sanitizeOnShutdown";
|
|
|
|
Sanitizer.prefDidShutdown = "didShutdownSanitize";
|
|
|
|
|
2008-11-06 03:57:00 +00:00
|
|
|
// Time span constants corresponding to values of the privacy.sanitize.timeSpan
|
|
|
|
// pref. Used to determine how much history to clear, for various items
|
|
|
|
Sanitizer.TIMESPAN_EVERYTHING = 0;
|
|
|
|
Sanitizer.TIMESPAN_HOUR = 1;
|
|
|
|
Sanitizer.TIMESPAN_2HOURS = 2;
|
|
|
|
Sanitizer.TIMESPAN_4HOURS = 3;
|
|
|
|
Sanitizer.TIMESPAN_TODAY = 4;
|
|
|
|
|
|
|
|
// Return a 2 element array representing the start and end times,
|
|
|
|
// in the uSec-since-epoch format that PRTime likes. If we should
|
2009-04-15 17:59:07 +00:00
|
|
|
// clear everything, return null. Use ts if it is defined; otherwise
|
|
|
|
// use the timeSpan pref.
|
|
|
|
Sanitizer.getClearRange = function (ts) {
|
|
|
|
if (ts === undefined)
|
|
|
|
ts = Sanitizer.prefs.getIntPref("timeSpan");
|
2008-11-06 03:57:00 +00:00
|
|
|
if (ts === Sanitizer.TIMESPAN_EVERYTHING)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// PRTime is microseconds while JS time is milliseconds
|
|
|
|
var endDate = Date.now() * 1000;
|
|
|
|
switch (ts) {
|
|
|
|
case Sanitizer.TIMESPAN_HOUR :
|
|
|
|
var startDate = endDate - 3600000000; // 1*60*60*1000000
|
|
|
|
break;
|
|
|
|
case Sanitizer.TIMESPAN_2HOURS :
|
|
|
|
startDate = endDate - 7200000000; // 2*60*60*1000000
|
|
|
|
break;
|
|
|
|
case Sanitizer.TIMESPAN_4HOURS :
|
|
|
|
startDate = endDate - 14400000000; // 4*60*60*1000000
|
|
|
|
break;
|
|
|
|
case Sanitizer.TIMESPAN_TODAY :
|
|
|
|
var d = new Date(); // Start with today
|
|
|
|
d.setHours(0); // zero us back to midnight...
|
|
|
|
d.setMinutes(0);
|
|
|
|
d.setSeconds(0);
|
|
|
|
startDate = d.valueOf() * 1000; // convert to epoch usec
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw "Invalid time span for clear private data: " + ts;
|
|
|
|
}
|
|
|
|
return [startDate, endDate];
|
|
|
|
};
|
|
|
|
|
2005-08-23 16:38:28 +00:00
|
|
|
Sanitizer._prefs = null;
|
|
|
|
Sanitizer.__defineGetter__("prefs", function()
|
|
|
|
{
|
|
|
|
return Sanitizer._prefs ? Sanitizer._prefs
|
|
|
|
: Sanitizer._prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService)
|
|
|
|
.getBranch(Sanitizer.prefDomain);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Shows sanitization UI
|
|
|
|
Sanitizer.showUI = function(aParentWindow)
|
|
|
|
{
|
|
|
|
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowWatcher);
|
2005-09-23 21:53:04 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
ww.openWindow(null, // make this an app-modal window on Mac
|
|
|
|
#else
|
2005-08-23 16:38:28 +00:00
|
|
|
ww.openWindow(aParentWindow,
|
2005-09-23 21:53:04 +00:00
|
|
|
#endif
|
2005-08-23 16:38:28 +00:00
|
|
|
"chrome://browser/content/sanitize.xul",
|
|
|
|
"Sanitize",
|
2009-01-30 08:13:16 +00:00
|
|
|
"chrome,titlebar,dialog,centerscreen,modal",
|
2005-08-23 16:38:28 +00:00
|
|
|
null);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes privacy sensitive data in a batch, optionally showing the
|
|
|
|
* sanitize UI, according to user preferences
|
|
|
|
*/
|
|
|
|
Sanitizer.sanitize = function(aParentWindow)
|
|
|
|
{
|
2009-01-02 00:00:49 +00:00
|
|
|
Sanitizer.showUI(aParentWindow);
|
2005-08-23 16:38:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2009-05-21 09:51:56 +00:00
|
|
|
var s = new Sanitizer();
|
|
|
|
s.prefDomain = "privacy.clearOnShutdown.";
|
2013-05-08 23:08:07 +00:00
|
|
|
s.sanitize().then(function() {
|
|
|
|
prefs.setBoolPref(Sanitizer.prefDidShutdown, true);
|
|
|
|
});
|
2005-08-23 16:38:28 +00:00
|
|
|
}
|
|
|
|
};
|