[GTK] Add support for Geoclue2
authormario.prada@samsung.com <mario.prada@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Mar 2014 00:23:20 +0000 (00:23 +0000)
committermario.prada@samsung.com <mario.prada@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 11 Mar 2014 00:23:20 +0000 (00:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=120185

Reviewed by Carlos Garcia Campos.

.:

Add support for Geoclue2 using autotools.

* Source/autotools/FindDependencies.m4: Add support for handling
both Geoclue 1.0 and 2.0.
* Source/autotools/PrintBuildConfiguration.m4: Print the version
of geoclue that is being used.
* Source/autotools/SetupAutoconfHeader.m4: Define GEOCLUE_API_VERSION_2.
* Source/autotools/SetupAutomake.m4: Likewise, for AM_CONDITIONAL.
* Source/autotools/Versions.m4: Added minimum required version for Geoclue2.

Add support for Geoclue2 using CMake.

* Source/cmake/FindGeoClue2.cmake: Added.
* Source/cmake/OptionsGTK.cmake:  Add support for handling Geoclue 1.0 and 2.0.
* Source/cmakeconfig.h.cmake: Define WTF_USE_GEOCLUE2.

Source/WebCore:

Implement a new geolocation provider based on Geoclue2, which will only
be used if a good enough version of Geoclue2 is found  at configure time.

* GNUmakefile.am: Generate C-API for accessing the D-Bus API
provided by Geoclue2, and place it in DerivedSources.
* GNUmakefile.list.am: Add GeolocationProviderGeoclue2.cpp, and
include the generated proxy files when using Geoclue2.
* PlatformGTK.cmake: Likewise, for CMake based builds.
* platform/geoclue/GeolocationProviderGeoclue.h: Modified to
accomodate the needs both for Geoclue and Geoclue2 providers.
* platform/geoclue/GeolocationProviderGeoclue1.cpp: Renamed from Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp.
(GeolocationProviderGeoclue::getPositionCallback):
(GeolocationProviderGeoclue::positionChangedCallback):
(GeolocationProviderGeoclue::createGeocluePositionCallback):
(GeolocationProviderGeoclue::geoclueClientSetRequirementsCallback):
(GeolocationProviderGeoclue::createGeoclueClientCallback):
(GeolocationProviderGeoclue::GeolocationProviderGeoclue):
(GeolocationProviderGeoclue::~GeolocationProviderGeoclue):
(GeolocationProviderGeoclue::startUpdating):
(GeolocationProviderGeoclue::stopUpdating):
(GeolocationProviderGeoclue::setEnableHighAccuracy):
(GeolocationProviderGeoclue::initializeGeoclueClient):
(GeolocationProviderGeoclue::initializeGeocluePosition):
(GeolocationProviderGeoclue::updateClientRequirements):
(GeolocationProviderGeoclue::positionChanged):
(GeolocationProviderGeoclue::errorOccurred):
* platform/geoclue/GeolocationProviderGeoclue2.cpp: Added.
(GeolocationProviderGeoclue::GeolocationProviderGeoclue):
(GeolocationProviderGeoclue::~GeolocationProviderGeoclue):
(GeolocationProviderGeoclue::startUpdating):
(GeolocationProviderGeoclue::stopUpdating):
(GeolocationProviderGeoclue::setEnableHighAccuracy):
(GeolocationProviderGeoclue::createGeoclueManagerProxyCallback):
(GeolocationProviderGeoclue::getGeoclueClientCallback):
(GeolocationProviderGeoclue::createGeoclueClientProxyCallback):
(GeolocationProviderGeoclue::startClientCallback):
(GeolocationProviderGeoclue::locationUpdatedCallback):
(GeolocationProviderGeoclue::createLocationProxyCallback):
(GeolocationProviderGeoclue::startGeoclueClient):
(GeolocationProviderGeoclue::updateLocation):
(GeolocationProviderGeoclue::errorOccurred):
(GeolocationProviderGeoclue::updateClientRequirements):

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

16 files changed:
ChangeLog
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.am
Source/WebCore/GNUmakefile.list.am
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.h
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue1.cpp [moved from Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp with 82% similarity]
Source/WebCore/platform/geoclue/GeolocationProviderGeoclue2.cpp [new file with mode: 0644]
Source/autotools/FindDependencies.m4
Source/autotools/PrintBuildConfiguration.m4
Source/autotools/SetupAutoconfHeader.m4
Source/autotools/SetupAutomake.m4
Source/autotools/Versions.m4
Source/cmake/FindGeoClue2.cmake [new file with mode: 0644]
Source/cmake/OptionsGTK.cmake
Source/cmakeconfig.h.cmake

index 9ef8c79..bcd3299 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2014-03-10  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        [GTK] Add support for Geoclue2
+        https://bugs.webkit.org/show_bug.cgi?id=120185
+
+        Reviewed by Carlos Garcia Campos.
+
+        Patch by Anton Obzhirov <a.obzhirov@samsung.com> and Mario Sanchez Prada <mario.prada@samsung.com>
+
+        Add support for Geoclue2 using autotools.
+
+        * Source/autotools/FindDependencies.m4: Add support for handling
+        both Geoclue 1.0 and 2.0.
+        * Source/autotools/PrintBuildConfiguration.m4: Print the version
+        of geoclue that is being used.
+        * Source/autotools/SetupAutoconfHeader.m4: Define GEOCLUE_API_VERSION_2.
+        * Source/autotools/SetupAutomake.m4: Likewise, for AM_CONDITIONAL.
+        * Source/autotools/Versions.m4: Added minimum required version for Geoclue2.
+
+        Add support for Geoclue2 using CMake.
+
+        * Source/cmake/FindGeoClue2.cmake: Added.
+        * Source/cmake/OptionsGTK.cmake:  Add support for handling Geoclue 1.0 and 2.0.
+        * Source/cmakeconfig.h.cmake: Define WTF_USE_GEOCLUE2.
+
 2014-03-10  Martin Robinson  <mrobinson@igalia.com>
 
         [GTK][CMAKE] gtk-doc HTML documentation is generated by default when building with CMake
index 9466fd8..d6a9c1c 100644 (file)
@@ -1,3 +1,55 @@
+2014-03-10  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        [GTK] Add support for Geoclue2
+        https://bugs.webkit.org/show_bug.cgi?id=120185
+
+        Reviewed by Carlos Garcia Campos.
+
+        Patch by Anton Obzhirov <a.obzhirov@samsung.com> and Mario Sanchez Prada <mario.prada@samsung.com>
+
+        Implement a new geolocation provider based on Geoclue2, which will only
+        be used if a good enough version of Geoclue2 is found  at configure time.
+
+        * GNUmakefile.am: Generate C-API for accessing the D-Bus API
+        provided by Geoclue2, and place it in DerivedSources.
+        * GNUmakefile.list.am: Add GeolocationProviderGeoclue2.cpp, and
+        include the generated proxy files when using Geoclue2.
+        * PlatformGTK.cmake: Likewise, for CMake based builds.
+        * platform/geoclue/GeolocationProviderGeoclue.h: Modified to
+        accomodate the needs both for Geoclue and Geoclue2 providers.
+        * platform/geoclue/GeolocationProviderGeoclue1.cpp: Renamed from Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp.
+        (GeolocationProviderGeoclue::getPositionCallback):
+        (GeolocationProviderGeoclue::positionChangedCallback):
+        (GeolocationProviderGeoclue::createGeocluePositionCallback):
+        (GeolocationProviderGeoclue::geoclueClientSetRequirementsCallback):
+        (GeolocationProviderGeoclue::createGeoclueClientCallback):
+        (GeolocationProviderGeoclue::GeolocationProviderGeoclue):
+        (GeolocationProviderGeoclue::~GeolocationProviderGeoclue):
+        (GeolocationProviderGeoclue::startUpdating):
+        (GeolocationProviderGeoclue::stopUpdating):
+        (GeolocationProviderGeoclue::setEnableHighAccuracy):
+        (GeolocationProviderGeoclue::initializeGeoclueClient):
+        (GeolocationProviderGeoclue::initializeGeocluePosition):
+        (GeolocationProviderGeoclue::updateClientRequirements):
+        (GeolocationProviderGeoclue::positionChanged):
+        (GeolocationProviderGeoclue::errorOccurred):
+        * platform/geoclue/GeolocationProviderGeoclue2.cpp: Added.
+        (GeolocationProviderGeoclue::GeolocationProviderGeoclue):
+        (GeolocationProviderGeoclue::~GeolocationProviderGeoclue):
+        (GeolocationProviderGeoclue::startUpdating):
+        (GeolocationProviderGeoclue::stopUpdating):
+        (GeolocationProviderGeoclue::setEnableHighAccuracy):
+        (GeolocationProviderGeoclue::createGeoclueManagerProxyCallback):
+        (GeolocationProviderGeoclue::getGeoclueClientCallback):
+        (GeolocationProviderGeoclue::createGeoclueClientProxyCallback):
+        (GeolocationProviderGeoclue::startClientCallback):
+        (GeolocationProviderGeoclue::locationUpdatedCallback):
+        (GeolocationProviderGeoclue::createLocationProxyCallback):
+        (GeolocationProviderGeoclue::startGeoclueClient):
+        (GeolocationProviderGeoclue::updateLocation):
+        (GeolocationProviderGeoclue::errorOccurred):
+        (GeolocationProviderGeoclue::updateClientRequirements):
+
 2014-03-10  Brent Fulgham  <bfulgham@apple.com>
 
         Unreviewed Windows Build Fix.
index 51d172c..40df2c9 100644 (file)
@@ -386,6 +386,12 @@ audio_DATA = $(WebCore)/platform/audio/resources/Composite.wav
 dist_audio_DATA = $(audio_DATA)
 endif  # END ENABLE_WEB_AUDIO
 
+if USE_GEOCLUE2
+DerivedSources/Platform/Geoclue2Interface.c: DerivedSources/Platform/Geoclue2Interface.h
+DerivedSources/Platform/Geoclue2Interface.h:
+       $(AM_V_GEN)gdbus-codegen --interface-prefix org.freedesktop.GeoClue2. --c-namespace Geoclue --generate-c-code DerivedSources/Platform/Geoclue2Interface $(GEOCLUE_DBUS_INTERFACE)
+endif
+
 IDL_PATH := \
     $(WebCore)/Modules/battery \
     $(WebCore)/Modules/gamepad \
index 10b7440..824152b 100644 (file)
@@ -875,6 +875,12 @@ platform_built_sources += \
        DerivedSources/Platform/WebKitFontFamilyNames.cpp \
        DerivedSources/Platform/WebKitFontFamilyNames.h
 
+if USE_GEOCLUE2
+platform_built_sources += \
+       DerivedSources/Platform/Geoclue2Interface.h \
+       DerivedSources/Platform/Geoclue2Interface.c
+endif
+
 # These files need to be part of WebCore otherwise they cause undefined
 # symbols havoc
 webcore_built_sources += \
@@ -5575,7 +5581,8 @@ platform_sources += \
        Source/WebCore/platform/audio/ZeroPole.cpp \
        Source/WebCore/platform/audio/ZeroPole.h \
        Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.h \
-       Source/WebCore/platform/geoclue/GeolocationProviderGeoclue.cpp \
+       Source/WebCore/platform/geoclue/GeolocationProviderGeoclue1.cpp \
+       Source/WebCore/platform/geoclue/GeolocationProviderGeoclue2.cpp \
        Source/WebCore/platform/geoclue/GeolocationProviderGeoclueClient.h \
        Source/WebCore/platform/glib/BatteryProviderUPowerClient.h \
        Source/WebCore/platform/glib/BatteryProviderUPower.cpp \
index 74a4dfa..9e4fb07 100644 (file)
@@ -40,7 +40,8 @@ list(APPEND WebCore_SOURCES
     platform/audio/gstreamer/FFTFrameGStreamer.cpp
     platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp
 
-    platform/geoclue/GeolocationProviderGeoclue.cpp
+    platform/geoclue/GeolocationProviderGeoclue1.cpp
+    platform/geoclue/GeolocationProviderGeoclue2.cpp
 
     platform/graphics/GraphicsContext3DPrivate.cpp
     platform/graphics/OpenGLShims.cpp
@@ -243,6 +244,17 @@ list(APPEND WebCorePlatformGTK_SOURCES
     platform/gtk/WidgetRenderingContext.cpp
 )
 
+if (WTF_USE_GEOCLUE2)
+    list(APPEND WebCore_SOURCES
+        ${DERIVED_SOURCES_WEBCORE_DIR}/Geoclue2Interface.c
+    )
+    execute_process(COMMAND pkg-config --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}
+    )
+endif ()
+
 if (ENABLE_NETSCAPE_PLUGIN_API)
     list(APPEND WebCore_SOURCES
         plugins/PluginDatabase.cpp
index 4a77431..654cee5 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * 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
 #if ENABLE(GEOLOCATION)
 
 #include "GeolocationProviderGeoclueClient.h"
+#include <wtf/gobject/GRefPtr.h>
+
+#if USE(GEOCLUE2)
+#include "Geoclue2Interface.h"
+#else
 #include <geoclue/geoclue-master.h>
 #include <geoclue/geoclue-position.h>
-#include <wtf/gobject/GRefPtr.h>
+#endif
 
 namespace WebCore {
 
@@ -38,18 +44,41 @@ public:
     void stopUpdating();
     void setEnableHighAccuracy(bool);
 
-    // To be used from signal callbacks.
+private:
+#if USE(GEOCLUE2)
+    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*);
+#else
+    static void getPositionCallback(GeocluePosition*, GeocluePositionFields, int, double, double, double, GeoclueAccuracy*, GError*, GeolocationProviderGeoclue*);
+    static void positionChangedCallback(GeocluePosition*, GeocluePositionFields, int, double, double, double, GeoclueAccuracy*, GeolocationProviderGeoclue*);
+    static void createGeocluePositionCallback(GeoclueMasterClient*, GeocluePosition*, GError*, GeolocationProviderGeoclue*);
+    static void geoclueClientSetRequirementsCallback(GeoclueMasterClient*, GError*, GeolocationProviderGeoclue*);
+    static void createGeoclueClientCallback(GeoclueMaster*, GeoclueMasterClient*, char*, GError*, GeolocationProviderGeoclue*);
+
     void initializeGeoclueClient(GeoclueMasterClient*);
     void initializeGeocluePosition(GeocluePosition*);
-    void updateClientRequirements();
     void positionChanged(GeocluePosition*, GeocluePositionFields, int, double, double, double, GeoclueAccuracy*);
+#endif
+
     void errorOccurred(const char*);
+    void updateClientRequirements();
 
-private:
     GeolocationProviderGeoclueClient* m_client;
 
+#if USE(GEOCLUE2)
+    GRefPtr<GeoclueManager> m_managerProxy;
+    GRefPtr<GeoclueClient> m_clientProxy;
+#else
     GRefPtr<GeoclueMasterClient> m_geoclueClient;
     GRefPtr<GeocluePosition> m_geocluePosition;
+#endif
 
     double m_latitude;
     double m_longitude;
 #include "config.h"
 #include "GeolocationProviderGeoclue.h"
 
-#if ENABLE(GEOLOCATION)
+#if ENABLE(GEOLOCATION) && !USE(GEOCLUE2)
 
 using namespace WebCore;
 
-static void getPositionCallback(GeocluePosition* position, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy, GError* error, GeolocationProviderGeoclue* provider)
+void GeolocationProviderGeoclue::getPositionCallback(GeocluePosition* position, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy, GError* error, GeolocationProviderGeoclue* provider)
 {
     if (error) {
         provider->errorOccurred(error->message);
@@ -40,12 +40,12 @@ static void getPositionCallback(GeocluePosition* position, GeocluePositionFields
     provider->positionChanged(position, fields, timestamp, latitude, longitude, altitude, accuracy);
 }
 
-static void positionChangedCallback(GeocluePosition* position, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy, GeolocationProviderGeoclue* provider)
+void GeolocationProviderGeoclue::positionChangedCallback(GeocluePosition* position, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy, GeolocationProviderGeoclue* provider)
 {
     provider->positionChanged(position, fields, timestamp, latitude, longitude, altitude, accuracy);
 }
 
-static void createGeocluePositionCallback(GeoclueMasterClient*, GeocluePosition* position, GError *error, GeolocationProviderGeoclue* provider)
+void GeolocationProviderGeoclue::createGeocluePositionCallback(GeoclueMasterClient*, GeocluePosition* position, GError *error, GeolocationProviderGeoclue* provider)
 {
     if (error) {
         provider->errorOccurred(error->message);
@@ -55,7 +55,7 @@ static void createGeocluePositionCallback(GeoclueMasterClient*, GeocluePosition*
     provider->initializeGeocluePosition(position);
 }
 
-static void geoclueClientSetRequirementsCallback(GeoclueMasterClient* client, GError* error, GeolocationProviderGeoclue* provider)
+void GeolocationProviderGeoclue::geoclueClientSetRequirementsCallback(GeoclueMasterClient*, GError* error, GeolocationProviderGeoclue* provider)
 {
     if (error) {
         provider->errorOccurred(error->message);
@@ -63,7 +63,7 @@ static void geoclueClientSetRequirementsCallback(GeoclueMasterClient* client, GE
     }
 }
 
-static void createGeoclueClientCallback(GeoclueMaster*, GeoclueMasterClient* client, char*, GError* error, GeolocationProviderGeoclue* provider)
+void GeolocationProviderGeoclue::createGeoclueClientCallback(GeoclueMaster*, GeoclueMasterClient* client, char*, GError* error, GeolocationProviderGeoclue* provider)
 {
     if (error) {
         provider->errorOccurred(error->message);
@@ -75,8 +75,6 @@ static void createGeoclueClientCallback(GeoclueMaster*, GeoclueMasterClient* cli
 
 GeolocationProviderGeoclue::GeolocationProviderGeoclue(GeolocationProviderGeoclueClient* client)
     : m_client(client)
-    , m_geoclueClient(0)
-    , m_geocluePosition(0)
     , m_latitude(0)
     , m_longitude(0)
     , m_altitude(0)
@@ -154,7 +152,7 @@ void GeolocationProviderGeoclue::updateClientRequirements()
     geoclue_master_client_set_requirements_async(m_geoclueClient.get(), accuracyLevel, 0, false, GEOCLUE_RESOURCE_ALL, reinterpret_cast<GeoclueSetRequirementsCallback>(geoclueClientSetRequirementsCallback), this);
 }
 
-void GeolocationProviderGeoclue::positionChanged(GeocluePosition* position, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy)
+void GeolocationProviderGeoclue::positionChanged(GeocluePosition*, GeocluePositionFields fields, int timestamp, double latitude, double longitude, double altitude, GeoclueAccuracy* accuracy)
 {
     if (!(fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)) {
         errorOccurred("Position could not be determined.");
@@ -176,4 +174,4 @@ void GeolocationProviderGeoclue::errorOccurred(const char* message)
     m_client->notifyErrorOccurred(message);
 }
 
-#endif // ENABLE(GEOLOCATION)
+#endif // ENABLE(GEOLOCATION) && !USE(GEOCLUE2)
diff --git a/Source/WebCore/platform/geoclue/GeolocationProviderGeoclue2.cpp b/Source/WebCore/platform/geoclue/GeolocationProviderGeoclue2.cpp
new file mode 100644 (file)
index 0000000..7487195
--- /dev/null
@@ -0,0 +1,209 @@
+/*
+ * 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 ENABLE(GEOLOCATION) && USE(GEOCLUE2)
+
+#include <wtf/gobject/GUniquePtr.h>
+#include <wtf/gobject/GlibUtilities.h>
+#include <wtf/text/CString.h>
+
+const char* gGeoclueBusName = "org.freedesktop.GeoClue2";
+const char* gGeoclueManagerPath = "/org/freedesktop/GeoClue2/Manager";
+
+using 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;
+    }
+
+    if (!m_clientProxy) {
+        geoclue_manager_call_get_client(m_managerProxy.get(), nullptr, reinterpret_cast<GAsyncReadyCallback>(getGeoclueClientCallback), this);
+        return;
+    }
+
+    startGeoclueClient();
+}
+
+void GeolocationProviderGeoclue::stopUpdating()
+{
+    if (m_clientProxy)
+        geoclue_client_call_stop(m_clientProxy.get(), nullptr, nullptr, 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.
+    // FIXME: We provide the program name as the desktop ID for now but, in an ideal world,
+    // we should provide a proper "application ID" (normally the name of a .desktop file).
+    // https://bugs.webkit.org/show_bug.cgi?id=129879
+    geoclue_client_set_desktop_id(provider->m_clientProxy.get(), g_get_prgname());
+
+    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);
+}
+
+#endif // ENABLE(GEOLOCATION) && USE(GEOCLUE2)
index 8da8d89..0287603 100644 (file)
@@ -404,9 +404,20 @@ PKG_CHECK_MODULES([LIBXSLT],[libxslt >= libxslt_required_version])
 AC_SUBST([LIBXSLT_CFLAGS])
 AC_SUBST([LIBXSLT_LIBS])
 
-# Check if geoclue is available.
+# Check if geoclue is available, with a preference over Geoclue2 if present.
+geolocation_description="none"
 if test "$enable_geolocation" = "yes"; then
-    PKG_CHECK_MODULES([GEOCLUE], [geoclue])
+    PKG_CHECK_MODULES([GEOCLUE2], [gio-unix-2.0 geoclue-2.0 >= geoclue2_required_version], [found_geoclue2=yes], [found_geoclue2=no])
+    if test "$found_geoclue2" = "yes"; then
+        GEOCLUE_CFLAGS="$GEOCLUE2_CFLAGS"
+        GEOCLUE_LIBS="$GEOCLUE2_LIBS"
+        GEOCLUE_DBUS_INTERFACE=`$PKG_CONFIG --variable dbus_interface geoclue-2.0`
+        AC_SUBST(GEOCLUE_DBUS_INTERFACE)
+        geolocation_description="Geoclue 2"
+    else
+        PKG_CHECK_MODULES([GEOCLUE], [geoclue])
+        geolocation_description="Geoclue"
+    fi
     AC_SUBST([GEOCLUE_CFLAGS])
     AC_SUBST([GEOCLUE_LIBS])
 fi
index 702995b..5c236a7 100644 (file)
@@ -17,6 +17,7 @@ Build configuration:
  Code coverage support                                    : $enable_coverage
  Optimized memory allocator                               : $enable_fast_malloc
  Accelerated rendering backend                            : $acceleration_description
+ Geolocation backend                                      : $geolocation_description
 
 Features:
 =======
index b872f9d..fafca70 100644 (file)
@@ -27,6 +27,10 @@ if test "$enable_webkit2" = "yes"; then
     fi
 fi
 
+if test "$found_geoclue2" = "yes"; then
+    AC_DEFINE([WTF_USE_GEOCLUE2], [1], [ ])
+fi
+
 if test "$os_win32" = "yes"; then
     AC_DEFINE([XP_WIN], [1], [ ])
     AC_DEFINE([UNICODE], [1], [ ])
index 3532db2..78da6b0 100644 (file)
@@ -33,6 +33,9 @@ AM_CONDITIONAL([TARGET_WIN32], [test "$enable_win32_target" = "yes"])
 AM_CONDITIONAL([TARGET_QUARTZ], [test "$enable_quartz_target" = "yes"])
 AM_CONDITIONAL([TARGET_DIRECTFB], [test "$enable_directfb_target" = "yes"])
 
+# Geoclue conditionals.
+AM_CONDITIONAL([USE_GEOCLUE2],[test "$found_geoclue2" = "yes"])
+
 # GStreamer feature conditionals.
 AM_CONDITIONAL([USE_GSTREAMER], [test "$enable_video" = "yes" || test "$enable_web_audio" = "yes"])
 AM_CONDITIONAL([USE_WEBAUDIO_GSTREAMER], [test "$enable_web_audio" = "yes"])
index f6ea371..3230c2c 100644 (file)
@@ -24,6 +24,7 @@ m4_define([cairo_required_version], [1.10])
 m4_define([enchant_required_version], [0.22])
 m4_define([fontconfig_required_version], [2.5])
 m4_define([freetype2_required_version], [9.0])
+m4_define([geoclue2_required_version], [2.1.5])
 m4_define([glib_required_version], [2.36.0])
 m4_define([gobject_introspection_required_version], [1.32.0])
 m4_define([gstreamer_plugins_base_required_version], [1.0.3])
diff --git a/Source/cmake/FindGeoClue2.cmake b/Source/cmake/FindGeoClue2.cmake
new file mode 100644 (file)
index 0000000..3143b44
--- /dev/null
@@ -0,0 +1,51 @@
+# - Try to find GeoClue 2
+# Once done, this will define
+#
+#  GEOCLUE2_FOUND - system has GeoClue 2.
+#  GEOCLUE2_INCLUDE_DIRS - the GeoClue 2. include directories
+#  GEOCLUE2_LIBRARIES - link these to use 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 DEFAULT_MSG VERSION_OK)
index 4d80135..f239965 100644 (file)
@@ -204,7 +204,13 @@ endif ()
 find_package(GLIB 2.33.2 REQUIRED COMPONENTS ${glib_components})
 
 if (ENABLE_GEOLOCATION)
-    find_package(GeoClue)
+    find_package(GeoClue2 2.1.5)
+    if (GEOCLUE2_FOUND)
+      set(WTF_USE_GEOCLUE2 1)
+    else ()
+      find_package(GeoClue)
+      set(WTF_USE_GEOCLUE2 0)
+    endif ()
 endif ()
 
 # We don't use find_package for GLX because it is part of -lGL, unlike EGL.
index 1b955b4..c9c2f3b 100644 (file)
 #cmakedefine01 ENABLE_XHR_TIMEOUT
 #cmakedefine01 ENABLE_XSLT
 #cmakedefine01 USE_SYSTEM_MALLOC
+#cmakedefine01 WTF_USE_GEOCLUE2
 #cmakedefine01 WTF_USE_TILED_BACKING_STORE
 #cmakedefine01 HAVE_LLVM