Bug 1533312 - Expose tracking annotation categories, r=dimi
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 15 Mar 2019 18:38:27 +0000
changeset 464434 fbb0b16293f0
parent 464433 8e01eb4f12c7
child 464435 cd11bf45d948
push id35716
push useraciure@mozilla.com
push dateSun, 17 Mar 2019 09:42:17 +0000
treeherdermozilla-central@8ee97c045359 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdimi
bugs1533312
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533312 - Expose tracking annotation categories, r=dimi Differential Revision: https://phabricator.services.mozilla.com/D22475
netwerk/protocol/http/nsIHttpChannel.idl
netwerk/url-classifier/UrlClassifierCommon.cpp
netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp
--- a/netwerk/protocol/http/nsIHttpChannel.idl
+++ b/netwerk/protocol/http/nsIHttpChannel.idl
@@ -527,43 +527,55 @@ interface nsIHttpChannel : nsIChannel
 
       /**
        * The resource is on the cryptomining list. This is only available if
        * the privacy.trackingprotection.cryptomining_annotate_enabled pref is set.
        */
       CLASSIFIED_CRYPTOMINING = 0x02,
 
       /**
-       * The resource is on the tracking protection list. This is only available
+       * The following are about tracking annotation and are available only
        * if the privacy.trackingprotection.annotate_channels pref.
+       * CLASSIFIED_TRACKING is set if we are not able to identify the
+       * type of classification.
        */
       CLASSIFIED_TRACKING = 0x04,
+      CLASSIFIED_TRACKING_AD = 0x08,
+      CLASSIFIED_TRACKING_ANALYTICS = 0x10,
+      CLASSIFIED_TRACKING_SOCIAL = 0x20,
+      CLASSIFIED_TRACKING_CONTENT = 0x40,
+
+      /**
+       * This is exposed to help to identify tracking classification
+       */
+      CLASSIFIED_ANY_TRACKING = CLASSIFIED_TRACKING |
+        CLASSIFIED_TRACKING_AD | CLASSIFIED_TRACKING_ANALYTICS |
+        CLASSIFIED_TRACKING_SOCIAL | CLASSIFIED_TRACKING_CONTENT |
+        CLASSIFIED_FINGERPRINTING,
     };
 
     /**
      * Returns true if the channel has loaded a resource that is classified as
      * tracker.
      * This is a helper attribute which returns the same value of
-     * (classificationFlags & CLASSIFIED_TRACKING) ||
-     *   (classificationFlags & CLASSIFIED_FINGERPRINTING)
+     * (classificationFlags & CLASSIFIED_ANY_TRACKING)
      *
      * Note that top-level channels could be marked as tracking
      * resource. In order to identify third-party tracking resources
      * specifically, use isThirdPartyTrackingResource.
      */
     [infallible] readonly attribute boolean isTrackingResource;
 
     /**
      * Returns the classification flags if the channel has been processed by
      * URL-Classifier features and is considered third-party with the top
      * window URI.
      *
      * This is a helper attribute which returns the same value of
-     * (thirdPartyClassificationFlags & CLASSIFIED_TRACKING) ||
-     *   (thirdPartyClassificationFlags & CLASSIFIED_FINGERPRINTING)
+     * (thirdPartyClassificationFlags & CLASSIFIED_ANY_TRACKING)
      */
     [infallible] readonly attribute boolean isThirdPartyTrackingResource;
 
     /**
      * Returns the allowing status for flash plugin for this channel.
      */
     cenum FlashPluginState : 8 {
       FlashPluginUnknown = 0,
--- a/netwerk/url-classifier/UrlClassifierCommon.cpp
+++ b/netwerk/url-classifier/UrlClassifierCommon.cpp
@@ -451,15 +451,13 @@ bool UrlClassifierCommon::IsAllowListed(
     }
   }
 
   return isAllowListed;
 }
 
 // static
 bool UrlClassifierCommon::IsTrackingClassificationFlag(uint32_t aFlag) {
-  return (aFlag & nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING) ||
-         (aFlag &
-          nsIHttpChannel::ClassificationFlags::CLASSIFIED_FINGERPRINTING);
+  return (aFlag & nsIHttpChannel::ClassificationFlags::CLASSIFIED_ANY_TRACKING);
 }
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp
+++ b/netwerk/url-classifier/UrlClassifierFeatureTrackingAnnotation.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "UrlClassifierFeatureTrackingAnnotation.h"
 
+#include "Classifier.h"
 #include "mozilla/AntiTrackingCommon.h"
 #include "mozilla/Logging.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/net/UrlClassifierCommon.h"
 #include "nsContentUtils.h"
 
 namespace mozilla {
@@ -30,17 +31,16 @@ namespace {
   "urlclassifier.trackingAnnotationWhitelistTable.testEntries"
 #define URLCLASSIFIER_TRACKING_ANNOTATION_SKIP_URLS \
   "urlclassifier.trackingAnnotationSkipURLs"
 #define TABLE_ANNOTATION_BLACKLIST_PREF "annotation-blacklist-pref"
 #define TABLE_ANNOTATION_WHITELIST_PREF "annotation-whitelist-pref"
 
 StaticRefPtr<UrlClassifierFeatureTrackingAnnotation> gFeatureTrackingAnnotation;
 
-
 }  // namespace
 
 UrlClassifierFeatureTrackingAnnotation::UrlClassifierFeatureTrackingAnnotation()
     : UrlClassifierFeatureBase(
           NS_LITERAL_CSTRING(TRACKING_ANNOTATION_FEATURE_NAME),
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_BLACKLIST),
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_WHITELIST),
           NS_LITERAL_CSTRING(URLCLASSIFIER_ANNOTATION_BLACKLIST_TEST_ENTRIES),
@@ -119,19 +119,49 @@ UrlClassifierFeatureTrackingAnnotation::
                                                        const nsACString& aList,
                                                        bool* aShouldContinue) {
   NS_ENSURE_ARG_POINTER(aChannel);
   NS_ENSURE_ARG_POINTER(aShouldContinue);
 
   // This is not a blocking feature.
   *aShouldContinue = true;
 
+  nsTArray<nsCString> list;
+  Classifier::SplitTables(aList, list);
+
+  uint32_t flags = 0;
+  for (nsCString& table : list) {
+    if (StringBeginsWith(table, NS_LITERAL_CSTRING("ads-track-"))) {
+      flags |= nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_AD;
+      continue;
+    }
+
+    if (StringBeginsWith(table, NS_LITERAL_CSTRING("analytics-track-"))) {
+      flags |=
+          nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_ANALYTICS;
+      continue;
+    }
+
+    if (StringBeginsWith(table, NS_LITERAL_CSTRING("social-track-"))) {
+      flags |= nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_SOCIAL;
+      continue;
+    }
+
+    if (StringBeginsWith(table, NS_LITERAL_CSTRING("content-track-"))) {
+      flags |= nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING_CONTENT;
+      continue;
+    }
+  }
+
+  if (flags == 0) {
+    flags |= nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING;
+  }
+
   UrlClassifierCommon::AnnotateChannel(
-      aChannel, AntiTrackingCommon::eTrackingAnnotations,
-      nsIHttpChannel::ClassificationFlags::CLASSIFIED_TRACKING,
+      aChannel, AntiTrackingCommon::eTrackingAnnotations, flags,
       nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 UrlClassifierFeatureTrackingAnnotation::GetURIByListType(
     nsIChannel* aChannel, nsIUrlClassifierFeature::listType aListType,