ExtensionBrowsingData.sys.mjs (2631B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const lazy = {}; 6 7 ChromeUtils.defineLazyGetter(lazy, "makeRange", () => { 8 const { ExtensionParent } = ChromeUtils.importESModule( 9 "resource://gre/modules/ExtensionParent.sys.mjs" 10 ); 11 // Defined in ext-browsingData.js 12 return ExtensionParent.apiManager.global.makeRange; 13 }); 14 15 ChromeUtils.defineESModuleGetters(lazy, { 16 Sanitizer: "resource:///modules/Sanitizer.sys.mjs", 17 }); 18 19 export class BrowsingDataDelegate { 20 // Unused for now 21 constructor() {} 22 23 // This method returns undefined for all data types that are _not_ handled by 24 // this delegate. 25 handleRemoval(dataType, options) { 26 // TODO (Bug 1803799): Use Sanitizer.sanitize() instead of internal cleaners. 27 let o = { progress: {} }; 28 switch (dataType) { 29 case "downloads": 30 return lazy.Sanitizer.items.downloads.clear(lazy.makeRange(options), o); 31 case "formData": 32 return lazy.Sanitizer.items.formdata.clear(lazy.makeRange(options), o); 33 case "history": 34 return lazy.Sanitizer.items.history.clear(lazy.makeRange(options), o); 35 36 default: 37 return undefined; 38 } 39 } 40 41 settings() { 42 const PREF_DOMAIN = "privacy.cpd."; 43 // The following prefs are the only ones in Firefox that match corresponding 44 // values used by Chrome when rerturning settings. 45 const PREF_LIST = ["cache", "cookies", "history", "formdata", "downloads"]; 46 47 // since will be the start of what is returned by Sanitizer.getClearRange 48 // divided by 1000 to convert to ms. 49 // If Sanitizer.getClearRange returns undefined that means the range is 50 // currently "Everything", so we should set since to 0. 51 let clearRange = lazy.Sanitizer.getClearRange(); 52 let since = clearRange ? clearRange[0] / 1000 : 0; 53 let options = { since }; 54 55 let dataToRemove = {}; 56 let dataRemovalPermitted = {}; 57 58 for (let item of PREF_LIST) { 59 // The property formData needs a different case than the 60 // formdata preference. 61 const name = item === "formdata" ? "formData" : item; 62 // We assume the pref exists, and throw if it doesn't. 63 dataToRemove[name] = Services.prefs.getBoolPref(`${PREF_DOMAIN}${item}`); 64 // Firefox doesn't have the same concept of dataRemovalPermitted 65 // as Chrome, so it will always be true. 66 dataRemovalPermitted[name] = true; 67 } 68 69 return Promise.resolve({ 70 options, 71 dataToRemove, 72 dataRemovalPermitted, 73 }); 74 } 75 }