Title: [97733] trunk/Source/WebKit2
Revision
97733
Author
[email protected]
Date
2011-10-18 03:03:03 -0700 (Tue, 18 Oct 2011)

Log Message

[Qt][WK2] Implement geolocation provider for qt port
https://bugs.webkit.org/show_bug.cgi?id=59199

Patch by Adenilson Cavalcanti <[email protected]> on 2011-10-18
Reviewed by Simon Hausmann.

Based on patch by Kenneth Christiansen <[email protected]>

Implements default location provider for WK2 QtWebKit (WebGeolocationProviderQt),
allowing QtWebKit clients to implement or override their own provider using WK2 APIs.

* UIProcess/API/C/WKGeolocationManager.h:
* UIProcess/qt/WebContextQt.cpp:
(WebKit::WebContext::platformInitializeWebProcess):
* UIProcess/qt/WebGeolocationProviderQt.cpp: Added.
(toLocationProvider):
(locationStartUpdating):
(locationStopUpdating):
(WebGeolocationProviderQt::create):
(WebGeolocationProviderQt::provider):
(WebGeolocationProviderQt::WebGeolocationProviderQt):
(WebGeolocationProviderQt::~WebGeolocationProviderQt):
(WebGeolocationProviderQt::updateTimeout):
(WebGeolocationProviderQt::positionUpdated):
(WebGeolocationProviderQt::startUpdating):
(WebGeolocationProviderQt::stopUpdating):
* UIProcess/qt/WebGeolocationProviderQt.h: Added.
* WebKit2.pro:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (97732 => 97733)


--- trunk/Source/WebKit2/ChangeLog	2011-10-18 09:28:14 UTC (rev 97732)
+++ trunk/Source/WebKit2/ChangeLog	2011-10-18 10:03:03 UTC (rev 97733)
@@ -1,3 +1,33 @@
+2011-10-18  Adenilson Cavalcanti  <[email protected]>
+
+        [Qt][WK2] Implement geolocation provider for qt port
+        https://bugs.webkit.org/show_bug.cgi?id=59199
+
+        Reviewed by Simon Hausmann.
+
+        Based on patch by Kenneth Christiansen <[email protected]>
+
+        Implements default location provider for WK2 QtWebKit (WebGeolocationProviderQt),
+        allowing QtWebKit clients to implement or override their own provider using WK2 APIs.
+
+        * UIProcess/API/C/WKGeolocationManager.h:
+        * UIProcess/qt/WebContextQt.cpp:
+        (WebKit::WebContext::platformInitializeWebProcess):
+        * UIProcess/qt/WebGeolocationProviderQt.cpp: Added.
+        (toLocationProvider):
+        (locationStartUpdating):
+        (locationStopUpdating):
+        (WebGeolocationProviderQt::create):
+        (WebGeolocationProviderQt::provider):
+        (WebGeolocationProviderQt::WebGeolocationProviderQt):
+        (WebGeolocationProviderQt::~WebGeolocationProviderQt):
+        (WebGeolocationProviderQt::updateTimeout):
+        (WebGeolocationProviderQt::positionUpdated):
+        (WebGeolocationProviderQt::startUpdating):
+        (WebGeolocationProviderQt::stopUpdating):
+        * UIProcess/qt/WebGeolocationProviderQt.h: Added.
+        * WebKit2.pro:
+
 2011-10-18  Carlos Garcia Campos  <[email protected]>
 
         [UNIX] Use SOCK_SEQPACKET when available

Modified: trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp (97732 => 97733)


--- trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp	2011-10-18 09:28:14 UTC (rev 97732)
+++ trunk/Source/WebKit2/UIProcess/qt/WebContextQt.cpp	2011-10-18 10:03:03 UTC (rev 97733)
@@ -29,7 +29,12 @@
 
 #include "ApplicationCacheStorage.h"
 #include "FileSystem.h"
+#include "WKSharedAPICast.h"
+#if ENABLE(GEOLOCATION)
+#include "WebGeolocationProviderQt.h"
+#endif
 #include "WebProcessCreationParameters.h"
+
 #include <QCoreApplication>
 #include <QDesktopServices>
 #include <QDir>
@@ -64,6 +69,10 @@
 {
     qRegisterMetaType<QProcess::ExitStatus>("QProcess::ExitStatus");
     parameters.cookieStorageDirectory = defaultDataLocation();
+#if ENABLE(GEOLOCATION)
+    static WebGeolocationProviderQt* location = WebGeolocationProviderQt::create(toAPI(geolocationManagerProxy()));
+    WKGeolocationManagerSetProvider(toAPI(geolocationManagerProxy()), WebGeolocationProviderQt::provider(location));
+#endif
 }
 
 void WebContext::platformInvalidateContext()

Added: trunk/Source/WebKit2/UIProcess/qt/WebGeolocationProviderQt.cpp (0 => 97733)


--- trunk/Source/WebKit2/UIProcess/qt/WebGeolocationProviderQt.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/WebGeolocationProviderQt.cpp	2011-10-18 10:03:03 UTC (rev 97733)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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 program 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 program; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "WebGeolocationProviderQt.h"
+
+#if ENABLE(GEOLOCATION)
+
+#include <QtLocation/QGeoPositionInfoSource>
+
+using namespace WebKit;
+
+static inline const WebGeolocationProviderQt* toLocationProvider(const void* clientInfo)
+{
+    return static_cast<const WebGeolocationProviderQt*>(clientInfo);
+}
+
+static void locationStartUpdating(WKGeolocationManagerRef geolocationManager, const void* clientInfo)
+{
+    toLocationProvider(clientInfo)->startUpdating();
+}
+
+static void locationStopUpdating(WKGeolocationManagerRef geolocationManager, const void* clientInfo)
+{
+    toLocationProvider(clientInfo)->stopUpdating();
+}
+
+WebGeolocationProviderQt* WebGeolocationProviderQt::create(WKGeolocationManagerRef manager)
+{
+    return new WebGeolocationProviderQt(manager);
+}
+
+WKGeolocationProvider* WebGeolocationProviderQt::provider(const WebGeolocationProviderQt* location)
+{
+    static WKGeolocationProvider provider = {
+        0, // This features the version.
+        location, // This points to the object implementer.
+        locationStartUpdating, // The callbacks are next.
+        locationStopUpdating
+    };
+
+    return &provider;
+}
+
+WebGeolocationProviderQt::WebGeolocationProviderQt(WKGeolocationManagerRef manager)
+    : m_manager(manager)
+    , m_source(0)
+{
+}
+
+WebGeolocationProviderQt::~WebGeolocationProviderQt()
+{
+}
+
+void WebGeolocationProviderQt::updateTimeout()
+{
+    WKGeolocationManagerProviderDidFailToDeterminePosition(m_manager);
+}
+
+void WebGeolocationProviderQt::positionUpdated(const QGeoPositionInfo& geoPosition)
+{
+    if (!geoPosition.isValid())
+        return;
+
+    QGeoCoordinate coord = geoPosition.coordinate();
+    double latitude = coord.latitude();
+    double longitude = coord.longitude();
+    double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy);
+    double timeStampInSeconds = geoPosition.timestamp().toMSecsSinceEpoch() / 1000;
+
+    m_lastPosition.adopt(WKGeolocationPositionCreate(timeStampInSeconds, latitude, longitude, accuracy));
+
+    WKGeolocationManagerProviderDidChangePosition(m_manager, m_lastPosition.get());
+}
+
+void WebGeolocationProviderQt::startUpdating() const
+{
+    if (!m_source) {
+        if (!(m_source = QGeoPositionInfoSource::createDefaultSource(const_cast<WebGeolocationProviderQt*>(this)))) {
+            // Let the manager known that the provider is not available.
+            WKGeolocationManagerSetProvider(m_manager, 0);
+            // Notify failure at retrieving the position.
+            WKGeolocationManagerProviderDidFailToDeterminePosition(m_manager);
+            return;
+        }
+
+        connect(m_source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
+        connect(m_source, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
+    }
+
+    m_source->startUpdates();
+}
+
+void WebGeolocationProviderQt::stopUpdating() const
+{
+    if (m_source)
+        m_source->stopUpdates();
+}
+
+#endif // ENABLE(GEOLOCATION)

Added: trunk/Source/WebKit2/UIProcess/qt/WebGeolocationProviderQt.h (0 => 97733)


--- trunk/Source/WebKit2/UIProcess/qt/WebGeolocationProviderQt.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/qt/WebGeolocationProviderQt.h	2011-10-18 10:03:03 UTC (rev 97733)
@@ -0,0 +1,56 @@
+/*
+    Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
+
+    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.
+*/
+
+
+#ifndef WebGeolocationProviderQt_h
+#define WebGeolocationProviderQt_h
+
+#include <QObject>
+#include <WebKit2/WKGeolocationManager.h>
+#include <WebKit2/WKGeolocationPosition.h>
+#include <WebKit2/WKRetainPtr.h>
+
+class QGeoPositionInfoSource;
+class QGeoPositionInfo;
+
+class WebGeolocationProviderQt : public QObject {
+    Q_OBJECT
+public:
+    static WebGeolocationProviderQt* create(WKGeolocationManagerRef);
+    static WKGeolocationProvider* provider(const WebGeolocationProviderQt*);
+
+    virtual ~WebGeolocationProviderQt();
+
+    void startUpdating() const;
+    void stopUpdating() const;
+
+public Q_SLOTS:
+    void updateTimeout();
+    void positionUpdated(const QGeoPositionInfo&);
+
+private:
+    Q_DISABLE_COPY(WebGeolocationProviderQt);
+    WebGeolocationProviderQt(WKGeolocationManagerRef);
+
+    WKGeolocationManagerRef m_manager;
+    WKRetainPtr<WKGeolocationPositionRef> m_lastPosition;
+    mutable QGeoPositionInfoSource* m_source;
+};
+
+#endif /* WebGeolocationProviderQt_h */

Modified: trunk/Source/WebKit2/WebKit2.pro (97732 => 97733)


--- trunk/Source/WebKit2/WebKit2.pro	2011-10-18 09:28:14 UTC (rev 97732)
+++ trunk/Source/WebKit2/WebKit2.pro	2011-10-18 10:03:03 UTC (rev 97733)
@@ -272,6 +272,7 @@
     UIProcess/qt/ViewportInteractionEngine.h \
     UIProcess/qt/WebUndoCommandQt.h \
     UIProcess/qt/WebContextMenuProxyQt.h \
+    UIProcess/qt/WebGeolocationProviderQt.h \
     UIProcess/qt/WebPopupMenuProxyQt.h \
     UIProcess/qt/WebPopupMenuProxyQtDesktop.h \
     WebProcess/ApplicationCache/WebApplicationCacheManager.h \
@@ -513,6 +514,7 @@
     UIProcess/qt/ViewportInteractionEngine.cpp \
     UIProcess/qt/WebContextMenuProxyQt.cpp \
     UIProcess/qt/WebContextQt.cpp \
+    UIProcess/qt/WebGeolocationProviderQt.cpp \
     UIProcess/qt/WebFullScreenManagerProxyQt.cpp \
     UIProcess/qt/WebInspectorProxyQt.cpp \
     UIProcess/qt/WebPageProxyQt.cpp \
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to