2014-06-25 09:12:07 +04:00
|
|
|
// -*- indent-tabs-mode: nil; js-indent-level: 4 -*-
|
2012-05-21 15:12:37 +04: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 10:54:06 +04:00
|
|
|
|
2013-02-06 04:08:02 +04:00
|
|
|
let Cc = Components.classes;
|
|
|
|
let Ci = Components.interfaces;
|
2013-06-05 02:59:50 +04:00
|
|
|
let Cu = Components.utils;
|
2013-02-06 04:08:02 +04:00
|
|
|
|
2013-06-05 02:59:50 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-09-24 23:31:12 +04:00
|
|
|
Cu.import("resource://gre/modules/LoadContextInfo.jsm");
|
|
|
|
Cu.import("resource://gre/modules/FormHistory.jsm");
|
2014-02-11 21:16:00 +04:00
|
|
|
Cu.import("resource://gre/modules/Messaging.jsm");
|
2013-02-06 04:08:02 +04:00
|
|
|
|
|
|
|
function dump(a) {
|
2013-08-08 19:05:48 +04:00
|
|
|
Services.console.logStringMessage(a);
|
2013-02-06 04:08:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["Sanitizer"];
|
|
|
|
|
2013-02-06 04:08:03 +04:00
|
|
|
let downloads = {
|
|
|
|
dlmgr: Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager),
|
|
|
|
|
|
|
|
iterate: function (aCallback) {
|
|
|
|
let dlmgr = downloads.dlmgr;
|
|
|
|
let dbConn = dlmgr.DBConnection;
|
|
|
|
let stmt = dbConn.createStatement("SELECT id FROM moz_downloads WHERE " +
|
|
|
|
"state = ? OR state = ? OR state = ? OR state = ? OR state = ? OR state = ?");
|
2014-06-27 18:59:09 +04:00
|
|
|
stmt.bindByIndex(0, Ci.nsIDownloadManager.DOWNLOAD_FINISHED);
|
|
|
|
stmt.bindByIndex(1, Ci.nsIDownloadManager.DOWNLOAD_FAILED);
|
|
|
|
stmt.bindByIndex(2, Ci.nsIDownloadManager.DOWNLOAD_CANCELED);
|
|
|
|
stmt.bindByIndex(3, Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL);
|
|
|
|
stmt.bindByIndex(4, Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY);
|
|
|
|
stmt.bindByIndex(5, Ci.nsIDownloadManager.DOWNLOAD_DIRTY);
|
2013-02-06 04:08:03 +04:00
|
|
|
while (stmt.executeStep()) {
|
|
|
|
aCallback(dlmgr.getDownload(stmt.row.id));
|
|
|
|
}
|
|
|
|
stmt.finalize();
|
|
|
|
},
|
|
|
|
|
|
|
|
get canClear() {
|
|
|
|
return this.dlmgr.canCleanUp;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
function Sanitizer() {}
|
|
|
|
Sanitizer.prototype = {
|
|
|
|
clearItem: function (aItemName)
|
|
|
|
{
|
2013-06-05 02:59:50 +04:00
|
|
|
let item = this.items[aItemName];
|
|
|
|
let canClear = item.canClear;
|
|
|
|
if (typeof canClear == "function") {
|
|
|
|
canClear(function clearCallback(aCanClear) {
|
|
|
|
if (aCanClear)
|
|
|
|
item.clear();
|
|
|
|
});
|
|
|
|
} else if (canClear) {
|
|
|
|
item.clear();
|
|
|
|
}
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
items: {
|
|
|
|
cache: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
|
|
|
|
try {
|
|
|
|
cache.clear();
|
|
|
|
} catch(er) {}
|
|
|
|
|
|
|
|
let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
|
|
|
|
.getImgCacheForDocument(null);
|
|
|
|
try {
|
|
|
|
imageCache.clearCache(false); // true=chrome, false=content
|
|
|
|
} catch(er) {}
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
cookies: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
Services.cookies.removeAll();
|
|
|
|
resolve();
|
|
|
|
});
|
2009-05-30 05:28:12 +04:00
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2009-05-30 05:28:12 +04:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
siteSettings: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
// Clear site-specific permissions like "Allow this site to open popups"
|
|
|
|
Services.perms.removeAll();
|
|
|
|
|
|
|
|
// Clear site-specific settings like page-zoom level
|
|
|
|
Cc["@mozilla.org/content-pref/service;1"]
|
|
|
|
.getService(Ci.nsIContentPrefService2)
|
|
|
|
.removeAllDomains(null);
|
|
|
|
|
|
|
|
// Clear "Never remember passwords for this site", which is not handled by
|
|
|
|
// the permission manager
|
|
|
|
var hosts = Services.logins.getAllDisabledHosts({})
|
|
|
|
for (var host of hosts) {
|
|
|
|
Services.logins.setLoginSavingEnabled(host, true);
|
|
|
|
}
|
2009-05-30 05:28:12 +04:00
|
|
|
|
2014-09-04 21:42:31 +04:00
|
|
|
// Clear site security settings
|
|
|
|
var sss = Cc["@mozilla.org/ssservice;1"]
|
|
|
|
.getService(Ci.nsISiteSecurityService);
|
|
|
|
sss.clearAll();
|
|
|
|
|
2014-06-19 11:04:00 +04:00
|
|
|
resolve();
|
|
|
|
});
|
2009-05-30 05:28:12 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
offlineApps: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
var cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
|
|
|
|
var appCacheStorage = cacheService.appCacheStorage(LoadContextInfo.default, null);
|
|
|
|
try {
|
|
|
|
appCacheStorage.asyncEvictStorage(null);
|
|
|
|
} catch(er) {}
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
history: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-09-03 02:53:30 +04:00
|
|
|
return Messaging.sendRequestForResult({ type: "Sanitize:ClearHistory" })
|
2014-09-04 21:31:13 +04:00
|
|
|
.catch(e => Cu.reportError("Java-side history clearing failed: " + e))
|
2014-09-03 02:53:30 +04:00
|
|
|
.then(function() {
|
2014-06-19 11:04:00 +04:00
|
|
|
try {
|
|
|
|
Services.obs.notifyObservers(null, "browser:purge-session-history", "");
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
try {
|
|
|
|
var predictor = Cc["@mozilla.org/network/predictor;1"].getService(Ci.nsINetworkPredictor);
|
|
|
|
predictor.reset();
|
|
|
|
} catch (e) { }
|
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04: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 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
formdata: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
FormHistory.update({ op: "remove" });
|
|
|
|
resolve();
|
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2013-06-05 02:59:50 +04:00
|
|
|
canClear: function (aCallback)
|
2008-09-07 10:54:06 +04:00
|
|
|
{
|
2013-06-05 02:59:50 +04:00
|
|
|
let count = 0;
|
|
|
|
let countDone = {
|
|
|
|
handleResult: function(aResult) { count = aResult; },
|
|
|
|
handleError: function(aError) { Cu.reportError(aError); },
|
|
|
|
handleCompletion: function(aReason) { aCallback(aReason == 0 && count > 0); }
|
|
|
|
};
|
|
|
|
FormHistory.count({}, countDone);
|
2008-09-07 10:54:06 +04:00
|
|
|
}
|
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2013-02-06 04:08:03 +04:00
|
|
|
downloadFiles: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
downloads.iterate(function (dl) {
|
|
|
|
// Delete the downloaded files themselves
|
|
|
|
let f = dl.targetFile;
|
|
|
|
if (f.exists()) {
|
|
|
|
f.remove(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also delete downloads from history
|
|
|
|
dl.remove();
|
|
|
|
});
|
|
|
|
resolve();
|
2013-02-06 04:08:03 +04:00
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
get canClear()
|
|
|
|
{
|
2013-02-06 04:08:03 +04:00
|
|
|
return downloads.canClear;
|
2008-09-07 10:54:06 +04:00
|
|
|
}
|
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
passwords: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
Services.logins.removeAllLogins();
|
|
|
|
resolve();
|
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
get canClear()
|
|
|
|
{
|
2012-03-20 03:51:29 +04:00
|
|
|
let count = Services.logins.countLogins("", "", ""); // count all logins
|
2008-09-07 10:54:06 +04:00
|
|
|
return (count > 0);
|
|
|
|
}
|
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
sessions: {
|
|
|
|
clear: function ()
|
|
|
|
{
|
2014-06-19 11:04:00 +04:00
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
// clear all auth tokens
|
|
|
|
var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
|
|
|
|
sdr.logoutAndTeardown();
|
|
|
|
|
|
|
|
// clear FTP and plain HTTP auth sessions
|
|
|
|
Services.obs.notifyObservers(null, "net:clear-active-logins", null);
|
2008-09-07 10:54:06 +04:00
|
|
|
|
2014-06-19 11:04:00 +04:00
|
|
|
resolve();
|
|
|
|
});
|
2008-09-07 10:54:06 +04:00
|
|
|
},
|
2012-04-20 23:49:47 +04:00
|
|
|
|
2008-09-07 10:54:06 +04:00
|
|
|
get canClear()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-06 04:08:02 +04:00
|
|
|
this.Sanitizer = new Sanitizer();
|