Bug 1596845 - Pass full trr domain into content process r=acreskey,necko-reviewers,kershaw
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 23 Dec 2022 09:26:16 +0000
changeset 647324 0c74e206883c15054e6dd50c07bc466d51e66e29
parent 647323 13d383bde6cfbf5b9f381745ff3253e8bde2d7e7
child 647325 30f730eba0c402ae97e28f1b62cf31182efcc588
push id40502
push usermlaza@mozilla.com
push dateFri, 23 Dec 2022 15:33:12 +0000
treeherdermozilla-central@46d61edff678 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersacreskey, necko-reviewers, kershaw
bugs1596845
milestone110.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 1596845 - Pass full trr domain into content process r=acreskey,necko-reviewers,kershaw Previosuly we'd only pass the `TRRService::ProviderKey()` into the content process. But now we need the full domain for the error page in the content process, so we now pass the full domain. The ChildDNSService now holds on to the full domain, but calls into `TRRService` to update the key for telemetry and returns that when necessary. Depends on D164348 Differential Revision: https://phabricator.services.mozilla.com/D164642
dom/base/Document.cpp
dom/ipc/ContentParent.cpp
netwerk/dns/ChildDNSService.cpp
netwerk/dns/ChildDNSService.h
netwerk/dns/TRRService.cpp
netwerk/dns/TRRService.h
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsIDNSService.idl
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -2117,17 +2117,17 @@ void Document::AccumulatePageLoadTelemet
   nsCOMPtr<nsIHttpChannelInternal> httpChannel =
       do_QueryInterface(GetChannel());
   if (httpChannel) {
     bool resolvedByTRR = false;
     Unused << httpChannel->GetIsResolvedByTRR(&resolvedByTRR);
     if (resolvedByTRR) {
       RefPtr<net::ChildDNSService> dnsServiceChild =
           net::ChildDNSService::GetSingleton();
-      dnsServiceChild->GetTRRDomain(dnsKey);
+      dnsServiceChild->GetTRRDomainKey(dnsKey);
       aEventTelemetryDataOut.trrDomain = mozilla::Some(dnsKey);
     }
 
     uint32_t major;
     uint32_t minor;
     if (NS_SUCCEEDED(httpChannel->GetResponseVersion(&major, &minor))) {
       if (major == 3) {
         http3Key = "http3"_ns;
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -3109,17 +3109,18 @@ bool ContentParent::InitInternal(Process
   bool isReadyForBackgroundProcessing = false;
 #if defined(XP_WIN)
   RefPtr<DllServices> dllSvc(DllServices::Get());
   isReadyForBackgroundProcessing = dllSvc->IsReadyForBackgroundProcessing();
 #endif
 
   xpcomInit.perfStatsMask() = PerfStats::GetCollectionMask();
 
-  xpcomInit.trrDomain() = TRRService::ProviderKey();
+  nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
+  dns->GetTrrDomain(xpcomInit.trrDomain());
 
   Unused << SendSetXPCOMProcessAttributes(
       xpcomInit, initialData, lnf, fontList, std::move(sharedUASheetHandle),
       sharedUASheetAddress, std::move(sharedFontListBlocks),
       isReadyForBackgroundProcessing);
 
   ipc::WritableSharedMap* sharedData =
       nsFrameMessageManager::sParentProcessManager->SharedData();
--- a/netwerk/dns/ChildDNSService.cpp
+++ b/netwerk/dns/ChildDNSService.cpp
@@ -17,16 +17,17 @@
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/net/NeckoChild.h"
 #include "mozilla/net/DNSListenerProxy.h"
 #include "mozilla/net/TRRServiceParent.h"
 #include "nsHostResolver.h"
 #include "nsServiceManagerUtils.h"
 #include "prsystem.h"
 #include "DNSAdditionalInfo.h"
+#include "TRRService.h"
 
 namespace mozilla {
 namespace net {
 
 //-----------------------------------------------------------------------------
 // ChildDNSService
 //-----------------------------------------------------------------------------
 
@@ -463,16 +464,23 @@ ChildDNSService::Observe(nsISupports* su
     mODoHActivated = u"true"_ns.Equals(data);
   }
 
   return NS_OK;
 }
 
 void ChildDNSService::SetTRRDomain(const nsACString& aTRRDomain) {
   mTRRDomain = aTRRDomain;
+  TRRService::SetProviderDomain(aTRRDomain);
 }
 
-void ChildDNSService::GetTRRDomain(nsACString& aTRRDomain) {
+void ChildDNSService::GetTRRDomainKey(nsACString& aTRRDomain) {
+  aTRRDomain = TRRService::ProviderKey();
+}
+
+NS_IMETHODIMP
+ChildDNSService::GetTrrDomain(nsACString& aTRRDomain) {
   aTRRDomain = mTRRDomain;
+  return NS_OK;
 }
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/dns/ChildDNSService.h
+++ b/netwerk/dns/ChildDNSService.h
@@ -31,17 +31,17 @@ class ChildDNSService final : public DNS
 
   ChildDNSService();
 
   static already_AddRefed<ChildDNSService> GetSingleton();
 
   void NotifyRequestDone(DNSRequestSender* aDnsRequest);
 
   void SetTRRDomain(const nsACString& aTRRDomain);
-  void GetTRRDomain(nsACString& aTRRDomain);
+  void GetTRRDomainKey(nsACString& aTRRDomain);
 
  private:
   virtual ~ChildDNSService() = default;
 
   void MOZ_ALWAYS_INLINE GetDNSRecordHashKey(
       const nsACString& aHost, const nsACString& aTrrServer, int32_t aPort,
       uint16_t aType, const OriginAttributes& aOriginAttributes,
       uint32_t aFlags, uintptr_t aListenerAddr, nsACString& aHashKey);
--- a/netwerk/dns/TRRService.cpp
+++ b/netwerk/dns/TRRService.cpp
@@ -49,16 +49,26 @@ constexpr nsLiteralCString kTRRDomains[]
     "(other)"_ns,
     "mozilla.cloudflare-dns.com"_ns,
     "firefox.dns.nextdns.io"_ns,
     "private.canadianshield.cira.ca"_ns,
     "doh.xfinity.com"_ns,  // Steered clients
     "dns.shaw.ca"_ns, // Steered clients
     // clang-format on
 };
+// static
+void TRRService::SetProviderDomain(const nsACString& aTRRDomain) {
+  sDomainIndex = 0;
+  for (size_t i = 1; i < std::size(kTRRDomains); i++) {
+    if (aTRRDomain.Equals(kTRRDomains[i])) {
+      sDomainIndex = i;
+      break;
+    }
+  }
+}
 
 // static
 const nsCString& TRRService::ProviderKey() { return kTRRDomains[sDomainIndex]; }
 
 NS_IMPL_ISUPPORTS_INHERITED(TRRService, TRRServiceBase, nsIObserver,
                             nsISupportsWeakReference)
 
 NS_IMPL_ADDREF_USING_AGGREGATOR(TRRService::ConfirmationContext, OwningObject())
@@ -287,35 +297,29 @@ bool TRRService::MaybeSetPrivateURI(cons
     if (NS_FAILED(rv)) {
       LOG(("TRRService::MaybeSetPrivateURI failed to create URI!\n"));
       return false;
     }
 
     nsAutoCString host;
     url->GetHost(host);
 
-    sDomainIndex = 0;
-    for (size_t i = 1; i < std::size(kTRRDomains); i++) {
-      if (host.Equals(kTRRDomains[i])) {
-        sDomainIndex = i;
-        break;
-      }
-    }
+    SetProviderDomain(host);
 
     mPrivateURI = newURI;
 
     // Notify the content processes of the new TRR
     for (auto* cp :
          dom::ContentParent::AllProcesses(dom::ContentParent::eLive)) {
       PNeckoParent* neckoParent =
           SingleManagedOrNull(cp->ManagedPNeckoParent());
       if (!neckoParent) {
         continue;
       }
-      Unused << neckoParent->SendSetTRRDomain(ProviderKey());
+      Unused << neckoParent->SendSetTRRDomain(host);
     }
 
     AsyncCreateTRRConnectionInfo(mPrivateURI);
 
     // The URI has changed. We should trigger a new confirmation immediately.
     // We must do this here because the URI could also change because of
     // steering.
     mConfirmationTriggered =
--- a/netwerk/dns/TRRService.h
+++ b/netwerk/dns/TRRService.h
@@ -77,16 +77,17 @@ class TRRService : public TRRServiceBase
   already_AddRefed<nsIThread> TRRThread();
   bool IsOnTRRThread();
 
   bool IsUsingAutoDetectedURL() { return mURISetByDetection; }
 
   // Returns a reference to a static string identifying the current DoH server
   // If the DoH server is not one of the built-in ones it will return "(other)"
   static const nsCString& ProviderKey();
+  static void SetProviderDomain(const nsACString& aTRRDomain);
 
   void InitTRRConnectionInfo() override;
 
  private:
   virtual ~TRRService();
 
   friend class TRRServiceChild;
   friend class TRRServiceParent;
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -1459,16 +1459,30 @@ NS_IMETHODIMP
 nsDNSService::GetCurrentTrrConfirmationState(uint32_t* aConfirmationState) {
   *aConfirmationState = uint32_t(TRRService::CONFIRM_OFF);
   if (mTrrService) {
     *aConfirmationState = mTrrService->ConfirmationState();
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsDNSService::GetTrrDomain(nsACString& aTRRDomain) {
+  nsAutoCString url;
+  if (mTrrService) {
+    mTrrService->GetURI(url);
+  }
+  nsCOMPtr<nsIURI> uri;
+  nsresult rv = NS_NewURI(getter_AddRefs(uri), url);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  return uri->GetHost(aTRRDomain);
+}
+
 size_t nsDNSService::SizeOfIncludingThis(
     mozilla::MallocSizeOf mallocSizeOf) const {
   // Measurement of the following members may be added later if DMD finds it
   // is worthwhile:
   // - mIDN
   // - mLock
 
   size_t n = mallocSizeOf(this);
--- a/netwerk/dns/nsIDNSService.idl
+++ b/netwerk/dns/nsIDNSService.idl
@@ -255,16 +255,21 @@ interface nsIDNSService : nsISupports
     readonly attribute unsigned long currentTrrConfirmationState;
 
     /**
      * @return the hostname of the operating system.
      */
     readonly attribute AUTF8String myHostName;
 
     /**
+     * returns the current TRR domain.
+     */
+    readonly attribute ACString trrDomain;
+
+    /**
      * Returns true when we have valid ODoHConfigs to encrypt/decrypt oblivious
      * DNS packets.
      */
     readonly attribute boolean ODoHActivated;
 
     /*************************************************************************
      * Listed below are the various flags that may be OR'd together to form
      * the aFlags parameter passed to asyncResolve() and resolve().