Bug 1039012: Only cancel third party channels with NS_ERROR_TRACKING_URI (r=gcp,briansmith)

This commit is contained in:
Monica Chew 2014-07-24 10:59:00 -07:00
parent cdd8d91bda
commit 7a088efd88
4 changed files with 33 additions and 4 deletions

View File

@ -30,7 +30,7 @@ interface nsIURIClassifierCallback : nsISupports
* The URI classifier service checks a URI against lists of phishing
* and malware sites.
*/
[scriptable, uuid(617f1002-ec55-42c4-a7b0-ebb221ba9fa2)]
[scriptable, uuid(de4f03cd-1a28-4f51-906b-c54b47a533c5)]
interface nsIURIClassifier : nsISupports
{
/**
@ -38,6 +38,10 @@ interface nsIURIClassifier : nsISupports
*
* @param aPrincipal
* The principal that should be checked by the URI classifier.
* @param aTrackingProtectionEnabled
* Whether or not to classify the given URI against tracking
* protection lists
*
* @param aCallback
* The URI classifier will call this callback when the URI has been
* classified.
@ -48,5 +52,6 @@ interface nsIURIClassifier : nsISupports
* callback will be called.
*/
boolean classify(in nsIPrincipal aPrincipal,
in boolean aTrackingProtectionEnabled,
in nsIURIClassifierCallback aCallback);
};

View File

@ -11,6 +11,7 @@
#include "nsICacheEntryDescriptor.h"
#include "prlog.h"
#include "nsIScriptSecurityManager.h"
#include "mozIThirdPartyUtil.h"
#if defined(PR_LOGGING)
//
@ -32,6 +33,24 @@ nsChannelClassifier::nsChannelClassifier()
#endif
}
bool
nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel* aChannel)
{
nsresult rv;
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return false;
}
// Third party checks don't work for chrome:// URIs in mochitests, so just
// default to isThirdParty = true
bool isThirdParty = true;
(void)thirdPartyUtil->IsThirdPartyChannel(aChannel, nullptr, &isThirdParty);
return isThirdParty;
}
nsresult
nsChannelClassifier::Start(nsIChannel *aChannel)
{
@ -97,7 +116,9 @@ nsChannelClassifier::Start(nsIChannel *aChannel)
NS_ENSURE_SUCCESS(rv, rv);
bool expectCallback;
rv = uriClassifier->Classify(principal, this, &expectCallback);
bool trackingProtectionEnabled = ShouldEnableTrackingProtection(aChannel);
rv = uriClassifier->Classify(principal, trackingProtectionEnabled, this,
&expectCallback);
if (NS_FAILED(rv)) return rv;
if (expectCallback) {

View File

@ -28,6 +28,8 @@ private:
~nsChannelClassifier() {}
void MarkEntryClassified(nsresult status);
bool HasBeenClassified(nsIChannel *aChannel);
// Whether or not tracking protection should be enabled on this channel.
bool ShouldEnableTrackingProtection(nsIChannel* aChannel);
};
#endif

View File

@ -1215,6 +1215,7 @@ nsUrlClassifierDBService::Init()
// nsChannelClassifier is the only consumer of this interface.
NS_IMETHODIMP
nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
bool aTrackingProtectionEnabled,
nsIURIClassifierCallback* c,
bool* result)
{
@ -1246,8 +1247,8 @@ nsUrlClassifierDBService::Classify(nsIPrincipal* aPrincipal,
}
nsAutoCString tracking;
Preferences::GetCString(TRACKING_TABLE_PREF, &tracking);
if (!tracking.IsEmpty()) {
LOG(("Looking up in tracking table, [cb=%p]", callback.get()));
if (aTrackingProtectionEnabled && !tracking.IsEmpty()) {
LOG(("Looking up third party in tracking table, [cb=%p]", callback.get()));
tables.Append(',');
tables.Append(tracking);
}