зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1141814
- Part2: Lower the priority of channel loading tracking resource, r=honzab
--HG-- extra : rebase_source : 8b79d23c4d2f8a813a9e76816bd540dd91bc6f8e
This commit is contained in:
Родитель
90c2d1f846
Коммит
d7704a975d
|
@ -312,9 +312,9 @@ nsBaseChannel::ClassifyURI()
|
|||
}
|
||||
|
||||
if (mLoadFlags & LOAD_CLASSIFY_URI) {
|
||||
RefPtr<nsChannelClassifier> classifier = new nsChannelClassifier();
|
||||
RefPtr<nsChannelClassifier> classifier = new nsChannelClassifier(this);
|
||||
if (classifier) {
|
||||
classifier->Start(this);
|
||||
classifier->Start();
|
||||
} else {
|
||||
Cancel(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsISecurityEventSink.h"
|
||||
#include "nsISupportsPriority.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -50,15 +51,26 @@ static LazyLogModule gChannelClassifierLog("nsChannelClassifier");
|
|||
NS_IMPL_ISUPPORTS(nsChannelClassifier,
|
||||
nsIURIClassifierCallback)
|
||||
|
||||
nsChannelClassifier::nsChannelClassifier()
|
||||
nsChannelClassifier::nsChannelClassifier(nsIChannel *aChannel)
|
||||
: mIsAllowListed(false),
|
||||
mSuspendedChannel(false)
|
||||
mSuspendedChannel(false),
|
||||
mChannel(aChannel),
|
||||
mTrackingProtectionEnabled(Nothing())
|
||||
{
|
||||
MOZ_ASSERT(mChannel);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
|
||||
bool *result)
|
||||
nsChannelClassifier::ShouldEnableTrackingProtection(bool *result)
|
||||
{
|
||||
nsresult rv = ShouldEnableTrackingProtectionInternal(mChannel, result);
|
||||
mTrackingProtectionEnabled = Some(*result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsChannelClassifier::ShouldEnableTrackingProtectionInternal(nsIChannel *aChannel,
|
||||
bool *result)
|
||||
{
|
||||
// Should only be called in the parent process.
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
|
@ -252,10 +264,8 @@ nsChannelClassifier::NotifyTrackingProtectionDisabled(nsIChannel *aChannel)
|
|||
}
|
||||
|
||||
void
|
||||
nsChannelClassifier::Start(nsIChannel *aChannel)
|
||||
nsChannelClassifier::Start()
|
||||
{
|
||||
mChannel = aChannel;
|
||||
|
||||
nsresult rv = StartInternal();
|
||||
if (NS_FAILED(rv)) {
|
||||
// If we aren't getting a callback for any reason, assume a good verdict and
|
||||
|
@ -344,7 +354,19 @@ nsChannelClassifier::StartInternal()
|
|||
|
||||
bool expectCallback;
|
||||
bool trackingProtectionEnabled = false;
|
||||
(void)ShouldEnableTrackingProtection(mChannel, &trackingProtectionEnabled);
|
||||
if (mTrackingProtectionEnabled.isNothing()) {
|
||||
(void)ShouldEnableTrackingProtection(&trackingProtectionEnabled);
|
||||
} else {
|
||||
trackingProtectionEnabled = mTrackingProtectionEnabled.value();
|
||||
}
|
||||
|
||||
static bool sAnnotateChannelEnabled = false;
|
||||
static bool sIsInited = false;
|
||||
if (!sIsInited) {
|
||||
sIsInited = true;
|
||||
Preferences::AddBoolVarCache(&sAnnotateChannelEnabled,
|
||||
"privacy.trackingprotection.annotate_channels");
|
||||
}
|
||||
|
||||
if (LOG_ENABLED()) {
|
||||
nsCOMPtr<nsIURI> principalURI;
|
||||
|
@ -353,8 +375,8 @@ nsChannelClassifier::StartInternal()
|
|||
"uri %s", this, principalURI->GetSpecOrDefault().get(),
|
||||
uri->GetSpecOrDefault().get()));
|
||||
}
|
||||
rv = uriClassifier->Classify(principal, trackingProtectionEnabled, this,
|
||||
&expectCallback);
|
||||
rv = uriClassifier->Classify(principal, sAnnotateChannelEnabled | trackingProtectionEnabled,
|
||||
this, &expectCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -667,6 +689,26 @@ nsChannelClassifier::OnClassifyComplete(nsresult aErrorCode)
|
|||
}
|
||||
MarkEntryClassified(aErrorCode);
|
||||
|
||||
// The value of |mTrackingProtectionEnabled| should be assigned at
|
||||
// |ShouldEnableTrackingProtection| before.
|
||||
MOZ_ASSERT(mTrackingProtectionEnabled, "Should contain a value.");
|
||||
|
||||
if (aErrorCode == NS_ERROR_TRACKING_URI &&
|
||||
!mTrackingProtectionEnabled.valueOr(false)) {
|
||||
if (LOG_ENABLED()) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
mChannel->GetURI(getter_AddRefs(uri));
|
||||
LOG(("nsChannelClassifier[%p]: lower the priority of channel %p"
|
||||
", since %s is a tracker", this, mChannel.get(),
|
||||
uri->GetSpecOrDefault().get()));
|
||||
}
|
||||
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);
|
||||
if (p) {
|
||||
p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
|
||||
}
|
||||
aErrorCode = NS_OK;
|
||||
}
|
||||
|
||||
if (NS_FAILED(aErrorCode)) {
|
||||
if (LOG_ENABLED()) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "nsIURIClassifier.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
class nsIChannel;
|
||||
class nsIHttpChannelInternal;
|
||||
|
@ -19,16 +20,16 @@ namespace net {
|
|||
class nsChannelClassifier final : public nsIURIClassifierCallback
|
||||
{
|
||||
public:
|
||||
nsChannelClassifier();
|
||||
explicit nsChannelClassifier(nsIChannel* aChannel);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURICLASSIFIERCALLBACK
|
||||
|
||||
// Calls nsIURIClassifier.Classify with the principal of the given channel,
|
||||
// and cancels the channel on a bad verdict.
|
||||
void Start(nsIChannel *aChannel);
|
||||
void Start();
|
||||
// Whether or not tracking protection should be enabled on this channel.
|
||||
nsresult ShouldEnableTrackingProtection(nsIChannel *aChannel, bool *result);
|
||||
nsresult ShouldEnableTrackingProtection(bool *result);
|
||||
|
||||
private:
|
||||
// True if the channel is on the allow list.
|
||||
|
@ -36,6 +37,7 @@ private:
|
|||
// True if the channel has been suspended.
|
||||
bool mSuspendedChannel;
|
||||
nsCOMPtr<nsIChannel> mChannel;
|
||||
Maybe<bool> mTrackingProtectionEnabled;
|
||||
|
||||
~nsChannelClassifier() {}
|
||||
// Caches good classifications for the channel principal.
|
||||
|
@ -52,6 +54,9 @@ private:
|
|||
// Checks that the channel was loaded by the URI currently loaded in aDoc
|
||||
static bool SameLoadingURI(nsIDocument *aDoc, nsIChannel *aChannel);
|
||||
|
||||
nsresult ShouldEnableTrackingProtectionInternal(nsIChannel *aChannel,
|
||||
bool *result);
|
||||
|
||||
public:
|
||||
// If we are blocking tracking content, update the corresponding flag in
|
||||
// the respective docshell and call nsISecurityEventSink::onSecurityChange.
|
||||
|
|
|
@ -5885,12 +5885,14 @@ nsHttpChannel::BeginConnect()
|
|||
return AsyncCall(&nsHttpChannel::HandleAsyncAPIRedirect);
|
||||
}
|
||||
// Check to see if this principal exists on local blocklists.
|
||||
RefPtr<nsChannelClassifier> channelClassifier = new nsChannelClassifier();
|
||||
RefPtr<nsChannelClassifier> channelClassifier = new nsChannelClassifier(this);
|
||||
if (mLoadFlags & LOAD_CLASSIFY_URI) {
|
||||
nsCOMPtr<nsIURIClassifier> classifier = do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID);
|
||||
bool tpEnabled = false;
|
||||
channelClassifier->ShouldEnableTrackingProtection(this, &tpEnabled);
|
||||
if (classifier && tpEnabled) {
|
||||
channelClassifier->ShouldEnableTrackingProtection(&tpEnabled);
|
||||
bool annotateChannelEnabled =
|
||||
Preferences::GetBool("privacy.trackingprotection.annotate_channels");
|
||||
if (classifier && (tpEnabled || annotateChannelEnabled)) {
|
||||
// We skip speculative connections by setting mLocalBlocklist only
|
||||
// when tracking protection is enabled. Though we could do this for
|
||||
// both phishing and malware, it is not necessary for correctness,
|
||||
|
@ -6012,7 +6014,7 @@ nsHttpChannel::BeginConnect()
|
|||
// be overridden.
|
||||
LOG(("nsHttpChannel::Starting nsChannelClassifier %p [this=%p]",
|
||||
channelClassifier.get(), this));
|
||||
channelClassifier->Start(this);
|
||||
channelClassifier->Start();
|
||||
if (callContinueBeginConnect) {
|
||||
return ContinueBeginConnectWithResult();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче