summaryrefslogtreecommitdiffstats
path: root/application/basilisk/components/sessionstore/PrivacyLevel.jsm
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-06-04 13:17:38 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-06-04 13:17:38 +0200
commita1be17c1cea81ebb1e8b131a662c698d78f3f7f2 (patch)
treea92f7de513be600cc07bac458183e9af40e00c06 /application/basilisk/components/sessionstore/PrivacyLevel.jsm
parentbf11fdd304898ac675e39b01b280d39550e419d0 (diff)
downloadUXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar.gz
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar.lz
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.tar.xz
UXP-a1be17c1cea81ebb1e8b131a662c698d78f3f7f2.zip
Issue #303 Part 1: Move basilisk files from /browser to /application/basilisk
Diffstat (limited to 'application/basilisk/components/sessionstore/PrivacyLevel.jsm')
-rw-r--r--application/basilisk/components/sessionstore/PrivacyLevel.jsm64
1 files changed, 64 insertions, 0 deletions
diff --git a/application/basilisk/components/sessionstore/PrivacyLevel.jsm b/application/basilisk/components/sessionstore/PrivacyLevel.jsm
new file mode 100644
index 000000000..135f1f959
--- /dev/null
+++ b/application/basilisk/components/sessionstore/PrivacyLevel.jsm
@@ -0,0 +1,64 @@
+/* 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/. */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["PrivacyLevel"];
+
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+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.
+ */
+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: function (url) {
+ return PrivacyLevel.canSave({ isHttps: url.startsWith("https:") });
+ },
+
+ /**
+ * Checks whether we're allowed to save data for a specific site.
+ *
+ * @param {isHttps: boolean}
+ * An object that must have one property: 'isHttps'.
+ * 'isHttps' tells whether the site us secure communication (HTTPS).
+ * @return {bool} Whether we can save data for the specified site.
+ */
+ canSave: function ({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;
+ }
+});