summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/PrivateBrowsingUtils.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/modules/PrivateBrowsingUtils.sys.mjs
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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 'toolkit/modules/PrivateBrowsingUtils.sys.mjs')
-rw-r--r--toolkit/modules/PrivateBrowsingUtils.sys.mjs71
1 files changed, 71 insertions, 0 deletions
diff --git a/toolkit/modules/PrivateBrowsingUtils.sys.mjs b/toolkit/modules/PrivateBrowsingUtils.sys.mjs
new file mode 100644
index 0000000000..487a43bfbf
--- /dev/null
+++ b/toolkit/modules/PrivateBrowsingUtils.sys.mjs
@@ -0,0 +1,71 @@
+/* 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 kAutoStartPref = "browser.privatebrowsing.autostart";
+
+// This will be set to true when the PB mode is autostarted from the command
+// line for the current session.
+var gTemporaryAutoStartMode = false;
+
+export var PrivateBrowsingUtils = {
+ get enabled() {
+ return Services.policies.isAllowed("privatebrowsing");
+ },
+
+ // Rather than passing content windows to this function, please use
+ // isBrowserPrivate since it works with e10s.
+ isWindowPrivate: function pbu_isWindowPrivate(aWindow) {
+ if (!aWindow.isChromeWindow) {
+ dump(
+ "WARNING: content window passed to PrivateBrowsingUtils.isWindowPrivate. " +
+ "Use isContentWindowPrivate instead (but only for frame scripts).\n" +
+ new Error().stack
+ );
+ }
+
+ return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
+ },
+
+ // This should be used only in frame scripts.
+ isContentWindowPrivate: function pbu_isWindowPrivate(aWindow) {
+ return this.privacyContextFromWindow(aWindow).usePrivateBrowsing;
+ },
+
+ isBrowserPrivate(aBrowser) {
+ let chromeWin = aBrowser.ownerGlobal;
+ if (chromeWin.gMultiProcessBrowser || !aBrowser.contentWindow) {
+ // In e10s we have to look at the chrome window's private
+ // browsing status since the only alternative is to check the
+ // content window, which is in another process. If the browser
+ // is lazy or is running in windowless configuration then the
+ // content window doesn't exist.
+ return this.isWindowPrivate(chromeWin);
+ }
+ return this.privacyContextFromWindow(aBrowser.contentWindow)
+ .usePrivateBrowsing;
+ },
+
+ privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
+ return aWindow.docShell.QueryInterface(Ci.nsILoadContext);
+ },
+
+ get permanentPrivateBrowsing() {
+ try {
+ return (
+ gTemporaryAutoStartMode || Services.prefs.getBoolPref(kAutoStartPref)
+ );
+ } catch (e) {
+ // The pref does not exist
+ return false;
+ }
+ },
+
+ // These should only be used from internal code
+ enterTemporaryAutoStartMode: function pbu_enterTemporaryAutoStartMode() {
+ gTemporaryAutoStartMode = true;
+ },
+ get isInTemporaryAutoStartMode() {
+ return gTemporaryAutoStartMode;
+ },
+};