From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- toolkit/modules/sessionstore/PrivacyLevel.sys.mjs | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 toolkit/modules/sessionstore/PrivacyLevel.sys.mjs (limited to 'toolkit/modules/sessionstore/PrivacyLevel.sys.mjs') diff --git a/toolkit/modules/sessionstore/PrivacyLevel.sys.mjs b/toolkit/modules/sessionstore/PrivacyLevel.sys.mjs new file mode 100644 index 0000000000..c3267fa5cf --- /dev/null +++ b/toolkit/modules/sessionstore/PrivacyLevel.sys.mjs @@ -0,0 +1,63 @@ +/* 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"; + +// 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; + +export var PrivacyLevel = { + /** + * 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) { + // Never save any data when full privacy is requested. + if (this.privacyLevel == PRIVACY_FULL) { + return false; + } + + // Don't save data for encrypted sites when requested. + if (isHttps && this.privacyLevel == PRIVACY_ENCRYPTED) { + return false; + } + + return true; + }, + + canSaveAnything() { + return this.privacyLevel != PRIVACY_FULL; + }, + + shouldSaveEverything() { + return this.privacyLevel == PRIVACY_NONE; + }, +}; + +XPCOMUtils.defineLazyPreferenceGetter( + PrivacyLevel, + "privacyLevel", + "browser.sessionstore.privacy_level" +); -- cgit v1.2.3