Bug 1422277 - Add an observer notification for when the captive portal detection is "done" r=bagder

MozReview-Commit-ID: D9Qr0CuUJiQ

--HG--
extra : rebase_source : 74ecc449bee263d27af83fa101e6ef59166fecab
This commit is contained in:
Valentin Gosu 2017-12-01 13:20:29 +01:00
parent 64e1bd8242
commit d093ecbe77
3 changed files with 23 additions and 0 deletions

View file

@ -335,6 +335,17 @@ CaptivePortalService::Observe(nsISupports *aSubject,
return NS_OK;
}
void
CaptivePortalService::NotifyConnectivityAvailable(bool aCaptive)
{
nsCOMPtr<nsIObserverService> observerService = services::GetObserverService();
if (observerService) {
nsCOMPtr<nsICaptivePortalService> cps(this);
observerService->NotifyObservers(cps, NS_CAPTIVE_PORTAL_CONNECTIVITY,
aCaptive ? u"captive" : u"clear");
}
}
//-----------------------------------------------------------------------------
// CaptivePortalService::nsICaptivePortalCallback
//-----------------------------------------------------------------------------
@ -364,8 +375,10 @@ CaptivePortalService::Complete(bool success)
if (success) {
if (mEverBeenCaptive) {
mState = UNLOCKED_PORTAL;
NotifyConnectivityAvailable(true);
} else {
mState = NOT_CAPTIVE;
NotifyConnectivityAvailable(false);
}
}

View file

@ -45,6 +45,7 @@ private:
virtual ~CaptivePortalService();
nsresult PerformCheck();
nsresult RearmTimer();
void NotifyConnectivityAvailable(bool aCaptive);
nsCOMPtr<nsICaptivePortalDetector> mCaptivePortalDetector;
int32_t mState;

View file

@ -56,4 +56,13 @@ interface nsICaptivePortalService : nsISupports
*/
#define NS_IPC_CAPTIVE_PORTAL_SET_STATE "ipc:network:captive-portal-set-state"
/**
* This notification will be emitted when the captive portal service has
* determined that we can connect to the internet.
* The service will pass either "captive" if there is an unlocked captive portal
* present, or "clear" if no captive portal was detected.
* Note: this notification only gets sent in the parent process.
*/
#define NS_CAPTIVE_PORTAL_CONNECTIVITY "network:captive-portal-connectivity"
%}