From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- netwerk/base/CaptivePortalService.h | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 netwerk/base/CaptivePortalService.h (limited to 'netwerk/base/CaptivePortalService.h') diff --git a/netwerk/base/CaptivePortalService.h b/netwerk/base/CaptivePortalService.h new file mode 100644 index 0000000000..f0a7200b4b --- /dev/null +++ b/netwerk/base/CaptivePortalService.h @@ -0,0 +1,79 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef CaptivePortalService_h_ +#define CaptivePortalService_h_ + +#include "nsICaptivePortalService.h" +#include "nsICaptivePortalDetector.h" +#include "nsINamed.h" +#include "nsIObserver.h" +#include "nsWeakReference.h" +#include "nsITimer.h" +#include "nsCOMArray.h" +#include "mozilla/TimeStamp.h" + +namespace mozilla { +namespace net { + +class CaptivePortalService : public nsICaptivePortalService, + public nsIObserver, + public nsSupportsWeakReference, + public nsITimerCallback, + public nsICaptivePortalCallback, + public nsINamed { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSICAPTIVEPORTALSERVICE + NS_DECL_NSIOBSERVER + NS_DECL_NSITIMERCALLBACK + NS_DECL_NSICAPTIVEPORTALCALLBACK + NS_DECL_NSINAMED + + nsresult Initialize(); + nsresult Start(); + nsresult Stop(); + + static already_AddRefed GetSingleton(); + + // This method is only called in the content process, in order to mirror + // the captive portal state in the parent process. + void SetStateInChild(int32_t aState); + + private: + static const uint32_t kDefaultInterval = 60 * 1000; // check every 60 seconds + + CaptivePortalService(); + virtual ~CaptivePortalService(); + nsresult PerformCheck(); + nsresult RearmTimer(); + void NotifyConnectivityAvailable(bool aCaptive); + + nsCOMPtr mCaptivePortalDetector; + int32_t mState{UNKNOWN}; + + nsCOMPtr mTimer; + bool mStarted{false}; + bool mInitialized{false}; + bool mRequestInProgress{false}; + bool mEverBeenCaptive{false}; + + uint32_t mDelay{kDefaultInterval}; + int32_t mSlackCount{0}; + + uint32_t mMinInterval{kDefaultInterval}; + uint32_t mMaxInterval{25 * kDefaultInterval}; + float mBackoffFactor{5.0}; + + void StateTransition(int32_t aNewState); + + // This holds a timestamp when the last time when the captive portal check + // has changed state. + mozilla::TimeStamp mLastChecked; +}; + +} // namespace net +} // namespace mozilla + +#endif // CaptivePortalService_h_ -- cgit v1.2.3