[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.22-985-g3c00f00
steveblock at google.com
steveblock at google.com
Wed Mar 17 18:32:55 UTC 2010
The following commit has been merged in the webkit-1.1 branch:
commit c629bc58d75739601426bbdf910fe4fb12054d0b
Author: steveblock at google.com <steveblock at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Mar 11 11:38:39 2010 +0000
2010-03-10 Steve Block <steveblock at google.com>
Reviewed by Jeremy Orlow.
Implements Geolocation maximumAge property
https://bugs.webkit.org/show_bug.cgi?id=30676
Test: fast/dom/Geolocation/maximum-age.html
* WebCore.xcodeproj/project.pbxproj: Modified. Adds GeolocationPositionCache.h to Private headers
* page/Geolocation.cpp: Modified.
(WebCore::Geolocation::GeoNotifier::setUseCachedPosition): Added.
(WebCore::Geolocation::GeoNotifier::runSuccessCallback): Added.
(WebCore::Geolocation::GeoNotifier::timerFired): Modified. Added logic to handle using a cached position
(WebCore::Geolocation::Watchers::contains): Added. Required to determine if a notifier is a watch request
(WebCore::Geolocation::startRequest): Modified. Added logic to check for a cached position
(WebCore::Geolocation::requestUsesCachedPosition): Added. Callback to Geolocation object when notifier uses a cached position
(WebCore::Geolocation::makeCachedPositionCallbacks): Added.
(WebCore::Geolocation::haveSuitableCachedPosition): Added.
(WebCore::Geolocation::setIsAllowed): Modified.
(WebCore::Geolocation::positionChanged): Modified. Make callbacks using cached position where appropriate
(WebCore::Geolocation::geolocationServiceErrorOccurred): Modified. Make callbacks using cached position where appropriate
* page/Geolocation.h: Modified.
2010-03-10 Steve Block <steveblock at google.com>
Reviewed by Jeremy Orlow.
Implements Geolocation maximumAge property
https://bugs.webkit.org/show_bug.cgi?id=30676
* fast/dom/Geolocation/resources/maximum-age.js: Added. Checks that a cached position is used only when it should be.
* fast/dom/Geolocation/maximum-age.html: Added. HTML wraper for above test.
* fast/dom/Geolocation/maximum-age-expected.txt: Added. Expected result for above test.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55841 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index c6b56ba..91ba1c2 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2010-03-10 Steve Block <steveblock at google.com>
+
+ Reviewed by Jeremy Orlow.
+
+ Implements Geolocation maximumAge property
+ https://bugs.webkit.org/show_bug.cgi?id=30676
+
+ * fast/dom/Geolocation/resources/maximum-age.js: Added. Checks that a cached position is used only when it should be.
+ * fast/dom/Geolocation/maximum-age.html: Added. HTML wraper for above test.
+ * fast/dom/Geolocation/maximum-age-expected.txt: Added. Expected result for above test.
+
2010-03-11 Philippe Normand <pnormand at igalia.com>
Unreviewed.
diff --git a/LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt b/LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt
new file mode 100644
index 0000000..71b1980
--- /dev/null
+++ b/LayoutTests/fast/dom/Geolocation/maximum-age-expected.txt
@@ -0,0 +1,24 @@
+Tests that the PositionOptions.maximumAge parameter is correctly applied.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+PASS position.coords.latitude is mockLatitude
+PASS position.coords.longitude is mockLongitude
+PASS position.coords.accuracy is mockAccuracy
+
+PASS position.coords.latitude is mockLatitude
+PASS position.coords.longitude is mockLongitude
+PASS position.coords.accuracy is mockAccuracy
+
+PASS position.coords.latitude is mockLatitude
+PASS position.coords.longitude is mockLongitude
+PASS position.coords.accuracy is mockAccuracy
+
+PASS error.code is mockCode
+PASS error.message is mockMessage
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/dom/Geolocation/maximum-age.html b/LayoutTests/fast/dom/Geolocation/maximum-age.html
new file mode 100644
index 0000000..2d871e0
--- /dev/null
+++ b/LayoutTests/fast/dom/Geolocation/maximum-age.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../js/resources/js-test-style.css">
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="resources/maximum-age.js"></script>
+<script src="resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/Geolocation/resources/maximum-age.js b/LayoutTests/fast/dom/Geolocation/resources/maximum-age.js
new file mode 100644
index 0000000..f48aa0d
--- /dev/null
+++ b/LayoutTests/fast/dom/Geolocation/resources/maximum-age.js
@@ -0,0 +1,81 @@
+description("Tests that the PositionOptions.maximumAge parameter is correctly applied.");
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100.0;
+
+var mockCode = 1;
+var mockMessage = 'test';
+
+var position;
+var error;
+
+function checkPosition(p) {
+ debug('');
+ position = p;
+ shouldBe('position.coords.latitude', 'mockLatitude');
+ shouldBe('position.coords.longitude', 'mockLongitude');
+ shouldBe('position.coords.accuracy', 'mockAccuracy');
+}
+
+function checkError(e) {
+ debug('');
+ error = e;
+ shouldBe('error.code', 'mockCode');
+ shouldBe('error.message', 'mockMessage');
+}
+
+window.layoutTestController.setGeolocationPermission(true);
+window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
+
+// Initialize the cached Position
+navigator.geolocation.getCurrentPosition(function(p) {
+ checkPosition(p);
+ testZeroMaximumAge();
+}, function(e) {
+ testFailed('Error callback invoked unexpectedly');
+ window.layoutTestController.notifyDone();
+});
+
+function testZeroMaximumAge() {
+ // Update the position provided by the mock service.
+ window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
+ // The default maximumAge is zero, so we expect the updated position from the service.
+ navigator.geolocation.getCurrentPosition(function(p) {
+ checkPosition(p);
+ testNonZeroMaximumAge();
+ }, function(e) {
+ testFailed('Error callback invoked unexpectedly');
+ window.layoutTestController.notifyDone();
+ });
+}
+
+function testNonZeroMaximumAge() {
+ // Update the mock service to report an error.
+ window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
+ // The maximumAge is non-zero, so we expect the cached position, not the error from the service.
+ navigator.geolocation.getCurrentPosition(function(p) {
+ checkPosition(p);
+ testZeroMaximumAgeError();
+ }, function(e) {
+ testFailed('Error callback invoked unexpectedly');
+ window.layoutTestController.notifyDone();
+ }, {maximumAge: 1000});
+}
+
+function testZeroMaximumAgeError() {
+ // The default maximumAge is zero, so we expect the error from the service.
+ navigator.geolocation.getCurrentPosition(function(p) {
+ testFailed('Success callback invoked unexpectedly');
+ window.layoutTestController.notifyDone();
+ }, function(e) {
+ checkError(e);
+ debug('<br /><span class="pass">TEST COMPLETE</span>');
+ window.layoutTestController.notifyDone();
+ });
+}
+
+window.layoutTestController.waitUntilDone();
+
+var isAsynchronous = true;
+var successfullyParsed = true;
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index b822639..352dbdc 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,27 @@
+2010-03-10 Steve Block <steveblock at google.com>
+
+ Reviewed by Jeremy Orlow.
+
+ Implements Geolocation maximumAge property
+ https://bugs.webkit.org/show_bug.cgi?id=30676
+
+ Test: fast/dom/Geolocation/maximum-age.html
+
+ * WebCore.xcodeproj/project.pbxproj: Modified. Adds GeolocationPositionCache.h to Private headers
+ * page/Geolocation.cpp: Modified.
+ (WebCore::Geolocation::GeoNotifier::setUseCachedPosition): Added.
+ (WebCore::Geolocation::GeoNotifier::runSuccessCallback): Added.
+ (WebCore::Geolocation::GeoNotifier::timerFired): Modified. Added logic to handle using a cached position
+ (WebCore::Geolocation::Watchers::contains): Added. Required to determine if a notifier is a watch request
+ (WebCore::Geolocation::startRequest): Modified. Added logic to check for a cached position
+ (WebCore::Geolocation::requestUsesCachedPosition): Added. Callback to Geolocation object when notifier uses a cached position
+ (WebCore::Geolocation::makeCachedPositionCallbacks): Added.
+ (WebCore::Geolocation::haveSuitableCachedPosition): Added.
+ (WebCore::Geolocation::setIsAllowed): Modified.
+ (WebCore::Geolocation::positionChanged): Modified. Make callbacks using cached position where appropriate
+ (WebCore::Geolocation::geolocationServiceErrorOccurred): Modified. Make callbacks using cached position where appropriate
+ * page/Geolocation.h: Modified.
+
2010-03-11 Csaba Osztrogonác <ossy at webkit.org>
Unreviewed buildfix after r55823. (To fix Qt --minimal build.)
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 4ef1f9c..10f7e0e 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -1123,7 +1123,7 @@
5913953B110758450083EC55 /* JNIBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 5913953A110758450083EC55 /* JNIBridge.h */; };
5913953D1107584E0083EC55 /* JNIBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5913953C1107584E0083EC55 /* JNIBridge.cpp */; };
596229781133EFD700DC4CBB /* GeolocationPositionCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 596229771133EFD700DC4CBB /* GeolocationPositionCache.cpp */; };
- 5962297A1133EFE200DC4CBB /* GeolocationPositionCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 596229791133EFE200DC4CBB /* GeolocationPositionCache.h */; };
+ 5962297A1133EFE200DC4CBB /* GeolocationPositionCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 596229791133EFE200DC4CBB /* GeolocationPositionCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
599E759011055A1F00D904FA /* Bridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 599E758F11055A1F00D904FA /* Bridge.h */; settings = {ATTRIBUTES = (Private, ); }; };
59A9E7B01104758800DFB4C1 /* JavaInstanceJSC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59A9E7AF1104758800DFB4C1 /* JavaInstanceJSC.cpp */; };
59A9E7B21104759400DFB4C1 /* JavaInstanceJSC.h in Headers */ = {isa = PBXBuildFile; fileRef = 59A9E7B11104759400DFB4C1 /* JavaInstanceJSC.h */; };
diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp
index dbf32e8..e1f692b 100644
--- a/WebCore/page/Geolocation.cpp
+++ b/WebCore/page/Geolocation.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
* Copyright (C) 2009 Torch Mobile, Inc.
+ * Copyright 2010, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,6 +32,7 @@
#include "Document.h"
#include "Frame.h"
#include "Page.h"
+#include <wtf/CurrentTime.h>
#if ENABLE(CLIENT_BASED_GEOLOCATION)
#include "Coordinates.h"
@@ -43,6 +45,7 @@
namespace WebCore {
static const char permissionDeniedErrorMessage[] = "User denied Geolocation";
+static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocation service";
#if ENABLE(CLIENT_BASED_GEOLOCATION)
@@ -79,6 +82,7 @@ Geolocation::GeoNotifier::GeoNotifier(Geolocation* geolocation, PassRefPtr<Posit
, m_errorCallback(errorCallback)
, m_options(options)
, m_timer(this, &Geolocation::GeoNotifier::timerFired)
+ , m_useCachedPosition(false)
{
ASSERT(m_geolocation);
ASSERT(m_successCallback);
@@ -95,11 +99,22 @@ void Geolocation::GeoNotifier::setFatalError(PassRefPtr<PositionError> error)
m_timer.startOneShot(0);
}
+void Geolocation::GeoNotifier::setUseCachedPosition()
+{
+ m_useCachedPosition = true;
+ m_timer.startOneShot(0);
+}
+
bool Geolocation::GeoNotifier::hasZeroTimeout() const
{
return m_options->hasTimeout() && m_options->timeout() == 0;
}
+void Geolocation::GeoNotifier::runSuccessCallback(Geoposition* position)
+{
+ m_successCallback->handleEvent(position);
+}
+
void Geolocation::GeoNotifier::startTimerIfNeeded()
{
if (m_options->hasTimeout())
@@ -122,6 +137,14 @@ void Geolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*)
return;
}
+ if (m_useCachedPosition) {
+ // Clear the cached position flag in case this is a watch request, which
+ // will continue to run.
+ m_useCachedPosition = false;
+ m_geolocation->requestUsesCachedPosition(this);
+ return;
+ }
+
if (m_errorCallback) {
RefPtr<PositionError> error = PositionError::create(PositionError::TIMEOUT, "Timeout expired");
m_errorCallback->handleEvent(error.get());
@@ -155,6 +178,11 @@ void Geolocation::Watchers::remove(GeoNotifier* notifier)
m_notifierToIdMap.remove(iter);
}
+bool Geolocation::Watchers::contains(GeoNotifier* notifier) const
+{
+ return m_notifierToIdMap.contains(notifier);
+}
+
void Geolocation::Watchers::clear()
{
m_idToNotifierMap.clear();
@@ -178,6 +206,7 @@ Geolocation::Geolocation(Frame* frame)
#endif
, m_allowGeolocation(Unknown)
, m_shouldClearCache(false)
+ , m_positionCache(new GeolocationPositionCache)
{
if (!m_frame)
return;
@@ -248,16 +277,16 @@ PassRefPtr<Geolocation::GeoNotifier> Geolocation::startRequest(PassRefPtr<Positi
// the permission state can not change again in the lifetime of this page.
if (isDenied())
notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage));
- else {
- if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) {
+ else if (haveSuitableCachedPosition(notifier->m_options.get()))
+ notifier->setUseCachedPosition();
+ else if (notifier->hasZeroTimeout() || startUpdating(notifier.get())) {
#if ENABLE(CLIENT_BASED_GEOLOCATION)
- // Only start timer if we're not waiting for user permission.
- if (!m_startRequestPermissionNotifier)
+ // Only start timer if we're not waiting for user permission.
+ if (!m_startRequestPermissionNotifier)
#endif
- notifier->startTimerIfNeeded();
- } else
- notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, "Failed to start Geolocation service"));
- }
+ notifier->startTimerIfNeeded();
+ } else
+ notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
return notifier.release();
}
@@ -272,6 +301,55 @@ void Geolocation::fatalErrorOccurred(Geolocation::GeoNotifier* notifier)
stopUpdating();
}
+void Geolocation::requestUsesCachedPosition(GeoNotifier* notifier)
+{
+ // This is called asynchronously, so the permissions could have been denied
+ // since we last checked in startRequest.
+ if (isDenied()) {
+ notifier->setFatalError(PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage));
+ return;
+ }
+
+ m_requestsAwaitingCachedPosition.add(notifier);
+
+ // If permissions are allowed, make the callback
+ if (isAllowed()) {
+ makeCachedPositionCallbacks();
+ return;
+ }
+
+ // Request permissions, which may be synchronous or asynchronous.
+ requestPermission();
+}
+
+void Geolocation::makeCachedPositionCallbacks()
+{
+ // All modifications to m_requestsAwaitingCachedPosition are done
+ // asynchronously, so we don't need to worry about it being modified from
+ // the callbacks.
+ GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end();
+ for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.begin(); iter != end; ++iter) {
+ GeoNotifier* notifier = iter->get();
+ notifier->runSuccessCallback(m_positionCache->cachedPosition());
+
+ // If this is a one-shot request, stop it. Otherwise, if the watch still
+ // exists, start the service to get updates.
+ if (m_oneShots.contains(notifier))
+ m_oneShots.remove(notifier);
+ else if (m_watchers.contains(notifier)) {
+ if (notifier->hasZeroTimeout() || startUpdating(notifier))
+ notifier->startTimerIfNeeded();
+ else
+ notifier->setFatalError(PositionError::create(PositionError::POSITION_UNAVAILABLE, failedToStartServiceErrorMessage));
+ }
+ }
+
+ m_requestsAwaitingCachedPosition.clear();
+
+ if (!hasListeners())
+ stopUpdating();
+}
+
void Geolocation::requestTimedOut(GeoNotifier* notifier)
{
// If this is a one-shot request, stop it.
@@ -281,6 +359,18 @@ void Geolocation::requestTimedOut(GeoNotifier* notifier)
stopUpdating();
}
+bool Geolocation::haveSuitableCachedPosition(PositionOptions* options)
+{
+ if (!m_positionCache->cachedPosition())
+ return false;
+ if (!options->hasMaximumAge())
+ return true;
+ if (!options->maximumAge())
+ return false;
+ DOMTimeStamp currentTimeMillis = currentTime() * 1000.0;
+ return m_positionCache->cachedPosition()->timestamp() > currentTimeMillis - options->maximumAge();
+}
+
void Geolocation::clearWatch(int watchId)
{
m_watchers.remove(watchId);
@@ -307,6 +397,8 @@ void Geolocation::resume()
void Geolocation::setIsAllowed(bool allowed)
{
+ // This may be due to either a new position from the service, or a cached
+ // position.
m_allowGeolocation = allowed ? Yes : No;
#if ENABLE(CLIENT_BASED_GEOLOCATION)
@@ -329,14 +421,22 @@ void Geolocation::setIsAllowed(bool allowed)
return;
}
#endif
-
- if (isAllowed())
- makeSuccessCallbacks();
- else {
+
+ if (!isAllowed()) {
RefPtr<PositionError> error = PositionError::create(PositionError::PERMISSION_DENIED, permissionDeniedErrorMessage);
error->setIsFatal(true);
handleError(error.get());
+ m_requestsAwaitingCachedPosition.clear();
+ return;
}
+
+ // If the service has a last position, use it to call back for all requests.
+ // If any of the requests are waiting for permission for a cached position,
+ // the position from the service will be at least as fresh.
+ if (lastPosition())
+ makeSuccessCallbacks();
+ else
+ makeCachedPositionCallbacks();
}
void Geolocation::sendError(Vector<RefPtr<GeoNotifier> >& notifiers, PositionError* error)
@@ -438,6 +538,8 @@ void Geolocation::positionChanged(PassRefPtr<Geoposition> newPosition)
{
m_currentPosition = newPosition;
+ m_positionCache->setCachedPosition(m_currentPosition.get());
+
// Stop all currently running timers.
stopTimers();
@@ -503,6 +605,9 @@ void Geolocation::geolocationServiceErrorOccurred(GeolocationService* service)
{
ASSERT(service->lastError());
+ // Note that we do not stop timers here. For one-shots, the request is
+ // cleared in handleError. For watchers, the spec requires that the timer is
+ // not cleared.
handleError(service->lastError());
}
diff --git a/WebCore/page/Geolocation.h b/WebCore/page/Geolocation.h
index c2e9131..c44b9e5 100644
--- a/WebCore/page/Geolocation.h
+++ b/WebCore/page/Geolocation.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
+ * Copyright 2010, The Android Open Source Project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,6 +27,7 @@
#ifndef Geolocation_h
#define Geolocation_h
+#include "GeolocationPositionCache.h"
#include "GeolocationService.h"
#include "Geoposition.h"
#include "PositionCallback.h"
@@ -95,6 +97,8 @@ private:
void setFatalError(PassRefPtr<PositionError>);
bool hasZeroTimeout() const;
+ void setUseCachedPosition();
+ void runSuccessCallback(Geoposition*);
void startTimerIfNeeded();
void timerFired(Timer<GeoNotifier>*);
@@ -104,6 +108,7 @@ private:
RefPtr<PositionOptions> m_options;
Timer<GeoNotifier> m_timer;
RefPtr<PositionError> m_fatalError;
+ bool m_useCachedPosition;
private:
GeoNotifier(Geolocation*, PassRefPtr<PositionCallback>, PassRefPtr<PositionErrorCallback>, PassRefPtr<PositionOptions>);
@@ -114,6 +119,7 @@ private:
void set(int id, PassRefPtr<GeoNotifier>);
void remove(int id);
void remove(GeoNotifier*);
+ bool contains(GeoNotifier*) const;
void clear();
bool isEmpty() const;
void getNotifiersVector(Vector<RefPtr<GeoNotifier> >&) const;
@@ -153,6 +159,9 @@ private:
void fatalErrorOccurred(GeoNotifier*);
void requestTimedOut(GeoNotifier*);
+ void requestUsesCachedPosition(GeoNotifier*);
+ bool haveSuitableCachedPosition(PositionOptions*);
+ void makeCachedPositionCallbacks();
typedef HashSet<RefPtr<GeoNotifier> > GeoNotifierSet;
@@ -174,6 +183,9 @@ private:
No
} m_allowGeolocation;
bool m_shouldClearCache;
+
+ OwnPtr<GeolocationPositionCache> m_positionCache;
+ GeoNotifierSet m_requestsAwaitingCachedPosition;
};
} // namespace WebCore
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list