bug 1444887 TRR: get captive portal state in init r?valentin draft
authorDaniel Stenberg <daniel@haxx.se>
Mon, 12 Mar 2018 14:48:49 +0100
changeset 766456 f31c313a4351a4cc5768f58979e58c31d70e8ead
parent 766174 fdd1a0082c71673239fc2f3a6a93de889c07a1be
push id102331
push userbmo:daniel@haxx.se
push dateMon, 12 Mar 2018 22:12:57 +0000
reviewersvalentin
bugs1444887
milestone60.0a1
bug 1444887 TRR: get captive portal state in init r?valentin To prevent it from sitting waiting for an event that was sent before the TRRService started. MozReview-Commit-ID: 9F0IlWGdA9O
netwerk/dns/TRRService.cpp
--- a/netwerk/dns/TRRService.cpp
+++ b/netwerk/dns/TRRService.cpp
@@ -66,29 +66,43 @@ 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);
   }
+  nsCOMPtr<nsICaptivePortalService> captivePortalService =
+    do_GetService(NS_CAPTIVEPORTAL_CID);
+  if (captivePortalService) {
+    int32_t captiveState;
+    MOZ_ALWAYS_SUCCEEDS(captivePortalService->GetState(&captiveState));
+
+    if ((captiveState == nsICaptivePortalService::UNLOCKED_PORTAL) ||
+        (captiveState == nsICaptivePortalService::NOT_CAPTIVE)) {
+      mCaptiveIsPassed = true;
+    }
+    LOG(("TRRService::Init mCaptiveState=%d mCaptiveIsPassed=%d\n",
+         captiveState, (int)mCaptiveIsPassed));
+  }
 
   ReadPrefs(NULL);
 
   gTRRService = this;
 
   LOG(("Initialized TRRService\n"));
   return NS_OK;
 }
 
 bool
 TRRService::Enabled()
 {
-  if (mConfirmationState == CONFIRM_INIT && !mWaitForCaptive) {
+  if (mConfirmationState == CONFIRM_INIT &&
+      (!mWaitForCaptive || mCaptiveIsPassed)) {
     LOG(("TRRService::Enabled => CONFIRM_TRYING\n"));
     mConfirmationState = CONFIRM_TRYING;
   }
 
   if (mConfirmationState == CONFIRM_TRYING) {
     LOG(("TRRService::Enabled MaybeConfirm()\n"));
     MaybeConfirm();
   }