Bug 1456005 - Add captive portal URI to the TRR exclusion list r=dragana
authorKershaw Chang <kershaw@mozilla.com>
Wed, 14 Aug 2019 19:35:16 +0000
changeset 488216 b3a7ade91b6114da1cfccf7e8f75d71f0c717edb
parent 488215 c290f5eed098cde975a779d88e43b260f2d4c222
child 488217 e91774d533a9e195a183920fe208df5c25edcaea
push id36437
push userncsoregi@mozilla.com
push dateThu, 15 Aug 2019 19:33:18 +0000
treeherdermozilla-central@44aac6fc3352 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1456005
milestone70.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 1456005 - Add captive portal URI to the TRR exclusion list r=dragana Differential Revision: https://phabricator.services.mozilla.com/D41207
netwerk/dns/TRRService.cpp
--- a/netwerk/dns/TRRService.cpp
+++ b/netwerk/dns/TRRService.cpp
@@ -13,16 +13,17 @@
 
 #include "mozilla/Preferences.h"
 #include "mozilla/Tokenizer.h"
 
 static const char kOpenCaptivePortalLoginEvent[] = "captive-portal-login";
 static const char kClearPrivateData[] = "clear-private-data";
 static const char kPurge[] = "browser:purge-session-history";
 static const char kDisableIpv6Pref[] = "network.dns.disableIPv6";
+static const char kCaptivedetectCanonicalURL[] = "captivedetect.canonicalURL";
 
 #define TRR_PREF_PREFIX "network.trr."
 #define TRR_PREF(x) TRR_PREF_PREFIX x
 
 namespace mozilla {
 namespace net {
 
 #undef LOG
@@ -68,16 +69,17 @@ nsresult TRRService::Init() {
     observerService->AddObserver(this, kClearPrivateData, true);
     observerService->AddObserver(this, kPurge, true);
   }
   nsCOMPtr<nsIPrefBranch> prefBranch;
   GetPrefBranch(getter_AddRefs(prefBranch));
   if (prefBranch) {
     prefBranch->AddObserver(TRR_PREF_PREFIX, this, true);
     prefBranch->AddObserver(kDisableIpv6Pref, this, true);
+    prefBranch->AddObserver(kCaptivedetectCanonicalURL, this, true);
   }
   nsCOMPtr<nsICaptivePortalService> captivePortalService =
       do_GetService(NS_CAPTIVEPORTAL_CID);
   if (captivePortalService) {
     int32_t captiveState;
     MOZ_ALWAYS_SUCCEEDS(captivePortalService->GetState(&captiveState));
 
     if ((captiveState == nsICaptivePortalService::UNLOCKED_PORTAL) ||
@@ -280,19 +282,35 @@ nsresult TRRService::ReadPrefs(const cha
     }
   }
   if (!name || !strcmp(name, TRR_PREF("max-fails"))) {
     uint32_t fails;
     if (NS_SUCCEEDED(Preferences::GetUint(TRR_PREF("max-fails"), &fails))) {
       mDisableAfterFails = fails;
     }
   }
-  if (!name || !strcmp(name, TRR_PREF("excluded-domains"))) {
+  if (!name || !strcmp(name, TRR_PREF("excluded-domains")) ||
+      !strcmp(name, kCaptivedetectCanonicalURL)) {
     nsAutoCString excludedDomains;
     Preferences::GetCString(TRR_PREF("excluded-domains"), excludedDomains);
+    nsAutoCString canonicalSiteURL;
+    Preferences::GetCString(kCaptivedetectCanonicalURL, canonicalSiteURL);
+
+    nsCOMPtr<nsIURI> uri;
+    nsresult rv = NS_NewURI(getter_AddRefs(uri), canonicalSiteURL,
+                            UTF_8_ENCODING, nullptr);
+    if (NS_SUCCEEDED(rv)) {
+      nsAutoCString host;
+      uri->GetHost(host);
+
+      if (!excludedDomains.IsEmpty() && excludedDomains.Last() != ',') {
+        excludedDomains.AppendLiteral(",");
+      }
+      excludedDomains.Append(host);
+    }
 
     mExcludedDomains.Clear();
     nsCCharSeparatedTokenizer tokenizer(
         excludedDomains, ',', nsCCharSeparatedTokenizer::SEPARATOR_OPTIONAL);
     while (tokenizer.hasMoreTokens()) {
       nsAutoCString token(tokenizer.nextToken());
       LOG(("TRRService::ReadPrefs excluded-domains host:[%s]\n", token.get()));
       mExcludedDomains.PutEntry(token);