Bug 1823341 - Make toolkit/components/antitracking buildable outside of a unified build environment r=andi

Depends on D172968

Differential Revision: https://phabricator.services.mozilla.com/D172969
This commit is contained in:
serge-sans-paille 2023-03-21 10:47:28 +00:00
parent eb997b688d
commit ca06ea9162
20 changed files with 70 additions and 15 deletions

View file

@ -12,6 +12,7 @@
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIURI.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsString.h" #include "nsString.h"
@ -20,6 +21,7 @@
#include "mozilla/Atomics.h" #include "mozilla/Atomics.h"
#include "mozilla/Monitor.h" #include "mozilla/Monitor.h"
#include "mozilla/MozPromise.h" #include "mozilla/MozPromise.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/StaticMutex.h" #include "mozilla/StaticMutex.h"
#include "mozilla/ThreadBound.h" #include "mozilla/ThreadBound.h"
#include "mozilla/Variant.h" #include "mozilla/Variant.h"

View file

@ -22,6 +22,7 @@
#include "nsEffectiveTLDService.h" #include "nsEffectiveTLDService.h"
#include "nsGlobalWindowInner.h" #include "nsGlobalWindowInner.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsICookieService.h"
#include "nsIHttpChannel.h" #include "nsIHttpChannel.h"
#include "nsIPermission.h" #include "nsIPermission.h"
#include "nsIURI.h" #include "nsIURI.h"

View file

@ -9,11 +9,15 @@
#include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/PermissionManager.h" #include "mozilla/PermissionManager.h"
#include "mozilla/ScopeExit.h" #include "mozilla/ScopeExit.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsGlobalWindowInner.h"
#include "nsICookieJarSettings.h"
#include "nsIHttpChannel.h" #include "nsIHttpChannel.h"
#include "nsIHttpChannelInternal.h" #include "nsIHttpChannelInternal.h"
#include "nsNetUtil.h"
using namespace mozilla; using namespace mozilla;

View file

@ -9,6 +9,8 @@
#include "nsIEffectiveTLDService.h" #include "nsIEffectiveTLDService.h"
#include "nsITrackingDBService.h" #include "nsITrackingDBService.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "mozilla/BasePrincipal.h" #include "mozilla/BasePrincipal.h"

View file

@ -12,6 +12,7 @@
#include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/dom/WindowGlobalParent.h"
#include "nsIClassifiedChannel.h" #include "nsIClassifiedChannel.h"
@ -24,6 +25,7 @@
#include "mozIThirdPartyUtil.h" #include "mozIThirdPartyUtil.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom;
using mozilla::dom::BrowsingContext; using mozilla::dom::BrowsingContext;
using mozilla::dom::ContentChild; using mozilla::dom::ContentChild;
using mozilla::dom::Document; using mozilla::dom::Document;

View file

@ -13,8 +13,10 @@
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "AntiTrackingLog.h" #include "AntiTrackingLog.h"
#include "prtime.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIPermission.h"
#include "nsTArray.h" #include "nsTArray.h"
using namespace mozilla; using namespace mozilla;

View file

@ -11,9 +11,11 @@
#include "StorageAccessAPIHelper.h" #include "StorageAccessAPIHelper.h"
#include "mozilla/net/HttpBaseChannel.h" #include "mozilla/net/HttpBaseChannel.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsICookieJarSettings.h"
#include "nsICookieService.h" #include "nsICookieService.h"
#include "nsIEffectiveTLDService.h" #include "nsIEffectiveTLDService.h"
#include "nsINavHistoryService.h" #include "nsINavHistoryService.h"

View file

@ -8,6 +8,7 @@
#include "AntiTrackingLog.h" #include "AntiTrackingLog.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsServiceManagerUtils.h"
#include "mozilla/ClearOnShutdown.h" #include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"

View file

@ -7,8 +7,10 @@
#ifndef mozilla_PartitioningExceptionList_h #ifndef mozilla_PartitioningExceptionList_h
#define mozilla_PartitioningExceptionList_h #define mozilla_PartitioningExceptionList_h
#include "nsCOMPtr.h"
#include "nsIPartitioningExceptionListService.h" #include "nsIPartitioningExceptionListService.h"
#include "nsTArrayForwardDeclare.h" #include "nsTArray.h"
#include "nsString.h"
class nsIChannel; class nsIChannel;
class nsIPrincipal; class nsIPrincipal;

View file

@ -6,9 +6,13 @@
#include "RejectForeignAllowList.h" #include "RejectForeignAllowList.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/ClearOnShutdown.h" #include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h" #include "mozilla/StaticPtr.h"
#include "nsIHttpChannel.h"
#include "nsIURI.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsScriptSecurityManager.h"
#define REJECTFOREIGNALLOWLIST_PREF "privacy.rejectForeign.allowList"_ns #define REJECTFOREIGNALLOWLIST_PREF "privacy.rejectForeign.allowList"_ns
#define REJECTFOREIGNALLOWLIST_NAME "RejectForeignAllowList"_ns #define REJECTFOREIGNALLOWLIST_NAME "RejectForeignAllowList"_ns

View file

@ -8,6 +8,7 @@
#define mozilla_RejectForeignAllowList_h #define mozilla_RejectForeignAllowList_h
#include "nsIUrlClassifierExceptionListService.h" #include "nsIUrlClassifierExceptionListService.h"
#include "nsIPrincipal.h"
class nsIHttpChannel; class nsIHttpChannel;
class nsIURI; class nsIURI;

View file

@ -9,6 +9,8 @@
#include "nsIObserver.h" #include "nsIObserver.h"
#include <functional>
namespace mozilla { namespace mozilla {
class SettingsChangeObserver final : public nsIObserver { class SettingsChangeObserver final : public nsIObserver {

View file

@ -6,19 +6,32 @@
#include "StorageAccess.h" #include "StorageAccess.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/Components.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/net/CookieJarSettings.h" #include "mozilla/net/CookieJarSettings.h"
#include "mozilla/PermissionManager.h"
#include "mozilla/StaticPrefs_browser.h" #include "mozilla/StaticPrefs_browser.h"
#include "mozilla/StaticPrefs_network.h" #include "mozilla/StaticPrefs_network.h"
#include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h" #include "mozilla/StorageAccess.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsGlobalWindowInner.h"
#include "nsICookiePermission.h" #include "nsICookiePermission.h"
#include "nsICookieService.h" #include "nsICookieService.h"
#include "nsICookieJarSettings.h" #include "nsICookieJarSettings.h"
#include "nsIHttpChannel.h"
#include "nsIPermission.h" #include "nsIPermission.h"
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
#include "nsIClassifiedChannel.h"
#include "nsNetUtil.h"
#include "nsScriptSecurityManager.h"
#include "nsSandboxFlags.h" #include "nsSandboxFlags.h"
#include "AntiTrackingUtils.h"
#include "AntiTrackingLog.h"
#include "ContentBlockingAllowList.h"
#include "mozIThirdPartyUtil.h"
#include "RejectForeignAllowList.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
@ -26,7 +39,7 @@ using mozilla::net::CookieJarSettings;
// This internal method returns ACCESS_DENY if the access is denied, // This internal method returns ACCESS_DENY if the access is denied,
// ACCESS_DEFAULT if unknown, some other access code if granted. // ACCESS_DEFAULT if unknown, some other access code if granted.
uint32_t CheckCookiePermissionForPrincipal( uint32_t mozilla::detail::CheckCookiePermissionForPrincipal(
nsICookieJarSettings* aCookieJarSettings, nsIPrincipal* aPrincipal) { nsICookieJarSettings* aCookieJarSettings, nsIPrincipal* aPrincipal) {
MOZ_ASSERT(aCookieJarSettings); MOZ_ASSERT(aCookieJarSettings);
MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aPrincipal);
@ -46,6 +59,7 @@ uint32_t CheckCookiePermissionForPrincipal(
return cookiePermission; return cookiePermission;
} }
/* /*
* Checks if storage for a given principal is permitted by the user's * Checks if storage for a given principal is permitted by the user's
* preferences. If aWindow is non-null, its principal must be passed as * preferences. If aWindow is non-null, its principal must be passed as
@ -470,7 +484,7 @@ bool ShouldAllowAccessFor(nsPIDOMWindowInner* aWindow, nsIURI* aURI,
return false; return false;
} }
uint32_t cookiePermission = CheckCookiePermissionForPrincipal( uint32_t cookiePermission = detail::CheckCookiePermissionForPrincipal(
document->CookieJarSettings(), document->NodePrincipal()); document->CookieJarSettings(), document->NodePrincipal());
if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) { if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) {
LOG( LOG(
@ -651,7 +665,7 @@ bool ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI,
} }
uint32_t cookiePermission = uint32_t cookiePermission =
CheckCookiePermissionForPrincipal(cookieJarSettings, channelPrincipal); detail::CheckCookiePermissionForPrincipal(cookieJarSettings, channelPrincipal);
if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) { if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) {
LOG( LOG(
("CheckCookiePermissionForPrincipal() returned a non-default access " ("CheckCookiePermissionForPrincipal() returned a non-default access "
@ -869,7 +883,7 @@ bool ApproximateAllowAccessForWithoutChannel(
return true; return true;
} }
uint32_t cookiePermission = CheckCookiePermissionForPrincipal( uint32_t cookiePermission = detail::CheckCookiePermissionForPrincipal(
parentDocument->CookieJarSettings(), parentDocument->NodePrincipal()); parentDocument->CookieJarSettings(), parentDocument->NodePrincipal());
if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) { if (cookiePermission != nsICookiePermission::ACCESS_DEFAULT) {
LOG( LOG(

View file

@ -158,6 +158,11 @@ bool ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI,
bool ShouldAllowAccessFor(nsIPrincipal* aPrincipal, bool ShouldAllowAccessFor(nsIPrincipal* aPrincipal,
nsICookieJarSettings* aCookieJarSettings); nsICookieJarSettings* aCookieJarSettings);
namespace detail {
uint32_t CheckCookiePermissionForPrincipal(
nsICookieJarSettings* aCookieJarSettings, nsIPrincipal* aPrincipal);
}
} // namespace mozilla } // namespace mozilla
#endif // mozilla_StorageAccess_h #endif // mozilla_StorageAccess_h

View file

@ -16,10 +16,12 @@
#include "mozilla/dom/BrowsingContextGroup.h" #include "mozilla/dom/BrowsingContextGroup.h"
#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/WindowContext.h" #include "mozilla/dom/WindowContext.h"
#include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/net/CookieJarSettings.h" #include "mozilla/net/CookieJarSettings.h"
#include "mozilla/PermissionManager.h" #include "mozilla/PermissionManager.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "mozIThirdPartyUtil.h" #include "mozIThirdPartyUtil.h"
@ -37,6 +39,7 @@
#include "nsIWebProgressListener.h" #include "nsIWebProgressListener.h"
#include "nsScriptSecurityManager.h" #include "nsScriptSecurityManager.h"
#include "RejectForeignAllowList.h" #include "RejectForeignAllowList.h"
#include "StorageAccess.h"
namespace mozilla { namespace mozilla {
@ -450,7 +453,7 @@ StorageAccessAPIHelper::CompleteAllowAccessFor(
// we'll return to the content process we need to inform when this // we'll return to the content process we need to inform when this
// function is done. So we don't need to create an extra IPC for the case. // function is done. So we don't need to create an extra IPC for the case.
if (aReason != ContentBlockingNotifier::eOpener) { if (aReason != ContentBlockingNotifier::eOpener) {
ContentParent* cp = aParentContext->Canonical()->GetContentParent(); dom::ContentParent* cp = aParentContext->Canonical()->GetContentParent();
Unused << cp->SendOnAllowAccessFor(aParentContext, trackingOrigin, Unused << cp->SendOnAllowAccessFor(aParentContext, trackingOrigin,
aCookieBehavior, aReason); aCookieBehavior, aReason);
} }
@ -741,7 +744,7 @@ StorageAccessAPIHelper::CheckCookiesPermittedDecidesStorageAccessAPI(
nsIPrincipal* aRequestingPrincipal) { nsIPrincipal* aRequestingPrincipal) {
MOZ_ASSERT(aCookieJarSettings); MOZ_ASSERT(aCookieJarSettings);
MOZ_ASSERT(aRequestingPrincipal); MOZ_ASSERT(aRequestingPrincipal);
uint32_t cookiePermission = CheckCookiePermissionForPrincipal( uint32_t cookiePermission = detail::CheckCookiePermissionForPrincipal(
aCookieJarSettings, aRequestingPrincipal); aCookieJarSettings, aRequestingPrincipal);
if (cookiePermission == nsICookiePermission::ACCESS_ALLOW || if (cookiePermission == nsICookiePermission::ACCESS_ALLOW ||
cookiePermission == nsICookiePermission::ACCESS_SESSION) { cookiePermission == nsICookiePermission::ACCESS_SESSION) {

View file

@ -7,13 +7,19 @@
#include "StoragePrincipalHelper.h" #include "StoragePrincipalHelper.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h" #include "mozilla/ipc/PBackgroundSharedTypes.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/net/CookieJarSettings.h"
#include "mozilla/ScopeExit.h" #include "mozilla/ScopeExit.h"
#include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPrefs_privacy.h"
#include "mozilla/StorageAccess.h" #include "mozilla/StorageAccess.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsICookieJarSettings.h"
#include "nsICookieService.h"
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsIEffectiveTLDService.h" #include "nsIEffectiveTLDService.h"
#include "nsIPrivateBrowsingChannel.h"
#include "AntiTrackingUtils.h"
namespace mozilla { namespace mozilla {
@ -324,7 +330,7 @@ nsresult StoragePrincipalHelper::GetPrincipal(nsPIDOMWindowInner* aWindow,
MOZ_ASSERT(aWindow); MOZ_ASSERT(aWindow);
MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aPrincipal);
nsCOMPtr<Document> doc = aWindow->GetExtantDoc(); nsCOMPtr<dom::Document> doc = aWindow->GetExtantDoc();
NS_ENSURE_STATE(doc); NS_ENSURE_STATE(doc);
nsCOMPtr<nsIPrincipal> outPrincipal; nsCOMPtr<nsIPrincipal> outPrincipal;
@ -369,7 +375,7 @@ bool StoragePrincipalHelper::ShouldUsePartitionPrincipalForServiceWorker(
return false; return false;
} }
RefPtr<Document> document = aDocShell->GetExtantDocument(); RefPtr<dom::Document> document = aDocShell->GetExtantDocument();
// If we cannot get the document from the docShell, we turn to get its // If we cannot get the document from the docShell, we turn to get its
// parent's document. // parent's document.
@ -390,8 +396,8 @@ bool StoragePrincipalHelper::ShouldUsePartitionPrincipalForServiceWorker(
// If there was no document, we create one cookieJarSettings here in order // If there was no document, we create one cookieJarSettings here in order
// to get the cookieBehavior. We don't need a real value for RFP because // to get the cookieBehavior. We don't need a real value for RFP because
// we are only using this object to check default cookie behavior. // we are only using this object to check default cookie behavior.
cookieJarSettings = CookieJarSettings::Create( cookieJarSettings = net::CookieJarSettings::Create(
CookieJarSettings::eRegular, /* shouldResistFingerpreinting */ false); net::CookieJarSettings::eRegular, /* shouldResistFingerpreinting */ false);
} }
// We only support partitioned service workers when dFPI is enabled. // We only support partitioned service workers when dFPI is enabled.
@ -483,7 +489,7 @@ bool StoragePrincipalHelper::GetOriginAttributes(
// static // static
bool StoragePrincipalHelper::GetRegularPrincipalOriginAttributes( bool StoragePrincipalHelper::GetRegularPrincipalOriginAttributes(
Document* aDocument, OriginAttributes& aAttributes) { dom::Document* aDocument, OriginAttributes& aAttributes) {
aAttributes = mozilla::OriginAttributes(); aAttributes = mozilla::OriginAttributes();
if (!aDocument) { if (!aDocument) {
return false; return false;
@ -536,7 +542,7 @@ bool StoragePrincipalHelper::GetOriginAttributesForNetworkState(
// static // static
void StoragePrincipalHelper::GetOriginAttributesForNetworkState( void StoragePrincipalHelper::GetOriginAttributesForNetworkState(
Document* aDocument, OriginAttributes& aAttributes) { dom::Document* aDocument, OriginAttributes& aAttributes) {
aAttributes = aDocument->NodePrincipal()->OriginAttributesRef(); aAttributes = aDocument->NodePrincipal()->OriginAttributesRef();
if (!StaticPrefs::privacy_partition_network_state()) { if (!StaticPrefs::privacy_partition_network_state()) {

View file

@ -9,6 +9,7 @@
#include <cstdint> #include <cstdint>
#include "ErrorList.h" #include "ErrorList.h"
#include "nsStringFwd.h"
/** /**
* StoragePrincipal * StoragePrincipal

View file

@ -7,6 +7,7 @@
#include "TemporaryAccessGrantObserver.h" #include "TemporaryAccessGrantObserver.h"
#include "mozilla/PermissionManager.h" #include "mozilla/PermissionManager.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"

View file

@ -11,6 +11,8 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsHashKeys.h" #include "nsHashKeys.h"
#include "nsHashtablesFwd.h" #include "nsHashtablesFwd.h"
#include "nsTHashMap.h"
#include "nsINamed.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsString.h" #include "nsString.h"
#include "PLDHashTable.h" #include "PLDHashTable.h"

View file

@ -94,6 +94,4 @@ XPCSHELL_TESTS_MANIFESTS += ["test/xpcshell/xpcshell.ini"]
TEST_DIRS += ["test/gtest"] TEST_DIRS += ["test/gtest"]
REQUIRES_UNIFIED_BUILD = True
SPHINX_TREES["anti-tracking"] = "docs" SPHINX_TREES["anti-tracking"] = "docs"