Title: [136164] trunk
Revision
136164
Author
[email protected]
Date
2012-11-29 14:18:32 -0800 (Thu, 29 Nov 2012)

Log Message

Use GeolocationController's last geoposition as cached position.
https://bugs.webkit.org/show_bug.cgi?id=103540

Reviewed by Benjamin Poulain.

The page's GeolocationController mediates access to the
GeolocationClient for multiple frames' Geolocation instances. This
patch changes the position cache to be on the GeolocationController
rather than on the Geolocation instance.

This fixes a bug where if one frame has has received a fresh
position, then a request for a cached position from a second frame
does not succeed because the Geolocation instance in the second
frame's position cache hasn't received the position update that
went to the first frame.

Source/WebCore:

Test: fast/dom/Geolocation/cached-position-iframe.html

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::makeCachedPositionCallbacks):
(WebCore::Geolocation::haveSuitableCachedPosition):
(WebCore::Geolocation::positionChanged):
* Modules/geolocation/Geolocation.h:
* Modules/geolocation/GeolocationController.h:
(GeolocationController):

LayoutTests:

* fast/dom/Geolocation/cached-position-iframe-expected.txt: Added.
* fast/dom/Geolocation/cached-position-iframe.html: Added.
* fast/dom/Geolocation/resources/cached-position-iframe-inner.html: Added.
* fast/dom/Geolocation/script-tests/cached-position-iframe.js: Added.
(window.onmessage):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (136163 => 136164)


--- trunk/LayoutTests/ChangeLog	2012-11-29 22:16:19 UTC (rev 136163)
+++ trunk/LayoutTests/ChangeLog	2012-11-29 22:18:32 UTC (rev 136164)
@@ -1,3 +1,27 @@
+2012-11-29  John Knottenbelt  <[email protected]>
+
+        Use GeolocationController's last geoposition as cached position.
+        https://bugs.webkit.org/show_bug.cgi?id=103540
+
+        Reviewed by Benjamin Poulain.
+
+        The page's GeolocationController mediates access to the
+        GeolocationClient for multiple frames' Geolocation instances. This
+        patch changes the position cache to be on the GeolocationController
+        rather than on the Geolocation instance.
+
+        This fixes a bug where if one frame has has received a fresh
+        position, then a request for a cached position from a second frame
+        does not succeed because the Geolocation instance in the second
+        frame's position cache hasn't received the position update that
+        went to the first frame.
+
+        * fast/dom/Geolocation/cached-position-iframe-expected.txt: Added.
+        * fast/dom/Geolocation/cached-position-iframe.html: Added.
+        * fast/dom/Geolocation/resources/cached-position-iframe-inner.html: Added.
+        * fast/dom/Geolocation/script-tests/cached-position-iframe.js: Added.
+        (window.onmessage):
+
 2012-11-29  Zhenyao Mo  <[email protected]>
 
         Unreviewed, WebKit gardening.

Added: trunk/LayoutTests/fast/dom/Geolocation/cached-position-iframe-expected.txt (0 => 136164)


--- trunk/LayoutTests/fast/dom/Geolocation/cached-position-iframe-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/cached-position-iframe-expected.txt	2012-11-29 22:18:32 UTC (rev 136164)
@@ -0,0 +1,11 @@
+Tests that a cached position can be obtained in one frame after another frame has received a fresh position.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Received cached position lat: 51.478, long: -0.166
+PASS success is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Geolocation/cached-position-iframe.html (0 => 136164)


--- trunk/LayoutTests/fast/dom/Geolocation/cached-position-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/cached-position-iframe.html	2012-11-29 22:18:32 UTC (rev 136164)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/Geolocation/resources/cached-position-iframe-inner.html (0 => 136164)


--- trunk/LayoutTests/fast/dom/Geolocation/resources/cached-position-iframe-inner.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/resources/cached-position-iframe-inner.html	2012-11-29 22:18:32 UTC (rev 136164)
@@ -0,0 +1,26 @@
+<html>
+<body>
+  <script>
+    function successCallback(position) {
+        var message = {
+            'success': true,
+            'message': 'Received cached position lat: ' + position.coords.latitude + ', long: ' + position.coords.longitude
+        };
+        parent.postMessage(message, '*');
+    }
+
+    function errorCallback(error) {
+        var message = {
+            'success': false,
+            'message': 'Failed to get position.'
+        }
+        parent.postMessage(message, '*');
+    }
+
+    navigator.geolocation.getCurrentPosition(
+        successCallback,
+        errorCallback,
+        { maximumAge:600000, timeout:0 });
+  </script>
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/Geolocation/script-tests/cached-position-iframe.js (0 => 136164)


--- trunk/LayoutTests/fast/dom/Geolocation/script-tests/cached-position-iframe.js	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Geolocation/script-tests/cached-position-iframe.js	2012-11-29 22:18:32 UTC (rev 136164)
@@ -0,0 +1,24 @@
+description('Tests that a cached position can be obtained in one frame after another frame has received a fresh position.');
+
+if (window.testRunner) {
+    testRunner.setMockGeolocationPosition(51.478, -0.166, 100);
+    testRunner.setGeolocationPermission(true);
+}
+
+window._onmessage_ = function (messageEvent) {
+    debug(messageEvent.data.message);
+    success = messageEvent.data.success;
+    shouldBeTrue('success');
+    finishJSTest();
+}
+
+navigator.geolocation.getCurrentPosition(
+    function() {
+        // Kick off the iframe to request a cached position. The iframe
+        // will post a message back on success / failure.
+        iframe = document.createElement('iframe');
+        iframe.src = '';
+        document.body.appendChild(iframe);
+    });
+
+window.jsTestIsAsync = true;

Modified: trunk/Source/WebCore/ChangeLog (136163 => 136164)


--- trunk/Source/WebCore/ChangeLog	2012-11-29 22:16:19 UTC (rev 136163)
+++ trunk/Source/WebCore/ChangeLog	2012-11-29 22:18:32 UTC (rev 136164)
@@ -1,3 +1,31 @@
+2012-11-29  John Knottenbelt  <[email protected]>
+
+        Use GeolocationController's last geoposition as cached position.
+        https://bugs.webkit.org/show_bug.cgi?id=103540
+
+        Reviewed by Benjamin Poulain.
+
+        The page's GeolocationController mediates access to the
+        GeolocationClient for multiple frames' Geolocation instances. This
+        patch changes the position cache to be on the GeolocationController
+        rather than on the Geolocation instance.
+
+        This fixes a bug where if one frame has has received a fresh
+        position, then a request for a cached position from a second frame
+        does not succeed because the Geolocation instance in the second
+        frame's position cache hasn't received the position update that
+        went to the first frame.
+
+        Test: fast/dom/Geolocation/cached-position-iframe.html
+
+        * Modules/geolocation/Geolocation.cpp:
+        (WebCore::Geolocation::makeCachedPositionCallbacks):
+        (WebCore::Geolocation::haveSuitableCachedPosition):
+        (WebCore::Geolocation::positionChanged):
+        * Modules/geolocation/Geolocation.h:
+        * Modules/geolocation/GeolocationController.h:
+        (GeolocationController):
+
 2012-11-29  Alexei Filippov  <[email protected]>
 
         Web Inspector: Allow sorting in NMI snapshot grid view

Modified: trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp (136163 => 136164)


--- trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp	2012-11-29 22:16:19 UTC (rev 136163)
+++ trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp	2012-11-29 22:18:32 UTC (rev 136164)
@@ -373,7 +373,7 @@
     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_cachedPosition.get());
+        notifier->runSuccessCallback(lastPosition());
 
         // If this is a one-shot request, stop it. Otherwise, if the watch still
         // exists, start the service to get updates.
@@ -404,14 +404,15 @@
 
 bool Geolocation::haveSuitableCachedPosition(PositionOptions* options)
 {
-    if (!m_cachedPosition)
+    Geoposition* cachedPosition = lastPosition();
+    if (!cachedPosition)
         return false;
     if (!options->hasMaximumAge())
         return true;
     if (!options->maximumAge())
         return false;
     DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime());
-    return m_cachedPosition->timestamp() > currentTimeMillis - options->maximumAge();
+    return cachedPosition->timestamp() > currentTimeMillis - options->maximumAge();
 }
 
 void Geolocation::clearWatch(int watchID)
@@ -624,8 +625,6 @@
 {
     ASSERT(isAllowed());
 
-    m_cachedPosition = lastPosition();
-
     // Stop all currently running timers.
     stopTimers();
 

Modified: trunk/Source/WebCore/Modules/geolocation/Geolocation.h (136163 => 136164)


--- trunk/Source/WebCore/Modules/geolocation/Geolocation.h	2012-11-29 22:16:19 UTC (rev 136163)
+++ trunk/Source/WebCore/Modules/geolocation/Geolocation.h	2012-11-29 22:18:32 UTC (rev 136164)
@@ -173,7 +173,6 @@
         No
     } m_allowGeolocation;
 
-    RefPtr<Geoposition> m_cachedPosition;
     GeoNotifierSet m_requestsAwaitingCachedPosition;
 };
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to