//----------------------------------------------------------------------------- // CaptivePortalService::nsIObserver //----------------------------------------------------------------------------- NS_IMETHODIMP CaptivePortalService::Observe(nsISupports *aSubject, const char * aTopic, const char16_t * aData) { LOG(("CaptivePortalService::Observe() topic=%s\n", aTopic)); if (!strcmp(aTopic, kOpenCaptivePortalLoginEvent)) { // A redirect or altered content has been detected. // The user needs to log in. We are in a captive portal. mState = LOCKED_PORTAL; mLastChecked = TimeStamp::Now(); mEverBeenCaptive = true; } else if (!strcmp(aTopic, kCaptivePortalLoginSuccessEvent)) { // The user has successfully logged in. We have connectivity. mState = UNLOCKED_PORTAL; mLastChecked = TimeStamp::Now(); mRequestInProgress = false; mSlackCount = 0; mDelay = mMinInterval; RearmTimer(); } else if (!strcmp(aTopic, kAbortCaptivePortalLoginEvent)) { // The login has been aborted mRequestInProgress = false; mState = UNKNOWN; mLastChecked = TimeStamp::Now(); mSlackCount = 0; } return NS_OK; }
//----------------------------------------------------------------------------- // CaptivePortalService::nsITimer // This callback gets called every mDelay miliseconds // It issues a checkCaptivePortal operation if one isn't already in progress //----------------------------------------------------------------------------- NS_IMETHODIMP CaptivePortalService::Notify(nsITimer *aTimer) { LOG(("CaptivePortalService::Notify\n")); MOZ_ASSERT(aTimer == mTimer); MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); PerformCheck(); // This is needed because we don't want to always make requests very often. // Every 10 checks, we the delay is increased mBackoffFactor times // to a maximum delay of mMaxInterval mSlackCount++; if (mSlackCount % 10 == 0) { mDelay = mDelay * mBackoffFactor; } if (mDelay > mMaxInterval) { mDelay = mMaxInterval; } // Note - if mDelay is 0, the timer will not be rearmed. RearmTimer(); return NS_OK; }
static void StartDemo(HBROWSER_HANDLE hbrowser, HDOC_HANDLE hdoc, HELEMENT_HANDLE helem) { DemoStepCountDown = 0; CurrentButton = 0; CurrentButtonOver = 0; DemoUrlCountDown = 0; DemoStepElement = 0; CurrentElementX = 0; CurrentElementY = 0; RearmTimer(hbrowser, helem, 0); }
NS_IMETHODIMP CaptivePortalService::RecheckCaptivePortal() { LOG(("CaptivePortalService::RecheckCaptivePortal\n")); if (XRE_GetProcessType() != GeckoProcessType_Default) { // Doesn't do anything if called in the content process. return NS_OK; } // This is called for user activity. We need to reset the slack count, // so the checks continue to be quite frequent. mSlackCount = 0; mDelay = mMinInterval; PerformCheck(); RearmTimer(); return NS_OK; }
//----------------------------------------------------------------------------- // CaptivePortalService::nsIObserver //----------------------------------------------------------------------------- NS_IMETHODIMP CaptivePortalService::Observe(nsISupports *aSubject, const char * aTopic, const char16_t * aData) { if (XRE_GetProcessType() != GeckoProcessType_Default) { // Doesn't do anything if called in the content process. return NS_OK; } LOG(("CaptivePortalService::Observe() topic=%s\n", aTopic)); if (!strcmp(aTopic, kOpenCaptivePortalLoginEvent)) { // A redirect or altered content has been detected. // The user needs to log in. We are in a captive portal. mState = LOCKED_PORTAL; mLastChecked = TimeStamp::Now(); mEverBeenCaptive = true; } else if (!strcmp(aTopic, kCaptivePortalLoginSuccessEvent)) { // The user has successfully logged in. We have connectivity. mState = UNLOCKED_PORTAL; mLastChecked = TimeStamp::Now(); mSlackCount = 0; mDelay = mMinInterval; RearmTimer(); } else if (!strcmp(aTopic, kAbortCaptivePortalLoginEvent)) { // The login has been aborted mState = UNKNOWN; mLastChecked = TimeStamp::Now(); mSlackCount = 0; } // Send notification so that the captive portal state is mirrored in the // content process. nsCOMPtr<nsIObserverService> observerService = services::GetObserverService(); if (observerService) { nsCOMPtr<nsICaptivePortalService> cps(this); observerService->NotifyObservers(cps, NS_IPC_CAPTIVE_PORTAL_SET_STATE, nullptr); } return NS_OK; }
// Set up event handlers and load the name into the text control (see below) // Load the current element name into the text control (see below) HTMLEventStatus NewElementBodycb(HBROWSER_HANDLE hbrowser, HDOC_HANDLE hdoc, HELEMENT_HANDLE helem, HTMLEvent* event,char * param) { switch (event->type) { case HTML_EVENT_LOAD: SetNewElementHandlers(hbrowser, hdoc, helem); NewElementLoadName(hbrowser, hdoc); if (DemoModeEnabled) StartDemo(hbrowser, hdoc, helem); break; case HTML_EVENT_TIMER: if (DemoModeEnabled) if (UpdateDemoMode(hbrowser, hdoc, helem)>=0) RearmTimer(hbrowser, helem, 0); break; case HTML_EVENT_UNLOAD: break; default: break; } return (HTML_EVENT_STATUS_CONTINUE); }