summaryrefslogtreecommitdiffstats
path: root/WebCore
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2009-08-25 12:10:30 +0100
committerSteve Block <steveblock@google.com>2009-09-03 18:24:20 +0100
commit3ae77a67311f7f1a6a072ccb81b5f502b09e4fb2 (patch)
tree41e0110540d80ed537af6db9c47c92b6c5e84a95 /WebCore
parentf7d703686fcbad876e7ce6d21a52d9a6cd71d2e8 (diff)
downloadexternal_webkit-3ae77a67311f7f1a6a072ccb81b5f502b09e4fb2.zip
external_webkit-3ae77a67311f7f1a6a072ccb81b5f502b09e4fb2.tar.gz
external_webkit-3ae77a67311f7f1a6a072ccb81b5f502b09e4fb2.tar.bz2
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.
Diffstat (limited to 'WebCore')
-rw-r--r--WebCore/page/Geolocation.cpp57
-rw-r--r--WebCore/page/Geolocation.h1
2 files changed, 25 insertions, 33 deletions
diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp
index e57a8b5..5d908a3 100644
--- a/WebCore/page/Geolocation.cpp
+++ b/WebCore/page/Geolocation.cpp
@@ -105,13 +105,33 @@ void Geolocation::disconnectFrame()
void Geolocation::getCurrentPosition(PassRefPtr<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
{
+ RefPtr<GeoNotifier> notifier = makeRequest(successCallback, errorCallback, options);
+ if (!notifier)
+ return;
+
+ m_oneShots.add(notifier);
+}
+
+int Geolocation::watchPosition(PassRefPtr<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
+{
+ RefPtr<GeoNotifier> notifier = makeRequest(successCallback, errorCallback, options);
+ if (!notifier)
+ return 0;
+
+ static int sIdentifier = 0;
+ m_watchers.set(++sIdentifier, notifier);
+
+ return sIdentifier;
+}
+
+PassRefPtr<Geolocation::GeoNotifier> Geolocation::makeRequest(PassRefPtr<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
+{
RefPtr<GeoNotifier> 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<PositionError> 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<PositionCallback> successCallbac
RefPtr<PositionError> 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<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options)
-{
- RefPtr<GeoNotifier> 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<PositionError> 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<PositionError> 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 6681592..18c2be3 100644
--- a/WebCore/page/Geolocation.h
+++ b/WebCore/page/Geolocation.h
@@ -111,6 +111,7 @@ private:
void handleError(PositionError*);
void requestPermission();
+ PassRefPtr<GeoNotifier> makeRequest(PassRefPtr<PositionCallback>, PassRefPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>);
// GeolocationServiceClient
virtual void geolocationServicePositionChanged(GeolocationService*);