From b999b2f567121b11fe014341931a72a5a7a6f4b4 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 28 Oct 2009 11:29:58 +0000 Subject: [PATCH] Stop Geolocation service when browser tab is in the background. This is a fix for bug http://b/issue?id=2211437 Change-Id: Id44b5b5679a302ecb16d5f493ea900d252faf2dc --- .../platform/android/GeolocationServiceAndroid.cpp | 23 ++++++++++++++++++++-- .../platform/android/GeolocationServiceAndroid.h | 3 +++ WebKit/android/jni/WebViewCore.cpp | 16 +++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/WebCore/platform/android/GeolocationServiceAndroid.cpp b/WebCore/platform/android/GeolocationServiceAndroid.cpp index 024877ea6..20185ce3c 100644 --- a/WebCore/platform/android/GeolocationServiceAndroid.cpp +++ b/WebCore/platform/android/GeolocationServiceAndroid.cpp @@ -50,6 +50,7 @@ public: ~GeolocationServiceBridge(); void start(); + void stop(); void setEnableGps(bool enable); // Static wrapper functions to hide JNI nastiness. @@ -109,6 +110,7 @@ GeolocationServiceBridge::GeolocationServiceBridge(ListenerInterface* listener) GeolocationServiceBridge::~GeolocationServiceBridge() { + stop(); stopJavaImplementation(); } @@ -119,6 +121,13 @@ void GeolocationServiceBridge::start() javaGeolocationServiceClassMethodIDs[GEOLOCATION_SERVICE_METHOD_START]); } +void GeolocationServiceBridge::stop() +{ + ASSERT(m_javaGeolocationServiceObject); + getJNIEnv()->CallVoidMethod(m_javaGeolocationServiceObject, + javaGeolocationServiceClassMethodIDs[GEOLOCATION_SERVICE_METHOD_STOP]); +} + void GeolocationServiceBridge::setEnableGps(bool enable) { ASSERT(m_javaGeolocationServiceObject); @@ -253,8 +262,6 @@ void GeolocationServiceBridge::stopJavaImplementation() { // Called by GeolocationServiceAndroid on WebKit thread. ASSERT(m_javaGeolocationServiceObject); - getJNIEnv()->CallVoidMethod(m_javaGeolocationServiceObject, - javaGeolocationServiceClassMethodIDs[GEOLOCATION_SERVICE_METHOD_STOP]); getJNIEnv()->DeleteGlobalRef(m_javaGeolocationServiceObject); } @@ -320,6 +327,18 @@ void GeolocationServiceAndroid::stopUpdating() m_lastError = 0; } +void GeolocationServiceAndroid::suspend() +{ + ASSERT(m_javaBridge); + m_javaBridge->stop(); +} + +void GeolocationServiceAndroid::resume() +{ + ASSERT(m_javaBridge); + m_javaBridge->start(); +} + // Note that there is no guarantee that subsequent calls to this method offer a // more accurate or updated position. void GeolocationServiceAndroid::newPositionAvailable(PassRefPtr position) diff --git a/WebCore/platform/android/GeolocationServiceAndroid.h b/WebCore/platform/android/GeolocationServiceAndroid.h index f233f9aa3..0eed8d7e8 100644 --- a/WebCore/platform/android/GeolocationServiceAndroid.h +++ b/WebCore/platform/android/GeolocationServiceAndroid.h @@ -51,6 +51,9 @@ namespace WebCore { virtual Geoposition* lastPosition() const { return m_lastPosition.get(); } virtual PositionError* lastError() const { return m_lastError.get(); } + virtual void suspend(); + virtual void resume(); + // Android-specific void newPositionAvailable(PassRefPtr); void newErrorAvailable(PassRefPtr); diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 158896741..53f9fd06f 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -47,6 +47,7 @@ #include "FrameLoaderClientAndroid.h" #include "FrameTree.h" #include "FrameView.h" +#include "Geolocation.h" #include "GraphicsContext.h" #include "GraphicsJNI.h" #include "HitTestResult.h" @@ -64,6 +65,7 @@ #include "InlineTextBox.h" #include #include "KeyboardCodes.h" +#include "Navigator.h" #include "Node.h" #include "Page.h" #include "PageGroup.h" @@ -2986,6 +2988,13 @@ static void Pause(JNIEnv* env, jobject obj) ChromeClientAndroid* chromeClientAndroid = static_cast(chromeClient); chromeClientAndroid->storeGeolocationPermissions(); + Frame* mainFrame = GET_NATIVE_VIEW(env, obj)->mainFrame(); + for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext()) { + Geolocation* geolocation = frame->domWindow()->navigator()->optionalGeolocation(); + if (geolocation) + geolocation->suspend(); + } + ANPEvent event; SkANP::InitEvent(&event, kLifecycle_ANPEventType); event.data.lifecycle.action = kPause_ANPLifecycleAction; @@ -2994,6 +3003,13 @@ static void Pause(JNIEnv* env, jobject obj) static void Resume(JNIEnv* env, jobject obj) { + Frame* mainFrame = GET_NATIVE_VIEW(env, obj)->mainFrame(); + for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext()) { + Geolocation* geolocation = frame->domWindow()->navigator()->optionalGeolocation(); + if (geolocation) + geolocation->resume(); + } + ANPEvent event; SkANP::InitEvent(&event, kLifecycle_ANPEventType); event.data.lifecycle.action = kResume_ANPLifecycleAction; -- 2.11.0