Title: [119475] trunk
Revision
119475
Author
[email protected]
Date
2012-06-05 02:46:21 -0700 (Tue, 05 Jun 2012)

Log Message

[GTK][WK2] Implement API for Geolocation permission requests in the GTK port
https://bugs.webkit.org/show_bug.cgi?id=83879

Reviewed by Carlos Garcia Campos.

Source/WebKit2:

Added a new kind of permission request for supporting the
Geolocation API in WebKit2GTK+.

New WebKitGeolocationPermissionRequest class, implementing the
WebKitPermissionRequest interface, to enabling client applications
to allow or deny geolocation permission requests.

* GNUmakefile.list.am: Added new files.
* UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp: Added.
(_WebKitGeolocationPermissionRequestPrivate):
(webkitGeolocationPermissionRequestAllow):
(webkitGeolocationPermissionRequestDeny):
(webkit_permission_request_interface_init):
(webkit_geolocation_permission_request_init):
(webkitGeolocationPermissionRequestFinalize):
(webkit_geolocation_permission_request_class_init):
(webkitGeolocationPermissionRequestCreate):
* UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h: Added.
(_WebKitGeolocationPermissionRequest):
(_WebKitGeolocationPermissionRequestClass):
* UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h: Added.

Include WKGeolocationPermissionRequest.h in WebKitPrivate.h, so we
can use it from the new WebKitGeolocationPermissionRequest class.

* UIProcess/API/gtk/WebKitPrivate.h: Added new include.

Implement geolocation permission requests in the UI client.

* UIProcess/API/gtk/WebKitUIClient.cpp:
(decidePolicyForGeolocationPermissionRequest): Create a new
instance of the WebKitGeolocationPermissionRequest class and call
to webkitWebViewMakePermissionRequest().
(attachUIClientToView): Provide an implementation function for
decidePolicyForGeolocationPermissionRequest.
* UIProcess/API/gtk/WebKitWebView.h: Add new element to
WebKitPermissionRequestType enumeration for geolocation requests.
* UIProcess/API/gtk/webkit2.h: Added header file for
WebKitGeolocationPermissionRequest

New unit tests to test allowing and denying permission requests.

* UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
(testWebViewPermissionRequests): New test that loads a simple HTML
with _javascript_ code requesting the current location.
(beforeAll): Added new test.

Updated documentation files.

* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt:

Tools:

Make minibrowser connect to the new 'permission requests' signal
to allow users handle the Geolocation permission requests.

* MiniBrowser/gtk/BrowserWindow.c:
(geolocationRequestDialogCallback): Callback for the dialog asking
the user for allowing or not geolocation permission requests.
(webViewDecidePermissionRequest): Launch a dialog to ask the user
whether to allow or deny geolocation permission requests.
(browserWindowConstructed): Connect to 'permission-request' signal.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (119474 => 119475)


--- trunk/Source/WebKit2/ChangeLog	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/ChangeLog	2012-06-05 09:46:21 UTC (rev 119475)
@@ -1,3 +1,62 @@
+2012-06-05  Mario Sanchez Prada  <[email protected]>
+
+        [GTK][WK2] Implement API for Geolocation permission requests in the GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=83879
+
+        Reviewed by Carlos Garcia Campos.
+
+        Added a new kind of permission request for supporting the
+        Geolocation API in WebKit2GTK+.
+
+        New WebKitGeolocationPermissionRequest class, implementing the
+        WebKitPermissionRequest interface, to enabling client applications
+        to allow or deny geolocation permission requests.
+
+        * GNUmakefile.list.am: Added new files.
+        * UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp: Added.
+        (_WebKitGeolocationPermissionRequestPrivate):
+        (webkitGeolocationPermissionRequestAllow):
+        (webkitGeolocationPermissionRequestDeny):
+        (webkit_permission_request_interface_init):
+        (webkit_geolocation_permission_request_init):
+        (webkitGeolocationPermissionRequestFinalize):
+        (webkit_geolocation_permission_request_class_init):
+        (webkitGeolocationPermissionRequestCreate):
+        * UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h: Added.
+        (_WebKitGeolocationPermissionRequest):
+        (_WebKitGeolocationPermissionRequestClass):
+        * UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h: Added.
+
+        Include WKGeolocationPermissionRequest.h in WebKitPrivate.h, so we
+        can use it from the new WebKitGeolocationPermissionRequest class.
+
+        * UIProcess/API/gtk/WebKitPrivate.h: Added new include.
+
+        Implement geolocation permission requests in the UI client.
+
+        * UIProcess/API/gtk/WebKitUIClient.cpp:
+        (decidePolicyForGeolocationPermissionRequest): Create a new
+        instance of the WebKitGeolocationPermissionRequest class and call
+        to webkitWebViewMakePermissionRequest().
+        (attachUIClientToView): Provide an implementation function for
+        decidePolicyForGeolocationPermissionRequest.
+        * UIProcess/API/gtk/WebKitWebView.h: Add new element to
+        WebKitPermissionRequestType enumeration for geolocation requests.
+        * UIProcess/API/gtk/webkit2.h: Added header file for
+        WebKitGeolocationPermissionRequest
+
+        New unit tests to test allowing and denying permission requests.
+
+        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
+        (testWebViewPermissionRequests): New test that loads a simple HTML
+        with _javascript_ code requesting the current location.
+        (beforeAll): Added new test.
+
+        Updated documentation files.
+
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
+
 2012-06-04  Sadrul Habib Chowdhury  <[email protected]>
 
         [chromium] Fix software rendering for device-scale-factor > 1

Modified: trunk/Source/WebKit2/GNUmakefile.list.am (119474 => 119475)


--- trunk/Source/WebKit2/GNUmakefile.list.am	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/GNUmakefile.list.am	2012-06-05 09:46:21 UTC (rev 119475)
@@ -95,6 +95,7 @@
 	$(WebKit2)/UIProcess/API/gtk/WebKitError.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitFileChooserRequest.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitHitTestResult.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitJavascriptResult.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitMimeInfo.h \
@@ -513,6 +514,7 @@
 	Source/WebKit2/UIProcess/API/C/WKFramePolicyListener.h \
 	Source/WebKit2/UIProcess/API/C/WKGeolocationManager.cpp \
 	Source/WebKit2/UIProcess/API/C/WKGeolocationManager.h \
+	Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.cpp \
 	Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.h \
 	Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp \
 	Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h \
@@ -584,6 +586,9 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitFileChooserRequestPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp \

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp (0 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp	2012-06-05 09:46:21 UTC (rev 119475)
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "WebKitGeolocationPermissionRequest.h"
+
+#include "WebKitGeolocationPermissionRequestPrivate.h"
+#include "WebKitPermissionRequest.h"
+
+/**
+ * SECTION: WebKitGeolocationPermissionRequest
+ * @Short_description: A permission request for sharing user's location
+ * @Title: WebKitGeolocationPermissionRequest
+ * @See_also: #WebKitPermissionRequest, #WebKitWebView
+ *
+ * WebKitGeolocationPermissionRequest represents a request for
+ * permission to decide whether WebKit should provide the user's
+ * location to a website when requested throught the Geolocation API.
+ */
+static void webkit_permission_request_interface_init(WebKitPermissionRequestIface*);
+G_DEFINE_TYPE_WITH_CODE(WebKitGeolocationPermissionRequest, webkit_geolocation_permission_request, G_TYPE_OBJECT,
+                        G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_PERMISSION_REQUEST,
+                                              webkit_permission_request_interface_init))
+
+struct _WebKitGeolocationPermissionRequestPrivate {
+    WKRetainPtr<WKGeolocationPermissionRequestRef> wkRequest;
+    bool madeDecision;
+};
+
+static void webkitGeolocationPermissionRequestAllow(WebKitPermissionRequest* request)
+{
+    ASSERT(WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(request));
+
+    WebKitGeolocationPermissionRequestPrivate* priv = WEBKIT_GEOLOCATION_PERMISSION_REQUEST(request)->priv;
+
+    // Only one decision at a time.
+    if (priv->madeDecision)
+        return;
+
+    WKGeolocationPermissionRequestAllow(priv->wkRequest.get());
+    priv->madeDecision = true;
+}
+
+static void webkitGeolocationPermissionRequestDeny(WebKitPermissionRequest* request)
+{
+    ASSERT(WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(request));
+
+    WebKitGeolocationPermissionRequestPrivate* priv = WEBKIT_GEOLOCATION_PERMISSION_REQUEST(request)->priv;
+
+    // Only one decision at a time.
+    if (priv->madeDecision)
+        return;
+
+    WKGeolocationPermissionRequestDeny(priv->wkRequest.get());
+    priv->madeDecision = true;
+}
+
+static void webkit_permission_request_interface_init(WebKitPermissionRequestIface* iface)
+{
+    iface->allow = webkitGeolocationPermissionRequestAllow;
+    iface->deny = webkitGeolocationPermissionRequestDeny;
+}
+
+static void webkit_geolocation_permission_request_init(WebKitGeolocationPermissionRequest* request)
+{
+    request->priv = G_TYPE_INSTANCE_GET_PRIVATE(request, WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST, WebKitGeolocationPermissionRequestPrivate);
+    new (request->priv) WebKitGeolocationPermissionRequestPrivate();
+}
+
+static void webkitGeolocationPermissionRequestFinalize(GObject* object)
+{
+    WebKitGeolocationPermissionRequestPrivate* priv = WEBKIT_GEOLOCATION_PERMISSION_REQUEST(object)->priv;
+
+    // Default behaviour when no decision has been made is denying the request.
+    if (!priv->madeDecision)
+        WKGeolocationPermissionRequestDeny(priv->wkRequest.get());
+
+    priv->~WebKitGeolocationPermissionRequestPrivate();
+    G_OBJECT_CLASS(webkit_geolocation_permission_request_parent_class)->finalize(object);
+}
+
+static void webkit_geolocation_permission_request_class_init(WebKitGeolocationPermissionRequestClass* klass)
+{
+    GObjectClass* objectClass = G_OBJECT_CLASS(klass);
+    objectClass->finalize = webkitGeolocationPermissionRequestFinalize;
+    g_type_class_add_private(klass, sizeof(WebKitGeolocationPermissionRequestPrivate));
+}
+
+WebKitGeolocationPermissionRequest* webkitGeolocationPermissionRequestCreate(WKGeolocationPermissionRequestRef wkRequest)
+{
+    WebKitGeolocationPermissionRequest* geolocationPermissionRequest = WEBKIT_GEOLOCATION_PERMISSION_REQUEST(g_object_new(WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST, NULL));
+    geolocationPermissionRequest->priv->wkRequest = wkRequest;
+    return geolocationPermissionRequest;
+}

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h (0 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h	2012-06-05 09:46:21 UTC (rev 119475)
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitGeolocationPermissionRequest_h
+#define WebKitGeolocationPermissionRequest_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST            (webkit_geolocation_permission_request_get_type())
+#define WEBKIT_GEOLOCATION_PERMISSION_REQUEST(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST, WebKitGeolocationPermissionRequest))
+#define WEBKIT_GEOLOCATION_PERMISSION_REQUEST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST, WebKitGeolocationPermissionRequestClass))
+#define WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST))
+#define WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST))
+#define WEBKIT_GEOLOCATION_PERMISSION_REQUEST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST, WebKitGeolocationPermissionRequestClass))
+
+typedef struct _WebKitGeolocationPermissionRequest        WebKitGeolocationPermissionRequest;
+typedef struct _WebKitGeolocationPermissionRequestClass   WebKitGeolocationPermissionRequestClass;
+typedef struct _WebKitGeolocationPermissionRequestPrivate WebKitGeolocationPermissionRequestPrivate;
+
+struct _WebKitGeolocationPermissionRequest {
+    GObject parent;
+
+    /*< private >*/
+    WebKitGeolocationPermissionRequestPrivate *priv;
+};
+
+struct _WebKitGeolocationPermissionRequestClass {
+    GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_geolocation_permission_request_get_type (void);
+
+G_END_DECLS
+
+#endif

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h (0 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h	2012-06-05 09:46:21 UTC (rev 119475)
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+#ifndef WebKitGeolocationPermissionRequestPrivate_h
+#define WebKitGeolocationPermissionRequestPrivate_h
+
+#include "WebKitGeolocationPermissionRequest.h"
+#include "WebKitPrivate.h"
+
+WebKitGeolocationPermissionRequest* webkitGeolocationPermissionRequestCreate(WKGeolocationPermissionRequestRef);
+
+#endif // WebKitGeolocationPermissionRequestPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h (119474 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h	2012-06-05 09:46:21 UTC (rev 119475)
@@ -31,6 +31,7 @@
 #include <WebKit2/WKFindOptions.h>
 #include <WebKit2/WKFullScreenClientGtk.h>
 #include <WebKit2/WKGeolocationManager.h>
+#include <WebKit2/WKGeolocationPermissionRequest.h>
 #include <WebKit2/WKGeolocationPosition.h>
 #include <WebKit2/WKInspector.h>
 #include <WebKit2/WKInspectorClientGtk.h>

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp (119474 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp	2012-06-05 09:46:21 UTC (rev 119475)
@@ -21,6 +21,7 @@
 #include "WebKitUIClient.h"
 
 #include "WebKitFileChooserRequestPrivate.h"
+#include "WebKitGeolocationPermissionRequestPrivate.h"
 #include "WebKitPrivate.h"
 #include "WebKitWebViewBasePrivate.h"
 #include "WebKitWebViewPrivate.h"
@@ -144,6 +145,12 @@
     webkitWebViewRunFileChooserRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
 }
 
+static void decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKGeolocationPermissionRequestRef request, const void* clientInfo)
+{
+    GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(request));
+    webkitWebViewMakePermissionRequest(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get()));
+}
+
 void attachUIClientToView(WebKitWebView* webView)
 {
     WKPageUIClient wkUIClient = {
@@ -178,7 +185,7 @@
         0, // pageDidScroll
         0, // exceededDatabaseQuota
         runOpenPanel,
-        0, // decidePolicyForGeolocationPermissionRequest
+        decidePolicyForGeolocationPermissionRequest,
         0, // headerHeight
         0, // footerHeight
         0, // drawHeader

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (119474 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2012-06-05 09:46:21 UTC (rev 119475)
@@ -22,6 +22,7 @@
     <xi:include href=""
     <xi:include href=""
     <xi:include href=""
+    <xi:include href=""
     <xi:include href=""
     <xi:include href=""
     <xi:include href=""

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (119474 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-06-05 09:46:21 UTC (rev 119475)
@@ -388,6 +388,24 @@
 </SECTION>
 
 <SECTION>
+<FILE>WebKitGeolocationPermissionRequest</FILE>
+WebKitGeolocationPermissionRequest
+
+<SUBSECTION Standard>
+WebKitGeolocationPermissionRequestClass
+WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST
+WEBKIT_GEOLOCATION_PERMISSION_REQUEST
+WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST
+WEBKIT_GEOLOCATION_PERMISSION_REQUEST_CLASS
+WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST_CLASS
+WEBKIT_GEOLOCATION_PERMISSION_REQUEST_GET_CLASS
+
+<SUBSECTION Private>
+WebKitGeolocationPermissionRequestPrivate
+webkit_geolocation_permission_request_get_type
+</SECTION>
+
+<SECTION>
 <FILE>WebKitPolicyDecision</FILE>
 WebKitPolicyDecision
 webkit_policy_decision_download

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp (119474 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp	2012-06-05 09:46:21 UTC (rev 119475)
@@ -19,6 +19,8 @@
 
 #include "config.h"
 #include "WebViewTest.h"
+#include <_javascript_Core/JSStringRef.h>
+#include <_javascript_Core/JSValueRef.h>
 #include <wtf/HashSet.h>
 #include <wtf/gobject/GRefPtr.h>
 #include <wtf/text/StringHash.h>
@@ -278,15 +280,30 @@
         g_main_loop_quit(test->m_mainLoop);
     }
 
+    static gboolean permissionRequested(WebKitWebView*, WebKitPermissionRequest* request, UIClientTest* test)
+    {
+        g_assert(WEBKIT_IS_PERMISSION_REQUEST(request));
+        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request));
+
+        if (test->m_allowPermissionRequests)
+            webkit_permission_request_allow(request);
+        else
+            webkit_permission_request_deny(request);
+
+        return TRUE;
+    }
+
     UIClientTest()
         : m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT)
         , m_scriptDialogConfirmed(true)
+        , m_allowPermissionRequests(false)
         , m_mouseTargetModifiers(0)
     {
         webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE);
         g_signal_connect(m_webView, "create", G_CALLBACK(viewCreate), this);
         g_signal_connect(m_webView, "script-dialog", G_CALLBACK(scriptDialog), this);
         g_signal_connect(m_webView, "mouse-target-changed", G_CALLBACK(mouseTargetChanged), this);
+        g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequested), this);
     }
 
     ~UIClientTest()
@@ -314,6 +331,7 @@
     Vector<WebViewEvents> m_webViewEvents;
     WebKitScriptDialogType m_scriptDialogType;
     bool m_scriptDialogConfirmed;
+    bool m_allowPermissionRequests;
     WindowProperties m_windowProperties;
     HashSet<WTF::String> m_windowPropertiesChanged;
     GRefPtr<WebKitHitTestResult> m_mouseTargetHitTestResult;
@@ -449,6 +467,42 @@
     g_assert(!test->m_mouseTargetModifiers);
 }
 
+static void testWebViewPermissionRequests(UIClientTest* test, gconstpointer)
+{
+    test->showInWindowAndWaitUntilMapped();
+    static const char* geolocationRequestHTML =
+        "<html>"
+        "  <script>"
+        "  function runTest()"
+        "  {"
+        "    navigator.geolocation.getCurrentPosition(function(p) { document.title = \"OK\" },"
+        "                                             function(e) { document.title = e.code });"
+        "  }"
+        "  </script>"
+        "  <body _onload_='runTest();'></body>"
+        "</html>";
+
+    // Test denying a permission request.
+    test->m_allowPermissionRequests = false;
+    test->loadHtml(geolocationRequestHTML, 0);
+    test->waitUntilTitleChanged();
+
+    // According to the Geolocation API specification, '1' is the
+    // error code returned for the PERMISSION_DENIED error.
+    // http://dev.w3.org/geo/api/spec-source.html#position_error_interface
+    const gchar* result = webkit_web_view_get_title(test->m_webView);
+    g_assert_cmpstr(result, ==, "1");
+
+    // Test allowing a permission request.
+    test->m_allowPermissionRequests = true;
+    test->loadHtml(geolocationRequestHTML, 0);
+    test->waitUntilTitleChanged();
+
+    // Check that we did not get the PERMISSION_DENIED error now.
+    result = webkit_web_view_get_title(test->m_webView);
+    g_assert_cmpstr(result, !=, "1");
+}
+
 static void testWebViewZoomLevel(WebViewTest* test, gconstpointer)
 {
     g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 1);
@@ -730,6 +784,7 @@
     UIClientTest::add("WebKitWebView", "_javascript_-dialogs", testWebViewJavaScriptDialogs);
     UIClientTest::add("WebKitWebView", "window-properties", testWebViewWindowProperties);
     UIClientTest::add("WebKitWebView", "mouse-target", testWebViewMouseTarget);
+    UIClientTest::add("WebKitWebView", "permission-requests", testWebViewPermissionRequests);
     WebViewTest::add("WebKitWebView", "zoom-level", testWebViewZoomLevel);
     WebViewTest::add("WebKitWebView", "run-_javascript_", testWebViewRunJavaScript);
     FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h (119474 => 119475)


--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-06-05 09:46:21 UTC (rev 119475)
@@ -33,6 +33,7 @@
 #include <webkit2/WebKitError.h>
 #include <webkit2/WebKitFileChooserRequest.h>
 #include <webkit2/WebKitFindController.h>
+#include <webkit2/WebKitGeolocationPermissionRequest.h>
 #include <webkit2/WebKitHitTestResult.h>
 #include <webkit2/WebKitJavascriptResult.h>
 #include <webkit2/WebKitMimeInfo.h>

Modified: trunk/Tools/ChangeLog (119474 => 119475)


--- trunk/Tools/ChangeLog	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Tools/ChangeLog	2012-06-05 09:46:21 UTC (rev 119475)
@@ -1,3 +1,20 @@
+2012-06-05  Mario Sanchez Prada  <[email protected]>
+
+        [GTK][WK2] Implement API for Geolocation permission requests in the GTK port
+        https://bugs.webkit.org/show_bug.cgi?id=83879
+
+        Reviewed by Carlos Garcia Campos.
+
+        Make minibrowser connect to the new 'permission requests' signal
+        to allow users handle the Geolocation permission requests.
+
+        * MiniBrowser/gtk/BrowserWindow.c:
+        (geolocationRequestDialogCallback): Callback for the dialog asking
+        the user for allowing or not geolocation permission requests.
+        (webViewDecidePermissionRequest): Launch a dialog to ask the user
+        whether to allow or deny geolocation permission requests.
+        (browserWindowConstructed): Connect to 'permission-request' signal.
+
 2012-06-04  Chase Phillips  <[email protected]>
 
         Make a builder group support+expect multiple loads.

Modified: trunk/Tools/MiniBrowser/gtk/BrowserWindow.c (119474 => 119475)


--- trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2012-06-05 09:37:41 UTC (rev 119474)
+++ trunk/Tools/MiniBrowser/gtk/BrowserWindow.c	2012-06-05 09:46:21 UTC (rev 119475)
@@ -213,6 +213,21 @@
     browserWindowUpdateNavigationActions(window, backForwadlist);
 }
 
+static void geolocationRequestDialogCallback(GtkDialog *dialog, gint response, WebKitPermissionRequest *request)
+{
+    switch (response) {
+    case GTK_RESPONSE_YES:
+        webkit_permission_request_allow(request);
+        break;
+    default:
+        webkit_permission_request_deny(request);
+        break;
+    }
+
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+    g_object_unref(request);
+}
+
 static void webViewClose(WebKitWebView *webView, BrowserWindow *window)
 {
     gtk_widget_destroy(GTK_WIDGET(window));
@@ -277,6 +292,24 @@
     return TRUE;
 }
 
+static gboolean webViewDecidePermissionRequest(WebKitWebView *webView, WebKitPermissionRequest *request, BrowserWindow *window)
+{
+    if (!WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(request))
+        return FALSE;
+
+    GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window),
+                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                                               GTK_MESSAGE_QUESTION,
+                                               GTK_BUTTONS_YES_NO,
+                                               "Geolocation request");
+
+    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "Allow geolocation request?");
+    g_signal_connect(dialog, "response", G_CALLBACK(geolocationRequestDialogCallback), g_object_ref(request));
+    gtk_widget_show(dialog);
+
+    return TRUE;
+}
+
 static void webViewMouseTargetChanged(WebKitWebView *webView, WebKitHitTestResult *hitTestResult, guint mouseModifiers, BrowserWindow *window)
 {
     if (!webkit_hit_test_result_context_is_link(hitTestResult)) {
@@ -434,6 +467,7 @@
     g_signal_connect(window->webView, "create", G_CALLBACK(webViewCreate), window);
     g_signal_connect(window->webView, "load-failed", G_CALLBACK(webViewLoadFailed), window);
     g_signal_connect(window->webView, "decide-policy", G_CALLBACK(webViewDecidePolicy), window);
+    g_signal_connect(window->webView, "permission-request", G_CALLBACK(webViewDecidePermissionRequest), window);
     g_signal_connect(window->webView, "mouse-target-changed", G_CALLBACK(webViewMouseTargetChanged), window);
     g_signal_connect(window->webView, "notify::zoom-level", G_CALLBACK(webViewZoomLevelChanged), window);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to