2015-09-24 20:32:09 +00:00
|
|
|
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
2015-07-27 17:18:19 +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
|
|
|
|
2017-02-22 17:02:59 +00:00
|
|
|
/* import-globals-from sanitizeDialog.js */
|
|
|
|
|
2013-03-20 17:09:41 +00:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2014-09-24 16:22:05 +00:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2015-07-27 17:18:19 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
|
|
|
|
"resource://gre/modules/AppConstants.jsm");
|
2013-03-20 17:09:41 +00:00
|
|
|
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");
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "DownloadsCommon",
|
|
|
|
"resource:///modules/DownloadsCommon.jsm");
|
2015-01-27 01:58:22 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch",
|
|
|
|
"resource://gre/modules/TelemetryStopwatch.jsm");
|
2015-07-27 17:18:19 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "console",
|
2015-10-14 21:40:08 +00:00
|
|
|
"resource://gre/modules/Console.jsm");
|
2015-07-27 17:18:19 +00:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "setTimeout",
|
|
|
|
"resource://gre/modules/Timer.jsm");
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2017-06-07 21:23:47 +00:00
|
|
|
var {classes: Cc, interfaces: Ci} = Components;
|
2017-05-31 21:24:52 +00:00
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
/**
|
|
|
|
* A number of iterations after which to yield time back
|
|
|
|
* to the system.
|
|
|
|
*/
|
|
|
|
const YIELD_PERIOD = 10;
|
|
|
|
|
|
|
|
function Sanitizer() {
|
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
Sanitizer.prototype = {
|
2005-08-23 16:38:28 +00:00
|
|
|
// warning to the caller: this one may raise an exception (e.g. bug #265028)
|
2016-12-31 02:47:25 +00:00
|
|
|
clearItem(aItemName) {
|
2015-10-07 17:46:35 +00:00
|
|
|
this.items[aItemName].clear();
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2009-05-21 09:51:56 +00:00
|
|
|
prefDomain: "",
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2016-12-31 02:47:25 +00:00
|
|
|
getNameFromPreference(aPreferenceName) {
|
2008-11-06 03:57:00 +00:00
|
|
|
return aPreferenceName.substr(this.prefDomain.length);
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +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.
|
2014-09-24 16:22:05 +00:00
|
|
|
*
|
2016-04-13 12:08:18 +00:00
|
|
|
* @param [optional] itemsToClear
|
|
|
|
* Array of items to be cleared. if specified only those
|
|
|
|
* items get cleared, irrespectively of the preference settings.
|
|
|
|
* @param [optional] options
|
|
|
|
* Object whose properties are options for this sanitization.
|
|
|
|
* TODO (bug 1167238) document options here.
|
2005-08-23 16:38:28 +00:00
|
|
|
*/
|
2017-05-12 12:42:39 +00:00
|
|
|
async sanitize(itemsToClear = null, options = {}) {
|
2016-04-13 12:08:18 +00:00
|
|
|
let progress = options.progress || {};
|
|
|
|
let promise = this._sanitize(itemsToClear, progress);
|
2015-07-27 17:18:19 +00:00
|
|
|
|
|
|
|
// Depending on preferences, the sanitizer may perform asynchronous
|
|
|
|
// work before it starts cleaning up the Places database (e.g. closing
|
|
|
|
// windows). We need to make sure that the connection to that database
|
|
|
|
// hasn't been closed by the time we use it.
|
2016-04-13 12:08:18 +00:00
|
|
|
// Though, if this is a sanitize on shutdown, we already have a blocker.
|
|
|
|
if (!progress.isShutdown) {
|
|
|
|
let shutdownClient = Cc["@mozilla.org/browser/nav-history-service;1"]
|
|
|
|
.getService(Ci.nsPIPlacesDatabase)
|
|
|
|
.shutdownClient
|
|
|
|
.jsclient;
|
|
|
|
shutdownClient.addBlocker("sanitize.js: Sanitize",
|
|
|
|
promise,
|
|
|
|
{
|
|
|
|
fetchState: () => ({ progress })
|
2015-07-27 17:18:19 +00:00
|
|
|
}
|
2016-04-13 12:08:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
try {
|
2017-05-12 12:42:39 +00:00
|
|
|
await promise;
|
2015-07-27 17:18:19 +00:00
|
|
|
} finally {
|
2017-04-14 19:51:39 +00:00
|
|
|
Services.obs.notifyObservers(null, "sanitizer-sanitization-complete");
|
2015-07-27 17:18:19 +00:00
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
},
|
2015-07-27 17:18:19 +00:00
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
async _sanitize(aItemsToClear, progress = {}) {
|
2015-07-27 17:18:19 +00:00
|
|
|
let seenError = false;
|
|
|
|
let itemsToClear;
|
2014-09-24 16:22:05 +00:00
|
|
|
if (Array.isArray(aItemsToClear)) {
|
2015-07-27 17:18:19 +00:00
|
|
|
// Shallow copy the array, as we are going to modify
|
|
|
|
// it in place later.
|
|
|
|
itemsToClear = [...aItemsToClear];
|
2014-09-24 16:22:05 +00:00
|
|
|
} else {
|
|
|
|
let branch = Services.prefs.getBranch(this.prefDomain);
|
2015-08-10 09:07:54 +00:00
|
|
|
itemsToClear = Object.keys(this.items).filter(itemName => {
|
|
|
|
try {
|
|
|
|
return branch.getBoolPref(itemName);
|
|
|
|
} catch (ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2014-09-24 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
// Store the list of items to clear, in case we are killed before we
|
|
|
|
// get a chance to complete.
|
2017-07-31 10:51:35 +00:00
|
|
|
Services.prefs.setStringPref(Sanitizer.PREF_SANITIZE_IN_PROGRESS,
|
|
|
|
JSON.stringify(itemsToClear));
|
2015-07-27 17:18:19 +00:00
|
|
|
|
|
|
|
// Store the list of items to clear, for debugging/forensics purposes
|
|
|
|
for (let k of itemsToClear) {
|
|
|
|
progress[k] = "ready";
|
2014-09-24 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure open windows get cleared first, if they're in our list, so that they don't stick
|
|
|
|
// around in the recently closed windows list, and so we can cancel the whole thing
|
|
|
|
// if the user selects to keep a window open from a beforeunload prompt.
|
|
|
|
let openWindowsIndex = itemsToClear.indexOf("openWindows");
|
|
|
|
if (openWindowsIndex != -1) {
|
|
|
|
itemsToClear.splice(openWindowsIndex, 1);
|
2017-05-12 12:42:39 +00:00
|
|
|
await this.items.openWindows.clear();
|
2015-07-27 17:18:19 +00:00
|
|
|
progress.openWindows = "cleared";
|
2015-06-30 22:08:19 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 03:57:00 +00:00
|
|
|
// Cache the range of times to clear
|
2015-07-27 17:18:19 +00:00
|
|
|
let range = null;
|
|
|
|
// If we ignore timespan, clear everything,
|
|
|
|
// otherwise, pick a range.
|
|
|
|
if (!this.ignoreTimespan) {
|
2009-04-15 17:59:07 +00:00
|
|
|
range = this.range || Sanitizer.getClearRange();
|
2015-07-27 17:18:19 +00:00
|
|
|
}
|
2013-04-19 22:21:30 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
// For performance reasons we start all the clear tasks at once, then wait
|
|
|
|
// for their promises later.
|
|
|
|
// Some of the clear() calls may raise exceptions (for example bug 265028),
|
|
|
|
// we catch and store them, but continue to sanitize as much as possible.
|
|
|
|
// Callers should check returned errors and give user feedback
|
|
|
|
// about items that could not be sanitized
|
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_TOTAL", refObj);
|
|
|
|
|
|
|
|
let annotateError = (name, ex) => {
|
|
|
|
progress[name] = "failed";
|
|
|
|
seenError = true;
|
|
|
|
console.error("Error sanitizing " + name, ex);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Array of objects in form { name, promise }.
|
2016-02-29 16:26:12 +00:00
|
|
|
// `name` is the item's name and `promise` may be a promise, if the
|
|
|
|
// sanitization is asynchronous, or the function return value, otherwise.
|
|
|
|
let handles = [];
|
2016-12-22 11:03:28 +00:00
|
|
|
for (let name of itemsToClear) {
|
2016-02-29 16:26:12 +00:00
|
|
|
let item = this.items[name];
|
2015-07-27 17:18:19 +00:00
|
|
|
try {
|
2016-02-29 16:26:12 +00:00
|
|
|
// Catch errors here, so later we can just loop through these.
|
|
|
|
handles.push({ name,
|
|
|
|
promise: item.clear(range)
|
|
|
|
.then(() => progress[name] = "cleared",
|
|
|
|
ex => annotateError(name, ex))
|
|
|
|
});
|
2016-02-04 12:51:34 +00:00
|
|
|
} catch (ex) {
|
2016-02-29 16:26:12 +00:00
|
|
|
annotateError(name, ex);
|
2005-08-23 16:38:28 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
}
|
2016-02-29 16:26:12 +00:00
|
|
|
for (let handle of handles) {
|
|
|
|
progress[handle.name] = "blocking";
|
2017-05-12 12:42:39 +00:00
|
|
|
await handle.promise;
|
2016-02-29 16:26:12 +00:00
|
|
|
}
|
2013-04-19 22:21:30 +00:00
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
// Sanitization is complete.
|
2016-02-04 12:51:34 +00:00
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_TOTAL", refObj);
|
|
|
|
// Reset the inProgress preference since we were not killed during
|
|
|
|
// sanitization.
|
2017-07-31 10:51:35 +00:00
|
|
|
Services.prefs.clearUserPref(Sanitizer.PREF_SANITIZE_IN_PROGRESS);
|
2015-07-27 17:18:19 +00:00
|
|
|
progress = {};
|
|
|
|
if (seenError) {
|
|
|
|
throw new Error("Error sanitizing");
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +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
|
2017-03-21 18:29:43 +00:00
|
|
|
ignoreTimespan: true,
|
|
|
|
range: null,
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
items: {
|
|
|
|
cache: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2016-02-04 12:51:34 +00:00
|
|
|
let seenException;
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_CACHE", refObj);
|
2015-01-27 01:58:22 +00:00
|
|
|
|
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.
|
2016-02-04 12:51:34 +00:00
|
|
|
let cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
|
|
|
|
.getService(Ci.nsICacheStorageService);
|
2013-09-20 09:11:25 +00:00
|
|
|
cache.clear();
|
2016-02-04 12:51:34 +00:00
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
2010-07-12 01:01:53 +00:00
|
|
|
|
|
|
|
try {
|
2016-02-04 12:51:34 +00:00
|
|
|
let imageCache = Cc["@mozilla.org/image/tools;1"]
|
|
|
|
.getService(Ci.imgITools)
|
|
|
|
.getImgCacheForDocument(null);
|
2010-07-12 01:01:53 +00:00
|
|
|
imageCache.clearCache(false); // true=chrome, false=content
|
2016-02-04 12:51:34 +00:00
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_CACHE", refObj);
|
2016-02-04 12:51:34 +00:00
|
|
|
if (seenException) {
|
|
|
|
throw seenException;
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
cookies: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2016-02-04 12:51:34 +00:00
|
|
|
let seenException;
|
2015-07-27 17:18:19 +00:00
|
|
|
let yieldCounter = 0;
|
|
|
|
let refObj = {};
|
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
// Clear cookies.
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_COOKIES_2", refObj);
|
|
|
|
try {
|
|
|
|
let cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
|
|
|
|
.getService(Ci.nsICookieManager);
|
|
|
|
if (range) {
|
|
|
|
// Iterate through the cookies and delete any created after our cutoff.
|
|
|
|
let cookiesEnum = cookieMgr.enumerator;
|
|
|
|
while (cookiesEnum.hasMoreElements()) {
|
|
|
|
let cookie = cookiesEnum.getNext().QueryInterface(Ci.nsICookie2);
|
|
|
|
|
|
|
|
if (cookie.creationTime > range[0]) {
|
|
|
|
// This cookie was created after our cutoff, clear it
|
2016-02-25 15:41:13 +00:00
|
|
|
cookieMgr.remove(cookie.host, cookie.name, cookie.path,
|
2016-04-10 04:46:07 +00:00
|
|
|
false, cookie.originAttributes);
|
2016-02-04 12:51:34 +00:00
|
|
|
|
|
|
|
if (++yieldCounter % YIELD_PERIOD == 0) {
|
2017-05-12 12:42:39 +00:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 0)); // Don't block the main thread too long
|
2016-02-04 12:51:34 +00:00
|
|
|
}
|
2015-07-27 17:18:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} else {
|
2016-02-04 12:51:34 +00:00
|
|
|
// Remove everything
|
|
|
|
cookieMgr.removeAll();
|
2017-05-12 12:42:39 +00:00
|
|
|
await new Promise(resolve => setTimeout(resolve, 0)); // Don't block the main thread too long
|
2016-02-04 12:51:34 +00:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
} finally {
|
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_COOKIES_2", refObj);
|
2008-11-06 03:57:00 +00:00
|
|
|
}
|
2015-06-11 00:31:34 +00:00
|
|
|
|
2015-03-03 14:51:05 +00:00
|
|
|
// Clear deviceIds. Done asynchronously (returns before complete).
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
|
|
|
let mediaMgr = Components.classes["@mozilla.org/mediaManagerService;1"]
|
|
|
|
.getService(Ci.nsIMediaManagerService);
|
|
|
|
mediaMgr.sanitizeDeviceIds(range && range[0]);
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
2015-03-03 14:51:05 +00:00
|
|
|
|
2011-02-08 22:16:09 +00:00
|
|
|
// Clear plugin data.
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
2017-05-12 12:42:39 +00:00
|
|
|
await Sanitizer.clearPluginData(range);
|
2016-02-04 12:51:34 +00:00
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seenException) {
|
|
|
|
throw seenException;
|
|
|
|
}
|
2017-05-12 12:42:39 +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: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2016-07-26 15:27:17 +00:00
|
|
|
Components.utils.import("resource:///modules/offlineAppCache.jsm");
|
|
|
|
// This doesn't wait for the cleanup to be complete.
|
|
|
|
OfflineAppCacheHelper.clear();
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2008-01-23 04:06:36 +00:00
|
|
|
},
|
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
history: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2016-02-04 12:51:34 +00:00
|
|
|
let seenException;
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_HISTORY", refObj);
|
2005-02-25 09:07:58 +00:00
|
|
|
try {
|
2016-02-04 12:51:34 +00:00
|
|
|
if (range) {
|
2017-05-12 12:42:39 +00:00
|
|
|
await PlacesUtils.history.removeVisitsByFilter({
|
2016-02-04 12:51:34 +00:00
|
|
|
beginDate: new Date(range[0] / 1000),
|
|
|
|
endDate: new Date(range[1] / 1000)
|
2015-07-27 17:18:19 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Remove everything.
|
2017-05-12 12:42:39 +00:00
|
|
|
await PlacesUtils.history.clear();
|
2015-07-27 17:18:19 +00:00
|
|
|
}
|
2016-02-04 12:51:34 +00:00
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
2015-07-27 17:18:19 +00:00
|
|
|
} finally {
|
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_HISTORY", refObj);
|
|
|
|
}
|
2016-02-04 12:51:34 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
let clearStartingTime = range ? String(range[0]) : "";
|
|
|
|
Services.obs.notifyObservers(null, "browser:purge-session-history", clearStartingTime);
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let predictor = Components.classes["@mozilla.org/network/predictor;1"]
|
|
|
|
.getService(Components.interfaces.nsINetworkPredictor);
|
|
|
|
predictor.reset();
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seenException) {
|
|
|
|
throw seenException;
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
formdata: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2016-02-04 12:51:34 +00:00
|
|
|
let seenException;
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_FORMDATA", refObj);
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
2016-12-16 18:57:08 +00:00
|
|
|
// Clear undo history of all search bars.
|
2016-02-04 12:51:34 +00:00
|
|
|
let windows = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
while (windows.hasMoreElements()) {
|
|
|
|
let currentWindow = windows.getNext();
|
|
|
|
let currentDocument = currentWindow.document;
|
2016-12-16 18:57:08 +00:00
|
|
|
|
|
|
|
// searchBar.textbox may not exist due to the search bar binding
|
|
|
|
// not having been constructed yet if the search bar is in the
|
|
|
|
// overflow or menu panel. It won't have a value or edit history in
|
|
|
|
// that case.
|
2016-02-04 12:51:34 +00:00
|
|
|
let searchBar = currentDocument.getElementById("searchbar");
|
2016-12-16 18:57:08 +00:00
|
|
|
if (searchBar && searchBar.textbox)
|
2016-02-04 12:51:34 +00:00
|
|
|
searchBar.textbox.reset();
|
2016-12-16 18:57:08 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
let tabBrowser = currentWindow.gBrowser;
|
|
|
|
if (!tabBrowser) {
|
|
|
|
// No tab browser? This means that it's too early during startup (typically,
|
|
|
|
// Session Restore hasn't completed yet). Since we don't have find
|
|
|
|
// bars at that stage and since Session Restore will not restore
|
|
|
|
// find bars further down during startup, we have nothing to clear.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (let tab of tabBrowser.tabs) {
|
|
|
|
if (tabBrowser.isFindBarInitialized(tab))
|
|
|
|
tabBrowser.getFindBar(tab).clear();
|
|
|
|
}
|
|
|
|
// Clear any saved find value
|
|
|
|
tabBrowser._lastFindValue = "";
|
2013-07-06 00:56:36 +00:00
|
|
|
}
|
2016-02-04 12:51:34 +00:00
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
2006-02-01 15:22:15 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
|
|
|
let change = { op: "remove" };
|
|
|
|
if (range) {
|
|
|
|
[ change.firstUsedStart, change.firstUsedEnd ] = range;
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
await new Promise(resolve => {
|
2016-02-04 12:51:34 +00:00
|
|
|
FormHistory.update(change, {
|
|
|
|
handleError(e) {
|
|
|
|
seenException = new Error("Error " + e.result + ": " + e.message);
|
|
|
|
},
|
|
|
|
handleCompletion() {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
2013-04-19 22:21:30 +00:00
|
|
|
}
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_FORMDATA", refObj);
|
2016-02-04 12:51:34 +00:00
|
|
|
if (seenException) {
|
|
|
|
throw seenException;
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2005-02-25 09:07:58 +00:00
|
|
|
downloads: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_DOWNLOADS", refObj);
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
2013-11-04 18:21:13 +00:00
|
|
|
let filterByTime = null;
|
2016-02-04 12:51:34 +00:00
|
|
|
if (range) {
|
2013-11-04 18:21:13 +00:00
|
|
|
// Convert microseconds back to milliseconds for date comparisons.
|
2016-02-04 12:51:34 +00:00
|
|
|
let rangeBeginMs = range[0] / 1000;
|
|
|
|
let rangeEndMs = range[1] / 1000;
|
2013-11-04 18:21:13 +00:00
|
|
|
filterByTime = download => download.startTime >= rangeBeginMs &&
|
|
|
|
download.startTime <= rangeEndMs;
|
2008-11-06 03:57:00 +00:00
|
|
|
}
|
2013-11-04 18:21:13 +00:00
|
|
|
|
|
|
|
// Clear all completed/cancelled downloads
|
2017-05-12 12:42:39 +00:00
|
|
|
let list = await Downloads.getList(Downloads.ALL);
|
2013-11-04 18:21:13 +00:00
|
|
|
list.removeFinished(filterByTime);
|
2016-02-04 12:51:34 +00:00
|
|
|
} finally {
|
2015-07-27 17:18:19 +00:00
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_DOWNLOADS", refObj);
|
2016-02-04 12:51:34 +00:00
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2005-07-26 21:38:23 +00:00
|
|
|
sessions: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_SESSIONS", refObj);
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
|
|
|
// clear all auth tokens
|
|
|
|
let sdr = Components.classes["@mozilla.org/security/sdr;1"]
|
|
|
|
.getService(Components.interfaces.nsISecretDecoderRing);
|
|
|
|
sdr.logoutAndTeardown();
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
// clear FTP and plain HTTP auth sessions
|
2017-04-14 19:51:39 +00:00
|
|
|
Services.obs.notifyObservers(null, "net:clear-active-logins");
|
2016-02-04 12:51:34 +00:00
|
|
|
} finally {
|
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_SESSIONS", refObj);
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2009-01-20 15:59:49 +00:00
|
|
|
},
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2009-01-20 15:59:49 +00:00
|
|
|
siteSettings: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
2016-02-04 12:51:34 +00:00
|
|
|
let seenException;
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_SITESETTINGS", refObj);
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
let startDateMS = range ? range[0] / 1000 : null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Clear site-specific permissions like "Allow this site to open popups"
|
|
|
|
// we ignore the "end" range and hope it is now() - none of the
|
|
|
|
// interfaces used here support a true range anyway.
|
|
|
|
if (startDateMS == null) {
|
|
|
|
Services.perms.removeAll();
|
|
|
|
} else {
|
|
|
|
Services.perms.removeAllSince(startDateMS);
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
2014-10-14 05:03:31 +00:00
|
|
|
}
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
|
|
|
// Clear site-specific settings like page-zoom level
|
|
|
|
let cps = Components.classes["@mozilla.org/content-pref/service;1"]
|
|
|
|
.getService(Components.interfaces.nsIContentPrefService2);
|
|
|
|
if (startDateMS == null) {
|
|
|
|
cps.removeAllDomains(null);
|
|
|
|
} else {
|
|
|
|
cps.removeAllDomainsSince(startDateMS, null);
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
2014-10-14 05:03:31 +00:00
|
|
|
}
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2016-02-04 12:51:34 +00:00
|
|
|
try {
|
|
|
|
// Clear site security settings - no support for ranges in this
|
|
|
|
// interface either, so we clearAll().
|
|
|
|
let sss = Cc["@mozilla.org/ssservice;1"]
|
|
|
|
.getService(Ci.nsISiteSecurityService);
|
|
|
|
sss.clearAll();
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2015-04-21 18:10:51 +00:00
|
|
|
// Clear all push notification subscriptions
|
2015-07-29 16:12:51 +00:00
|
|
|
try {
|
2017-05-12 12:42:39 +00:00
|
|
|
await new Promise((resolve, reject) => {
|
2016-05-20 16:38:26 +00:00
|
|
|
let push = Cc["@mozilla.org/push/Service;1"]
|
|
|
|
.getService(Ci.nsIPushService);
|
|
|
|
push.clearForDomain("*", status => {
|
|
|
|
if (Components.isSuccessCode(status)) {
|
|
|
|
resolve();
|
|
|
|
} else {
|
|
|
|
reject(new Error("Error clearing push subscriptions: " +
|
|
|
|
status));
|
|
|
|
}
|
|
|
|
});
|
2015-12-08 20:41:48 +00:00
|
|
|
});
|
2016-05-20 16:38:26 +00:00
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
2015-07-29 16:12:51 +00:00
|
|
|
}
|
2015-04-21 18:10:51 +00:00
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_SITESETTINGS", refObj);
|
2016-02-04 12:51:34 +00:00
|
|
|
if (seenException) {
|
|
|
|
throw seenException;
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
}
|
2014-09-24 16:22:05 +00:00
|
|
|
},
|
2015-10-07 17:46:35 +00:00
|
|
|
|
2014-09-24 16:22:05 +00:00
|
|
|
openWindows: {
|
|
|
|
privateStateForNewWindow: "non-private",
|
2016-12-29 23:34:54 +00:00
|
|
|
_canCloseWindow(aWindow) {
|
2015-09-24 20:32:09 +00:00
|
|
|
if (aWindow.CanCloseWindow()) {
|
|
|
|
// We already showed PermitUnload for the window, so let's
|
|
|
|
// make sure we don't do it again when we actually close the
|
|
|
|
// window.
|
|
|
|
aWindow.skipNextCanClose = true;
|
|
|
|
return true;
|
2014-09-24 16:22:05 +00:00
|
|
|
}
|
2016-04-05 18:33:33 +00:00
|
|
|
return false;
|
2014-09-24 16:22:05 +00:00
|
|
|
},
|
2016-12-29 23:34:54 +00:00
|
|
|
_resetAllWindowClosures(aWindowList) {
|
2014-09-24 16:22:05 +00:00
|
|
|
for (let win of aWindowList) {
|
2015-09-24 20:32:09 +00:00
|
|
|
win.skipNextCanClose = false;
|
2014-09-24 16:22:05 +00:00
|
|
|
}
|
|
|
|
},
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear() {
|
2014-09-24 16:22:05 +00:00
|
|
|
// NB: this closes all *browser* windows, not other windows like the library, about window,
|
|
|
|
// browser console, etc.
|
|
|
|
|
|
|
|
// Keep track of the time in case we get stuck in la-la-land because of onbeforeunload
|
|
|
|
// dialogs
|
|
|
|
let existingWindow = Services.appShell.hiddenDOMWindow;
|
|
|
|
let startDate = existingWindow.performance.now();
|
|
|
|
|
|
|
|
// First check if all these windows are OK with being closed:
|
|
|
|
let windowEnumerator = Services.wm.getEnumerator("navigator:browser");
|
|
|
|
let windowList = [];
|
|
|
|
while (windowEnumerator.hasMoreElements()) {
|
|
|
|
let someWin = windowEnumerator.getNext();
|
|
|
|
windowList.push(someWin);
|
|
|
|
// If someone says "no" to a beforeunload prompt, we abort here:
|
|
|
|
if (!this._canCloseWindow(someWin)) {
|
|
|
|
this._resetAllWindowClosures(windowList);
|
2015-07-27 17:18:19 +00:00
|
|
|
throw new Error("Sanitize could not close windows: cancelled by user");
|
2014-09-24 16:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ...however, beforeunload prompts spin the event loop, and so the code here won't get
|
|
|
|
// hit until the prompt has been dismissed. If more than 1 minute has elapsed since we
|
|
|
|
// started prompting, stop, because the user might not even remember initiating the
|
|
|
|
// 'forget', and the timespans will be all wrong by now anyway:
|
|
|
|
if (existingWindow.performance.now() > (startDate + 60 * 1000)) {
|
|
|
|
this._resetAllWindowClosures(windowList);
|
2015-07-27 17:18:19 +00:00
|
|
|
throw new Error("Sanitize could not close windows: timeout");
|
2014-09-24 16:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If/once we get here, we should actually be able to close all windows.
|
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
let refObj = {};
|
|
|
|
TelemetryStopwatch.start("FX_SANITIZE_OPENWINDOWS", refObj);
|
2015-01-27 01:58:22 +00:00
|
|
|
|
2014-09-24 16:22:05 +00:00
|
|
|
// First create a new window. We do this first so that on non-mac, we don't
|
|
|
|
// accidentally close the app by closing all the windows.
|
|
|
|
let handler = Cc["@mozilla.org/browser/clh;1"].getService(Ci.nsIBrowserHandler);
|
|
|
|
let defaultArgs = handler.defaultArgs;
|
|
|
|
let features = "chrome,all,dialog=no," + this.privateStateForNewWindow;
|
|
|
|
let newWindow = existingWindow.openDialog("chrome://browser/content/", "_blank",
|
|
|
|
features, defaultArgs);
|
|
|
|
|
2015-10-12 07:30:23 +00:00
|
|
|
let onFullScreen = null;
|
2015-07-27 17:18:19 +00:00
|
|
|
if (AppConstants.platform == "macosx") {
|
2015-10-12 07:30:23 +00:00
|
|
|
onFullScreen = function(e) {
|
2015-07-27 17:18:19 +00:00
|
|
|
newWindow.removeEventListener("fullscreen", onFullScreen);
|
|
|
|
let docEl = newWindow.document.documentElement;
|
|
|
|
let sizemode = docEl.getAttribute("sizemode");
|
|
|
|
if (!newWindow.fullScreen && sizemode == "fullscreen") {
|
|
|
|
docEl.setAttribute("sizemode", "normal");
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-05 18:33:33 +00:00
|
|
|
return undefined;
|
2015-01-27 01:58:22 +00:00
|
|
|
}
|
2015-07-27 17:18:19 +00:00
|
|
|
newWindow.addEventListener("fullscreen", onFullScreen);
|
2014-10-27 03:46:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
let promiseReady = new Promise(resolve => {
|
|
|
|
// Window creation and destruction is asynchronous. We need to wait
|
|
|
|
// until all existing windows are fully closed, and the new window is
|
|
|
|
// fully open, before continuing. Otherwise the rest of the sanitizer
|
|
|
|
// could run too early (and miss new cookies being set when a page
|
|
|
|
// closes) and/or run too late (and not have a fully-formed window yet
|
|
|
|
// in existence). See bug 1088137.
|
|
|
|
let newWindowOpened = false;
|
2015-10-12 07:30:23 +00:00
|
|
|
let onWindowOpened = function(subject, topic, data) {
|
2015-07-27 17:18:19 +00:00
|
|
|
if (subject != newWindow)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Services.obs.removeObserver(onWindowOpened, "browser-delayed-startup-finished");
|
|
|
|
if (AppConstants.platform == "macosx") {
|
|
|
|
newWindow.removeEventListener("fullscreen", onFullScreen);
|
|
|
|
}
|
|
|
|
newWindowOpened = true;
|
2014-10-27 03:46:03 +00:00
|
|
|
// If we're the last thing to happen, invoke callback.
|
2015-07-27 17:18:19 +00:00
|
|
|
if (numWindowsClosing == 0) {
|
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_OPENWINDOWS", refObj);
|
|
|
|
resolve();
|
2015-01-27 01:58:22 +00:00
|
|
|
}
|
2014-10-27 03:46:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-27 17:18:19 +00:00
|
|
|
let numWindowsClosing = windowList.length;
|
2015-10-12 07:30:23 +00:00
|
|
|
let onWindowClosed = function() {
|
2015-07-27 17:18:19 +00:00
|
|
|
numWindowsClosing--;
|
|
|
|
if (numWindowsClosing == 0) {
|
|
|
|
Services.obs.removeObserver(onWindowClosed, "xul-window-destroyed");
|
|
|
|
// If we're the last thing to happen, invoke callback.
|
|
|
|
if (newWindowOpened) {
|
|
|
|
TelemetryStopwatch.finish("FX_SANITIZE_OPENWINDOWS", refObj);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-14 19:51:38 +00:00
|
|
|
Services.obs.addObserver(onWindowOpened, "browser-delayed-startup-finished");
|
|
|
|
Services.obs.addObserver(onWindowClosed, "xul-window-destroyed");
|
2015-07-27 17:18:19 +00:00
|
|
|
});
|
2014-10-27 03:46:03 +00:00
|
|
|
|
|
|
|
// Start the process of closing windows
|
2014-09-24 16:22:05 +00:00
|
|
|
while (windowList.length) {
|
|
|
|
windowList.pop().close();
|
|
|
|
}
|
|
|
|
newWindow.focus();
|
2017-05-12 12:42:39 +00:00
|
|
|
await promiseReady;
|
|
|
|
}
|
2014-09-24 16:22:05 +00:00
|
|
|
},
|
2016-12-20 14:24:06 +00:00
|
|
|
|
|
|
|
pluginData: {
|
2017-05-12 12:42:39 +00:00
|
|
|
async clear(range) {
|
|
|
|
await Sanitizer.clearPluginData(range);
|
|
|
|
},
|
2016-12-20 14:24:06 +00:00
|
|
|
},
|
2005-04-03 15:34:14 +00:00
|
|
|
}
|
2005-02-25 09:07:58 +00:00
|
|
|
};
|
|
|
|
|
2016-02-19 22:22:24 +00:00
|
|
|
// The preferences branch for the sanitizer.
|
2015-07-27 17:18:19 +00:00
|
|
|
Sanitizer.PREF_DOMAIN = "privacy.sanitize.";
|
2016-02-19 22:22:24 +00:00
|
|
|
// Whether we should sanitize on shutdown.
|
2015-07-27 17:18:19 +00:00
|
|
|
Sanitizer.PREF_SANITIZE_ON_SHUTDOWN = "privacy.sanitize.sanitizeOnShutdown";
|
2016-02-19 22:22:24 +00:00
|
|
|
// During a sanitization this is set to a json containing the array of items
|
|
|
|
// being sanitized, then cleared once the sanitization is complete.
|
|
|
|
// This allows to retry a sanitization on startup in case it was interrupted
|
|
|
|
// by a crash.
|
2015-07-27 17:18:19 +00:00
|
|
|
Sanitizer.PREF_SANITIZE_IN_PROGRESS = "privacy.sanitize.sanitizeInProgress";
|
2016-02-19 22:22:24 +00:00
|
|
|
// Whether the previous shutdown sanitization completed successfully.
|
2016-02-23 22:29:43 +00:00
|
|
|
// This is used to detect cases where we were supposed to sanitize on shutdown
|
|
|
|
// but due to a crash we were unable to. In such cases there may not be any
|
|
|
|
// sanitization in progress, cause we didn't have a chance to start it yet.
|
2015-07-27 17:18:19 +00:00
|
|
|
Sanitizer.PREF_SANITIZE_DID_SHUTDOWN = "privacy.sanitize.didShutdownSanitize";
|
2005-08-23 16:38:28 +00:00
|
|
|
|
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;
|
2014-09-24 16:22:05 +00:00
|
|
|
Sanitizer.TIMESPAN_5MIN = 5;
|
|
|
|
Sanitizer.TIMESPAN_24HOURS = 6;
|
2008-11-06 03:57:00 +00:00
|
|
|
|
|
|
|
// 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.
|
2016-11-11 16:10:51 +00:00
|
|
|
Sanitizer.getClearRange = function(ts) {
|
2009-04-15 17:59:07 +00:00
|
|
|
if (ts === undefined)
|
|
|
|
ts = Sanitizer.prefs.getIntPref("timeSpan");
|
2008-11-06 03:57:00 +00:00
|
|
|
if (ts === Sanitizer.TIMESPAN_EVERYTHING)
|
|
|
|
return null;
|
2013-08-21 07:36:07 +00:00
|
|
|
|
2008-11-06 03:57:00 +00:00
|
|
|
// PRTime is microseconds while JS time is milliseconds
|
|
|
|
var endDate = Date.now() * 1000;
|
|
|
|
switch (ts) {
|
2014-09-24 16:22:05 +00:00
|
|
|
case Sanitizer.TIMESPAN_5MIN :
|
|
|
|
var startDate = endDate - 300000000; // 5*60*1000000
|
|
|
|
break;
|
2008-11-06 03:57:00 +00:00
|
|
|
case Sanitizer.TIMESPAN_HOUR :
|
2014-09-24 16:22:05 +00:00
|
|
|
startDate = endDate - 3600000000; // 1*60*60*1000000
|
2008-11-06 03:57:00 +00:00
|
|
|
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;
|
2014-09-24 16:22:05 +00:00
|
|
|
case Sanitizer.TIMESPAN_24HOURS :
|
|
|
|
startDate = endDate - 86400000000; // 24*60*60*1000000
|
|
|
|
break;
|
2008-11-06 03:57:00 +00:00
|
|
|
default:
|
|
|
|
throw "Invalid time span for clear private data: " + ts;
|
|
|
|
}
|
|
|
|
return [startDate, endDate];
|
|
|
|
};
|
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
Sanitizer.clearPluginData = async function(range) {
|
2016-12-20 14:24:06 +00:00
|
|
|
// Clear plugin data.
|
|
|
|
// As evidenced in bug 1253204, clearing plugin data can sometimes be
|
|
|
|
// very, very long, for mysterious reasons. Unfortunately, this is not
|
|
|
|
// something actionable by Mozilla, so crashing here serves no purpose.
|
|
|
|
//
|
|
|
|
// For this reason, instead of waiting for sanitization to always
|
|
|
|
// complete, we introduce a soft timeout. Once this timeout has
|
|
|
|
// elapsed, we proceed with the shutdown of Firefox.
|
|
|
|
let seenException;
|
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
let promiseClearPluginData = async function() {
|
2016-12-20 14:24:06 +00:00
|
|
|
const FLAG_CLEAR_ALL = Ci.nsIPluginHost.FLAG_CLEAR_ALL;
|
|
|
|
let ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
|
|
|
|
|
|
|
// Determine age range in seconds. (-1 means clear all.) We don't know
|
|
|
|
// that range[1] is actually now, so we compute age range based
|
|
|
|
// on the lower bound. If range results in a negative age, do nothing.
|
|
|
|
let age = range ? (Date.now() / 1000 - range[0] / 1000000) : -1;
|
|
|
|
if (!range || age >= 0) {
|
|
|
|
let tags = ph.getPluginTags();
|
|
|
|
for (let tag of tags) {
|
|
|
|
try {
|
2017-05-12 12:42:39 +00:00
|
|
|
let rv = await new Promise(resolve =>
|
2016-12-20 14:24:06 +00:00
|
|
|
ph.clearSiteData(tag, null, FLAG_CLEAR_ALL, age, resolve)
|
|
|
|
);
|
|
|
|
// If the plugin doesn't support clearing by age, clear everything.
|
|
|
|
if (rv == Components.results.NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED) {
|
2017-05-12 12:42:39 +00:00
|
|
|
await new Promise(resolve =>
|
2016-12-20 14:24:06 +00:00
|
|
|
ph.clearSiteData(tag, null, FLAG_CLEAR_ALL, -1, resolve)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
// Ignore errors from plug-ins
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
};
|
2016-12-20 14:24:06 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
// We don't want to wait for this operation to complete...
|
|
|
|
promiseClearPluginData = promiseClearPluginData(range);
|
|
|
|
|
|
|
|
// ... at least, not for more than 10 seconds.
|
2017-05-12 12:42:39 +00:00
|
|
|
await Promise.race([
|
2016-12-20 14:24:06 +00:00
|
|
|
promiseClearPluginData,
|
|
|
|
new Promise(resolve => setTimeout(resolve, 10000 /* 10 seconds */))
|
|
|
|
]);
|
|
|
|
} catch (ex) {
|
|
|
|
seenException = ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detach waiting for plugin data to be cleared.
|
|
|
|
promiseClearPluginData.catch(() => {
|
|
|
|
// If this exception is raised before the soft timeout, it
|
|
|
|
// will appear in `seenException`. Otherwise, it's too late
|
|
|
|
// to do anything about it.
|
|
|
|
});
|
|
|
|
|
|
|
|
if (seenException) {
|
|
|
|
throw seenException;
|
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
};
|
2016-12-20 14:24:06 +00:00
|
|
|
|
2005-08-23 16:38:28 +00:00
|
|
|
Sanitizer._prefs = null;
|
2016-12-31 02:47:25 +00:00
|
|
|
Sanitizer.__defineGetter__("prefs", function() {
|
2005-08-23 16:38:28 +00:00
|
|
|
return Sanitizer._prefs ? Sanitizer._prefs
|
|
|
|
: Sanitizer._prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefService)
|
2015-07-27 17:18:19 +00:00
|
|
|
.getBranch(Sanitizer.PREF_DOMAIN);
|
2005-08-23 16:38:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Shows sanitization UI
|
2016-12-31 02:47:25 +00:00
|
|
|
Sanitizer.showUI = function(aParentWindow) {
|
2015-07-27 17:18:19 +00:00
|
|
|
let win = AppConstants.platform == "macosx" ?
|
2016-11-10 22:48:04 +00:00
|
|
|
null : // make this an app-modal window on Mac
|
2015-07-27 17:18:19 +00:00
|
|
|
aParentWindow;
|
2016-02-04 12:51:34 +00:00
|
|
|
Services.ww.openWindow(win,
|
|
|
|
"chrome://browser/content/sanitize.xul",
|
|
|
|
"Sanitize",
|
|
|
|
"chrome,titlebar,dialog,centerscreen,modal",
|
|
|
|
null);
|
2005-08-23 16:38:28 +00:00
|
|
|
};
|
|
|
|
|
2013-08-21 07:36:07 +00:00
|
|
|
/**
|
|
|
|
* Deletes privacy sensitive data in a batch, optionally showing the
|
2005-08-23 16:38:28 +00:00
|
|
|
* sanitize UI, according to user preferences
|
|
|
|
*/
|
2016-12-31 02:47:25 +00:00
|
|
|
Sanitizer.sanitize = function(aParentWindow) {
|
2009-01-02 00:00:49 +00:00
|
|
|
Sanitizer.showUI(aParentWindow);
|
2005-08-23 16:38:28 +00:00
|
|
|
};
|
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
Sanitizer.onStartup = async function() {
|
2016-02-19 22:22:24 +00:00
|
|
|
// Check if we were interrupted during the last shutdown sanitization.
|
|
|
|
let shutownSanitizationWasInterrupted =
|
2017-07-31 10:51:35 +00:00
|
|
|
Services.prefs.getBoolPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN, false) &&
|
|
|
|
Services.prefs.getPrefType(Sanitizer.PREF_SANITIZE_DID_SHUTDOWN) == Ci.nsIPrefBranch.PREF_INVALID;
|
2016-02-23 22:29:43 +00:00
|
|
|
|
2017-07-31 10:51:35 +00:00
|
|
|
if (Services.prefs.prefHasUserValue(Sanitizer.PREF_SANITIZE_DID_SHUTDOWN)) {
|
2016-02-23 22:29:43 +00:00
|
|
|
// Reset the pref, so that if we crash before having a chance to
|
|
|
|
// sanitize on shutdown, we will do at the next startup.
|
|
|
|
// Flushing prefs has a cost, so do this only if necessary.
|
2017-07-31 10:51:35 +00:00
|
|
|
Services.prefs.clearUserPref(Sanitizer.PREF_SANITIZE_DID_SHUTDOWN);
|
2016-02-23 22:29:43 +00:00
|
|
|
Services.prefs.savePrefFile(null);
|
|
|
|
}
|
2016-02-19 22:22:24 +00:00
|
|
|
|
2016-04-13 12:08:18 +00:00
|
|
|
// Make sure that we are triggered during shutdown.
|
|
|
|
let shutdownClient = Cc["@mozilla.org/browser/nav-history-service;1"]
|
|
|
|
.getService(Ci.nsPIPlacesDatabase)
|
|
|
|
.shutdownClient
|
|
|
|
.jsclient;
|
|
|
|
// We need to pass to sanitize() (through sanitizeOnShutdown) a state object
|
|
|
|
// that tracks the status of the shutdown blocker. This `progress` object
|
|
|
|
// will be updated during sanitization and reported with the crash in case of
|
|
|
|
// a shutdown timeout.
|
|
|
|
// We use the `options` argument to pass the `progress` object to sanitize().
|
|
|
|
let progress = { isShutdown: true };
|
|
|
|
shutdownClient.addBlocker("sanitize.js: Sanitize on shutdown",
|
|
|
|
() => sanitizeOnShutdown({ progress }),
|
|
|
|
{
|
|
|
|
fetchState: () => ({ progress })
|
2016-02-04 14:40:40 +00:00
|
|
|
}
|
2016-04-13 12:08:18 +00:00
|
|
|
);
|
2015-07-17 17:18:00 +00:00
|
|
|
|
2016-02-23 22:29:43 +00:00
|
|
|
// Check if Firefox crashed during a sanitization.
|
2017-07-31 10:51:35 +00:00
|
|
|
let lastInterruptedSanitization = Services.prefs.getStringPref(Sanitizer.PREF_SANITIZE_IN_PROGRESS, "");
|
2016-02-19 22:22:24 +00:00
|
|
|
if (lastInterruptedSanitization) {
|
2015-07-27 17:18:19 +00:00
|
|
|
let s = new Sanitizer();
|
2016-02-19 22:22:24 +00:00
|
|
|
// If the json is invalid this will just throw and reject the Task.
|
|
|
|
let itemsToClear = JSON.parse(lastInterruptedSanitization);
|
2017-05-12 12:42:39 +00:00
|
|
|
await s.sanitize(itemsToClear);
|
2016-02-19 22:22:24 +00:00
|
|
|
} else if (shutownSanitizationWasInterrupted) {
|
2016-02-23 22:29:43 +00:00
|
|
|
// Otherwise, could be we were supposed to sanitize on shutdown but we
|
|
|
|
// didn't have a chance, due to an earlier crash.
|
|
|
|
// In such a case, just redo a shutdown sanitize now, during startup.
|
2017-05-12 12:42:39 +00:00
|
|
|
await sanitizeOnShutdown();
|
2015-07-27 17:18:19 +00:00
|
|
|
}
|
2017-05-12 12:42:39 +00:00
|
|
|
};
|
2015-07-27 17:18:19 +00:00
|
|
|
|
2017-05-12 12:42:39 +00:00
|
|
|
var sanitizeOnShutdown = async function(options = {}) {
|
2017-07-31 10:51:35 +00:00
|
|
|
if (!Services.prefs.getBoolPref(Sanitizer.PREF_SANITIZE_ON_SHUTDOWN)) {
|
2015-07-27 17:18:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Need to sanitize upon shutdown
|
|
|
|
let s = new Sanitizer();
|
|
|
|
s.prefDomain = "privacy.clearOnShutdown.";
|
2017-05-12 12:42:39 +00:00
|
|
|
await s.sanitize(null, options);
|
2016-02-19 22:22:24 +00:00
|
|
|
// We didn't crash during shutdown sanitization, so annotate it to avoid
|
|
|
|
// sanitizing again on startup.
|
2017-07-31 10:51:35 +00:00
|
|
|
Services.prefs.setBoolPref(Sanitizer.PREF_SANITIZE_DID_SHUTDOWN, true);
|
2016-02-19 22:22:24 +00:00
|
|
|
Services.prefs.savePrefFile(null);
|
2017-05-12 12:42:39 +00:00
|
|
|
};
|