[GTK][WPE] Add API to provide geolocation information
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 10:10:35 +0000 (10:10 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Mar 2019 10:10:35 +0000 (10:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195940

Reviewed by Michael Catanzaro.

.:

Build with geolocation enabled by default in both GTK and WPE. In GTK add a specific USE_GEOCLUE build option
instead of using ENABLE_GEOLOCATION.

* Source/cmake/OptionsGTK.cmake:
* Source/cmake/OptionsWPE.cmake:

Source/WebCore:

Replace ENABLE(GEOLOCATION) with USE(GEOCLUE).

* PlatformGTK.cmake:
* platform/geoclue/GeolocationProviderGeoclue.cpp:
* platform/geoclue/GeolocationProviderGeoclue.h:
* platform/geoclue/GeolocationProviderGeoclueClient.h:

Source/WebCore/platform/gtk/po:

* POTFILES.in: Add WebKitGeolocationManager.cpp.

Source/WebKit:

Add WebKitGeolocationManager public class to handle geolocation position updates. WebKitGeolocationProvider has
been removed and the default implementation based on GeoClue is done by WebKitGeolocationManager.

* PlatformGTK.cmake:
* PlatformWPE.cmake:
* SourcesGTK.txt:
* SourcesWPE.txt:
* UIProcess/API/glib/WebKitGeolocationManager.cpp: Added.
(_WebKitGeolocationPosition::_WebKitGeolocationPosition):
(webkit_geolocation_position_new):
(webkit_geolocation_position_copy):
(webkit_geolocation_position_free):
(webkit_geolocation_position_set_timestamp):
(webkit_geolocation_position_set_altitude):
(webkit_geolocation_position_set_altitude_accuracy):
(webkit_geolocation_position_set_heading):
(webkit_geolocation_position_set_speed):
(webkitGeolocationManagerStop):
(webkitGeolocationManagerSetEnableHighAccuracy):
(webkitGeolocationManagerCreate):
(webkitGeolocationManagerGetProperty):
(webkit_geolocation_manager_class_init):
(webkit_gelocation_manager_update_position):
(webkit_gelocation_manager_failed):
(webkit_geolocation_manager_get_enable_high_accuracy):
* UIProcess/API/glib/WebKitGeolocationManagerPrivate.h: Copied from Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h.
* UIProcess/API/glib/WebKitGeolocationProvider.cpp: Removed.
* UIProcess/API/glib/WebKitGeolocationProvider.h: Removed.
* UIProcess/API/glib/WebKitWebContext.cpp:
(webkitWebContextConstructed): Create a WebKitGeolocationManager instead of a WebKitGeolocationProvider.
(webkit_web_context_get_geolocation_manager): Get the WebKitGeolocationManager.
* UIProcess/API/gtk/WebKitGeolocationManager.h: Added.
* UIProcess/API/gtk/WebKitWebContext.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/gtk/docs/webkit2gtk-4.0.types:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
* UIProcess/API/gtk/webkit2.h:
* UIProcess/API/wpe/WebKitGeolocationManager.h: Added.
* UIProcess/API/wpe/WebKitWebContext.h:
* UIProcess/API/wpe/docs/wpe-0.1-sections.txt:
* UIProcess/API/wpe/docs/wpe-docs.sgml:
* UIProcess/API/wpe/webkit.h:

Tools:

Add a new test to check the new API.

* TestWebKitAPI/Tests/WebKitGLib/TestGeolocationManager.cpp: Added.
(testGeolocationManagerCurrentPosition):
(testGeolocationManagerWatchPosition):
(beforeAll):
(afterAll):
* TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
(testWebViewGeolocationPermissionRequests): Stop using ENABLE(GEOLOCATION) conditionals for geolocation tests.
(beforeAll): Ditto.
* TestWebKitAPI/glib/CMakeLists.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243285 268f45cc-cd09-0410-ab3c-d52691b4dbfc

35 files changed:
ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.h
Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h
Source/WebCore/platform/gtk/po/ChangeLog
Source/WebCore/platform/gtk/po/POTFILES.in
Source/WebKit/ChangeLog
Source/WebKit/PlatformGTK.cmake
Source/WebKit/PlatformWPE.cmake
Source/WebKit/SourcesGTK.txt
Source/WebKit/SourcesWPE.txt
Source/WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/API/glib/WebKitGeolocationManagerPrivate.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/glib/WebKitGeolocationProvider.cpp [deleted file]
Source/WebKit/UIProcess/API/glib/WebKitGeolocationProvider.h [deleted file]
Source/WebKit/UIProcess/API/glib/WebKitWebContext.cpp
Source/WebKit/UIProcess/API/gtk/WebKitGeolocationManager.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/gtk/WebKitWebContext.h
Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0.types
Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
Source/WebKit/UIProcess/API/gtk/webkit2.h
Source/WebKit/UIProcess/API/wpe/WebKitGeolocationManager.h [new file with mode: 0644]
Source/WebKit/UIProcess/API/wpe/WebKitWebContext.h
Source/WebKit/UIProcess/API/wpe/docs/wpe-1.0-sections.txt
Source/WebKit/UIProcess/API/wpe/docs/wpe-docs.sgml
Source/WebKit/UIProcess/API/wpe/webkit.h
Source/cmake/OptionsGTK.cmake
Source/cmake/OptionsWPE.cmake
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitGLib/TestGeolocationManager.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp
Tools/TestWebKitAPI/glib/CMakeLists.txt

index 8a83364..def4eaf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WPE] Add API to provide geolocation information
+        https://bugs.webkit.org/show_bug.cgi?id=195940
+
+        Reviewed by Michael Catanzaro.
+
+        Build with geolocation enabled by default in both GTK and WPE. In GTK add a specific USE_GEOCLUE build option
+        instead of using ENABLE_GEOLOCATION.
+
+        * Source/cmake/OptionsGTK.cmake:
+        * Source/cmake/OptionsWPE.cmake:
+
 2019-03-20  Simon Fraser  <simon.fraser@apple.com>
 
         Rename ENABLE_ACCELERATED_OVERFLOW_SCROLLING macro to ENABLE_OVERFLOW_SCROLLING_TOUCH
index 08f808a..23988a5 100644 (file)
@@ -1,5 +1,19 @@
 2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK][WPE] Add API to provide geolocation information
+        https://bugs.webkit.org/show_bug.cgi?id=195940
+
+        Reviewed by Michael Catanzaro.
+
+        Replace ENABLE(GEOLOCATION) with USE(GEOCLUE).
+
+        * PlatformGTK.cmake:
+        * platform/geoclue/GeolocationProviderGeoclue.cpp:
+        * platform/geoclue/GeolocationProviderGeoclue.h:
+        * platform/geoclue/GeolocationProviderGeoclueClient.h:
+
+2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [WPE] Confusing messages in stderr when surfaceless context is not supported
         https://bugs.webkit.org/show_bug.cgi?id=195742
 
index e0dd9cd..ba49231 100644 (file)
@@ -75,7 +75,7 @@ list(APPEND WebCorePlatformGTK_SOURCES
     rendering/RenderThemeGtk.cpp
 )
 
-if (ENABLE_GEOLOCATION)
+if (USE_GEOCLUE)
     list(APPEND WebCore_SOURCES
         ${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface.c
     )
index 9839773..2deaf76 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "GeolocationProviderGeoclue.h"
 
-#if ENABLE(GEOLOCATION)
+#if USE(GEOCLUE)
 
 #include <wtf/glib/GLibUtilities.h>
 #include <wtf/glib/GUniquePtr.h>
@@ -212,4 +212,4 @@ void GeolocationProviderGeoclue::updateClientRequirements()
 
 } // namespace WebCore
 
-#endif // ENABLE(GEOLOCATION)
+#endif // USE(GEOCLUE)
index 4a4db7a..224b791 100644 (file)
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef GeolocationProviderGeoclue_h
-#define GeolocationProviderGeoclue_h
+#pragma once
 
-#if ENABLE(GEOLOCATION)
+#if USE(GEOCLUE)
 
 #include "GeolocationProviderGeoclueClient.h"
 #include <wtf/glib/GRefPtr.h>
@@ -71,6 +70,4 @@ private:
 
 } // namespace WebCore
 
-#endif // ENABLE(GEOLOCATION)
-
-#endif // GeolocationProviderGeoclue_h
+#endif // USE(GEOCLUE)
index ea69e25..68de276 100644 (file)
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef GeolocationProviderGeoclueClient_h
-#define GeolocationProviderGeoclueClient_h
+#pragma once
 
-#if ENABLE(GEOLOCATION)
+#if USE(GEOCLUE)
 
 namespace WebCore {
 
@@ -32,6 +31,4 @@ public:
 
 } // namespace WebCore
 
-#endif // ENABLE(GEOLOCATION)
-
-#endif // GeolocationProviderGeoclueClient_h
+#endif // USE(GEOCLUE)
index faaa849..794bf17 100644 (file)
@@ -1,3 +1,12 @@
+2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WPE] Add API to provide geolocation information
+        https://bugs.webkit.org/show_bug.cgi?id=195940
+
+        Reviewed by Michael Catanzaro.
+
+        * POTFILES.in: Add WebKitGeolocationManager.cpp.
+
 2019-03-13  Milo Casagrande <milo@milo.name>
 
         [l10n] Updated Italian translation of WebKitGTK+
index 1fc1448..f493200 100644 (file)
@@ -16,6 +16,7 @@ LocalizedStringsGtk.cpp
 ../../../WebKit/UIProcess/API/glib/WebKitFaviconDatabase.cpp
 ../../../WebKit/UIProcess/API/glib/WebKitFileChooserRequest.cpp
 ../../../WebKit/UIProcess/API/glib/WebKitFindController.cpp
+../../../WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp
 ../../../WebKit/UIProcess/API/glib/WebKitNavigationPolicyDecision.cpp
 ../../../WebKit/UIProcess/API/glib/WebKitNotification.cpp
 ../../../WebKit/UIProcess/API/glib/WebKitResponsePolicyDecision.cpp
index 4613bc9..279c034 100644 (file)
@@ -1,3 +1,53 @@
+2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK][WPE] Add API to provide geolocation information
+        https://bugs.webkit.org/show_bug.cgi?id=195940
+
+        Reviewed by Michael Catanzaro.
+
+        Add WebKitGeolocationManager public class to handle geolocation position updates. WebKitGeolocationProvider has
+        been removed and the default implementation based on GeoClue is done by WebKitGeolocationManager.
+
+        * PlatformGTK.cmake:
+        * PlatformWPE.cmake:
+        * SourcesGTK.txt:
+        * SourcesWPE.txt:
+        * UIProcess/API/glib/WebKitGeolocationManager.cpp: Added.
+        (_WebKitGeolocationPosition::_WebKitGeolocationPosition):
+        (webkit_geolocation_position_new):
+        (webkit_geolocation_position_copy):
+        (webkit_geolocation_position_free):
+        (webkit_geolocation_position_set_timestamp):
+        (webkit_geolocation_position_set_altitude):
+        (webkit_geolocation_position_set_altitude_accuracy):
+        (webkit_geolocation_position_set_heading):
+        (webkit_geolocation_position_set_speed):
+        (webkitGeolocationManagerStop):
+        (webkitGeolocationManagerSetEnableHighAccuracy):
+        (webkitGeolocationManagerCreate):
+        (webkitGeolocationManagerGetProperty):
+        (webkit_geolocation_manager_class_init):
+        (webkit_gelocation_manager_update_position):
+        (webkit_gelocation_manager_failed):
+        (webkit_geolocation_manager_get_enable_high_accuracy):
+        * UIProcess/API/glib/WebKitGeolocationManagerPrivate.h: Copied from Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h.
+        * UIProcess/API/glib/WebKitGeolocationProvider.cpp: Removed.
+        * UIProcess/API/glib/WebKitGeolocationProvider.h: Removed.
+        * UIProcess/API/glib/WebKitWebContext.cpp:
+        (webkitWebContextConstructed): Create a WebKitGeolocationManager instead of a WebKitGeolocationProvider.
+        (webkit_web_context_get_geolocation_manager): Get the WebKitGeolocationManager.
+        * UIProcess/API/gtk/WebKitGeolocationManager.h: Added.
+        * UIProcess/API/gtk/WebKitWebContext.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0.types:
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
+        * UIProcess/API/gtk/webkit2.h:
+        * UIProcess/API/wpe/WebKitGeolocationManager.h: Added.
+        * UIProcess/API/wpe/WebKitWebContext.h:
+        * UIProcess/API/wpe/docs/wpe-0.1-sections.txt:
+        * UIProcess/API/wpe/docs/wpe-docs.sgml:
+        * UIProcess/API/wpe/webkit.h:
+
 2019-03-20  Youenn Fablet  <youenn@apple.com>
 
         Compute quota after network process restart based on default quota and space used
index 993ab58..76eb5e9 100644 (file)
@@ -82,6 +82,7 @@ set(WebKit2GTK_INSTALLED_HEADERS
     ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitFindController.h
     ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitFormSubmissionRequest.h
     ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitForwardDeclarations.h
+    ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitGeolocationManager.h
     ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h
     ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitHitTestResult.h
     ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitInstallMissingMediaPluginsPermissionRequest.h
index cbdf487..373ae0b 100644 (file)
@@ -113,6 +113,7 @@ set(WPE_API_INSTALLED_HEADERS
     ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitFileChooserRequest.h
     ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitFindController.h
     ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitFormSubmissionRequest.h
+    ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitGeolocationManager.h
     ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitGeolocationPermissionRequest.h
     ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitHitTestResult.h
     ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitInstallMissingMediaPluginsPermissionRequest.h
index cc05987..53522d0 100644 (file)
@@ -146,8 +146,8 @@ UIProcess/API/glib/WebKitFileChooserRequest.cpp @no-unify
 UIProcess/API/glib/WebKitFindController.cpp @no-unify
 UIProcess/API/glib/WebKitFormClient.cpp @no-unify
 UIProcess/API/glib/WebKitFormSubmissionRequest.cpp @no-unify
+UIProcess/API/glib/WebKitGeolocationManager.cpp @no-unify
 UIProcess/API/glib/WebKitGeolocationPermissionRequest.cpp @no-unify
-UIProcess/API/glib/WebKitGeolocationProvider.cpp @no-unify
 UIProcess/API/glib/WebKitIconLoadingClient.cpp @no-unify
 UIProcess/API/glib/WebKitInjectedBundleClient.cpp @no-unify
 UIProcess/API/glib/WebKitInstallMissingMediaPluginsPermissionRequest.cpp @no-unify
index ca6a150..5fc1ca5 100644 (file)
@@ -131,8 +131,8 @@ UIProcess/API/glib/WebKitFileChooserRequest.cpp @no-unify
 UIProcess/API/glib/WebKitFindController.cpp @no-unify
 UIProcess/API/glib/WebKitFormClient.cpp @no-unify
 UIProcess/API/glib/WebKitFormSubmissionRequest.cpp @no-unify
+UIProcess/API/glib/WebKitGeolocationManager.cpp @no-unify
 UIProcess/API/glib/WebKitGeolocationPermissionRequest.cpp @no-unify
-UIProcess/API/glib/WebKitGeolocationProvider.cpp @no-unify
 UIProcess/API/glib/WebKitInjectedBundleClient.cpp @no-unify
 UIProcess/API/glib/WebKitInstallMissingMediaPluginsPermissionRequest.cpp @no-unify
 UIProcess/API/glib/WebKitJavascriptResult.cpp @no-unify
diff --git a/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp b/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp
new file mode 100644 (file)
index 0000000..e791b3e
--- /dev/null
@@ -0,0 +1,478 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitGeolocationManager.h"
+
+#include "APIGeolocationProvider.h"
+#include "WebGeolocationPosition.h"
+#include "WebKitGeolocationManagerPrivate.h"
+#include <glib/gi18n-lib.h>
+#include <wtf/WallTime.h>
+#include <wtf/glib/WTFGType.h>
+
+#if USE(GEOCLUE)
+#include <WebCore/GeolocationProviderGeoclue.h>
+#include <WebCore/GeolocationProviderGeoclueClient.h>
+#endif
+
+using namespace WebKit;
+using namespace WebCore;
+
+/**
+ * SECTION:WebKitGeolocationManager
+ * @short_description: WebKitGeolocationManager
+ * @title: Geolocation manager
+ * @see_also: #WebKitGeolocationPermissionRequest, #WebKitWebContext
+ *
+ * WebKitGeolocationManager provides API to get the geographical position of the user.
+ * Once a #WebKitGeolocationPermissionRequest is allowed, when WebKit needs to know the
+ * user location #WebKitGeolocationManager::start signal is emitted. If the signal is handled
+ * and returns %TRUE, the application is responsible for providing the position every time it's
+ * updated by calling webkit_gelocation_manager_update_position(). The signal #WebKitGeolocationManager::stop
+ * will be emitted when location updates are no longer needed.
+ *
+ * Since: 2.26
+ */
+
+enum {
+    PROP_0,
+
+    PROP_ENABLE_HIGH_ACCURACY
+};
+
+enum {
+    START,
+    STOP,
+    LAST_SIGNAL
+};
+
+struct _WebKitGeolocationPosition {
+    _WebKitGeolocationPosition() = default;
+
+    _WebKitGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> timestamp = WTF::nullopt)
+    {
+        position.timestamp = timestamp.valueOr(WallTime::now().secondsSinceEpoch().value());
+        position.latitude = latitude;
+        position.longitude = longitude;
+        position.accuracy = accuracy;
+    }
+
+    explicit _WebKitGeolocationPosition(const GeolocationPosition& other)
+    {
+        position = other;
+    }
+
+    GeolocationPosition position;
+};
+
+/**
+ * WebKitGeolocationPosition:
+ *
+ * WebKitGeolocationPosition is an opaque struct used to provide position updates to a
+ * #WebKitGeolocationManager using webkit_gelocation_manager_update_position().
+ *
+ * Since: 2.26
+ */
+
+G_DEFINE_BOXED_TYPE(WebKitGeolocationPosition, webkit_geolocation_position, webkit_geolocation_position_copy, webkit_geolocation_position_free)
+
+/**
+ * webkit_geolocation_position_new:
+ * @latitude: a valid latitude in degrees
+ * @longitude: a valid longitude in degrees
+ * @accuracy: accuracy of location in meters
+ *
+ * Create a new #WebKitGeolocationPosition
+ *
+ * Returns: (transfer full): a newly created #WebKitGeolocationPosition
+ *
+ * Since: 2.26
+ */
+WebKitGeolocationPosition* webkit_geolocation_position_new(double latitude, double longitude, double accuracy)
+{
+    auto* position = static_cast<WebKitGeolocationPosition*>(fastMalloc(sizeof(WebKitGeolocationPosition)));
+    new (position) WebKitGeolocationPosition(latitude, longitude, accuracy);
+    return position;
+}
+
+/**
+ * webkit_geolocation_position_copy:
+ * @position: a #WebKitGeolocationPosition
+ *
+ * Make a copy of the #WebKitGeolocationPosition
+ *
+ * Returns: (transfer full): a copy of @position
+ *
+ * Since: 2.26
+ */
+WebKitGeolocationPosition* webkit_geolocation_position_copy(WebKitGeolocationPosition* position)
+{
+    g_return_val_if_fail(position, nullptr);
+
+    auto* copy = static_cast<WebKitGeolocationPosition*>(fastMalloc(sizeof(WebKitGeolocationPosition)));
+    new (copy) WebKitGeolocationPosition(position->position);
+    return copy;
+}
+
+/**
+ * webkit_geolocation_position_free:
+ * @position: a #WebKitGeolocationPosition
+ *
+ * Free the #WebKitGeolocationPosition
+ *
+ * Since: 2.26
+ */
+void webkit_geolocation_position_free(WebKitGeolocationPosition* position)
+{
+    g_return_if_fail(position);
+
+    position->~WebKitGeolocationPosition();
+    fastFree(position);
+}
+
+/**
+ * webkit_geolocation_position_set_timestamp:
+ * @position: a #WebKitGeolocationPosition
+ * @timestamp: timestamp in seconds since the epoch, or 0 to use current time
+ *
+ * Set the @position timestamp. By default it's the time when the @position was created.
+ *
+ * Since: 2.26
+ */
+void webkit_geolocation_position_set_timestamp(WebKitGeolocationPosition* position, guint64 timestamp)
+{
+    g_return_if_fail(position);
+
+    position->position.timestamp = timestamp ? static_cast<double>(timestamp) : WallTime::now().secondsSinceEpoch().value();
+}
+
+/**
+ * webkit_geolocation_position_set_altitude:
+ * @position: a #WebKitGeolocationPosition
+ * @altitude: altitude in meters
+ *
+ * Set the @position altitude
+ *
+ * Since: 2.26
+ */
+void webkit_geolocation_position_set_altitude(WebKitGeolocationPosition* position, double altitude)
+{
+    g_return_if_fail(position);
+
+    position->position.altitude = altitude;
+}
+
+/**
+ * webkit_geolocation_position_set_altitude_accuracy:
+ * @position: a #WebKitGeolocationPosition
+ * @altitude_accuracy: accuracy of position altitude in meters
+ *
+ * Set the accuracy of @position altitude
+ *
+ * Since: 2.26
+ */
+void webkit_geolocation_position_set_altitude_accuracy(WebKitGeolocationPosition* position, double altitudeAccuracy)
+{
+    g_return_if_fail(position);
+
+    position->position.altitudeAccuracy = altitudeAccuracy;
+}
+
+/**
+ * webkit_geolocation_position_set_heading:
+ * @position: a #WebKitGeolocationPosition
+ * @heading: heading in degrees
+ *
+ * Set the @position heading, as a positive angle between the direction of movement and the North
+ * direction, in clockwise direction.
+ *
+ * Since: 2.26
+ */
+void webkit_geolocation_position_set_heading(WebKitGeolocationPosition* position, double heading)
+{
+    g_return_if_fail(position);
+
+    position->position.heading = heading;
+}
+
+/**
+ * webkit_geolocation_position_set_speed:
+ * @position: a #WebKitGeolocationPosition
+ * @speed: speed in meters per second
+ *
+ * Set the @position speed
+ *
+ * Since: 2.26
+ */
+void webkit_geolocation_position_set_speed(WebKitGeolocationPosition* position, double speed)
+{
+    g_return_if_fail(position);
+
+    position->position.speed = speed;
+}
+
+#if USE(GEOCLUE)
+class GeoclueProviderClient final : public GeolocationProviderGeoclueClient {
+public:
+    explicit GeoclueProviderClient(WebKitGeolocationManager* manager)
+        : m_manager(manager)
+    {
+    }
+
+private:
+    void notifyPositionChanged(int timestamp, double latitude, double longitude, double altitude, double accuracy, double) override
+    {
+        WebKitGeolocationPosition position(latitude, longitude, accuracy, static_cast<double>(timestamp));
+        webkit_geolocation_position_set_altitude(&position, altitude);
+        webkit_gelocation_manager_update_position(m_manager, &position);
+    }
+
+    void notifyErrorOccurred(const char* message) override
+    {
+        webkit_gelocation_manager_failed(m_manager, message);
+    }
+
+    WebKitGeolocationManager* m_manager;
+};
+#endif
+
+struct _WebKitGeolocationManagerPrivate {
+    RefPtr<WebGeolocationManagerProxy> manager;
+    bool highAccuracyEnabled;
+#if USE(GEOCLUE)
+    std::unique_ptr<GeoclueProviderClient> providerClient;
+    std::unique_ptr<GeolocationProviderGeoclue> provider;
+#endif
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+WEBKIT_DEFINE_TYPE(WebKitGeolocationManager, webkit_geolocation_manager, G_TYPE_OBJECT)
+
+static void webkitGeolocationManagerStart(WebKitGeolocationManager* manager)
+{
+    gboolean returnValue;
+    g_signal_emit(manager, signals[START], 0, &returnValue);
+    if (returnValue) {
+#if USE(GEOCLUE)
+        manager->priv->provider = nullptr;
+        manager->priv->providerClient = nullptr;
+#endif
+        return;
+    }
+
+#if USE(GEOCLUE)
+    if (!manager->priv->provider) {
+        manager->priv->providerClient = std::make_unique<GeoclueProviderClient>(manager);
+        manager->priv->provider = std::make_unique<GeolocationProviderGeoclue>(manager->priv->providerClient.get());
+    }
+    manager->priv->provider->startUpdating();
+#endif
+}
+
+static void webkitGeolocationManagerStop(WebKitGeolocationManager* manager)
+{
+    g_signal_emit(manager, signals[STOP], 0, nullptr);
+
+#if USE(GEOCLUE)
+    if (manager->priv->provider)
+        manager->priv->provider->stopUpdating();
+#endif
+}
+
+static void webkitGeolocationManagerSetEnableHighAccuracy(WebKitGeolocationManager* manager, bool enabled)
+{
+    if (manager->priv->highAccuracyEnabled == enabled)
+        return;
+
+    manager->priv->highAccuracyEnabled = enabled;
+    g_object_notify(G_OBJECT(manager), "enable-high-accuracy");
+#if USE(GEOCLUE)
+    if (manager->priv->provider)
+        manager->priv->provider->setEnableHighAccuracy(enabled);
+#endif
+}
+
+class GeolocationProvider final : public API::GeolocationProvider {
+public:
+    explicit GeolocationProvider(WebKitGeolocationManager* manager)
+        : m_manager(manager)
+    {
+    }
+
+private:
+    void startUpdating(WebGeolocationManagerProxy&) override
+    {
+        webkitGeolocationManagerStart(m_manager);
+    }
+
+    void stopUpdating(WebGeolocationManagerProxy&) override
+    {
+        webkitGeolocationManagerStop(m_manager);
+    }
+
+    void setEnableHighAccuracy(WebGeolocationManagerProxy&, bool enabled) override
+    {
+        webkitGeolocationManagerSetEnableHighAccuracy(m_manager, enabled);
+    }
+
+    WebKitGeolocationManager* m_manager;
+};
+
+WebKitGeolocationManager* webkitGeolocationManagerCreate(WebGeolocationManagerProxy* proxy)
+{
+    auto* manager = WEBKIT_GEOLOCATION_MANAGER(g_object_new(WEBKIT_TYPE_GEOLOCATION_MANAGER, nullptr));
+    manager->priv->manager = proxy;
+    proxy->setProvider(std::make_unique<GeolocationProvider>(manager));
+    return manager;
+}
+
+static void webkitGeolocationManagerGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
+{
+    WebKitGeolocationManager* manager = WEBKIT_GEOLOCATION_MANAGER(object);
+
+    switch (propId) {
+    case PROP_ENABLE_HIGH_ACCURACY:
+        g_value_set_boolean(value, webkit_geolocation_manager_get_enable_high_accuracy(manager));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+    }
+}
+
+static void webkit_geolocation_manager_class_init(WebKitGeolocationManagerClass* geolocationManagerClass)
+{
+    GObjectClass* gObjectClass = G_OBJECT_CLASS(geolocationManagerClass);
+    gObjectClass->get_property = webkitGeolocationManagerGetProperty;
+
+    /**
+     * WebKitGeolocationManager:enable-high-accuracy:
+     *
+     * Whether high accuracy is enabled. This is a read-only property that will be
+     * set to %TRUE when a #WebKitGeolocationManager needs to get accurate position updates.
+     * You can connect to notify::enable-high-accuracy signal to monitor it.
+     *
+     * Since: 2.26
+     */
+    g_object_class_install_property(
+        gObjectClass,
+        PROP_ENABLE_HIGH_ACCURACY,
+        g_param_spec_boolean(
+            "enable-high-accuracy",
+            _("Enable high accuracy"),
+            _("Whether high accuracy is enabled"),
+            FALSE,
+            WEBKIT_PARAM_READABLE));
+
+    /**
+     * WebKitGeolocationManager::start:
+     * @manager: the #WebKitGeolocationManager on which the signal is emitted
+     *
+     * The signal is emitted to notify that @manager needs to start receiving
+     * position updates. After this signal is emitted the user should provide
+     * the updates using webkit_gelocation_manager_update_position() every time
+     * the position changes, or use webkit_gelocation_manager_failed() in case
+     * it isn't possible to determine the current position.
+     *
+     * If the signal is not handled, WebKit will try to determine the position
+     * using GeoClue if available.
+     *
+     * Returns: %TRUE to stop other handlers from being invoked for the event.
+     *    %FALSE to propagate the event further.
+     *
+     * Since: 2.26
+     */
+    signals[START] = g_signal_new(
+        "start",
+        G_TYPE_FROM_CLASS(geolocationManagerClass),
+        G_SIGNAL_RUN_LAST,
+        0,
+        g_signal_accumulator_true_handled, nullptr,
+        g_cclosure_marshal_generic,
+        G_TYPE_BOOLEAN, 0);
+
+    /**
+     * WebKitGeolocationManager::stop:
+     * @manager: the #WebKitGeolocationManager on which the signal is emitted
+     *
+     * The signal is emitted to notify that @manager doesn't need to receive
+     * position updates anymore.
+     *
+     * Since: 2.26
+     */
+    signals[STOP] = g_signal_new(
+        "stop",
+        G_TYPE_FROM_CLASS(geolocationManagerClass),
+        G_SIGNAL_RUN_LAST,
+        0,
+        nullptr, nullptr,
+        g_cclosure_marshal_generic,
+        G_TYPE_NONE, 0);
+}
+
+/**
+ * webkit_gelocation_manager_update_position:
+ * @manager: a #WebKitGeolocationManager
+ * @position: a #WebKitGeolocationPosition
+ *
+ * Notify @manager that position has been updated to @position.
+ *
+ * Since: 2.26
+ */
+void webkit_gelocation_manager_update_position(WebKitGeolocationManager* manager, WebKitGeolocationPosition* position)
+{
+    g_return_if_fail(WEBKIT_IS_GEOLOCATION_MANAGER(manager));
+    g_return_if_fail(position);
+
+    GeolocationPosition corePosition = position->position;
+    auto wkPosition = WebGeolocationPosition::create(WTFMove(corePosition));
+    manager->priv->manager->providerDidChangePosition(wkPosition.ptr());
+}
+
+/**
+ * webkit_gelocation_manager_failed:
+ * @manager: a #WebKitGeolocationManager
+ * @error_message: the error message
+ *
+ * Notify @manager that determining the position failed.
+ *
+ * Since: 2.26
+ */
+void webkit_gelocation_manager_failed(WebKitGeolocationManager* manager, const char* errorMessage)
+{
+    g_return_if_fail(WEBKIT_IS_GEOLOCATION_MANAGER(manager));
+
+    manager->priv->manager->providerDidFailToDeterminePosition(String::fromUTF8(errorMessage));
+}
+
+/**
+ * webkit_geolocation_manager_get_enable_high_accuracy:
+ * @manager: a #WebKitGeolocationManager
+ *
+ * Get whether high accuracy is enabled.
+ *
+ * Since: 2.26
+ */
+gboolean webkit_geolocation_manager_get_enable_high_accuracy(WebKitGeolocationManager* manager)
+{
+    g_return_val_if_fail(WEBKIT_IS_GEOLOCATION_MANAGER(manager), FALSE);
+
+    return manager->priv->highAccuracyEnabled;
+}
diff --git a/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManagerPrivate.h b/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManagerPrivate.h
new file mode 100644 (file)
index 0000000..1a8be5e
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include "WebGeolocationManagerProxy.h"
+#include "WebKitGeolocationManager.h"
+
+WebKitGeolocationManager* webkitGeolocationManagerCreate(WebKit::WebGeolocationManagerProxy*);
diff --git a/Source/WebKit/UIProcess/API/glib/WebKitGeolocationProvider.cpp b/Source/WebKit/UIProcess/API/glib/WebKitGeolocationProvider.cpp
deleted file mode 100644 (file)
index 95b02e8..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WebKitGeolocationProvider.h"
-
-#if ENABLE(GEOLOCATION)
-
-#include "APIGeolocationProvider.h"
-#include "WebGeolocationManagerProxy.h"
-#include "WebGeolocationPosition.h"
-
-namespace WebKit {
-
-class GeolocationProvider : public API::GeolocationProvider {
-public:
-    explicit GeolocationProvider(WebKitGeolocationProvider& provider)
-        : m_provider(provider)
-    {
-    }
-
-private:
-    void startUpdating(WebGeolocationManagerProxy&) override
-    {
-        m_provider.startUpdating();
-    }
-
-    void stopUpdating(WebGeolocationManagerProxy&) override
-    {
-        m_provider.stopUpdating();
-    }
-
-    WebKitGeolocationProvider& m_provider;
-};
-
-WebKitGeolocationProvider::~WebKitGeolocationProvider()
-{
-    m_provider.stopUpdating();
-    m_geolocationManager->setProvider(nullptr);
-}
-
-WebKitGeolocationProvider::WebKitGeolocationProvider(WebGeolocationManagerProxy* geolocationManager)
-    : m_geolocationManager(geolocationManager)
-    , m_provider(this)
-{
-    ASSERT(geolocationManager);
-    geolocationManager->setProvider(std::make_unique<GeolocationProvider>(*this));
-}
-
-void WebKitGeolocationProvider::startUpdating()
-{
-    m_provider.startUpdating();
-}
-
-void WebKitGeolocationProvider::stopUpdating()
-{
-    m_provider.stopUpdating();
-}
-
-void WebKitGeolocationProvider::notifyPositionChanged(int timestamp, double latitude, double longitude, double altitude, double accuracy, double altitudeAccuracy)
-{
-    WebCore::GeolocationPosition corePosition { static_cast<double>(timestamp), latitude, longitude, accuracy };
-    corePosition.altitude = altitude;
-    corePosition.altitudeAccuracy = altitudeAccuracy;
-    auto position = WebGeolocationPosition::create(WTFMove(corePosition));
-    m_geolocationManager->providerDidChangePosition(position.ptr());
-}
-
-void WebKitGeolocationProvider::notifyErrorOccurred(const char* /* message */)
-{
-    m_geolocationManager->providerDidFailToDeterminePosition();
-}
-
-} // namespace WebKit
-
-#endif // ENABLE(GEOLOCATION)
diff --git a/Source/WebKit/UIProcess/API/glib/WebKitGeolocationProvider.h b/Source/WebKit/UIProcess/API/glib/WebKitGeolocationProvider.h
deleted file mode 100644 (file)
index dc16361..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-#if ENABLE(GEOLOCATION)
-
-#include <WebCore/GeolocationProviderGeoclue.h>
-#include <WebCore/GeolocationProviderGeoclueClient.h>
-
-namespace WebKit {
-class WebGeolocationManagerProxy;
-
-class WebKitGeolocationProvider final : public WebCore::GeolocationProviderGeoclueClient {
-public:
-    explicit WebKitGeolocationProvider(WebGeolocationManagerProxy*);
-    ~WebKitGeolocationProvider();
-
-    void startUpdating();
-    void stopUpdating();
-
-private:
-    // GeolocationProviderGeoclueClient interface.
-    void notifyPositionChanged(int, double, double, double, double, double) override;
-    void notifyErrorOccurred(const char*) override;
-
-    RefPtr<WebGeolocationManagerProxy> m_geolocationManager;
-    WebCore::GeolocationProviderGeoclue m_provider;
-};
-
-} // namespace WebKit
-
-#endif // ENABLE(GEOLOCATION)
-
index ff3ff86..2c1f3e9 100644 (file)
 #include "TextCheckerState.h"
 #include "WebAutomationSession.h"
 #include "WebCertificateInfo.h"
-#include "WebGeolocationManagerProxy.h"
 #include "WebKitAutomationSessionPrivate.h"
 #include "WebKitCustomProtocolManagerClient.h"
 #include "WebKitDownloadClient.h"
 #include "WebKitDownloadPrivate.h"
 #include "WebKitFaviconDatabasePrivate.h"
-#include "WebKitGeolocationProvider.h"
+#include "WebKitGeolocationManagerPrivate.h"
 #include "WebKitInjectedBundleClient.h"
 #include "WebKitNetworkProxySettingsPrivate.h"
 #include "WebKitNotificationProvider.h"
@@ -170,9 +169,7 @@ struct _WebKitWebContextPrivate {
     GRefPtr<WebKitSecurityManager> securityManager;
     URISchemeHandlerMap uriSchemeHandlers;
     URISchemeRequestMap uriSchemeRequests;
-#if ENABLE(GEOLOCATION)
-    std::unique_ptr<WebKitGeolocationProvider> geolocationProvider;
-#endif
+    GRefPtr<WebKitGeolocationManager> geolocationManager;
     std::unique_ptr<WebKitNotificationProvider> notificationProvider;
     GRefPtr<WebKitWebsiteDataManager> websiteDataManager;
 
@@ -367,9 +364,7 @@ static void webkitWebContextConstructed(GObject* object)
     attachDownloadClientToContext(webContext);
     attachCustomProtocolManagerClientToContext(webContext);
 
-#if ENABLE(GEOLOCATION)
-    priv->geolocationProvider = std::make_unique<WebKitGeolocationProvider>(priv->processPool->supplement<WebGeolocationManagerProxy>());
-#endif
+    priv->geolocationManager = adoptGRef(webkitGeolocationManagerCreate(priv->processPool->supplement<WebGeolocationManagerProxy>()));
     priv->notificationProvider = std::make_unique<WebKitNotificationProvider>(priv->processPool->supplement<WebNotificationManagerProxy>(), webContext);
 #if PLATFORM(GTK) && ENABLE(REMOTE_INSPECTOR)
     priv->remoteInspectorProtocolHandler = std::make_unique<RemoteInspectorProtocolHandler>(webContext);
@@ -867,6 +862,23 @@ WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* con
     return webkit_website_data_manager_get_cookie_manager(context->priv->websiteDataManager.get());
 }
 
+/**
+ * webkit_web_context_get_geolocation_manager:
+ * @context: a #WebKitWebContext
+ *
+ * Get the #WebKitGeolocationManager of @context.
+ *
+ * Returns: (transfer none): the #WebKitGeolocationManager of @context.
+ *
+ * Since: 2.26
+ */
+WebKitGeolocationManager* webkit_web_context_get_geolocation_manager(WebKitWebContext* context)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), nullptr);
+
+    return context->priv->geolocationManager.get();
+}
+
 static void ensureFaviconDatabase(WebKitWebContext* context)
 {
     WebKitWebContextPrivate* priv = context->priv;
diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitGeolocationManager.h b/Source/WebKit/UIProcess/API/gtk/WebKitGeolocationManager.h
new file mode 100644 (file)
index 0000000..207c5f8
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitGeolocationManager_h
+#define WebKitGeolocationManager_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_GEOLOCATION_MANAGER            (webkit_geolocation_manager_get_type())
+#define WEBKIT_GEOLOCATION_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_GEOLOCATION_MANAGER, WebKitGeolocationManager))
+#define WEBKIT_IS_GEOLOCATION_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_GEOLOCATION_MANAGER))
+#define WEBKIT_GEOLOCATION_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_GEOLOCATION_MANAGER, WebKitGeolocationManagerClass))
+#define WEBKIT_IS_GEOLOCATION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_GEOLOCATION_MANAGER))
+#define WEBKIT_GEOLOCATION_MANAGER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_GEOLOCATION_MANAGER, WebKitGeolocationManagerClass))
+
+#define WEBKIT_TYPE_GEOLOCATION_POSITION           (webkit_geolocation_position_get_type())
+
+typedef struct _WebKitGeolocationManager        WebKitGeolocationManager;
+typedef struct _WebKitGeolocationManagerClass   WebKitGeolocationManagerClass;
+typedef struct _WebKitGeolocationManagerPrivate WebKitGeolocationManagerPrivate;
+typedef struct _WebKitGeolocationPosition       WebKitGeolocationPosition;
+
+struct _WebKitGeolocationManager {
+    GObject parent;
+
+    /*< private >*/
+    WebKitGeolocationManagerPrivate *priv;
+};
+
+struct _WebKitGeolocationManagerClass {
+    GObjectClass parent_class;
+
+    void (*_webkit_reserved0) (void);
+    void (*_webkit_reserved1) (void);
+    void (*_webkit_reserved2) (void);
+    void (*_webkit_reserved3) (void);
+};
+
+WEBKIT_API GType
+webkit_geolocation_manager_get_type                 (void);
+
+WEBKIT_API void
+webkit_gelocation_manager_update_position           (WebKitGeolocationManager  *manager,
+                                                     WebKitGeolocationPosition *position);
+
+WEBKIT_API void
+webkit_gelocation_manager_failed                    (WebKitGeolocationManager  *manager,
+                                                     const char                *error_message);
+
+WEBKIT_API gboolean
+webkit_geolocation_manager_get_enable_high_accuracy (WebKitGeolocationManager  *manager);
+
+
+WEBKIT_API GType
+webkit_geolocation_position_get_type                (void);
+
+WEBKIT_API WebKitGeolocationPosition *
+webkit_geolocation_position_new                     (double                     latitude,
+                                                     double                     longitude,
+                                                     double                     accuracy);
+
+WEBKIT_API WebKitGeolocationPosition *
+webkit_geolocation_position_copy                    (WebKitGeolocationPosition *position);
+
+WEBKIT_API void
+webkit_geolocation_position_free                    (WebKitGeolocationPosition *position);
+
+WEBKIT_API void
+webkit_geolocation_position_set_timestamp           (WebKitGeolocationPosition *position,
+                                                     guint64                    timestamp);
+
+WEBKIT_API void
+webkit_geolocation_position_set_altitude            (WebKitGeolocationPosition *position,
+                                                     double                     altitude);
+
+WEBKIT_API void
+webkit_geolocation_position_set_altitude_accuracy   (WebKitGeolocationPosition *position,
+                                                     double                     altitude_accuracy);
+
+WEBKIT_API void
+webkit_geolocation_position_set_heading             (WebKitGeolocationPosition *position,
+                                                     double                     heading);
+
+WEBKIT_API void
+webkit_geolocation_position_set_speed               (WebKitGeolocationPosition *position,
+                                                     double                     speed);
+
+G_END_DECLS
+
+#endif /* WebKitGeolocationManager_h */
index 81351af..82a8d82 100644 (file)
@@ -30,6 +30,7 @@
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitDownload.h>
 #include <webkit2/WebKitFaviconDatabase.h>
+#include <webkit2/WebKitGeolocationManager.h>
 #include <webkit2/WebKitNetworkProxySettings.h>
 #include <webkit2/WebKitSecurityManager.h>
 #include <webkit2/WebKitURISchemeRequest.h>
@@ -214,6 +215,9 @@ webkit_web_context_download_uri                     (WebKitWebContext
 WEBKIT_API WebKitCookieManager *
 webkit_web_context_get_cookie_manager               (WebKitWebContext              *context);
 
+WEBKIT_API WebKitGeolocationManager *
+webkit_web_context_get_geolocation_manager          (WebKitWebContext              *context);
+
 WEBKIT_API WebKitFaviconDatabase *
 webkit_web_context_get_favicon_database             (WebKitWebContext              *context);
 
index 06d7450..eee101a 100644 (file)
@@ -44,6 +44,7 @@ webkit_web_context_clear_cache
 webkit_web_context_set_network_proxy_settings
 webkit_web_context_download_uri
 webkit_web_context_get_cookie_manager
+webkit_web_context_get_geolocation_manager
 webkit_web_context_get_favicon_database
 webkit_web_context_set_favicon_database_directory
 webkit_web_context_get_favicon_database_directory
@@ -1494,6 +1495,40 @@ WEBKIT_TYPE_APPLICATION_INFO
 </SECTION>
 
 <SECTION>
+<FILE>WebKitGeolocationManager</FILE>
+WebKitGeolocationManager
+webkit_gelocation_manager_update_position
+webkit_gelocation_manager_failed
+webkit_geolocation_manager_get_enable_high_accuracy
+
+<SUBSECTION Position>
+WebKitGeolocationPosition
+webkit_geolocation_position_new
+webkit_geolocation_position_copy
+webkit_geolocation_position_free
+webkit_geolocation_position_set_timestamp
+webkit_geolocation_position_set_altitude
+webkit_geolocation_position_set_altitude_accuracy
+webkit_geolocation_position_set_heading
+webkit_geolocation_position_set_speed
+
+<SUBSECTION Private>
+WebKitGeolocationManagerPrivate
+webkit_geolocation_manager_get_type
+webkit_geolocation_position_get_type
+
+<SUBSECTION Standard>
+WebKitGeolocationManagerClass
+WEBKIT_TYPE_GEOLOCATION_MANAGER
+WEBKIT_GEOLOCATION_MANAGER
+WEBKIT_IS_GEOLOCATION_MANAGER
+WEBKIT_GEOLOCATION_MANAGER_CLASS
+WEBKIT_IS_GEOLOCATION_MANAGER_CLASS
+WEBKIT_GEOLOCATION_MANAGER_GET_CLASS
+WEBKIT_TYPE_GEOLOCATION_POSITION
+</SECTION>
+
+<SECTION>
 <FILE>WebKitWebExtension</FILE>
 WebKitWebExtension
 WebKitWebExtensionInitializeFunction
index cfed673..ad5b026 100644 (file)
@@ -40,3 +40,5 @@ webkit_automation_session_get_type
 webkit_option_menu_get_type
 webkit_option_menu_item_get_type
 webkit_device_info_permission_request_get_type
+webkit_geolocation_manager_get_type
+webkit_geolocation_position_get_type
\ No newline at end of file
index aceea54..9d3a2bd 100644 (file)
@@ -62,6 +62,7 @@
     <xi:include href="xml/WebKitNetworkProxySettings.xml"/>
     <xi:include href="xml/WebKitAutomationSession.xml"/>
     <xi:include href="xml/WebKitApplicationInfo.xml"/>
+    <xi:include href="xml/WebKitGeolocationManager.xml"/>
   </chapter>
 
   <chapter>
     <xi:include href="xml/api-index-2.24.xml"><xi:fallback /></xi:include>
   </index>
 
+  <index id="api-index-2-26" role="2.26">
+    <title>Index of new symbols in 2.26</title>
+    <xi:include href="xml/api-index-2.26.xml"><xi:fallback /></xi:include>
+  </index>
+
   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
 </book>
index 1470b27..f3edcce 100644 (file)
@@ -49,6 +49,7 @@
 #include <webkit2/WebKitFileChooserRequest.h>
 #include <webkit2/WebKitFindController.h>
 #include <webkit2/WebKitFormSubmissionRequest.h>
+#include <webkit2/WebKitGeolocationManager.h>
 #include <webkit2/WebKitGeolocationPermissionRequest.h>
 #include <webkit2/WebKitHitTestResult.h>
 #include <webkit2/WebKitInstallMissingMediaPluginsPermissionRequest.h>
diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitGeolocationManager.h b/Source/WebKit/UIProcess/API/wpe/WebKitGeolocationManager.h
new file mode 100644 (file)
index 0000000..609cb4c
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <wpe/webkit.h> can be included directly."
+#endif
+
+#ifndef WebKitGeolocationManager_h
+#define WebKitGeolocationManager_h
+
+#include <glib-object.h>
+#include <wpe/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_GEOLOCATION_MANAGER            (webkit_geolocation_manager_get_type())
+#define WEBKIT_GEOLOCATION_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_GEOLOCATION_MANAGER, WebKitGeolocationManager))
+#define WEBKIT_IS_GEOLOCATION_MANAGER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_GEOLOCATION_MANAGER))
+#define WEBKIT_GEOLOCATION_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_GEOLOCATION_MANAGER, WebKitGeolocationManagerClass))
+#define WEBKIT_IS_GEOLOCATION_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_GEOLOCATION_MANAGER))
+#define WEBKIT_GEOLOCATION_MANAGER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_GEOLOCATION_MANAGER, WebKitGeolocationManagerClass))
+
+#define WEBKIT_TYPE_GEOLOCATION_POSITION           (webkit_geolocation_position_get_type())
+
+typedef struct _WebKitGeolocationManager        WebKitGeolocationManager;
+typedef struct _WebKitGeolocationManagerClass   WebKitGeolocationManagerClass;
+typedef struct _WebKitGeolocationManagerPrivate WebKitGeolocationManagerPrivate;
+typedef struct _WebKitGeolocationPosition       WebKitGeolocationPosition;
+
+struct _WebKitGeolocationManager {
+    GObject parent;
+
+    /*< private >*/
+    WebKitGeolocationManagerPrivate *priv;
+};
+
+struct _WebKitGeolocationManagerClass {
+    GObjectClass parent_class;
+
+    void (*_webkit_reserved0) (void);
+    void (*_webkit_reserved1) (void);
+    void (*_webkit_reserved2) (void);
+    void (*_webkit_reserved3) (void);
+};
+
+WEBKIT_API GType
+webkit_geolocation_manager_get_type                 (void);
+
+WEBKIT_API void
+webkit_gelocation_manager_update_position           (WebKitGeolocationManager  *manager,
+                                                     WebKitGeolocationPosition *position);
+
+WEBKIT_API void
+webkit_gelocation_manager_failed                    (WebKitGeolocationManager  *manager,
+                                                     const char                *error_message);
+
+WEBKIT_API gboolean
+webkit_geolocation_manager_get_enable_high_accuracy (WebKitGeolocationManager  *manager);
+
+
+WEBKIT_API GType
+webkit_geolocation_position_get_type                (void);
+
+WEBKIT_API WebKitGeolocationPosition *
+webkit_geolocation_position_new                     (double                     latitude,
+                                                     double                     longitude,
+                                                     double                     accuracy);
+
+WEBKIT_API WebKitGeolocationPosition *
+webkit_geolocation_position_copy                    (WebKitGeolocationPosition *position);
+
+WEBKIT_API void
+webkit_geolocation_position_free                    (WebKitGeolocationPosition *position);
+
+WEBKIT_API void
+webkit_geolocation_position_set_timestamp           (WebKitGeolocationPosition *position,
+                                                     guint64                    timestamp);
+
+WEBKIT_API void
+webkit_geolocation_position_set_altitude            (WebKitGeolocationPosition *position,
+                                                     double                     altitude);
+
+WEBKIT_API void
+webkit_geolocation_position_set_altitude_accuracy   (WebKitGeolocationPosition *position,
+                                                     double                     altitude_accuracy);
+
+WEBKIT_API void
+webkit_geolocation_position_set_heading             (WebKitGeolocationPosition *position,
+                                                     double                     heading);
+
+WEBKIT_API void
+webkit_geolocation_position_set_speed               (WebKitGeolocationPosition *position,
+                                                     double                     speed);
+
+G_END_DECLS
+
+#endif /* WebKitGeolocationManager_h */
index 081cd11..a32680f 100644 (file)
@@ -30,6 +30,7 @@
 #include <wpe/WebKitDefines.h>
 #include <wpe/WebKitDownload.h>
 #include <wpe/WebKitFaviconDatabase.h>
+#include <wpe/WebKitGeolocationManager.h>
 #include <wpe/WebKitNetworkProxySettings.h>
 #include <wpe/WebKitSecurityManager.h>
 #include <wpe/WebKitURISchemeRequest.h>
@@ -214,6 +215,9 @@ webkit_web_context_download_uri                     (WebKitWebContext
 WEBKIT_API WebKitCookieManager *
 webkit_web_context_get_cookie_manager               (WebKitWebContext              *context);
 
+WEBKIT_API WebKitGeolocationManager *
+webkit_web_context_get_geolocation_manager          (WebKitWebContext              *context);
+
 WEBKIT_API WebKitFaviconDatabase *
 webkit_web_context_get_favicon_database             (WebKitWebContext              *context);
 
index 18c91c8..5677f56 100644 (file)
@@ -22,6 +22,7 @@ webkit_web_context_clear_cache
 webkit_web_context_set_network_proxy_settings
 webkit_web_context_download_uri
 webkit_web_context_get_cookie_manager
+webkit_web_context_get_geolocation_manager
 webkit_web_context_get_favicon_database
 webkit_web_context_set_favicon_database_directory
 webkit_web_context_get_favicon_database_directory
@@ -1368,6 +1369,40 @@ WEBKIT_TYPE_APPLICATION_INFO
 </SECTION>
 
 <SECTION>
+<FILE>WebKitGeolocationManager</FILE>
+WebKitGeolocationManager
+webkit_gelocation_manager_update_position
+webkit_gelocation_manager_failed
+webkit_geolocation_manager_get_enable_high_accuracy
+
+<SUBSECTION Position>
+WebKitGeolocationPosition
+webkit_geolocation_position_new
+webkit_geolocation_position_copy
+webkit_geolocation_position_free
+webkit_geolocation_position_set_timestamp
+webkit_geolocation_position_set_altitude
+webkit_geolocation_position_set_altitude_accuracy
+webkit_geolocation_position_set_heading
+webkit_geolocation_position_set_speed
+
+<SUBSECTION Private>
+WebKitGeolocationManagerPrivate
+webkit_geolocation_manager_get_type
+webkit_geolocation_position_get_type
+
+<SUBSECTION Standard>
+WebKitGeolocationManagerClass
+WEBKIT_TYPE_GEOLOCATION_MANAGER
+WEBKIT_GEOLOCATION_MANAGER
+WEBKIT_IS_GEOLOCATION_MANAGER
+WEBKIT_GEOLOCATION_MANAGER_CLASS
+WEBKIT_IS_GEOLOCATION_MANAGER_CLASS
+WEBKIT_GEOLOCATION_MANAGER_GET_CLASS
+WEBKIT_TYPE_GEOLOCATION_POSITION
+</SECTION>
+
+<SECTION>
 <FILE>WebKitURIUtilities</FILE>
 webkit_uri_for_display
 </SECTION>
index f6eb38d..c7b36d0 100644 (file)
@@ -56,6 +56,7 @@
     <xi:include href="xml/WebKitAutomationSession.xml"/>
     <xi:include href="xml/WebKitApplicationInfo.xml"/>
     <xi:include href="xml/WebKitColor.xml"/>
+    <xi:include href="xml/WebKitGeolocationManager.xml"/>
   </chapter>
 
   <chapter>
     <xi:include href="xml/api-index-2.22.xml"><xi:fallback /></xi:include>
   </index>
 
+  <index id="api-index-2-24" role="2.24">
+    <title>Index of new symbols in 2.24</title>
+    <xi:include href="xml/api-index-2.24.xml"><xi:fallback /></xi:include>
+  </index>
+
+  <index id="api-index-2-26" role="2.26">
+    <title>Index of new symbols in 2.26</title>
+    <xi:include href="xml/api-index-2.62.xml"><xi:fallback /></xi:include>
+  </index>
+
   <xi:include href="xml/annotation-glossary.xml"><xi:fallback /></xi:include>
 </book>
index ec2a61d..48523b4 100644 (file)
@@ -47,6 +47,7 @@
 #include <wpe/WebKitFaviconDatabase.h>
 #include <wpe/WebKitFindController.h>
 #include <wpe/WebKitFormSubmissionRequest.h>
+#include <wpe/WebKitGeolocationManager.h>
 #include <wpe/WebKitGeolocationPermissionRequest.h>
 #include <wpe/WebKitHitTestResult.h>
 #include <wpe/WebKitInstallMissingMediaPluginsPermissionRequest.h>
index 8a0cd3b..f6cfeb6 100644 (file)
@@ -80,6 +80,7 @@ WEBKIT_OPTION_DEFINE(ENABLE_PLUGIN_PROCESS_GTK2 "Whether to build WebKitPluginPr
 WEBKIT_OPTION_DEFINE(ENABLE_QUARTZ_TARGET "Whether to enable support for the Quartz windowing target." PUBLIC ${GTK3_SUPPORTS_QUARTZ})
 WEBKIT_OPTION_DEFINE(ENABLE_X11_TARGET "Whether to enable support for the X11 windowing target." PUBLIC ${GTK3_SUPPORTS_X11})
 WEBKIT_OPTION_DEFINE(ENABLE_WAYLAND_TARGET "Whether to enable support for the Wayland windowing target." PUBLIC ${GTK3_SUPPORTS_WAYLAND})
+WEBKIT_OPTION_DEFINE(USE_GEOCLUE "Whether to enable default geolocation implementation using GeoClue2" PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBNOTIFY "Whether to enable the default web notification implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBHYPHEN "Whether to enable the default automatic hyphenation implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBSECRET "Whether to enable the persistent credential storage using libsecret." PUBLIC ON)
@@ -140,7 +141,6 @@ endif ()
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ACCELERATED_2D_CANVAS PUBLIC OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ASYNC_SCROLLING PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DRAG_SUPPORT PUBLIC ON)
-WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_GEOLOCATION PUBLIC ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ICONDATABASE PUBLIC ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SPELLCHECK PUBLIC ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_TOUCH_EVENTS PUBLIC ON)
@@ -222,10 +222,10 @@ if (USE_LIBSECRET)
     endif ()
 endif ()
 
-if (ENABLE_GEOLOCATION)
+if (USE_GEOCLUE)
     find_package(GeoClue2 2.1.5)
     if (NOT GEOCLUE2_FOUND)
-        message(FATAL_ERROR "Geoclue is needed for ENABLE_GEOLOCATION.")
+        message(FATAL_ERROR "Geoclue is needed for USE_GEOCLUE.")
     endif ()
 endif ()
 
index b57104d..5d7c9b3 100644 (file)
@@ -48,7 +48,6 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_XSLT PUBLIC ON)
 # Changing these options is completely unsupported.
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ASYNC_SCROLLING PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CONTENT_EXTENSIONS PRIVATE ON)
-WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_GEOLOCATION PRIVATE OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MHTML PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API PRIVATE OFF)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NOTIFICATIONS PRIVATE OFF)
index 3fed59e..532af17 100644 (file)
@@ -1,5 +1,24 @@
 2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK][WPE] Add API to provide geolocation information
+        https://bugs.webkit.org/show_bug.cgi?id=195940
+
+        Reviewed by Michael Catanzaro.
+
+        Add a new test to check the new API.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestGeolocationManager.cpp: Added.
+        (testGeolocationManagerCurrentPosition):
+        (testGeolocationManagerWatchPosition):
+        (beforeAll):
+        (afterAll):
+        * TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
+        (testWebViewGeolocationPermissionRequests): Stop using ENABLE(GEOLOCATION) conditionals for geolocation tests.
+        (beforeAll): Ditto.
+        * TestWebKitAPI/glib/CMakeLists.txt:
+
+2019-03-21  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GLib] Returning G_TYPE_OBJECT from a method does not work
         https://bugs.webkit.org/show_bug.cgi?id=195574
 
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGLib/TestGeolocationManager.cpp b/Tools/TestWebKitAPI/Tests/WebKitGLib/TestGeolocationManager.cpp
new file mode 100644 (file)
index 0000000..981b5ef
--- /dev/null
@@ -0,0 +1,337 @@
+/*
+ * Copyright (C) 2019 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "TestMain.h"
+
+#include "WebViewTest.h"
+#include <wtf/WallTime.h>
+
+class GeolocationTest: public WebViewTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(GeolocationTest);
+
+    struct Position {
+        double timestamp { std::numeric_limits<double>::quiet_NaN() };
+        double latitude { std::numeric_limits<double>::quiet_NaN() };
+        double longitude { std::numeric_limits<double>::quiet_NaN() };
+        double accuracy { std::numeric_limits<double>::quiet_NaN() };
+
+        Optional<double> altitude;
+        Optional<double> altitudeAccuracy;
+        Optional<double> heading;
+        Optional<double> speed;
+    };
+
+    static gboolean startCallback(WebKitGeolocationManager* manager, GeolocationTest* test)
+    {
+        g_assert_true(test->m_manager == manager);
+        test->start();
+        return TRUE;
+    }
+
+    static void stopCallback(WebKitGeolocationManager* manager, GeolocationTest* test)
+    {
+        g_assert_true(test->m_manager == manager);
+        test->stop();
+    }
+
+    static gboolean permissionRequested(WebKitWebView*, WebKitPermissionRequest* request, GeolocationTest* test)
+    {
+        g_assert_true(WEBKIT_IS_PERMISSION_REQUEST(request));
+        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request));
+
+        if (WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(request)) {
+            webkit_permission_request_allow(request);
+            return TRUE;
+        }
+
+        return FALSE;
+    }
+
+    GeolocationTest()
+        : m_manager(webkit_web_context_get_geolocation_manager(m_webContext.get()))
+    {
+        g_assert_true(WEBKIT_IS_GEOLOCATION_MANAGER(m_manager));
+        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_manager));
+        g_signal_connect(m_manager, "start", G_CALLBACK(startCallback), this);
+        g_signal_connect(m_manager, "stop", G_CALLBACK(stopCallback), this);
+        g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequested), this);
+    }
+
+    ~GeolocationTest()
+    {
+        if (m_checkPosition)
+            webkit_geolocation_position_free(m_checkPosition);
+
+        g_signal_handlers_disconnect_matched(m_manager, G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
+        g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
+    }
+
+    void start()
+    {
+        g_assert_false(m_updating);
+        m_updating = true;
+
+        if (m_errorMessage) {
+            g_assert_false(m_checkPosition);
+            webkit_gelocation_manager_failed(m_manager, m_errorMessage.get());
+        }
+
+        if (m_checkPosition) {
+            g_assert_false(m_errorMessage.get());
+            webkit_gelocation_manager_update_position(m_manager, m_checkPosition);
+        }
+
+        g_main_loop_quit(m_mainLoop);
+    }
+
+    void stop()
+    {
+        g_assert_true(m_updating);
+        m_updating = false;
+        if (m_watching)
+            g_main_loop_quit(m_mainLoop);
+    }
+
+    Position lastPosition()
+    {
+        GUniqueOutPtr<GError> error;
+        auto* javascriptResult = runJavaScriptAndWaitUntilFinished("position", &error.outPtr());
+        g_assert_nonnull(javascriptResult);
+        g_assert_no_error(error.get());
+
+        auto* jsPosition = webkit_javascript_result_get_js_value(javascriptResult);
+        g_assert_true(jsc_value_is_object(jsPosition));
+        Position result;
+        GRefPtr<JSCValue> value = adoptGRef(jsc_value_object_get_property(jsPosition, "latitude"));
+        g_assert_true(jsc_value_is_number(value.get()));
+        result.latitude = jsc_value_to_double(value.get());
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "longitude"));
+        g_assert_true(jsc_value_is_number(value.get()));
+        result.longitude = jsc_value_to_double(value.get());
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "accuracy"));
+        g_assert_true(jsc_value_is_number(value.get()));
+        result.accuracy = jsc_value_to_double(value.get());
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "altitude"));
+        if (!jsc_value_is_null(value.get())) {
+            g_assert_true(jsc_value_is_number(value.get()));
+            result.altitude = jsc_value_to_double(value.get());
+        }
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "altitudeAccuracy"));
+        if (!jsc_value_is_null(value.get())) {
+            g_assert_true(jsc_value_is_number(value.get()));
+            result.altitudeAccuracy = jsc_value_to_double(value.get());
+        }
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "heading"));
+        if (!jsc_value_is_null(value.get())) {
+            g_assert_true(jsc_value_is_number(value.get()));
+            result.heading = jsc_value_to_double(value.get());
+        }
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "speed"));
+        if (!jsc_value_is_null(value.get())) {
+            g_assert_true(jsc_value_is_number(value.get()));
+            result.speed = jsc_value_to_double(value.get());
+        }
+        value = adoptGRef(jsc_value_object_get_property(jsPosition, "timestamp"));
+        g_assert_true(jsc_value_is_number(value.get()));
+        result.timestamp = jsc_value_to_double(value.get());
+        return result;
+    }
+
+    Position checkCurrentPosition(WebKitGeolocationPosition* position, bool enableHighAccuracy = false)
+    {
+        g_clear_pointer(&m_checkPosition, webkit_geolocation_position_free);
+        m_checkPosition = position;
+
+        static const char getCurrentPosition[] =
+            "var position = null;\n"
+            "options = { enableHighAccuracy: %s }\n"
+            "navigator.geolocation.getCurrentPosition(function(p) {\n"
+            "  position = { };\n"
+            "  position.latitude = p.coords.latitude;\n"
+            "  position.longitude = p.coords.longitude;\n"
+            "  position.accuracy = p.coords.accuracy;\n"
+            "  position.altitude = p.coords.altitude;\n"
+            "  position.altitudeAccuracy = p.coords.altitudeAccuracy;\n"
+            "  position.heading = p.coords.heading;\n"
+            "  position.speed = p.coords.speed;\n"
+            "  position.timestamp = p.timestamp;\n"
+            "}, undefined, options);";
+        GUniquePtr<char> script(g_strdup_printf(getCurrentPosition, enableHighAccuracy ? "true" : "false"));
+        GUniqueOutPtr<GError> error;
+        runJavaScriptAndWaitUntilFinished(script.get(), &error.outPtr());
+        g_assert_no_error(error.get());
+        g_main_loop_run(m_mainLoop);
+        g_clear_pointer(&m_checkPosition, webkit_geolocation_position_free);
+        g_assert_true(webkit_geolocation_manager_get_enable_high_accuracy(m_manager) == enableHighAccuracy);
+
+        return lastPosition();
+    }
+
+    GUniquePtr<char> checkFailedToDeterminePosition(const char* errorMessage)
+    {
+        m_errorMessage.reset(g_strdup(errorMessage));
+        static const char getCurrentPosition[] =
+            "var error;\n"
+            "navigator.geolocation.getCurrentPosition(\n"
+            "  function(p) { error = null; },\n"
+            "  function(e) { error = e.message.toString(); }\n"
+            ");";
+        GUniqueOutPtr<GError> error;
+        auto* javascriptResult = runJavaScriptAndWaitUntilFinished(getCurrentPosition, &error.outPtr());
+        g_assert_no_error(error.get());
+        g_main_loop_run(m_mainLoop);
+        m_errorMessage = nullptr;
+
+        javascriptResult = runJavaScriptAndWaitUntilFinished("error", &error.outPtr());
+        g_assert_nonnull(javascriptResult);
+        g_assert_no_error(error.get());
+        auto* jsErrorMessage = webkit_javascript_result_get_js_value(javascriptResult);
+        g_assert_true(jsc_value_is_string(jsErrorMessage));
+        return GUniquePtr<char>(jsc_value_to_string(jsErrorMessage));
+    }
+
+    void startWatch()
+    {
+        g_clear_pointer(&m_checkPosition, webkit_geolocation_position_free);
+        m_errorMessage = nullptr;
+
+        m_watching = true;
+        static const char watchPosition[] =
+            "var position = null;\n"
+            "var watchID = navigator.geolocation.watchPosition(function(p) {\n"
+            "  position = { };\n"
+            "  position.latitude = p.coords.latitude;\n"
+            "  position.longitude = p.coords.longitude;\n"
+            "  position.accuracy = p.coords.accuracy;\n"
+            "  position.altitude = p.coords.altitude;\n"
+            "  position.altitudeAccuracy = p.coords.altitudeAccuracy;\n"
+            "  position.heading = p.coords.heading;\n"
+            "  position.speed = p.coords.speed;\n"
+            "  position.timestamp = p.timestamp;\n"
+            "});";
+        GUniqueOutPtr<GError> error;
+        auto* javascriptResult = runJavaScriptAndWaitUntilFinished(watchPosition, &error.outPtr());
+        g_assert_nonnull(javascriptResult);
+        g_assert_no_error(error.get());
+        g_main_loop_run(m_mainLoop);
+    }
+
+    void stopWatch()
+    {
+        GUniqueOutPtr<GError> error;
+        runJavaScriptAndWaitUntilFinished("navigator.geolocation.clearWatch(watchID)", &error.outPtr());
+        g_assert_no_error(error.get());
+        g_main_loop_run(m_mainLoop);
+        m_watching = false;
+    }
+
+    WebKitGeolocationManager* m_manager;
+    bool m_updating { false };
+    bool m_watching { false };
+    WebKitGeolocationPosition* m_checkPosition { nullptr };
+    GUniquePtr<char> m_errorMessage;
+};
+
+static void testGeolocationManagerCurrentPosition(GeolocationTest* test, gconstpointer)
+{
+    test->showInWindow();
+    test->loadHtml("<html><body></body></html>", "https://foo.com/bar");
+    test->waitUntilLoadFinished();
+
+    WebKitGeolocationPosition* position = webkit_geolocation_position_new(37.1760783, -3.59033, 17);
+    g_assert_false(test->m_updating);
+    auto result = test->checkCurrentPosition(position);
+    g_assert_false(test->m_updating);
+    g_assert_cmpfloat(result.latitude, ==, 37.1760783);
+    g_assert_cmpfloat(result.longitude, ==, -3.59033);
+    g_assert_cmpfloat(result.accuracy, ==, 17);
+    g_assert_false(result.altitude);
+    g_assert_false(result.altitudeAccuracy);
+    g_assert_false(result.heading);
+    g_assert_false(result.speed);
+    g_assert_cmpfloat(result.timestamp, >, 0);
+    g_assert_cmpfloat(result.timestamp / 1000., <, WallTime::now().secondsSinceEpoch().value());
+
+    position = webkit_geolocation_position_new(27.986065, 86.922623, 0);
+    auto timestamp = WallTime::now().secondsSinceEpoch();
+    webkit_geolocation_position_set_timestamp(position, timestamp.value());
+    webkit_geolocation_position_set_altitude(position, 8495);
+    webkit_geolocation_position_set_altitude_accuracy(position, 0);
+    webkit_geolocation_position_set_heading(position, 100.55);
+    webkit_geolocation_position_set_speed(position, 0.05);
+    g_assert_false(test->m_updating);
+    result = test->checkCurrentPosition(position, true);
+    g_assert_false(test->m_updating);
+    g_assert_cmpfloat(result.latitude, ==, 27.986065);
+    g_assert_cmpfloat(result.longitude, ==, 86.922623);
+    g_assert_cmpfloat(result.accuracy, ==, 0);
+    g_assert_true(result.altitude);
+    g_assert_cmpfloat(result.altitude.value(), ==, 8495);
+    g_assert_true(result.altitudeAccuracy);
+    g_assert_cmpfloat(result.altitudeAccuracy.value(), ==, 0);
+    g_assert_true(result.heading);
+    g_assert_cmpfloat(result.heading.value(), ==, 100.55);
+    g_assert_true(result.speed);
+    g_assert_cmpfloat(result.speed.value(), ==, 0.05);
+    g_assert_cmpfloat_with_epsilon(result.timestamp / 1000., timestamp.value(), 1);
+
+    auto errorMessage = test->checkFailedToDeterminePosition("GPS is not active");
+    g_assert_cmpstr(errorMessage.get(), ==, "GPS is not active");
+}
+
+static void testGeolocationManagerWatchPosition(GeolocationTest* test, gconstpointer)
+{
+    test->showInWindow();
+    test->loadHtml("<html><body></body></html>", "https://foo.com/bar");
+    test->waitUntilLoadFinished();
+
+    test->startWatch();
+    g_assert_true(test->m_updating);
+
+    WebKitGeolocationPosition* position = webkit_geolocation_position_new(37.1760783, -3.59033, 17);
+    webkit_gelocation_manager_update_position(test->m_manager, position);
+    webkit_geolocation_position_free(position);
+    auto result = test->lastPosition();
+    g_assert_cmpfloat(result.latitude, ==, 37.1760783);
+    g_assert_cmpfloat(result.longitude, ==, -3.59033);
+    g_assert_cmpfloat(result.accuracy, ==, 17);
+
+    position = webkit_geolocation_position_new(38.1770783, -3.60033, 17);
+    webkit_gelocation_manager_update_position(test->m_manager, position);
+    webkit_geolocation_position_free(position);
+    result = test->lastPosition();
+    g_assert_cmpfloat(result.latitude, ==, 38.1770783);
+    g_assert_cmpfloat(result.longitude, ==, -3.60033);
+    g_assert_cmpfloat(result.accuracy, ==, 17);
+
+    test->stopWatch();
+    g_assert_false(test->m_updating);
+}
+
+void beforeAll()
+{
+    GeolocationTest::add("WebKitGeolocationManager", "current-position", testGeolocationManagerCurrentPosition);
+    GeolocationTest::add("WebKitGeolocationManager", "watch-position", testGeolocationManagerWatchPosition);
+}
+
+void afterAll()
+{
+}
index 405c05c..9a7edaa 100644 (file)
@@ -786,7 +786,6 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer)
 }
 #endif // PLATFORM(GTK)
 
-#if ENABLE(GEOLOCATION)
 static void testWebViewGeolocationPermissionRequests(UIClientTest* test, gconstpointer)
 {
     // Some versions of geoclue give a runtime warning because it tries
@@ -831,7 +830,6 @@ static void testWebViewGeolocationPermissionRequests(UIClientTest* test, gconstp
     g_assert_cmpstr(result, !=, "1");
     test->addLogFatalFlag(G_LOG_LEVEL_WARNING);
 }
-#endif // ENABLE(GEOLOCATION)
 
 #if ENABLE(MEDIA_STREAM)
 static void testWebViewUserMediaEnumerateDevicesPermissionCheck(UIClientTest* test, gconstpointer)
@@ -1193,9 +1191,7 @@ void beforeAll()
 #if PLATFORM(GTK)
     UIClientTest::add("WebKitWebView", "mouse-target", testWebViewMouseTarget);
 #endif
-#if ENABLE(GEOLOCATION)
     UIClientTest::add("WebKitWebView", "geolocation-permission-requests", testWebViewGeolocationPermissionRequests);
-#endif
 #if ENABLE(MEDIA_STREAM)
     UIClientTest::add("WebKitWebView", "usermedia-enumeratedevices-permission-check", testWebViewUserMediaEnumerateDevicesPermissionCheck);
     UIClientTest::add("WebKitWebView", "usermedia-permission-requests", testWebViewUserMediaPermissionRequests);
index 65a0078..7cf2177 100644 (file)
@@ -146,6 +146,7 @@ ADD_WK2_TEST(TestWebKitUserContentManager ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKi
 ADD_WK2_TEST(TestWebsiteData ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp)
 ADD_WK2_TEST(TestConsoleMessage ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/TestConsoleMessage.cpp)
 ADD_WK2_TEST(TestDOMElement ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/TestDOMElement.cpp)
+ADD_WK2_TEST(TestGeolocationManager ${TOOLS_DIR}/TestWebKitAPI/Tests/WebKitGLib/TestGeolocationManager.cpp)
 
 # FIXME: Enable for WPE
 if (PORT STREQUAL "GTK")