Bug 1487093 - Propagate cookie blocking notification to child nsIChannel, r=ehsan, r=valentin

This commit is contained in:
Andrea Marchesini 2018-08-30 17:44:39 +02:00
Родитель 8ad0a3df62
Коммит 45cfa7f75c
15 изменённых файлов: 133 добавлений и 1 удалений

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

@ -38,6 +38,13 @@ SimpleChannelParent::NotifyTrackingProtectionDisabled()
return NS_OK;
}
NS_IMETHODIMP
SimpleChannelParent::NotifyTrackingCookieBlocked()
{
// Nothing to do.
return NS_OK;
}
NS_IMETHODIMP
SimpleChannelParent::NotifyTrackingResource(bool aIsThirdParty)
{

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

@ -34,6 +34,12 @@ interface nsIParentChannel : nsIStreamListener
*/
[noscript] void notifyTrackingProtectionDisabled();
/**
* Called to notify the HttpChannelChild that cookie has been blocked for
* this load.
*/
[noscript] void notifyTrackingCookieBlocked();
/**
* Called to set matched information when URL matches SafeBrowsing list.
* @param aList

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

@ -38,6 +38,13 @@ DataChannelParent::NotifyTrackingProtectionDisabled()
return NS_OK;
}
NS_IMETHODIMP
DataChannelParent::NotifyTrackingCookieBlocked()
{
// Nothing to do.
return NS_OK;
}
NS_IMETHODIMP
DataChannelParent::NotifyTrackingResource(bool aIsThirdParty)
{

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

@ -38,6 +38,13 @@ FileChannelParent::NotifyTrackingProtectionDisabled()
return NS_OK;
}
NS_IMETHODIMP
FileChannelParent::NotifyTrackingCookieBlocked()
{
// Nothing to do.
return NS_OK;
}
NS_IMETHODIMP
FileChannelParent::NotifyTrackingResource(bool aIsThirdParty)
{

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

@ -576,6 +576,13 @@ FTPChannelParent::NotifyTrackingProtectionDisabled()
return NS_OK;
}
NS_IMETHODIMP
FTPChannelParent::NotifyTrackingCookieBlocked()
{
// One day, this should probably be filled in.
return NS_OK;
}
NS_IMETHODIMP
FTPChannelParent::NotifyTrackingResource(bool aIsThirdParty)
{

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

@ -347,6 +347,21 @@ HttpBackgroundChannelChild::RecvNotifyTrackingProtectionDisabled()
return IPC_OK();
}
IPCResult
HttpBackgroundChannelChild::RecvNotifyTrackingCookieBlocked()
{
LOG(("HttpBackgroundChannelChild::RecvNotifyTrackingCookieBlocked [this=%p]\n", this));
MOZ_ASSERT(OnSocketThread());
if (NS_WARN_IF(!mChannelChild)) {
return IPC_OK();
}
mChannelChild->ProcessNotifyTrackingCookieBlocked();
return IPC_OK();
}
IPCResult
HttpBackgroundChannelChild::RecvNotifyTrackingResource(const bool& aIsThirdParty)
{

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

@ -65,6 +65,8 @@ protected:
IPCResult RecvNotifyTrackingProtectionDisabled() override;
IPCResult RecvNotifyTrackingCookieBlocked() override;
IPCResult RecvNotifyTrackingResource(const bool& aIsThirdParty) override;
IPCResult RecvSetClassifierMatchedInfo(const ClassifierInfo& info) override;

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

@ -379,6 +379,33 @@ HttpBackgroundChannelParent::OnNotifyTrackingProtectionDisabled()
return SendNotifyTrackingProtectionDisabled();
}
bool
HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked()
{
LOG(("HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked [this=%p]\n", this));
AssertIsInMainProcess();
if (NS_WARN_IF(!mIPCOpened)) {
return false;
}
if (!IsOnBackgroundThread()) {
MutexAutoLock lock(mBgThreadMutex);
nsresult rv = mBackgroundThread->Dispatch(
NewRunnableMethod(
"net::HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked",
this,
&HttpBackgroundChannelParent::OnNotifyTrackingCookieBlocked),
NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
return NS_SUCCEEDED(rv);
}
return SendNotifyTrackingCookieBlocked();
}
bool
HttpBackgroundChannelParent::OnNotifyTrackingResource(bool aIsThirdParty)
{

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

@ -69,6 +69,9 @@ public:
// To send NotifyTrackingProtectionDisabled message over background channel.
bool OnNotifyTrackingProtectionDisabled();
// To send NotifyTrackingCookieBlocked message over background channel.
bool OnNotifyTrackingCookieBlocked();
// To send NotifyTrackingResource message over background channel.
bool OnNotifyTrackingResource(bool aIsThirdParty);

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

@ -10,6 +10,7 @@
#include "nsHttp.h"
#include "nsICacheEntry.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/DocGroup.h"
@ -2039,6 +2040,23 @@ HttpChannelChild::ProcessNotifyTrackingProtectionDisabled()
NS_DISPATCH_NORMAL);
}
void
HttpChannelChild::ProcessNotifyTrackingCookieBlocked()
{
LOG(("HttpChannelChild::ProcessNotifyTrackingCookieBlocked [this=%p]\n", this));
MOZ_ASSERT(OnSocketThread());
RefPtr<HttpChannelChild> self = this;
nsCOMPtr<nsIEventTarget> neckoTarget = GetNeckoTarget();
neckoTarget->Dispatch(
NS_NewRunnableFunction(
"nsChannelClassifier::NotifyTrackingCookieBlocked",
[self]() {
AntiTrackingCommon::NotifyRejection(self);
}),
NS_DISPATCH_NORMAL);
}
void
HttpChannelChild::ProcessNotifyTrackingResource(bool aIsThirdParty)
{

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

@ -253,6 +253,7 @@ private:
void ProcessFlushedForDiversion();
void ProcessDivertMessages();
void ProcessNotifyTrackingProtectionDisabled();
void ProcessNotifyTrackingCookieBlocked();
void ProcessNotifyTrackingResource(bool aIsThirdParty);
void ProcessSetClassifierMatchedInfo(const nsCString& aList,
const nsCString& aProvider,

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

@ -1805,7 +1805,18 @@ HttpChannelParent::NotifyTrackingProtectionDisabled()
LOG(("HttpChannelParent::NotifyTrackingProtectionDisabled [this=%p]\n", this));
if (!mIPCClosed) {
MOZ_ASSERT(mBgParent);
Unused << mBgParent->OnNotifyTrackingProtectionDisabled();
Unused << NS_WARN_IF(!mBgParent->OnNotifyTrackingProtectionDisabled());
}
return NS_OK;
}
NS_IMETHODIMP
HttpChannelParent::NotifyTrackingCookieBlocked()
{
LOG(("HttpChannelParent::NotifyTrackingCookieBlocked [this=%p]\n", this));
if (!mIPCClosed) {
MOZ_ASSERT(mBgParent);
Unused << NS_WARN_IF(!mBgParent->OnNotifyTrackingCookieBlocked());
}
return NS_OK;
}

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

@ -56,6 +56,9 @@ child:
// Tell the child that tracking protection was disabled for this load.
async NotifyTrackingProtectionDisabled();
// Tell the child that tracking cookies are blocked for this load.
async NotifyTrackingCookieBlocked();
// Tell the child that the resource being loaded is on the tracking
// protection list.
async NotifyTrackingResource(bool aIsThirdParty);

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

@ -19,11 +19,13 @@
#include "nsICookieService.h"
#include "nsIHttpChannelInternal.h"
#include "nsIIOService.h"
#include "nsIParentChannel.h"
#include "nsIPermissionManager.h"
#include "nsIPrincipal.h"
#include "nsIURI.h"
#include "nsIURL.h"
#include "nsIWebProgressListener.h"
#include "nsNetUtil.h"
#include "nsPIDOMWindow.h"
#include "nsScriptSecurityManager.h"
#include "prtime.h"
@ -843,6 +845,16 @@ AntiTrackingCommon::NotifyRejection(nsIChannel* aChannel)
return;
}
// Can be called in EITHER the parent or child process.
nsCOMPtr<nsIParentChannel> parentChannel;
NS_QueryNotificationCallbacks(aChannel, parentChannel);
if (parentChannel) {
// This channel is a parent-process proxy for a child process request.
// Tell the child process channel to do this instead.
parentChannel->NotifyTrackingCookieBlocked();
return;
}
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = services::GetThirdPartyUtil();
if (!thirdPartyUtil) {
return;

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

@ -422,6 +422,12 @@ NS_IMETHODIMP nsExtProtocolChannel::NotifyTrackingProtectionDisabled()
return NS_OK;
}
NS_IMETHODIMP nsExtProtocolChannel::NotifyTrackingCookieBlocked()
{
// nothing to do
return NS_OK;
}
NS_IMETHODIMP nsExtProtocolChannel::SetClassifierMatchedInfo(const nsACString& aList,
const nsACString& aProvider,
const nsACString& aFullHash)