From 7812491622fc50022065992edd69b420060ace5b Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Wed, 26 Jul 2023 10:14:37 +0000 Subject: [PATCH] Bug 1842030 - Part 1: Adding CanonicalBrowsingContext::IsPrivateBrowsingActive(). r=nika The CanonicalBrowsingContext::IsPrivateBrowsingActive() function allows us to know if private browsing is active. We need it to prevent setting cookies if there is no active private browsing session. Differential Revision: https://phabricator.services.mozilla.com/D184010 --- docshell/base/CanonicalBrowsingContext.cpp | 5 +++++ docshell/base/CanonicalBrowsingContext.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp index 31c97e2680530..385d7f367c2e1 100644 --- a/docshell/base/CanonicalBrowsingContext.cpp +++ b/docshell/base/CanonicalBrowsingContext.cpp @@ -1433,6 +1433,11 @@ uint32_t CanonicalBrowsingContext::CountSiteOrigins( return uniqueSiteOrigins.Count(); } +/* static */ +bool CanonicalBrowsingContext::IsPrivateBrowsingActive() { + return gNumberOfPrivateContexts > 0; +} + void CanonicalBrowsingContext::UpdateMediaControlAction( const MediaControlAction& aAction) { if (IsDiscarded()) { diff --git a/docshell/base/CanonicalBrowsingContext.h b/docshell/base/CanonicalBrowsingContext.h index 244f95e36e8a5..3bf1db6cb2b62 100644 --- a/docshell/base/CanonicalBrowsingContext.h +++ b/docshell/base/CanonicalBrowsingContext.h @@ -203,6 +203,9 @@ class CanonicalBrowsingContext final : public BrowsingContext { GlobalObject& aGlobal, const Sequence>& aRoots); + // Return true if a private browsing session is active. + static bool IsPrivateBrowsingActive(); + // This function would propogate the action to its all child browsing contexts // in content processes. void UpdateMediaControlAction(const MediaControlAction& aAction);