Title: [243409] trunk
Revision
243409
Author
[email protected]
Date
2019-03-23 03:37:41 -0700 (Sat, 23 Mar 2019)

Log Message

[GTK] Remove build time dependency on Geoclue2
https://bugs.webkit.org/show_bug.cgi?id=195994

Reviewed by Michael Catanzaro.

.:

Remove USE_GEOCLUE build option.

* Source/cmake/FindGeoClue2.cmake: Removed.
* Source/cmake/OptionsGTK.cmake:

Source/WebCore:

Remove old Geoclue implementation.

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

Source/WebCore/platform/gtk/po:

* POTFILES.in: Add GeoclueGeolocationProvider.cpp.

Source/WebKit:

Add GeoclueGeolocationProvider class to provide geolocation position updates using Geoclue2 DBus service.

* PlatformGTK.cmake:
* PlatformWPE.cmake:
* SourcesGTK.txt:
* SourcesWPE.txt:
* UIProcess/API/glib/WebKitGeolocationManager.cpp:
(_WebKitGeolocationPosition::_WebKitGeolocationPosition):
(webkitGeolocationManagerStop):
(webkitGeolocationManagerSetEnableHighAccuracy):
(webkitGeolocationManagerDispose):
(webkit_geolocation_manager_class_init):
* UIProcess/geoclue/GeoclueGeolocationProvider.cpp: Added.
(WebKit::GeoclueGeolocationProvider::GeoclueGeolocationProvider):
(WebKit::GeoclueGeolocationProvider::~GeoclueGeolocationProvider):
(WebKit::GeoclueGeolocationProvider::start):
(WebKit::GeoclueGeolocationProvider::stop):
(WebKit::GeoclueGeolocationProvider::setEnableHighAccuracy):
(WebKit::GeoclueGeolocationProvider::destroyManagerLater):
(WebKit::GeoclueGeolocationProvider::destroyManager):
(WebKit::GeoclueGeolocationProvider::setupManager):
(WebKit::GeoclueGeolocationProvider::createClient):
(WebKit::GeoclueGeolocationProvider::setupClient):
(WebKit::GeoclueGeolocationProvider::startClient):
(WebKit::GeoclueGeolocationProvider::stopClient):
(WebKit::GeoclueGeolocationProvider::requestAccuracyLevel):
(WebKit::GeoclueGeolocationProvider::clientLocationUpdatedCallback):
(WebKit::GeoclueGeolocationProvider::createLocation):
(WebKit::GeoclueGeolocationProvider::locationUpdated):
(WebKit::GeoclueGeolocationProvider::didFail):
* UIProcess/geoclue/GeoclueGeolocationProvider.h: Added.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/ChangeLog (243408 => 243409)


--- trunk/ChangeLog	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/ChangeLog	2019-03-23 10:37:41 UTC (rev 243409)
@@ -1,3 +1,15 @@
+2019-03-23  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remove build time dependency on Geoclue2
+        https://bugs.webkit.org/show_bug.cgi?id=195994
+
+        Reviewed by Michael Catanzaro.
+
+        Remove USE_GEOCLUE build option.
+
+        * Source/cmake/FindGeoClue2.cmake: Removed.
+        * Source/cmake/OptionsGTK.cmake:
+
 2019-03-21  Carlos Garcia Campos  <[email protected]>
 
         [GTK][WPE] Add API to provide geolocation information

Modified: trunk/Source/WebCore/ChangeLog (243408 => 243409)


--- trunk/Source/WebCore/ChangeLog	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebCore/ChangeLog	2019-03-23 10:37:41 UTC (rev 243409)
@@ -1,3 +1,18 @@
+2019-03-23  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remove build time dependency on Geoclue2
+        https://bugs.webkit.org/show_bug.cgi?id=195994
+
+        Reviewed by Michael Catanzaro.
+
+        Remove old Geoclue implementation.
+
+        * PlatformGTK.cmake:
+        * SourcesGTK.txt:
+        * platform/geoclue/GeolocationProviderGeoclue.cpp: Removed.
+        * platform/geoclue/GeolocationProviderGeoclue.h: Removed.
+        * platform/geoclue/GeolocationProviderGeoclueClient.h: Removed.
+
 2019-03-22  Eric Carlson  <[email protected]>
 
         Flaky AVEncoderBitRateKey symbol not found crash on imported/w3c/web-platform-tests/mediacapture-record/MediaRecorder-constructor.html

Modified: trunk/Source/WebCore/PlatformGTK.cmake (243408 => 243409)


--- trunk/Source/WebCore/PlatformGTK.cmake	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebCore/PlatformGTK.cmake	2019-03-23 10:37:41 UTC (rev 243409)
@@ -21,7 +21,6 @@
     "${WEBCORE_DIR}/editing/atk"
     "${WEBCORE_DIR}/page/gtk"
     "${WEBCORE_DIR}/platform/generic"
-    "${WEBCORE_DIR}/platform/geoclue"
     "${WEBCORE_DIR}/platform/gtk"
     "${WEBCORE_DIR}/platform/graphics/egl"
     "${WEBCORE_DIR}/platform/graphics/glx"
@@ -75,18 +74,6 @@
     rendering/RenderThemeGtk.cpp
 )
 
-if (USE_GEOCLUE)
-    list(APPEND WebCore_SOURCES
-        ${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface.c
-    )
-    execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable dbus_interface geoclue-2.0 OUTPUT_VARIABLE GEOCLUE_DBUS_INTERFACE)
-    add_custom_command(
-         OUTPUT ${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface.c ${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface.h
-         COMMAND gdbus-codegen --interface-prefix org.freedesktop.GeoClue2. --c-namespace Geoclue --generate-c-code ${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface ${GEOCLUE_DBUS_INTERFACE}
-    )
-    set_source_files_properties(${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface.c PROPERTIES COMPILE_FLAGS -Wno-unused-parameter)
-endif ()
-
 list(APPEND WebCore_USER_AGENT_STYLE_SHEETS
     ${WEBCORE_DIR}/css/mediaControlsGtk.css
 )

Modified: trunk/Source/WebCore/SourcesGTK.txt (243408 => 243409)


--- trunk/Source/WebCore/SourcesGTK.txt	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebCore/SourcesGTK.txt	2019-03-23 10:37:41 UTC (rev 243409)
@@ -61,8 +61,6 @@
 
 platform/generic/ScrollAnimatorGeneric.cpp
 
-platform/geoclue/GeolocationProviderGeoclue.cpp
-
 platform/graphics/GLContext.cpp @no-unify
 platform/graphics/GraphicsContext3DPrivate.cpp
 

Modified: trunk/Source/WebCore/platform/gtk/po/ChangeLog (243408 => 243409)


--- trunk/Source/WebCore/platform/gtk/po/ChangeLog	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebCore/platform/gtk/po/ChangeLog	2019-03-23 10:37:41 UTC (rev 243409)
@@ -1,3 +1,12 @@
+2019-03-23  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remove build time dependency on Geoclue2
+        https://bugs.webkit.org/show_bug.cgi?id=195994
+
+        Reviewed by Michael Catanzaro.
+
+        * POTFILES.in: Add GeoclueGeolocationProvider.cpp.
+
 2019-03-21  Carlos Garcia Campos  <[email protected]>
 
         [GTK][WPE] Add API to provide geolocation information

Modified: trunk/Source/WebCore/platform/gtk/po/POTFILES.in (243408 => 243409)


--- trunk/Source/WebCore/platform/gtk/po/POTFILES.in	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebCore/platform/gtk/po/POTFILES.in	2019-03-23 10:37:41 UTC (rev 243409)
@@ -37,6 +37,7 @@
 ../../../WebKit/UIProcess/API/gtk/WebKitWebInspector.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
 ../../../WebKit/UIProcess/API/gtk/WebKitWebViewGtk.cpp
+../../../WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp
 ../../../WebKit/UIProcess/gtk/WebColorPickerGtk.cpp
 ../../../WebKit/UIProcess/gtk/WebKitInspectorWindow.cpp
 ../../../WebKit/UIProcess/WebsiteData/WebsiteDataRecord.cpp

Modified: trunk/Source/WebKit/ChangeLog (243408 => 243409)


--- trunk/Source/WebKit/ChangeLog	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebKit/ChangeLog	2019-03-23 10:37:41 UTC (rev 243409)
@@ -1,3 +1,42 @@
+2019-03-23  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remove build time dependency on Geoclue2
+        https://bugs.webkit.org/show_bug.cgi?id=195994
+
+        Reviewed by Michael Catanzaro.
+
+        Add GeoclueGeolocationProvider class to provide geolocation position updates using Geoclue2 DBus service.
+
+        * PlatformGTK.cmake:
+        * PlatformWPE.cmake:
+        * SourcesGTK.txt:
+        * SourcesWPE.txt:
+        * UIProcess/API/glib/WebKitGeolocationManager.cpp:
+        (_WebKitGeolocationPosition::_WebKitGeolocationPosition):
+        (webkitGeolocationManagerStop):
+        (webkitGeolocationManagerSetEnableHighAccuracy):
+        (webkitGeolocationManagerDispose):
+        (webkit_geolocation_manager_class_init):
+        * UIProcess/geoclue/GeoclueGeolocationProvider.cpp: Added.
+        (WebKit::GeoclueGeolocationProvider::GeoclueGeolocationProvider):
+        (WebKit::GeoclueGeolocationProvider::~GeoclueGeolocationProvider):
+        (WebKit::GeoclueGeolocationProvider::start):
+        (WebKit::GeoclueGeolocationProvider::stop):
+        (WebKit::GeoclueGeolocationProvider::setEnableHighAccuracy):
+        (WebKit::GeoclueGeolocationProvider::destroyManagerLater):
+        (WebKit::GeoclueGeolocationProvider::destroyManager):
+        (WebKit::GeoclueGeolocationProvider::setupManager):
+        (WebKit::GeoclueGeolocationProvider::createClient):
+        (WebKit::GeoclueGeolocationProvider::setupClient):
+        (WebKit::GeoclueGeolocationProvider::startClient):
+        (WebKit::GeoclueGeolocationProvider::stopClient):
+        (WebKit::GeoclueGeolocationProvider::requestAccuracyLevel):
+        (WebKit::GeoclueGeolocationProvider::clientLocationUpdatedCallback):
+        (WebKit::GeoclueGeolocationProvider::createLocation):
+        (WebKit::GeoclueGeolocationProvider::locationUpdated):
+        (WebKit::GeoclueGeolocationProvider::didFail):
+        * UIProcess/geoclue/GeoclueGeolocationProvider.h: Added.
+
 2019-03-22  Simon Fraser  <[email protected]>
 
         Undo collision with r243390.

Modified: trunk/Source/WebKit/PlatformGTK.cmake (243408 => 243409)


--- trunk/Source/WebKit/PlatformGTK.cmake	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebKit/PlatformGTK.cmake	2019-03-23 10:37:41 UTC (rev 243409)
@@ -397,6 +397,7 @@
     "${WEBKIT_DIR}/UIProcess/CoordinatedGraphics"
     "${WEBKIT_DIR}/UIProcess/Network/CustomProtocols/soup"
     "${WEBKIT_DIR}/UIProcess/Plugins/gtk"
+    "${WEBKIT_DIR}/UIProcess/geoclue"
     "${WEBKIT_DIR}/UIProcess/glib"
     "${WEBKIT_DIR}/UIProcess/gstreamer"
     "${WEBKIT_DIR}/UIProcess/gtk"

Modified: trunk/Source/WebKit/PlatformWPE.cmake (243408 => 243409)


--- trunk/Source/WebKit/PlatformWPE.cmake	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebKit/PlatformWPE.cmake	2019-03-23 10:37:41 UTC (rev 243409)
@@ -257,6 +257,7 @@
     "${WEBKIT_DIR}/UIProcess/API/wpe"
     "${WEBKIT_DIR}/UIProcess/CoordinatedGraphics"
     "${WEBKIT_DIR}/UIProcess/Network/CustomProtocols/soup"
+    "${WEBKIT_DIR}/UIProcess/geoclue"
     "${WEBKIT_DIR}/UIProcess/gstreamer"
     "${WEBKIT_DIR}/UIProcess/linux"
     "${WEBKIT_DIR}/UIProcess/soup"

Modified: trunk/Source/WebKit/SourcesGTK.txt (243408 => 243409)


--- trunk/Source/WebKit/SourcesGTK.txt	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebKit/SourcesGTK.txt	2019-03-23 10:37:41 UTC (rev 243409)
@@ -209,6 +209,8 @@
 
 UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp
 
+UIProcess/geoclue/GeoclueGeolocationProvider.cpp
+
 UIProcess/Launcher/glib/ProcessLauncherGLib.cpp @no-unify
 UIProcess/Launcher/glib/BubblewrapLauncher.cpp @no-unify
 UIProcess/Launcher/glib/FlatpakLauncher.cpp @no-unify

Modified: trunk/Source/WebKit/SourcesWPE.txt (243408 => 243409)


--- trunk/Source/WebKit/SourcesWPE.txt	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebKit/SourcesWPE.txt	2019-03-23 10:37:41 UTC (rev 243409)
@@ -183,6 +183,8 @@
 
 UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp
 
+UIProcess/geoclue/GeoclueGeolocationProvider.cpp
+
 UIProcess/glib/WebProcessPoolGLib.cpp
 UIProcess/glib/WebProcessProxyGLib.cpp
 

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp (243408 => 243409)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitGeolocationManager.cpp	2019-03-23 10:37:41 UTC (rev 243409)
@@ -21,6 +21,7 @@
 #include "WebKitGeolocationManager.h"
 
 #include "APIGeolocationProvider.h"
+#include "GeoclueGeolocationProvider.h"
 #include "WebGeolocationPosition.h"
 #include "WebKitGeolocationManagerPrivate.h"
 #include <glib/gi18n-lib.h>
@@ -27,11 +28,6 @@
 #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;
 
@@ -66,14 +62,19 @@
 struct _WebKitGeolocationPosition {
     _WebKitGeolocationPosition() = default;
 
-    _WebKitGeolocationPosition(double latitude, double longitude, double accuracy, Optional<double> timestamp = WTF::nullopt)
+    _WebKitGeolocationPosition(double latitude, double longitude, double accuracy)
     {
-        position.timestamp = timestamp.valueOr(WallTime::now().secondsSinceEpoch().value());
+        position.timestamp = WallTime::now().secondsSinceEpoch().value();
         position.latitude = latitude;
         position.longitude = longitude;
         position.accuracy = accuracy;
     }
 
+    explicit _WebKitGeolocationPosition(GeolocationPosition&& corePosition)
+        : position(WTFMove(corePosition))
+    {
+    }
+
     explicit _WebKitGeolocationPosition(const GeolocationPosition& other)
     {
         position = other;
@@ -228,38 +229,10 @@
     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
+    std::unique_ptr<GeoclueGeolocationProvider> geoclueProvider;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -271,20 +244,23 @@
     gboolean returnValue;
     g_signal_emit(manager, signals[START], 0, &returnValue);
     if (returnValue) {
-#if USE(GEOCLUE)
-        manager->priv->provider = nullptr;
-        manager->priv->providerClient = nullptr;
-#endif
+        manager->priv->geoclueProvider = nullptr;
         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());
+    if (!manager->priv->geoclueProvider) {
+        manager->priv->geoclueProvider = std::make_unique<GeoclueGeolocationProvider>();
+        manager->priv->geoclueProvider->setEnableHighAccuracy(manager->priv->highAccuracyEnabled);
     }
-    manager->priv->provider->startUpdating();
-#endif
+    manager->priv->geoclueProvider->start([manager](GeolocationPosition&& corePosition, Optional<CString> error) {
+        if (error) {
+            webkit_gelocation_manager_failed(manager, error->data());
+            return;
+        }
+
+        WebKitGeolocationPosition position(WTFMove(corePosition));
+        webkit_gelocation_manager_update_position(manager, &position);
+    });
 }
 
 static void webkitGeolocationManagerStop(WebKitGeolocationManager* manager)
@@ -291,10 +267,8 @@
 {
     g_signal_emit(manager, signals[STOP], 0, nullptr);
 
-#if USE(GEOCLUE)
-    if (manager->priv->provider)
-        manager->priv->provider->stopUpdating();
-#endif
+    if (manager->priv->geoclueProvider)
+        manager->priv->geoclueProvider->stop();
 }
 
 static void webkitGeolocationManagerSetEnableHighAccuracy(WebKitGeolocationManager* manager, bool enabled)
@@ -304,10 +278,8 @@
 
     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
+    if (manager->priv->geoclueProvider)
+        manager->priv->geoclueProvider->setEnableHighAccuracy(enabled);
 }
 
 class GeolocationProvider final : public API::GeolocationProvider {

Added: trunk/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp (0 => 243409)


--- trunk/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp	2019-03-23 10:37:41 UTC (rev 243409)
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2019 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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 "GeoclueGeolocationProvider.h"
+
+#include <WebCore/GeolocationPosition.h>
+#include <gio/gio.h>
+#include <glib/gi18n-lib.h>
+
+#if USE(GLIB_EVENT_LOOP)
+#include <wtf/glib/RunLoopSourcePriority.h>
+#endif
+
+namespace WebKit {
+
+GeoclueGeolocationProvider::GeoclueGeolocationProvider()
+    : m_destroyManagerLaterTimer(RunLoop::current(), this, &GeoclueGeolocationProvider::destroyManager)
+{
+#if USE(GLIB_EVENT_LOOP)
+    m_destroyManagerLaterTimer.setPriority(RunLoopSourcePriority::ReleaseUnusedResourcesTimer);
+#endif
+}
+
+GeoclueGeolocationProvider::~GeoclueGeolocationProvider()
+{
+    stop();
+}
+
+void GeoclueGeolocationProvider::start(UpdateNotifyFunction&& updateNotifyFunction)
+{
+    m_destroyManagerLaterTimer.stop();
+    m_updateNotifyFunction = WTFMove(updateNotifyFunction);
+    m_isRunning = true;
+
+    if (!m_manager) {
+        g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,
+            "org.freedesktop.GeoClue2", "/org/freedesktop/GeoClue2/Manager", "org.freedesktop.GeoClue2.Manager", nullptr,
+            [](GObject*, GAsyncResult* result, gpointer userData) {
+                auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
+                GUniqueOutPtr<GError> error;
+                GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
+                if (error) {
+                    provider.didFail(_("Failed to connect to geolocation service"));
+                    return;
+                }
+                provider.setupManager(WTFMove(proxy));
+            }, this);
+        return;
+    }
+
+    startClient();
+}
+
+void GeoclueGeolocationProvider::stop()
+{
+    if (!m_isRunning)
+        return;
+
+    m_isRunning = false;
+    m_updateNotifyFunction = nullptr;
+    g_cancellable_cancel(m_cancellable.get());
+    stopClient();
+    destroyManagerLater();
+}
+
+void GeoclueGeolocationProvider::setEnableHighAccuracy(bool enabled)
+{
+    if (m_isHighAccuracyEnabled == enabled)
+        return;
+
+    requestAccuracyLevel();
+}
+
+void GeoclueGeolocationProvider::destroyManagerLater()
+{
+    if (!m_manager)
+        return;
+
+    if (m_destroyManagerLaterTimer.isActive())
+        return;
+
+    m_destroyManagerLaterTimer.startOneShot(60_s);
+}
+
+void GeoclueGeolocationProvider::destroyManager()
+{
+    ASSERT(!m_isRunning);
+    m_client = nullptr;
+    m_manager = nullptr;
+}
+
+void GeoclueGeolocationProvider::setupManager(GRefPtr<GDBusProxy>&& proxy)
+{
+    m_manager = WTFMove(proxy);
+    if (!m_isRunning) {
+        destroyManagerLater();
+        return;
+    }
+
+    g_dbus_proxy_call(m_manager.get(), "CreateClient", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr,
+        [](GObject* manager, GAsyncResult* result, gpointer userData) {
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
+            GUniqueOutPtr<GError> error;
+            GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(manager), result, &error.outPtr()));
+            if (error) {
+                provider.didFail(_("Failed to connect to geolocation service"));
+                return;
+            }
+            const char* clientPath;
+            g_variant_get(returnValue.get(), "(&o)", &clientPath);
+            provider.createClient(clientPath);
+        }, this);
+}
+
+void GeoclueGeolocationProvider::createClient(const char* clientPath)
+{
+    if (!m_isRunning) {
+        destroyManagerLater();
+        return;
+    }
+
+    g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,
+        "org.freedesktop.GeoClue2", clientPath, "org.freedesktop.GeoClue2.Client", nullptr,
+        [](GObject*, GAsyncResult* result, gpointer userData) {
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
+            GUniqueOutPtr<GError> error;
+            GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
+            if (error) {
+                provider.didFail(_("Failed to connect to geolocation service"));
+                return;
+            }
+            provider.setupClient(WTFMove(proxy));
+        }, this);
+}
+
+void GeoclueGeolocationProvider::setupClient(GRefPtr<GDBusProxy>&& proxy)
+{
+    m_client = WTFMove(proxy);
+    if (!m_isRunning) {
+        destroyManagerLater();
+        return;
+    }
+
+    // Geoclue2 requires the client to provide a desktop ID for security
+    // reasons, which should identify the application requesting the location.
+    // We use the application ID configured for the default GApplication, and
+    // also fallback to our old behavior of using g_get_prgname().
+    const char* applicationID = nullptr;
+    if (auto* defaultApplication = g_application_get_default())
+        applicationID = g_application_get_application_id(defaultApplication);
+    if (!applicationID)
+        applicationID = g_get_prgname();
+    g_dbus_proxy_call(m_client.get(), "org.freedesktop.DBus.Properties.Set",
+        g_variant_new("(ssv)", "org.freedesktop.GeoClue2.Client", "DesktopId", g_variant_new_string(applicationID)),
+        G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr);
+
+    requestAccuracyLevel();
+
+    startClient();
+}
+
+void GeoclueGeolocationProvider::startClient()
+{
+    if (!m_client)
+        return;
+
+    g_signal_connect(m_client.get(), "g-signal", G_CALLBACK(clientLocationUpdatedCallback), this);
+
+    m_cancellable = adoptGRef(g_cancellable_new());
+    g_dbus_proxy_call(m_client.get(), "Start", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable.get(),
+        [](GObject* client, GAsyncResult* result, gpointer userData) {
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
+            GUniqueOutPtr<GError> error;
+            GRefPtr<GVariant> returnValue = adoptGRef(g_dbus_proxy_call_finish(G_DBUS_PROXY(client), result, &error.outPtr()));
+            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                return;
+
+            if (error) {
+                provider.didFail(_("Failed to determine position from geolocation service"));
+                return;
+            }
+        }, this);
+}
+
+void GeoclueGeolocationProvider::stopClient()
+{
+    if (!m_client)
+        return;
+
+    g_signal_handlers_disconnect_matched(m_client.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
+    m_cancellable = nullptr;
+    g_dbus_proxy_call(m_client.get(), "Stop", nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr);
+}
+
+void GeoclueGeolocationProvider::requestAccuracyLevel()
+{
+    if (!m_client)
+        return;
+
+    // GeoclueAccuracyLevelCity = 4, GeoclueAccuracyLevelExact = 8.
+    unsigned accuracy = m_isHighAccuracyEnabled ? 8 : 4;
+    g_dbus_proxy_call(m_client.get(), "org.freedesktop.DBus.Properties.Set",
+        g_variant_new("(ssv)", "org.freedesktop.GeoClue2.Client", "RequestedAccuracyLevel", g_variant_new_uint32(accuracy)),
+        G_DBUS_CALL_FLAGS_NONE, -1, nullptr, nullptr, nullptr);
+}
+
+void GeoclueGeolocationProvider::clientLocationUpdatedCallback(GDBusProxy* client, gchar*, gchar* signal, GVariant* parameters, gpointer userData)
+{
+    if (g_strcmp0(signal, "LocationUpdated"))
+        return;
+
+    const char* locationPath;
+    g_variant_get(parameters, "(o&o)", nullptr, &locationPath);
+    auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
+    provider.createLocation(locationPath);
+}
+
+void GeoclueGeolocationProvider::createLocation(const char* locationPath)
+{
+    g_dbus_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, nullptr,
+        "org.freedesktop.GeoClue2", locationPath, "org.freedesktop.GeoClue2.Location", m_cancellable.get(),
+        [](GObject*, GAsyncResult* result, gpointer userData) {
+            auto& provider = *static_cast<GeoclueGeolocationProvider*>(userData);
+            GUniqueOutPtr<GError> error;
+            GRefPtr<GDBusProxy> proxy = adoptGRef(g_dbus_proxy_new_for_bus_finish(result, &error.outPtr()));
+            if (g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                return;
+
+            if (error) {
+                provider.didFail(_("Failed to determine position from geolocation service"));
+                return;
+            }
+            provider.locationUpdated(WTFMove(proxy));
+        }, this);
+}
+
+void GeoclueGeolocationProvider::locationUpdated(GRefPtr<GDBusProxy>&& proxy)
+{
+    WebCore::GeolocationPosition position;
+    GRefPtr<GVariant> property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Latitude"));
+    position.latitude = g_variant_get_double(property.get());
+    property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Longitude"));
+    position.longitude = g_variant_get_double(property.get());
+    property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Accuracy"));
+    position.accuracy = g_variant_get_double(property.get());
+    property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Altitude"));
+    position.altitude = g_variant_get_double(property.get());
+    property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Speed"));
+    position.speed = g_variant_get_double(property.get());
+    property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Heading"));
+    position.heading = g_variant_get_double(property.get());
+    property = adoptGRef(g_dbus_proxy_get_cached_property(proxy.get(), "Timestamp"));
+    guint64 timestamp;
+    g_variant_get(property.get(), "(tt)", &timestamp, nullptr);
+    position.timestamp = static_cast<double>(timestamp);
+    m_updateNotifyFunction(WTFMove(position), WTF::nullopt);
+}
+
+void GeoclueGeolocationProvider::didFail(CString errorMessage)
+{
+    m_updateNotifyFunction({ }, errorMessage);
+}
+
+} // namespace WebKit

Added: trunk/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h (0 => 243409)


--- trunk/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h	2019-03-23 10:37:41 UTC (rev 243409)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2019 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#pragma once
+
+#include <wtf/Noncopyable.h>
+#include <wtf/RunLoop.h>
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+typedef struct _GDBusProxy GDBusProxy;
+
+namespace WebCore {
+class GeolocationPosition;
+}
+
+namespace WebKit {
+
+class GeoclueGeolocationProvider {
+    WTF_MAKE_NONCOPYABLE(GeoclueGeolocationProvider); WTF_MAKE_FAST_ALLOCATED;
+public:
+    GeoclueGeolocationProvider();
+    ~GeoclueGeolocationProvider();
+
+    using UpdateNotifyFunction = Function<void(WebCore::GeolocationPosition&&, Optional<CString> error)>;
+    void start(UpdateNotifyFunction&&);
+    void stop();
+    void setEnableHighAccuracy(bool);
+
+private:
+    void destroyManager();
+    void destroyManagerLater();
+
+    void setupManager(GRefPtr<GDBusProxy>&&);
+    void createClient(const char*);
+    void setupClient(GRefPtr<GDBusProxy>&&);
+    void requestAccuracyLevel();
+    void createLocation(const char*);
+    void locationUpdated(GRefPtr<GDBusProxy>&&);
+    void didFail(CString);
+
+    void startClient();
+    void stopClient();
+
+    static void clientLocationUpdatedCallback(GDBusProxy*, gchar*, gchar*, GVariant*, gpointer);
+
+    bool m_isRunning { false };
+    bool m_isHighAccuracyEnabled { false };
+    GRefPtr<GDBusProxy> m_manager;
+    GRefPtr<GDBusProxy> m_client;
+    GRefPtr<GCancellable> m_cancellable;
+    UpdateNotifyFunction m_updateNotifyFunction;
+    RunLoop::Timer<GeoclueGeolocationProvider> m_destroyManagerLaterTimer;
+};
+
+} // namespace WebKit

Deleted: trunk/Source/cmake/FindGeoClue2.cmake (243408 => 243409)


--- trunk/Source/cmake/FindGeoClue2.cmake	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/cmake/FindGeoClue2.cmake	2019-03-23 10:37:41 UTC (rev 243409)
@@ -1,50 +0,0 @@
-# - Try to find GeoClue 2
-# Once done, this will define
-#
-#  GEOCLUE2_FOUND - system has GeoClue 2.
-#
-# Copyright (C) 2012 Raphael Kubo da Costa <[email protected]>
-# Copyright (C) 2013, 2014 Igalia S.L.
-# Copyright (C) 2014 Samsung Electronics. All rights reserved.
-#
-# 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 THE COPYRIGHT HOLDER 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 THE COPYRIGHT HOLDER 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.
-
-find_package(PkgConfig)
-pkg_check_modules(GEOCLUE2 geoclue-2.0)
-
-set(VERSION_OK FALSE)
-if (GEOCLUE2_VERSION)
-    set(VERSION_OK TRUE)
-    if (GeoClue2_FIND_VERSION_EXACT)
-        if (NOT("${GeoClue2_FIND_VERSION}" VERSION_EQUAL "${GEOCLUE2_VERSION}"))
-            set(VERSION_OK FALSE)
-        endif ()
-    else ()
-        if ("${GEOCLUE2_VERSION}" VERSION_LESS "${GeoClue2_FIND_VERSION}")
-            set(VERSION_OK FALSE)
-        endif ()
-    endif ()
-endif ()
-
-include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(GeoClue2 REQUIRED_VARS VERSION_OK
-                                  FOUND_VAR GEOCLUE2_FOUND)

Modified: trunk/Source/cmake/OptionsGTK.cmake (243408 => 243409)


--- trunk/Source/cmake/OptionsGTK.cmake	2019-03-23 07:58:07 UTC (rev 243408)
+++ trunk/Source/cmake/OptionsGTK.cmake	2019-03-23 10:37:41 UTC (rev 243409)
@@ -80,7 +80,6 @@
 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)
@@ -222,13 +221,6 @@
     endif ()
 endif ()
 
-if (USE_GEOCLUE)
-    find_package(GeoClue2 2.1.5)
-    if (NOT GEOCLUE2_FOUND)
-        message(FATAL_ERROR "Geoclue is needed for USE_GEOCLUE.")
-    endif ()
-endif ()
-
 if (ENABLE_INTROSPECTION)
     find_package(GObjectIntrospection)
     if (NOT INTROSPECTION_FOUND)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to