Bug 1589954 - Implement the rest of nsIClassifiedChannel methods on DocumentChannel; r=jya
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 23 Oct 2019 17:55:32 +0000
changeset 498754 82274c20257455ffb7ea74404ee9d27bc4246819
parent 498753 5a8b6efcadb8488ba10079308fc22d71f2532600
child 498755 165ae98171b34cd87320cf2f70aeab0f982b8245
push id98665
push usereakhgari@mozilla.com
push dateWed, 23 Oct 2019 17:56:06 +0000
treeherderautoland@82274c202574 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1589954
milestone72.0a1
first release with
nightly linux32
82274c202574 / 72.0a1 / 20191023215406 / files
nightly linux64
82274c202574 / 72.0a1 / 20191023215406 / files
nightly mac
82274c202574 / 72.0a1 / 20191023215406 / files
nightly win32
82274c202574 / 72.0a1 / 20191023215406 / files
nightly win64
82274c202574 / 72.0a1 / 20191023215406 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1589954 - Implement the rest of nsIClassifiedChannel methods on DocumentChannel; r=jya Differential Revision: https://phabricator.services.mozilla.com/D49863
netwerk/ipc/DocumentChannelChild.cpp
netwerk/ipc/DocumentChannelChild.h
netwerk/ipc/DocumentChannelParent.cpp
netwerk/ipc/PDocumentChannel.ipdl
--- a/netwerk/ipc/DocumentChannelChild.cpp
+++ b/netwerk/ipc/DocumentChannelChild.cpp
@@ -440,18 +440,22 @@ IPCResult DocumentChannelChild::RecvConf
   Maybe<nsresult> cancelCode;
   rv = CSPService::ConsultCSPForRedirect(originalUri, aNewUri, mLoadInfo,
                                          cancelCode);
   aResolve(Tuple<const nsresult&, const Maybe<nsresult>&>(rv, cancelCode));
   return IPC_OK();
 }
 
 IPCResult DocumentChannelChild::RecvNotifyClassificationFlags(
-    const uint32_t& aClassificationFlags) {
-  mThirdPartyClassificationFlags |= aClassificationFlags;
+    const uint32_t& aClassificationFlags, const bool& aIsThirdParty) {
+  if (aIsThirdParty) {
+    mThirdPartyClassificationFlags |= aClassificationFlags;
+  } else {
+    mFirstPartyClassificationFlags |= aClassificationFlags;
+  }
   return IPC_OK();
 }
 
 IPCResult DocumentChannelChild::RecvNotifyChannelClassifierProtectionDisabled(
     const uint32_t& aAcceptedReason) {
   UrlClassifierCommon::NotifyChannelClassifierProtectionDisabled(
       this, aAcceptedReason);
   return IPC_OK();
@@ -587,33 +591,51 @@ DocumentChannelChild::Resume() {
   }
 
   mEventQueue->Resume();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentChannelChild::IsTrackingResource(bool* aIsTrackingResource) {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  MOZ_ASSERT(!mFirstPartyClassificationFlags ||
+             !mThirdPartyClassificationFlags);
+  *aIsTrackingResource = UrlClassifierCommon::IsTrackingClassificationFlag(
+                             mThirdPartyClassificationFlags) ||
+                         UrlClassifierCommon::IsTrackingClassificationFlag(
+                             mFirstPartyClassificationFlags);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentChannelChild::IsThirdPartyTrackingResource(bool* aIsTrackingResource) {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  MOZ_ASSERT(
+      !(mFirstPartyClassificationFlags && mThirdPartyClassificationFlags));
+  *aIsTrackingResource = UrlClassifierCommon::IsTrackingClassificationFlag(
+      mThirdPartyClassificationFlags);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentChannelChild::GetClassificationFlags(uint32_t* aClassificationFlags) {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  MOZ_ASSERT(aClassificationFlags);
+  if (mThirdPartyClassificationFlags) {
+    *aClassificationFlags = mThirdPartyClassificationFlags;
+  } else {
+    *aClassificationFlags = mFirstPartyClassificationFlags;
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentChannelChild::GetFirstPartyClassificationFlags(
     uint32_t* aClassificationFlags) {
-  return NS_ERROR_NOT_IMPLEMENTED;
+  MOZ_ASSERT(aClassificationFlags);
+  *aClassificationFlags = mFirstPartyClassificationFlags;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentChannelChild::GetThirdPartyClassificationFlags(
     uint32_t* aClassificationFlags) {
   MOZ_ASSERT(aClassificationFlags);
   *aClassificationFlags = mThirdPartyClassificationFlags;
   return NS_OK;
--- a/netwerk/ipc/DocumentChannelChild.h
+++ b/netwerk/ipc/DocumentChannelChild.h
@@ -65,17 +65,17 @@ class DocumentChannelChild final : publi
       nsTArray<DocumentChannelRedirect>&& aRedirects,
       const uint64_t& aChannelId, nsIURI* aOriginalURI,
       const uint32_t& aRedirectMode, const uint32_t& aRedirectFlags,
       const Maybe<uint32_t>& aContentDisposition,
       const Maybe<nsString>& aContentDispositionFilename,
       RedirectToRealChannelResolver&& aResolve);
 
   mozilla::ipc::IPCResult RecvNotifyClassificationFlags(
-      const uint32_t& aClassificationFlags);
+      const uint32_t& aClassificationFlags, const bool& aIsThirdParty);
   mozilla::ipc::IPCResult RecvNotifyChannelClassifierProtectionDisabled(
       const uint32_t& aAcceptedReason);
   mozilla::ipc::IPCResult RecvNotifyCookieAllowed();
   mozilla::ipc::IPCResult RecvNotifyCookieBlocked(
       const uint32_t& aRejectedReason);
 
   mozilla::ipc::IPCResult RecvSetClassifierMatchedInfo(
       const nsCString& aList, const nsCString& aProvider,
@@ -100,16 +100,17 @@ class DocumentChannelChild final : publi
 
   ~DocumentChannelChild() = default;
 
   RefPtr<ChannelEventQueue> mEventQueue;
   nsCOMPtr<nsIChildChannel> mRedirectChannel;
   nsTArray<DocumentChannelRedirect> mRedirects;
 
   // Classified channel's matched information
+  uint32_t mFirstPartyClassificationFlags = 0;
   uint32_t mThirdPartyClassificationFlags = 0;
   nsCString mMatchedList;
   nsCString mMatchedProvider;
   nsCString mMatchedFullHash;
   nsTArray<nsCString> mMatchedTrackingLists;
   nsTArray<nsCString> mMatchedTrackingFullHashes;
 
   RedirectToRealChannelResolver mRedirectResolver;
--- a/netwerk/ipc/DocumentChannelParent.cpp
+++ b/netwerk/ipc/DocumentChannelParent.cpp
@@ -760,18 +760,19 @@ DocumentChannelParent::SetClassifierMatc
   mIParentChannelFunctions.AppendElement(
       IParentChannelFunction{VariantIndex<2>{}, std::move(params)});
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DocumentChannelParent::NotifyClassificationFlags(uint32_t aClassificationFlags,
                                                  bool aIsThirdParty) {
-  if (aIsThirdParty && CanSend()) {
-    Unused << SendNotifyClassificationFlags(aClassificationFlags);
+  if (CanSend()) {
+    Unused << SendNotifyClassificationFlags(aClassificationFlags,
+                                            aIsThirdParty);
   }
 
   mIParentChannelFunctions.AppendElement(IParentChannelFunction{
       VariantIndex<3>{},
       ClassificationFlagsParams{aClassificationFlags, aIsThirdParty}});
   return NS_OK;
 }
 
--- a/netwerk/ipc/PDocumentChannel.ipdl
+++ b/netwerk/ipc/PDocumentChannel.ipdl
@@ -45,17 +45,18 @@ parent:
   async __delete__();
 
 child:
 
   // Used to cancel child channel if we hit errors during creating and
   // AsyncOpen of nsHttpChannel on the parent.
   async FailedAsyncOpen(nsresult status);
 
-  async NotifyClassificationFlags(uint32_t classificationFlags);
+  async NotifyClassificationFlags(uint32_t classificationFlags, bool
+isThirdParty);
   async NotifyChannelClassifierProtectionDisabled(uint32_t acceptedReason);
   async NotifyCookieAllowed();
   async NotifyCookieBlocked(uint32_t rejectedReason);
 
   async SetClassifierMatchedInfo(nsCString list, nsCString provider, nsCString fullHash);
   async SetClassifierMatchedTrackingInfo(nsCString lists, nsCString fullHash);
 
   // This message is sent to a child that has been redirected to another process.