From a48fac9e3bb285f16e2e7e87a6411f151ed1bb3c Mon Sep 17 00:00:00 2001 From: Noemi Erli Date: Mon, 9 Mar 2020 19:19:41 +0200 Subject: [PATCH] Backed out 8 changesets (bug 1620322) for causing bustages in ContentBlockingLog.cpp CLOSED TREE Backed out changeset 3dcf513e36cb (bug 1620322) Backed out changeset 46714855ce1d (bug 1620322) Backed out changeset 0eb2b5f7322f (bug 1620322) Backed out changeset 72d640fa0740 (bug 1620322) Backed out changeset 4533bb4e5177 (bug 1620322) Backed out changeset 659270edd419 (bug 1620322) Backed out changeset 6802c18b1914 (bug 1620322) Backed out changeset 60ff34db9f15 (bug 1620322) --HG-- rename : toolkit/components/antitracking/ContentBlockingLog.cpp => dom/base/ContentBlockingLog.cpp rename : toolkit/components/antitracking/ContentBlockingLog.h => dom/base/ContentBlockingLog.h rename : toolkit/components/antitracking/ContentBlocking.cpp => toolkit/components/antitracking/AntiTrackingCommon.cpp rename : toolkit/components/antitracking/ContentBlocking.h => toolkit/components/antitracking/AntiTrackingCommon.h --- build/win32/orderfile.txt | 5 + build/win64/orderfile.txt | 6 + .../base}/ContentBlockingLog.cpp | 5 +- .../base}/ContentBlockingLog.h | 22 +- dom/base/Document.cpp | 41 +- dom/base/Document.h | 2 +- dom/base/Navigator.cpp | 13 +- dom/base/ThirdPartyUtil.cpp | 9 +- dom/base/moz.build | 2 + dom/base/nsContentUtils.cpp | 1 + dom/base/nsGlobalWindowInner.cpp | 4 +- dom/base/nsGlobalWindowOuter.cpp | 13 +- dom/base/nsPIDOMWindow.h | 1 + dom/base/nsWindowRoot.cpp | 1 - dom/ipc/BrowserChild.cpp | 2 +- dom/ipc/BrowserChild.h | 3 +- dom/ipc/BrowserParent.cpp | 2 +- dom/ipc/BrowserParent.h | 2 +- dom/ipc/ContentParent.cpp | 27 +- dom/ipc/PBrowser.ipdl | 2 +- dom/ipc/WindowGlobalParent.cpp | 2 +- dom/ipc/WindowGlobalParent.h | 8 +- dom/media/MediaCache.cpp | 1 - dom/reporting/CrashReport.cpp | 1 - dom/security/ReferrerInfo.cpp | 5 +- dom/workers/RuntimeService.cpp | 1 + .../permissions/nsPermissionManager.cpp | 2 +- image/ImageCacheKey.cpp | 4 +- image/imgFrame.cpp | 1 - js/xpconnect/src/XPCJSContext.cpp | 1 - .../src/peerconnection/RTCStatsReport.h | 1 - netwerk/base/nsNetUtil.cpp | 1 + netwerk/cookie/CookieServiceChild.cpp | 1 + netwerk/cookie/nsCookieService.cpp | 11 +- netwerk/ipc/DocumentLoadListener.cpp | 3 +- .../protocol/http/ClassifierDummyChannel.cpp | 5 +- .../http/ClassifierDummyChannelChild.cpp | 5 +- netwerk/protocol/http/HttpBaseChannel.cpp | 4 +- netwerk/protocol/http/HttpChannelChild.cpp | 1 + netwerk/protocol/http/nsHttpChannel.cpp | 5 +- netwerk/protocol/http/nsHttpHandler.cpp | 4 +- .../url-classifier/UrlClassifierCommon.cpp | 9 +- netwerk/url-classifier/UrlClassifierCommon.h | 2 +- .../url-classifier/UrlClassifierFeatureBase.h | 1 + ...lassifierFeatureCryptominingAnnotation.cpp | 1 + ...lassifierFeatureCryptominingProtection.cpp | 1 + ...ssifierFeatureFingerprintingAnnotation.cpp | 1 + ...ssifierFeatureFingerprintingProtection.cpp | 1 + ...ssifierFeatureSocialTrackingAnnotation.cpp | 1 + ...ssifierFeatureSocialTrackingProtection.cpp | 1 + ...UrlClassifierFeatureTrackingAnnotation.cpp | 1 + ...UrlClassifierFeatureTrackingProtection.cpp | 1 + ...entBlocking.cpp => AntiTrackingCommon.cpp} | 1110 ++++++++++++++++- .../antitracking/AntiTrackingCommon.h | 176 +++ .../antitracking/AntiTrackingIPCUtils.h | 15 +- .../AntiTrackingRedirectHeuristic.cpp | 222 ---- .../AntiTrackingRedirectHeuristic.h | 20 - .../antitracking/AntiTrackingUtils.cpp | 124 -- .../antitracking/AntiTrackingUtils.h | 47 - .../components/antitracking/ContentBlocking.h | 103 -- .../antitracking/ContentBlockingAllowList.h | 7 +- .../antitracking/ContentBlockingNotifier.cpp | 530 -------- .../antitracking/ContentBlockingNotifier.h | 67 - .../ContentBlockingUserInteraction.cpp | 83 -- .../ContentBlockingUserInteraction.h | 29 - .../antitracking/SettingsChangeObserver.cpp | 2 +- .../components/antitracking/StorageAccess.cpp | 33 +- .../antitracking/StoragePrincipalHelper.cpp | 7 +- .../antitracking/StoragePrincipalHelper.h | 2 - .../TemporaryAccessGrantObserver.cpp | 92 -- .../TemporaryAccessGrantObserver.h | 88 -- .../antitracking/URLDecorationStripper.cpp | 1 - toolkit/components/antitracking/moz.build | 15 +- .../telemetry/tests/gtest/TestOrigins.cpp | 6 +- 74 files changed, 1407 insertions(+), 1622 deletions(-) rename {toolkit/components/antitracking => dom/base}/ContentBlockingLog.cpp (98%) rename {toolkit/components/antitracking => dom/base}/ContentBlockingLog.h (96%) rename toolkit/components/antitracking/{ContentBlocking.cpp => AntiTrackingCommon.cpp} (51%) create mode 100644 toolkit/components/antitracking/AntiTrackingCommon.h delete mode 100644 toolkit/components/antitracking/AntiTrackingRedirectHeuristic.cpp delete mode 100644 toolkit/components/antitracking/AntiTrackingRedirectHeuristic.h delete mode 100644 toolkit/components/antitracking/AntiTrackingUtils.cpp delete mode 100644 toolkit/components/antitracking/AntiTrackingUtils.h delete mode 100644 toolkit/components/antitracking/ContentBlocking.h delete mode 100644 toolkit/components/antitracking/ContentBlockingNotifier.cpp delete mode 100644 toolkit/components/antitracking/ContentBlockingNotifier.h delete mode 100644 toolkit/components/antitracking/ContentBlockingUserInteraction.cpp delete mode 100644 toolkit/components/antitracking/ContentBlockingUserInteraction.h delete mode 100644 toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp delete mode 100644 toolkit/components/antitracking/TemporaryAccessGrantObserver.h diff --git a/build/win32/orderfile.txt b/build/win32/orderfile.txt index 9c5973c368cc..e9ffd0477db3 100644 --- a/build/win32/orderfile.txt +++ b/build/win32/orderfile.txt @@ -19404,6 +19404,7 @@ Gecko_BeginWritingCString ?ShouldEnableClassifier@UrlClassifierCommon@net@mozilla@@SA_NPAVnsIChannel@@@Z ?AddonMayLoad@UrlClassifierCommon@net@mozilla@@SA_NPAVnsIChannel@@PAVnsIURI@@@Z ?GetTopWindowURI@HttpBaseChannel@net@mozilla@@UAG?AW4nsresult@@PAPAVnsIURI@@@Z +?MaybeGetDocumentURIBeingLoaded@AntiTrackingCommon@mozilla@@SA?AU?$already_AddRefed@VnsIURI@@@@PAVnsIChannel@@@Z ?GetTopWindowURI@HttpBaseChannel@net@mozilla@@IAE?AW4nsresult@@PAVnsIURI@@PAPAV5@@Z XPCOMService_GetThirdPartyUtil ?GetTopWindowForChannel@ThirdPartyUtil@@UAG?AW4nsresult@@PAVnsIChannel@@PAVnsIURI@@PAPAVmozIDOMWindowProxy@@@Z @@ -19531,6 +19532,7 @@ XPCOMService_GetThirdPartyUtil ?IsTrackingClassificationFlag@UrlClassifierCommon@net@mozilla@@SA_NI@Z ?DeQueue@nsHostResolver@@AAEXAAV?$LinkedList@V?$RefPtr@VnsHostRecord@@@@@mozilla@@PAPAVAddrHostRecord@@@Z ?popFirst@?$LinkedList@V?$RefPtr@VnsHostRecord@@@@@mozilla@@QAE?AV?$RefPtr@VnsHostRecord@@@@XZ +?IsFirstPartyStorageAccessGrantedFor@AntiTrackingCommon@mozilla@@SA_NPAVnsIHttpChannel@@PAVnsIURI@@PAI@Z ?GetTopLevelPrincipal@LoadInfo@net@mozilla@@UAEPAVnsIPrincipal@@XZ ?GetIsMainDocumentChannel@HttpBaseChannel@net@mozilla@@UAG?AW4nsresult@@PA_N@Z ?GetAddrInfo@net@mozilla@@YA?AW4nsresult@@ABV?$nsTSubstring@D@@GGPAPAVAddrInfo@12@_N@Z @@ -19546,10 +19548,12 @@ XPCOMService_GetThirdPartyUtil ?extensions_cookiesBehavior_overrideOnTopLevel@StaticPrefs@mozilla@@SA_NXZ ?GetChannelId@HttpBaseChannel@net@mozilla@@UAG?AW4nsresult@@PA_K@Z ??$?0PAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@@?$PairHelper@PAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@$00$0A@@detail@mozilla@@IAE@$$QAPAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@$$QAV?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@2@@Z +?OnAntiTrackingSettingsChanged@AntiTrackingCommon@mozilla@@SAXABV?$function@$$A6AXXZ@std@@@Z ?first@?$PairHelper@PAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@$00$0A@@detail@mozilla@@IBEABQAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@XZ ??4?$UniquePtr@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@@mozilla@@QAEAAV01@$$QAV01@@Z ??$AppendElement@ABV?$function@$$A6AXXZ@std@@UnsTArrayInfallibleAllocator@@@?$nsTArray_Impl@V?$function@$$A6AXXZ@std@@UnsTArrayInfallibleAllocator@@@@IAEPAV?$function@$$A6AXXZ@std@@ABV12@@Z ??$EnsureCapacity@UnsTArrayInfallibleAllocator@@@?$nsTArray_base@UnsTArrayInfallibleAllocator@@U?$nsTArray_CopyWithConstructors@V?$function@$$A6AXXZ@std@@@@@@IAE?AUnsTArrayInfallibleResult@@II@Z +?IsOnContentBlockingAllowList@AntiTrackingCommon@mozilla@@SA?AW4nsresult@@PAVnsIURI@@_NW4ContentBlockingAllowListPurpose@12@AA_N@Z ?TestPermissionOriginNoSuffix@nsPermissionManager@@UAG?AW4nsresult@@ABV?$nsTSubstring@D@@0PAI@Z ?NS_IsSafeTopLevelNav@@YA_NPAVnsIChannel@@@Z ?IsSafeMethod@nsHttpRequestHead@net@mozilla@@QAE_NXZ @@ -26364,6 +26368,7 @@ Gecko_AppendPropertyValuePair ?QueryInterface@imgLoader@@UAG?AW4nsresult@@ABUnsID@@PAPAX@Z ?FindEntryProperties@imgLoader@@UAG?AW4nsresult@@PAVnsIURI@@PAVDocument@dom@mozilla@@PAPAVnsIProperties@@@Z ?IsThirdPartyTrackingResourceWindow@nsContentUtils@@SA_NPAVnsPIDOMWindowInner@@@Z +?MaybeIsFirstPartyStorageAccessGrantedFor@AntiTrackingCommon@mozilla@@SA_NPAVnsPIDOMWindowInner@@PAVnsIURI@@@Z ??$CreateAndResolve@_N@?$MozPromise@H_N$00@mozilla@@SA?AV?$RefPtr@V?$MozPromise@H_N$00@mozilla@@@@$$QA_NPBD@Z ?AdjustPriority@HttpBaseChannel@net@mozilla@@UAG?AW4nsresult@@H@Z ?SetTimingEnabled@imgRequestProxy@@UAG?AW4nsresult@@_N@Z diff --git a/build/win64/orderfile.txt b/build/win64/orderfile.txt index 1df3ef30f4d1..4d8b55209951 100644 --- a/build/win64/orderfile.txt +++ b/build/win64/orderfile.txt @@ -19322,6 +19322,7 @@ Gecko_BeginWritingCString ?ShouldEnableClassifier@UrlClassifierCommon@net@mozilla@@SA_NPEAVnsIChannel@@@Z ?AddonMayLoad@UrlClassifierCommon@net@mozilla@@SA_NPEAVnsIChannel@@PEAVnsIURI@@@Z ?GetTopWindowURI@HttpBaseChannel@net@mozilla@@UEAA?AW4nsresult@@PEAPEAVnsIURI@@@Z +?MaybeGetDocumentURIBeingLoaded@AntiTrackingCommon@mozilla@@SA?AU?$already_AddRefed@VnsIURI@@@@PEAVnsIChannel@@@Z ?GetTopWindowURI@HttpBaseChannel@net@mozilla@@IEAA?AW4nsresult@@PEAVnsIURI@@PEAPEAV5@@Z XPCOMService_GetThirdPartyUtil ?GetTopWindowForChannel@ThirdPartyUtil@@UEAA?AW4nsresult@@PEAVnsIChannel@@PEAVnsIURI@@PEAPEAVmozIDOMWindowProxy@@@Z @@ -19442,6 +19443,7 @@ XPCOMService_GetThirdPartyUtil ?IsThirdPartyInternal@ThirdPartyUtil@@AEAA?AW4nsresult@@AEBV?$nsTString@D@@PEAVnsIURI@@PEA_N@Z ?IsTrackingResource@HttpBaseChannel@net@mozilla@@UEAA?AW4nsresult@@PEA_N@Z ?IsTrackingClassificationFlag@UrlClassifierCommon@net@mozilla@@SA_NI@Z +?IsFirstPartyStorageAccessGrantedFor@AntiTrackingCommon@mozilla@@SA_NPEAVnsIHttpChannel@@PEAVnsIURI@@PEAI@Z ?GetTopLevelPrincipal@LoadInfo@net@mozilla@@UEAAPEAVnsIPrincipal@@XZ ?GetIsMainDocumentChannel@HttpBaseChannel@net@mozilla@@UEAA?AW4nsresult@@PEA_N@Z ?GetIsContentPrincipal@BasePrincipal@mozilla@@UEAA?AW4nsresult@@PEA_N@Z @@ -19462,10 +19464,12 @@ XPCOMService_GetThirdPartyUtil ?extensions_cookiesBehavior_overrideOnTopLevel@StaticPrefs@mozilla@@SA_NXZ ?GetChannelId@HttpBaseChannel@net@mozilla@@UEAA?AW4nsresult@@PEA_K@Z ??$?0PEAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@@?$PairHelper@PEAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@$00$0A@@detail@mozilla@@IEAA@$$QEAPEAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@$$QEAV?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@2@@Z +?OnAntiTrackingSettingsChanged@AntiTrackingCommon@mozilla@@SAXAEBV?$function@$$A6AXXZ@std@@@Z ?first@?$PairHelper@PEAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@$00$0A@@detail@mozilla@@IEBAAEBQEAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@XZ ?reset@?$UniquePtr@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@V?$DefaultDelete@V?$nsTArray@V?$function@$$A6AXXZ@std@@@@@mozilla@@@mozilla@@QEAAXPEAV?$nsTArray@V?$function@$$A6AXXZ@std@@@@@Z ??$AppendElement@AEBV?$function@$$A6AXXZ@std@@UnsTArrayInfallibleAllocator@@@?$nsTArray_Impl@V?$function@$$A6AXXZ@std@@UnsTArrayInfallibleAllocator@@@@IEAAPEAV?$function@$$A6AXXZ@std@@AEBV12@@Z ??$EnsureCapacity@UnsTArrayInfallibleAllocator@@@?$nsTArray_base@UnsTArrayInfallibleAllocator@@U?$nsTArray_CopyWithConstructors@V?$function@$$A6AXXZ@std@@@@@@IEAA?AUnsTArrayInfallibleResult@@_K0@Z +?IsOnContentBlockingAllowList@AntiTrackingCommon@mozilla@@SA?AW4nsresult@@PEAVnsIURI@@_NW4ContentBlockingAllowListPurpose@12@AEA_N@Z ?TestPermissionOriginNoSuffix@nsPermissionManager@@UEAA?AW4nsresult@@AEBV?$nsTSubstring@D@@0PEAI@Z ?NS_IsSafeTopLevelNav@@YA_NPEAVnsIChannel@@@Z ?IsSafeMethod@nsHttpRequestHead@net@mozilla@@QEAA_NXZ @@ -26331,6 +26335,7 @@ UnregisterWeakMemoryReporter ?ExplicitSetUploadStreamLength@HttpBaseChannel@net@mozilla@@AEAA?AW4nsresult@@_K_N@Z ??$ReplaceChar@_SX@?$nsTString@_S@@QEAAXPEBD_S@Z ?Set@URLParams@dom@mozilla@@QEAAXAEBV?$nsTSubstring@_S@@0@Z +?NotifyBlockingDecision@AntiTrackingCommon@mozilla@@SAXPEAVnsIChannel@@W4BlockingDecision@12@I@Z ?ConstructorEnabled@ChannelWrapper_Binding@dom@mozilla@@YA_NPEAUJSContext@@V?$Handle@PEAVJSObject@@@JS@@@Z ?CreateInterfaceObjects@ChannelWrapper_Binding@dom@mozilla@@YAXPEAUJSContext@@V?$Handle@PEAVJSObject@@@JS@@AEAVProtoAndIfaceCache@23@_N@Z ?Id@ChannelWrapper@extensions@mozilla@@QEBA_KXZ @@ -26665,6 +26670,7 @@ Gecko_AppendPropertyValuePair ?IsImageInCache@nsContentUtils@@SA_NPEAVnsIURI@@PEAVDocument@dom@mozilla@@@Z ?FindEntryProperties@imgLoader@@UEAA?AW4nsresult@@PEAVnsIURI@@PEAVDocument@dom@mozilla@@PEAPEAVnsIProperties@@@Z ?IsThirdPartyTrackingResourceWindow@nsContentUtils@@SA_NPEAVnsPIDOMWindowInner@@@Z +?MaybeIsFirstPartyStorageAccessGrantedFor@AntiTrackingCommon@mozilla@@SA_NPEAVnsPIDOMWindowInner@@PEAVnsIURI@@@Z ??$CreateAndResolve@_N@?$MozPromise@H_N$00@mozilla@@SA?AV?$RefPtr@V?$MozPromise@H_N$00@mozilla@@@@$$QEA_NPEBD@Z ?AdjustPriority@HttpBaseChannel@net@mozilla@@UEAA?AW4nsresult@@H@Z ?SetTimingEnabled@imgRequestProxy@@UEAA?AW4nsresult@@_N@Z diff --git a/toolkit/components/antitracking/ContentBlockingLog.cpp b/dom/base/ContentBlockingLog.cpp similarity index 98% rename from toolkit/components/antitracking/ContentBlockingLog.cpp rename to dom/base/ContentBlockingLog.cpp index 8061bd1fef8b..39960a5fa9a7 100644 --- a/toolkit/components/antitracking/ContentBlockingLog.cpp +++ b/dom/base/ContentBlockingLog.cpp @@ -30,6 +30,8 @@ static LazyLogModule gContentBlockingLog("ContentBlockingLog"); typedef Telemetry::OriginMetricID OriginMetricID; +namespace dom { + // sync with TelemetryOriginData.inc NS_NAMED_LITERAL_CSTRING(ContentBlockingLog::kDummyOriginHash, "PAGELOAD"); @@ -108,7 +110,7 @@ static void ReportOriginSingleHash(OriginMetricID aId, Maybe ContentBlockingLog::RecordLogParent( const nsACString& aOrigin, uint32_t aType, bool aBlocked, - const Maybe& aReason, + const Maybe& aReason, const nsTArray& aTrackingFullHashes) { MOZ_ASSERT(XRE_IsParentProcess()); @@ -291,4 +293,5 @@ void ContentBlockingLog::ReportOrigins() { } } +} // namespace dom } // namespace mozilla diff --git a/toolkit/components/antitracking/ContentBlockingLog.h b/dom/base/ContentBlockingLog.h similarity index 96% rename from toolkit/components/antitracking/ContentBlockingLog.h rename to dom/base/ContentBlockingLog.h index 40d504f7a2b6..326c0b4bde6e 100644 --- a/toolkit/components/antitracking/ContentBlockingLog.h +++ b/dom/base/ContentBlockingLog.h @@ -4,10 +4,10 @@ * 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/. */ -#ifndef mozilla_ContentBlockingLog_h -#define mozilla_ContentBlockingLog_h +#ifndef mozilla_dom_ContentBlockingLog_h +#define mozilla_dom_ContentBlockingLog_h -#include "mozilla/ContentBlockingNotifier.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/JSONWriter.h" #include "mozilla/Maybe.h" #include "mozilla/StaticPrefs_browser.h" @@ -18,19 +18,18 @@ #include "nsTArray.h" #include "nsWindowSizes.h" -class nsIPrincipal; - namespace mozilla { +namespace dom { class ContentBlockingLog final { - typedef ContentBlockingNotifier::StorageAccessGrantedReason + typedef AntiTrackingCommon::StorageAccessGrantedReason StorageAccessGrantedReason; struct LogEntry { uint32_t mType; uint32_t mRepeatCount; bool mBlocked; - Maybe mReason; + Maybe mReason; nsTArray mTrackingFullHashes; }; @@ -88,12 +87,12 @@ class ContentBlockingLog final { // ContentBlockingLog from content processes. Maybe RecordLogParent( const nsACString& aOrigin, uint32_t aType, bool aBlocked, - const Maybe& aReason, + const Maybe& aReason, const nsTArray& aTrackingFullHashes); void RecordLog( const nsACString& aOrigin, uint32_t aType, bool aBlocked, - const Maybe& aReason, + const Maybe& aReason, const nsTArray& aTrackingFullHashes) { RecordLogInternal(aOrigin, aType, aBlocked, aReason, aTrackingFullHashes); } @@ -242,8 +241,8 @@ class ContentBlockingLog final { private: void RecordLogInternal( const nsACString& aOrigin, uint32_t aType, bool aBlocked, - const Maybe& - aReason = Nothing(), + const Maybe& aReason = + Nothing(), const nsTArray& aTrackingFullHashes = nsTArray()) { DebugOnly isCookiesBlockedTracker = aType == nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || @@ -425,6 +424,7 @@ class ContentBlockingLog final { OriginDataTable mLog; }; +} // namespace dom } // namespace mozilla #endif diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 9d2c87365049..bc0aeaefb9ca 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -11,13 +11,11 @@ #include "AudioChannelService.h" #include "mozilla/dom/Document.h" #include "DocumentInlines.h" -#include "mozilla/AntiTrackingUtils.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/ArrayUtils.h" #include "mozilla/AutoRestore.h" #include "mozilla/BinarySearch.h" -#include "mozilla/ContentBlocking.h" #include "mozilla/ContentBlockingAllowList.h" -#include "mozilla/ContentBlockingUserInteraction.h" #include "mozilla/CSSEnabledState.h" #include "mozilla/DebugOnly.h" #include "mozilla/EditorCommands.h" @@ -15066,9 +15064,9 @@ void Document::MaybeAllowStorageForOpenerAfterUserInteraction() { } // We don't care when the asynchronous work finishes here. - Unused << ContentBlocking::AllowAccessFor( + Unused << AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor( NodePrincipal(), openerInner, - ContentBlockingNotifier::eOpenerAfterUserInteraction); + AntiTrackingCommon::eOpenerAfterUserInteraction); } namespace { @@ -15168,7 +15166,7 @@ class UserIntractionTimer final : public Runnable, // If the document is not gone, let's reset its timer flag. nsCOMPtr document = do_QueryReferent(mDocument); if (document) { - ContentBlockingUserInteraction::Observe(mPrincipal); + AntiTrackingCommon::StoreUserInteractionFor(mPrincipal); document->ResetUserInteractionTimer(); } } @@ -15214,7 +15212,7 @@ void Document::MaybeStoreUserInteractionAsPermission() { if (!mUserHasInteracted) { // First interaction, let's store this info now. - ContentBlockingUserInteraction::Observe(NodePrincipal()); + AntiTrackingCommon::StoreUserInteractionFor(NodePrincipal()); return; } @@ -15639,11 +15637,10 @@ already_AddRefed Document::RequestStorageAccess( RefPtr self(this); - auto performFinalChecks = - [inner, - self]() -> RefPtr { - RefPtr p = - new ContentBlocking::StorageAccessFinalCheckPromise::Private( + auto performFinalChecks = [inner, self]() + -> RefPtr { + RefPtr p = + new AntiTrackingCommon::StorageAccessFinalCheckPromise::Private( __func__); RefPtr sapr = StorageAccessPermissionRequest::Create( @@ -15652,7 +15649,7 @@ already_AddRefed Document::RequestStorageAccess( [p] { Telemetry::AccumulateCategorical( Telemetry::LABELS_STORAGE_ACCESS_API_UI::Allow); - p->Resolve(ContentBlocking::eAllow, __func__); + p->Resolve(AntiTrackingCommon::eAllow, __func__); }, // Block [p] { @@ -15697,10 +15694,10 @@ already_AddRefed Document::RequestStorageAccess( MOZ_ASSERT_IF(pr2 != PromptResult::Granted, pr2 == PromptResult::Denied); if (pr2 == PromptResult::Granted) { - ContentBlocking::StorageAccessPromptChoices choice = - ContentBlocking::eAllow; + AntiTrackingCommon::StorageAccessPromptChoices choice = + AntiTrackingCommon::eAllow; if (autoGrant) { - choice = ContentBlocking::eAllowAutoGrant; + choice = AntiTrackingCommon::eAllowAutoGrant; } if (!autoGrant) { p->Resolve(choice, __func__); @@ -15723,8 +15720,8 @@ already_AddRefed Document::RequestStorageAccess( return std::move(p); }; - ContentBlocking::AllowAccessFor( - NodePrincipal(), inner, ContentBlockingNotifier::eStorageAccessAPI, + AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor( + NodePrincipal(), inner, AntiTrackingCommon::eStorageAccessAPI, performFinalChecks) ->Then( GetCurrentThreadSerialEventTarget(), __func__, @@ -15787,7 +15784,7 @@ Document::AutomaticStorageAccessCanBeGranted() { bool Document::AutomaticStorageAccessCanBeGranted(nsIPrincipal* aPrincipal) { nsAutoCString prefix; - AntiTrackingUtils::CreateStoragePermissionKey(aPrincipal, prefix); + AntiTrackingCommon::CreateStoragePermissionKey(aPrincipal, prefix); nsPermissionManager* permManager = nsPermissionManager::GetInstance(); if (NS_WARN_IF(!permManager)) { @@ -16047,11 +16044,11 @@ nsIPrincipal* Document::EffectiveStoragePrincipal() const { return mActiveStoragePrincipal; } - // We use the lower-level ContentBlocking API here to ensure this + // We use the lower-level AntiTrackingCommon API here to ensure this // check doesn't send notifications. uint32_t rejectedReason = 0; - if (ContentBlocking::ShouldAllowAccessFor(inner, GetDocumentURI(), - &rejectedReason)) { + if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + inner, GetDocumentURI(), &rejectedReason)) { return mActiveStoragePrincipal = NodePrincipal(); } diff --git a/dom/base/Document.h b/dom/base/Document.h index 61cd7c56a0c6..20e17aba2678 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -48,11 +48,11 @@ #include "nsContentListDeclarations.h" #include "nsExpirationTracker.h" #include "nsClassHashtable.h" -#include "nsWindowSizes.h" #include "ReferrerInfo.h" #include "mozilla/Attributes.h" #include "mozilla/CallState.h" #include "mozilla/CORSMode.h" +#include "mozilla/dom/ContentBlockingLog.h" #include "mozilla/dom/DispatcherTrait.h" #include "mozilla/dom/DocumentOrShadowRoot.h" #include "mozilla/dom/ViewportMetaData.h" diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 89e044f8c8a6..1388a20edd59 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -11,8 +11,7 @@ #include "nsIXULAppInfo.h" #include "nsPluginArray.h" #include "nsMimeTypeArray.h" -#include "mozilla/ContentBlocking.h" -#include "mozilla/ContentBlockingNotifier.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/MemoryReporting.h" #include "mozilla/dom/BodyExtractor.h" #include "mozilla/dom/FetchBinding.h" @@ -528,13 +527,13 @@ bool Navigator::CookieEnabled() { } uint32_t rejectedReason = 0; - bool granted = ContentBlocking::ShouldAllowAccessFor(mWindow, contentURI, - &rejectedReason); + bool granted = AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + mWindow, contentURI, &rejectedReason); - ContentBlockingNotifier::OnDecision( + AntiTrackingCommon::NotifyBlockingDecision( mWindow, - granted ? ContentBlockingNotifier::BlockingDecision::eAllow - : ContentBlockingNotifier::BlockingDecision::eBlock, + granted ? AntiTrackingCommon::BlockingDecision::eAllow + : AntiTrackingCommon::BlockingDecision::eBlock, rejectedReason); return granted; } diff --git a/dom/base/ThirdPartyUtil.cpp b/dom/base/ThirdPartyUtil.cpp index be469cc959be..7c06909c4a31 100644 --- a/dom/base/ThirdPartyUtil.cpp +++ b/dom/base/ThirdPartyUtil.cpp @@ -19,7 +19,6 @@ #include "nsReadableUtils.h" #include "nsThreadUtils.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/ContentBlocking.h" #include "mozilla/ContentBlockingAllowList.h" #include "mozilla/dom/Document.h" #include "mozilla/Logging.h" @@ -494,15 +493,15 @@ ThirdPartyUtil::AnalyzeChannel(nsIChannel* aChannel, bool aNotify, nsIURI* aURI, aRequireThirdPartyCheck ? result.contains(ThirdPartyAnalysis::IsForeign) : true; if (performStorageChecks && - ContentBlocking::ShouldAllowAccessFor(aChannel, aURI ? aURI : uri.get(), - aRejectedReason)) { + AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + aChannel, aURI ? aURI : uri.get(), aRejectedReason)) { result += ThirdPartyAnalysis::IsFirstPartyStorageAccessGranted; } if (aNotify && !result.contains( ThirdPartyAnalysis::IsFirstPartyStorageAccessGranted)) { - ContentBlockingNotifier::OnDecision( - aChannel, ContentBlockingNotifier::BlockingDecision::eBlock, + AntiTrackingCommon::NotifyBlockingDecision( + aChannel, AntiTrackingCommon::BlockingDecision::eBlock, *aRejectedReason); } } diff --git a/dom/base/moz.build b/dom/base/moz.build index a777da3712ee..45bbd86ef554 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -156,6 +156,7 @@ EXPORTS.mozilla.dom += [ 'ChromeNodeList.h', 'ChromeUtils.h', 'Comment.h', + 'ContentBlockingLog.h', 'ContentFrameMessageManager.h', 'ContentProcessMessageManager.h', 'CustomElementRegistry.h', @@ -279,6 +280,7 @@ UNIFIED_SOURCES += [ 'ChromeNodeList.cpp', 'ChromeUtils.cpp', 'Comment.cpp', + 'ContentBlockingLog.cpp', 'ContentFrameMessageManager.cpp', 'ContentIterator.cpp', 'ContentProcessMessageManager.cpp', diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 4e50f62515e2..e445de694e5b 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -33,6 +33,7 @@ #include "gfxDrawable.h" #include "ImageOps.h" #include "mozAutoDocUpdate.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/ArrayUtils.h" #include "mozilla/Attributes.h" diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 7e3b8eb706f7..d6934fde0e8a 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -4400,8 +4400,8 @@ Storage* nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError) { // it may be okay to provide SessionStorage even when we receive a value of // eDeny. // - // ContentBlocking::ShouldAllowAccessFor will return false for 3 main - // reasons. + // AntiTrackingCommon::IsFirstPartyStorageAccessGranted will return false + // for 3 main reasons. // // 1. Cookies are entirely blocked due to a per-origin permission // (nsICookiePermission::ACCESS_DENY for the top-level principal or this diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp index 602096089508..249580e733d1 100644 --- a/dom/base/nsGlobalWindowOuter.cpp +++ b/dom/base/nsGlobalWindowOuter.cpp @@ -21,8 +21,7 @@ #include "nsIPermissionManager.h" #include "nsISecureBrowserUI.h" #include "nsIWebProgressListener.h" -#include "mozilla/AntiTrackingUtils.h" -#include "mozilla/ContentBlocking.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowsingContextBinding.h" @@ -2482,8 +2481,8 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument, // permission has been granted already. // Don't notify in this case, since we would be notifying the user // needlessly. - mHasStorageAccess = - ContentBlocking::ShouldAllowAccessFor(newInnerWindow, uri, nullptr); + mHasStorageAccess = AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + newInnerWindow, uri, nullptr); } return NS_OK; @@ -6868,7 +6867,7 @@ nsGlobalWindowOuter::Observe(nsISupports* aSupports, const char* aTopic, if (!principal) { return NS_OK; } - if (!AntiTrackingUtils::IsStorageAccessPermission(permission, principal)) { + if (!AntiTrackingCommon::IsStorageAccessPermission(permission, principal)) { return NS_OK; } if (!nsCRT::strcmp(aData, u"deleted")) { @@ -7184,8 +7183,8 @@ void nsGlobalWindowOuter::MaybeAllowStorageForOpenedWindow(nsIURI* aURI) { aURI, doc->NodePrincipal()->OriginAttributesRef()); // We don't care when the asynchronous work finishes here. - Unused << ContentBlocking::AllowAccessFor(principal, inner, - ContentBlockingNotifier::eOpener); + Unused << AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor( + principal, inner, AntiTrackingCommon::eOpener); } //***************************************************************************** diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 87afe21f1e81..a0fba102ccf5 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -13,6 +13,7 @@ #include "nsCOMPtr.h" #include "nsTArray.h" #include "mozilla/dom/EventTarget.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/Maybe.h" #include "mozilla/TaskCategory.h" #include "js/TypeDecls.h" diff --git a/dom/base/nsWindowRoot.cpp b/dom/base/nsWindowRoot.cpp index c4a5c6e7fda9..55d6a5c0040f 100644 --- a/dom/base/nsWindowRoot.cpp +++ b/dom/base/nsWindowRoot.cpp @@ -7,7 +7,6 @@ #include "mozilla/BasicEvents.h" #include "mozilla/EventDispatcher.h" #include "mozilla/EventListenerManager.h" -#include "mozilla/StaticPrefs_browser.h" #include "mozilla/dom/WindowRootBinding.h" #include "nsCOMPtr.h" #include "nsWindowRoot.h" diff --git a/dom/ipc/BrowserChild.cpp b/dom/ipc/BrowserChild.cpp index d01cd27e1e0e..9e3a1f7ae9f8 100644 --- a/dom/ipc/BrowserChild.cpp +++ b/dom/ipc/BrowserChild.cpp @@ -4048,7 +4048,7 @@ void BrowserChild::NotifyContentBlockingEvent( uint32_t aEvent, nsIChannel* aChannel, bool aBlocked, const nsACString& aTrackingOrigin, const nsTArray& aTrackingFullHashes, - const Maybe& + const Maybe& aReason) { if (!IPCOpen()) { return; diff --git a/dom/ipc/BrowserChild.h b/dom/ipc/BrowserChild.h index 16308a1b6534..b3a5d15f02d9 100644 --- a/dom/ipc/BrowserChild.h +++ b/dom/ipc/BrowserChild.h @@ -699,8 +699,7 @@ class BrowserChild final : public nsMessageManagerScriptExecutor, uint32_t aEvent, nsIChannel* aChannel, bool aBlocked, const nsACString& aTrackingOrigin, const nsTArray& aTrackingFullHashes, - const Maybe& - aReason); + const Maybe& aReason); protected: virtual ~BrowserChild(); diff --git a/dom/ipc/BrowserParent.cpp b/dom/ipc/BrowserParent.cpp index be05078e51af..85035a1d527e 100644 --- a/dom/ipc/BrowserParent.cpp +++ b/dom/ipc/BrowserParent.cpp @@ -2695,7 +2695,7 @@ mozilla::ipc::IPCResult BrowserParent::RecvNotifyContentBlockingEvent( const uint32_t& aEvent, const RequestData& aRequestData, const bool aBlocked, const nsACString& aTrackingOrigin, nsTArray&& aTrackingFullHashes, - const Maybe& + const Maybe& aReason) { MOZ_ASSERT(aRequestData.elapsedLoadTimeMS().isNothing()); diff --git a/dom/ipc/BrowserParent.h b/dom/ipc/BrowserParent.h index 9883f8e9889b..079c249e723a 100644 --- a/dom/ipc/BrowserParent.h +++ b/dom/ipc/BrowserParent.h @@ -317,7 +317,7 @@ class BrowserParent final : public PBrowserParent, const uint32_t& aEvent, const RequestData& aRequestData, const bool aBlocked, const nsACString& aTrackingOrigin, nsTArray&& aTrackingFullHashes, - const Maybe& + const Maybe& aReason); mozilla::ipc::IPCResult RecvNavigationFinished(); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 15ff982fc366..7bd19d2a1d1d 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -40,10 +40,9 @@ #include "URIUtils.h" #include "gfxPlatform.h" #include "gfxPlatformFontList.h" -#include "mozilla/ContentBlocking.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" #include "mozilla/BenchmarkStorageParent.h" -#include "mozilla/ContentBlockingUserInteraction.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/Components.h" #include "mozilla/DataStorage.h" @@ -5822,23 +5821,23 @@ ContentParent::RecvFirstPartyStorageAccessGrantedForOrigin( const Principal& aParentPrincipal, const Principal& aTrackingPrincipal, const nsCString& aTrackingOrigin, const int& aAllowMode, FirstPartyStorageAccessGrantedForOriginResolver&& aResolver) { - ContentBlocking::SaveAccessForOriginOnParentProcess( - aParentPrincipal, aTrackingPrincipal, aTrackingOrigin, aAllowMode) - ->Then( - GetCurrentThreadSerialEventTarget(), __func__, - [aResolver = std::move(aResolver)]( - ContentBlocking::ParentAccessGrantPromise::ResolveOrRejectValue&& - aValue) { - bool success = - aValue.IsResolve() && NS_SUCCEEDED(aValue.ResolveValue()); - aResolver(success); - }); + AntiTrackingCommon:: + SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess( + aParentPrincipal, aTrackingPrincipal, aTrackingOrigin, aAllowMode) + ->Then(GetCurrentThreadSerialEventTarget(), __func__, + [aResolver = std::move(aResolver)]( + AntiTrackingCommon::FirstPartyStorageAccessGrantPromise:: + ResolveOrRejectValue&& aValue) { + bool success = aValue.IsResolve() && + NS_SUCCEEDED(aValue.ResolveValue()); + aResolver(success); + }); return IPC_OK(); } mozilla::ipc::IPCResult ContentParent::RecvStoreUserInteractionAsPermission( const Principal& aPrincipal) { - ContentBlockingUserInteraction::Observe(aPrincipal); + AntiTrackingCommon::StoreUserInteractionFor(aPrincipal); return IPC_OK(); } diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 46b9843922a7..9b68a58df500 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -95,7 +95,7 @@ using mozilla::ScrollFlags from "mozilla/PresShellForwards.h"; using struct InputFormData from "mozilla/dom/SessionStoreMessageUtils.h"; using struct CollectedInputDataValue from "mozilla/dom/SessionStoreMessageUtils.h"; using refcounted class nsITransportSecurityInfo from "nsITransportSecurityInfo.h"; -using mozilla::ContentBlockingNotifier::StorageAccessGrantedReason from "mozilla/ContentBlockingNotifier.h"; +using mozilla::AntiTrackingCommon::StorageAccessGrantedReason from "mozilla/AntiTrackingCommon.h"; using CallerType from "mozilla/dom/BindingDeclarations.h"; namespace mozilla { diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index d040fe028d6e..848751cd3774 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -311,7 +311,7 @@ void WindowGlobalParent::NotifyContentBlockingEvent( uint32_t aEvent, nsIRequest* aRequest, bool aBlocked, const nsACString& aTrackingOrigin, const nsTArray& aTrackingFullHashes, - const Maybe& aReason) { + const Maybe& aReason) { MOZ_ASSERT(NS_IsMainThread()); DebugOnly isCookiesBlockedTracker = aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || diff --git a/dom/ipc/WindowGlobalParent.h b/dom/ipc/WindowGlobalParent.h index 32935c970fb3..560f6ad3172c 100644 --- a/dom/ipc/WindowGlobalParent.h +++ b/dom/ipc/WindowGlobalParent.h @@ -7,8 +7,7 @@ #ifndef mozilla_dom_WindowGlobalParent_h #define mozilla_dom_WindowGlobalParent_h -#include "mozilla/ContentBlockingLog.h" -#include "mozilla/ContentBlockingNotifier.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/RefPtr.h" #include "mozilla/dom/DOMRect.h" #include "mozilla/dom/PWindowGlobalParent.h" @@ -19,6 +18,7 @@ #include "nsISupports.h" #include "mozilla/dom/WindowGlobalActor.h" #include "mozilla/dom/CanonicalBrowsingContext.h" +#include "mozilla/dom/ContentBlockingLog.h" class nsIPrincipal; class nsIURI; @@ -146,8 +146,8 @@ class WindowGlobalParent final : public WindowContext, uint32_t aEvent, nsIRequest* aRequest, bool aBlocked, const nsACString& aTrackingOrigin, const nsTArray& aTrackingFullHashes, - const Maybe& - aReason = Nothing()); + const Maybe& aReason = + Nothing()); ContentBlockingLog* GetContentBlockingLog() { return &mContentBlockingLog; } diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index 86662448e066..e93e1de972ec 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -19,7 +19,6 @@ #include "mozilla/Preferences.h" #include "mozilla/Services.h" #include "mozilla/StaticPtr.h" -#include "mozilla/StaticPrefs_browser.h" #include "mozilla/StaticPrefs_media.h" #include "mozilla/SystemGroup.h" #include "mozilla/Telemetry.h" diff --git a/dom/reporting/CrashReport.cpp b/dom/reporting/CrashReport.cpp index 4bc50c280e75..e41ffa976dce 100644 --- a/dom/reporting/CrashReport.cpp +++ b/dom/reporting/CrashReport.cpp @@ -9,7 +9,6 @@ #include "mozilla/dom/Navigator.h" #include "mozilla/dom/ReportingHeader.h" #include "mozilla/dom/ReportDeliver.h" -#include "mozilla/JSONWriter.h" #include "nsIPrincipal.h" #include "nsIURIMutator.h" #include "nsString.h" diff --git a/dom/security/ReferrerInfo.cpp b/dom/security/ReferrerInfo.cpp index 4e7ea0c39be2..36fc546c3f07 100644 --- a/dom/security/ReferrerInfo.cpp +++ b/dom/security/ReferrerInfo.cpp @@ -18,8 +18,8 @@ #include "nsCharSeparatedTokenizer.h" #include "ReferrerInfo.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" -#include "mozilla/ContentBlocking.h" #include "mozilla/net/CookieJarSettings.h" #include "mozilla/net/HttpBaseChannel.h" #include "mozilla/dom/Element.h" @@ -205,7 +205,8 @@ ReferrerPolicy ReferrerInfo::GetDefaultReferrerPolicy(nsIHttpChannel* aChannel, if (aChannel && aURI && cjs->GetRejectThirdPartyTrackers()) { uint32_t rejectedReason = 0; thirdPartyTrackerIsolated = - !ContentBlocking::ShouldAllowAccessFor(aChannel, aURI, &rejectedReason); + !AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + aChannel, aURI, &rejectedReason); // Here we intentionally do not notify about the rejection reason, if any // in order to avoid this check to have any visible side-effects (e.g. a // web console report.) diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 2bfe4f9bc105..b20abd71cbb8 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -25,6 +25,7 @@ #include "js/ContextOptions.h" #include "js/LocaleSensitive.h" #include "mozilla/AbstractThread.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/ArrayUtils.h" #include "mozilla/Atomics.h" #include "mozilla/Attributes.h" diff --git a/extensions/permissions/nsPermissionManager.cpp b/extensions/permissions/nsPermissionManager.cpp index 6709c5342789..02f18c7f13c5 100644 --- a/extensions/permissions/nsPermissionManager.cpp +++ b/extensions/permissions/nsPermissionManager.cpp @@ -5,9 +5,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/Attributes.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/dom/ContentParent.h" #include "mozilla/BasePrincipal.h" -#include "mozilla/ContentBlockingUserInteraction.h" #include "mozilla/ContentPrincipal.h" #include "mozilla/DebugOnly.h" #include "mozilla/Pair.h" diff --git a/image/ImageCacheKey.cpp b/image/ImageCacheKey.cpp index fc6c3e19e23d..d5c69e3de67f 100644 --- a/image/ImageCacheKey.cpp +++ b/image/ImageCacheKey.cpp @@ -7,7 +7,7 @@ #include -#include "mozilla/ContentBlocking.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/HashFunctions.h" #include "mozilla/StorageAccess.h" #include "mozilla/Unused.h" @@ -185,7 +185,7 @@ nsCString ImageCacheKey::GetTopLevelBaseDomain(Document* aDocument, // this point. The best approach here is to be conservative: if we are sure // that the permission is granted, let's return 0. Otherwise, let's make a // unique image cache per the top-level document eTLD+1. - if (!ContentBlocking::ApproximateAllowAccessForWithoutChannel( + if (!AntiTrackingCommon::MaybeIsFirstPartyStorageAccessGrantedFor( aDocument->GetInnerWindow(), aURI)) { nsPIDOMWindowOuter* top = aDocument->GetInnerWindow()->GetInProcessScriptableTop(); diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index 765e6b6b7f00..1bbf59e9ddea 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -27,7 +27,6 @@ #include "mozilla/layers/SourceSurfaceVolatileData.h" #include "mozilla/Likely.h" #include "mozilla/MemoryReporting.h" -#include "mozilla/StaticPrefs_browser.h" #include "nsMargin.h" #include "nsRefreshDriver.h" #include "nsThreadUtils.h" diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index 5d2e768368ad..a8766de86d6a 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -28,7 +28,6 @@ #ifdef FUZZING # include "mozilla/StaticPrefs_fuzzing.h" #endif -#include "mozilla/StaticPrefs_browser.h" #include "mozilla/StaticPrefs_javascript.h" #include "mozilla/dom/ScriptSettings.h" diff --git a/media/webrtc/signaling/src/peerconnection/RTCStatsReport.h b/media/webrtc/signaling/src/peerconnection/RTCStatsReport.h index c2be8cf95097..5f9eb49dfc23 100644 --- a/media/webrtc/signaling/src/peerconnection/RTCStatsReport.h +++ b/media/webrtc/signaling/src/peerconnection/RTCStatsReport.h @@ -18,7 +18,6 @@ #include "mozilla/ErrorResult.h" #include "mozilla/UniquePtr.h" #include "prtime.h" // PR_Now -#include "mozilla/MozPromise.h" #include "mozilla/TimeStamp.h" #include "mozilla/dom/RTCStatsReportBinding.h" // RTCStatsCollection diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 8abd0dd9e4ea..0d56efa586d2 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -9,6 +9,7 @@ #include "nsNetUtil.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/Atomics.h" #include "mozilla/Encoding.h" #include "mozilla/LoadContext.h" diff --git a/netwerk/cookie/CookieServiceChild.cpp b/netwerk/cookie/CookieServiceChild.cpp index 229a726fb19b..453e156a66c9 100644 --- a/netwerk/cookie/CookieServiceChild.cpp +++ b/netwerk/cookie/CookieServiceChild.cpp @@ -5,6 +5,7 @@ #include "mozilla/net/CookieServiceChild.h" #include "mozilla/net/NeckoChannelParams.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/LoadInfo.h" #include "mozilla/BasePrincipal.h" #include "mozilla/ClearOnShutdown.h" diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index 76afa4becdd7..7151fa929c67 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -4,9 +4,9 @@ * 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/. */ +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/Attributes.h" #include "mozilla/ClearOnShutdown.h" -#include "mozilla/ContentBlockingNotifier.h" #include "mozilla/DebugOnly.h" #include "mozilla/Likely.h" #include "mozilla/Printf.h" @@ -2265,8 +2265,8 @@ void nsCookieService::SetCookieStringInternal( } void nsCookieService::NotifyAccepted(nsIChannel* aChannel) { - ContentBlockingNotifier::OnDecision( - aChannel, ContentBlockingNotifier::BlockingDecision::eAllow, 0); + AntiTrackingCommon::NotifyBlockingDecision( + aChannel, AntiTrackingCommon::BlockingDecision::eAllow, 0); } // notify observers that a cookie was rejected due to the users' prefs. @@ -2282,9 +2282,8 @@ void nsCookieService::NotifyRejected(nsIURI* aHostURI, nsIChannel* aChannel, MOZ_ASSERT(aOperation == OPERATION_READ); } - ContentBlockingNotifier::OnDecision( - aChannel, ContentBlockingNotifier::BlockingDecision::eBlock, - aRejectedReason); + AntiTrackingCommon::NotifyBlockingDecision( + aChannel, AntiTrackingCommon::BlockingDecision::eBlock, aRejectedReason); } // notify observers that the cookie list changed. there are five possible diff --git a/netwerk/ipc/DocumentLoadListener.cpp b/netwerk/ipc/DocumentLoadListener.cpp index 8144f04383d6..532d3655463f 100644 --- a/netwerk/ipc/DocumentLoadListener.cpp +++ b/netwerk/ipc/DocumentLoadListener.cpp @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "DocumentLoadListener.h" -#include "mozilla/AntiTrackingUtils.h" #include "mozilla/ContentBlockingAllowList.h" #include "mozilla/DebugOnly.h" #include "mozilla/LoadInfo.h" @@ -382,7 +381,7 @@ bool DocumentLoadListener::Open( } nsCOMPtr uriBeingLoaded = - AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(mChannel); + AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded(mChannel); CanonicalBrowsingContext* bc = GetBrowsingContext(); RefPtr topWindow = GetTopWindowExcludingExtensionAccessibleContentFrames(bc, uriBeingLoaded); diff --git a/netwerk/protocol/http/ClassifierDummyChannel.cpp b/netwerk/protocol/http/ClassifierDummyChannel.cpp index 174af843ce8a..34e58110bf5e 100644 --- a/netwerk/protocol/http/ClassifierDummyChannel.cpp +++ b/netwerk/protocol/http/ClassifierDummyChannel.cpp @@ -7,7 +7,7 @@ #include "ClassifierDummyChannel.h" -#include "mozilla/ContentBlocking.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/ClassifierDummyChannelChild.h" #include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/dom/ContentChild.h" @@ -60,7 +60,8 @@ ClassifierDummyChannel::StorageAllowed( return eAsyncNeeded; } - if (ContentBlocking::ShouldAllowAccessFor(httpChannel, uri, nullptr)) { + if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel, uri, + nullptr)) { return eStorageGranted; } diff --git a/netwerk/protocol/http/ClassifierDummyChannelChild.cpp b/netwerk/protocol/http/ClassifierDummyChannelChild.cpp index 34fde15a4522..29780377fab3 100644 --- a/netwerk/protocol/http/ClassifierDummyChannelChild.cpp +++ b/netwerk/protocol/http/ClassifierDummyChannelChild.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ClassifierDummyChannelChild.h" -#include "mozilla/ContentBlocking.h" #include "mozilla/ipc/BackgroundUtils.h" #include "mozilla/ipc/URIUtils.h" #include "nsIURI.h" @@ -86,8 +85,8 @@ mozilla::ipc::IPCResult ClassifierDummyChannelChild::Recv__delete__( RefPtr httpChannel = do_QueryObject(channel); httpChannel->AddClassificationFlags(aClassificationFlags, mIsThirdParty); - bool storageGranted = - ContentBlocking::ShouldAllowAccessFor(httpChannel, mURI, nullptr); + bool storageGranted = AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + httpChannel, mURI, nullptr); mCallback(storageGranted); return IPC_OK(); } diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp index 214b26b80f74..9fb6f6fb80ee 100644 --- a/netwerk/protocol/http/HttpBaseChannel.cpp +++ b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -15,7 +15,7 @@ #include "HttpLog.h" #include "LoadInfo.h" #include "mozIThirdPartyUtil.h" -#include "mozilla/AntiTrackingUtils.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" #include "mozilla/BinarySearch.h" #include "mozilla/ConsoleReportCollector.h" @@ -2014,7 +2014,7 @@ HttpBaseChannel::SetTopWindowURIIfUnknown(nsIURI* aTopWindowURI) { NS_IMETHODIMP HttpBaseChannel::GetTopWindowURI(nsIURI** aTopWindowURI) { nsCOMPtr uriBeingLoaded = - AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(this); + AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded(this); return GetTopWindowURI(uriBeingLoaded, aTopWindowURI); } diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 0851de69b573..d44884306cee 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -10,6 +10,7 @@ #include "nsHttp.h" #include "nsICacheEntry.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" #include "mozilla/Unused.h" #include "mozilla/dom/ContentChild.h" diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index ab1a3a90793e..367f5c464536 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -55,9 +55,9 @@ #include "nsThreadUtils.h" #include "GeckoProfiler.h" #include "nsIConsoleService.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/Attributes.h" #include "mozilla/BasePrincipal.h" -#include "mozilla/ContentBlocking.h" #include "mozilla/DebugOnly.h" #include "mozilla/Preferences.h" #include "mozilla/Services.h" @@ -4025,7 +4025,8 @@ bool nsHttpChannel::IsIsolated() { } mIsIsolated = StaticPrefs::browser_cache_cache_isolation() || (IsThirdPartyTrackingResource() && - !ContentBlocking::ShouldAllowAccessFor(this, mURI, nullptr)); + !AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + this, mURI, nullptr)); mHasBeenIsolatedChecked = true; return mIsIsolated; } diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index eddcfcd1e72b..f36e0f00a29f 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -63,7 +63,7 @@ #include "mozilla/ipc/URIUtils.h" #include "mozilla/Telemetry.h" #include "mozilla/Unused.h" -#include "mozilla/AntiTrackingRedirectHeuristic.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" #include "mozilla/LazyIdleThread.h" #include "mozilla/SyncRunnable.h" @@ -838,7 +838,7 @@ nsresult nsHttpHandler::AsyncOnChannelRedirect( newChan->GetURI(getter_AddRefs(newURI)); MOZ_ASSERT(newURI); - AntiTrackingRedirectHeuristic(oldChan, oldURI, newChan, newURI); + AntiTrackingCommon::RedirectHeuristic(oldChan, oldURI, newChan, newURI); // TODO E10S This helper has to be initialized on the other process RefPtr redirectCallbackHelper = diff --git a/netwerk/url-classifier/UrlClassifierCommon.cpp b/netwerk/url-classifier/UrlClassifierCommon.cpp index 88f578652351..17d8c3e11f61 100644 --- a/netwerk/url-classifier/UrlClassifierCommon.cpp +++ b/netwerk/url-classifier/UrlClassifierCommon.cpp @@ -7,10 +7,9 @@ #include "mozilla/net/UrlClassifierCommon.h" #include "ClassifierDummyChannel.h" -#include "mozilla/AntiTrackingUtils.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/BasePrincipal.h" #include "mozilla/ContentBlockingAllowList.h" -#include "mozilla/ContentBlockingNotifier.h" #include "mozilla/dom/WindowGlobalParent.h" #include "mozilla/net/HttpBaseChannel.h" #include "mozilla/net/UrlClassifierFeatureFactory.h" @@ -212,7 +211,7 @@ nsresult UrlClassifierCommon::SetBlockedContent(nsIChannel* channel, if (!state) { state = nsIWebProgressListener::STATE_BLOCKED_UNSAFE_CONTENT; } - ContentBlockingNotifier::OnEvent(channel, state); + AntiTrackingCommon::NotifyContentBlockingEvent(channel, state); return NS_OK; } @@ -228,7 +227,7 @@ nsresult UrlClassifierCommon::SetBlockedContent(nsIChannel* channel, } nsCOMPtr uriBeingLoaded = - AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(channel); + AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded(channel); nsCOMPtr win; rv = thirdPartyUtil->GetTopWindowForChannel(channel, uriBeingLoaded, getter_AddRefs(win)); @@ -444,7 +443,7 @@ void UrlClassifierCommon::AnnotateChannel(nsIChannel* aChannel, IsCryptominingClassificationFlag(aClassificationFlags); if (validClassificationFlags && isThirdPartyWithTopLevelWinURI) { - ContentBlockingNotifier::OnEvent(aChannel, aLoadingState); + AntiTrackingCommon::NotifyContentBlockingEvent(aChannel, aLoadingState); } if (isThirdPartyWithTopLevelWinURI && diff --git a/netwerk/url-classifier/UrlClassifierCommon.h b/netwerk/url-classifier/UrlClassifierCommon.h index 59e7bdfcf7fb..2018b2331ba8 100644 --- a/netwerk/url-classifier/UrlClassifierCommon.h +++ b/netwerk/url-classifier/UrlClassifierCommon.h @@ -7,8 +7,8 @@ #ifndef mozilla_net_UrlClassifierCommon_h #define mozilla_net_UrlClassifierCommon_h -#include "mozilla/Logging.h" #include "nsString.h" +#include "mozilla/AntiTrackingCommon.h" #include diff --git a/netwerk/url-classifier/UrlClassifierFeatureBase.h b/netwerk/url-classifier/UrlClassifierFeatureBase.h index eee1837ca782..6262904d58a0 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureBase.h +++ b/netwerk/url-classifier/UrlClassifierFeatureBase.h @@ -11,6 +11,7 @@ #include "nsIUrlClassifierSkipListService.h" #include "nsTArray.h" #include "nsString.h" +#include "mozilla/AntiTrackingCommon.h" namespace mozilla { namespace net { diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp index 21d2e8e76824..3d086c96898a 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureCryptominingAnnotation.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureCryptominingAnnotation.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "nsIClassifiedChannel.h" #include "nsContentUtils.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp index cfd06c61a574..1250e7f85adf 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureCryptominingProtection.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureCryptominingProtection.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/StaticPrefs_privacy.h" #include "nsContentUtils.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp index c532f21fd682..9cc870a32d0e 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingAnnotation.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureFingerprintingAnnotation.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "nsIClassifiedChannel.h" #include "nsContentUtils.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp index e150567f5579..6e6b83e505d9 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureFingerprintingProtection.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureFingerprintingProtection.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/StaticPrefs_privacy.h" #include "nsContentUtils.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp index 791876d1badc..1a2a3bce5346 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingAnnotation.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureSocialTrackingAnnotation.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "nsIClassifiedChannel.h" #include "nsContentUtils.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp index a7552cbb56e0..f85fe5458c1c 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureSocialTrackingProtection.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureSocialTrackingProtection.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "mozilla/StaticPrefs_privacy.h" #include "nsContentUtils.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp index bae124a67e1d..e6e564b42e19 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp @@ -7,6 +7,7 @@ #include "UrlClassifierFeatureTrackingAnnotation.h" #include "Classifier.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/Logging.h" #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StaticPtr.h" diff --git a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp index 4e19b8ab9a42..af9e1177957e 100644 --- a/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp +++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingProtection.cpp @@ -6,6 +6,7 @@ #include "UrlClassifierFeatureTrackingProtection.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/net/UrlClassifierCommon.h" #include "nsContentUtils.h" #include "nsIHttpChannelInternal.h" diff --git a/toolkit/components/antitracking/ContentBlocking.cpp b/toolkit/components/antitracking/AntiTrackingCommon.cpp similarity index 51% rename from toolkit/components/antitracking/ContentBlocking.cpp rename to toolkit/components/antitracking/AntiTrackingCommon.cpp index 86ec9682d62a..a65cd4358ce7 100644 --- a/toolkit/components/antitracking/ContentBlocking.cpp +++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp @@ -5,14 +5,23 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "AntiTrackingLog.h" -#include "ContentBlocking.h" -#include "AntiTrackingUtils.h" -#include "TemporaryAccessGrantObserver.h" +#include "AntiTrackingCommon.h" #include "mozilla/ContentBlockingAllowList.h" -#include "mozilla/ContentBlockingUserInteraction.h" #include "mozilla/dom/BrowsingContext.h" +#include "mozilla/dom/CanonicalBrowsingContext.h" #include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/WindowGlobalParent.h" +#include "mozilla/net/UrlClassifierCommon.h" +#include "mozilla/ipc/MessageChannel.h" +#include "mozilla/AbstractThread.h" +#include "mozilla/HashFunctions.h" +#include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/Logging.h" +#include "mozilla/MruCache.h" +#include "mozilla/Pair.h" +#include "mozilla/ScopeExit.h" +#include "mozilla/StaticPrefs_extensions.h" #include "mozilla/StaticPrefs_privacy.h" #include "mozIThirdPartyUtil.h" #include "nsContentUtils.h" @@ -20,12 +29,26 @@ #include "nsIClassifiedChannel.h" #include "nsICookiePermission.h" #include "nsICookieService.h" +#include "nsIDocShell.h" +#include "nsIHttpChannelInternal.h" +#include "nsIParentChannel.h" #include "nsIPermission.h" -#include "nsIPrincipal.h" -#include "nsIURI.h" -#include "nsIWebProgressListener.h" #include "nsPermissionManager.h" +#include "nsIPrincipal.h" +#include "nsIRedirectHistoryEntry.h" +#include "nsIScriptError.h" +#include "nsIURI.h" +#include "nsIURIFixup.h" +#include "nsIWebProgressListener.h" +#include "nsNetUtil.h" +#include "nsPIDOMWindow.h" +#include "nsPrintfCString.h" #include "nsScriptSecurityManager.h" +#include "nsSandboxFlags.h" +#include "prtime.h" + +#define ANTITRACKING_PERM_KEY "3rdPartyStorage" +#define ANTITRACKING_CONSOLE_CATEGORY NS_LITERAL_CSTRING("Content Blocking") namespace mozilla { @@ -38,6 +61,8 @@ using mozilla::dom::BrowsingContext; using mozilla::dom::ContentChild; using mozilla::dom::Document; +static const uint32_t kMaxConsoleOutputDelayMs = 100; + namespace { bool GetParentPrincipalAndTrackingOrigin( @@ -75,6 +100,18 @@ bool GetParentPrincipalAndTrackingOrigin( return true; }; +void CreatePermissionKey(const nsCString& aTrackingOrigin, + nsACString& aPermissionKey) { + MOZ_ASSERT(aPermissionKey.IsEmpty()); + + static const nsLiteralCString prefix = + NS_LITERAL_CSTRING(ANTITRACKING_PERM_KEY "^"); + + aPermissionKey.SetCapacity(prefix.Length() + aTrackingOrigin.Length()); + aPermissionKey.Append(prefix); + aPermissionKey.Append(aTrackingOrigin); +} + // This internal method returns ACCESS_DENY if the access is denied, // ACCESS_DEFAULT if unknown, some other access code if granted. uint32_t CheckCookiePermissionForPrincipal( @@ -143,6 +180,360 @@ int32_t CookiesBehavior(nsIPrincipal* aPrincipal, return aCookieJarSettings->GetCookieBehavior(); } +void RunConsoleReportingRunnable(already_AddRefed&& aRunnable) { + if (StaticPrefs::privacy_restrict3rdpartystorage_console_lazy()) { + nsresult rv = NS_DispatchToCurrentThreadQueue(std::move(aRunnable), + kMaxConsoleOutputDelayMs, + EventQueuePriority::Idle); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } + } else { + nsCOMPtr runnable(std::move(aRunnable)); + nsresult rv = runnable->Run(); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } + } +} + +void ReportBlockingToConsole(uint64_t aWindowID, nsIURI* aURI, + uint32_t aRejectedReason) { + MOZ_ASSERT(aWindowID); + MOZ_ASSERT(aURI); + MOZ_ASSERT( + aRejectedReason == 0 || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || + aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || + aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); + + nsAutoString sourceLine; + uint32_t lineNumber = 0, columnNumber = 0; + JSContext* cx = nsContentUtils::GetCurrentJSContext(); + if (cx) { + nsJSUtils::GetCallingLocation(cx, sourceLine, &lineNumber, &columnNumber); + } + + nsCOMPtr uri(aURI); + + RefPtr runnable = NS_NewRunnableFunction( + "ReportBlockingToConsoleDelayed", [aWindowID, sourceLine, lineNumber, + columnNumber, uri, aRejectedReason]() { + const char* message = nullptr; + nsAutoCString category; + // When changing this list, please make sure to update the corresponding + // code in antitracking_head.js (inside _createTask). + switch (aRejectedReason) { + case nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION: + message = "CookieBlockedByPermission"; + category = NS_LITERAL_CSTRING("cookieBlockedPermission"); + break; + + case nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER: + message = "CookieBlockedTracker"; + category = NS_LITERAL_CSTRING("cookieBlockedTracker"); + break; + + case nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL: + message = "CookieBlockedAll"; + category = NS_LITERAL_CSTRING("cookieBlockedAll"); + break; + + case nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN: + message = "CookieBlockedForeign"; + category = NS_LITERAL_CSTRING("cookieBlockedForeign"); + break; + + default: + return; + } + + MOZ_ASSERT(message); + + // Strip the URL of any possible username/password and make it ready + // to be presented in the UI. + nsCOMPtr urifixup = services::GetURIFixup(); + NS_ENSURE_TRUE_VOID(urifixup); + nsCOMPtr exposableURI; + nsresult rv = + urifixup->CreateExposableURI(uri, getter_AddRefs(exposableURI)); + NS_ENSURE_SUCCESS_VOID(rv); + + AutoTArray params; + CopyUTF8toUTF16(exposableURI->GetSpecOrDefault(), + *params.AppendElement()); + + nsAutoString errorText; + rv = nsContentUtils::FormatLocalizedString( + nsContentUtils::eNECKO_PROPERTIES, message, params, errorText); + NS_ENSURE_SUCCESS_VOID(rv); + + nsContentUtils::ReportToConsoleByWindowID( + errorText, nsIScriptError::warningFlag, category, aWindowID, + nullptr, sourceLine, lineNumber, columnNumber); + }); + + RunConsoleReportingRunnable(runnable.forget()); +} + +void ReportBlockingToConsole(nsIChannel* aChannel, nsIURI* aURI, + uint32_t aRejectedReason) { + MOZ_ASSERT(aChannel && aURI); + + uint64_t windowID; + + if (XRE_IsParentProcess()) { + // Get the top-level window ID from the top-level BrowsingContext + nsCOMPtr loadInfo = aChannel->LoadInfo(); + RefPtr bc; + loadInfo->GetBrowsingContext(getter_AddRefs(bc)); + + if (!bc || bc->IsDiscarded()) { + return; + } + + bc = bc->Top(); + RefPtr wgp = + bc->Canonical()->GetCurrentWindowGlobal(); + if (!wgp) { + return; + } + + windowID = wgp->InnerWindowId(); + } else { + nsresult rv; + nsCOMPtr httpChannel = do_QueryInterface(aChannel, &rv); + + if (!httpChannel) { + return; + } + + rv = httpChannel->GetTopLevelContentWindowId(&windowID); + if (NS_FAILED(rv) || !windowID) { + windowID = nsContentUtils::GetInnerWindowID(httpChannel); + } + } + + ReportBlockingToConsole(windowID, aURI, aRejectedReason); +} + +void ReportUnblockingToConsole( + nsPIDOMWindowInner* aWindow, const nsAString& aTrackingOrigin, + AntiTrackingCommon::StorageAccessGrantedReason aReason) { + nsCOMPtr principal = + nsGlobalWindowInner::Cast(aWindow)->GetPrincipal(); + if (NS_WARN_IF(!principal)) { + return; + } + + RefPtr doc = aWindow->GetExtantDoc(); + if (NS_WARN_IF(!doc)) { + return; + } + + nsAutoString trackingOrigin(aTrackingOrigin); + + nsAutoString sourceLine; + uint32_t lineNumber = 0, columnNumber = 0; + JSContext* cx = nsContentUtils::GetCurrentJSContext(); + if (cx) { + nsJSUtils::GetCallingLocation(cx, sourceLine, &lineNumber, &columnNumber); + } + + RefPtr runnable = NS_NewRunnableFunction( + "ReportUnblockingToConsoleDelayed", + [doc, principal, trackingOrigin, sourceLine, lineNumber, columnNumber, + aReason]() { + nsAutoString origin; + nsresult rv = nsContentUtils::GetUTFOrigin(principal, origin); + if (NS_WARN_IF(NS_FAILED(rv))) { + return; + } + + // Not adding grantedOrigin yet because we may not want it later. + AutoTArray params = {origin, trackingOrigin}; + const char* messageWithSameOrigin = nullptr; + + switch (aReason) { + case AntiTrackingCommon::eStorageAccessAPI: + messageWithSameOrigin = "CookieAllowedForTrackerByStorageAccessAPI"; + break; + + case AntiTrackingCommon::eOpenerAfterUserInteraction: + [[fallthrough]]; + case AntiTrackingCommon::eOpener: + messageWithSameOrigin = "CookieAllowedForTrackerByHeuristic"; + break; + } + + nsContentUtils::ReportToConsole( + nsIScriptError::warningFlag, ANTITRACKING_CONSOLE_CATEGORY, doc, + nsContentUtils::eNECKO_PROPERTIES, messageWithSameOrigin, params, + nullptr, sourceLine, lineNumber, columnNumber); + }); + + RunConsoleReportingRunnable(runnable.forget()); +} + +already_AddRefed GetTopWindow(nsPIDOMWindowInner* aWindow) { + Document* document = aWindow->GetExtantDoc(); + if (!document) { + return nullptr; + } + + nsIChannel* channel = document->GetChannel(); + if (!channel) { + return nullptr; + } + + nsCOMPtr pwin = + aWindow->GetBrowsingContext()->Top()->GetDOMWindow(); + + if (!pwin) { + return nullptr; + } + + return pwin.forget(); +} + +class TemporaryAccessGrantCacheKey : public PLDHashEntryHdr { + public: + typedef Pair, nsCString> KeyType; + typedef const KeyType* KeyTypePointer; + + explicit TemporaryAccessGrantCacheKey(KeyTypePointer aKey) + : mPrincipal(aKey->first()), mType(aKey->second()) {} + TemporaryAccessGrantCacheKey(TemporaryAccessGrantCacheKey&& aOther) = default; + + ~TemporaryAccessGrantCacheKey() = default; + + KeyType GetKey() const { return MakePair(mPrincipal, mType); } + bool KeyEquals(KeyTypePointer aKey) const { + return !!mPrincipal == !!aKey->first() && mType == aKey->second() && + (mPrincipal ? (mPrincipal->Equals(aKey->first())) : true); + } + + static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; } + static PLDHashNumber HashKey(KeyTypePointer aKey) { + if (!aKey) { + return 0; + } + + BasePrincipal* bp = BasePrincipal::Cast(aKey->first()); + return HashGeneric(bp->GetOriginNoSuffixHash(), bp->GetOriginSuffixHash(), + HashString(aKey->second())); + } + + enum { ALLOW_MEMMOVE = true }; + + private: + nsCOMPtr mPrincipal; + nsCString mType; +}; + +class TemporaryAccessGrantObserver final : public nsIObserver { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + + static void Create(nsPermissionManager* aPM, nsIPrincipal* aPrincipal, + const nsACString& aType) { + MOZ_ASSERT(XRE_IsParentProcess()); + + if (!sObservers) { + sObservers = MakeUnique(); + } + Unused << sObservers + ->LookupForAdd(MakePair(nsCOMPtr(aPrincipal), + nsCString(aType))) + .OrInsert([&]() -> nsITimer* { + // Only create a new observer if we don't have a matching + // entry in our hashtable. + nsCOMPtr timer; + RefPtr observer = + new TemporaryAccessGrantObserver(aPM, aPrincipal, + aType); + nsresult rv = NS_NewTimerWithObserver( + getter_AddRefs(timer), observer, + 24 * 60 * 60 * 1000, // 24 hours + nsITimer::TYPE_ONE_SHOT); + + if (NS_SUCCEEDED(rv)) { + observer->SetTimer(timer); + return timer; + } + timer->Cancel(); + return nullptr; + }); + } + + void SetTimer(nsITimer* aTimer) { + mTimer = aTimer; + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (observerService) { + observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); + } + } + + private: + TemporaryAccessGrantObserver(nsPermissionManager* aPM, + nsIPrincipal* aPrincipal, + const nsACString& aType) + : mPM(aPM), mPrincipal(aPrincipal), mType(aType) { + MOZ_ASSERT(XRE_IsParentProcess(), + "Enforcing temporary access grant lifetimes can only be done in " + "the parent process"); + } + + ~TemporaryAccessGrantObserver() = default; + + private: + typedef nsDataHashtable> + ObserversTable; + static UniquePtr sObservers; + nsCOMPtr mTimer; + RefPtr mPM; + nsCOMPtr mPrincipal; + nsCString mType; +}; + +UniquePtr + TemporaryAccessGrantObserver::sObservers; + +NS_IMPL_ISUPPORTS(TemporaryAccessGrantObserver, nsIObserver) + +NS_IMETHODIMP +TemporaryAccessGrantObserver::Observe(nsISupports* aSubject, const char* aTopic, + const char16_t* aData) { + if (strcmp(aTopic, NS_TIMER_CALLBACK_TOPIC) == 0) { + Unused << mPM->RemoveFromPrincipal(mPrincipal, mType); + + MOZ_ASSERT(sObservers); + sObservers->Remove(MakePair(mPrincipal, mType)); + } else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) { + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (observerService) { + observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); + } + if (mTimer) { + mTimer->Cancel(); + mTimer = nullptr; + } + sObservers.reset(); + } + + return NS_OK; +} + bool CheckAntiTrackingPermission(nsIPrincipal* aPrincipal, const nsAutoCString& aType, bool aIsInPrivateBrowsing, @@ -245,17 +636,175 @@ bool CheckAntiTrackingPermission(nsIPrincipal* aPrincipal, return true; } +// This API finishes the remaining work left in NotifyBlockingDecisionInternal. +void NotifyAllowDecisionInternal(nsIChannel* aReportingChannel, + nsIChannel* aTrackingChannel, nsIURI* aURI, + nsPIDOMWindowOuter* aWindow) { + nsAutoCString trackingOrigin; + if (aURI) { + Unused << nsContentUtils::GetASCIIOrigin(aURI, trackingOrigin); + } + + // This can be called in either the parent process or the child processes. + + // Now send the generic "cookies loaded" notifications, from the most generic + // to the most specific. + AntiTrackingCommon::NotifyContentBlockingEvent( + aWindow, aReportingChannel, aTrackingChannel, false, + nsIWebProgressListener::STATE_COOKIES_LOADED, trackingOrigin); + + nsCOMPtr classifiedChannel = + do_QueryInterface(aTrackingChannel); + if (!classifiedChannel) { + return; + } + + uint32_t classificationFlags = + classifiedChannel->GetThirdPartyClassificationFlags(); + if (classificationFlags & + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING) { + AntiTrackingCommon::NotifyContentBlockingEvent( + aWindow, aReportingChannel, aTrackingChannel, false, + nsIWebProgressListener::STATE_COOKIES_LOADED_TRACKER, trackingOrigin); + } + + if (classificationFlags & + nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_SOCIALTRACKING) { + AntiTrackingCommon::NotifyContentBlockingEvent( + aWindow, aReportingChannel, aTrackingChannel, false, + nsIWebProgressListener::STATE_COOKIES_LOADED_SOCIALTRACKER, + trackingOrigin); + } +} + +void NotifyBlockingDecisionInternal( + nsIChannel* aReportingChannel, nsIChannel* aTrackingChannel, + AntiTrackingCommon::BlockingDecision aDecision, uint32_t aRejectedReason, + nsIURI* aURI, nsPIDOMWindowOuter* aWindow) { + MOZ_ASSERT(aWindow); + + // When this is called with system priviledged, the decision should always be + // ALLOW, and we can also stop processing this event. + if (nsGlobalWindowOuter::Cast(aWindow)->GetPrincipal() == + nsContentUtils::GetSystemPrincipal()) { + MOZ_DIAGNOSTIC_ASSERT(aDecision == + AntiTrackingCommon::BlockingDecision::eAllow); + return; + } + + nsAutoCString trackingOrigin; + if (aURI) { + Unused << nsContentUtils::GetASCIIOrigin(aURI, trackingOrigin); + } + + if (aDecision == AntiTrackingCommon::BlockingDecision::eBlock) { + AntiTrackingCommon::NotifyContentBlockingEvent( + aWindow, aReportingChannel, aTrackingChannel, true, aRejectedReason, + trackingOrigin); + + ReportBlockingToConsole(aReportingChannel, aURI, aRejectedReason); + } + + NotifyAllowDecisionInternal(aReportingChannel, aTrackingChannel, aURI, + aWindow); +} + +void NotifyBlockingDecisionInternal( + nsIChannel* aReportingChannel, nsIChannel* aTrackingChannel, + AntiTrackingCommon::BlockingDecision aDecision, uint32_t aRejectedReason, + nsIURI* aURI) { + // Can be called only in the parent process when there is no window. + MOZ_ASSERT(XRE_IsParentProcess()); + + nsAutoCString trackingOrigin; + if (aURI) { + Unused << nsContentUtils::GetASCIIOrigin(aURI, trackingOrigin); + } + + if (aDecision == AntiTrackingCommon::BlockingDecision::eBlock) { + AntiTrackingCommon::NotifyContentBlockingEvent( + nullptr, aReportingChannel, aTrackingChannel, true, aRejectedReason, + trackingOrigin); + + ReportBlockingToConsole(aReportingChannel, aURI, aRejectedReason); + } + + NotifyAllowDecisionInternal(aReportingChannel, aTrackingChannel, aURI, + nullptr); +} + +// Send a message to notify OnContentBlockingEvent in the parent, which will +// update the ContentBlockingLog in the parent. +void NotifyContentBlockingEventInChild( + nsPIDOMWindowOuter* aWindow, nsIChannel* aReportingChannel, + nsIChannel* aTrackingChannel, bool aBlocked, uint32_t aRejectedReason, + const nsACString& aTrackingOrigin, + const Maybe& aReason) { + MOZ_ASSERT(XRE_IsContentProcess()); + MOZ_ASSERT(aWindow); + + RefPtr browserChild = dom::BrowserChild::GetFrom(aWindow); + NS_ENSURE_TRUE_VOID(browserChild); + + nsTArray trackingFullHashes; + nsCOMPtr classifiedChannel = + do_QueryInterface(aTrackingChannel); + + if (classifiedChannel) { + Unused << classifiedChannel->GetMatchedTrackingFullHashes( + trackingFullHashes); + } + + browserChild->NotifyContentBlockingEvent(aRejectedReason, aReportingChannel, + aBlocked, aTrackingOrigin, + trackingFullHashes, aReason); +} + +// Update the ContentBlockingLog of the top-level WindowGlobalParent of +// the reporting channel. +void NotifyContentBlockingEventInParent( + nsIChannel* aReportingChannel, nsIChannel* aTrackingChannel, bool aBlocked, + uint32_t aRejectedReason, const nsACString& aTrackingOrigin, + const Maybe& aReason) { + MOZ_ASSERT(XRE_IsParentProcess()); + + nsCOMPtr loadInfo = aReportingChannel->LoadInfo(); + RefPtr bc; + loadInfo->GetBrowsingContext(getter_AddRefs(bc)); + + if (!bc || bc->IsDiscarded()) { + return; + } + + bc = bc->Top(); + RefPtr wgp = + bc->Canonical()->GetCurrentWindowGlobal(); + NS_ENSURE_TRUE_VOID(wgp); + + nsTArray trackingFullHashes; + nsCOMPtr classifiedChannel = + do_QueryInterface(aTrackingChannel); + + if (classifiedChannel) { + Unused << classifiedChannel->GetMatchedTrackingFullHashes( + trackingFullHashes); + } + + wgp->NotifyContentBlockingEvent(aRejectedReason, aReportingChannel, aBlocked, + aTrackingOrigin, trackingFullHashes, aReason); +} + } // namespace -/* static */ RefPtr -ContentBlocking::AllowAccessFor( +/* static */ RefPtr +AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor( nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aParentWindow, - ContentBlockingNotifier::StorageAccessGrantedReason aReason, - const ContentBlocking::PerformFinalChecks& aPerformFinalChecks) { + StorageAccessGrantedReason aReason, + const AntiTrackingCommon::PerformFinalChecks& aPerformFinalChecks) { MOZ_ASSERT(aParentWindow); switch (aReason) { - case ContentBlockingNotifier::eOpener: + case eOpener: if (!StaticPrefs:: privacy_restrict3rdpartystorage_heuristic_window_open()) { LOG( @@ -265,7 +814,7 @@ ContentBlocking::AllowAccessFor( return StorageAccessGrantPromise::CreateAndReject(false, __func__); } break; - case ContentBlockingNotifier::eOpenerAfterUserInteraction: + case eOpenerAfterUserInteraction: if (!StaticPrefs:: privacy_restrict3rdpartystorage_heuristic_opened_window_after_interaction()) { LOG( @@ -422,20 +971,17 @@ ContentBlocking::AllowAccessFor( "privacy.restrict3rdpartystorage." "userInteractionRequiredForHosts", &isInPrefList); - if (isInPrefList && - !ContentBlockingUserInteraction::Exists(trackingPrincipal)) { + if (isInPrefList && !HasUserInteraction(trackingPrincipal)) { LOG_PRIN(("Tracking principal (%s) hasn't been interacted with before, " "refusing to add a first-party storage permission to access it", _spec), trackingPrincipal); - ContentBlockingNotifier::OnDecision( - aParentWindow, ContentBlockingNotifier::BlockingDecision::eBlock, - blockReason); + NotifyBlockingDecision(aParentWindow, BlockingDecision::eBlock, + blockReason); return StorageAccessGrantPromise::CreateAndReject(false, __func__); } - nsCOMPtr pwin = - AntiTrackingUtils::GetTopWindow(parentWindow); + nsCOMPtr pwin = GetTopWindow(parentWindow); if (!pwin) { LOG(("Couldn't get the top window")); return StorageAccessGrantPromise::CreateAndReject(false, __func__); @@ -446,8 +992,7 @@ ContentBlocking::AllowAccessFor( topLevelStoragePrincipal, aReason](int aAllowMode) -> RefPtr { nsAutoCString permissionKey; - AntiTrackingUtils::CreateStoragePermissionKey(trackingOrigin, - permissionKey); + CreatePermissionKey(trackingOrigin, permissionKey); // Let's store the permission in the current parent window. topInnerWindow->SaveStorageAccessGranted(permissionKey); @@ -458,20 +1003,21 @@ ContentBlocking::AllowAccessFor( nsIChannel* channel = pwin->GetCurrentInnerWindow()->GetExtantDoc()->GetChannel(); - ContentBlockingNotifier::OnEvent( + NotifyContentBlockingEvent( pwin, channel, parentWindow->GetExtantDoc()->GetChannel(), false, blockReason, trackingOrigin, Some(aReason)); - ContentBlockingNotifier::ReportUnblockingToConsole( - parentWindow, NS_ConvertUTF8toUTF16(trackingOrigin), aReason); + ReportUnblockingToConsole(parentWindow, + NS_ConvertUTF8toUTF16(trackingOrigin), aReason); if (XRE_IsParentProcess()) { LOG(("Saving the permission: trackingOrigin=%s", trackingOrigin.get())); - return SaveAccessForOriginOnParentProcess(topLevelStoragePrincipal, - trackingPrincipal, - trackingOrigin, aAllowMode) + return SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess( + topLevelStoragePrincipal, trackingPrincipal, trackingOrigin, + aAllowMode) ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [](ParentAccessGrantPromise::ResolveOrRejectValue&& aValue) { + [](FirstPartyStorageAccessGrantPromise::ResolveOrRejectValue&& + aValue) { if (aValue.IsResolve()) { return StorageAccessGrantPromise::CreateAndResolve( eAllow, __func__); @@ -523,8 +1069,8 @@ ContentBlocking::AllowAccessFor( } /* static */ -RefPtr -ContentBlocking::SaveAccessForOriginOnParentProcess( +RefPtr +AntiTrackingCommon::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess( nsIPrincipal* aParentPrincipal, nsIPrincipal* aTrackingPrincipal, const nsCString& aTrackingOrigin, int aAllowMode, uint64_t aExpirationTime) { @@ -533,7 +1079,8 @@ ContentBlocking::SaveAccessForOriginOnParentProcess( if (!aParentPrincipal || !aTrackingPrincipal) { LOG(("Invalid input arguments passed")); - return ParentAccessGrantPromise::CreateAndReject(false, __func__); + return FirstPartyStorageAccessGrantPromise::CreateAndReject(false, + __func__); }; LOG_PRIN(("Saving a first-party storage permission on %s for " @@ -544,13 +1091,15 @@ ContentBlocking::SaveAccessForOriginOnParentProcess( if (NS_WARN_IF(!aParentPrincipal)) { // The child process is sending something wrong. Let's ignore it. LOG(("aParentPrincipal is null, bailing out early")); - return ParentAccessGrantPromise::CreateAndReject(false, __func__); + return FirstPartyStorageAccessGrantPromise::CreateAndReject(false, + __func__); } nsPermissionManager* permManager = nsPermissionManager::GetInstance(); if (NS_WARN_IF(!permManager)) { LOG(("Permission manager is null, bailing out early")); - return ParentAccessGrantPromise::CreateAndReject(false, __func__); + return FirstPartyStorageAccessGrantPromise::CreateAndReject(false, + __func__); } // Remember that this pref is stored in seconds! @@ -570,7 +1119,7 @@ ContentBlocking::SaveAccessForOriginOnParentProcess( } nsAutoCString type; - AntiTrackingUtils::CreateStoragePermissionKey(aTrackingOrigin, type); + CreatePermissionKey(aTrackingOrigin, type); LOG( ("Computed permission key: %s, expiry: %u, proceeding to save in the " @@ -588,12 +1137,59 @@ ContentBlocking::SaveAccessForOriginOnParentProcess( } LOG(("Result: %s", NS_SUCCEEDED(rv) ? "success" : "failure")); - return ParentAccessGrantPromise::CreateAndResolve(rv, __func__); + return FirstPartyStorageAccessGrantPromise::CreateAndResolve(rv, __func__); } -bool ContentBlocking::ShouldAllowAccessFor(nsPIDOMWindowInner* aWindow, - nsIURI* aURI, - uint32_t* aRejectedReason) { +// static +bool AntiTrackingCommon::CreateStoragePermissionKey(nsIPrincipal* aPrincipal, + nsACString& aKey) { + if (!aPrincipal) { + return false; + } + + nsAutoCString origin; + nsresult rv = aPrincipal->GetOriginNoSuffix(origin); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + + CreatePermissionKey(origin, aKey); + return true; +} + +// static +bool AntiTrackingCommon::IsStorageAccessPermission(nsIPermission* aPermission, + nsIPrincipal* aPrincipal) { + MOZ_ASSERT(aPermission); + MOZ_ASSERT(aPrincipal); + + // The permission key may belong either to a tracking origin on the same + // origin as the granted origin, or on another origin as the granted origin + // (for example when a tracker in a third-party context uses window.open to + // open another origin where that second origin would be the granted origin.) + // But even in the second case, the type of the permission would still be + // formed by concatenating the granted origin to the end of the type name + // (see CreatePermissionKey). Therefore, we pass in the same argument to + // both tracking origin and granted origin here in order to compute the + // shorter permission key and will then do a prefix match on the type of the + // input permission to see if it is a storage access permission or not. + nsAutoCString permissionKey; + bool result = CreateStoragePermissionKey(aPrincipal, permissionKey); + if (NS_WARN_IF(!result)) { + return false; + } + + nsAutoCString type; + nsresult rv = aPermission->GetType(type); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + + return StringBeginsWith(type, permissionKey); +} + +bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + nsPIDOMWindowInner* aWindow, nsIURI* aURI, uint32_t* aRejectedReason) { MOZ_ASSERT(aWindow); MOZ_ASSERT(aURI); @@ -783,7 +1379,7 @@ bool ContentBlocking::ShouldAllowAccessFor(nsPIDOMWindowInner* aWindow, } nsAutoCString type; - AntiTrackingUtils::CreateStoragePermissionKey(trackingOrigin, type); + CreatePermissionKey(trackingOrigin, type); if (topInnerWindow->HasStorageAccessGranted(type)) { LOG(("Permission stored in the window. All good.")); @@ -795,8 +1391,8 @@ bool ContentBlocking::ShouldAllowAccessFor(nsPIDOMWindowInner* aWindow, aRejectedReason, blockedReason); } -bool ContentBlocking::ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, - uint32_t* aRejectedReason) { +bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + nsIChannel* aChannel, nsIURI* aURI, uint32_t* aRejectedReason) { MOZ_ASSERT(aURI); MOZ_ASSERT(aChannel); @@ -1046,7 +1642,7 @@ bool ContentBlocking::ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, } nsAutoCString type; - AntiTrackingUtils::CreateStoragePermissionKey(trackingOrigin, type); + CreatePermissionKey(trackingOrigin, type); uint32_t privateBrowsingId = 0; rv = channelPrincipal->GetPrivateBrowsingId(&privateBrowsingId); @@ -1059,7 +1655,7 @@ bool ContentBlocking::ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, aRejectedReason, blockedReason); } -bool ContentBlocking::ShouldAllowAccessFor( +bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( nsIPrincipal* aPrincipal, nsICookieJarSettings* aCookieJarSettings) { MOZ_ASSERT(aPrincipal); MOZ_ASSERT(aCookieJarSettings); @@ -1082,7 +1678,7 @@ bool ContentBlocking::ShouldAllowAccessFor( } /* static */ -bool ContentBlocking::ApproximateAllowAccessForWithoutChannel( +bool AntiTrackingCommon::MaybeIsFirstPartyStorageAccessGrantedFor( nsPIDOMWindowInner* aFirstPartyWindow, nsIURI* aURI) { MOZ_ASSERT(aFirstPartyWindow); MOZ_ASSERT(aURI); @@ -1137,9 +1733,431 @@ bool ContentBlocking::ApproximateAllowAccessForWithoutChannel( nsIPrincipal* parentPrincipal = parentDocument->NodePrincipal(); nsAutoCString type; - AntiTrackingUtils::CreateStoragePermissionKey(origin, type); + CreatePermissionKey(origin, type); return CheckAntiTrackingPermission( parentPrincipal, type, nsContentUtils::IsInPrivateBrowsing(parentDocument), nullptr, 0); } + +/* static */ +void AntiTrackingCommon::NotifyBlockingDecision(nsIChannel* aChannel, + BlockingDecision aDecision, + uint32_t aRejectedReason) { + MOZ_ASSERT( + aRejectedReason == 0 || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || + aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || + aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); + MOZ_ASSERT(aDecision == BlockingDecision::eBlock || + aDecision == BlockingDecision::eAllow); + + if (!aChannel) { + return; + } + + nsCOMPtr uri; + aChannel->GetURI(getter_AddRefs(uri)); + + // Can be called in EITHER the parent or child process. + // Window is only needed while in child processes. + if (XRE_IsParentProcess()) { + NotifyBlockingDecisionInternal(aChannel, aChannel, aDecision, + aRejectedReason, uri); + return; + } + + MOZ_ASSERT(XRE_IsContentProcess()); + + nsCOMPtr thirdPartyUtil = services::GetThirdPartyUtil(); + if (!thirdPartyUtil) { + return; + } + + nsCOMPtr uriBeingLoaded = MaybeGetDocumentURIBeingLoaded(aChannel); + nsCOMPtr win; + nsresult rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, uriBeingLoaded, + getter_AddRefs(win)); + NS_ENSURE_SUCCESS_VOID(rv); + + nsCOMPtr pwin = nsPIDOMWindowOuter::From(win); + if (!pwin) { + return; + } + + NotifyBlockingDecisionInternal(aChannel, aChannel, aDecision, aRejectedReason, + uri, pwin); +} + +/* static */ +void AntiTrackingCommon::NotifyBlockingDecision(nsPIDOMWindowInner* aWindow, + BlockingDecision aDecision, + uint32_t aRejectedReason) { + MOZ_ASSERT(aWindow); + MOZ_ASSERT( + aRejectedReason == 0 || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || + aRejectedReason == + nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || + aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || + aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); + MOZ_ASSERT(aDecision == BlockingDecision::eBlock || + aDecision == BlockingDecision::eAllow); + + nsCOMPtr pwin = GetTopWindow(aWindow); + if (!pwin) { + return; + } + + nsPIDOMWindowInner* inner = pwin->GetCurrentInnerWindow(); + if (!inner) { + return; + } + Document* pwinDoc = inner->GetExtantDoc(); + if (!pwinDoc) { + return; + } + nsIChannel* channel = pwinDoc->GetChannel(); + if (!channel) { + return; + } + + Document* document = aWindow->GetExtantDoc(); + if (!document) { + return; + } + nsIURI* uri = document->GetDocumentURI(); + nsIChannel* trackingChannel = document->GetChannel(); + + NotifyBlockingDecisionInternal(channel, trackingChannel, aDecision, + aRejectedReason, uri, pwin); +} + +/* static */ +void AntiTrackingCommon::StoreUserInteractionFor(nsIPrincipal* aPrincipal) { + if (!aPrincipal) { + // The content process may have sent us garbage data. + return; + } + + if (XRE_IsParentProcess()) { + LOG_PRIN(("Saving the userInteraction for %s", _spec), aPrincipal); + + nsPermissionManager* permManager = nsPermissionManager::GetInstance(); + if (NS_WARN_IF(!permManager)) { + LOG(("Permission manager is null, bailing out early")); + return; + } + + // Remember that this pref is stored in seconds! + uint32_t expirationType = nsIPermissionManager::EXPIRE_TIME; + uint32_t expirationTime = + StaticPrefs::privacy_userInteraction_expiration() * 1000; + int64_t when = (PR_Now() / PR_USEC_PER_MSEC) + expirationTime; + + uint32_t privateBrowsingId = 0; + nsresult rv = aPrincipal->GetPrivateBrowsingId(&privateBrowsingId); + if (!NS_WARN_IF(NS_FAILED(rv)) && privateBrowsingId > 0) { + // If we are coming from a private window, make sure to store a + // session-only permission which won't get persisted to disk. + expirationType = nsIPermissionManager::EXPIRE_SESSION; + when = 0; + } + + rv = permManager->AddFromPrincipal(aPrincipal, USER_INTERACTION_PERM, + nsIPermissionManager::ALLOW_ACTION, + expirationType, when); + Unused << NS_WARN_IF(NS_FAILED(rv)); + return; + } + + ContentChild* cc = ContentChild::GetSingleton(); + MOZ_ASSERT(cc); + + LOG_PRIN(("Asking the parent process to save the user-interaction for us: %s", + _spec), + aPrincipal); + cc->SendStoreUserInteractionAsPermission(IPC::Principal(aPrincipal)); +} + +/* static */ +bool AntiTrackingCommon::HasUserInteraction(nsIPrincipal* aPrincipal) { + nsPermissionManager* permManager = nsPermissionManager::GetInstance(); + if (NS_WARN_IF(!permManager)) { + return false; + } + + uint32_t result = 0; + nsresult rv = permManager->TestPermissionWithoutDefaultsFromPrincipal( + aPrincipal, USER_INTERACTION_PERM, &result); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + + return result == nsIPermissionManager::ALLOW_ACTION; +} + +/* static */ +already_AddRefed AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded( + nsIChannel* aChannel) { + nsCOMPtr uriBeingLoaded; + nsLoadFlags loadFlags = 0; + nsresult rv = aChannel->GetLoadFlags(&loadFlags); + if (NS_WARN_IF(NS_FAILED(rv))) { + return nullptr; + } + if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) { + // If the channel being loaded is a document channel, this call may be + // coming from an OnStopRequest notification, which might mean that our + // document may still be in the loading process, so we may need to pass in + // the uriBeingLoaded argument explicitly. + rv = aChannel->GetURI(getter_AddRefs(uriBeingLoaded)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return nullptr; + } + } + return uriBeingLoaded.forget(); +} + +/* static */ +void AntiTrackingCommon::NotifyContentBlockingEvent(nsIChannel* aChannel, + uint32_t aRejectedReason) { + MOZ_ASSERT(XRE_IsParentProcess() && aChannel); + + nsCOMPtr uri; + aChannel->GetURI(getter_AddRefs(uri)); + + nsAutoCString trackingOrigin; + if (uri) { + Unused << nsContentUtils::GetASCIIOrigin(uri, trackingOrigin); + } + + return AntiTrackingCommon::NotifyContentBlockingEvent( + nullptr, aChannel, aChannel, true, aRejectedReason, trackingOrigin); +} + +/* static */ +void AntiTrackingCommon::NotifyContentBlockingEvent( + nsPIDOMWindowOuter* aWindow, nsIChannel* aReportingChannel, + nsIChannel* aTrackingChannel, bool aBlocked, uint32_t aRejectedReason, + const nsACString& aTrackingOrigin, + const Maybe& aReason) { + if (XRE_IsParentProcess()) { + NotifyContentBlockingEventInParent(aReportingChannel, aTrackingChannel, + aBlocked, aRejectedReason, + aTrackingOrigin, aReason); + } else { + NotifyContentBlockingEventInChild( + aWindow, aReportingChannel, aTrackingChannel, aBlocked, aRejectedReason, + aTrackingOrigin, aReason); + } +} + +/* static */ +void AntiTrackingCommon::RedirectHeuristic(nsIChannel* aOldChannel, + nsIURI* aOldURI, + nsIChannel* aNewChannel, + nsIURI* aNewURI) { + MOZ_ASSERT(aOldChannel); + MOZ_ASSERT(aOldURI); + MOZ_ASSERT(aNewChannel); + MOZ_ASSERT(aNewURI); + + nsresult rv; + + if (!StaticPrefs::privacy_restrict3rdpartystorage_heuristic_redirect()) { + return; + } + + nsCOMPtr newChannel = do_QueryInterface(aNewChannel); + if (!newChannel) { + return; + } + + LOG_SPEC(("Checking redirect-heuristic for %s", _spec), aOldURI); + + nsCOMPtr oldLoadInfo = aOldChannel->LoadInfo(); + MOZ_ASSERT(oldLoadInfo); + + nsCOMPtr newLoadInfo = aNewChannel->LoadInfo(); + MOZ_ASSERT(newLoadInfo); + + nsContentPolicyType contentType = oldLoadInfo->GetExternalContentPolicyType(); + if (contentType != nsIContentPolicy::TYPE_DOCUMENT || + !aOldChannel->IsDocument()) { + LOG_SPEC(("Ignoring redirect for %s because it's not a document", _spec), + aOldURI); + // We care about document redirects only. + return; + } + + nsCOMPtr classifiedOldChannel = + do_QueryInterface(aOldChannel); + nsCOMPtr classifiedNewChannel = + do_QueryInterface(aNewChannel); + if (!classifiedOldChannel || !classifiedNewChannel) { + LOG_SPEC2(("Ignoring redirect for %s to %s because there is not " + "nsIClassifiedChannel interface", + _spec1, _spec2), + aOldURI, aNewURI); + return; + } + + bool allowedByPreviousRedirect = + oldLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(); + + // We're looking at the first-party classification flags because we're + // interested in first-party redirects. + uint32_t newClassificationFlags = + classifiedNewChannel->GetFirstPartyClassificationFlags(); + + if (net::UrlClassifierCommon::IsTrackingClassificationFlag( + newClassificationFlags)) { + // This is not a tracking -> non-tracking redirect. + LOG_SPEC2(("Redirect for %s to %s because it's not tracking to " + "non-tracking. Part of a chain of granted redirects: %d", + _spec1, _spec2, allowedByPreviousRedirect), + aOldURI, aNewURI); + newLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( + allowedByPreviousRedirect); + return; + } + + uint32_t oldClassificationFlags = + classifiedOldChannel->GetFirstPartyClassificationFlags(); + + if (!net::UrlClassifierCommon::IsTrackingClassificationFlag( + oldClassificationFlags) && + !allowedByPreviousRedirect) { + // This is not a tracking -> non-tracking redirect. + LOG_SPEC2( + ("Redirect for %s to %s because it's not tracking to non-tracking.", + _spec1, _spec2), + aOldURI, aNewURI); + return; + } + + nsIScriptSecurityManager* ssm = + nsScriptSecurityManager::GetScriptSecurityManager(); + MOZ_ASSERT(ssm); + + nsCOMPtr trackingPrincipal; + + const nsTArray>& chain = + oldLoadInfo->RedirectChain(); + + if (allowedByPreviousRedirect && !chain.IsEmpty()) { + rv = chain[0]->GetPrincipal(getter_AddRefs(trackingPrincipal)); + if (NS_WARN_IF(NS_FAILED(rv))) { + LOG(("Can't obtain the principal from the redirect chain")); + return; + } + } else { + rv = ssm->GetChannelResultPrincipal(aOldChannel, + getter_AddRefs(trackingPrincipal)); + if (NS_WARN_IF(NS_FAILED(rv))) { + LOG(("Can't obtain the principal from the tracking")); + return; + } + } + + nsCOMPtr redirectedPrincipal; + rv = ssm->GetChannelResultPrincipal(aNewChannel, + getter_AddRefs(redirectedPrincipal)); + if (NS_WARN_IF(NS_FAILED(rv))) { + LOG(("Can't obtain the principal from the redirected")); + return; + } + + if (!AntiTrackingCommon::HasUserInteraction(trackingPrincipal)) { + LOG_SPEC2(("Ignoring redirect for %s to %s because no user-interaction on " + "tracker", + _spec1, _spec2), + aOldURI, aNewURI); + return; + } + + nsAutoCString trackingOrigin; + rv = trackingPrincipal->GetOrigin(trackingOrigin); + if (NS_WARN_IF(NS_FAILED(rv))) { + LOG(("Can't get the origin from the Principal")); + return; + } + + nsAutoCString redirectedOrigin; + rv = nsContentUtils::GetASCIIOrigin(aNewURI, redirectedOrigin); + if (NS_WARN_IF(NS_FAILED(rv))) { + LOG(("Can't get the origin from the URI")); + return; + } + + LOG(("Adding a first-party storage exception for %s...", + PromiseFlatCString(redirectedOrigin).get())); + + nsCOMPtr cookieJarSettings; + rv = oldLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)); + if (NS_WARN_IF(NS_FAILED(rv))) { + LOG(("Can't get the cookieJarSettings")); + return; + } + + int32_t behavior = cookieJarSettings->GetCookieBehavior(); + + if (!cookieJarSettings->GetRejectThirdPartyTrackers()) { + LOG( + ("Disabled by network.cookie.cookieBehavior pref (%d), bailing out " + "early", + behavior)); + return; + } + + MOZ_ASSERT( + behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || + behavior == + nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN); + + if (ContentBlockingAllowList::Check(newChannel)) { + return; + } + + LOG(("Saving the permission: trackingOrigin=%s, grantedOrigin=%s", + trackingOrigin.get(), redirectedOrigin.get())); + + // Any new redirect from this loadInfo must be considered as granted. + newLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain(true); + + uint64_t innerWindowID; + Unused << newChannel->GetTopLevelContentWindowId(&innerWindowID); + + nsAutoString errorText; + AutoTArray params = {NS_ConvertUTF8toUTF16(redirectedOrigin), + NS_ConvertUTF8toUTF16(trackingOrigin)}; + rv = nsContentUtils::FormatLocalizedString( + nsContentUtils::eNECKO_PROPERTIES, "CookieAllowedForTrackerByHeuristic", + params, errorText); + if (NS_SUCCEEDED(rv)) { + nsContentUtils::ReportToConsoleByWindowID( + errorText, nsIScriptError::warningFlag, ANTITRACKING_CONSOLE_CATEGORY, + innerWindowID); + } + + // We don't care about this promise because the operation is actually sync. + RefPtr promise = + SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess( + redirectedPrincipal, trackingPrincipal, trackingOrigin, + StorageAccessPromptChoices::eAllow, + StaticPrefs::privacy_restrict3rdpartystorage_expiration_redirect()); + Unused << promise; +} diff --git a/toolkit/components/antitracking/AntiTrackingCommon.h b/toolkit/components/antitracking/AntiTrackingCommon.h new file mode 100644 index 000000000000..dfb489b3f0ae --- /dev/null +++ b/toolkit/components/antitracking/AntiTrackingCommon.h @@ -0,0 +1,176 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef mozilla_antitrackingservice_h +#define mozilla_antitrackingservice_h + +#include "nsString.h" +#include "mozilla/MozPromise.h" +#include "mozilla/RefPtr.h" +#include "mozilla/StaticPrefs_privacy.h" + +#define USER_INTERACTION_PERM NS_LITERAL_CSTRING("storageAccessAPI") + +class nsIChannel; +class nsICookieJarSettings; +class nsIPermission; +class nsIPrincipal; +class nsIURI; +class nsPIDOMWindowInner; +class nsPIDOMWindowOuter; + +namespace mozilla { + +class OriginAttributes; + +class AntiTrackingCommon final { + public: + // Normally we would include PContentParent.h here and use the + // ipc::FirstPartyStorageAccessGrantedForOriginResolver type which maps to + // the same underlying type, but that results in Windows compilation errors, + // so we use the underlying type to avoid the #include here. + typedef std::function + FirstPartyStorageAccessGrantedForOriginResolver; + + // This method returns true if the URI has first party storage access when + // loaded inside the passed 3rd party context tracking resource window. + // If the window is first party context, please use + // MaybeIsFirstPartyStorageAccessGrantedFor(); + // + // aRejectedReason could be set to one of these values if passed and if the + // storage permission is not granted: + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN + static bool IsFirstPartyStorageAccessGrantedFor( + nsPIDOMWindowInner* a3rdPartyTrackingWindow, nsIURI* aURI, + uint32_t* aRejectedReason); + + // Note: you should use IsFirstPartyStorageAccessGrantedFor() passing the + // nsIChannel! Use this method _only_ if the channel is not available. + // For first party window, it's impossible to know if the aURI is a tracking + // resource synchronously, so here we return the best guest: if we are sure + // that the permission is granted for the origin of aURI, this method returns + // true, otherwise false. + static bool MaybeIsFirstPartyStorageAccessGrantedFor( + nsPIDOMWindowInner* aFirstPartyWindow, nsIURI* aURI); + + // It returns true if the URI has access to the first party storage. + // aChannel can be a 3rd party channel, or not. + // See IsFirstPartyStorageAccessGrantedFor(window) to see the possible values + // of aRejectedReason. + static bool IsFirstPartyStorageAccessGrantedFor(nsIChannel* aChannel, + nsIURI* aURI, + uint32_t* aRejectedReason); + + // This method checks if the principal has the permission to access to the + // first party storage. + static bool IsFirstPartyStorageAccessGrantedFor( + nsIPrincipal* aPrincipal, nsICookieJarSettings* aCookieJarSettings); + + enum StorageAccessGrantedReason { + eStorageAccessAPI, + eOpenerAfterUserInteraction, + eOpener + }; + enum StorageAccessPromptChoices { eAllow, eAllowAutoGrant }; + + // Grant the permission for aOrigin to have access to the first party storage. + // This method can handle 2 different scenarios: + // - aParentWindow is a 3rd party context, it opens an aOrigin window and the + // user interacts with it. We want to grant the permission at the + // combination: top-level + aParentWindow + aOrigin. + // Ex: example.net loads an iframe tracker.com, which opens a popup + // tracker.prg and the user interacts with it. tracker.org is allowed if + // loaded by tracker.com when loaded by example.net. + // - aParentWindow is a first party context and a 3rd party resource (probably + // becuase of a script) opens a popup and the user interacts with it. We + // want to grant the permission for the 3rd party context to have access to + // the first party stoage when loaded in aParentWindow. + // Ex: example.net import tracker.com/script.js which does opens a popup and + // the user interacts with it. tracker.com is allowed when loaded by + // example.net. + typedef MozPromise StorageAccessFinalCheckPromise; + typedef std::function()> + PerformFinalChecks; + typedef MozPromise StorageAccessGrantPromise; + static MOZ_MUST_USE RefPtr + AddFirstPartyStorageAccessGrantedFor( + nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aParentWindow, + StorageAccessGrantedReason aReason, + const PerformFinalChecks& aPerformFinalChecks = nullptr); + + // Given a principal, returns the storage permission key that will be used for + // the principal. Returns true on success. + static bool CreateStoragePermissionKey(nsIPrincipal* aPrincipal, + nsACString& aKey); + + // Returns true if the permission passed in is a storage access permission + // for the passed in principal argument. + static bool IsStorageAccessPermission(nsIPermission* aPermission, + nsIPrincipal* aPrincipal); + + static void StoreUserInteractionFor(nsIPrincipal* aPrincipal); + + static bool HasUserInteraction(nsIPrincipal* aPrincipal); + + // For IPC only. + typedef MozPromise FirstPartyStorageAccessGrantPromise; + static RefPtr + SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess( + nsIPrincipal* aPrincipal, nsIPrincipal* aTrackingPrinciapl, + const nsCString& aTrackingOrigin, int aAllowMode, + uint64_t aExpirationTime = + StaticPrefs::privacy_restrict3rdpartystorage_expiration()); + + enum class BlockingDecision { + eBlock, + eAllow, + }; + + // This method can be called on the parent process or on the content process. + // The notification is propagated to the child channel if aChannel is a parent + // channel proxy. + // + // aDecision can be eBlock if we have decided to block some content, or eAllow + // if we have decided to allow the content through. + // + // aRejectedReason must be one of these values: + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL + // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN + static void NotifyBlockingDecision(nsIChannel* aChannel, + BlockingDecision aDecision, + uint32_t aRejectedReason); + + static void NotifyBlockingDecision(nsPIDOMWindowInner* aWindow, + BlockingDecision aDecision, + uint32_t aRejectedReason); + + // Get the current document URI from a document channel as it is being loaded. + static already_AddRefed MaybeGetDocumentURIBeingLoaded( + nsIChannel* aChannel); + + static void NotifyContentBlockingEvent(nsIChannel* aChannel, + uint32_t aRejectedReason); + + static void NotifyContentBlockingEvent( + nsPIDOMWindowOuter* aWindow, nsIChannel* aReportingChannel, + nsIChannel* aTrackingChannel, bool aBlocked, uint32_t aRejectedReason, + const nsACString& aTrackingOrigin, + const Maybe& aReason = Nothing()); + + static void RedirectHeuristic(nsIChannel* aOldChannel, nsIURI* aOldURI, + nsIChannel* aNewChannel, nsIURI* aNewURI); +}; + +} // namespace mozilla + +#endif // mozilla_antitrackingservice_h diff --git a/toolkit/components/antitracking/AntiTrackingIPCUtils.h b/toolkit/components/antitracking/AntiTrackingIPCUtils.h index f7f5bf6b50d7..9faa13baad51 100644 --- a/toolkit/components/antitracking/AntiTrackingIPCUtils.h +++ b/toolkit/components/antitracking/AntiTrackingIPCUtils.h @@ -9,20 +9,19 @@ #include "ipc/IPCMessageUtils.h" -#include "mozilla/ContentBlockingNotifier.h" +#include "mozilla/AntiTrackingCommon.h" namespace IPC { -// For allowing passing the enum -// ContentBlockingNotifier::StorageAccessGrantedReason over IPC. +// For allowing passing the enum AntiTrackingCommon::StorageAccessGrantedReason +// over IPC. template <> -struct ParamTraits +struct ParamTraits : public ContiguousEnumSerializerInclusive< - mozilla::ContentBlockingNotifier::StorageAccessGrantedReason, - mozilla::ContentBlockingNotifier::StorageAccessGrantedReason:: + mozilla::AntiTrackingCommon::StorageAccessGrantedReason, + mozilla::AntiTrackingCommon::StorageAccessGrantedReason:: eStorageAccessAPI, - mozilla::ContentBlockingNotifier::StorageAccessGrantedReason:: - eOpener> {}; + mozilla::AntiTrackingCommon::StorageAccessGrantedReason::eOpener> {}; } // namespace IPC diff --git a/toolkit/components/antitracking/AntiTrackingRedirectHeuristic.cpp b/toolkit/components/antitracking/AntiTrackingRedirectHeuristic.cpp deleted file mode 100644 index 207362f1186e..000000000000 --- a/toolkit/components/antitracking/AntiTrackingRedirectHeuristic.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#include "AntiTrackingLog.h" -#include "AntiTrackingRedirectHeuristic.h" -#include "ContentBlocking.h" -#include "ContentBlockingAllowList.h" -#include "ContentBlockingUserInteraction.h" - -#include "mozilla/dom/BrowsingContext.h" -#include "mozilla/dom/Document.h" -#include "mozilla/net/UrlClassifierCommon.h" -#include "nsContentUtils.h" -#include "nsIChannel.h" -#include "nsIClassifiedChannel.h" -#include "nsICookieService.h" -#include "nsIRedirectHistoryEntry.h" -#include "nsIScriptError.h" -#include "nsIURI.h" -#include "nsPIDOMWindow.h" -#include "nsScriptSecurityManager.h" - -namespace mozilla { - -void AntiTrackingRedirectHeuristic(nsIChannel* aOldChannel, nsIURI* aOldURI, - nsIChannel* aNewChannel, nsIURI* aNewURI) { - MOZ_ASSERT(aOldChannel); - MOZ_ASSERT(aOldURI); - MOZ_ASSERT(aNewChannel); - MOZ_ASSERT(aNewURI); - - nsresult rv; - - if (!StaticPrefs::privacy_restrict3rdpartystorage_heuristic_redirect()) { - return; - } - - nsCOMPtr newChannel = do_QueryInterface(aNewChannel); - if (!newChannel) { - return; - } - - LOG_SPEC(("Checking redirect-heuristic for %s", _spec), aOldURI); - - nsCOMPtr oldLoadInfo = aOldChannel->LoadInfo(); - MOZ_ASSERT(oldLoadInfo); - - nsCOMPtr newLoadInfo = aNewChannel->LoadInfo(); - MOZ_ASSERT(newLoadInfo); - - nsContentPolicyType contentType = oldLoadInfo->GetExternalContentPolicyType(); - if (contentType != nsIContentPolicy::TYPE_DOCUMENT || - !aOldChannel->IsDocument()) { - LOG_SPEC(("Ignoring redirect for %s because it's not a document", _spec), - aOldURI); - // We care about document redirects only. - return; - } - - nsCOMPtr classifiedOldChannel = - do_QueryInterface(aOldChannel); - nsCOMPtr classifiedNewChannel = - do_QueryInterface(aNewChannel); - if (!classifiedOldChannel || !classifiedNewChannel) { - LOG_SPEC2(("Ignoring redirect for %s to %s because there is not " - "nsIClassifiedChannel interface", - _spec1, _spec2), - aOldURI, aNewURI); - return; - } - - bool allowedByPreviousRedirect = - oldLoadInfo->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(); - - // We're looking at the first-party classification flags because we're - // interested in first-party redirects. - uint32_t newClassificationFlags = - classifiedNewChannel->GetFirstPartyClassificationFlags(); - - if (net::UrlClassifierCommon::IsTrackingClassificationFlag( - newClassificationFlags)) { - // This is not a tracking -> non-tracking redirect. - LOG_SPEC2(("Redirect for %s to %s because it's not tracking to " - "non-tracking. Part of a chain of granted redirects: %d", - _spec1, _spec2, allowedByPreviousRedirect), - aOldURI, aNewURI); - newLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain( - allowedByPreviousRedirect); - return; - } - - uint32_t oldClassificationFlags = - classifiedOldChannel->GetFirstPartyClassificationFlags(); - - if (!net::UrlClassifierCommon::IsTrackingClassificationFlag( - oldClassificationFlags) && - !allowedByPreviousRedirect) { - // This is not a tracking -> non-tracking redirect. - LOG_SPEC2( - ("Redirect for %s to %s because it's not tracking to non-tracking.", - _spec1, _spec2), - aOldURI, aNewURI); - return; - } - - nsIScriptSecurityManager* ssm = - nsScriptSecurityManager::GetScriptSecurityManager(); - MOZ_ASSERT(ssm); - - nsCOMPtr trackingPrincipal; - - const nsTArray>& chain = - oldLoadInfo->RedirectChain(); - - if (allowedByPreviousRedirect && !chain.IsEmpty()) { - rv = chain[0]->GetPrincipal(getter_AddRefs(trackingPrincipal)); - if (NS_WARN_IF(NS_FAILED(rv))) { - LOG(("Can't obtain the principal from the redirect chain")); - return; - } - } else { - rv = ssm->GetChannelResultPrincipal(aOldChannel, - getter_AddRefs(trackingPrincipal)); - if (NS_WARN_IF(NS_FAILED(rv))) { - LOG(("Can't obtain the principal from the tracking")); - return; - } - } - - nsCOMPtr redirectedPrincipal; - rv = ssm->GetChannelResultPrincipal(aNewChannel, - getter_AddRefs(redirectedPrincipal)); - if (NS_WARN_IF(NS_FAILED(rv))) { - LOG(("Can't obtain the principal from the redirected")); - return; - } - - if (!ContentBlockingUserInteraction::Exists(trackingPrincipal)) { - LOG_SPEC2(("Ignoring redirect for %s to %s because no user-interaction on " - "tracker", - _spec1, _spec2), - aOldURI, aNewURI); - return; - } - - nsAutoCString trackingOrigin; - rv = trackingPrincipal->GetOrigin(trackingOrigin); - if (NS_WARN_IF(NS_FAILED(rv))) { - LOG(("Can't get the origin from the Principal")); - return; - } - - nsAutoCString redirectedOrigin; - rv = nsContentUtils::GetASCIIOrigin(aNewURI, redirectedOrigin); - if (NS_WARN_IF(NS_FAILED(rv))) { - LOG(("Can't get the origin from the URI")); - return; - } - - LOG(("Adding a first-party storage exception for %s...", - PromiseFlatCString(redirectedOrigin).get())); - - nsCOMPtr cookieJarSettings; - rv = oldLoadInfo->GetCookieJarSettings(getter_AddRefs(cookieJarSettings)); - if (NS_WARN_IF(NS_FAILED(rv))) { - LOG(("Can't get the cookieJarSettings")); - return; - } - - int32_t behavior = cookieJarSettings->GetCookieBehavior(); - - if (!cookieJarSettings->GetRejectThirdPartyTrackers()) { - LOG( - ("Disabled by network.cookie.cookieBehavior pref (%d), bailing out " - "early", - behavior)); - return; - } - - MOZ_ASSERT( - behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER || - behavior == - nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN); - - if (ContentBlockingAllowList::Check(newChannel)) { - return; - } - - LOG(("Saving the permission: trackingOrigin=%s, grantedOrigin=%s", - trackingOrigin.get(), redirectedOrigin.get())); - - // Any new redirect from this loadInfo must be considered as granted. - newLoadInfo->SetAllowListFutureDocumentsCreatedFromThisRedirectChain(true); - - uint64_t innerWindowID; - Unused << newChannel->GetTopLevelContentWindowId(&innerWindowID); - - nsAutoString errorText; - AutoTArray params = {NS_ConvertUTF8toUTF16(redirectedOrigin), - NS_ConvertUTF8toUTF16(trackingOrigin)}; - rv = nsContentUtils::FormatLocalizedString( - nsContentUtils::eNECKO_PROPERTIES, "CookieAllowedForTrackerByHeuristic", - params, errorText); - if (NS_SUCCEEDED(rv)) { - nsContentUtils::ReportToConsoleByWindowID( - errorText, nsIScriptError::warningFlag, ANTITRACKING_CONSOLE_CATEGORY, - innerWindowID); - } - - // We don't care about this promise because the operation is actually sync. - RefPtr promise = - ContentBlocking::SaveAccessForOriginOnParentProcess( - redirectedPrincipal, trackingPrincipal, trackingOrigin, - ContentBlocking::StorageAccessPromptChoices::eAllow, - StaticPrefs::privacy_restrict3rdpartystorage_expiration_redirect()); - Unused << promise; -} - -} // namespace mozilla diff --git a/toolkit/components/antitracking/AntiTrackingRedirectHeuristic.h b/toolkit/components/antitracking/AntiTrackingRedirectHeuristic.h deleted file mode 100644 index 4b8d9a602a1d..000000000000 --- a/toolkit/components/antitracking/AntiTrackingRedirectHeuristic.h +++ /dev/null @@ -1,20 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_antitrackingredirectheuristic_h -#define mozilla_antitrackingredirectheuristic_h - -class nsIChannel; -class nsIURI; - -namespace mozilla { - -void AntiTrackingRedirectHeuristic(nsIChannel* aOldChannel, nsIURI* aOldURI, - nsIChannel* aNewChannel, nsIURI* aNewURI); - -} // namespace mozilla - -#endif // mozilla_antitrackingredirectheuristic_h diff --git a/toolkit/components/antitracking/AntiTrackingUtils.cpp b/toolkit/components/antitracking/AntiTrackingUtils.cpp deleted file mode 100644 index d4eb93d81859..000000000000 --- a/toolkit/components/antitracking/AntiTrackingUtils.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#include "AntiTrackingUtils.h" - -#include "mozilla/dom/BrowsingContext.h" -#include "mozilla/dom/Document.h" -#include "nsIChannel.h" -#include "nsIPermission.h" -#include "nsIURI.h" -#include "nsPIDOMWindow.h" - -#define ANTITRACKING_PERM_KEY "3rdPartyStorage" - -using namespace mozilla; -using namespace mozilla::dom; - -/* static */ already_AddRefed -AntiTrackingUtils::GetTopWindow(nsPIDOMWindowInner* aWindow) { - Document* document = aWindow->GetExtantDoc(); - if (!document) { - return nullptr; - } - - nsIChannel* channel = document->GetChannel(); - if (!channel) { - return nullptr; - } - - nsCOMPtr pwin = - aWindow->GetBrowsingContext()->Top()->GetDOMWindow(); - - if (!pwin) { - return nullptr; - } - - return pwin.forget(); -} - -/* static */ -already_AddRefed AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded( - nsIChannel* aChannel) { - nsCOMPtr uriBeingLoaded; - nsLoadFlags loadFlags = 0; - nsresult rv = aChannel->GetLoadFlags(&loadFlags); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - if (loadFlags & nsIChannel::LOAD_DOCUMENT_URI) { - // If the channel being loaded is a document channel, this call may be - // coming from an OnStopRequest notification, which might mean that our - // document may still be in the loading process, so we may need to pass in - // the uriBeingLoaded argument explicitly. - rv = aChannel->GetURI(getter_AddRefs(uriBeingLoaded)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; - } - } - return uriBeingLoaded.forget(); -} - -// static -void AntiTrackingUtils::CreateStoragePermissionKey( - const nsCString& aTrackingOrigin, nsACString& aPermissionKey) { - MOZ_ASSERT(aPermissionKey.IsEmpty()); - - static const nsLiteralCString prefix = - NS_LITERAL_CSTRING(ANTITRACKING_PERM_KEY "^"); - - aPermissionKey.SetCapacity(prefix.Length() + aTrackingOrigin.Length()); - aPermissionKey.Append(prefix); - aPermissionKey.Append(aTrackingOrigin); -} - -// static -bool AntiTrackingUtils::CreateStoragePermissionKey(nsIPrincipal* aPrincipal, - nsACString& aKey) { - if (!aPrincipal) { - return false; - } - - nsAutoCString origin; - nsresult rv = aPrincipal->GetOriginNoSuffix(origin); - if (NS_WARN_IF(NS_FAILED(rv))) { - return false; - } - - CreateStoragePermissionKey(origin, aKey); - return true; -} - -// static -bool AntiTrackingUtils::IsStorageAccessPermission(nsIPermission* aPermission, - nsIPrincipal* aPrincipal) { - MOZ_ASSERT(aPermission); - MOZ_ASSERT(aPrincipal); - - // The permission key may belong either to a tracking origin on the same - // origin as the granted origin, or on another origin as the granted origin - // (for example when a tracker in a third-party context uses window.open to - // open another origin where that second origin would be the granted origin.) - // But even in the second case, the type of the permission would still be - // formed by concatenating the granted origin to the end of the type name - // (see CreatePermissionKey). Therefore, we pass in the same argument to - // both tracking origin and granted origin here in order to compute the - // shorter permission key and will then do a prefix match on the type of the - // input permission to see if it is a storage access permission or not. - nsAutoCString permissionKey; - bool result = CreateStoragePermissionKey(aPrincipal, permissionKey); - if (NS_WARN_IF(!result)) { - return false; - } - - nsAutoCString type; - nsresult rv = aPermission->GetType(type); - if (NS_WARN_IF(NS_FAILED(rv))) { - return false; - } - - return StringBeginsWith(type, permissionKey); -} diff --git a/toolkit/components/antitracking/AntiTrackingUtils.h b/toolkit/components/antitracking/AntiTrackingUtils.h deleted file mode 100644 index 534f3435c939..000000000000 --- a/toolkit/components/antitracking/AntiTrackingUtils.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_antitrackingutils_h -#define mozilla_antitrackingutils_h - -#include "mozilla/AlreadyAddRefed.h" -#include "nsStringFwd.h" - -class nsPIDOMWindowInner; -class nsPIDOMWindowOuter; -class nsIChannel; -class nsIPermission; -class nsIPrincipal; -class nsIURI; - -namespace mozilla { - -class AntiTrackingUtils final { - public: - static already_AddRefed GetTopWindow( - nsPIDOMWindowInner* aWindow); - - // Get the current document URI from a document channel as it is being loaded. - static already_AddRefed MaybeGetDocumentURIBeingLoaded( - nsIChannel* aChannel); - - static void CreateStoragePermissionKey(const nsCString& aTrackingOrigin, - nsACString& aPermissionKey); - - // Given a principal, returns the storage permission key that will be used for - // the principal. Returns true on success. - static bool CreateStoragePermissionKey(nsIPrincipal* aPrincipal, - nsACString& aKey); - - // Returns true if the permission passed in is a storage access permission - // for the passed in principal argument. - static bool IsStorageAccessPermission(nsIPermission* aPermission, - nsIPrincipal* aPrincipal); -}; - -} // namespace mozilla - -#endif // mozilla_antitrackingutils_h diff --git a/toolkit/components/antitracking/ContentBlocking.h b/toolkit/components/antitracking/ContentBlocking.h deleted file mode 100644 index a05812a87cff..000000000000 --- a/toolkit/components/antitracking/ContentBlocking.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_antitrackingservice_h -#define mozilla_antitrackingservice_h - -#include "nsString.h" -#include "mozilla/ContentBlockingNotifier.h" -#include "mozilla/MozPromise.h" -#include "mozilla/RefPtr.h" -#include "mozilla/StaticPrefs_privacy.h" - -class nsIChannel; -class nsICookieJarSettings; -class nsIPermission; -class nsIPrincipal; -class nsIURI; -class nsPIDOMWindowInner; -class nsPIDOMWindowOuter; - -namespace mozilla { - -class OriginAttributes; - -class ContentBlocking final { - public: - // This method returns true if the URI has first party storage access when - // loaded inside the passed 3rd party context tracking resource window. - // If the window is first party context, please use - // ApproximateAllowAccessForWithoutChannel(); - // - // aRejectedReason could be set to one of these values if passed and if the - // storage permission is not granted: - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN - static bool ShouldAllowAccessFor(nsPIDOMWindowInner* a3rdPartyTrackingWindow, - nsIURI* aURI, uint32_t* aRejectedReason); - - // Note: you should use ShouldAllowAccessFor() passing the nsIChannel! Use - // this method _only_ if the channel is not available. For first party - // window, it's impossible to know if the aURI is a tracking resource - // synchronously, so here we return the best guest: if we are sure that the - // permission is granted for the origin of aURI, this method returns true, - // otherwise false. - static bool ApproximateAllowAccessForWithoutChannel( - nsPIDOMWindowInner* aFirstPartyWindow, nsIURI* aURI); - - // It returns true if the URI has access to the first party storage. - // aChannel can be a 3rd party channel, or not. - // See ShouldAllowAccessFor(window) to see the possible values of - // aRejectedReason. - static bool ShouldAllowAccessFor(nsIChannel* aChannel, nsIURI* aURI, - uint32_t* aRejectedReason); - - // This method checks if the principal has the permission to access to the - // first party storage. - static bool ShouldAllowAccessFor(nsIPrincipal* aPrincipal, - nsICookieJarSettings* aCookieJarSettings); - - enum StorageAccessPromptChoices { eAllow, eAllowAutoGrant }; - - // Grant the permission for aOrigin to have access to the first party storage. - // This method can handle 2 different scenarios: - // - aParentWindow is a 3rd party context, it opens an aOrigin window and the - // user interacts with it. We want to grant the permission at the - // combination: top-level + aParentWindow + aOrigin. - // Ex: example.net loads an iframe tracker.com, which opens a popup - // tracker.prg and the user interacts with it. tracker.org is allowed if - // loaded by tracker.com when loaded by example.net. - // - aParentWindow is a first party context and a 3rd party resource (probably - // becuase of a script) opens a popup and the user interacts with it. We - // want to grant the permission for the 3rd party context to have access to - // the first party stoage when loaded in aParentWindow. - // Ex: example.net import tracker.com/script.js which does opens a popup and - // the user interacts with it. tracker.com is allowed when loaded by - // example.net. - typedef MozPromise StorageAccessFinalCheckPromise; - typedef std::function()> - PerformFinalChecks; - typedef MozPromise StorageAccessGrantPromise; - static MOZ_MUST_USE RefPtr AllowAccessFor( - nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aParentWindow, - ContentBlockingNotifier::StorageAccessGrantedReason aReason, - const PerformFinalChecks& aPerformFinalChecks = nullptr); - - // For IPC only. - typedef MozPromise ParentAccessGrantPromise; - static RefPtr SaveAccessForOriginOnParentProcess( - nsIPrincipal* aPrincipal, nsIPrincipal* aTrackingPrinciapl, - const nsCString& aTrackingOrigin, int aAllowMode, - uint64_t aExpirationTime = - StaticPrefs::privacy_restrict3rdpartystorage_expiration()); -}; - -} // namespace mozilla - -#endif // mozilla_antitrackingservice_h diff --git a/toolkit/components/antitracking/ContentBlockingAllowList.h b/toolkit/components/antitracking/ContentBlockingAllowList.h index 241904ae5c91..050e9cd7e0c3 100644 --- a/toolkit/components/antitracking/ContentBlockingAllowList.h +++ b/toolkit/components/antitracking/ContentBlockingAllowList.h @@ -26,8 +26,6 @@ class ContentBlockingAllowList final { static nsresult Check(nsIPrincipal* aContentBlockingAllowListPrincipal, bool aIsPrivateBrowsing, bool& aIsAllowListed); - static bool Check(nsIHttpChannel* aChannel); - // Computes the principal used to check the content blocking allow list for a // top-level document based on the document principal. This function is used // right after setting up the document principal. @@ -43,11 +41,12 @@ class ContentBlockingAllowList final { // Check(). static ContentBlockingAllowListCache& Cache(); - // Utility APIs for ContentBlocking. + // Utility APIs for AntiTrackingCommon. static bool Check(nsIPrincipal* aTopWinPrincipal, bool aIsPrivateBrowsing); static bool Check(nsPIDOMWindowInner* aWindow); + static bool Check(nsIHttpChannel* aChannel); - friend class ContentBlocking; + friend class AntiTrackingCommon; }; } // namespace mozilla diff --git a/toolkit/components/antitracking/ContentBlockingNotifier.cpp b/toolkit/components/antitracking/ContentBlockingNotifier.cpp deleted file mode 100644 index 59f46780b4ae..000000000000 --- a/toolkit/components/antitracking/ContentBlockingNotifier.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#include "AntiTrackingLog.h" -#include "ContentBlockingNotifier.h" -#include "AntiTrackingUtils.h" - -#include "mozilla/AbstractEventQueue.h" -#include "mozilla/StaticPrefs_privacy.h" -#include "mozilla/dom/BrowserChild.h" -#include "mozilla/dom/BrowsingContext.h" -#include "mozilla/dom/WindowGlobalParent.h" -#include "nsIClassifiedChannel.h" -#include "nsIRunnable.h" -#include "nsIScriptError.h" -#include "nsIURI.h" -#include "nsIURIFixup.h" -#include "nsGlobalWindowInner.h" -#include "nsJSUtils.h" -#include "mozIThirdPartyUtil.h" - -using namespace mozilla; -using mozilla::dom::BrowsingContext; -using mozilla::dom::ContentChild; -using mozilla::dom::Document; - -static const uint32_t kMaxConsoleOutputDelayMs = 100; - -namespace { - -void RunConsoleReportingRunnable(already_AddRefed&& aRunnable) { - if (StaticPrefs::privacy_restrict3rdpartystorage_console_lazy()) { - nsresult rv = NS_DispatchToCurrentThreadQueue(std::move(aRunnable), - kMaxConsoleOutputDelayMs, - EventQueuePriority::Idle); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; - } - } else { - nsCOMPtr runnable(std::move(aRunnable)); - nsresult rv = runnable->Run(); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; - } - } -} - -void ReportBlockingToConsole(uint64_t aWindowID, nsIURI* aURI, - uint32_t aRejectedReason) { - MOZ_ASSERT(aWindowID); - MOZ_ASSERT(aURI); - MOZ_ASSERT( - aRejectedReason == 0 || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); - - nsAutoString sourceLine; - uint32_t lineNumber = 0, columnNumber = 0; - JSContext* cx = nsContentUtils::GetCurrentJSContext(); - if (cx) { - nsJSUtils::GetCallingLocation(cx, sourceLine, &lineNumber, &columnNumber); - } - - nsCOMPtr uri(aURI); - - RefPtr runnable = NS_NewRunnableFunction( - "ReportBlockingToConsoleDelayed", [aWindowID, sourceLine, lineNumber, - columnNumber, uri, aRejectedReason]() { - const char* message = nullptr; - nsAutoCString category; - // When changing this list, please make sure to update the corresponding - // code in antitracking_head.js (inside _createTask). - switch (aRejectedReason) { - case nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION: - message = "CookieBlockedByPermission"; - category = NS_LITERAL_CSTRING("cookieBlockedPermission"); - break; - - case nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER: - message = "CookieBlockedTracker"; - category = NS_LITERAL_CSTRING("cookieBlockedTracker"); - break; - - case nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL: - message = "CookieBlockedAll"; - category = NS_LITERAL_CSTRING("cookieBlockedAll"); - break; - - case nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN: - message = "CookieBlockedForeign"; - category = NS_LITERAL_CSTRING("cookieBlockedForeign"); - break; - - default: - return; - } - - MOZ_ASSERT(message); - - // Strip the URL of any possible username/password and make it ready - // to be presented in the UI. - nsCOMPtr urifixup = services::GetURIFixup(); - NS_ENSURE_TRUE_VOID(urifixup); - nsCOMPtr exposableURI; - nsresult rv = - urifixup->CreateExposableURI(uri, getter_AddRefs(exposableURI)); - NS_ENSURE_SUCCESS_VOID(rv); - - AutoTArray params; - CopyUTF8toUTF16(exposableURI->GetSpecOrDefault(), - *params.AppendElement()); - - nsAutoString errorText; - rv = nsContentUtils::FormatLocalizedString( - nsContentUtils::eNECKO_PROPERTIES, message, params, errorText); - NS_ENSURE_SUCCESS_VOID(rv); - - nsContentUtils::ReportToConsoleByWindowID( - errorText, nsIScriptError::warningFlag, category, aWindowID, - nullptr, sourceLine, lineNumber, columnNumber); - }); - - RunConsoleReportingRunnable(runnable.forget()); -} - -void ReportBlockingToConsole(nsIChannel* aChannel, nsIURI* aURI, - uint32_t aRejectedReason) { - MOZ_ASSERT(aChannel && aURI); - - uint64_t windowID; - - if (XRE_IsParentProcess()) { - // Get the top-level window ID from the top-level BrowsingContext - nsCOMPtr loadInfo = aChannel->LoadInfo(); - RefPtr bc; - loadInfo->GetBrowsingContext(getter_AddRefs(bc)); - - if (!bc || bc->IsDiscarded()) { - return; - } - - bc = bc->Top(); - RefPtr wgp = - bc->Canonical()->GetCurrentWindowGlobal(); - if (!wgp) { - return; - } - - windowID = wgp->InnerWindowId(); - } else { - nsresult rv; - nsCOMPtr httpChannel = do_QueryInterface(aChannel, &rv); - - if (!httpChannel) { - return; - } - - rv = httpChannel->GetTopLevelContentWindowId(&windowID); - if (NS_FAILED(rv) || !windowID) { - windowID = nsContentUtils::GetInnerWindowID(httpChannel); - } - } - - ReportBlockingToConsole(windowID, aURI, aRejectedReason); -} - -// This API finishes the remaining work left in NotifyBlockingDecision. -void NotifyAllowDecision(nsIChannel* aReportingChannel, - nsIChannel* aTrackingChannel, nsIURI* aURI, - nsPIDOMWindowOuter* aWindow) { - nsAutoCString trackingOrigin; - if (aURI) { - Unused << nsContentUtils::GetASCIIOrigin(aURI, trackingOrigin); - } - - // This can be called in either the parent process or the child processes. - - // Now send the generic "cookies loaded" notifications, from the most generic - // to the most specific. - ContentBlockingNotifier::OnEvent( - aWindow, aReportingChannel, aTrackingChannel, false, - nsIWebProgressListener::STATE_COOKIES_LOADED, trackingOrigin); - - nsCOMPtr classifiedChannel = - do_QueryInterface(aTrackingChannel); - if (!classifiedChannel) { - return; - } - - uint32_t classificationFlags = - classifiedChannel->GetThirdPartyClassificationFlags(); - if (classificationFlags & - nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_TRACKING) { - ContentBlockingNotifier::OnEvent( - aWindow, aReportingChannel, aTrackingChannel, false, - nsIWebProgressListener::STATE_COOKIES_LOADED_TRACKER, trackingOrigin); - } - - if (classificationFlags & - nsIClassifiedChannel::ClassificationFlags::CLASSIFIED_SOCIALTRACKING) { - ContentBlockingNotifier::OnEvent( - aWindow, aReportingChannel, aTrackingChannel, false, - nsIWebProgressListener::STATE_COOKIES_LOADED_SOCIALTRACKER, - trackingOrigin); - } -} - -void NotifyBlockingDecision(nsIChannel* aReportingChannel, - nsIChannel* aTrackingChannel, - ContentBlockingNotifier::BlockingDecision aDecision, - uint32_t aRejectedReason, nsIURI* aURI, - nsPIDOMWindowOuter* aWindow) { - MOZ_ASSERT(aWindow); - - // When this is called with system priviledged, the decision should always be - // ALLOW, and we can also stop processing this event. - if (nsGlobalWindowOuter::Cast(aWindow)->GetPrincipal() == - nsContentUtils::GetSystemPrincipal()) { - MOZ_DIAGNOSTIC_ASSERT(aDecision == - ContentBlockingNotifier::BlockingDecision::eAllow); - return; - } - - nsAutoCString trackingOrigin; - if (aURI) { - Unused << nsContentUtils::GetASCIIOrigin(aURI, trackingOrigin); - } - - if (aDecision == ContentBlockingNotifier::BlockingDecision::eBlock) { - ContentBlockingNotifier::OnEvent(aWindow, aReportingChannel, - aTrackingChannel, true, aRejectedReason, - trackingOrigin); - - ReportBlockingToConsole(aReportingChannel, aURI, aRejectedReason); - } - - NotifyAllowDecision(aReportingChannel, aTrackingChannel, aURI, aWindow); -} - -void NotifyBlockingDecision(nsIChannel* aReportingChannel, - nsIChannel* aTrackingChannel, - ContentBlockingNotifier::BlockingDecision aDecision, - uint32_t aRejectedReason, nsIURI* aURI) { - // Can be called only in the parent process when there is no window. - MOZ_ASSERT(XRE_IsParentProcess()); - - nsAutoCString trackingOrigin; - if (aURI) { - Unused << nsContentUtils::GetASCIIOrigin(aURI, trackingOrigin); - } - - if (aDecision == ContentBlockingNotifier::BlockingDecision::eBlock) { - ContentBlockingNotifier::OnEvent(nullptr, aReportingChannel, - aTrackingChannel, true, aRejectedReason, - trackingOrigin); - - ReportBlockingToConsole(aReportingChannel, aURI, aRejectedReason); - } - - NotifyAllowDecision(aReportingChannel, aTrackingChannel, aURI, nullptr); -} - -// Send a message to notify OnContentBlockingEvent in the parent, which will -// update the ContentBlockingLog in the parent. -void NotifyEventInChild( - nsPIDOMWindowOuter* aWindow, nsIChannel* aReportingChannel, - nsIChannel* aTrackingChannel, bool aBlocked, uint32_t aRejectedReason, - const nsACString& aTrackingOrigin, - const Maybe& aReason) { - MOZ_ASSERT(XRE_IsContentProcess()); - MOZ_ASSERT(aWindow); - - RefPtr browserChild = dom::BrowserChild::GetFrom(aWindow); - NS_ENSURE_TRUE_VOID(browserChild); - - nsTArray trackingFullHashes; - nsCOMPtr classifiedChannel = - do_QueryInterface(aTrackingChannel); - - if (classifiedChannel) { - Unused << classifiedChannel->GetMatchedTrackingFullHashes( - trackingFullHashes); - } - - browserChild->NotifyContentBlockingEvent(aRejectedReason, aReportingChannel, - aBlocked, aTrackingOrigin, - trackingFullHashes, aReason); -} - -// Update the ContentBlockingLog of the top-level WindowGlobalParent of -// the reporting channel. -void NotifyEventInParent( - nsIChannel* aReportingChannel, nsIChannel* aTrackingChannel, bool aBlocked, - uint32_t aRejectedReason, const nsACString& aTrackingOrigin, - const Maybe& aReason) { - MOZ_ASSERT(XRE_IsParentProcess()); - - nsCOMPtr loadInfo = aReportingChannel->LoadInfo(); - RefPtr bc; - loadInfo->GetBrowsingContext(getter_AddRefs(bc)); - - if (!bc || bc->IsDiscarded()) { - return; - } - - bc = bc->Top(); - RefPtr wgp = - bc->Canonical()->GetCurrentWindowGlobal(); - NS_ENSURE_TRUE_VOID(wgp); - - nsTArray trackingFullHashes; - nsCOMPtr classifiedChannel = - do_QueryInterface(aTrackingChannel); - - if (classifiedChannel) { - Unused << classifiedChannel->GetMatchedTrackingFullHashes( - trackingFullHashes); - } - - wgp->NotifyContentBlockingEvent(aRejectedReason, aReportingChannel, aBlocked, - aTrackingOrigin, trackingFullHashes, aReason); -} - -} // namespace - -/* static */ void ContentBlockingNotifier::ReportUnblockingToConsole( - nsPIDOMWindowInner* aWindow, const nsAString& aTrackingOrigin, - ContentBlockingNotifier::StorageAccessGrantedReason aReason) { - nsCOMPtr principal = - nsGlobalWindowInner::Cast(aWindow)->GetPrincipal(); - if (NS_WARN_IF(!principal)) { - return; - } - - RefPtr doc = aWindow->GetExtantDoc(); - if (NS_WARN_IF(!doc)) { - return; - } - - nsAutoString trackingOrigin(aTrackingOrigin); - - nsAutoString sourceLine; - uint32_t lineNumber = 0, columnNumber = 0; - JSContext* cx = nsContentUtils::GetCurrentJSContext(); - if (cx) { - nsJSUtils::GetCallingLocation(cx, sourceLine, &lineNumber, &columnNumber); - } - - RefPtr runnable = NS_NewRunnableFunction( - "ReportUnblockingToConsoleDelayed", - [doc, principal, trackingOrigin, sourceLine, lineNumber, columnNumber, - aReason]() { - nsAutoString origin; - nsresult rv = nsContentUtils::GetUTFOrigin(principal, origin); - if (NS_WARN_IF(NS_FAILED(rv))) { - return; - } - - // Not adding grantedOrigin yet because we may not want it later. - AutoTArray params = {origin, trackingOrigin}; - const char* messageWithSameOrigin = nullptr; - - switch (aReason) { - case ContentBlockingNotifier::eStorageAccessAPI: - messageWithSameOrigin = "CookieAllowedForTrackerByStorageAccessAPI"; - break; - - case ContentBlockingNotifier::eOpenerAfterUserInteraction: - [[fallthrough]]; - case ContentBlockingNotifier::eOpener: - messageWithSameOrigin = "CookieAllowedForTrackerByHeuristic"; - break; - } - - nsContentUtils::ReportToConsole( - nsIScriptError::warningFlag, ANTITRACKING_CONSOLE_CATEGORY, doc, - nsContentUtils::eNECKO_PROPERTIES, messageWithSameOrigin, params, - nullptr, sourceLine, lineNumber, columnNumber); - }); - - RunConsoleReportingRunnable(runnable.forget()); -} - -/* static */ -void ContentBlockingNotifier::OnDecision(nsIChannel* aChannel, - BlockingDecision aDecision, - uint32_t aRejectedReason) { - MOZ_ASSERT( - aRejectedReason == 0 || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); - MOZ_ASSERT(aDecision == BlockingDecision::eBlock || - aDecision == BlockingDecision::eAllow); - - if (!aChannel) { - return; - } - - nsCOMPtr uri; - aChannel->GetURI(getter_AddRefs(uri)); - - // Can be called in EITHER the parent or child process. - // Window is only needed while in child processes. - if (XRE_IsParentProcess()) { - NotifyBlockingDecision(aChannel, aChannel, aDecision, aRejectedReason, uri); - return; - } - - MOZ_ASSERT(XRE_IsContentProcess()); - - nsCOMPtr thirdPartyUtil = services::GetThirdPartyUtil(); - if (!thirdPartyUtil) { - return; - } - - nsCOMPtr uriBeingLoaded = - AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(aChannel); - nsCOMPtr win; - nsresult rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, uriBeingLoaded, - getter_AddRefs(win)); - NS_ENSURE_SUCCESS_VOID(rv); - - nsCOMPtr pwin = nsPIDOMWindowOuter::From(win); - if (!pwin) { - return; - } - - NotifyBlockingDecision(aChannel, aChannel, aDecision, aRejectedReason, uri, - pwin); -} - -/* static */ -void ContentBlockingNotifier::OnDecision(nsPIDOMWindowInner* aWindow, - BlockingDecision aDecision, - uint32_t aRejectedReason) { - MOZ_ASSERT(aWindow); - MOZ_ASSERT( - aRejectedReason == 0 || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER || - aRejectedReason == - nsIWebProgressListener::STATE_COOKIES_PARTITIONED_FOREIGN || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL || - aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN); - MOZ_ASSERT(aDecision == BlockingDecision::eBlock || - aDecision == BlockingDecision::eAllow); - - nsCOMPtr pwin = AntiTrackingUtils::GetTopWindow(aWindow); - if (!pwin) { - return; - } - - nsPIDOMWindowInner* inner = pwin->GetCurrentInnerWindow(); - if (!inner) { - return; - } - Document* pwinDoc = inner->GetExtantDoc(); - if (!pwinDoc) { - return; - } - nsIChannel* channel = pwinDoc->GetChannel(); - if (!channel) { - return; - } - - Document* document = aWindow->GetExtantDoc(); - if (!document) { - return; - } - nsIURI* uri = document->GetDocumentURI(); - nsIChannel* trackingChannel = document->GetChannel(); - - NotifyBlockingDecision(channel, trackingChannel, aDecision, aRejectedReason, - uri, pwin); -} - -/* static */ -void ContentBlockingNotifier::OnEvent(nsIChannel* aChannel, - uint32_t aRejectedReason) { - MOZ_ASSERT(XRE_IsParentProcess() && aChannel); - - nsCOMPtr uri; - aChannel->GetURI(getter_AddRefs(uri)); - - nsAutoCString trackingOrigin; - if (uri) { - Unused << nsContentUtils::GetASCIIOrigin(uri, trackingOrigin); - } - - return ContentBlockingNotifier::OnEvent(nullptr, aChannel, aChannel, true, - aRejectedReason, trackingOrigin); -} - -/* static */ -void ContentBlockingNotifier::OnEvent( - nsPIDOMWindowOuter* aWindow, nsIChannel* aReportingChannel, - nsIChannel* aTrackingChannel, bool aBlocked, uint32_t aRejectedReason, - const nsACString& aTrackingOrigin, - const Maybe& aReason) { - if (XRE_IsParentProcess()) { - NotifyEventInParent(aReportingChannel, aTrackingChannel, aBlocked, - aRejectedReason, aTrackingOrigin, aReason); - } else { - NotifyEventInChild(aWindow, aReportingChannel, aTrackingChannel, aBlocked, - aRejectedReason, aTrackingOrigin, aReason); - } -} diff --git a/toolkit/components/antitracking/ContentBlockingNotifier.h b/toolkit/components/antitracking/ContentBlockingNotifier.h deleted file mode 100644 index 8418c5245c3f..000000000000 --- a/toolkit/components/antitracking/ContentBlockingNotifier.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_contentblockingnotifier_h -#define mozilla_contentblockingnotifier_h - -#include "nsStringFwd.h" -#include "mozilla/Maybe.h" - -#define ANTITRACKING_CONSOLE_CATEGORY NS_LITERAL_CSTRING("Content Blocking") - -class nsIChannel; -class nsPIDOMWindowInner; -class nsPIDOMWindowOuter; - -namespace mozilla { - -class ContentBlockingNotifier final { - public: - enum class BlockingDecision { - eBlock, - eAllow, - }; - enum StorageAccessGrantedReason { - eStorageAccessAPI, - eOpenerAfterUserInteraction, - eOpener - }; - - // This method can be called on the parent process or on the content process. - // The notification is propagated to the child channel if aChannel is a parent - // channel proxy. - // - // aDecision can be eBlock if we have decided to block some content, or eAllow - // if we have decided to allow the content through. - // - // aRejectedReason must be one of these values: - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL - // * nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN - static void OnDecision(nsIChannel* aChannel, BlockingDecision aDecision, - uint32_t aRejectedReason); - - static void OnDecision(nsPIDOMWindowInner* aWindow, - BlockingDecision aDecision, uint32_t aRejectedReason); - - static void OnEvent(nsIChannel* aChannel, uint32_t aRejectedReason); - - static void OnEvent( - nsPIDOMWindowOuter* aWindow, nsIChannel* aReportingChannel, - nsIChannel* aTrackingChannel, bool aBlocked, uint32_t aRejectedReason, - const nsACString& aTrackingOrigin, - const Maybe& aReason = Nothing()); - - static void ReportUnblockingToConsole(nsPIDOMWindowInner* aWindow, - const nsAString& aTrackingOrigin, - StorageAccessGrantedReason aReason); -}; - -} // namespace mozilla - -#endif // mozilla_contentblockingnotifier_h diff --git a/toolkit/components/antitracking/ContentBlockingUserInteraction.cpp b/toolkit/components/antitracking/ContentBlockingUserInteraction.cpp deleted file mode 100644 index 44f6d77c6318..000000000000 --- a/toolkit/components/antitracking/ContentBlockingUserInteraction.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#include "AntiTrackingLog.h" -#include "ContentBlockingUserInteraction.h" -#include "AntiTrackingUtils.h" - -#include "mozilla/dom/ContentChild.h" -#include "nsIPrincipal.h" -#include "nsPermissionManager.h" -#include "nsXULAppAPI.h" -#include "prtime.h" - -namespace mozilla { - -/* static */ -void ContentBlockingUserInteraction::Observe(nsIPrincipal* aPrincipal) { - if (!aPrincipal) { - // The content process may have sent us garbage data. - return; - } - - if (XRE_IsParentProcess()) { - LOG_PRIN(("Saving the userInteraction for %s", _spec), aPrincipal); - - nsPermissionManager* permManager = nsPermissionManager::GetInstance(); - if (NS_WARN_IF(!permManager)) { - LOG(("Permission manager is null, bailing out early")); - return; - } - - // Remember that this pref is stored in seconds! - uint32_t expirationType = nsIPermissionManager::EXPIRE_TIME; - uint32_t expirationTime = - StaticPrefs::privacy_userInteraction_expiration() * 1000; - int64_t when = (PR_Now() / PR_USEC_PER_MSEC) + expirationTime; - - uint32_t privateBrowsingId = 0; - nsresult rv = aPrincipal->GetPrivateBrowsingId(&privateBrowsingId); - if (!NS_WARN_IF(NS_FAILED(rv)) && privateBrowsingId > 0) { - // If we are coming from a private window, make sure to store a - // session-only permission which won't get persisted to disk. - expirationType = nsIPermissionManager::EXPIRE_SESSION; - when = 0; - } - - rv = permManager->AddFromPrincipal(aPrincipal, USER_INTERACTION_PERM, - nsIPermissionManager::ALLOW_ACTION, - expirationType, when); - Unused << NS_WARN_IF(NS_FAILED(rv)); - return; - } - - dom::ContentChild* cc = dom::ContentChild::GetSingleton(); - MOZ_ASSERT(cc); - - LOG_PRIN(("Asking the parent process to save the user-interaction for us: %s", - _spec), - aPrincipal); - cc->SendStoreUserInteractionAsPermission(IPC::Principal(aPrincipal)); -} - -/* static */ -bool ContentBlockingUserInteraction::Exists(nsIPrincipal* aPrincipal) { - nsPermissionManager* permManager = nsPermissionManager::GetInstance(); - if (NS_WARN_IF(!permManager)) { - return false; - } - - uint32_t result = 0; - nsresult rv = permManager->TestPermissionWithoutDefaultsFromPrincipal( - aPrincipal, USER_INTERACTION_PERM, &result); - if (NS_WARN_IF(NS_FAILED(rv))) { - return false; - } - - return result == nsIPermissionManager::ALLOW_ACTION; -} - -} // namespace mozilla diff --git a/toolkit/components/antitracking/ContentBlockingUserInteraction.h b/toolkit/components/antitracking/ContentBlockingUserInteraction.h deleted file mode 100644 index 31d105702bac..000000000000 --- a/toolkit/components/antitracking/ContentBlockingUserInteraction.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_contentblockinguserinteraction_h -#define mozilla_contentblockinguserinteraction_h - -#define USER_INTERACTION_PERM NS_LITERAL_CSTRING("storageAccessAPI") - -class nsIPrincipal; - -namespace mozilla { - -class ContentBlockingUserInteraction final { - public: - // Used to remember that we observed a user interaction that is significant - // for content blocking. - static void Observe(nsIPrincipal* aPrincipal); - - // Used to query whether we've observed a user interaction that is significant - // for content blocking for the given principal in the past. - static bool Exists(nsIPrincipal* aPrincipal); -}; - -} // namespace mozilla - -#endif // mozilla_contentblockinguserinteraction_h diff --git a/toolkit/components/antitracking/SettingsChangeObserver.cpp b/toolkit/components/antitracking/SettingsChangeObserver.cpp index eb2ba5bbd334..d4bdb2c39711 100644 --- a/toolkit/components/antitracking/SettingsChangeObserver.cpp +++ b/toolkit/components/antitracking/SettingsChangeObserver.cpp @@ -5,7 +5,7 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "SettingsChangeObserver.h" -#include "ContentBlockingUserInteraction.h" +#include "AntiTrackingCommon.h" #include "mozilla/Services.h" #include "mozilla/Preferences.h" diff --git a/toolkit/components/antitracking/StorageAccess.cpp b/toolkit/components/antitracking/StorageAccess.cpp index 0084ffef4e0a..53d7ac0c1e19 100644 --- a/toolkit/components/antitracking/StorageAccess.cpp +++ b/toolkit/components/antitracking/StorageAccess.cpp @@ -6,21 +6,14 @@ #include "mozilla/dom/Document.h" #include "mozilla/net/CookieJarSettings.h" -#include "mozilla/ContentBlocking.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/StaticPrefs_browser.h" #include "mozilla/StaticPrefs_network.h" #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/StorageAccess.h" -#include "nsContentUtils.h" -#include "nsICookiePermission.h" #include "nsICookieService.h" #include "nsICookieJarSettings.h" -#include "nsIPermission.h" #include "nsIWebProgressListener.h" -#include "nsSandboxFlags.h" - -using namespace mozilla; -using namespace mozilla::dom; /** * Gets the cookie lifetime policy for a given cookieJarSettings and a given @@ -175,8 +168,9 @@ static bool StorageDisabledByAntiTrackingInternal( if (aWindow) { nsIURI* documentURI = aURI ? aURI : aWindow->GetDocumentURI(); - return !documentURI || !ContentBlocking::ShouldAllowAccessFor( - aWindow, documentURI, &aRejectedReason); + return !documentURI || + !AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + aWindow, documentURI, &aRejectedReason); } if (aChannel) { @@ -186,12 +180,13 @@ static bool StorageDisabledByAntiTrackingInternal( return false; } - return !ContentBlocking::ShouldAllowAccessFor(aChannel, uri, - &aRejectedReason); + return !AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + aChannel, uri, &aRejectedReason); } MOZ_ASSERT(aPrincipal); - return !ContentBlocking::ShouldAllowAccessFor(aPrincipal, aCookieJarSettings); + return !AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + aPrincipal, aCookieJarSettings); } namespace mozilla { @@ -305,16 +300,16 @@ bool StorageDisabledByAntiTracking(nsPIDOMWindowInner* aWindow, bool disabled = StorageDisabledByAntiTrackingInternal( aWindow, aChannel, aPrincipal, aURI, cookieJarSettings, aRejectedReason); if (aWindow) { - ContentBlockingNotifier::OnDecision( + AntiTrackingCommon::NotifyBlockingDecision( aWindow, - disabled ? ContentBlockingNotifier::BlockingDecision::eBlock - : ContentBlockingNotifier::BlockingDecision::eAllow, + disabled ? AntiTrackingCommon::BlockingDecision::eBlock + : AntiTrackingCommon::BlockingDecision::eAllow, aRejectedReason); } else if (aChannel) { - ContentBlockingNotifier::OnDecision( + AntiTrackingCommon::NotifyBlockingDecision( aChannel, - disabled ? ContentBlockingNotifier::BlockingDecision::eBlock - : ContentBlockingNotifier::BlockingDecision::eAllow, + disabled ? AntiTrackingCommon::BlockingDecision::eBlock + : AntiTrackingCommon::BlockingDecision::eAllow, aRejectedReason); } return disabled; diff --git a/toolkit/components/antitracking/StoragePrincipalHelper.cpp b/toolkit/components/antitracking/StoragePrincipalHelper.cpp index 12cd90ac4a25..dde64eac5e02 100644 --- a/toolkit/components/antitracking/StoragePrincipalHelper.cpp +++ b/toolkit/components/antitracking/StoragePrincipalHelper.cpp @@ -7,7 +7,7 @@ #include "StoragePrincipalHelper.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" -#include "mozilla/ContentBlocking.h" +#include "mozilla/AntiTrackingCommon.h" #include "mozilla/ScopeExit.h" #include "mozilla/StorageAccess.h" #include "nsContentUtils.h" @@ -32,12 +32,13 @@ bool ChooseOriginAttributes(nsIChannel* aChannel, OriginAttributes& aAttrs) { } uint32_t rejectedReason = 0; - if (ContentBlocking::ShouldAllowAccessFor(aChannel, uri, &rejectedReason)) { + if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor( + aChannel, uri, &rejectedReason)) { return false; } // Let's use the storage principal only if we need to partition the cookie - // jar. We use the lower-level ContentBlocking API here to ensure this + // jar. We use the lower-level AntiTrackingCommon API here to ensure this // check doesn't send notifications. if (!ShouldPartitionStorage(rejectedReason) || !StoragePartitioningEnabled(rejectedReason, cjs)) { diff --git a/toolkit/components/antitracking/StoragePrincipalHelper.h b/toolkit/components/antitracking/StoragePrincipalHelper.h index ba88165420df..314bdc05d8c3 100644 --- a/toolkit/components/antitracking/StoragePrincipalHelper.h +++ b/toolkit/components/antitracking/StoragePrincipalHelper.h @@ -7,8 +7,6 @@ #ifndef mozilla_StoragePrincipalHelper_h #define mozilla_StoragePrincipalHelper_h -#include "nsError.h" - /** * StoragePrincipal * ~~~~~~~~~~~~~~~~ diff --git a/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp b/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp deleted file mode 100644 index 383b7bd4117c..000000000000 --- a/toolkit/components/antitracking/TemporaryAccessGrantObserver.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#include "TemporaryAccessGrantObserver.h" - -#include "nsIObserverService.h" -#include "nsPermissionManager.h" -#include "nsTHashtable.h" -#include "nsXULAppAPI.h" - -using namespace mozilla; - -UniquePtr - TemporaryAccessGrantObserver::sObservers; - -TemporaryAccessGrantObserver::TemporaryAccessGrantObserver( - nsPermissionManager* aPM, nsIPrincipal* aPrincipal, const nsACString& aType) - : mPM(aPM), mPrincipal(aPrincipal), mType(aType) { - MOZ_ASSERT(XRE_IsParentProcess(), - "Enforcing temporary access grant lifetimes can only be done in " - "the parent process"); -} - -NS_IMPL_ISUPPORTS(TemporaryAccessGrantObserver, nsIObserver) - -// static -void TemporaryAccessGrantObserver::Create(nsPermissionManager* aPM, - nsIPrincipal* aPrincipal, - const nsACString& aType) { - MOZ_ASSERT(XRE_IsParentProcess()); - - if (!sObservers) { - sObservers = MakeUnique(); - } - Unused << sObservers - ->LookupForAdd(MakePair(nsCOMPtr(aPrincipal), - nsCString(aType))) - .OrInsert([&]() -> nsITimer* { - // Only create a new observer if we don't have a matching - // entry in our hashtable. - nsCOMPtr timer; - RefPtr observer = - new TemporaryAccessGrantObserver(aPM, aPrincipal, aType); - nsresult rv = - NS_NewTimerWithObserver(getter_AddRefs(timer), observer, - 24 * 60 * 60 * 1000, // 24 hours - nsITimer::TYPE_ONE_SHOT); - - if (NS_SUCCEEDED(rv)) { - observer->SetTimer(timer); - return timer; - } - timer->Cancel(); - return nullptr; - }); -} - -void TemporaryAccessGrantObserver::SetTimer(nsITimer* aTimer) { - mTimer = aTimer; - nsCOMPtr observerService = - mozilla::services::GetObserverService(); - if (observerService) { - observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false); - } -} - -NS_IMETHODIMP -TemporaryAccessGrantObserver::Observe(nsISupports* aSubject, const char* aTopic, - const char16_t* aData) { - if (strcmp(aTopic, NS_TIMER_CALLBACK_TOPIC) == 0) { - Unused << mPM->RemoveFromPrincipal(mPrincipal, mType); - - MOZ_ASSERT(sObservers); - sObservers->Remove(MakePair(mPrincipal, mType)); - } else if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) { - nsCOMPtr observerService = - mozilla::services::GetObserverService(); - if (observerService) { - observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); - } - if (mTimer) { - mTimer->Cancel(); - mTimer = nullptr; - } - sObservers.reset(); - } - - return NS_OK; -} diff --git a/toolkit/components/antitracking/TemporaryAccessGrantObserver.h b/toolkit/components/antitracking/TemporaryAccessGrantObserver.h deleted file mode 100644 index 1c5acfdafb84..000000000000 --- a/toolkit/components/antitracking/TemporaryAccessGrantObserver.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* 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/. */ - -#ifndef mozilla_temporaryaccessgrantobserver_h -#define mozilla_temporaryaccessgrantobserver_h - -#include "mozilla/BasePrincipal.h" -#include "nsCOMPtr.h" -#include "nsHashKeys.h" -#include "nsIObserver.h" -#include "nsString.h" -#include "PLDHashTable.h" - -template -class nsDataHashtable; -class nsITimer; -class nsPermissionManager; -class TemporaryAccessGrantCacheKey; - -namespace mozilla { - -class TemporaryAccessGrantCacheKey : public PLDHashEntryHdr { - public: - typedef Pair, nsCString> KeyType; - typedef const KeyType* KeyTypePointer; - - explicit TemporaryAccessGrantCacheKey(KeyTypePointer aKey) - : mPrincipal(aKey->first()), mType(aKey->second()) {} - TemporaryAccessGrantCacheKey(TemporaryAccessGrantCacheKey&& aOther) = default; - - ~TemporaryAccessGrantCacheKey() = default; - - KeyType GetKey() const { return MakePair(mPrincipal, mType); } - bool KeyEquals(KeyTypePointer aKey) const { - return !!mPrincipal == !!aKey->first() && mType == aKey->second() && - (mPrincipal ? (mPrincipal->Equals(aKey->first())) : true); - } - - static KeyTypePointer KeyToPointer(KeyType& aKey) { return &aKey; } - static PLDHashNumber HashKey(KeyTypePointer aKey) { - if (!aKey) { - return 0; - } - - BasePrincipal* bp = BasePrincipal::Cast(aKey->first()); - return HashGeneric(bp->GetOriginNoSuffixHash(), bp->GetOriginSuffixHash(), - HashString(aKey->second())); - } - - enum { ALLOW_MEMMOVE = true }; - - private: - nsCOMPtr mPrincipal; - nsCString mType; -}; - -class TemporaryAccessGrantObserver final : public nsIObserver { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - - static void Create(nsPermissionManager* aPM, nsIPrincipal* aPrincipal, - const nsACString& aType); - - void SetTimer(nsITimer* aTimer); - - private: - TemporaryAccessGrantObserver(nsPermissionManager* aPM, - nsIPrincipal* aPrincipal, - const nsACString& aType); - ~TemporaryAccessGrantObserver() = default; - - private: - typedef nsDataHashtable> - ObserversTable; - static UniquePtr sObservers; - nsCOMPtr mTimer; - RefPtr mPM; - nsCOMPtr mPrincipal; - nsCString mType; -}; - -} // namespace mozilla - -#endif // mozilla_temporaryaccessgrantobserver_h diff --git a/toolkit/components/antitracking/URLDecorationStripper.cpp b/toolkit/components/antitracking/URLDecorationStripper.cpp index 642f16a321ea..5122e89620a1 100644 --- a/toolkit/components/antitracking/URLDecorationStripper.cpp +++ b/toolkit/components/antitracking/URLDecorationStripper.cpp @@ -10,7 +10,6 @@ #include "mozilla/Preferences.h" #include "nsCharSeparatedTokenizer.h" #include "nsEffectiveTLDService.h" -#include "nsIURI.h" #include "nsIURIMutator.h" namespace { diff --git a/toolkit/components/antitracking/moz.build b/toolkit/components/antitracking/moz.build index 1be11297daaa..2c3e9ea1f878 100644 --- a/toolkit/components/antitracking/moz.build +++ b/toolkit/components/antitracking/moz.build @@ -31,31 +31,20 @@ XPCOM_MANIFESTS += [ ] EXPORTS.mozilla = [ + 'AntiTrackingCommon.h', 'AntiTrackingIPCUtils.h', - 'AntiTrackingRedirectHeuristic.h', - 'AntiTrackingUtils.h', - 'ContentBlocking.h', 'ContentBlockingAllowList.h', - 'ContentBlockingLog.h', - 'ContentBlockingNotifier.h', - 'ContentBlockingUserInteraction.h', 'StorageAccess.h', 'StoragePrincipalHelper.h', 'URLDecorationStripper.h', ] UNIFIED_SOURCES += [ - 'AntiTrackingRedirectHeuristic.cpp', - 'AntiTrackingUtils.cpp', - 'ContentBlocking.cpp', + 'AntiTrackingCommon.cpp', 'ContentBlockingAllowList.cpp', - 'ContentBlockingLog.cpp', - 'ContentBlockingNotifier.cpp', - 'ContentBlockingUserInteraction.cpp', 'SettingsChangeObserver.cpp', 'StorageAccess.cpp', 'StoragePrincipalHelper.cpp', - 'TemporaryAccessGrantObserver.cpp', 'URLDecorationStripper.cpp', ] diff --git a/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp b/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp index ee8d41d91b63..6696e2c5ddb4 100644 --- a/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp +++ b/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp @@ -6,7 +6,7 @@ #include "core/TelemetryOrigin.h" #include "gtest/gtest.h" #include "gmock/gmock.h" -#include "mozilla/ContentBlockingLog.h" +#include "mozilla/dom/ContentBlockingLog.h" #include "mozilla/Services.h" #include "mozilla/Telemetry.h" #include "mozilla/Unused.h" @@ -48,7 +48,7 @@ TEST_F(TelemetryTestFixture, RecordOrigin) { Unused << mTelemetry->ClearOrigins(); Telemetry::RecordOrigin(OriginMetricID::TelemetryTest_Test1, - mozilla::ContentBlockingLog::kDummyOriginHash); + mozilla::dom::ContentBlockingLog::kDummyOriginHash); JS::RootedValue originSnapshot(aCx); GetOriginSnapshot(aCx, &originSnapshot); @@ -65,7 +65,7 @@ TEST_F(TelemetryTestFixture, RecordOrigin) { JS::RootedObject originsObj(aCx, &origins.toObject()); JS::RootedValue count(aCx); ASSERT_TRUE(JS_GetProperty( - aCx, originsObj, mozilla::ContentBlockingLog::kDummyOriginHash.get(), + aCx, originsObj, mozilla::dom::ContentBlockingLog::kDummyOriginHash.get(), &count)); ASSERT_TRUE(count.isInt32() && count.toInt32() == 1) << "Must have recorded the origin exactly once.";