[GTK] Remove build time dependency on Geoclue2
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 Mar 2019 10:37:41 +0000 (10:37 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 23 Mar 2019 10:37:41 +0000 (10:37 +0000)
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.

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

19 files changed:
ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/SourcesGTK.txt
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp [deleted file]
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.h [deleted file]
Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h [deleted file]
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
Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp [new file with mode: 0644]
Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h [new file with mode: 0644]
Source/cmake/FindGeoClue2.cmake [deleted file]
Source/cmake/OptionsGTK.cmake

index def4eaf..256243a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2019-03-23  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [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  <cgarcia@igalia.com>
 
         [GTK][WPE] Add API to provide geolocation information
index b513729..dc82166 100644 (file)
@@ -1,3 +1,18 @@
+2019-03-23  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [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  <eric.carlson@apple.com>
 
         Flaky AVEncoderBitRateKey symbol not found crash on imported/w3c/web-platform-tests/mediacapture-record/MediaRecorder-constructor.html
index ba49231..03d81aa 100644 (file)
@@ -21,7 +21,6 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES
     "${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 @@ list(APPEND WebCorePlatformGTK_SOURCES
     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
 )
index 15a0ba8..a79d4e7 100644 (file)
@@ -61,8 +61,6 @@ platform/UserAgentQuirks.cpp
 
 platform/generic/ScrollAnimatorGeneric.cpp
 
-platform/geoclue/GeolocationProviderGeoclue.cpp
-
 platform/graphics/GLContext.cpp @no-unify
 platform/graphics/GraphicsContext3DPrivate.cpp
 
diff --git a/Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp b/Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp
deleted file mode 100644 (file)
index 2deaf76..0000000
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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 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 "GeolocationProviderGeoclue.h"
-
-#if USE(GEOCLUE)
-
-#include <wtf/glib/GLibUtilities.h>
-#include <wtf/glib/GUniquePtr.h>
-#include <wtf/text/CString.h>
-
-const char* gGeoclueBusName = "org.freedesktop.GeoClue2";
-const char* gGeoclueManagerPath = "/org/freedesktop/GeoClue2/Manager";
-
-namespace WebCore {
-
-typedef enum {
-    GeoclueAccuracyLevelCountry = 1,
-    GeoclueAccuracyLevelCity = 4,
-    GeoclueAccuracyLevelStreet = 6,
-    GeoclueAccuracyLevelExact = 8,
-} GeoclueAccuracyLevel;
-
-GeolocationProviderGeoclue::GeolocationProviderGeoclue(GeolocationProviderGeoclueClient* client)
-    : m_client(client)
-    , m_latitude(0)
-    , m_longitude(0)
-    , m_altitude(0)
-    , m_accuracy(0)
-    , m_altitudeAccuracy(0)
-    , m_timestamp(0)
-    , m_enableHighAccuracy(false)
-    , m_isUpdating(false)
-{
-    ASSERT(m_client);
-}
-
-GeolocationProviderGeoclue::~GeolocationProviderGeoclue()
-{
-    stopUpdating();
-}
-
-void GeolocationProviderGeoclue::startUpdating()
-{
-    m_isUpdating = true;
-
-    if (!m_managerProxy) {
-        geoclue_manager_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, gGeoclueBusName, gGeoclueManagerPath, nullptr,
-            reinterpret_cast<GAsyncReadyCallback>(createGeoclueManagerProxyCallback), this);
-        return;
-    }
-
-    geoclue_manager_call_get_client(m_managerProxy.get(), nullptr, reinterpret_cast<GAsyncReadyCallback>(getGeoclueClientCallback), this);
-}
-
-void GeolocationProviderGeoclue::stopUpdating()
-{
-    if (m_clientProxy) {
-        geoclue_client_call_stop(m_clientProxy.get(), nullptr, nullptr, nullptr);
-        g_signal_handlers_disconnect_by_func(m_clientProxy.get(), reinterpret_cast<gpointer>(locationUpdatedCallback), this);
-        m_clientProxy = nullptr;
-    }
-    m_isUpdating = false;
-}
-
-void GeolocationProviderGeoclue::setEnableHighAccuracy(bool enable)
-{
-    if (m_enableHighAccuracy == enable)
-        return;
-
-    m_enableHighAccuracy = enable;
-
-    // If we're already updating we should report the new requirements in order
-    // to change to a more suitable provider if needed. If not, return.
-    if (!m_isUpdating)
-        return;
-
-    updateClientRequirements();
-}
-
-void GeolocationProviderGeoclue::createGeoclueManagerProxyCallback(GObject*, GAsyncResult* result, GeolocationProviderGeoclue* provider)
-{
-    GUniqueOutPtr<GError> error;
-    provider->m_managerProxy = adoptGRef(geoclue_manager_proxy_new_for_bus_finish(result, &error.outPtr()));
-    if (error) {
-        provider->errorOccurred(error->message);
-        return;
-    }
-
-    geoclue_manager_call_get_client(provider->m_managerProxy.get(), nullptr, reinterpret_cast<GAsyncReadyCallback>(getGeoclueClientCallback), provider);
-}
-
-void GeolocationProviderGeoclue::getGeoclueClientCallback(GObject* sourceObject, GAsyncResult* result, GeolocationProviderGeoclue* provider)
-{
-    GUniqueOutPtr<GError> error;
-    GUniqueOutPtr<gchar> path;
-    if (!geoclue_manager_call_get_client_finish(GEOCLUE_MANAGER(sourceObject), &path.outPtr(), result, &error.outPtr())) {
-        provider->errorOccurred(error->message);
-        return;
-    }
-
-    geoclue_client_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, gGeoclueBusName, path.get(), nullptr,
-        reinterpret_cast<GAsyncReadyCallback>(createGeoclueClientProxyCallback), provider);
-}
-
-void GeolocationProviderGeoclue::createGeoclueClientProxyCallback(GObject*, GAsyncResult* result, GeolocationProviderGeoclue* provider)
-{
-    GUniqueOutPtr<GError> error;
-    provider->m_clientProxy = adoptGRef(geoclue_client_proxy_new_for_bus_finish(result, &error.outPtr()));
-    if (error) {
-        provider->errorOccurred(error->message);
-        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* appId = nullptr;
-    GApplication* defaultApp = g_application_get_default();
-    if (defaultApp)
-        appId = g_application_get_application_id(defaultApp);
-    if (!appId)
-        appId = g_get_prgname();
-
-    geoclue_client_set_desktop_id(provider->m_clientProxy.get(), appId);
-
-    provider->startGeoclueClient();
-}
-
-void GeolocationProviderGeoclue::startClientCallback(GObject* sourceObject, GAsyncResult* result, GeolocationProviderGeoclue* provider)
-{
-    GUniqueOutPtr<GError> error;
-    if (!geoclue_client_call_start_finish(GEOCLUE_CLIENT(sourceObject), result, &error.outPtr()))
-        static_cast<GeolocationProviderGeoclue*>(provider)->errorOccurred(error->message);
-}
-
-void GeolocationProviderGeoclue::locationUpdatedCallback(GeoclueClient*, const gchar*, const gchar* newPath, GeolocationProviderGeoclue* provider)
-{
-    geoclue_location_proxy_new_for_bus(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, gGeoclueBusName, newPath, nullptr,
-        reinterpret_cast<GAsyncReadyCallback>(createLocationProxyCallback), provider);
-}
-
-void GeolocationProviderGeoclue::createLocationProxyCallback(GObject*, GAsyncResult* result, GeolocationProviderGeoclue* provider)
-{
-    GUniqueOutPtr<GError> error;
-    GRefPtr<GeoclueLocation> locationProxy = adoptGRef(geoclue_location_proxy_new_for_bus_finish(result, &error.outPtr()));
-    if (error) {
-        provider->errorOccurred(error->message);
-        return;
-    }
-    provider->updateLocation(locationProxy.get());
-}
-
-void GeolocationProviderGeoclue::startGeoclueClient()
-{
-    // Set the requirement for the client.
-    updateClientRequirements();
-
-    g_signal_connect(m_clientProxy.get(), "location-updated", G_CALLBACK(locationUpdatedCallback), this);
-    geoclue_client_call_start(m_clientProxy.get(), nullptr, reinterpret_cast<GAsyncReadyCallback>(startClientCallback), this);
-}
-
-void GeolocationProviderGeoclue::updateLocation(GeoclueLocation* locationProxy)
-{
-    GTimeVal timeValue;
-    g_get_current_time(&timeValue);
-    m_timestamp = timeValue.tv_sec;
-    m_latitude = geoclue_location_get_latitude(locationProxy);
-    m_longitude = geoclue_location_get_longitude(locationProxy);
-    m_accuracy = geoclue_location_get_accuracy(locationProxy);
-    m_client->notifyPositionChanged(m_timestamp, m_latitude, m_longitude, m_altitude, m_accuracy, m_altitudeAccuracy);
-}
-
-void GeolocationProviderGeoclue::errorOccurred(const char* message)
-{
-    m_isUpdating = false;
-    m_client->notifyErrorOccurred(message);
-}
-
-void GeolocationProviderGeoclue::updateClientRequirements()
-{
-    if (!m_clientProxy)
-        return;
-
-    GeoclueAccuracyLevel accuracyLevel = m_enableHighAccuracy ? GeoclueAccuracyLevelExact : GeoclueAccuracyLevelCity;
-    geoclue_client_set_requested_accuracy_level(m_clientProxy.get(), accuracyLevel);
-}
-
-} // namespace WebCore
-
-#endif // USE(GEOCLUE)
diff --git a/Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.h b/Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.h
deleted file mode 100644 (file)
index 224b791..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- * Copyright (C) 2014 Samsung Electronics. All rights reserved.
- *
- * 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 USE(GEOCLUE)
-
-#include "GeolocationProviderGeoclueClient.h"
-#include <wtf/glib/GRefPtr.h>
-
-#include "Geoclue2Interface.h"
-
-namespace WebCore {
-
-class GeolocationProviderGeoclue {
-public:
-    GeolocationProviderGeoclue(GeolocationProviderGeoclueClient*);
-    ~GeolocationProviderGeoclue();
-
-    void startUpdating();
-    void stopUpdating();
-    void setEnableHighAccuracy(bool);
-
-private:
-    static void createGeoclueManagerProxyCallback(GObject*, GAsyncResult*, GeolocationProviderGeoclue*);
-    static void getGeoclueClientCallback(GObject*, GAsyncResult*, GeolocationProviderGeoclue*);
-    static void createGeoclueClientProxyCallback(GObject*, GAsyncResult*, GeolocationProviderGeoclue*);
-    static void startClientCallback(GObject*, GAsyncResult*, GeolocationProviderGeoclue*);
-    static void locationUpdatedCallback(GeoclueClient*, const gchar*, const gchar*, GeolocationProviderGeoclue*);
-    static void createLocationProxyCallback(GObject*, GAsyncResult*, GeolocationProviderGeoclue*);
-
-    void startGeoclueClient();
-    void updateLocation(GeoclueLocation*);
-
-    void errorOccurred(const char*);
-    void updateClientRequirements();
-
-    GeolocationProviderGeoclueClient* m_client;
-
-    GRefPtr<GeoclueManager> m_managerProxy;
-    GRefPtr<GeoclueClient> m_clientProxy;
-
-    double m_latitude;
-    double m_longitude;
-    double m_altitude;
-    double m_accuracy;
-    double m_altitudeAccuracy;
-    int m_timestamp;
-
-    bool m_enableHighAccuracy;
-    bool m_isUpdating;
-};
-
-} // namespace WebCore
-
-#endif // USE(GEOCLUE)
diff --git a/Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h b/Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h
deleted file mode 100644 (file)
index 68de276..0000000
+++ /dev/null
@@ -1,34 +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 USE(GEOCLUE)
-
-namespace WebCore {
-
-class GeolocationProviderGeoclueClient {
-public:
-    virtual void notifyPositionChanged(int timestamp, double latitude, double longitude, double altitude, double accuracy, double altitudeAccuracy) = 0;
-    virtual void notifyErrorOccurred(const char* message) = 0;
-};
-
-} // namespace WebCore
-
-#endif // USE(GEOCLUE)
index 794bf17..30b6d1e 100644 (file)
@@ -1,3 +1,12 @@
+2019-03-23  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [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  <cgarcia@igalia.com>
 
         [GTK][WPE] Add API to provide geolocation information
index f493200..a329a5b 100644 (file)
@@ -37,6 +37,7 @@ LocalizedStringsGtk.cpp
 ../../../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
index 91d5352..2557c44 100644 (file)
@@ -1,3 +1,42 @@
+2019-03-23  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [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  <simon.fraser@apple.com>
 
         Undo collision with r243390.
index 76eb5e9..3041431 100644 (file)
@@ -397,6 +397,7 @@ list(APPEND WebKit_INCLUDE_DIRECTORIES
     "${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"
index 373ae0b..1d419ac 100644 (file)
@@ -257,6 +257,7 @@ list(APPEND WebKit_INCLUDE_DIRECTORIES
     "${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"
index 53522d0..ccc43a0 100644 (file)
@@ -209,6 +209,8 @@ UIProcess/Automation/gtk/WebAutomationSessionGtk.cpp
 
 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
index 5fc1ca5..0bf5416 100644 (file)
@@ -183,6 +183,8 @@ UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp
 
 UIProcess/CoordinatedGraphics/DrawingAreaProxyCoordinatedGraphics.cpp
 
+UIProcess/geoclue/GeoclueGeolocationProvider.cpp
+
 UIProcess/glib/WebProcessPoolGLib.cpp
 UIProcess/glib/WebProcessProxyGLib.cpp
 
index e791b3e..1ee7d2f 100644 (file)
 #include "WebKitGeolocationManager.h"
 
 #include "APIGeolocationProvider.h"
+#include "GeoclueGeolocationProvider.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;
 
@@ -66,14 +62,19 @@ enum {
 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 @@ void webkit_geolocation_position_set_speed(WebKitGeolocationPosition* 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
+    std::unique_ptr<GeoclueGeolocationProvider> geoclueProvider;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -271,30 +244,31 @@ 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
+        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)
 {
     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 @@ static void webkitGeolocationManagerSetEnableHighAccuracy(WebKitGeolocationManag
 
     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 {
diff --git a/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp b/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.cpp
new file mode 100644 (file)
index 0000000..8287464
--- /dev/null
@@ -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
diff --git a/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h b/Source/WebKit/UIProcess/geoclue/GeoclueGeolocationProvider.h
new file mode 100644 (file)
index 0000000..5711e2a
--- /dev/null
@@ -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
diff --git a/Source/cmake/FindGeoClue2.cmake b/Source/cmake/FindGeoClue2.cmake
deleted file mode 100644 (file)
index 84179cd..0000000
+++ /dev/null
@@ -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 <rakuco@webkit.org>
-# 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)
index f6cfeb6..e6c5f7d 100644 (file)
@@ -80,7 +80,6 @@ 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)
@@ -222,13 +221,6 @@ if (USE_LIBSECRET)
     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)