Changeset 119475 in webkit


Ignore:
Timestamp:
Jun 5, 2012 2:46:21 AM (12 years ago)
Author:
mario@webkit.org
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.

Location:
trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r119423 r119475  
     12012-06-05  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [GTK][WK2] Implement API for Geolocation permission requests in the GTK port
     4        https://bugs.webkit.org/show_bug.cgi?id=83879
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Added a new kind of permission request for supporting the
     9        Geolocation API in WebKit2GTK+.
     10
     11        New WebKitGeolocationPermissionRequest class, implementing the
     12        WebKitPermissionRequest interface, to enabling client applications
     13        to allow or deny geolocation permission requests.
     14
     15        * GNUmakefile.list.am: Added new files.
     16        * UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp: Added.
     17        (_WebKitGeolocationPermissionRequestPrivate):
     18        (webkitGeolocationPermissionRequestAllow):
     19        (webkitGeolocationPermissionRequestDeny):
     20        (webkit_permission_request_interface_init):
     21        (webkit_geolocation_permission_request_init):
     22        (webkitGeolocationPermissionRequestFinalize):
     23        (webkit_geolocation_permission_request_class_init):
     24        (webkitGeolocationPermissionRequestCreate):
     25        * UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h: Added.
     26        (_WebKitGeolocationPermissionRequest):
     27        (_WebKitGeolocationPermissionRequestClass):
     28        * UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h: Added.
     29
     30        Include WKGeolocationPermissionRequest.h in WebKitPrivate.h, so we
     31        can use it from the new WebKitGeolocationPermissionRequest class.
     32
     33        * UIProcess/API/gtk/WebKitPrivate.h: Added new include.
     34
     35        Implement geolocation permission requests in the UI client.
     36
     37        * UIProcess/API/gtk/WebKitUIClient.cpp:
     38        (decidePolicyForGeolocationPermissionRequest): Create a new
     39        instance of the WebKitGeolocationPermissionRequest class and call
     40        to webkitWebViewMakePermissionRequest().
     41        (attachUIClientToView): Provide an implementation function for
     42        decidePolicyForGeolocationPermissionRequest.
     43        * UIProcess/API/gtk/WebKitWebView.h: Add new element to
     44        WebKitPermissionRequestType enumeration for geolocation requests.
     45        * UIProcess/API/gtk/webkit2.h: Added header file for
     46        WebKitGeolocationPermissionRequest
     47
     48        New unit tests to test allowing and denying permission requests.
     49
     50        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     51        (testWebViewPermissionRequests): New test that loads a simple HTML
     52        with JavaScript code requesting the current location.
     53        (beforeAll): Added new test.
     54
     55        Updated documentation files.
     56
     57        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
     58        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
     59
    1602012-06-04  Sadrul Habib Chowdhury  <sadrul@chromium.org>
    261
  • trunk/Source/WebKit2/GNUmakefile.list.am

    r119404 r119475  
    9696        $(WebKit2)/UIProcess/API/gtk/WebKitFileChooserRequest.h \
    9797        $(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
     98        $(WebKit2)/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h \
    9899        $(WebKit2)/UIProcess/API/gtk/WebKitHitTestResult.h \
    99100        $(WebKit2)/UIProcess/API/gtk/WebKitJavascriptResult.h \
     
    514515        Source/WebKit2/UIProcess/API/C/WKGeolocationManager.cpp \
    515516        Source/WebKit2/UIProcess/API/C/WKGeolocationManager.h \
     517        Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.cpp \
    516518        Source/WebKit2/UIProcess/API/C/WKGeolocationPermissionRequest.h \
    517519        Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp \
     
    585587        Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.cpp \
    586588        Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.h \
     589        Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp \
     590        Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h \
     591        Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequestPrivate.h \
    587592        Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.cpp \
    588593        Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationProvider.h \
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h

    r119404 r119475  
    3232#include <WebKit2/WKFullScreenClientGtk.h>
    3333#include <WebKit2/WKGeolocationManager.h>
     34#include <WebKit2/WKGeolocationPermissionRequest.h>
    3435#include <WebKit2/WKGeolocationPosition.h>
    3536#include <WebKit2/WKInspector.h>
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp

    r118795 r119475  
    2222
    2323#include "WebKitFileChooserRequestPrivate.h"
     24#include "WebKitGeolocationPermissionRequestPrivate.h"
    2425#include "WebKitPrivate.h"
    2526#include "WebKitWebViewBasePrivate.h"
     
    143144    GRefPtr<WebKitFileChooserRequest> request = adoptGRef(webkitFileChooserRequestCreate(parameters, listener));
    144145    webkitWebViewRunFileChooserRequest(WEBKIT_WEB_VIEW(clientInfo), request.get());
     146}
     147
     148static void decidePolicyForGeolocationPermissionRequest(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKGeolocationPermissionRequestRef request, const void* clientInfo)
     149{
     150    GRefPtr<WebKitGeolocationPermissionRequest> geolocationPermissionRequest = adoptGRef(webkitGeolocationPermissionRequestCreate(request));
     151    webkitWebViewMakePermissionRequest(WEBKIT_WEB_VIEW(clientInfo), WEBKIT_PERMISSION_REQUEST(geolocationPermissionRequest.get()));
    145152}
    146153
     
    179186        0, // exceededDatabaseQuota
    180187        runOpenPanel,
    181         0, // decidePolicyForGeolocationPermissionRequest
     188        decidePolicyForGeolocationPermissionRequest,
    182189        0, // headerHeight
    183190        0, // footerHeight
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

    r118522 r119475  
    2323    <xi:include href="xml/WebKitDownload.xml"/>
    2424    <xi:include href="xml/WebKitPermissionRequest.xml"/>
     25    <xi:include href="xml/WebKitGeolocationPermissionRequest.xml"/>
    2526    <xi:include href="xml/WebKitPolicyDecision.xml"/>
    2627    <xi:include href="xml/WebKitNavigationPolicyDecision.xml"/>
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r119108 r119475  
    389389
    390390<SECTION>
     391<FILE>WebKitGeolocationPermissionRequest</FILE>
     392WebKitGeolocationPermissionRequest
     393
     394<SUBSECTION Standard>
     395WebKitGeolocationPermissionRequestClass
     396WEBKIT_TYPE_GEOLOCATION_PERMISSION_REQUEST
     397WEBKIT_GEOLOCATION_PERMISSION_REQUEST
     398WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST
     399WEBKIT_GEOLOCATION_PERMISSION_REQUEST_CLASS
     400WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST_CLASS
     401WEBKIT_GEOLOCATION_PERMISSION_REQUEST_GET_CLASS
     402
     403<SUBSECTION Private>
     404WebKitGeolocationPermissionRequestPrivate
     405webkit_geolocation_permission_request_get_type
     406</SECTION>
     407
     408<SECTION>
    391409<FILE>WebKitPolicyDecision</FILE>
    392410WebKitPolicyDecision
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r118904 r119475  
    2020#include "config.h"
    2121#include "WebViewTest.h"
     22#include <JavaScriptCore/JSStringRef.h>
     23#include <JavaScriptCore/JSValueRef.h>
    2224#include <wtf/HashSet.h>
    2325#include <wtf/gobject/GRefPtr.h>
     
    279281    }
    280282
     283    static gboolean permissionRequested(WebKitWebView*, WebKitPermissionRequest* request, UIClientTest* test)
     284    {
     285        g_assert(WEBKIT_IS_PERMISSION_REQUEST(request));
     286        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request));
     287
     288        if (test->m_allowPermissionRequests)
     289            webkit_permission_request_allow(request);
     290        else
     291            webkit_permission_request_deny(request);
     292
     293        return TRUE;
     294    }
     295
    281296    UIClientTest()
    282297        : m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT)
    283298        , m_scriptDialogConfirmed(true)
     299        , m_allowPermissionRequests(false)
    284300        , m_mouseTargetModifiers(0)
    285301    {
     
    288304        g_signal_connect(m_webView, "script-dialog", G_CALLBACK(scriptDialog), this);
    289305        g_signal_connect(m_webView, "mouse-target-changed", G_CALLBACK(mouseTargetChanged), this);
     306        g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequested), this);
    290307    }
    291308
     
    315332    WebKitScriptDialogType m_scriptDialogType;
    316333    bool m_scriptDialogConfirmed;
     334    bool m_allowPermissionRequests;
    317335    WindowProperties m_windowProperties;
    318336    HashSet<WTF::String> m_windowPropertiesChanged;
     
    450468}
    451469
     470static void testWebViewPermissionRequests(UIClientTest* test, gconstpointer)
     471{
     472    test->showInWindowAndWaitUntilMapped();
     473    static const char* geolocationRequestHTML =
     474        "<html>"
     475        "  <script>"
     476        "  function runTest()"
     477        "  {"
     478        "    navigator.geolocation.getCurrentPosition(function(p) { document.title = \"OK\" },"
     479        "                                             function(e) { document.title = e.code });"
     480        "  }"
     481        "  </script>"
     482        "  <body onload='runTest();'></body>"
     483        "</html>";
     484
     485    // Test denying a permission request.
     486    test->m_allowPermissionRequests = false;
     487    test->loadHtml(geolocationRequestHTML, 0);
     488    test->waitUntilTitleChanged();
     489
     490    // According to the Geolocation API specification, '1' is the
     491    // error code returned for the PERMISSION_DENIED error.
     492    // http://dev.w3.org/geo/api/spec-source.html#position_error_interface
     493    const gchar* result = webkit_web_view_get_title(test->m_webView);
     494    g_assert_cmpstr(result, ==, "1");
     495
     496    // Test allowing a permission request.
     497    test->m_allowPermissionRequests = true;
     498    test->loadHtml(geolocationRequestHTML, 0);
     499    test->waitUntilTitleChanged();
     500
     501    // Check that we did not get the PERMISSION_DENIED error now.
     502    result = webkit_web_view_get_title(test->m_webView);
     503    g_assert_cmpstr(result, !=, "1");
     504}
     505
    452506static void testWebViewZoomLevel(WebViewTest* test, gconstpointer)
    453507{
     
    731785    UIClientTest::add("WebKitWebView", "window-properties", testWebViewWindowProperties);
    732786    UIClientTest::add("WebKitWebView", "mouse-target", testWebViewMouseTarget);
     787    UIClientTest::add("WebKitWebView", "permission-requests", testWebViewPermissionRequests);
    733788    WebViewTest::add("WebKitWebView", "zoom-level", testWebViewZoomLevel);
    734789    WebViewTest::add("WebKitWebView", "run-javascript", testWebViewRunJavaScript);
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h

    r118794 r119475  
    3434#include <webkit2/WebKitFileChooserRequest.h>
    3535#include <webkit2/WebKitFindController.h>
     36#include <webkit2/WebKitGeolocationPermissionRequest.h>
    3637#include <webkit2/WebKitHitTestResult.h>
    3738#include <webkit2/WebKitJavascriptResult.h>
  • trunk/Tools/ChangeLog

    r119463 r119475  
     12012-06-05  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        [GTK][WK2] Implement API for Geolocation permission requests in the GTK port
     4        https://bugs.webkit.org/show_bug.cgi?id=83879
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Make minibrowser connect to the new 'permission requests' signal
     9        to allow users handle the Geolocation permission requests.
     10
     11        * MiniBrowser/gtk/BrowserWindow.c:
     12        (geolocationRequestDialogCallback): Callback for the dialog asking
     13        the user for allowing or not geolocation permission requests.
     14        (webViewDecidePermissionRequest): Launch a dialog to ask the user
     15        whether to allow or deny geolocation permission requests.
     16        (browserWindowConstructed): Connect to 'permission-request' signal.
     17
    1182012-06-04  Chase Phillips  <cmp@google.com>
    219
  • trunk/Tools/MiniBrowser/gtk/BrowserWindow.c

    r117735 r119475  
    214214}
    215215
     216static void geolocationRequestDialogCallback(GtkDialog *dialog, gint response, WebKitPermissionRequest *request)
     217{
     218    switch (response) {
     219    case GTK_RESPONSE_YES:
     220        webkit_permission_request_allow(request);
     221        break;
     222    default:
     223        webkit_permission_request_deny(request);
     224        break;
     225    }
     226
     227    gtk_widget_destroy(GTK_WIDGET(dialog));
     228    g_object_unref(request);
     229}
     230
    216231static void webViewClose(WebKitWebView *webView, BrowserWindow *window)
    217232{
     
    278293}
    279294
     295static gboolean webViewDecidePermissionRequest(WebKitWebView *webView, WebKitPermissionRequest *request, BrowserWindow *window)
     296{
     297    if (!WEBKIT_IS_GEOLOCATION_PERMISSION_REQUEST(request))
     298        return FALSE;
     299
     300    GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(window),
     301                                               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
     302                                               GTK_MESSAGE_QUESTION,
     303                                               GTK_BUTTONS_YES_NO,
     304                                               "Geolocation request");
     305
     306    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "Allow geolocation request?");
     307    g_signal_connect(dialog, "response", G_CALLBACK(geolocationRequestDialogCallback), g_object_ref(request));
     308    gtk_widget_show(dialog);
     309
     310    return TRUE;
     311}
     312
    280313static void webViewMouseTargetChanged(WebKitWebView *webView, WebKitHitTestResult *hitTestResult, guint mouseModifiers, BrowserWindow *window)
    281314{
     
    435468    g_signal_connect(window->webView, "load-failed", G_CALLBACK(webViewLoadFailed), window);
    436469    g_signal_connect(window->webView, "decide-policy", G_CALLBACK(webViewDecidePolicy), window);
     470    g_signal_connect(window->webView, "permission-request", G_CALLBACK(webViewDecidePermissionRequest), window);
    437471    g_signal_connect(window->webView, "mouse-target-changed", G_CALLBACK(webViewMouseTargetChanged), window);
    438472    g_signal_connect(window->webView, "notify::zoom-level", G_CALLBACK(webViewZoomLevelChanged), window);
Note: See TracChangeset for help on using the changeset viewer.