Commit 9c31da24 authored by valenting's avatar valenting
Browse files

Bug 1738984 - Prevent captive portal service from working post-shutdown r=necko-reviewers,dragana

parent f53cf350
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/net/CaptivePortalService.h"
#include "mozilla/AppShutdown.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Services.h"
#include "mozilla/Preferences.h"
@@ -61,6 +62,9 @@ nsresult CaptivePortalService::PerformCheck() {
  if (mRequestInProgress || !mInitialized || !mStarted) {
    return NS_OK;
  }
  if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
    return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
  }
  MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
  nsresult rv;
  if (!mCaptivePortalDetector) {
@@ -86,6 +90,11 @@ nsresult CaptivePortalService::RearmTimer() {
    mTimer->Cancel();
  }

  if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
    mTimer = nullptr;
    return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
  }

  // If we have successfully determined the state, and we have never detected
  // a captive portal, we don't need to keep polling, but will rely on events
  // to trigger detection.
@@ -123,6 +132,7 @@ nsresult CaptivePortalService::Initialize() {
    observerService->AddObserver(this, kOpenCaptivePortalLoginEvent, true);
    observerService->AddObserver(this, kAbortCaptivePortalLoginEvent, true);
    observerService->AddObserver(this, kCaptivePortalLoginSuccessEvent, true);
    observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
  }

  LOG(("Initialized CaptivePortalService\n"));
@@ -148,6 +158,10 @@ nsresult CaptivePortalService::Start() {
    return NS_OK;
  }

  if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
    return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
  }

  MOZ_ASSERT(mState == UNKNOWN, "Initial state should be UNKNOWN");
  mStarted = true;
  mEverBeenCaptive = false;
@@ -317,6 +331,9 @@ CaptivePortalService::Observe(nsISupports* aSubject, const char* aTopic,
    StateTransition(UNKNOWN);
    mLastChecked = TimeStamp::Now();
    mSlackCount = 0;
  } else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
    Stop();
    return NS_OK;
  }

  // Send notification so that the captive portal state is mirrored in the
@@ -347,6 +364,9 @@ NS_IMETHODIMP
CaptivePortalService::Prepare() {
  LOG(("CaptivePortalService::Prepare\n"));
  MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
  if (AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed)) {
    return NS_OK;
  }
  // XXX: Finish preparation shouldn't be called until dns and routing is
  // available.
  if (mCaptivePortalDetector) {