summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/WebCoreSupport
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2012-05-17 18:17:15 +0100
committerSteve Block <steveblock@google.com>2012-05-22 14:17:23 +0100
commit5c36c4ca9214cbbe65d12f6b138aef9618d41a99 (patch)
tree8112a55f7cf8cb505115429d01ee73badf586896 /Source/WebKit/android/WebCoreSupport
parent0e1334bbc130fb9f7b19ea2354693cea34ebb894 (diff)
downloadexternal_webkit-5c36c4ca9214cbbe65d12f6b138aef9618d41a99.zip
external_webkit-5c36c4ca9214cbbe65d12f6b138aef9618d41a99.tar.gz
external_webkit-5c36c4ca9214cbbe65d12f6b138aef9618d41a99.tar.bz2
Switch to client-based Geolocation
The motivation for this switch is that it is required to enable PREEMPT_GEOLOCATION_PERMISSION. See b/4500947. The switch involves changing lots of Android's WebKit plumbing to use a new GeolocationClientAndroid in WebKit (called from WebCore::GeolocationController), rather than the existing GeolocationServiceAndroid in WebCore/platform (called from WebCore::Geolocation). This is complicated by the need to support mocking for LayoutTests. The pattern used is very similar to that used for DeviceOrientation and DeviceMotion. This patch ... - Enables CLIENT_BASED_GEOLOCATION - Leaves PREEMPT_GEOLOCATION_PERMISSION disabled for now - Removes GeolocationServiceAndroid - Adds a new GeolocationClientAndroid - Just a proxy to real client - Adds a new GeolocationManager - Manages switching between the real and mock clients - Provides the appropriate client to GeolocationClientAndroid - Plumbs to the real client calls for permissions and for suspending/resuming - Adds a new GeolocationClientImpl - The real client - Based heavily on GeolocationServiceAndroid - Delegates to GeolocationServiceBridge, as GeolocationServiceAndroid did - Calls back directly to GeolocationController - Owns the existing GeolocationPermissions - Updates WebViewCore to call the GeolocationManager for permissions and for suspending/resuming - Removes superfluous ChromeClient methods for permissions Note that support for mocking will be added in a later change. See bug for details. Bug: 6511338 Change-Id: I4cdbf55846e76b37c161834b83135b4dc48dbcdc
Diffstat (limited to 'Source/WebKit/android/WebCoreSupport')
-rw-r--r--Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp28
-rw-r--r--Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.h21
-rw-r--r--Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.cpp96
-rw-r--r--Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.h61
-rw-r--r--Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.cpp199
-rw-r--r--Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.h83
-rw-r--r--Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp86
-rw-r--r--Source/WebKit/android/WebCoreSupport/GeolocationManager.h71
8 files changed, 604 insertions, 41 deletions
diff --git a/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp b/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp
index e736087..cad23dc 100644
--- a/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp
+++ b/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp
@@ -512,34 +512,6 @@ void ChromeClientAndroid::populateVisitedLinks()
android::WebViewCore::getWebViewCore(view)->populateVisitedLinks(&page->group());
}
-void ChromeClientAndroid::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
-{
- ASSERT(geolocation);
- if (!m_geolocationPermissions) {
- WebViewCore* webViewCore = android::WebViewCore::getWebViewCore(frame->view());
- ASSERT(webViewCore->mainFrame() == m_webFrame->page()->mainFrame());
- m_geolocationPermissions = new GeolocationPermissions(webViewCore);
- }
- m_geolocationPermissions->queryPermissionState(frame);
-}
-
-void ChromeClientAndroid::cancelGeolocationPermissionRequestForFrame(Frame* frame, WebCore::Geolocation*)
-{
- if (m_geolocationPermissions)
- m_geolocationPermissions->cancelPermissionStateQuery(frame);
-}
-
-void ChromeClientAndroid::provideGeolocationPermissions(const String &origin, bool allow, bool remember)
-{
- m_geolocationPermissions->providePermissionState(origin, allow, remember);
-}
-
-void ChromeClientAndroid::onMainFrameLoadStarted()
-{
- if (m_geolocationPermissions.get())
- m_geolocationPermissions->resetTemporaryPermissionStates();
-}
-
void ChromeClientAndroid::runOpenPanel(Frame* frame,
PassRefPtr<FileChooser> chooser)
{
diff --git a/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.h b/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.h
index 8b509d5..82f3a23 100644
--- a/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.h
+++ b/Source/WebKit/android/WebCoreSupport/ChromeClientAndroid.h
@@ -28,7 +28,6 @@
#include "ChromeClient.h"
-#include "GeolocationPermissions.h"
#include "PopupMenu.h"
#include "SearchPopupMenu.h"
#include "Timer.h"
@@ -47,13 +46,13 @@ namespace android {
class ChromeClientAndroid : public ChromeClient {
public:
- ChromeClientAndroid() : m_webFrame(0), m_geolocationPermissions(0)
+ ChromeClientAndroid() : m_webFrame(0)
#if USE(ACCELERATED_COMPOSITING)
- , m_rootGraphicsLayer(0)
- , m_needsLayerSync(false)
+ , m_rootGraphicsLayer(0)
+ , m_needsLayerSync(false)
#endif
- , m_triedToReclaimDBQuota(false)
- { }
+ , m_triedToReclaimDBQuota(false)
+ { }
virtual void chromeDestroyed();
virtual void setWindowRect(const FloatRect&);
@@ -147,11 +146,9 @@ namespace android {
#endif
// Methods used to request and provide Geolocation permissions.
- virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*);
- virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*);
- // Android-specific
- void provideGeolocationPermissions(const String &origin, bool allow, bool remember);
- void onMainFrameLoadStarted();
+ // Not used with client-based Geolocation
+ virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) { ASSERT_NOT_REACHED(); }
+ virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*) { ASSERT_NOT_REACHED(); }
virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>);
virtual void setCursor(const Cursor&);
@@ -201,8 +198,6 @@ namespace android {
private:
android::WebFrame* m_webFrame;
- // The Geolocation permissions manager.
- OwnPtr<GeolocationPermissions> m_geolocationPermissions;
#if USE(ACCELERATED_COMPOSITING)
WebCore::GraphicsLayer* m_rootGraphicsLayer;
bool m_needsLayerSync;
diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.cpp b/Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.cpp
new file mode 100644
index 0000000..7c5b207
--- /dev/null
+++ b/Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GeolocationClientAndroid.h"
+
+#include "WebViewCore.h"
+
+#include <Frame.h>
+#include <Page.h>
+
+using WebCore::Geolocation;
+using WebCore::GeolocationClient;
+using WebCore::GeolocationController;
+using WebCore::GeolocationPosition;
+
+namespace android {
+
+GeolocationClientAndroid::GeolocationClientAndroid() : m_webViewCore(0)
+{
+}
+
+GeolocationClientAndroid::~GeolocationClientAndroid()
+{
+}
+
+void GeolocationClientAndroid::geolocationDestroyed()
+{
+ delete this;
+}
+
+void GeolocationClientAndroid::startUpdating()
+{
+ client()->startUpdating();
+}
+
+void GeolocationClientAndroid::stopUpdating()
+{
+ client()->stopUpdating();
+}
+
+void GeolocationClientAndroid::setEnableHighAccuracy(bool enableHighAccuracy)
+{
+ client()->setEnableHighAccuracy(enableHighAccuracy);
+}
+
+GeolocationPosition* GeolocationClientAndroid::lastPosition()
+{
+ return client()->lastPosition();
+}
+
+void GeolocationClientAndroid::requestPermission(Geolocation* geolocation)
+{
+ client()->requestPermission(geolocation);
+}
+
+void GeolocationClientAndroid::cancelPermissionRequest(Geolocation* geolocation)
+{
+ client()->cancelPermissionRequest(geolocation);
+}
+
+void GeolocationClientAndroid::setWebViewCore(WebViewCore* webViewCore)
+{
+ ASSERT(!m_webViewCore);
+ m_webViewCore = webViewCore;
+ ASSERT(m_webViewCore);
+}
+
+GeolocationClient* GeolocationClientAndroid::client() const
+{
+ return m_webViewCore->geolocationManager()->client();
+}
+
+} // namespace android
diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.h b/Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.h
new file mode 100644
index 0000000..22405e1
--- /dev/null
+++ b/Source/WebKit/android/WebCoreSupport/GeolocationClientAndroid.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationClientAndroid_h
+#define GeolocationClientAndroid_h
+
+#include <GeolocationClient.h>
+
+namespace android {
+
+class WebViewCore;
+
+// The Android implementation of GeolocationClient. Acts as a proxy to
+// the real or mock impl, which is owned by the GeolocationManager.
+class GeolocationClientAndroid : public WebCore::GeolocationClient {
+public:
+ GeolocationClientAndroid();
+ virtual ~GeolocationClientAndroid();
+
+ // GeolocationClient
+ virtual void geolocationDestroyed();
+ virtual void startUpdating();
+ virtual void stopUpdating();
+ virtual void setEnableHighAccuracy(bool);
+ virtual WebCore::GeolocationPosition* lastPosition();
+ virtual void requestPermission(WebCore::Geolocation*);
+ virtual void cancelPermissionRequest(WebCore::Geolocation*);
+
+ void setWebViewCore(WebViewCore*);
+
+private:
+ WebCore::GeolocationClient* client() const;
+
+ WebViewCore* m_webViewCore;
+};
+
+} // namespace android
+
+#endif // GeolocationClientAndroid_h
diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.cpp b/Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.cpp
new file mode 100644
index 0000000..fce0e37
--- /dev/null
+++ b/Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.cpp
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GeolocationClientImpl.h"
+
+#include <Frame.h>
+#include <Page.h>
+#include <GeolocationController.h>
+#include <GeolocationError.h>
+#include <GeolocationPosition.h>
+#include <WebViewCore.h>
+#if PLATFORM(ANDROID)
+// Required for sim-eng build
+#include <math.h>
+#endif
+#include <wtf/CurrentTime.h>
+
+using WebCore::Geolocation;
+using WebCore::GeolocationError;
+using WebCore::GeolocationPosition;
+
+using namespace std;
+
+namespace {
+
+bool isPositionMovement(GeolocationPosition* position1, GeolocationPosition* position2)
+{
+ // For the small distances in which we are likely concerned, it's reasonable
+ // to approximate the distance between the two positions as the sum of the
+ // differences in latitude and longitude.
+ double delta = fabs(position1->latitude() - position2->latitude()) + fabs(position1->longitude() - position2->longitude());
+ // Approximate conversion from degrees of arc to metres.
+ delta *= 60 * 1852;
+ // The threshold is when the distance between the two positions exceeds the
+ // worse (larger) of the two accuracies.
+ int maxAccuracy = max(position1->accuracy(), position2->accuracy());
+ return delta > maxAccuracy;
+}
+
+bool isPositionMoreAccurate(GeolocationPosition* position1, GeolocationPosition* position2)
+{
+ return position2->accuracy() < position1->accuracy();
+}
+
+bool isPositionMoreTimely(GeolocationPosition* position1)
+{
+ double currentTime = WTF::currentTime();
+ double maximumAge = 10 * 60; // 10 minutes
+ return currentTime - position1->timestamp() > maximumAge;
+}
+
+} // anonymous namespace
+
+namespace android {
+
+GeolocationClientImpl::GeolocationClientImpl(WebViewCore* webViewCore)
+ : m_webViewCore(webViewCore)
+ , m_isSuspended(false)
+ , m_useGps(false)
+{
+}
+
+GeolocationClientImpl::~GeolocationClientImpl()
+{
+}
+
+void GeolocationClientImpl::geolocationDestroyed()
+{
+ // Lifetime is managed by GeolocationManager.
+}
+
+void GeolocationClientImpl::startUpdating()
+{
+ // Lazilly create the Java object.
+ ASSERT(!m_javaBridge);
+ m_javaBridge.set(new GeolocationServiceBridge(this, m_webViewCore));
+ ASSERT(m_javaBridge);
+
+ // Set whether to use GPS before we start the implementation.
+ m_javaBridge->setEnableGps(m_useGps);
+
+ // If we're suspended, don't start the service. It will be started when we
+ // get the call to resume().
+ if (!m_isSuspended)
+ m_javaBridge->start();
+}
+
+void GeolocationClientImpl::stopUpdating()
+{
+ // TODO: It would be good to re-use the Java bridge object.
+ m_javaBridge.clear();
+ // Reset last position and error to make sure that we always try to get a
+ // new position from the client when a request is first made.
+ m_lastPosition = 0;
+ m_lastError = 0;
+}
+
+void GeolocationClientImpl::setEnableHighAccuracy(bool enableHighAccuracy)
+{
+ // On Android, high power == GPS.
+ m_useGps = enableHighAccuracy;
+ if (m_javaBridge)
+ m_javaBridge->setEnableGps(m_useGps);
+}
+
+GeolocationPosition* GeolocationClientImpl::lastPosition()
+{
+ return m_lastPosition.get();
+}
+
+void GeolocationClientImpl::requestPermission(Geolocation* geolocation)
+{
+ permissions()->queryPermissionState(geolocation->frame());
+}
+
+void GeolocationClientImpl::cancelPermissionRequest(Geolocation* geolocation)
+{
+ permissions()->cancelPermissionStateQuery(geolocation->frame());
+}
+
+// Note that there is no guarantee that subsequent calls to this method offer a
+// more accurate or updated position.
+void GeolocationClientImpl::newPositionAvailable(PassRefPtr<GeolocationPosition> position)
+{
+ ASSERT(position);
+ if (!m_lastPosition
+ || isPositionMovement(m_lastPosition.get(), position.get())
+ || isPositionMoreAccurate(m_lastPosition.get(), position.get())
+ || isPositionMoreTimely(m_lastPosition.get())) {
+ m_lastPosition = position;
+ // Remove the last error.
+ m_lastError = 0;
+ m_webViewCore->mainFrame()->page()->geolocationController()->positionChanged(m_lastPosition.get());
+ }
+}
+
+void GeolocationClientImpl::newErrorAvailable(PassRefPtr<WebCore::GeolocationError> error)
+{
+ ASSERT(error);
+ // We leave the last position
+ m_lastError = error;
+ m_webViewCore->mainFrame()->page()->geolocationController()->errorOccurred(m_lastError.get());
+}
+
+void GeolocationClientImpl::suspend()
+{
+ m_isSuspended = true;
+ if (m_javaBridge)
+ m_javaBridge->stop();
+}
+
+void GeolocationClientImpl::resume()
+{
+ m_isSuspended = false;
+ if (m_javaBridge)
+ m_javaBridge->start();
+}
+
+void GeolocationClientImpl::resetTemporaryPermissionStates()
+{
+ permissions()->resetTemporaryPermissionStates();
+}
+
+void GeolocationClientImpl::providePermissionState(String origin, bool allow, bool remember)
+{
+ permissions()->providePermissionState(origin, allow, remember);
+}
+
+GeolocationPermissions* GeolocationClientImpl::permissions() const
+{
+ if (!m_permissions)
+ m_permissions = new GeolocationPermissions(m_webViewCore);
+ return m_permissions.get();
+}
+
+} // namespace android
diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.h b/Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.h
new file mode 100644
index 0000000..81a6db3
--- /dev/null
+++ b/Source/WebKit/android/WebCoreSupport/GeolocationClientImpl.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationClientImpl_h
+#define GeolocationClientImpl_h
+
+#include "GeolocationServiceBridge.h"
+#include "GeolocationClient.h"
+#include "GeolocationPermissions.h"
+
+#include <wtf/OwnPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+class Geolocation;
+class GeolocationController;
+}
+
+namespace android {
+
+class WebViewCore;
+
+// The real implementation of GeolocationClient.
+class GeolocationClientImpl : public WebCore::GeolocationClient, public GeolocationServiceBridge::Listener {
+public:
+ GeolocationClientImpl(WebViewCore*);
+ virtual ~GeolocationClientImpl();
+
+ // WebCore::GeolocationClient
+ virtual void geolocationDestroyed();
+ virtual void startUpdating();
+ virtual void stopUpdating();
+ virtual void setEnableHighAccuracy(bool);
+ virtual WebCore::GeolocationPosition* lastPosition();
+ virtual void requestPermission(WebCore::Geolocation*);
+ virtual void cancelPermissionRequest(WebCore::Geolocation*);
+
+ // GeolocationServiceBridge::Listener
+ virtual void newPositionAvailable(PassRefPtr<WebCore::GeolocationPosition>);
+ virtual void newErrorAvailable(PassRefPtr<WebCore::GeolocationError>);
+
+ void suspend();
+ void resume();
+ void resetTemporaryPermissionStates();
+ void providePermissionState(String origin, bool allow, bool remember);
+
+private:
+ GeolocationPermissions* permissions() const;
+
+ WebViewCore* m_webViewCore;
+ RefPtr<WebCore::GeolocationPosition> m_lastPosition;
+ RefPtr<WebCore::GeolocationError> m_lastError;
+ OwnPtr<GeolocationServiceBridge> m_javaBridge;
+ mutable OwnPtr<GeolocationPermissions> m_permissions;
+ bool m_isSuspended;
+ bool m_useGps;
+};
+
+} // namespace android
+
+#endif // GeolocationClientImpl_h
diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp b/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp
new file mode 100644
index 0000000..8d0d6b5
--- /dev/null
+++ b/Source/WebKit/android/WebCoreSupport/GeolocationManager.cpp
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "GeolocationManager.h"
+
+#include "GeolocationClientImpl.h"
+#include "WebViewCore.h"
+
+#include <GeolocationError.h>
+#include <GeolocationPosition.h>
+#include <JNIHelp.h>
+
+using WebCore::GeolocationClient;
+
+namespace android {
+
+GeolocationManager::GeolocationManager(WebViewCore* webViewCore)
+ : m_webViewCore(webViewCore)
+{
+}
+
+GeolocationClient* GeolocationManager::client() const
+{
+ // TODO: Return the mock client when appropriate. See http://b/6511338.
+ return realClient();
+}
+
+void GeolocationManager::suspendRealClient()
+{
+ // Don't create the real client if it's not present.
+ if (m_realClient)
+ m_realClient->suspend();
+}
+
+void GeolocationManager::resumeRealClient()
+{
+ // Don't create the real client if it's not present.
+ if (m_realClient)
+ m_realClient->resume();
+}
+
+void GeolocationManager::resetRealClientTemporaryPermissionStates()
+{
+ // Don't create the real client if it's not present.
+ if (m_realClient)
+ m_realClient->resetTemporaryPermissionStates();
+}
+
+void GeolocationManager::provideRealClientPermissionState(WTF::String origin, bool allow, bool remember)
+{
+ // Don't create the real client if it's not present.
+ if (m_realClient)
+ m_realClient->providePermissionState(origin, allow, remember);
+}
+
+GeolocationClientImpl* GeolocationManager::realClient() const
+{
+ if (!m_realClient)
+ m_realClient.set(new GeolocationClientImpl(m_webViewCore));
+ return m_realClient.get();
+}
+
+} // namespace android
diff --git a/Source/WebKit/android/WebCoreSupport/GeolocationManager.h b/Source/WebKit/android/WebCoreSupport/GeolocationManager.h
new file mode 100644
index 0000000..707cf6f
--- /dev/null
+++ b/Source/WebKit/android/WebCoreSupport/GeolocationManager.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef GeolocationManager_h
+#define GeolocationManager_h
+
+#include "GeolocationClientImpl.h"
+
+#include <OwnPtr.h>
+#include <PassRefPtr.h>
+
+namespace WebCore {
+class GeolocationError;
+class GeolocationPosition;
+}
+
+namespace android {
+
+class GeolocationClientImpl;
+class WebViewCore;
+
+// This class takes care of the fact that the client used for Geolocation
+// may be either the real implementation or a mock. It also handles setting the
+// data on the mock client. This class is owned by WebViewCore and exists to
+// keep cruft out of that class.
+// TODO: Add support for mock. See b/6511338.
+class GeolocationManager {
+public:
+ GeolocationManager(WebViewCore*);
+
+ // For use by GeolocationClientAndroid. Gets the current client, either the
+ // real or mock.
+ WebCore::GeolocationClient* client() const;
+
+ void suspendRealClient();
+ void resumeRealClient();
+ void resetRealClientTemporaryPermissionStates();
+ void provideRealClientPermissionState(WTF::String origin, bool allow, bool remember);
+
+private:
+ GeolocationClientImpl* realClient() const;
+
+ WebViewCore* m_webViewCore;
+ mutable OwnPtr<GeolocationClientImpl> m_realClient;
+};
+
+} // namespace android
+
+#endif // GeolocationManager_h