2014-10-14 01:34:03 +04:00
|
|
|
/* 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"
|
2017-07-26 21:18:20 +03:00
|
|
|
#include "nsINamed.h"
|
2014-10-14 01:34:03 +04:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsCOMArray.h"
|
2016-01-09 04:20:50 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-10-14 01:34:03 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class CaptivePortalService : public nsICaptivePortalService,
|
|
|
|
public nsIObserver,
|
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsITimerCallback,
|
|
|
|
public nsICaptivePortalCallback,
|
2017-07-26 21:18:20 +03:00
|
|
|
public nsINamed {
|
2014-10-14 01:34:03 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICAPTIVEPORTALSERVICE
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
NS_DECL_NSICAPTIVEPORTALCALLBACK
|
2017-07-26 21:18:20 +03:00
|
|
|
NS_DECL_NSINAMED
|
2014-10-14 01:34:03 +04:00
|
|
|
|
|
|
|
nsresult Initialize();
|
|
|
|
nsresult Start();
|
|
|
|
nsresult Stop();
|
2016-11-17 19:35:24 +03:00
|
|
|
|
2018-07-02 16:30:33 +03:00
|
|
|
static already_AddRefed<nsICaptivePortalService> GetSingleton();
|
|
|
|
|
2016-11-17 19:35:24 +03:00
|
|
|
// 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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-14 01:34:03 +04:00
|
|
|
private:
|
2021-06-25 10:57:28 +03:00
|
|
|
static const uint32_t kDefaultInterval = 60 * 1000; // check every 60 seconds
|
|
|
|
|
2018-07-02 16:30:33 +03:00
|
|
|
CaptivePortalService();
|
2014-10-14 01:34:03 +04:00
|
|
|
virtual ~CaptivePortalService();
|
|
|
|
nsresult PerformCheck();
|
|
|
|
nsresult RearmTimer();
|
2017-12-01 15:20:29 +03:00
|
|
|
void NotifyConnectivityAvailable(bool aCaptive);
|
2014-10-14 01:34:03 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsICaptivePortalDetector> mCaptivePortalDetector;
|
2021-06-25 10:57:28 +03:00
|
|
|
int32_t mState{UNKNOWN};
|
2014-10-14 01:34:03 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
2021-06-25 10:57:28 +03:00
|
|
|
bool mStarted{false};
|
|
|
|
bool mInitialized{false};
|
|
|
|
bool mRequestInProgress{false};
|
|
|
|
bool mEverBeenCaptive{false};
|
|
|
|
|
|
|
|
uint32_t mDelay{kDefaultInterval};
|
|
|
|
int32_t mSlackCount{0};
|
2014-10-14 01:34:03 +04:00
|
|
|
|
2021-06-25 10:57:28 +03:00
|
|
|
uint32_t mMinInterval{kDefaultInterval};
|
|
|
|
uint32_t mMaxInterval{25 * kDefaultInterval};
|
|
|
|
float mBackoffFactor{5.0};
|
2014-10-14 01:34:03 +04:00
|
|
|
|
2021-06-25 10:57:28 +03:00
|
|
|
void StateTransition(int32_t aNewState);
|
2014-10-14 01:34:03 +04:00
|
|
|
|
|
|
|
// 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_
|