Bug 1522210 - Fingerprinting and cryptomining classifiers must have separate nsIWebProgressListener blocking state codes - part 5 - generalize content blocking notification, r=ehsan

Differential Revision: https://phabricator.services.mozilla.com/D17838
This commit is contained in:
Andrea Marchesini 2019-01-28 16:44:38 +01:00
Родитель bf8c0e40e2
Коммит e9ac7d9ef2
17 изменённых файлов: 44 добавлений и 30 удалений

Просмотреть файл

@ -42,7 +42,7 @@ SimpleChannelParent::NotifyCookieAllowed() {
}
NS_IMETHODIMP
SimpleChannelParent::NotifyTrackingCookieBlocked(uint32_t aRejectedReason) {
SimpleChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) {
// Nothing to do.
return NS_OK;
}

Просмотреть файл

@ -45,7 +45,7 @@ interface nsIParentChannel : nsIStreamListener
* Called to notify the HttpChannelChild that cookie has been blocked for
* this load.
*/
[noscript] void notifyTrackingCookieBlocked(in uint32_t aRejectedReason);
[noscript] void notifyCookieBlocked(in uint32_t aRejectedReason);
/**
* Called to notify the HttpChannelChild that flash plugin state has changed.

Просмотреть файл

@ -42,7 +42,7 @@ DataChannelParent::NotifyCookieAllowed() {
}
NS_IMETHODIMP
DataChannelParent::NotifyTrackingCookieBlocked(uint32_t aRejectedReason) {
DataChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) {
// Nothing to do.
return NS_OK;
}

Просмотреть файл

@ -42,7 +42,7 @@ FileChannelParent::NotifyCookieAllowed() {
}
NS_IMETHODIMP
FileChannelParent::NotifyTrackingCookieBlocked(uint32_t aRejectedReason) {
FileChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) {
// Nothing to do.
return NS_OK;
}

Просмотреть файл

@ -513,7 +513,7 @@ FTPChannelParent::NotifyCookieAllowed() {
}
NS_IMETHODIMP
FTPChannelParent::NotifyTrackingCookieBlocked(uint32_t aRejectedReason) {
FTPChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) {
// One day, this should probably be filled in.
return NS_OK;
}

Просмотреть файл

@ -327,10 +327,10 @@ IPCResult HttpBackgroundChannelChild::RecvNotifyCookieAllowed() {
return IPC_OK();
}
IPCResult HttpBackgroundChannelChild::RecvNotifyTrackingCookieBlocked(
IPCResult HttpBackgroundChannelChild::RecvNotifyCookieBlocked(
const uint32_t& aRejectedReason) {
LOG(
("HttpBackgroundChannelChild::RecvNotifyTrackingCookieBlocked [this=%p "
("HttpBackgroundChannelChild::RecvNotifyCookieBlocked [this=%p "
"aRejectedReason=%" PRIu32 "]\n",
this, aRejectedReason));
MOZ_ASSERT(OnSocketThread());
@ -339,7 +339,7 @@ IPCResult HttpBackgroundChannelChild::RecvNotifyTrackingCookieBlocked(
return IPC_OK();
}
mChannelChild->ProcessNotifyTrackingCookieBlocked(aRejectedReason);
mChannelChild->ProcessNotifyCookieBlocked(aRejectedReason);
return IPC_OK();
}

Просмотреть файл

@ -68,8 +68,7 @@ class HttpBackgroundChannelChild final : public PHttpBackgroundChannelChild {
IPCResult RecvNotifyCookieAllowed() override;
IPCResult RecvNotifyTrackingCookieBlocked(
const uint32_t& aRejectedReason) override;
IPCResult RecvNotifyCookieBlocked(const uint32_t& aRejectedReason) override;
IPCResult RecvNotifyTrackingResource(const bool& aIsThirdParty) override;

Просмотреть файл

@ -374,10 +374,10 @@ bool HttpBackgroundChannelParent::OnNotifyCookieAllowed() {
return SendNotifyCookieAllowed();
}
bool HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked(
bool HttpBackgroundChannelParent::OnNotifyCookieBlocked(
uint32_t aRejectedReason) {
LOG(
("HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked [this=%p "
("HttpBackgroundChannelParent::OnNotifyCookieBlocked [this=%p "
"aRejectedReason=%" PRIu32 "]\n",
this, aRejectedReason));
AssertIsInMainProcess();
@ -391,9 +391,9 @@ bool HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked(
RefPtr<HttpBackgroundChannelParent> self = this;
nsresult rv = mBackgroundThread->Dispatch(
NS_NewRunnableFunction(
"net::HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked",
"net::HttpBackgroundChannelParent::OnNotifyCookieBlocked",
[self, aRejectedReason]() {
self->OnNotifyTrackingCookieBlocked(aRejectedReason);
self->OnNotifyCookieBlocked(aRejectedReason);
}),
NS_DISPATCH_NORMAL);
@ -402,7 +402,7 @@ bool HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked(
return NS_SUCCEEDED(rv);
}
return SendNotifyTrackingCookieBlocked(aRejectedReason);
return SendNotifyCookieBlocked(aRejectedReason);
}
bool HttpBackgroundChannelParent::OnNotifyTrackingResource(bool aIsThirdParty) {

Просмотреть файл

@ -70,8 +70,8 @@ class HttpBackgroundChannelParent final : public PHttpBackgroundChannelParent {
// To send NotifyCookieAllowed message over background channel.
bool OnNotifyCookieAllowed();
// To send NotifyTrackingCookieBlocked message over background channel.
bool OnNotifyTrackingCookieBlocked(uint32_t aRejectedReason);
// To send NotifyCookieBlocked message over background channel.
bool OnNotifyCookieBlocked(uint32_t aRejectedReason);
// To send NotifyTrackingResource message over background channel.
bool OnNotifyTrackingResource(bool aIsThirdParty);

Просмотреть файл

@ -1843,10 +1843,8 @@ void HttpChannelChild::ProcessNotifyCookieAllowed() {
NS_DISPATCH_NORMAL);
}
void HttpChannelChild::ProcessNotifyTrackingCookieBlocked(
uint32_t aRejectedReason) {
LOG(("HttpChannelChild::ProcessNotifyTrackingCookieBlocked [this=%p]\n",
this));
void HttpChannelChild::ProcessNotifyCookieBlocked(uint32_t aRejectedReason) {
LOG(("HttpChannelChild::ProcessNotifyCookieBlocked [this=%p]\n", this));
MOZ_ASSERT(OnSocketThread());
RefPtr<HttpChannelChild> self = this;

Просмотреть файл

@ -264,7 +264,7 @@ class HttpChannelChild final : public PHttpChannelChild,
void ProcessNotifyChannelClassifierProtectionDisabled(
uint32_t aAcceptedReason);
void ProcessNotifyCookieAllowed();
void ProcessNotifyTrackingCookieBlocked(uint32_t aRejectedReason);
void ProcessNotifyCookieBlocked(uint32_t aRejectedReason);
void ProcessNotifyTrackingResource(bool aIsThirdParty);
void ProcessNotifyFlashPluginStateChanged(
nsIHttpChannel::FlashPluginState aState);

Просмотреть файл

@ -1812,12 +1812,11 @@ HttpChannelParent::NotifyCookieAllowed() {
}
NS_IMETHODIMP
HttpChannelParent::NotifyTrackingCookieBlocked(uint32_t aRejectedReason) {
LOG(("HttpChannelParent::NotifyTrackingCookieBlocked [this=%p]\n", this));
HttpChannelParent::NotifyCookieBlocked(uint32_t aRejectedReason) {
LOG(("HttpChannelParent::NotifyCookieBlocked [this=%p]\n", this));
if (!mIPCClosed) {
MOZ_ASSERT(mBgParent);
Unused << NS_WARN_IF(
!mBgParent->OnNotifyTrackingCookieBlocked(aRejectedReason));
Unused << NS_WARN_IF(!mBgParent->OnNotifyCookieBlocked(aRejectedReason));
}
return NS_OK;
}

Просмотреть файл

@ -62,7 +62,7 @@ child:
async NotifyCookieAllowed();
// Tell the child that tracking cookies are blocked for this load.
async NotifyTrackingCookieBlocked(uint32_t aRejectedReason);
async NotifyCookieBlocked(uint32_t aRejectedReason);
// Tell the child that the resource being loaded is on the tracking
// protection list.

Просмотреть файл

@ -209,12 +209,16 @@ namespace {
struct BlockingErrorCode {
nsresult mErrorCode;
uint32_t mBlockingEventCode;
uint32_t mAllowingEventCode;
const char* mConsoleMessage;
nsCString mConsoleCategory;
};
static const BlockingErrorCode sBlockingErrorCodes[] = {
{NS_ERROR_TRACKING_URI, "TrackerUriBlocked",
{NS_ERROR_TRACKING_URI,
nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT,
nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT, "TrackerUriBlocked",
NS_LITERAL_CSTRING("Tracking Protection")},
};
@ -233,6 +237,16 @@ static const BlockingErrorCode sBlockingErrorCodes[] = {
return false;
}
/* static */ bool UrlClassifierFeatureFactory::IsClassifierBlockingEventCode(
uint32_t aEventCode) {
for (const auto& blockingErrorCode : sBlockingErrorCodes) {
if (aEventCode == blockingErrorCode.mBlockingEventCode) {
return true;
}
}
return false;
}
/* static */ const char*
UrlClassifierFeatureFactory::ClassifierBlockingErrorCodeToConsoleMessage(
nsresult aError, nsACString& aCategory) {

Просмотреть файл

@ -41,6 +41,10 @@ class UrlClassifierFeatureFactory final {
// Returns true if this error is known as one of the blocking error codes.
static bool IsClassifierBlockingErrorCode(nsresult aError);
// Returns true if this event is a known blocking state from
// nsIWebProgressListener.
static bool IsClassifierBlockingEventCode(uint32_t aEventCode);
// This can be called only if IsClassifierBlockingErrorCode(aError) returns
// true.
static const char* ClassifierBlockingErrorCodeToConsoleMessage(

Просмотреть файл

@ -1502,7 +1502,7 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
// This channel is a parent-process proxy for a child process request.
// Tell the child process channel to do this instead.
if (aDecision == BlockingDecision::eBlock) {
parentChannel->NotifyTrackingCookieBlocked(aRejectedReason);
parentChannel->NotifyCookieBlocked(aRejectedReason);
} else {
parentChannel->NotifyCookieAllowed();
}

Просмотреть файл

@ -399,7 +399,7 @@ NS_IMETHODIMP nsExtProtocolChannel::NotifyCookieAllowed() {
return NS_OK;
}
NS_IMETHODIMP nsExtProtocolChannel::NotifyTrackingCookieBlocked(
NS_IMETHODIMP nsExtProtocolChannel::NotifyCookieBlocked(
uint32_t aRejectedReason) {
// nothing to do
return NS_OK;