diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/modules/sessionstore/PrivacyLevel.sys.mjs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/modules/sessionstore/PrivacyLevel.sys.mjs')
-rw-r--r-- | toolkit/modules/sessionstore/PrivacyLevel.sys.mjs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/toolkit/modules/sessionstore/PrivacyLevel.sys.mjs b/toolkit/modules/sessionstore/PrivacyLevel.sys.mjs new file mode 100644 index 0000000000..916df7ec67 --- /dev/null +++ b/toolkit/modules/sessionstore/PrivacyLevel.sys.mjs @@ -0,0 +1,54 @@ +/* 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/. */ + +const PREF = "browser.sessionstore.privacy_level"; + +// The following constants represent the different possible privacy levels that +// can be set by the user and that we need to consider when collecting text +// data, and cookies. +// +// Collect data from all sites (http and https). +// const PRIVACY_NONE = 0; +// Collect data from unencrypted sites (http), only. +const PRIVACY_ENCRYPTED = 1; +// Collect no data. +const PRIVACY_FULL = 2; + +/** + * The external API as exposed by this module. + */ +export var PrivacyLevel = Object.freeze({ + /** + * Returns whether the current privacy level allows saving data for the given + * |url|. + * + * @param url The URL we want to save data for. + * @return bool + */ + check(url) { + return PrivacyLevel.canSave(url.startsWith("https:")); + }, + + /** + * Checks whether we're allowed to save data for a specific site. + * + * @param isHttps A boolean that tells whether the site uses TLS. + * @return {bool} Whether we can save data for the specified site. + */ + canSave(isHttps) { + let level = Services.prefs.getIntPref(PREF); + + // Never save any data when full privacy is requested. + if (level == PRIVACY_FULL) { + return false; + } + + // Don't save data for encrypted sites when requested. + if (isHttps && level == PRIVACY_ENCRYPTED) { + return false; + } + + return true; + }, +}); |