Bug 1533312 - Expose tracking annotation categories, r=dimi
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 15 Mar 2019 18:38:27 +0000
changeset 525321 fbb0b16293f0ecf46837f473e4b02235d13b3db5
parent 525320 8e01eb4f12c7701b7f7f389a9db3229606ba0179
child 525322 cd11bf45d948ab603bfd0eecada05b8854e93e0a
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [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,