From 159531f4ce4c04455cd544a7c0f7c1644a50ccbe Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 24 Feb 2010 11:11:00 +0000 Subject: Update Android to reflect final version submitted to webkit.org for Geolocation maximumAge See http://trac.webkit.org/changeset/55841 Change-Id: Ib504563b7be40b0ff794cdcc625b07f494bb6483 --- WebCore/page/Geolocation.cpp | 57 +++++++++++++++++++++----------------------- WebCore/page/Geolocation.h | 2 +- 2 files changed, 28 insertions(+), 31 deletions(-) (limited to 'WebCore/page') diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp index d021f7b..ad5f8d6 100644 --- a/WebCore/page/Geolocation.cpp +++ b/WebCore/page/Geolocation.cpp @@ -48,6 +48,7 @@ namespace WebCore { static const char permissionDeniedErrorMessage[] = "User denied Geolocation"; +static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocation service"; #if ENABLE(CLIENT_BASED_GEOLOCATION) @@ -101,18 +102,18 @@ void Geolocation::GeoNotifier::setFatalError(PassRefPtr error) m_timer.startOneShot(0); } -bool Geolocation::GeoNotifier::hasZeroTimeout() const -{ - return m_options->hasTimeout() && m_options->timeout() == 0; -} - void Geolocation::GeoNotifier::setUseCachedPosition() { m_useCachedPosition = true; m_timer.startOneShot(0); } -void Geolocation::GeoNotifier::makeSuccessCallback(Geoposition* position) +bool Geolocation::GeoNotifier::hasZeroTimeout() const +{ + return m_options->hasTimeout() && m_options->timeout() == 0; +} + +void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position) { m_successCallback->handleEvent(position); } @@ -285,20 +286,16 @@ PassRefPtr Geolocation::startRequest(PassRefPtrsetFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); - else { - if (haveSuitableCachedPosition(notifier->m_options.get())) - notifier->setUseCachedPosition(); - else { - if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) { + else if (haveSuitableCachedPosition(notifier->m_options.get())) + notifier->setUseCachedPosition(); + else if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) { #if ENABLE(CLIENT_BASED_GEOLOCATION) - // Only start timer if we're not waiting for user permission. - if (!m_startRequestPermissionNotifier) + // Only start timer if we're not waiting for user permission. + if (!m_startRequestPermissionNotifier) #endif - notifier->startTimerIfNeeded(); - } else - notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, "Failed to start Geolocation service")); - } - } + notifier->startTimerIfNeeded(); + } else + notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); return notifier.release(); } @@ -313,15 +310,6 @@ void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) stopUpdating(); } -void Geolocation::requestTimedOut(GeoNotifier* notifier) -{ - // If this is a one-shot request, stop it. - m_oneShots.remove(notifier); - - if (!hasListeners()) - stopUpdating(); -} - void Geolocation::requestUsesCachedPosition(GeoNotifier* notifier) { // This is called asynchronously, so the permissions could have been denied @@ -351,7 +339,7 @@ void Geolocation::makeCachedPositionCallbacks() GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end(); for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.begin(); iter != end; ++iter) { GeoNotifier* notifier = iter->get(); - notifier->makeSuccessCallback(m_positionCache->cachedPosition()); + notifier->runSuccessCallback(m_positionCache->cachedPosition()); // If this is a one-shot request, stop it. Otherwise, if the watch still // exists, start the service to get updates. @@ -361,7 +349,7 @@ void Geolocation::makeCachedPositionCallbacks() if (notifier->hasZeroTimeout() || startUpdating(notifier)) notifier->startTimerIfNeeded(); else - notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, "Failed to start Geolocation service")); + notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage)); } } @@ -371,13 +359,22 @@ void Geolocation::makeCachedPositionCallbacks() stopUpdating(); } +void Geolocation::requestTimedOut(GeoNotifier* notifier) +{ + // If this is a one-shot request, stop it. + m_oneShots.remove(notifier); + + if (!hasListeners()) + stopUpdating(); +} + bool Geolocation::haveSuitableCachedPosition(PositionOptions* options) { if (!m_positionCache->cachedPosition()) return false; if (!options->hasMaximumAge()) return true; - if (options->maximumAge() == 0) + if (!options->maximumAge()) return false; DOMTimeStamp currentTimeMillis = currentTime() * 1000.0; return m_positionCache->cachedPosition()->timestamp() > currentTimeMillis - options->maximumAge(); diff --git a/WebCore/page/Geolocation.h b/WebCore/page/Geolocation.h index ade4ffe..2a282b5 100644 --- a/WebCore/page/Geolocation.h +++ b/WebCore/page/Geolocation.h @@ -97,7 +97,7 @@ private: void setFatalError(PassRefPtr); bool hasZeroTimeout() const; void setUseCachedPosition(); - void makeSuccessCallback(Geoposition*); + void runSuccessCallback(Geoposition*); void startTimerIfNeeded(); void timerFired(Timer*); -- cgit v1.1