summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/jni
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/jni
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/jni')
-rw-r--r--Source/WebKit/android/jni/GeolocationServiceBridge.cpp29
-rw-r--r--Source/WebKit/android/jni/GeolocationServiceBridge.h12
-rw-r--r--Source/WebKit/android/jni/WebCoreFrameBridge.cpp16
-rw-r--r--Source/WebKit/android/jni/WebViewCore.cpp18
-rw-r--r--Source/WebKit/android/jni/WebViewCore.h3
5 files changed, 31 insertions, 47 deletions
diff --git a/Source/WebKit/android/jni/GeolocationServiceBridge.cpp b/Source/WebKit/android/jni/GeolocationServiceBridge.cpp
index 044131f..056c788 100644
--- a/Source/WebKit/android/jni/GeolocationServiceBridge.cpp
+++ b/Source/WebKit/android/jni/GeolocationServiceBridge.cpp
@@ -26,17 +26,15 @@
#include "config.h"
#include "GeolocationServiceBridge.h"
-#include "GeolocationServiceAndroid.h"
#include "WebViewCore.h"
-#include <Geoposition.h>
+#include <GeolocationError.h>
+#include <GeolocationPosition.h>
#include <JNIHelp.h>
-#include <PositionError.h>
using JSC::Bindings::getJNIEnv;
-using WebCore::Coordinates;
-using WebCore::Geoposition;
-using WebCore::PositionError;
+using WebCore::GeolocationError;
+using WebCore::GeolocationPosition;
namespace android {
@@ -118,18 +116,17 @@ void GeolocationServiceBridge::newLocationAvailable(JNIEnv* env, jclass, jlong n
ASSERT(nativeObject);
ASSERT(location);
GeolocationServiceBridge* object = reinterpret_cast<GeolocationServiceBridge*>(nativeObject);
- object->m_listener->newPositionAvailable(toGeoposition(env, location));
+ object->m_listener->newPositionAvailable(toGeolocationPosition(env, location));
}
void GeolocationServiceBridge::newErrorAvailable(JNIEnv* env, jclass, jlong nativeObject, jstring message)
{
GeolocationServiceBridge* object = reinterpret_cast<GeolocationServiceBridge*>(nativeObject);
- RefPtr<PositionError> error =
- PositionError::create(PositionError::POSITION_UNAVAILABLE, android::jstringToWtfString(env, message));
+ RefPtr<GeolocationError> error = GeolocationError::create(GeolocationError::PositionUnavailable, jstringToWtfString(env, message));
object->m_listener->newErrorAvailable(error.release());
}
-PassRefPtr<Geoposition> GeolocationServiceBridge::toGeoposition(JNIEnv *env, const jobject &location)
+PassRefPtr<GeolocationPosition> GeolocationServiceBridge::toGeolocationPosition(JNIEnv *env, const jobject &location)
{
// Altitude is optional and may not be supplied.
bool hasAltitude =
@@ -158,18 +155,15 @@ PassRefPtr<Geoposition> GeolocationServiceBridge::toGeoposition(JNIEnv *env, con
env->CallFloatMethod(location, javaLocationClassMethodIDs[LocationMethodGetSpeed]) :
0.0;
- RefPtr<Coordinates> newCoordinates = Coordinates::create(
+ return GeolocationPosition::create(
+ env->CallLongMethod(location, javaLocationClassMethodIDs[LocationMethodGetTime]) / 1000.0,
env->CallDoubleMethod(location, javaLocationClassMethodIDs[LocationMethodGetLatitude]),
env->CallDoubleMethod(location, javaLocationClassMethodIDs[LocationMethodGetLongitude]),
- hasAltitude, Altitude,
Accuracy,
+ hasAltitude, Altitude,
false, 0.0, // AltitudeAccuracy not provided.
hasHeading, heading,
hasSpeed, speed);
-
- return Geoposition::create(
- newCoordinates.release(),
- env->CallLongMethod(location, javaLocationClassMethodIDs[LocationMethodGetTime]));
}
void GeolocationServiceBridge::startJavaImplementation(WebViewCore* webViewCore)
@@ -240,10 +234,9 @@ void GeolocationServiceBridge::startJavaImplementation(WebViewCore* webViewCore)
void GeolocationServiceBridge::stopJavaImplementation()
{
- // Called by GeolocationServiceAndroid on WebKit thread.
if (!m_javaGeolocationServiceObject)
return;
getJNIEnv()->DeleteGlobalRef(m_javaGeolocationServiceObject);
}
-} // namespace WebCore
+} // namespace android
diff --git a/Source/WebKit/android/jni/GeolocationServiceBridge.h b/Source/WebKit/android/jni/GeolocationServiceBridge.h
index 1813984..826ba71 100644
--- a/Source/WebKit/android/jni/GeolocationServiceBridge.h
+++ b/Source/WebKit/android/jni/GeolocationServiceBridge.h
@@ -30,8 +30,8 @@
#include <wtf/PassRefPtr.h>
namespace WebCore {
-class Geoposition;
-class PositionError;
+class GeolocationError;
+class GeolocationPosition;
}
namespace android {
@@ -40,14 +40,14 @@ class WebViewCore;
// GeolocationServiceBridge is the bridge to the Java implementation. It manages
// the lifetime of the Java object. It is an implementation detail of
-// GeolocationServiceAndroid.
+// GeolocationClientAndroid.
class GeolocationServiceBridge {
public:
class Listener {
public:
virtual ~Listener() {}
- virtual void newPositionAvailable(PassRefPtr<WebCore::Geoposition>) = 0;
- virtual void newErrorAvailable(PassRefPtr<WebCore::PositionError>) = 0;
+ virtual void newPositionAvailable(PassRefPtr<WebCore::GeolocationPosition>) = 0;
+ virtual void newErrorAvailable(PassRefPtr<WebCore::GeolocationError>) = 0;
};
GeolocationServiceBridge(Listener*, WebViewCore*);
@@ -60,7 +60,7 @@ public:
// Static wrapper functions to hide JNI nastiness.
static void newLocationAvailable(JNIEnv *env, jclass, jlong nativeObject, jobject location);
static void newErrorAvailable(JNIEnv *env, jclass, jlong nativeObject, jstring message);
- static PassRefPtr<WebCore::Geoposition> toGeoposition(JNIEnv *env, const jobject &location);
+ static PassRefPtr<WebCore::GeolocationPosition> toGeolocationPosition(JNIEnv *env, const jobject &location);
private:
void startJavaImplementation(WebViewCore*);
diff --git a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp
index af582fa..a9fa288 100644
--- a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp
+++ b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp
@@ -50,6 +50,7 @@
#include "FrameLoadRequest.h"
#include "FrameTree.h"
#include "FrameView.h"
+#include "GeolocationClientAndroid.h"
#include "GraphicsContext.h"
#include "HistoryItem.h"
#include "HTMLCollection.h"
@@ -497,15 +498,9 @@ WebFrame::loadStarted(WebCore::Frame* frame)
if (favicon)
env->DeleteLocalRef(favicon);
- // Inform the client that the main frame has started a new load.
- if (isMainFrame && mPage) {
- Chrome* chrome = mPage->chrome();
- if (chrome) {
- ChromeClientAndroid* client = static_cast<ChromeClientAndroid*>(chrome->client());
- if (client)
- client->onMainFrameLoadStarted();
- }
- }
+ // The main frame has started a new load.
+ if (isMainFrame && mPage)
+ WebViewCore::getWebViewCore(mPage->mainFrame()->view())->geolocationManager()->resetRealClientTemporaryPermissionStates();
}
void
@@ -1099,6 +1094,7 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss
EditorClientAndroid* editorC = new EditorClientAndroid;
DeviceMotionClientAndroid* deviceMotionC = new DeviceMotionClientAndroid;
DeviceOrientationClientAndroid* deviceOrientationC = new DeviceOrientationClientAndroid;
+ GeolocationClientAndroid* geolocationC = new GeolocationClientAndroid;
WebCore::Page::PageClients pageClients;
pageClients.chromeClient = chromeC;
@@ -1108,6 +1104,7 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss
pageClients.inspectorClient = new InspectorClientAndroid;
pageClients.deviceMotionClient = deviceMotionC;
pageClients.deviceOrientationClient = deviceOrientationC;
+ pageClients.geolocationClient = geolocationC;
WebCore::Page* page = new WebCore::Page(pageClients);
editorC->setPage(page);
@@ -1150,6 +1147,7 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss
frame->page()->focusController()->setFocused(true);
deviceMotionC->setWebViewCore(webViewCore);
deviceOrientationC->setWebViewCore(webViewCore);
+ geolocationC->setWebViewCore(webViewCore);
// Allow local access to file:/// and substitute data
WebCore::SecurityOrigin::setLocalLoadPolicy(
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp
index 8499b50..60830fc 100644
--- a/Source/WebKit/android/jni/WebViewCore.cpp
+++ b/Source/WebKit/android/jni/WebViewCore.cpp
@@ -443,6 +443,7 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
, m_screenOnCounter(0)
, m_currentNodeDomNavigationAxis(0)
, m_deviceMotionAndOrientationManager(this)
+ , m_geolocationManager(this)
#if ENABLE(TOUCH_EVENTS)
, m_forwardingTouchEvents(false)
#endif
@@ -4751,10 +4752,7 @@ static void GeolocationPermissionsProvide(JNIEnv* env, jobject obj,
jint nativeClass, jstring origin, jboolean allow, jboolean remember)
{
WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass);
- Frame* frame = viewImpl->mainFrame();
-
- ChromeClientAndroid* chromeClient = static_cast<ChromeClientAndroid*>(frame->page()->chrome()->client());
- chromeClient->provideGeolocationPermissions(jstringToWtfString(env, origin), allow, remember);
+ viewImpl->geolocationManager()->provideRealClientPermissionState(jstringToWtfString(env, origin), allow, remember);
}
static void RegisterURLSchemeAsLocal(JNIEnv* env, jobject obj, jint nativeClass,
@@ -4788,15 +4786,11 @@ static void Pause(JNIEnv* env, jobject obj, jint nativeClass)
WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass);
Frame* mainFrame = viewImpl->mainFrame();
- for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext()) {
- Geolocation* geolocation = frame->domWindow()->navigator()->optionalGeolocation();
- if (geolocation)
- geolocation->suspend();
- }
if (mainFrame)
mainFrame->settings()->setMinDOMTimerInterval(BACKGROUND_TIMER_INTERVAL);
viewImpl->deviceMotionAndOrientationManager()->maybeSuspendClients();
+ viewImpl->geolocationManager()->suspendRealClient();
ANPEvent event;
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
@@ -4810,15 +4804,11 @@ static void Resume(JNIEnv* env, jobject obj, jint nativeClass)
{
WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass);
Frame* mainFrame = viewImpl->mainFrame();
- for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext()) {
- Geolocation* geolocation = frame->domWindow()->navigator()->optionalGeolocation();
- if (geolocation)
- geolocation->resume();
- }
if (mainFrame)
mainFrame->settings()->setMinDOMTimerInterval(FOREGROUND_TIMER_INTERVAL);
viewImpl->deviceMotionAndOrientationManager()->maybeResumeClients();
+ viewImpl->geolocationManager()->resumeRealClient();
ANPEvent event;
SkANP::InitEvent(&event, kLifecycle_ANPEventType);
diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h
index bfd9387..f371f69 100644
--- a/Source/WebKit/android/jni/WebViewCore.h
+++ b/Source/WebKit/android/jni/WebViewCore.h
@@ -30,6 +30,7 @@
#include "DOMSelection.h"
#include "FileChooser.h"
#include "FocusDirection.h"
+#include "GeolocationManager.h"
#include "HitTestResult.h"
#include "PicturePile.h"
#include "PlatformGraphicsContext.h"
@@ -543,6 +544,7 @@ namespace android {
void setWebTextViewAutoFillable(int queryId, const string16& previewSummary);
DeviceMotionAndOrientationManager* deviceMotionAndOrientationManager() { return &m_deviceMotionAndOrientationManager; }
+ GeolocationManager* geolocationManager() { return &m_geolocationManager; }
void listBoxRequest(WebCoreReply* reply, const uint16_t** labels,
size_t count, const int enabled[], size_t enabledCount,
@@ -798,6 +800,7 @@ namespace android {
int m_screenOnCounter;
WebCore::Node* m_currentNodeDomNavigationAxis;
DeviceMotionAndOrientationManager m_deviceMotionAndOrientationManager;
+ GeolocationManager m_geolocationManager;
#if ENABLE(TOUCH_EVENTS)
bool m_forwardingTouchEvents;