From: Steve Block Date: Tue, 25 Aug 2009 11:10:30 +0000 (+0100) Subject: Refactors Geolocation to avoid duplication in getCurrentPosition and watchPosition. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=3ae77a67311f7f1a6a072ccb81b5f502b09e4fb2;p=android-x86%2Fexternal-webkit.git Refactors Geolocation to avoid duplication in getCurrentPosition and watchPosition. This change is being submitted to WebKit as part of https://bugs.webkit.org/show_bug.cgi?id=27944. --- diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp index e57a8b598..5d908a341 100644 --- a/WebCore/page/Geolocation.cpp +++ b/WebCore/page/Geolocation.cpp @@ -105,13 +105,33 @@ void Geolocation::disconnectFrame() void Geolocation::getCurrentPosition(PassRefPtr successCallback, PassRefPtr errorCallback, PassRefPtr options) { + RefPtr notifier = makeRequest(successCallback, errorCallback, options); + if (!notifier) + return; + + m_oneShots.add(notifier); +} + +int Geolocation::watchPosition(PassRefPtr successCallback, PassRefPtr errorCallback, PassRefPtr options) +{ + RefPtr notifier = makeRequest(successCallback, errorCallback, options); + if (!notifier) + return 0; + + static int sIdentifier = 0; + m_watchers.set(++sIdentifier, notifier); + + return sIdentifier; +} + +PassRefPtr Geolocation::makeRequest(PassRefPtr successCallback, PassRefPtr errorCallback, PassRefPtr options) +{ RefPtr notifier = GeoNotifier::create(this, successCallback, errorCallback, options); // Check whether permissions have already been denied. Note that if this is the case, // the permission state can not change again in the lifetime of this page. if (isDenied()) { - RefPtr error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage); - notifier->setFatalError(error.release()); + notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage)); } else { if (m_service->startUpdating(notifier->m_options.get())) notifier->startTimerIfNeeded(); @@ -120,12 +140,11 @@ void Geolocation::getCurrentPosition(PassRefPtr successCallbac RefPtr error = PositionError::create(PositionError::PERMISSION_DENIED, "Unable to Start"); notifier->m_errorCallback->handleEvent(error.get()); } - return; + return 0; } } - m_oneShots.add(notifier); - + return notifier.release(); } void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) @@ -143,34 +162,6 @@ void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier) m_service->stopUpdating(); } -int Geolocation::watchPosition(PassRefPtr successCallback, PassRefPtr errorCallback, PassRefPtr options) -{ - RefPtr notifier = GeoNotifier::create(this, successCallback, errorCallback, options); - - // Check whether permissions have already been denied. Note that if this is the case, - // the permission state can not change again in the lifetime of this page. - if (isDenied()) { - RefPtr error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage); - notifier->setFatalError(error.release()); - } else { - if (m_service->startUpdating(notifier->m_options.get())) - notifier->startTimerIfNeeded(); - else { - if (notifier->m_errorCallback) { - RefPtr error = PositionError::create(PositionError::PERMISSION_DENIED, "Unable to Start"); - notifier->m_errorCallback->handleEvent(error.get()); - } - return 0; - } - } - - static int sIdentifier = 0; - - m_watchers.set(++sIdentifier, notifier); - - return sIdentifier; -} - void Geolocation::requestTimedOut(GeoNotifier* notifier) { // If this is a one-shot request, stop it. diff --git a/WebCore/page/Geolocation.h b/WebCore/page/Geolocation.h index 6681592a1..18c2be34f 100644 --- a/WebCore/page/Geolocation.h +++ b/WebCore/page/Geolocation.h @@ -111,6 +111,7 @@ private: void handleError(PositionError*); void requestPermission(); + PassRefPtr makeRequest(PassRefPtr, PassRefPtr, PassRefPtr); // GeolocationServiceClient virtual void geolocationServicePositionChanged(GeolocationService*);