diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/components/extensions/ExtensionBrowsingData.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/extensions/ExtensionBrowsingData.sys.mjs')
-rw-r--r-- | browser/components/extensions/ExtensionBrowsingData.sys.mjs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/browser/components/extensions/ExtensionBrowsingData.sys.mjs b/browser/components/extensions/ExtensionBrowsingData.sys.mjs new file mode 100644 index 0000000000..ce90eab35d --- /dev/null +++ b/browser/components/extensions/ExtensionBrowsingData.sys.mjs @@ -0,0 +1,77 @@ +/* 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/. */ + +import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs"; + +const lazy = {}; + +XPCOMUtils.defineLazyGetter(lazy, "makeRange", () => { + const { ExtensionParent } = ChromeUtils.importESModule( + "resource://gre/modules/ExtensionParent.sys.mjs" + ); + // Defined in ext-browsingData.js + return ExtensionParent.apiManager.global.makeRange; +}); + +ChromeUtils.defineESModuleGetters(lazy, { + Preferences: "resource://gre/modules/Preferences.sys.mjs", + Sanitizer: "resource:///modules/Sanitizer.sys.mjs", +}); + +export class BrowsingDataDelegate { + // Unused for now + constructor(extension) {} + + // This method returns undefined for all data types that are _not_ handled by + // this delegate. + handleRemoval(dataType, options) { + // TODO (Bug 1803799): Use Sanitizer.sanitize() instead of internal cleaners. + let o = { progress: {} }; + switch (dataType) { + case "downloads": + return lazy.Sanitizer.items.downloads.clear(lazy.makeRange(options), o); + case "formData": + return lazy.Sanitizer.items.formdata.clear(lazy.makeRange(options), o); + case "history": + return lazy.Sanitizer.items.history.clear(lazy.makeRange(options), o); + + default: + return undefined; + } + } + + settings() { + const PREF_DOMAIN = "privacy.cpd."; + // The following prefs are the only ones in Firefox that match corresponding + // values used by Chrome when rerturning settings. + const PREF_LIST = ["cache", "cookies", "history", "formdata", "downloads"]; + + // since will be the start of what is returned by Sanitizer.getClearRange + // divided by 1000 to convert to ms. + // If Sanitizer.getClearRange returns undefined that means the range is + // currently "Everything", so we should set since to 0. + let clearRange = lazy.Sanitizer.getClearRange(); + let since = clearRange ? clearRange[0] / 1000 : 0; + let options = { since }; + + let dataToRemove = {}; + let dataRemovalPermitted = {}; + + for (let item of PREF_LIST) { + // The property formData needs a different case than the + // formdata preference. + const name = item === "formdata" ? "formData" : item; + dataToRemove[name] = lazy.Preferences.get(`${PREF_DOMAIN}${item}`); + // Firefox doesn't have the same concept of dataRemovalPermitted + // as Chrome, so it will always be true. + dataRemovalPermitted[name] = true; + } + + return Promise.resolve({ + options, + dataToRemove, + dataRemovalPermitted, + }); + } +} |