[Qt] navigator.geolocation support for Qt port
https://bugs.webkit.org/show_bug.cgi?id=39724
Patch by Mahesh Kulkarni <mahesh.kulkarni@nokia.com> on 2010-06-14
Reviewed by Laszlo Gombos.
WebCore:
Implemetion for Qt port of navigator.gelocation. Using qtmobility location service.
* WebCore.pri:
* WebCore.pro:
* platform/qt/GeolocationServiceQt.cpp: Added.
(WebCore::GeolocationServiceQt::create):
(WebCore::GeolocationServiceQt::GeolocationServiceQt):
(WebCore::GeolocationServiceQt::~GeolocationServiceQt):
(WebCore::GeolocationServiceQt::positionUpdated):
(WebCore::GeolocationServiceQt::startUpdating):
(WebCore::GeolocationServiceQt::stopUpdating):
* platform/qt/GeolocationServiceQt.h: Added.
(WebCore::GeolocationServiceQt::lastPosition):
(WebCore::GeolocationServiceQt::lastError):
WebKit/qt:
Implement ChromeClientQt::requestGeolocationPermissionForFrame() which delegates call to QWebPage::allowGeolocationRequest
Layout and unit test cases for the are also added.
* Api/qwebpage.cpp:
(QWebPage::allowGeolocationRequest):
* Api/qwebpage.h:
* WebCoreSupport/ChromeClientQt.cpp:
(WebCore::ChromeClientQt::requestGeolocationPermissionForFrame):
* WebCoreSupport/DumpRenderTreeSupportQt.cpp:
(DumpRenderTreeSupportQt::setMockGeolocationPosition):
(DumpRenderTreeSupportQt::setMockGeolocationError):
* WebCoreSupport/DumpRenderTreeSupportQt.h:
* tests/qwebpage/tst_qwebpage.cpp:
(JSTestPage::shouldInterruptJavaScript):
(JSTestPage::allowGeolocationRequest):
(JSTestPage::setGeolocationPermission):
(tst_QWebPage::geolocationRequestJS):
WebKitTools:
Implementation for geolocation cases to DumpRenderTreeQt
* DumpRenderTree/qt/DumpRenderTreeQt.cpp:
(WebCore::WebPage::allowGeolocationRequest):
* DumpRenderTree/qt/DumpRenderTreeQt.h:
* DumpRenderTree/qt/LayoutTestControllerQt.cpp:
(LayoutTestController::setGeolocationPermission):
(LayoutTestController::setMockGeolocationError):
(LayoutTestController::setMockGeolocationPosition):
* DumpRenderTree/qt/LayoutTestControllerQt.h:
(LayoutTestController::isGeolocationPermissionSet):
(LayoutTestController::geolocationPermission):
LayoutTests:
Uncommenting gelocation cases from Qt. Skipped one case: fast/dom/Geolocation/callback-to-remote-context2.html
* platform/qt/Skipped:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@61117 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 41aefff..165e6ee 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2010-06-14 Mahesh Kulkarni <mahesh.kulkarni@nokia.com>
+
+ Reviewed by Laszlo Gombos.
+
+ [Qt] navigator.geolocation support for Qt port
+ https://bugs.webkit.org/show_bug.cgi?id=39724
+
+ Uncommenting gelocation cases from Qt. Skipped one case: fast/dom/Geolocation/callback-to-remote-context2.html
+
+ * platform/qt/Skipped:
+
2010-06-14 Jeremy Orlow <jorlow@chromium.org>
Reviewed by Darin Adler.
diff --git a/LayoutTests/platform/qt/Skipped b/LayoutTests/platform/qt/Skipped
index 48e86dc..d5b7874 100644
--- a/LayoutTests/platform/qt/Skipped
+++ b/LayoutTests/platform/qt/Skipped
@@ -79,9 +79,6 @@
# =========================================================================== #
# Feature not supported... yet
# =========================================================================== #
-# ----- This port doesn't support Geolocation.. yet
-fast/dom/Geolocation
-fast/dom/Window/window-properties-geolocation.html
# This port doesn't support DeviceOrientation.
fast/dom/DeviceOrientation
@@ -5412,5 +5409,5 @@
# ============================================================================= #
# new skipped tests yet to be sorted
# ============================================================================= #
-
+fast/dom/Geolocation/callback-to-remote-context2.html
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 1f09272a..97fe488 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,25 @@
+2010-06-14 Mahesh Kulkarni <mahesh.kulkarni@nokia.com>
+
+ Reviewed by Laszlo Gombos.
+
+ [Qt] navigator.geolocation support for Qt port
+ https://bugs.webkit.org/show_bug.cgi?id=39724
+
+ Implemetion for Qt port of navigator.gelocation. Using qtmobility location service.
+
+ * WebCore.pri:
+ * WebCore.pro:
+ * platform/qt/GeolocationServiceQt.cpp: Added.
+ (WebCore::GeolocationServiceQt::create):
+ (WebCore::GeolocationServiceQt::GeolocationServiceQt):
+ (WebCore::GeolocationServiceQt::~GeolocationServiceQt):
+ (WebCore::GeolocationServiceQt::positionUpdated):
+ (WebCore::GeolocationServiceQt::startUpdating):
+ (WebCore::GeolocationServiceQt::stopUpdating):
+ * platform/qt/GeolocationServiceQt.h: Added.
+ (WebCore::GeolocationServiceQt::lastPosition):
+ (WebCore::GeolocationServiceQt::lastError):
+
2010-06-14 Jeremy Orlow <jorlow@chromium.org>
2 more build fixes.
diff --git a/WebCore/WebCore.pri b/WebCore/WebCore.pri
index ca4caea..2c06e12 100644
--- a/WebCore/WebCore.pri
+++ b/WebCore/WebCore.pri
@@ -8,6 +8,9 @@
DEFINES += ENABLE_NETSCAPE_PLUGIN_API=0
}
+## load mobilityconfig if mobility is available
+load(mobilityconfig, true)
+
## Define default features macros for optional components
## (look for defs in config.h and included files!)
# Try to locate sqlite3 source
@@ -109,13 +112,19 @@
else:DEFINES += ENABLE_XSLT=0
}
+# geolocation support if QtMobility exists
+!CONFIG(QTDIR_build):!contains(DEFINES, ENABLE_GEOLOCATION=.) {
+ contains(MOBILITY_CONFIG, location) {
+ DEFINES += ENABLE_GEOLOCATION=1
+ }
+}
+
# Bearer management is part of Qt 4.7
# for older version, check for mobility with bearer
!contains(DEFINES, ENABLE_QT_BEARER=.) {
!lessThan(QT_MINOR_VERSION, 7) {
DEFINES += ENABLE_QT_BEARER=1
} else {
- load(mobilityconfig)
contains(MOBILITY_CONFIG, bearer) {
DEFINES += ENABLE_QT_BEARER=1
}
@@ -168,7 +177,7 @@
contains(DEFINES, ENABLE_NOTIFICATIONS=1): FEATURE_DEFINES_JAVASCRIPT += ENABLE_NOTIFICATIONS=1
contains(DEFINES, ENABLE_METER_TAG=1): FEATURE_DEFINES_JAVASCRIPT += ENABLE_METER_TAG=1
contains(DEFINES, ENABLE_PROGRESS_TAG=1): FEATURE_DEFINES_JAVASCRIPT += ENABLE_PROGRESS_TAG=1
-
+contains(DEFINES, ENABLE_GEOLOCATION=1): FEATURE_DEFINES_JAVASCRIPT += ENABLE_GEOLOCATION=1
## Derived source generators
MATHML_NAMES = $$PWD/mathml/mathtags.in
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index 4a23375..5d669c5 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -2641,6 +2641,16 @@
}
}
+contains(DEFINES, ENABLE_GEOLOCATION=1) {
+ HEADERS += \
+ platform/qt/GeolocationServiceQt.h
+ SOURCES += \
+ platform/qt/GeolocationServiceQt.cpp
+
+ CONFIG += mobility
+ MOBILITY += location
+}
+
contains(DEFINES, ENABLE_SVG=1) {
SOURCES += \
# TODO: this-one-is-not-auto-added! FIXME! tmp/SVGElementFactory.cpp \
diff --git a/WebCore/platform/qt/GeolocationServiceQt.cpp b/WebCore/platform/qt/GeolocationServiceQt.cpp
new file mode 100644
index 0000000..e24d497
--- /dev/null
+++ b/WebCore/platform/qt/GeolocationServiceQt.cpp
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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. ``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
+ * 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 "GeolocationServiceQt.h"
+
+#include "Geolocation.h"
+#include "Geoposition.h"
+#include "PositionError.h"
+#include "PositionOptions.h"
+
+using namespace QtMobility;
+
+namespace WebCore {
+
+GeolocationService::FactoryFunction* GeolocationService::s_factoryFunction = &GeolocationServiceQt::create;
+
+GeolocationService* GeolocationServiceQt::create(GeolocationServiceClient* client)
+{
+ return new GeolocationServiceQt(client);
+}
+
+GeolocationServiceQt::GeolocationServiceQt(GeolocationServiceClient* client)
+ : GeolocationService(client)
+ , m_lastPosition(0)
+ , m_lastError(0)
+{
+ m_location = QGeoPositionInfoSource::createDefaultSource(this);
+
+ if (m_location)
+ connect(m_location, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
+}
+
+GeolocationServiceQt::~GeolocationServiceQt()
+{
+}
+
+void GeolocationServiceQt::positionUpdated(const QGeoPositionInfo &geoPosition)
+{
+ if (!geoPosition.isValid())
+ errorOccurred();
+
+ QGeoCoordinate coord = geoPosition.coordinate();
+ double latitude = coord.latitude();
+ double longitude = coord.longitude();
+ bool providesAltitude = true;
+ double altitude = coord.altitude();
+
+ double accuracy = geoPosition.hasAttribute(QGeoPositionInfo::HorizontalAccuracy) ?
+ geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy) : 0.0;
+
+ bool providesAltitudeAccuracy = geoPosition.hasAttribute(QGeoPositionInfo::VerticalAccuracy);
+ double altitudeAccuracy = providesAltitudeAccuracy ? geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy) : 0.0;
+
+ bool providesHeading = geoPosition.hasAttribute(QGeoPositionInfo::Direction);
+ double heading = providesHeading ? geoPosition.attribute(QGeoPositionInfo::Direction) : 0.0;
+
+ bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed);
+ double speed = providesSpeed ? geoPosition.attribute(QGeoPositionInfo::GroundSpeed) : 0.0;
+
+ RefPtr<Coordinates> coordinates = Coordinates::create(latitude, longitude, providesAltitude, altitude,
+ accuracy, providesAltitudeAccuracy, altitudeAccuracy,
+ providesHeading, heading, providesSpeed, speed);
+ m_lastPosition = Geoposition::create(coordinates.release(), geoPosition.timestamp().toTime_t());
+ positionChanged();
+}
+
+bool GeolocationServiceQt::startUpdating(PositionOptions*)
+{
+ m_lastPosition = 0;
+
+ if (!m_location)
+ return false;
+
+ // TODO: handle enableHighAccuracy()
+
+ m_location->startUpdates();
+ return true;
+}
+
+void GeolocationServiceQt::stopUpdating()
+{
+ if (m_location)
+ m_location->stopUpdates();
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/qt/GeolocationServiceQt.h b/WebCore/platform/qt/GeolocationServiceQt.h
new file mode 100644
index 0000000..2525e47
--- /dev/null
+++ b/WebCore/platform/qt/GeolocationServiceQt.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * 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. ``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
+ * 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.
+ */
+
+#ifndef GeolocationServiceQt_h
+#define GeolocationServiceQt_h
+
+#include "GeolocationService.h"
+#include <QGeoPositionInfoSource>
+#include <wtf/RefPtr.h>
+
+// FIXME: Remove usage of "using namespace" in a header file.
+// There is bug in qtMobility signal names are not full qualified when used with namespace
+// QtMobility namespace in slots throws up error and its required to be fixed in qtmobility.
+using namespace QtMobility;
+
+namespace WebCore {
+
+// This class provides a implementation of a GeolocationService for qtWebkit.
+// It uses QtMobility (v1.0.0) location service to get positions
+class GeolocationServiceQt : public QObject, GeolocationService {
+ Q_OBJECT
+
+public:
+ static GeolocationService* create(GeolocationServiceClient*);
+
+ GeolocationServiceQt(GeolocationServiceClient*);
+ virtual ~GeolocationServiceQt();
+
+ virtual bool startUpdating(PositionOptions*);
+ virtual void stopUpdating();
+
+ virtual Geoposition* lastPosition() const { return m_lastPosition.get(); }
+ virtual PositionError* lastError() const { return m_lastError.get(); }
+
+public Q_SLOTS:
+ // QGeoPositionInfoSource
+ void positionUpdated(const QGeoPositionInfo&);
+
+private:
+ RefPtr<Geoposition> m_lastPosition;
+ RefPtr<PositionError> m_lastError;
+
+ QtMobility::QGeoPositionInfoSource* m_location;
+};
+
+} // namespace WebCore
+
+#endif // GeolocationServiceQt_h
diff --git a/WebKit/qt/Api/qwebpage.cpp b/WebKit/qt/Api/qwebpage.cpp
index 902b42a..d49ac14 100644
--- a/WebKit/qt/Api/qwebpage.cpp
+++ b/WebKit/qt/Api/qwebpage.cpp
@@ -1936,6 +1936,30 @@
}
/*!
+ \fn bool QWebPage::allowGeolocationRequest()
+ \since 4.7
+
+ This function is called whenever a JavaScript program running inside \a frame tries to access user location through navigator.geolocation.
+
+ If the user wants to allow access to location then it should return true; otherwise false.
+
+ The default implementation executes the query using QMessageBox::information with QMessageBox::Yes and QMessageBox::No buttons.
+
+ \warning Because of binary compatibility constraints, this function is not virtual. If you want to
+ provide your own implementation in a QWebPage subclass, reimplement the allowGeolocationRequest()
+ slot in your subclass instead. QtWebKit will dynamically detect the slot and call it.
+*/
+bool QWebPage::allowGeolocationRequest(QWebFrame *frame)
+{
+#ifdef QT_NO_MESSAGEBOX
+ return false;
+#else
+ QWidget* parent = (d->client) ? d->client->ownerWidget() : 0;
+ return QMessageBox::Yes == QMessageBox::information(parent, tr("Location Request by- %1").arg(frame->url().host()), tr("The page wants to access your location information. Do you want to allow the request?"), QMessageBox::Yes, QMessageBox::No);
+#endif
+}
+
+/*!
This function is called whenever WebKit wants to create a new window of the given \a type, for
example when a JavaScript program requests to open a document in a new window.
diff --git a/WebKit/qt/Api/qwebpage.h b/WebKit/qt/Api/qwebpage.h
index a4b555a..721f4a8 100644
--- a/WebKit/qt/Api/qwebpage.h
+++ b/WebKit/qt/Api/qwebpage.h
@@ -307,6 +307,7 @@
public Q_SLOTS:
bool shouldInterruptJavaScript();
+ bool allowGeolocationRequest(QWebFrame *frame);
Q_SIGNALS:
void loadStarted();
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index ed8712e..658b86b 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,28 @@
+2010-06-14 Mahesh Kulkarni <mahesh.kulkarni@nokia.com>
+
+ Reviewed by Laszlo Gombos.
+
+ [Qt] navigator.geolocation support for Qt port
+ https://bugs.webkit.org/show_bug.cgi?id=39724
+
+ Implement ChromeClientQt::requestGeolocationPermissionForFrame() which delegates call to QWebPage::allowGeolocationRequest
+ Layout and unit test cases for the are also added.
+
+ * Api/qwebpage.cpp:
+ (QWebPage::allowGeolocationRequest):
+ * Api/qwebpage.h:
+ * WebCoreSupport/ChromeClientQt.cpp:
+ (WebCore::ChromeClientQt::requestGeolocationPermissionForFrame):
+ * WebCoreSupport/DumpRenderTreeSupportQt.cpp:
+ (DumpRenderTreeSupportQt::setMockGeolocationPosition):
+ (DumpRenderTreeSupportQt::setMockGeolocationError):
+ * WebCoreSupport/DumpRenderTreeSupportQt.h:
+ * tests/qwebpage/tst_qwebpage.cpp:
+ (JSTestPage::shouldInterruptJavaScript):
+ (JSTestPage::allowGeolocationRequest):
+ (JSTestPage::setGeolocationPermission):
+ (tst_QWebPage::geolocationRequestJS):
+
2010-06-14 Ilya Tikhonovsky <loislo@chromium.org>
Reviewed by Pavel Feldman.
diff --git a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
index d8389b5..98ffd8a 100644
--- a/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
@@ -36,6 +36,7 @@
#include "FrameLoader.h"
#include "FrameLoaderClientQt.h"
#include "FrameView.h"
+#include "Geolocation.h"
#include "HitTestResult.h"
#include "Icon.h"
#include "NotImplemented.h"
@@ -534,10 +535,12 @@
return false;
}
-void ChromeClientQt::requestGeolocationPermissionForFrame(Frame*, Geolocation*)
+void ChromeClientQt::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
{
- // See the comment in WebCore/page/ChromeClient.h
- notImplemented();
+ bool allow = false;
+ QWebFrame* webFrame = QWebFramePrivate::kit(frame);
+ QMetaObject::invokeMethod(m_webPage, "allowGeolocationRequest", Qt::DirectConnection, Q_RETURN_ARG(bool, allow), Q_ARG(QWebFrame*, webFrame));
+ geolocation->setIsAllowed(allow);
}
#if USE(ACCELERATED_COMPOSITING)
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
index 10323d8..c92e43f 100644
--- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
+++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
@@ -35,6 +35,9 @@
#include "FrameLoaderClientQt.h"
#include "FrameView.h"
#include "GCController.h"
+#include "Geolocation.h"
+#include "GeolocationServiceMock.h"
+#include "Geoposition.h"
#include "HistoryItem.h"
#include "HTMLInputElement.h"
#include "InspectorController.h"
@@ -42,6 +45,7 @@
#include "Page.h"
#include "PageGroup.h"
#include "PluginDatabase.h"
+#include "PositionError.h"
#include "PrintContext.h"
#include "RenderListItem.h"
#include "RenderTreeAsText.h"
@@ -52,6 +56,7 @@
#endif
#include "TextIterator.h"
#include "WorkerThread.h"
+#include <wtf/CurrentTime.h>
#include "qwebelement.h"
#include "qwebframe.h"
@@ -558,6 +563,22 @@
#endif
}
+void DumpRenderTreeSupportQt::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
+{
+#if ENABLE(GEOLOCATION)
+ RefPtr<Geoposition> geoposition = Geoposition::create(Coordinates::create(latitude, longitude, false, 0, accuracy, true, 0, false, 0, false, 0), currentTime() * 1000.0);
+ GeolocationServiceMock::setPosition(geoposition);
+#endif
+}
+
+void DumpRenderTreeSupportQt::setMockGeolocationError(int errorCode, const QString& message)
+{
+#if ENABLE(GEOLOCATION)
+ RefPtr<PositionError> positionError = PositionError::create(static_cast<PositionError::ErrorCode>(errorCode), message);
+ GeolocationServiceMock::setError(positionError);
+#endif
+}
+
void DumpRenderTreeSupportQt::setCheckPermissionFunction(CheckPermissionFunctionType* f)
{
checkPermissionFunction = f;
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
index 363e751..e3408e3 100644
--- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
+++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
@@ -97,6 +97,9 @@
static void removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
static void resetOriginAccessWhiteLists();
+ static void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
+ static void setMockGeolocationError(int errorCode, const QString& message);
+
static int workerThreadCount();
static QString markerTextForListItem(const QWebElement& listItem);
diff --git a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
index 6b29a07..5e6f4e6 100644
--- a/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
+++ b/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
@@ -77,6 +77,7 @@
void acceptNavigationRequest();
void infiniteLoopJS();
+ void geolocationRequestJS();
void loadFinished();
void acceptNavigationRequestWithNewWindow();
void userStyleSheet();
@@ -214,8 +215,21 @@
public slots:
bool shouldInterruptJavaScript() {
- return true;
+ return true;
}
+ bool allowGeolocationRequest(QWebFrame *frame)
+ {
+ return m_allowGeolocation;
+ }
+
+public:
+ void setGeolocationPermission(bool allow)
+ {
+ m_allowGeolocation = allow;
+ }
+
+private:
+ bool m_allowGeolocation;
};
void tst_QWebPage::infiniteLoopJS()
@@ -227,6 +241,28 @@
delete newPage;
}
+void tst_QWebPage::geolocationRequestJS()
+{
+ JSTestPage* newPage = new JSTestPage(m_view);
+ newPage->setGeolocationPermission(false);
+ m_view->setPage(newPage);
+ m_view->setHtml(QString("<html><body>test</body></html>"), QUrl());
+ m_view->page()->mainFrame()->evaluateJavaScript("var errorCode = 0; function error(err) { errorCode = err.code; } function success(pos) { } navigator.geolocation.getCurrentPosition(success, error)");
+ QTest::qWait(2000);
+ QVariant empty = m_view->page()->mainFrame()->evaluateJavaScript("errorCode");
+
+ QVERIFY(empty.type() == QVariant::Double && empty.toInt() != 0);
+
+ newPage->setGeolocationPermission(true);
+ m_view->page()->mainFrame()->evaluateJavaScript("errorCode = 0; navigator.geolocation.getCurrentPosition(success, error);");
+ empty = m_view->page()->mainFrame()->evaluateJavaScript("errorCode");
+
+ //http://dev.w3.org/geo/api/spec-source.html#position
+ //PositionError: const unsigned short PERMISSION_DENIED = 1;
+ QVERIFY(empty.type() == QVariant::Double && empty.toInt() != 1);
+ delete newPage;
+}
+
void tst_QWebPage::loadFinished()
{
qRegisterMetaType<QWebFrame*>("QWebFrame*");
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 9486ef1..13d9f20 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,23 @@
+2010-06-14 Mahesh Kulkarni <mahesh.kulkarni@nokia.com>
+
+ Reviewed by Laszlo Gombos.
+
+ [Qt] navigator.geolocation support for Qt port
+ https://bugs.webkit.org/show_bug.cgi?id=39724
+
+ Implementation for geolocation cases to DumpRenderTreeQt
+
+ * DumpRenderTree/qt/DumpRenderTreeQt.cpp:
+ (WebCore::WebPage::allowGeolocationRequest):
+ * DumpRenderTree/qt/DumpRenderTreeQt.h:
+ * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
+ (LayoutTestController::setGeolocationPermission):
+ (LayoutTestController::setMockGeolocationError):
+ (LayoutTestController::setMockGeolocationPosition):
+ * DumpRenderTree/qt/LayoutTestControllerQt.h:
+ (LayoutTestController::isGeolocationPermissionSet):
+ (LayoutTestController::geolocationPermission):
+
2010-06-13 Nathan Lawrence <nlawrence@apple.com>
Reviewed by Darin Adler.
diff --git a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
index bcb432a..f5fbb5c 100644
--- a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
+++ b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
@@ -348,6 +348,11 @@
#endif
}
+bool WebPage::allowGeolocationRequest(QWebFrame *)
+{
+ return m_drt->layoutTestController()->geolocationPermission();
+}
+
WebViewGraphicsBased::WebViewGraphicsBased(QWidget* parent)
: m_item(new QGraphicsWebView)
{
diff --git a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
index 65dc6d6..2ec972a 100644
--- a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
+++ b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
@@ -191,6 +191,7 @@
public slots:
bool shouldInterruptJavaScript() { return false; }
+ bool allowGeolocationRequest(QWebFrame *frame);
protected:
bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type);
diff --git a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
index 5f9bc21..8450376 100644
--- a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
+++ b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
@@ -646,5 +646,21 @@
DumpRenderTreeSupportQt::setEditingBehavior(m_drt->webPage(), editingBehavior);
}
+void LayoutTestController::setGeolocationPermission(bool allow)
+{
+ m_isGeolocationPermissionSet = true;
+ m_geolocationPermission = allow;
+}
+
+void LayoutTestController::setMockGeolocationError(int code, const QString& message)
+{
+ DumpRenderTreeSupportQt::setMockGeolocationError(code, message);
+}
+
+void LayoutTestController::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
+{
+ DumpRenderTreeSupportQt::setMockGeolocationPosition(latitude, longitude, accuracy);
+}
+
const unsigned LayoutTestController::maxViewWidth = 800;
const unsigned LayoutTestController::maxViewHeight = 600;
diff --git a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h
index 6286955..a041ad0 100644
--- a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h
+++ b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h
@@ -184,6 +184,12 @@
// https://bugs.webkit.org/show_bug.cgi?id=33333
void setCallCloseOnWebViews() {}
+ void setMockGeolocationError(int code, const QString& message);
+ void setMockGeolocationPosition(double latitude, double longitude, double accuracy);
+ void setGeolocationPermission(bool allow);
+ bool isGeolocationPermissionSet() const { return m_isGeolocationPermissionSet; }
+ bool geolocationPermission() const { return m_geolocationPermission; }
+
/*
Policy values: 'on', 'auto' or 'off'.
Orientation values: 'vertical' or 'horizontal'.
@@ -215,6 +221,8 @@
bool m_handleErrorPages;
bool m_loadFinished;
bool m_globalFlag;
+ bool m_isGeolocationPermissionSet;
+ bool m_geolocationPermission;
QUrl m_userStyleSheetLocation;
QBasicTimer m_timeoutTimer;