summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-11-09 17:56:54 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-11-09 17:56:54 -0800
commitf3df443854d9a26a47c5f48c60b552d9d3c7efdd (patch)
treebc9a52a56885374a6d42a6210fd9bd0597c5ecf1
parent6f9b8a1745fc174f1c436237dde772fca8e47f06 (diff)
parent7de0f59ef4a50e0a204f9918636f10b254865d5e (diff)
downloadwebkit-f3df443854d9a26a47c5f48c60b552d9d3c7efdd.tar.gz
Merge change I43c19e84 into eclair
* changes: Stop Geolocation service when browser tab is in the background. Do not merge.
-rw-r--r--WebCore/platform/android/GeolocationServiceAndroid.cpp29
-rw-r--r--WebCore/platform/android/GeolocationServiceAndroid.h3
-rw-r--r--WebKit/android/jni/WebViewCore.cpp17
3 files changed, 47 insertions, 2 deletions
diff --git a/WebCore/platform/android/GeolocationServiceAndroid.cpp b/WebCore/platform/android/GeolocationServiceAndroid.cpp
index 782d51560..934005301 100644
--- a/WebCore/platform/android/GeolocationServiceAndroid.cpp
+++ b/WebCore/platform/android/GeolocationServiceAndroid.cpp
@@ -51,6 +51,7 @@ public:
~GeolocationServiceBridge();
void start();
+ void stop();
void setEnableGps(bool enable);
// Static wrapper functions to hide JNI nastiness.
@@ -110,6 +111,7 @@ GeolocationServiceBridge::GeolocationServiceBridge(ListenerInterface* listener)
GeolocationServiceBridge::~GeolocationServiceBridge()
{
+ stop();
stopJavaImplementation();
}
@@ -120,6 +122,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);
@@ -254,8 +263,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);
}
@@ -322,6 +329,24 @@ void GeolocationServiceAndroid::stopUpdating()
m_lastError = 0;
}
+void GeolocationServiceAndroid::suspend()
+{
+ // If the Geolocation object has called stopUpdating, and hence the bridge
+ // object has been destroyed, we should not receive calls to this method
+ // until startUpdating is called again and the bridge is recreated.
+ ASSERT(m_javaBridge);
+ m_javaBridge->stop();
+}
+
+void GeolocationServiceAndroid::resume()
+{
+ // If the Geolocation object has called stopUpdating, and hence the bridge
+ // object has been destroyed, we should not receive calls to this method
+ // until startUpdating is called again and the bridge is recreated.
+ 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<Geoposition> position)
diff --git a/WebCore/platform/android/GeolocationServiceAndroid.h b/WebCore/platform/android/GeolocationServiceAndroid.h
index 90a8864dd..e8ed7ce62 100644
--- a/WebCore/platform/android/GeolocationServiceAndroid.h
+++ b/WebCore/platform/android/GeolocationServiceAndroid.h
@@ -52,6 +52,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<Geoposition>);
void newErrorAvailable(PassRefPtr<PositionError>);
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index f12960002..b16a69d8d 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -35,6 +35,7 @@
#include "Color.h"
#include "DatabaseTracker.h"
#include "Document.h"
+#include "DOMWindow.h"
#include "Element.h"
#include "Editor.h"
#include "EditorClientAndroid.h"
@@ -47,6 +48,7 @@
#include "FrameLoaderClientAndroid.h"
#include "FrameTree.h"
#include "FrameView.h"
+#include "Geolocation.h"
#include "GraphicsContext.h"
#include "GraphicsJNI.h"
#include "HitTestResult.h"
@@ -64,6 +66,7 @@
#include "InlineTextBox.h"
#include <JNIHelp.h>
#include "KeyboardCodes.h"
+#include "Navigator.h"
#include "Node.h"
#include "Page.h"
#include "PageGroup.h"
@@ -2773,6 +2776,13 @@ static void Pause(JNIEnv* env, jobject obj)
ChromeClientAndroid* chromeClientAndroid = static_cast<ChromeClientAndroid*>(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;
@@ -2781,6 +2791,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;