Bug 1493563 - Part 10: Implement the per-document blocked states in terms of the content blocking log; r=baku

It is arguably more accurate to implement these boolean
getters in terms of whether we remember blocking anything
in the category being asked about.  This will allow us to
correctly account for hiding the sheild icon when all
currently blocked trackers become unblocked, for example.

Differential Revision: https://phabricator.services.mozilla.com/D6600
This commit is contained in:
Ehsan Akhgari 2018-09-23 02:40:27 -04:00
parent 2f969011be
commit 214e30a710
3 changed files with 28 additions and 36 deletions

View File

@ -113,6 +113,22 @@ public:
return buffer;
}
bool HasBlockedAnyOfType(uint32_t aType)
{
for (auto iter = mLog.Iter(); !iter.Done(); iter.Next()) {
if (!iter.UserData()) {
continue;
}
for (auto& item: *iter.UserData()) {
if ((item.mType & aType) != 0) {
return true;
}
}
}
return false;
}
void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const
{
aSizes.mDOMOtherSize += mLog.ShallowSizeOfExcludingThis(aSizes.mState.mMallocSizeOf);

View File

@ -1403,12 +1403,6 @@ nsIDocument::nsIDocument()
mHasCSP(false),
mHasUnsafeEvalCSP(false),
mHasUnsafeInlineCSP(false),
mHasTrackingContentBlocked(false),
mHasSlowTrackingContentBlocked(false),
mHasAllCookiesBlocked(false),
mHasTrackingCookiesBlocked(false),
mHasForeignCookiesBlocked(false),
mHasCookiesBlockedByPermission(false),
mHasTrackingContentLoaded(false),
mBFCacheDisallowed(false),
mHasHadDefaultView(false),

View File

@ -992,7 +992,8 @@ public:
*/
bool GetHasTrackingContentBlocked()
{
return mHasTrackingContentBlocked;
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT);
}
/**
@ -1000,7 +1001,8 @@ public:
*/
bool GetHasSlowTrackingContentBlocked()
{
return mHasSlowTrackingContentBlocked;
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT);
}
/**
@ -1008,7 +1010,8 @@ public:
*/
bool GetHasAllCookiesBlocked()
{
return mHasAllCookiesBlocked;
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL);
}
/**
@ -1016,7 +1019,8 @@ public:
*/
bool GetHasTrackingCookiesBlocked()
{
return mHasTrackingCookiesBlocked;
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER);
}
/**
@ -1024,7 +1028,8 @@ public:
*/
bool GetHasForeignCookiesBlocked()
{
return mHasForeignCookiesBlocked;
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN);
}
/**
@ -1032,7 +1037,8 @@ public:
*/
bool GetHasCookiesBlockedByPermission()
{
return mHasCookiesBlockedByPermission;
return mContentBlockingLog.HasBlockedAnyOfType(
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION);
}
/**
@ -1041,7 +1047,6 @@ public:
void SetHasTrackingContentBlocked(bool aHasTrackingContentBlocked,
const nsAString& aOriginBlocked)
{
mHasTrackingContentBlocked = aHasTrackingContentBlocked;
RecordContentBlockingLog(aOriginBlocked,
nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT,
aHasTrackingContentBlocked);
@ -1053,7 +1058,6 @@ public:
void SetHasSlowTrackingContentBlocked(bool aHasSlowTrackingContentBlocked,
const nsAString& aOriginBlocked)
{
mHasSlowTrackingContentBlocked = aHasSlowTrackingContentBlocked;
RecordContentBlockingLog(aOriginBlocked,
nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT,
aHasSlowTrackingContentBlocked);
@ -1065,7 +1069,6 @@ public:
void SetHasAllCookiesBlocked(bool aHasAllCookiesBlocked,
const nsAString& aOriginBlocked)
{
mHasAllCookiesBlocked = aHasAllCookiesBlocked;
RecordContentBlockingLog(aOriginBlocked,
nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL,
aHasAllCookiesBlocked);
@ -1077,7 +1080,6 @@ public:
void SetHasTrackingCookiesBlocked(bool aHasTrackingCookiesBlocked,
const nsAString& aOriginBlocked)
{
mHasTrackingCookiesBlocked = aHasTrackingCookiesBlocked;
RecordContentBlockingLog(aOriginBlocked,
nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER,
aHasTrackingCookiesBlocked);
@ -1089,7 +1091,6 @@ public:
void SetHasForeignCookiesBlocked(bool aHasForeignCookiesBlocked,
const nsAString& aOriginBlocked)
{
mHasForeignCookiesBlocked = aHasForeignCookiesBlocked;
RecordContentBlockingLog(aOriginBlocked,
nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN,
aHasForeignCookiesBlocked);
@ -1101,7 +1102,6 @@ public:
void SetHasCookiesBlockedByPermission(bool aHasCookiesBlockedByPermission,
const nsAString& aOriginBlocked)
{
mHasCookiesBlockedByPermission = aHasCookiesBlockedByPermission;
RecordContentBlockingLog(aOriginBlocked,
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION,
aHasCookiesBlockedByPermission);
@ -4190,24 +4190,6 @@ protected:
// True if a document load has a CSP with unsafe-inline attached.
bool mHasUnsafeInlineCSP : 1;
// True if a document has blocked Tracking Content
bool mHasTrackingContentBlocked : 1;
// True if a document has blocked Slow Tracking Content
bool mHasSlowTrackingContentBlocked : 1;
// True if a document has blocked All Cookies
bool mHasAllCookiesBlocked : 1;
// True if a document has blocked Tracking Cookies
bool mHasTrackingCookiesBlocked : 1;
// True if a document has blocked Foreign Cookies
bool mHasForeignCookiesBlocked : 1;
// True if a document has blocked Cookies By Site Permission
bool mHasCookiesBlockedByPermission : 1;
// True if a document has loaded Tracking Content
bool mHasTrackingContentLoaded : 1;