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
This commit is contained in:
Noemi Erli 2020-03-09 19:19:41 +02:00
parent 5cbd62da48
commit a48fac9e3b
74 changed files with 1407 additions and 1622 deletions

View File

@ -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

View File

@ -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

View File

@ -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<uint32_t> ContentBlockingLog::RecordLogParent(
const nsACString& aOrigin, uint32_t aType, bool aBlocked,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason,
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason,
const nsTArray<nsCString>& aTrackingFullHashes) {
MOZ_ASSERT(XRE_IsParentProcess());
@ -291,4 +293,5 @@ void ContentBlockingLog::ReportOrigins() {
}
}
} // namespace dom
} // namespace mozilla

View File

@ -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<ContentBlockingNotifier::StorageAccessGrantedReason> mReason;
Maybe<AntiTrackingCommon::StorageAccessGrantedReason> mReason;
nsTArray<nsCString> mTrackingFullHashes;
};
@ -88,12 +87,12 @@ class ContentBlockingLog final {
// ContentBlockingLog from content processes.
Maybe<uint32_t> RecordLogParent(
const nsACString& aOrigin, uint32_t aType, bool aBlocked,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason,
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason,
const nsTArray<nsCString>& aTrackingFullHashes);
void RecordLog(
const nsACString& aOrigin, uint32_t aType, bool aBlocked,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason,
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason,
const nsTArray<nsCString>& 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<ContentBlockingNotifier::StorageAccessGrantedReason>&
aReason = Nothing(),
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason =
Nothing(),
const nsTArray<nsCString>& aTrackingFullHashes = nsTArray<nsCString>()) {
DebugOnly<bool> isCookiesBlockedTracker =
aType == nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER ||
@ -425,6 +424,7 @@ class ContentBlockingLog final {
OriginDataTable mLog;
};
} // namespace dom
} // namespace mozilla
#endif

View File

@ -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> 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<mozilla::dom::Promise> Document::RequestStorageAccess(
RefPtr<Document> self(this);
auto performFinalChecks =
[inner,
self]() -> RefPtr<ContentBlocking::StorageAccessFinalCheckPromise> {
RefPtr<ContentBlocking::StorageAccessFinalCheckPromise::Private> p =
new ContentBlocking::StorageAccessFinalCheckPromise::Private(
auto performFinalChecks = [inner, self]()
-> RefPtr<AntiTrackingCommon::StorageAccessFinalCheckPromise> {
RefPtr<AntiTrackingCommon::StorageAccessFinalCheckPromise::Private> p =
new AntiTrackingCommon::StorageAccessFinalCheckPromise::Private(
__func__);
RefPtr<StorageAccessPermissionRequest> sapr =
StorageAccessPermissionRequest::Create(
@ -15652,7 +15649,7 @@ already_AddRefed<mozilla::dom::Promise> 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<mozilla::dom::Promise> 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<mozilla::dom::Promise> 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();
}

View File

@ -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"

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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',

View File

@ -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"

View File

@ -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

View File

@ -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);
}
//*****************************************************************************

View File

@ -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"

View File

@ -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"

View File

@ -4048,7 +4048,7 @@ void BrowserChild::NotifyContentBlockingEvent(
uint32_t aEvent, nsIChannel* aChannel, bool aBlocked,
const nsACString& aTrackingOrigin,
const nsTArray<nsCString>& aTrackingFullHashes,
const Maybe<mozilla::ContentBlockingNotifier::StorageAccessGrantedReason>&
const Maybe<mozilla::AntiTrackingCommon::StorageAccessGrantedReason>&
aReason) {
if (!IPCOpen()) {
return;

View File

@ -699,8 +699,7 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
uint32_t aEvent, nsIChannel* aChannel, bool aBlocked,
const nsACString& aTrackingOrigin,
const nsTArray<nsCString>& aTrackingFullHashes,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>&
aReason);
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason);
protected:
virtual ~BrowserChild();

View File

@ -2695,7 +2695,7 @@ mozilla::ipc::IPCResult BrowserParent::RecvNotifyContentBlockingEvent(
const uint32_t& aEvent, const RequestData& aRequestData,
const bool aBlocked, const nsACString& aTrackingOrigin,
nsTArray<nsCString>&& aTrackingFullHashes,
const Maybe<mozilla::ContentBlockingNotifier::StorageAccessGrantedReason>&
const Maybe<mozilla::AntiTrackingCommon::StorageAccessGrantedReason>&
aReason) {
MOZ_ASSERT(aRequestData.elapsedLoadTimeMS().isNothing());

View File

@ -317,7 +317,7 @@ class BrowserParent final : public PBrowserParent,
const uint32_t& aEvent, const RequestData& aRequestData,
const bool aBlocked, const nsACString& aTrackingOrigin,
nsTArray<nsCString>&& aTrackingFullHashes,
const Maybe<mozilla::ContentBlockingNotifier::StorageAccessGrantedReason>&
const Maybe<mozilla::AntiTrackingCommon::StorageAccessGrantedReason>&
aReason);
mozilla::ipc::IPCResult RecvNavigationFinished();

View File

@ -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();
}

View File

@ -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 {

View File

@ -311,7 +311,7 @@ void WindowGlobalParent::NotifyContentBlockingEvent(
uint32_t aEvent, nsIRequest* aRequest, bool aBlocked,
const nsACString& aTrackingOrigin,
const nsTArray<nsCString>& aTrackingFullHashes,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason) {
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason) {
MOZ_ASSERT(NS_IsMainThread());
DebugOnly<bool> isCookiesBlockedTracker =
aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER ||

View File

@ -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<nsCString>& aTrackingFullHashes,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>&
aReason = Nothing());
const Maybe<AntiTrackingCommon::StorageAccessGrantedReason>& aReason =
Nothing());
ContentBlockingLog* GetContentBlockingLog() { return &mContentBlockingLog; }

View File

@ -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"

View File

@ -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"

View File

@ -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.)

View File

@ -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"

View File

@ -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"

View File

@ -7,7 +7,7 @@
#include <utility>
#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();

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -9,6 +9,7 @@
#include "nsNetUtil.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/Atomics.h"
#include "mozilla/Encoding.h"
#include "mozilla/LoadContext.h"

View File

@ -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"

View File

@ -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

View File

@ -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<nsIURI> uriBeingLoaded =
AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(mChannel);
AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded(mChannel);
CanonicalBrowsingContext* bc = GetBrowsingContext();
RefPtr<WindowGlobalParent> topWindow =
GetTopWindowExcludingExtensionAccessibleContentFrames(bc, uriBeingLoaded);

View File

@ -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;
}

View File

@ -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<HttpBaseChannel> 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();
}

View File

@ -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<nsIURI> uriBeingLoaded =
AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(this);
AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded(this);
return GetTopWindowURI(uriBeingLoaded, aTopWindowURI);
}

View File

@ -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"

View File

@ -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;
}

View File

@ -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<nsAsyncRedirectVerifyHelper> redirectCallbackHelper =

View File

@ -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<nsIURI> uriBeingLoaded =
AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(channel);
AntiTrackingCommon::MaybeGetDocumentURIBeingLoaded(channel);
nsCOMPtr<mozIDOMWindowProxy> 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 &&

View File

@ -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 <vector>

View File

@ -11,6 +11,7 @@
#include "nsIUrlClassifierSkipListService.h"
#include "nsTArray.h"
#include "nsString.h"
#include "mozilla/AntiTrackingCommon.h"
namespace mozilla {
namespace net {

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureCryptominingAnnotation.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "nsIClassifiedChannel.h"
#include "nsContentUtils.h"

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureCryptominingProtection.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "nsContentUtils.h"

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureFingerprintingAnnotation.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "nsIClassifiedChannel.h"
#include "nsContentUtils.h"

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureFingerprintingProtection.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "nsContentUtils.h"

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureSocialTrackingAnnotation.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "nsIClassifiedChannel.h"
#include "nsContentUtils.h"

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureSocialTrackingProtection.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/StaticPrefs_privacy.h"
#include "nsContentUtils.h"

View File

@ -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"

View File

@ -6,6 +6,7 @@
#include "UrlClassifierFeatureTrackingProtection.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "nsContentUtils.h"
#include "nsIHttpChannelInternal.h"

View File

@ -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<void(const bool&)>
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<int, bool, true> StorageAccessFinalCheckPromise;
typedef std::function<RefPtr<StorageAccessFinalCheckPromise>()>
PerformFinalChecks;
typedef MozPromise<int, bool, true> StorageAccessGrantPromise;
static MOZ_MUST_USE RefPtr<StorageAccessGrantPromise>
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<nsresult, bool, true> FirstPartyStorageAccessGrantPromise;
static RefPtr<FirstPartyStorageAccessGrantPromise>
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<nsIURI> 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<StorageAccessGrantedReason>& aReason = Nothing());
static void RedirectHeuristic(nsIChannel* aOldChannel, nsIURI* aOldURI,
nsIChannel* aNewChannel, nsIURI* aNewURI);
};
} // namespace mozilla
#endif // mozilla_antitrackingservice_h

View File

@ -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<mozilla::ContentBlockingNotifier::StorageAccessGrantedReason>
struct ParamTraits<mozilla::AntiTrackingCommon::StorageAccessGrantedReason>
: 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

View File

@ -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<nsIHttpChannel> newChannel = do_QueryInterface(aNewChannel);
if (!newChannel) {
return;
}
LOG_SPEC(("Checking redirect-heuristic for %s", _spec), aOldURI);
nsCOMPtr<nsILoadInfo> oldLoadInfo = aOldChannel->LoadInfo();
MOZ_ASSERT(oldLoadInfo);
nsCOMPtr<nsILoadInfo> 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<nsIClassifiedChannel> classifiedOldChannel =
do_QueryInterface(aOldChannel);
nsCOMPtr<nsIClassifiedChannel> 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<nsIPrincipal> trackingPrincipal;
const nsTArray<nsCOMPtr<nsIRedirectHistoryEntry>>& 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<nsIPrincipal> 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<nsICookieJarSettings> 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<nsString, 2> 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<ContentBlocking::ParentAccessGrantPromise> promise =
ContentBlocking::SaveAccessForOriginOnParentProcess(
redirectedPrincipal, trackingPrincipal, trackingOrigin,
ContentBlocking::StorageAccessPromptChoices::eAllow,
StaticPrefs::privacy_restrict3rdpartystorage_expiration_redirect());
Unused << promise;
}
} // namespace mozilla

View File

@ -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

View File

@ -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<nsPIDOMWindowOuter>
AntiTrackingUtils::GetTopWindow(nsPIDOMWindowInner* aWindow) {
Document* document = aWindow->GetExtantDoc();
if (!document) {
return nullptr;
}
nsIChannel* channel = document->GetChannel();
if (!channel) {
return nullptr;
}
nsCOMPtr<nsPIDOMWindowOuter> pwin =
aWindow->GetBrowsingContext()->Top()->GetDOMWindow();
if (!pwin) {
return nullptr;
}
return pwin.forget();
}
/* static */
already_AddRefed<nsIURI> AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(
nsIChannel* aChannel) {
nsCOMPtr<nsIURI> 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);
}

View File

@ -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<nsPIDOMWindowOuter> GetTopWindow(
nsPIDOMWindowInner* aWindow);
// Get the current document URI from a document channel as it is being loaded.
static already_AddRefed<nsIURI> 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

View File

@ -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<int, bool, true> StorageAccessFinalCheckPromise;
typedef std::function<RefPtr<StorageAccessFinalCheckPromise>()>
PerformFinalChecks;
typedef MozPromise<int, bool, true> StorageAccessGrantPromise;
static MOZ_MUST_USE RefPtr<StorageAccessGrantPromise> AllowAccessFor(
nsIPrincipal* aPrincipal, nsPIDOMWindowInner* aParentWindow,
ContentBlockingNotifier::StorageAccessGrantedReason aReason,
const PerformFinalChecks& aPerformFinalChecks = nullptr);
// For IPC only.
typedef MozPromise<nsresult, bool, true> ParentAccessGrantPromise;
static RefPtr<ParentAccessGrantPromise> SaveAccessForOriginOnParentProcess(
nsIPrincipal* aPrincipal, nsIPrincipal* aTrackingPrinciapl,
const nsCString& aTrackingOrigin, int aAllowMode,
uint64_t aExpirationTime =
StaticPrefs::privacy_restrict3rdpartystorage_expiration());
};
} // namespace mozilla
#endif // mozilla_antitrackingservice_h

View File

@ -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

View File

@ -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<nsIRunnable>&& 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<nsIRunnable> 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<nsIURI> uri(aURI);
RefPtr<Runnable> 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<nsIURIFixup> urifixup = services::GetURIFixup();
NS_ENSURE_TRUE_VOID(urifixup);
nsCOMPtr<nsIURI> exposableURI;
nsresult rv =
urifixup->CreateExposableURI(uri, getter_AddRefs(exposableURI));
NS_ENSURE_SUCCESS_VOID(rv);
AutoTArray<nsString, 1> 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<nsILoadInfo> loadInfo = aChannel->LoadInfo();
RefPtr<dom::BrowsingContext> bc;
loadInfo->GetBrowsingContext(getter_AddRefs(bc));
if (!bc || bc->IsDiscarded()) {
return;
}
bc = bc->Top();
RefPtr<dom::WindowGlobalParent> wgp =
bc->Canonical()->GetCurrentWindowGlobal();
if (!wgp) {
return;
}
windowID = wgp->InnerWindowId();
} else {
nsresult rv;
nsCOMPtr<nsIHttpChannel> 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<nsIClassifiedChannel> 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<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason) {
MOZ_ASSERT(XRE_IsContentProcess());
MOZ_ASSERT(aWindow);
RefPtr<dom::BrowserChild> browserChild = dom::BrowserChild::GetFrom(aWindow);
NS_ENSURE_TRUE_VOID(browserChild);
nsTArray<nsCString> trackingFullHashes;
nsCOMPtr<nsIClassifiedChannel> 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<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason) {
MOZ_ASSERT(XRE_IsParentProcess());
nsCOMPtr<nsILoadInfo> loadInfo = aReportingChannel->LoadInfo();
RefPtr<dom::BrowsingContext> bc;
loadInfo->GetBrowsingContext(getter_AddRefs(bc));
if (!bc || bc->IsDiscarded()) {
return;
}
bc = bc->Top();
RefPtr<dom::WindowGlobalParent> wgp =
bc->Canonical()->GetCurrentWindowGlobal();
NS_ENSURE_TRUE_VOID(wgp);
nsTArray<nsCString> trackingFullHashes;
nsCOMPtr<nsIClassifiedChannel> 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<nsIPrincipal> principal =
nsGlobalWindowInner::Cast(aWindow)->GetPrincipal();
if (NS_WARN_IF(!principal)) {
return;
}
RefPtr<Document> 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> 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<nsString, 3> 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<nsIURI> 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<mozIThirdPartyUtil> thirdPartyUtil = services::GetThirdPartyUtil();
if (!thirdPartyUtil) {
return;
}
nsCOMPtr<nsIURI> uriBeingLoaded =
AntiTrackingUtils::MaybeGetDocumentURIBeingLoaded(aChannel);
nsCOMPtr<mozIDOMWindowProxy> win;
nsresult rv = thirdPartyUtil->GetTopWindowForChannel(aChannel, uriBeingLoaded,
getter_AddRefs(win));
NS_ENSURE_SUCCESS_VOID(rv);
nsCOMPtr<nsPIDOMWindowOuter> 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<nsPIDOMWindowOuter> 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<nsIURI> 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<StorageAccessGrantedReason>& aReason) {
if (XRE_IsParentProcess()) {
NotifyEventInParent(aReportingChannel, aTrackingChannel, aBlocked,
aRejectedReason, aTrackingOrigin, aReason);
} else {
NotifyEventInChild(aWindow, aReportingChannel, aTrackingChannel, aBlocked,
aRejectedReason, aTrackingOrigin, aReason);
}
}

View File

@ -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<StorageAccessGrantedReason>& aReason = Nothing());
static void ReportUnblockingToConsole(nsPIDOMWindowInner* aWindow,
const nsAString& aTrackingOrigin,
StorageAccessGrantedReason aReason);
};
} // namespace mozilla
#endif // mozilla_contentblockingnotifier_h

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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;

View File

@ -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)) {

View File

@ -7,8 +7,6 @@
#ifndef mozilla_StoragePrincipalHelper_h
#define mozilla_StoragePrincipalHelper_h
#include "nsError.h"
/**
* StoragePrincipal
* ~~~~~~~~~~~~~~~~

View File

@ -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::ObserversTable>
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<ObserversTable>();
}
Unused << sObservers
->LookupForAdd(MakePair(nsCOMPtr<nsIPrincipal>(aPrincipal),
nsCString(aType)))
.OrInsert([&]() -> nsITimer* {
// Only create a new observer if we don't have a matching
// entry in our hashtable.
nsCOMPtr<nsITimer> timer;
RefPtr<TemporaryAccessGrantObserver> 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<nsIObserverService> 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<nsIObserverService> 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;
}

View File

@ -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, class>
class nsDataHashtable;
class nsITimer;
class nsPermissionManager;
class TemporaryAccessGrantCacheKey;
namespace mozilla {
class TemporaryAccessGrantCacheKey : public PLDHashEntryHdr {
public:
typedef Pair<nsCOMPtr<nsIPrincipal>, 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<nsIPrincipal> 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<TemporaryAccessGrantCacheKey, nsCOMPtr<nsITimer>>
ObserversTable;
static UniquePtr<ObserversTable> sObservers;
nsCOMPtr<nsITimer> mTimer;
RefPtr<nsPermissionManager> mPM;
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCString mType;
};
} // namespace mozilla
#endif // mozilla_temporaryaccessgrantobserver_h

View File

@ -10,7 +10,6 @@
#include "mozilla/Preferences.h"
#include "nsCharSeparatedTokenizer.h"
#include "nsEffectiveTLDService.h"
#include "nsIURI.h"
#include "nsIURIMutator.h"
namespace {

View File

@ -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',
]

View File

@ -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.";