Bug 1481252 - Part 0: add tracker statistics fields to document; r=smaug
authorLiang-Heng Chen <xeonchen@gmail.com>
Fri, 17 Aug 2018 17:04:44 +0000
changeset 432130 61909c98d50d54bcedec18a3c963ac8c37aa0664
parent 432129 b5df7764020578b9382c8105c761a0258a1af8cf
child 432131 74da82ac273d53e5aac36be2fd4f0f10676274f1
push id34460
push userdvarga@mozilla.com
push dateFri, 17 Aug 2018 21:51:39 +0000
treeherdermozilla-central@2f1bbddc826b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1481252
milestone63.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 1481252 - Part 0: add tracker statistics fields to document; r=smaug Differential Revision: https://phabricator.services.mozilla.com/D3023
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/webidl/Document.webidl
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1509,17 +1509,19 @@ nsIDocument::nsIDocument()
     mSubDocuments(nullptr),
     mHeaderData(nullptr),
     mFlashClassification(FlashClassification::Unclassified),
     mBoxObjectTable(nullptr),
     mCurrentOrientationAngle(0),
     mCurrentOrientationType(OrientationType::Portrait_primary),
     mServoRestyleRootDirtyBits(0),
     mThrowOnDynamicMarkupInsertionCounter(0),
-    mIgnoreOpensDuringUnloadCounter(0)
+    mIgnoreOpensDuringUnloadCounter(0),
+    mNumTrackersFound(0),
+    mNumTrackersBlocked(0)
 {
   SetIsInDocument();
 }
 
 nsDocument::nsDocument(const char* aContentType)
   : nsIDocument()
 {
   SetContentTypeInternal(nsDependentCString(aContentType));
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -3535,16 +3535,40 @@ public:
   }
 
   void DecrementIgnoreOpensDuringUnloadCounter()
   {
     MOZ_ASSERT(mIgnoreOpensDuringUnloadCounter);
     --mIgnoreOpensDuringUnloadCounter;
   }
 
+  void IncrementTrackerCount(bool aIsTrackerBlocked)
+  {
+    MOZ_ASSERT(!GetSameTypeParentDocument());
+
+    ++mNumTrackersFound;
+    if (aIsTrackerBlocked) {
+      ++mNumTrackersBlocked;
+    }
+  }
+
+  uint32_t NumTrackersFound()
+  {
+    MOZ_ASSERT(!GetSameTypeParentDocument() || mNumTrackersFound == 0);
+
+    return mNumTrackersFound;
+  }
+
+  uint32_t NumTrackersBlocked()
+  {
+    MOZ_ASSERT(!GetSameTypeParentDocument() || mNumTrackersBlocked == 0);
+
+    return mNumTrackersBlocked;
+  }
+
   bool AllowPaymentRequest() const
   {
     return mAllowPaymentRequest;
   }
 
   void SetAllowPaymentRequest(bool aAllowPaymentRequest)
   {
     mAllowPaymentRequest = aAllowPaymentRequest;
@@ -4487,16 +4511,22 @@ protected:
   // prevent custom element constructors from being able to use document.open(),
   // document.close(), and document.write() when they are invoked by the parser.
   uint32_t mThrowOnDynamicMarkupInsertionCounter;
 
   // Count of unload/beforeunload/pagehide operations in progress.
   uint32_t mIgnoreOpensDuringUnloadCounter;
 
   nsCOMPtr<nsIDOMXULCommandDispatcher> mCommandDispatcher; // [OWNER] of the focus tracker
+
+  // At the moment, trackers might be blocked by Tracking Protection or FastBlock.
+  // In order to know the numbers of trackers detected and blocked, we add
+  // these two values here and those are shared by TP and FB.
+  uint32_t mNumTrackersFound;
+  uint32_t mNumTrackersBlocked;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocument, NS_IDOCUMENT_IID)
 
 /**
  * mozAutoSubtreeModified batches DOM mutations so that a DOMSubtreeModified
  * event is dispatched, if necessary, when the outermost mozAutoSubtreeModified
  * object is deleted.
--- a/dom/webidl/Document.webidl
+++ b/dom/webidl/Document.webidl
@@ -513,16 +513,23 @@ enum FlashClassification {
   "allowed",        // Site is on the Flash whitelist
   "denied"          // Site is on the Flash blacklist
 };
 partial interface Document {
   [ChromeOnly]
   readonly attribute FlashClassification documentFlashClassification;
 };
 
+// Extension to obtain the number of trackers are detected and blocked in the
+// Document (and it's corresponding docshell sub-tree)
+partial interface Document {
+  [ChromeOnly] readonly attribute unsigned long numTrackersFound;
+  [ChromeOnly] readonly attribute unsigned long numTrackersBlocked;
+};
+
 Document implements XPathEvaluator;
 Document implements GlobalEventHandlers;
 Document implements DocumentAndElementEventHandlers;
 Document implements TouchEventHandlers;
 Document implements ParentNode;
 Document implements OnErrorEventHandlerForNodes;
 Document implements GeometryUtils;
 Document implements FontFaceSource;