mobile/android/modules/Sanitizer.jsm

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 // -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 let Cc = Components.classes;
michael@0 7 let Ci = Components.interfaces;
michael@0 8 let Cu = Components.utils;
michael@0 9
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 12 Cu.import("resource://gre/modules/LoadContextInfo.jsm");
michael@0 13 Cu.import("resource://gre/modules/FormHistory.jsm");
michael@0 14 Cu.import("resource://gre/modules/Messaging.jsm");
michael@0 15
michael@0 16 function dump(a) {
michael@0 17 Services.console.logStringMessage(a);
michael@0 18 }
michael@0 19
michael@0 20 this.EXPORTED_SYMBOLS = ["Sanitizer"];
michael@0 21
michael@0 22 let downloads = {
michael@0 23 dlmgr: Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager),
michael@0 24
michael@0 25 iterate: function (aCallback) {
michael@0 26 let dlmgr = downloads.dlmgr;
michael@0 27 let dbConn = dlmgr.DBConnection;
michael@0 28 let stmt = dbConn.createStatement("SELECT id FROM moz_downloads WHERE " +
michael@0 29 "state = ? OR state = ? OR state = ? OR state = ? OR state = ? OR state = ?");
michael@0 30 stmt.bindInt32Parameter(0, Ci.nsIDownloadManager.DOWNLOAD_FINISHED);
michael@0 31 stmt.bindInt32Parameter(1, Ci.nsIDownloadManager.DOWNLOAD_FAILED);
michael@0 32 stmt.bindInt32Parameter(2, Ci.nsIDownloadManager.DOWNLOAD_CANCELED);
michael@0 33 stmt.bindInt32Parameter(3, Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_PARENTAL);
michael@0 34 stmt.bindInt32Parameter(4, Ci.nsIDownloadManager.DOWNLOAD_BLOCKED_POLICY);
michael@0 35 stmt.bindInt32Parameter(5, Ci.nsIDownloadManager.DOWNLOAD_DIRTY);
michael@0 36 while (stmt.executeStep()) {
michael@0 37 aCallback(dlmgr.getDownload(stmt.row.id));
michael@0 38 }
michael@0 39 stmt.finalize();
michael@0 40 },
michael@0 41
michael@0 42 get canClear() {
michael@0 43 return this.dlmgr.canCleanUp;
michael@0 44 }
michael@0 45 };
michael@0 46
michael@0 47 function Sanitizer() {}
michael@0 48 Sanitizer.prototype = {
michael@0 49 clearItem: function (aItemName)
michael@0 50 {
michael@0 51 let item = this.items[aItemName];
michael@0 52 let canClear = item.canClear;
michael@0 53 if (typeof canClear == "function") {
michael@0 54 canClear(function clearCallback(aCanClear) {
michael@0 55 if (aCanClear)
michael@0 56 item.clear();
michael@0 57 });
michael@0 58 } else if (canClear) {
michael@0 59 item.clear();
michael@0 60 }
michael@0 61 },
michael@0 62
michael@0 63 items: {
michael@0 64 cache: {
michael@0 65 clear: function ()
michael@0 66 {
michael@0 67 var cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
michael@0 68 try {
michael@0 69 cache.clear();
michael@0 70 } catch(er) {}
michael@0 71
michael@0 72 let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
michael@0 73 .getImgCacheForDocument(null);
michael@0 74 try {
michael@0 75 imageCache.clearCache(false); // true=chrome, false=content
michael@0 76 } catch(er) {}
michael@0 77 },
michael@0 78
michael@0 79 get canClear()
michael@0 80 {
michael@0 81 return true;
michael@0 82 }
michael@0 83 },
michael@0 84
michael@0 85 cookies: {
michael@0 86 clear: function ()
michael@0 87 {
michael@0 88 Services.cookies.removeAll();
michael@0 89 },
michael@0 90
michael@0 91 get canClear()
michael@0 92 {
michael@0 93 return true;
michael@0 94 }
michael@0 95 },
michael@0 96
michael@0 97 siteSettings: {
michael@0 98 clear: function ()
michael@0 99 {
michael@0 100 // Clear site-specific permissions like "Allow this site to open popups"
michael@0 101 Services.perms.removeAll();
michael@0 102
michael@0 103 // Clear site-specific settings like page-zoom level
michael@0 104 Cc["@mozilla.org/content-pref/service;1"]
michael@0 105 .getService(Ci.nsIContentPrefService2)
michael@0 106 .removeAllDomains(null);
michael@0 107
michael@0 108 // Clear "Never remember passwords for this site", which is not handled by
michael@0 109 // the permission manager
michael@0 110 var hosts = Services.logins.getAllDisabledHosts({})
michael@0 111 for (var host of hosts) {
michael@0 112 Services.logins.setLoginSavingEnabled(host, true);
michael@0 113 }
michael@0 114 },
michael@0 115
michael@0 116 get canClear()
michael@0 117 {
michael@0 118 return true;
michael@0 119 }
michael@0 120 },
michael@0 121
michael@0 122 offlineApps: {
michael@0 123 clear: function ()
michael@0 124 {
michael@0 125 var cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
michael@0 126 var appCacheStorage = cacheService.appCacheStorage(LoadContextInfo.default, null);
michael@0 127 try {
michael@0 128 appCacheStorage.asyncEvictStorage(null);
michael@0 129 } catch(er) {}
michael@0 130 },
michael@0 131
michael@0 132 get canClear()
michael@0 133 {
michael@0 134 return true;
michael@0 135 }
michael@0 136 },
michael@0 137
michael@0 138 history: {
michael@0 139 clear: function ()
michael@0 140 {
michael@0 141 sendMessageToJava({ type: "Sanitize:ClearHistory" });
michael@0 142
michael@0 143 try {
michael@0 144 Services.obs.notifyObservers(null, "browser:purge-session-history", "");
michael@0 145 }
michael@0 146 catch (e) { }
michael@0 147
michael@0 148 try {
michael@0 149 var seer = Cc["@mozilla.org/network/seer;1"].getService(Ci.nsINetworkSeer);
michael@0 150 seer.reset();
michael@0 151 } catch (e) { }
michael@0 152 },
michael@0 153
michael@0 154 get canClear()
michael@0 155 {
michael@0 156 // bug 347231: Always allow clearing history due to dependencies on
michael@0 157 // the browser:purge-session-history notification. (like error console)
michael@0 158 return true;
michael@0 159 }
michael@0 160 },
michael@0 161
michael@0 162 formdata: {
michael@0 163 clear: function ()
michael@0 164 {
michael@0 165 FormHistory.update({ op: "remove" });
michael@0 166 },
michael@0 167
michael@0 168 canClear: function (aCallback)
michael@0 169 {
michael@0 170 let count = 0;
michael@0 171 let countDone = {
michael@0 172 handleResult: function(aResult) { count = aResult; },
michael@0 173 handleError: function(aError) { Cu.reportError(aError); },
michael@0 174 handleCompletion: function(aReason) { aCallback(aReason == 0 && count > 0); }
michael@0 175 };
michael@0 176 FormHistory.count({}, countDone);
michael@0 177 }
michael@0 178 },
michael@0 179
michael@0 180 downloadFiles: {
michael@0 181 clear: function ()
michael@0 182 {
michael@0 183 downloads.iterate(function (dl) {
michael@0 184 // Delete the downloaded files themselves
michael@0 185 let f = dl.targetFile;
michael@0 186 if (f.exists()) {
michael@0 187 f.remove(false);
michael@0 188 }
michael@0 189
michael@0 190 // Also delete downloads from history
michael@0 191 dl.remove();
michael@0 192 });
michael@0 193 },
michael@0 194
michael@0 195 get canClear()
michael@0 196 {
michael@0 197 return downloads.canClear;
michael@0 198 }
michael@0 199 },
michael@0 200
michael@0 201 passwords: {
michael@0 202 clear: function ()
michael@0 203 {
michael@0 204 Services.logins.removeAllLogins();
michael@0 205 },
michael@0 206
michael@0 207 get canClear()
michael@0 208 {
michael@0 209 let count = Services.logins.countLogins("", "", ""); // count all logins
michael@0 210 return (count > 0);
michael@0 211 }
michael@0 212 },
michael@0 213
michael@0 214 sessions: {
michael@0 215 clear: function ()
michael@0 216 {
michael@0 217 // clear all auth tokens
michael@0 218 var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
michael@0 219 sdr.logoutAndTeardown();
michael@0 220
michael@0 221 // clear FTP and plain HTTP auth sessions
michael@0 222 Services.obs.notifyObservers(null, "net:clear-active-logins", null);
michael@0 223 },
michael@0 224
michael@0 225 get canClear()
michael@0 226 {
michael@0 227 return true;
michael@0 228 }
michael@0 229 }
michael@0 230 }
michael@0 231 };
michael@0 232
michael@0 233 this.Sanitizer = new Sanitizer();

mercurial