Bug 1607518 - Make ClassifierDummyChannel implement nsIClassifiedChannel; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 20 Jan 2020 02:02:17 +0000
changeset 510785 25b89047cf0d49734cbcd97c1351c17d39ab55a2
parent 510784 4984af4d4ca6a9c2337c6a1d3dbc8f3b3c0d6e3e
child 510786 aaff3fef7fd64ef47225542ac075a3b9d4ef66a9
push id37036
push userdvarga@mozilla.com
push dateTue, 21 Jan 2020 00:17:43 +0000
treeherdermozilla-central@83b429758070 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1607518
milestone74.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 1607518 - Make ClassifierDummyChannel implement nsIClassifiedChannel; r=baku Differential Revision: https://phabricator.services.mozilla.com/D59932
netwerk/protocol/http/ClassifierDummyChannel.cpp
netwerk/protocol/http/ClassifierDummyChannel.h
netwerk/protocol/http/ClassifierDummyChannelParent.cpp
netwerk/url-classifier/UrlClassifierCommon.cpp
--- a/netwerk/protocol/http/ClassifierDummyChannel.cpp
+++ b/netwerk/protocol/http/ClassifierDummyChannel.cpp
@@ -4,16 +4,17 @@
 /* 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 "ClassifierDummyChannel.h"
 
 #include "mozilla/AntiTrackingCommon.h"
 #include "mozilla/net/ClassifierDummyChannelChild.h"
+#include "mozilla/net/UrlClassifierCommon.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPrefs_privacy.h"
 #include "nsContentSecurityManager.h"
 #include "nsIChannel.h"
 #include "nsIURI.h"
 #include "nsProxyRelease.h"
 #include "nsQueryObject.h"
@@ -69,27 +70,29 @@ ClassifierDummyChannel::StorageAllowed(
 
 NS_IMPL_ADDREF(ClassifierDummyChannel)
 NS_IMPL_RELEASE(ClassifierDummyChannel)
 
 NS_INTERFACE_MAP_BEGIN(ClassifierDummyChannel)
   NS_INTERFACE_MAP_ENTRY(nsIRequest)
   NS_INTERFACE_MAP_ENTRY(nsIChannel)
   NS_INTERFACE_MAP_ENTRY(nsIHttpChannelInternal)
+  NS_INTERFACE_MAP_ENTRY(nsIClassifiedChannel)
   NS_INTERFACE_MAP_ENTRY_CONCRETE(ClassifierDummyChannel)
 NS_INTERFACE_MAP_END
 
 ClassifierDummyChannel::ClassifierDummyChannel(
     nsIURI* aURI, nsIURI* aTopWindowURI,
     nsIPrincipal* aContentBlockingAllowListPrincipal,
     nsresult aTopWindowURIResult, nsILoadInfo* aLoadInfo)
     : mTopWindowURI(aTopWindowURI),
       mContentBlockingAllowListPrincipal(aContentBlockingAllowListPrincipal),
       mTopWindowURIResult(aTopWindowURIResult),
-      mClassificationFlags(0) {
+      mFirstPartyClassificationFlags(0),
+      mThirdPartyClassificationFlags(0) {
   MOZ_ASSERT(XRE_IsParentProcess());
 
   SetOriginalURI(aURI);
   SetLoadInfo(aLoadInfo);
 }
 
 ClassifierDummyChannel::~ClassifierDummyChannel() {
   NS_ReleaseOnMainThreadSystemGroup("ClassifierDummyChannel::mLoadInfo",
@@ -98,23 +101,23 @@ ClassifierDummyChannel::~ClassifierDummy
                                     mURI.forget());
   NS_ReleaseOnMainThreadSystemGroup("ClassifierDummyChannel::mTopWindowURI",
                                     mTopWindowURI.forget());
   NS_ReleaseOnMainThreadSystemGroup(
       "ClassifierDummyChannel::mContentBlockingAllowListPrincipal",
       mContentBlockingAllowListPrincipal.forget());
 }
 
-uint32_t ClassifierDummyChannel::ClassificationFlags() const {
-  return mClassificationFlags;
-}
-
 void ClassifierDummyChannel::AddClassificationFlags(
-    uint32_t aClassificationFlags) {
-  mClassificationFlags |= aClassificationFlags;
+    uint32_t aClassificationFlags, bool aThirdParty) {
+  if (aThirdParty) {
+    mThirdPartyClassificationFlags |= aClassificationFlags;
+  } else {
+    mFirstPartyClassificationFlags |= aClassificationFlags;
+  }
 }
 
 //-----------------------------------------------------------------------------
 // ClassifierDummyChannel::nsIChannel
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 ClassifierDummyChannel::GetOriginalURI(nsIURI** aOriginalURI) {
@@ -662,10 +665,99 @@ NS_IMETHODIMP ClassifierDummyChannel::Co
 }
 
 NS_IMETHODIMP
 ClassifierDummyChannel::GetCrossOriginOpenerPolicy(
     nsILoadInfo::CrossOriginOpenerPolicy* aPolicy) {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
+NS_IMETHODIMP ClassifierDummyChannel::SetMatchedInfo(
+    const nsACString& aList, const nsACString& aProvider,
+    const nsACString& aFullHash) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetMatchedList(nsACString& aMatchedList) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetMatchedProvider(
+    nsACString& aMatchedProvider) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetMatchedFullHash(
+    nsACString& aMatchedFullHash) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::SetMatchedTrackingInfo(
+    const nsTArray<nsCString>& aLists, const nsTArray<nsCString>& aFullHashes) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetMatchedTrackingLists(
+    nsTArray<nsCString>& aMatchedTrackingLists) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetMatchedTrackingFullHashes(
+    nsTArray<nsCString>& aMatchedTrackingFullHashes) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetFirstPartyClassificationFlags(
+    uint32_t* aFirstPartyClassificationFlags) {
+  *aFirstPartyClassificationFlags = mFirstPartyClassificationFlags;
+  return NS_OK;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetThirdPartyClassificationFlags(
+    uint32_t* aThirdPartyClassificationFlags) {
+  *aThirdPartyClassificationFlags = mThirdPartyClassificationFlags;
+  return NS_OK;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::GetClassificationFlags(
+    uint32_t* aClassificationFlags) {
+  if (mThirdPartyClassificationFlags) {
+    *aClassificationFlags = mThirdPartyClassificationFlags;
+  } else {
+    *aClassificationFlags = mFirstPartyClassificationFlags;
+  }
+  return NS_OK;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::IsTrackingResource(
+    bool* aIsTrackingResource) {
+  MOZ_ASSERT(!mFirstPartyClassificationFlags ||
+             !mThirdPartyClassificationFlags);
+  *aIsTrackingResource = UrlClassifierCommon::IsTrackingClassificationFlag(
+                             mThirdPartyClassificationFlags) ||
+                         UrlClassifierCommon::IsTrackingClassificationFlag(
+                             mFirstPartyClassificationFlags);
+  return NS_OK;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::IsThirdPartyTrackingResource(
+    bool* aIsTrackingResource) {
+  MOZ_ASSERT(
+      !(mFirstPartyClassificationFlags && mThirdPartyClassificationFlags));
+  *aIsTrackingResource = UrlClassifierCommon::IsTrackingClassificationFlag(
+      mThirdPartyClassificationFlags);
+  return NS_OK;
+}
+
+NS_IMETHODIMP ClassifierDummyChannel::IsSocialTrackingResource(
+    bool* aIsSocialTrackingResource) {
+  MOZ_ASSERT(!mFirstPartyClassificationFlags ||
+             !mThirdPartyClassificationFlags);
+  *aIsSocialTrackingResource =
+      UrlClassifierCommon::IsSocialTrackingClassificationFlag(
+          mThirdPartyClassificationFlags) ||
+      UrlClassifierCommon::IsSocialTrackingClassificationFlag(
+          mFirstPartyClassificationFlags);
+  return NS_OK;
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/protocol/http/ClassifierDummyChannel.h
+++ b/netwerk/protocol/http/ClassifierDummyChannel.h
@@ -4,27 +4,27 @@
 /* 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/. */
 
 #ifndef mozilla_net_ClassifierDummyChannel_h
 #define mozilla_net_ClassifierDummyChannel_h
 
 #include "nsIChannel.h"
+#include "nsIClassifiedChannel.h"
 #include "nsIHttpChannelInternal.h"
 #include <functional>
 
 #define CLASSIFIER_DUMMY_CHANNEL_IID                 \
   {                                                  \
     0x70ceb97d, 0xbfa6, 0x4255, {                    \
       0xb7, 0x08, 0xe1, 0xb4, 0x4a, 0x1e, 0x0e, 0x9a \
     }                                                \
   }
 
-class nsIChannel;
 class nsIPrincipal;
 
 namespace mozilla {
 namespace net {
 
 /**
  * In child intercept mode, the decision to intercept a channel is made in the
  * child process without consulting the parent process.  The decision is based
@@ -42,52 +42,53 @@ namespace net {
  *
  * This hack can be removed once Bug 1231208's new "parent intercept" mechanism
  * fully lands, the pref is enabled by default it stays enabled for long enough
  * to be confident we will never need/want to turn it off.  Then as part of bug
  * 1496997 we can remove this implementation.  Bug 1498259 covers removing this
  * hack in particular.
  */
 class ClassifierDummyChannel final : public nsIChannel,
-                                     public nsIHttpChannelInternal {
+                                     public nsIHttpChannelInternal,
+                                     public nsIClassifiedChannel {
  public:
   NS_DECLARE_STATIC_IID_ACCESSOR(CLASSIFIER_DUMMY_CHANNEL_IID)
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIREQUEST
   NS_DECL_NSICHANNEL
   NS_DECL_NSIHTTPCHANNELINTERNAL
+  NS_DECL_NSICLASSIFIEDCHANNEL
 
   enum StorageAllowedState {
     eStorageGranted,
     eStorageDenied,
     eAsyncNeeded,
   };
 
   static StorageAllowedState StorageAllowed(
       nsIChannel* aChannel, const std::function<void(bool)>& aCallback);
 
   ClassifierDummyChannel(nsIURI* aURI, nsIURI* aTopWindowURI,
                          nsIPrincipal* aContentBlockingAllowListPrincipal,
                          nsresult aTopWindowURIResult, nsILoadInfo* aLoadInfo);
 
-  uint32_t ClassificationFlags() const;
-
-  void AddClassificationFlags(uint32_t);
+  void AddClassificationFlags(uint32_t aClassificationFlags, bool aThirdParty);
 
  private:
   ~ClassifierDummyChannel();
 
   nsCOMPtr<nsILoadInfo> mLoadInfo;
   nsCOMPtr<nsIURI> mURI;
   nsCOMPtr<nsIURI> mTopWindowURI;
   nsCOMPtr<nsIPrincipal> mContentBlockingAllowListPrincipal;
   nsresult mTopWindowURIResult;
 
-  uint32_t mClassificationFlags;
+  uint32_t mFirstPartyClassificationFlags;
+  uint32_t mThirdPartyClassificationFlags;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(ClassifierDummyChannel,
                               CLASSIFIER_DUMMY_CHANNEL_IID)
 
 }  // namespace net
 }  // namespace mozilla
 
--- a/netwerk/protocol/http/ClassifierDummyChannelParent.cpp
+++ b/netwerk/protocol/http/ClassifierDummyChannelParent.cpp
@@ -34,17 +34,17 @@ void ClassifierDummyChannelParent::Init(
 
   RefPtr<ClassifierDummyChannel> channel = new ClassifierDummyChannel(
       aURI, aTopWindowURI, aContentBlockingAllowListPrincipal,
       aTopWindowURIResult, aLoadInfo);
 
   bool willCallback = NS_SUCCEEDED(AsyncUrlChannelClassifier::CheckChannel(
       channel, [self = std::move(self), channel]() {
         if (self->mIPCActive) {
-          Unused << Send__delete__(self, channel->ClassificationFlags());
+          Unused << Send__delete__(self, channel->GetClassificationFlags());
         }
       }));
 
   if (willCallback) {
     onExit.release();
   }
 }
 
--- a/netwerk/url-classifier/UrlClassifierCommon.cpp
+++ b/netwerk/url-classifier/UrlClassifierCommon.cpp
@@ -427,17 +427,17 @@ void SetClassificationFlagsHelper(nsICha
 
   RefPtr<HttpBaseChannel> httpChannel = do_QueryObject(aChannel);
   if (httpChannel) {
     httpChannel->AddClassificationFlags(aClassificationFlags, aIsThirdParty);
   }
 
   RefPtr<ClassifierDummyChannel> dummyChannel = do_QueryObject(aChannel);
   if (dummyChannel) {
-    dummyChannel->AddClassificationFlags(aClassificationFlags);
+    dummyChannel->AddClassificationFlags(aClassificationFlags, aIsThirdParty);
   }
 }
 
 void LowerPriorityHelper(nsIChannel* aChannel) {
   MOZ_ASSERT(aChannel);
 
   bool isBlockingResource = false;