Changeset 177073 in webkit


Ignore:
Timestamp:
Dec 10, 2014 9:36:40 AM (9 years ago)
Author:
Gustavo Noronha Silva
Message:

[GTK][WK2] Add HTML5 Notifications support
https://bugs.webkit.org/show_bug.cgi?id=61140

.:

Patch by Gustavo Noronha Silva <gustavo.noronha@collabora.com> on 2014-12-09
Reviewed by Carlos Garcia Campos.

  • Source/cmake/FindLibNotify.cmake: Added.
  • Source/cmake/OptionsGTK.cmake: add option to enable notifications, look for

libnotify and use it for a default implementation when found.

Source/WebKit2:

Patch by Claudio Saavedra <Claudio Saavedra> and Gustavo Noronha Silva <gustavo.noronha@collabora.com> on 2014-12-09
Reviewed by Carlos Garcia Campos.

  • PlatformGTK.cmake: add new files to the build.
  • UIProcess/API/gtk/WebKitForwardDeclarations.h:
  • UIProcess/API/gtk/WebKitNotification.cpp: Added. New GObject used to expose information about

the notification to the API.
(webkitNotificationGetProperty):
(webkit_notification_class_init):
(webkitNotificationCreate):
(webkit_notification_get_id):
(webkit_notification_get_title):
(webkit_notification_get_body):

  • UIProcess/API/gtk/WebKitNotification.h: Added.
  • UIProcess/API/gtk/WebKitNotificationPermissionRequest.cpp: Added. Permission request object

for notifications.
(webkitNotificationPermissionRequestAllow):
(webkitNotificationPermissionRequestDeny):
(webkit_permission_request_interface_init):
(webkitNotificationPermissionRequestDispose):
(webkit_notification_permission_request_class_init):
(webkitNotificationPermissionRequestCreate):

  • UIProcess/API/gtk/WebKitNotificationPermissionRequest.h: Added.
  • UIProcess/API/gtk/WebKitNotificationPermissionRequestPrivate.h: Added.
  • UIProcess/API/gtk/WebKitNotificationPrivate.h: Added.
  • UIProcess/API/gtk/WebKitNotificationProvider.cpp: Added. Notification provider that emits signals.

The C API allows overriding the notification providers and managers for customizing the handling of
notifications. We decided to go for a single manager and a single provider which provide more idiomatic
GObject API - signals.
(toNotificationProvider):
(showCallback):
(cancelCallback):
(WebKitNotificationProvider::~WebKitNotificationProvider):
(WebKitNotificationProvider::create):
(WebKitNotificationProvider::WebKitNotificationProvider):
(WebKitNotificationProvider::show):
(WebKitNotificationProvider::cancel):

  • UIProcess/API/gtk/WebKitNotificationProvider.h: Added.
  • UIProcess/API/gtk/WebKitUIClient.cpp: implemented decidePolicyForNotificationPermissionRequest.
  • UIProcess/API/gtk/WebKitWebContext.cpp:

(webkitWebContextConstructed): initialize the notification provider.

  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkitWebViewShowNotification): default implementation for showing the notification, currently
using GNotification, about to be ported to libnotify.
(webkit_web_view_class_init): set the default implementation for the show-notification signal.
(webkitWebViewEmitCloseNotification): emit the close-notification signal.
(webkitWebViewEmitShowNotification): emit the show-notification signal.

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/WebKitWebViewPrivate.h:
  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt: list new objects and methods.
  • UIProcess/API/gtk/webkit2.h: include new headers.

Tools:

Patch by Gustavo Noronha Silva <gustavo.noronha@collabora.com> on 2014-12-09
Reviewed by Carlos Garcia Campos.

  • Scripts/webkitperl/FeatureList.pm: enable notifications for GTK+.
  • TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:

(testWebViewNotification):
(beforeAll):

  • MiniBrowser/gtk/BrowserWindow.c: also handle notification permission requests.

(permissionRequestDialogCallback):
(webViewDecidePermissionRequest):
(geolocationRequestDialogCallback): Deleted.

LayoutTests:

Patch by Gustavo Noronha Silva <gustavo.noronha@collabora.com> on 2014-12-09
Reviewed by Carlos Garcia Campos.

  • platform/gtk/TestExpectations: unskip the HTTP tests for new-style notifications.
Location:
trunk
Files:
9 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r177049 r177073  
     12014-12-09  Gustavo Noronha Silva  <gustavo.noronha@collabora.com>
     2
     3        [GTK][WK2] Add HTML5 Notifications support
     4        https://bugs.webkit.org/show_bug.cgi?id=61140
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * Source/cmake/FindLibNotify.cmake: Added.
     9        * Source/cmake/OptionsGTK.cmake: add option to enable notifications, look for
     10        libnotify and use it for a default implementation when found.
     11
    1122014-12-09  Bem Jones-Bey  <bjonesbe@adobe.com>
    213
  • trunk/LayoutTests/ChangeLog

    r177054 r177073  
     12014-12-09  Gustavo Noronha Silva  <gustavo.noronha@collabora.com>
     2
     3        [GTK][WK2] Add HTML5 Notifications support
     4        https://bugs.webkit.org/show_bug.cgi?id=61140
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * platform/gtk/TestExpectations: unskip the HTTP tests for new-style notifications.
     9
    1102014-12-09  Alexey Proskuryakov  <ap@apple.com>
    211
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r176922 r177073  
    147147webkit.org/b/98927 fast/dom/DeviceOrientation [ Skip ]
    148148
    149 # Desktop notifications are not yet supported.
    150 webkit.org/b/61140 fast/notifications [ Skip ]
    151 webkit.org/b/61140 http/tests/notifications [ Skip ]
     149# https://bugs.webkit.org/show_bug.cgi?id=81697 Skip file:// based notifications tests
     150fast/notifications
     151
     152# we do not enable legacy notifications
     153http/tests/notifications/legacy/window-show-on-click.html
     154http/tests/notifications/legacy/request.html
     155http/tests/notifications/legacy/request-no-callback.html
     156http/tests/notifications/legacy/events.html
     157http/tests/notifications/legacy/show.html
     158http/tests/notifications/legacy/double-show.html
    152159
    153160# StorageTracker is not enabled.
  • trunk/Source/WebKit2/ChangeLog

    r177057 r177073  
     12014-12-09  Claudio Saavedra  <csaavedra@igalia.com> and Gustavo Noronha Silva  <gustavo.noronha@collabora.com>
     2
     3        [GTK][WK2] Add HTML5 Notifications support
     4        https://bugs.webkit.org/show_bug.cgi?id=61140
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * PlatformGTK.cmake: add new files to the build.
     9        * UIProcess/API/gtk/WebKitForwardDeclarations.h:
     10        * UIProcess/API/gtk/WebKitNotification.cpp: Added. New GObject used to expose information about
     11        the notification to the API.
     12        (webkitNotificationGetProperty):
     13        (webkit_notification_class_init):
     14        (webkitNotificationCreate):
     15        (webkit_notification_get_id):
     16        (webkit_notification_get_title):
     17        (webkit_notification_get_body):
     18        * UIProcess/API/gtk/WebKitNotification.h: Added.
     19        * UIProcess/API/gtk/WebKitNotificationPermissionRequest.cpp: Added. Permission request object
     20        for notifications.
     21        (webkitNotificationPermissionRequestAllow):
     22        (webkitNotificationPermissionRequestDeny):
     23        (webkit_permission_request_interface_init):
     24        (webkitNotificationPermissionRequestDispose):
     25        (webkit_notification_permission_request_class_init):
     26        (webkitNotificationPermissionRequestCreate):
     27        * UIProcess/API/gtk/WebKitNotificationPermissionRequest.h: Added.
     28        * UIProcess/API/gtk/WebKitNotificationPermissionRequestPrivate.h: Added.
     29        * UIProcess/API/gtk/WebKitNotificationPrivate.h: Added.
     30        * UIProcess/API/gtk/WebKitNotificationProvider.cpp: Added. Notification provider that emits signals.
     31        The C API allows overriding the notification providers and managers for customizing the handling of
     32        notifications. We decided to go for a single manager and a single provider which provide more idiomatic
     33        GObject API - signals.
     34        (toNotificationProvider):
     35        (showCallback):
     36        (cancelCallback):
     37        (WebKitNotificationProvider::~WebKitNotificationProvider):
     38        (WebKitNotificationProvider::create):
     39        (WebKitNotificationProvider::WebKitNotificationProvider):
     40        (WebKitNotificationProvider::show):
     41        (WebKitNotificationProvider::cancel):
     42        * UIProcess/API/gtk/WebKitNotificationProvider.h: Added.
     43        * UIProcess/API/gtk/WebKitUIClient.cpp: implemented decidePolicyForNotificationPermissionRequest.
     44        * UIProcess/API/gtk/WebKitWebContext.cpp:
     45        (webkitWebContextConstructed): initialize the notification provider.
     46        * UIProcess/API/gtk/WebKitWebView.cpp:
     47        (webkitWebViewShowNotification): default implementation for showing the notification, currently
     48        using GNotification, about to be ported to libnotify.
     49        (webkit_web_view_class_init): set the default implementation for the show-notification signal.
     50        (webkitWebViewEmitCloseNotification): emit the close-notification signal.
     51        (webkitWebViewEmitShowNotification): emit the show-notification signal.
     52        * UIProcess/API/gtk/WebKitWebView.h:
     53        * UIProcess/API/gtk/WebKitWebViewPrivate.h:
     54        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: list new objects and methods.
     55        * UIProcess/API/gtk/webkit2.h: include new headers.
     56
    1572014-12-10  Grzegorz Czajkowski  <g.czajkowski@samsung.com>
    258
  • trunk/Source/WebKit2/PlatformGTK.cmake

    r177016 r177073  
    159159    UIProcess/API/gtk/WebKitNavigationPolicyDecision.h
    160160    UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h
     161    UIProcess/API/gtk/WebKitNotificationPermissionRequest.cpp
     162    UIProcess/API/gtk/WebKitNotificationPermissionRequest.h
     163    UIProcess/API/gtk/WebKitNotificationPermissionRequestPrivate.h
     164    UIProcess/API/gtk/WebKitNotificationProvider.cpp
     165    UIProcess/API/gtk/WebKitNotificationProvider.h
     166    UIProcess/API/gtk/WebKitNotification.cpp
     167    UIProcess/API/gtk/WebKitNotification.h
     168    UIProcess/API/gtk/WebKitNotificationPrivate.h
    161169    UIProcess/API/gtk/WebKitPermissionRequest.cpp
    162170    UIProcess/API/gtk/WebKitPermissionRequest.h
     
    352360    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitNavigationAction.h
    353361    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h
     362    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitNotificationPermissionRequest.h
     363    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitNotification.h
    354364    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitPermissionRequest.h
    355365    ${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitPlugin.h
     
    456466)
    457467
     468if (LIBNOTIFY_FOUND)
     469list(APPEND WebKit2_INCLUDE_DIRECTORIES
     470    ${LIBNOTIFY_INCLUDE_DIRS}
     471)
     472endif ()
     473
    458474set(WebKit2CommonIncludeDirectories ${WebKit2_INCLUDE_DIRECTORIES})
    459475
     
    490506    ${GTK_UNIX_PRINT_LIBRARIES}
    491507)
     508
     509if (LIBNOTIFY_FOUND)
     510list(APPEND WebKit2_LIBRARIES
     511    ${LIBNOTIFY_LIBRARIES}
     512)
     513endif ()
     514
    492515ADD_WHOLE_ARCHIVE_TO_LIBRARIES(WebKit2_LIBRARIES)
    493516
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h

    r175694 r177073  
    3636typedef struct _WebKitContextMenu     WebKitContextMenu;
    3737typedef struct _WebKitContextMenuItem WebKitContextMenuItem;
     38typedef struct _WebKitNotification    WebKitNotification;
    3839
    3940#endif // WebKitForward_h
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitUIClient.cpp

    r176952 r177073  
    2525#include "WebKitGeolocationPermissionRequestPrivate.h"
    2626#include "WebKitNavigationActionPrivate.h"
     27#include "WebKitNotificationPermissionRequestPrivate.h"
    2728#include "WebKitPrivate.h"
    2829#include "WebKitURIRequestPrivate.h"
     
    167168    }
    168169
     170    virtual bool decidePolicyForNotificationPermissionRequest(WebPageProxy*, WebSecurityOrigin*, NotificationPermissionRequest* permissionRequest) override
     171    {
     172        GRefPtr<WebKitNotificationPermissionRequest> notificationPermissionRequest = adoptGRef(webkitNotificationPermissionRequestCreate(permissionRequest));
     173        webkitWebViewMakePermissionRequest(m_webView, WEBKIT_PERMISSION_REQUEST(notificationPermissionRequest.get()));
     174        return true;
     175    }
     176
    169177    virtual void printFrame(WebPageProxy*, WebFrameProxy* frame) override
    170178    {
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

    r176512 r177073  
    3434#include "WebKitGeolocationProvider.h"
    3535#include "WebKitInjectedBundleClient.h"
     36#include "WebKitNotificationProvider.h"
    3637#include "WebKitPluginPrivate.h"
    3738#include "WebKitPrivate.h"
     
    4546#include "WebKitWebViewBasePrivate.h"
    4647#include "WebKitWebViewPrivate.h"
     48#include "WebNotificationManagerProxy.h"
    4749#include "WebResourceCacheManagerProxy.h"
    4850#include <WebCore/FileSystem.h>
     
    167169    RefPtr<WebKitBatteryProvider> batteryProvider;
    168170#endif
     171#if ENABLE(NOTIFICATIONS)
     172    RefPtr<WebKitNotificationProvider> notificationProvider;
     173#endif
    169174#if ENABLE(SPELLCHECK)
    170175    std::unique_ptr<WebKitTextChecker> textChecker;
     
    278283#if ENABLE(BATTERY_STATUS)
    279284    priv->batteryProvider = WebKitBatteryProvider::create(priv->context->supplement<WebBatteryManagerProxy>());
     285#endif
     286#if ENABLE(NOTIFICATIONS)
     287    priv->notificationProvider = WebKitNotificationProvider::create(priv->context->supplement<WebNotificationManagerProxy>());
    280288#endif
    281289#if ENABLE(SPELLCHECK)
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r176513 r177073  
    22 * Copyright (C) 2011 Igalia S.L.
    33 * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
     4 * Copyright (C) 2014 Collabora Ltd.
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    4344#include "WebKitLoaderClient.h"
    4445#include "WebKitMarshal.h"
     46#include "WebKitNotificationPrivate.h"
    4547#include "WebKitPolicyClient.h"
    4648#include "WebKitPrintOperationPrivate.h"
     
    7072#include <wtf/text/CString.h>
    7173
     74#if USE(LIBNOTIFY)
     75#include <libnotify/notify.h>
     76#endif
     77
    7278using namespace WebKit;
    7379using namespace WebCore;
     
    124130
    125131    AUTHENTICATE,
     132
     133    SHOW_NOTIFICATION,
     134    CLOSE_NOTIFICATION,
    126135
    127136    LAST_SIGNAL
     
    145154typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap;
    146155typedef HashMap<uint64_t, GRefPtr<GTask> > SnapshotResultsMap;
     156#if USE(LIBNOTIFY)
     157typedef HashMap<uint64_t, GRefPtr<NotifyNotification>> NotifyNotificationsMap;
     158#endif
    147159class PageLoadStateObserver;
    148160
     
    195207    SnapshotResultsMap snapshotResultsMap;
    196208    GRefPtr<WebKitAuthenticationRequest> authenticationRequest;
     209
     210#if USE(LIBNOTIFY)
     211    NotifyNotificationsMap notifyNotificationsMap;
     212#endif
    197213};
    198214
     
    561577    GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(downloadProxy);
    562578    webkitDownloadSetWebView(download.get(), WEBKIT_WEB_VIEW(webViewBase));
     579}
     580
     581static gboolean webkitWebViewShowNotification(WebKitWebView* webView, WebKitNotification* webNotification)
     582{
     583#if USE(LIBNOTIFY)
     584    if (!notify_is_initted())
     585        notify_init(g_get_prgname());
     586
     587    GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification));
     588    if (!notification) {
     589        notification = adoptGRef(notify_notification_new(webkit_notification_get_title(webNotification),
     590            webkit_notification_get_body(webNotification), nullptr));
     591
     592        webView->priv->notifyNotificationsMap.set(webkit_notification_get_id(webNotification), notification);
     593    } else
     594        notify_notification_update(notification.get(), webkit_notification_get_title(webNotification),
     595            webkit_notification_get_body(webNotification), nullptr);
     596
     597    notify_notification_show(notification.get(), nullptr);
     598    return TRUE;
     599#else
     600    UNUSED_PARAM(webNotification);
     601    return FALSE;
     602#endif
     603}
     604
     605static gboolean webkitWebViewCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)
     606{
     607#if USE(LIBNOTIFY)
     608    if (GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification))) {
     609        notify_notification_close(notification.get(), nullptr);
     610        webView->priv->notifyNotificationsMap.remove(webkit_notification_get_id(webNotification));
     611    }
     612    return TRUE;
     613#else
     614    UNUSED_PARAM(webNotification);
     615    return FALSE;
     616#endif
    563617}
    564618
     
    714768    webViewClass->run_file_chooser = webkitWebViewRunFileChooser;
    715769    webViewClass->authenticate = webkitWebViewAuthenticate;
     770    webViewClass->show_notification = webkitWebViewShowNotification;
     771    webViewClass->close_notification = webkitWebViewCloseNotification;
    716772
    717773    /**
     
    15751631            G_TYPE_BOOLEAN, 1, /* number of parameters */
    15761632            WEBKIT_TYPE_AUTHENTICATION_REQUEST);
     1633
     1634    /**
     1635     * WebKitWebView::show-notification:
     1636     * @web_view: the #WebKitWebView
     1637     * @notification: a #WebKitNofication
     1638     *
     1639     * This signal is emitted when a notification should be presented to the
     1640     * user. The @notification is kept alive until either: 1) the web page cancels it
     1641     * or 2) a navigation happens.
     1642     *
     1643     * The default handler will emit a notification using libnotify, if built with
     1644     * support for it.
     1645     *
     1646     * Returns: %TRUE to stop other handlers from being invoked. %FALSE otherwise.
     1647     *
     1648     * Since: 2.8
     1649     */
     1650    signals[SHOW_NOTIFICATION] =
     1651        g_signal_new("show-notification",
     1652            G_TYPE_FROM_CLASS(gObjectClass),
     1653            G_SIGNAL_RUN_LAST,
     1654            G_STRUCT_OFFSET(WebKitWebViewClass, show_notification),
     1655            g_signal_accumulator_true_handled, nullptr /* accumulator data */,
     1656            webkit_marshal_BOOLEAN__OBJECT,
     1657            G_TYPE_BOOLEAN, 1,
     1658            WEBKIT_TYPE_NOTIFICATION);
     1659
     1660    /**
     1661     * WebKitNotification::close-notification:
     1662     * @web_view: the #WebKitWebView
     1663     * @notification: a #WebKitNofication
     1664     *
     1665     * This signal is emitted when a notification should be withdrawn.
     1666     *
     1667     * The default handler will close the notification using libnotify, if built with
     1668     * support for it.
     1669     *
     1670     * Returns: %TRUE to stop other handlers from being invoked. %FALSE otherwise.
     1671     *
     1672     * Since: 2.8
     1673     */
     1674    signals[CLOSE_NOTIFICATION] =
     1675        g_signal_new("close-notification",
     1676            G_TYPE_FROM_CLASS(gObjectClass),
     1677            G_SIGNAL_RUN_LAST,
     1678            G_STRUCT_OFFSET(WebKitWebViewClass, close_notification),
     1679            g_signal_accumulator_true_handled, nullptr /* accumulator data */,
     1680            webkit_marshal_BOOLEAN__OBJECT,
     1681            G_TYPE_BOOLEAN, 1,
     1682            WEBKIT_TYPE_NOTIFICATION);
    15771683}
    15781684
     
    19562062{
    19572063    g_signal_emit(webView, signals[INSECURE_CONTENT_DETECTED], 0, type);
     2064}
     2065
     2066bool webkitWebViewEmitShowNotification(WebKitWebView* webView, WebKitNotification* webNotification)
     2067{
     2068    gboolean handled;
     2069    g_signal_emit(webView, signals[SHOW_NOTIFICATION], 0, webNotification, &handled);
     2070    return handled;
     2071}
     2072
     2073void webkitWebViewEmitCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)
     2074{
     2075    gboolean handled;
     2076    g_signal_emit(webView, signals[CLOSE_NOTIFICATION], 0, webNotification, &handled);
    19582077}
    19592078
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r173691 r177073  
    239239                                                GTlsCertificate             *certificate,
    240240                                                GTlsCertificateFlags         errors);
     241    gboolean   (* show_notification)           (WebKitWebView               *web_view,
     242                                                WebKitNotification          *notification);
     243    gboolean   (* close_notification)          (WebKitWebView               *web_view,
     244                                                WebKitNotification          *notification);
     245
    241246    void (*_webkit_reserved0) (void);
    242247    void (*_webkit_reserved1) (void);
    243248    void (*_webkit_reserved2) (void);
    244249    void (*_webkit_reserved3) (void);
    245     void (*_webkit_reserved4) (void);
    246     void (*_webkit_reserved5) (void);
    247250};
    248251
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h

    r175694 r177073  
    5858void webkitWebViewHandleAuthenticationChallenge(WebKitWebView*, WebKit::AuthenticationChallengeProxy*);
    5959void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent);
     60bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*);
     61void webkitWebViewEmitCloseNotification(WebKitWebView*, WebKitNotification*);
    6062void webkitWebViewWebProcessCrashed(WebKitWebView*);
    6163
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r176952 r177073  
    617617
    618618<SECTION>
     619<FILE>WebKitNotification</FILE>
     620WebKitNotification
     621webkit_notification_get_id
     622webkit_notification_get_title
     623webkit_notification_get_body
     624
     625<SUBSECTION Standard>
     626WebKitNotificationClass
     627WEBKIT_TYPE_NOTIFICATION
     628WEBKIT_IS_NOTIFICATION
     629WEBKIT_NOTIFICATION
     630WEBKIT_NOTIFICATION_CLASS
     631WEBKIT_IS_NOTIFICATION_CLASS
     632WEBKIT_NOTIFICATION_GET_CLASS
     633
     634<SUBSECTION Private>
     635WebKitNotificationPrivate
     636webkit_notification_get_type
     637</SECTION>
     638
     639<SECTION>
     640<FILE>WebKitNotificationPermissionRequest</FILE>
     641WebKitNotificationPermissionRequest
     642
     643<SUBSECTION Standard>
     644WebKitNotificationPermissionRequestClass
     645WEBKIT_TYPE_NOTIFICATION_PERMISSION_REQUEST
     646WEBKIT_NOTIFICATION_PERMISSION_REQUEST
     647WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST
     648WEBKIT_NOTIFICATION_PERMISSION_REQUEST_CLASS
     649WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST_CLASS
     650WEBKIT_NOTIFICATION_PERMISSION_REQUEST_GET_CLASS
     651
     652<SUBSECTION Private>
     653WebKitNotificationPermissionRequestPrivate
     654webkit_notification_permission_request_get_type
     655</SECTION>
     656
     657<SECTION>
    619658<FILE>WebKitPolicyDecision</FILE>
    620659WebKitPolicyDecision
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h

    r176952 r177073  
    5151#include <webkit2/WebKitNavigationAction.h>
    5252#include <webkit2/WebKitNavigationPolicyDecision.h>
     53#include <webkit2/WebKitNotification.h>
     54#include <webkit2/WebKitNotificationPermissionRequest.h>
    5355#include <webkit2/WebKitPermissionRequest.h>
    5456#include <webkit2/WebKitPlugin.h>
  • trunk/Source/cmake/OptionsGTK.cmake

    r176928 r177073  
    5151find_package(GeoClue2 2.1.5)
    5252find_package(GnuTLS 3.0.0)
     53find_package(LibNotify)
    5354
    5455if (NOT GEOCLUE2_FOUND)
     
    152153WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NAVIGATOR_HWCONCURRENCY ON)
    153154WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API ON)
     155WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NOTIFICATIONS ON)
    154156WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PICTURE_SIZES ON)
    155157WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_QUOTA OFF)
     
    174176WEBKIT_OPTION_END()
    175177
     178if (LIBNOTIFY_FOUND)
     179    add_definitions(-DWTF_USE_LIBNOTIFY=1)
     180else ()
     181    add_definitions(-DWTF_USE_LIBNOTIFY=0)
     182endif ()
     183
    176184if (ENABLE_PLUGIN_PROCESS_GTK2)
    177185    find_package(GTK2 2.24.10 REQUIRED)
  • trunk/Tools/ChangeLog

    r177036 r177073  
     12014-12-09  Gustavo Noronha Silva  <gustavo.noronha@collabora.com>
     2
     3        [GTK][WK2] Add HTML5 Notifications support
     4        https://bugs.webkit.org/show_bug.cgi?id=61140
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * Scripts/webkitperl/FeatureList.pm: enable notifications for GTK+.
     9        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
     10        (testWebViewNotification):
     11        (beforeAll):
     12        * MiniBrowser/gtk/BrowserWindow.c: also handle notification permission requests.
     13        (permissionRequestDialogCallback):
     14        (webViewDecidePermissionRequest):
     15        (geolocationRequestDialogCallback): Deleted.
     16
    1172014-12-09  Benjamin Poulain  <bpoulain@apple.com>
    218
  • trunk/Tools/MiniBrowser/gtk/BrowserWindow.c

    r176952 r177073  
    417417        dialog_message_format = "%s";
    418418        dialog_message = "Allow geolocation request?";
     419    } else if (WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST(request)) {
     420        dialog_title = "Notification request";
     421        dialog_message_format = "%s";
     422        dialog_message = "Allow notifications request?";
    419423    } else if (WEBKIT_IS_USER_MEDIA_PERMISSION_REQUEST(request)) {
    420424        dialog_message_format = "Allow access to %s device?";
  • trunk/Tools/Scripts/webkitperl/FeatureList.pm

    r176712 r177073  
    328328
    329329    { option => "notifications", desc => "Toggle Notifications support",
    330       define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
     330      define => "ENABLE_NOTIFICATIONS", default => isGtk(), value => \$notificationsSupport },
    331331
    332332    { option => "orientation-events", desc => "Toggle Orientation Events support",
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp

    r176513 r177073  
    11/*
    22 * Copyright (C) 2011 Igalia S.L.
     3 * Copyright (C) 2014 Collabora Ltd.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    1920
    2021#include "config.h"
     22#include "WebKitTestServer.h"
    2123#include "WebViewTest.h"
    2224#include <JavaScriptCore/JSStringRef.h>
     
    2426#include <glib/gstdio.h>
    2527#include <wtf/gobject/GRefPtr.h>
     28
     29static WebKitTestServer* gServer;
    2630
    2731static void testWebViewWebContext(WebViewTest* test, gconstpointer)
     
    582586}
    583587
     588class NotificationWebViewTest: public WebViewTest {
     589public:
     590    MAKE_GLIB_TEST_FIXTURE(NotificationWebViewTest);
     591
     592    enum NotificationEvent {
     593        None,
     594        Permission,
     595        Shown,
     596        Cancelled
     597    };
     598
     599    static gboolean permissionRequestCallback(WebKitWebView*, WebKitPermissionRequest *request, NotificationWebViewTest* test)
     600    {
     601        g_assert(WEBKIT_IS_NOTIFICATION_PERMISSION_REQUEST(request));
     602        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request));
     603
     604        test->m_event = Permission;
     605
     606        webkit_permission_request_allow(request);
     607
     608        g_main_loop_quit(test->m_mainLoop);
     609
     610        return TRUE;
     611    }
     612
     613    static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test)
     614    {
     615        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification));
     616        test->m_notification = notification;
     617        test->m_event = Shown;
     618        g_main_loop_quit(test->m_mainLoop);
     619        return TRUE;
     620    }
     621
     622    static gboolean closeNotificationCallback(WebKitWebView*, WebKitNotification*, NotificationWebViewTest* test)
     623    {
     624        test->m_notification = nullptr;
     625        test->m_event = Cancelled;
     626        g_main_loop_quit(test->m_mainLoop);
     627        return TRUE;
     628    }
     629
     630    NotificationWebViewTest()
     631        : m_event(None)
     632    {
     633        g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequestCallback), this);
     634        g_signal_connect(m_webView, "show-notification", G_CALLBACK(showNotificationCallback), this);
     635        g_signal_connect(m_webView, "close-notification", G_CALLBACK(closeNotificationCallback), this);
     636
     637    }
     638
     639    ~NotificationWebViewTest()
     640    {
     641        g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
     642    }
     643
     644   void requestPermissionAndWaitUntilGiven()
     645    {
     646        m_event = None;
     647        webkit_web_view_run_javascript(m_webView, "Notification.requestPermission();", nullptr, nullptr, nullptr);
     648        g_main_loop_run(m_mainLoop);
     649    }
     650
     651    void requestNotificationAndWaitUntilShown(const char* title, const char* body)
     652    {
     653        m_event = None;
     654
     655        GUniquePtr<char> jscode(g_strdup_printf("n = new Notification('%s', { body: '%s'});", title, body));
     656        webkit_web_view_run_javascript(m_webView, jscode.get(), nullptr, nullptr, nullptr);
     657
     658        g_main_loop_run(m_mainLoop);
     659    }
     660
     661    void closeNotificationAndWaitUntilCancelled()
     662    {
     663        m_event = None;
     664        webkit_web_view_run_javascript(m_webView, "n.close()", nullptr, nullptr, nullptr);
     665        g_main_loop_run(m_mainLoop);
     666    }
     667
     668    NotificationEvent m_event;
     669    WebKitNotification* m_notification;
     670};
     671
     672static void testWebViewNotification(NotificationWebViewTest* test, gconstpointer)
     673{
     674    // Notifications don't work with local or special schemes.
     675    test->loadURI(gServer->getURIForPath("/").data());
     676    test->waitUntilLoadFinished();
     677
     678    test->requestPermissionAndWaitUntilGiven();
     679
     680    g_assert(test->m_event == NotificationWebViewTest::Permission);
     681
     682    static const char* title = "This is a notification";
     683    static const char* body = "This is the body.";
     684    test->requestNotificationAndWaitUntilShown(title, body);
     685
     686    g_assert(test->m_event == NotificationWebViewTest::Shown);
     687    g_assert(test->m_notification);
     688    g_assert_cmpstr(webkit_notification_get_title(test->m_notification), ==, title);
     689    g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body);
     690
     691    test->closeNotificationAndWaitUntilCancelled();
     692
     693    g_assert(test->m_event == NotificationWebViewTest::Cancelled);
     694
     695    test->requestNotificationAndWaitUntilShown(title, body);
     696
     697    g_assert(test->m_event == NotificationWebViewTest::Shown);
     698
     699    test->loadURI(gServer->getURIForPath("/").data());
     700    test->waitUntilLoadFinished();
     701
     702    g_assert(test->m_event == NotificationWebViewTest::Cancelled);
     703}
     704
     705static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
     706{
     707    if (message->method != SOUP_METHOD_GET) {
     708        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
     709        return;
     710    }
     711
     712    if (g_str_equal(path, "/")) {
     713        soup_message_set_status(message, SOUP_STATUS_OK);
     714        soup_message_body_complete(message->response_body);
     715    } else
     716        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
     717}
     718
    584719void beforeAll()
    585720{
     721    gServer = new WebKitTestServer();
     722    gServer->run(serverCallback);
     723
    586724    WebViewTest::add("WebKitWebView", "web-context", testWebViewWebContext);
    587725    WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset);
     
    595733    SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot);
    596734    WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility);
     735    NotificationWebViewTest::add("WebKitWebView", "notification", testWebViewNotification);
    597736}
    598737
Note: See TracChangeset for help on using the changeset viewer.