Changeset 179745 in webkit


Ignore:
Timestamp:
Feb 6, 2015 6:50:20 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Remove WebKitWebView::close-notification signal
https://bugs.webkit.org/show_bug.cgi?id=141330

Reviewed by Gustavo Noronha Silva.

Source/WebKit2:

In favor of a WebKitNotification::closed signal and
webkit_notification_close() method that both applications and
WebKit can use to close a notification. This also fixes the
onclose event that was not fired when the notification was
closed. It also brings back padding space in WebKitWebViewClass.

  • UIProcess/API/gtk/WebKitNotification.cpp:

(webkit_notification_class_init): Add WebKitNotification::closed signal.
(webkit_notification_close): Emit WebKitNotification::closed.

  • UIProcess/API/gtk/WebKitNotification.h:
  • UIProcess/API/gtk/WebKitNotificationProvider.cpp:

(WebKitNotificationProvider::notificationCloseCallback): Callback
for WebKitNotification::closed signal that notifies the WebProcess
and removes the notification from the map.
(WebKitNotificationProvider::show): Connect to WebKitNotification::closed.
(WebKitNotificationProvider::cancelNotificationByID): Call webkit_notification_close().

  • UIProcess/API/gtk/WebKitNotificationProvider.h:
  • UIProcess/API/gtk/WebKitWebView.cpp:

(notifyNotificationClosed): The user closed the annotation, call
webkit_notification_close().
(webNotificationClosed): The WebKitNotification has been closed,
close the libnotify notification if it hasn't been closed yet.
(webkitWebViewShowNotification): Create the libnotifiy
notification if needed and associate it to the WebKitNotification
as user data. Connect to the closed signal of both, the libnotifiy
notification and the WebKit notification.
(webkitWebViewCloseNotification): Deleted.
(webkit_web_view_class_init): Remove close-notification signal and
the default hanlder.
(webkitWebViewEmitCloseNotification): Deleted.

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/WebKitWebViewPrivate.h:
  • UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add webkit_notification_close.

Tools:

Update notifications unit tests according to the API changes, and
add a test case to check that onclose event is fired when a
notification is closed by the user.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:

(testWebViewNotification):

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r179744 r179745  
     12015-02-06  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Remove WebKitWebView::close-notification signal
     4        https://bugs.webkit.org/show_bug.cgi?id=141330
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        In favor of a WebKitNotification::closed signal and
     9        webkit_notification_close() method that both applications and
     10        WebKit can use to close a notification. This also fixes the
     11        onclose event that was not fired when the notification was
     12        closed. It also brings back padding space in WebKitWebViewClass.
     13
     14        * UIProcess/API/gtk/WebKitNotification.cpp:
     15        (webkit_notification_class_init): Add WebKitNotification::closed signal.
     16        (webkit_notification_close): Emit WebKitNotification::closed.
     17        * UIProcess/API/gtk/WebKitNotification.h:
     18        * UIProcess/API/gtk/WebKitNotificationProvider.cpp:
     19        (WebKitNotificationProvider::notificationCloseCallback): Callback
     20        for WebKitNotification::closed signal that notifies the WebProcess
     21        and removes the notification from the map.
     22        (WebKitNotificationProvider::show): Connect to WebKitNotification::closed.
     23        (WebKitNotificationProvider::cancelNotificationByID): Call webkit_notification_close().
     24        * UIProcess/API/gtk/WebKitNotificationProvider.h:
     25        * UIProcess/API/gtk/WebKitWebView.cpp:
     26        (notifyNotificationClosed): The user closed the annotation, call
     27        webkit_notification_close().
     28        (webNotificationClosed): The WebKitNotification has been closed,
     29        close the libnotify notification if it hasn't been closed yet.
     30        (webkitWebViewShowNotification): Create the libnotifiy
     31        notification if needed and associate it to the WebKitNotification
     32        as user data. Connect to the closed signal of both, the libnotifiy
     33        notification and the WebKit notification.
     34        (webkitWebViewCloseNotification): Deleted.
     35        (webkit_web_view_class_init): Remove close-notification signal and
     36        the default hanlder.
     37        (webkitWebViewEmitCloseNotification): Deleted.
     38        * UIProcess/API/gtk/WebKitWebView.h:
     39        * UIProcess/API/gtk/WebKitWebViewPrivate.h:
     40        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add webkit_notification_close.
     41
    1422015-02-06  Carlos Garcia Campos  <cgarcia@igalia.com>
    243
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp

    r177073 r179745  
    4343};
    4444
     45enum {
     46    CLOSED,
     47
     48    LAST_SIGNAL
     49};
     50
    4551struct _WebKitNotificationPrivate {
    4652    CString title;
     
    5056    WebKitWebView* webView;
    5157};
     58
     59static guint signals[LAST_SIGNAL] = { 0, };
    5260
    5361WEBKIT_DEFINE_TYPE(WebKitNotification, webkit_notification, G_TYPE_OBJECT)
     
    121129            nullptr,
    122130            WEBKIT_PARAM_READABLE));
     131
     132    /**
     133     * WebKitNotification::closed:
     134     * @notification: the #WebKitNotification on which the signal is emitted
     135     *
     136     * Emitted when a notification has been withdrawn.
     137     *
     138     * The default handler will close the notification using libnotify, if built with
     139     * support for it.
     140     *
     141     * Since: 2.8
     142     */
     143    signals[CLOSED] =
     144        g_signal_new(
     145            "closed",
     146            G_TYPE_FROM_CLASS(notificationClass),
     147            G_SIGNAL_RUN_LAST,
     148            0, 0,
     149            nullptr,
     150            g_cclosure_marshal_VOID__VOID,
     151            G_TYPE_NONE, 0);
    123152}
    124153
     
    188217    return notification->priv->body.data();
    189218}
     219
     220/**
     221 * webkit_notification_close:
     222 * @notification: a #WebKitNotification
     223 *
     224 * Closes the notification.
     225 *
     226 * Since: 2.8
     227 */
     228void webkit_notification_close(WebKitNotification* notification)
     229{
     230    g_return_if_fail(WEBKIT_IS_NOTIFICATION(notification));
     231
     232    g_signal_emit(notification, signals[CLOSED], 0);
     233}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h

    r177073 r179745  
    7171webkit_notification_get_body                 (WebKitNotification *notification);
    7272
     73WEBKIT_API void
     74webkit_notification_close                    (WebKitNotification* notification);
     75
    7376G_END_DECLS
    7477
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp

    r177073 r179745  
    8787}
    8888
     89void WebKitNotificationProvider::notificationCloseCallback(WebKitNotification* notification, WebKitNotificationProvider* provider)
     90{
     91    uint64_t notificationID = webkit_notification_get_id(notification);
     92    Vector<RefPtr<API::Object>, 1> arrayIDs;
     93    arrayIDs.uncheckedAppend(API::UInt64::create(notificationID));
     94    provider->m_notificationManager->providerDidCloseNotifications(API::Array::create(WTF::move(arrayIDs)).get());
     95    provider->m_notifications.remove(notificationID);
     96}
     97
    8998void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
    9099{
     
    93102    if (!notification) {
    94103        notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
     104        g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
    95105        m_notifications.set(webNotification.notificationID(), notification);
    96106    }
     
    103113{
    104114    if (GRefPtr<WebKitNotification> notification = m_notifications.get(notificationID))
    105         webkitWebViewEmitCloseNotification(webkitNotificationGetWebView(notification.get()), notification.get());
    106 
    107     m_notifications.remove(notificationID);
     115        webkit_notification_close(notification.get());
    108116}
    109117
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h

    r177073 r179745  
    4646
    4747    void cancelNotificationByID(uint64_t);
     48    static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*);
    4849
    4950    RefPtr<WebNotificationManagerProxy> m_notificationManager;
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r178892 r179745  
    132132
    133133    SHOW_NOTIFICATION,
    134     CLOSE_NOTIFICATION,
    135134
    136135    LAST_SIGNAL
     
    156155typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap;
    157156typedef HashMap<uint64_t, GRefPtr<GTask> > SnapshotResultsMap;
    158 #if USE(LIBNOTIFY)
    159 typedef HashMap<uint64_t, GRefPtr<NotifyNotification>> NotifyNotificationsMap;
    160 #endif
     157
    161158class PageLoadStateObserver;
    162159
     
    210207    GRefPtr<WebKitAuthenticationRequest> authenticationRequest;
    211208
    212 #if USE(LIBNOTIFY)
    213     NotifyNotificationsMap notifyNotificationsMap;
    214 #endif
    215209};
    216210
     
    584578}
    585579
    586 static gboolean webkitWebViewShowNotification(WebKitWebView* webView, WebKitNotification* webNotification)
     580#if USE(LIBNOTIFY)
     581static const char* gNotifyNotificationID = "wk-notify-notification";
     582
     583static void notifyNotificationClosed(NotifyNotification*, WebKitNotification* webNotification)
     584{
     585    g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr);
     586    webkit_notification_close(webNotification);
     587}
     588
     589static void webNotificationClosed(WebKitNotification* webNotification)
     590{
     591    NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID));
     592    if (!notification)
     593        return;
     594
     595    notify_notification_close(notification, nullptr);
     596    g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr);
     597}
     598#endif // USE(LIBNOTIFY)
     599
     600static gboolean webkitWebViewShowNotification(WebKitWebView*, WebKitNotification* webNotification)
    587601{
    588602#if USE(LIBNOTIFY)
     
    590604        notify_init(g_get_prgname());
    591605
    592     GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification));
     606    NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID));
    593607    if (!notification) {
    594         notification = adoptGRef(notify_notification_new(webkit_notification_get_title(webNotification),
    595             webkit_notification_get_body(webNotification), nullptr));
    596 
    597         webView->priv->notifyNotificationsMap.set(webkit_notification_get_id(webNotification), notification);
    598     } else
    599         notify_notification_update(notification.get(), webkit_notification_get_title(webNotification),
     608        notification = notify_notification_new(webkit_notification_get_title(webNotification),
    600609            webkit_notification_get_body(webNotification), nullptr);
    601610
    602     notify_notification_show(notification.get(), nullptr);
     611        g_signal_connect_object(notification, "closed", G_CALLBACK(notifyNotificationClosed), webNotification, static_cast<GConnectFlags>(0));
     612        g_signal_connect(webNotification, "closed", G_CALLBACK(webNotificationClosed), nullptr);
     613        g_object_set_data_full(G_OBJECT(webNotification), gNotifyNotificationID, notification, static_cast<GDestroyNotify>(g_object_unref));
     614    } else {
     615        notify_notification_update(notification, webkit_notification_get_title(webNotification),
     616            webkit_notification_get_body(webNotification), nullptr);
     617    }
     618
     619    notify_notification_show(notification, nullptr);
    603620    return TRUE;
    604621#else
    605     UNUSED_PARAM(webView);
    606     UNUSED_PARAM(webNotification);
    607     return FALSE;
    608 #endif
    609 }
    610 
    611 static gboolean webkitWebViewCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)
    612 {
    613 #if USE(LIBNOTIFY)
    614     if (GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification))) {
    615         notify_notification_close(notification.get(), nullptr);
    616         webView->priv->notifyNotificationsMap.remove(webkit_notification_get_id(webNotification));
    617     }
    618     return TRUE;
    619 #else
    620     UNUSED_PARAM(webView);
    621622    UNUSED_PARAM(webNotification);
    622623    return FALSE;
     
    785786    webViewClass->authenticate = webkitWebViewAuthenticate;
    786787    webViewClass->show_notification = webkitWebViewShowNotification;
    787     webViewClass->close_notification = webkitWebViewCloseNotification;
    788788
    789789    /**
     
    17151715            G_TYPE_BOOLEAN, 1,
    17161716            WEBKIT_TYPE_NOTIFICATION);
    1717 
    1718     /**
    1719      * WebKitNotification::close-notification:
    1720      * @web_view: the #WebKitWebView
    1721      * @notification: a #WebKitNofication
    1722      *
    1723      * This signal is emitted when a notification should be withdrawn.
    1724      *
    1725      * The default handler will close the notification using libnotify, if built with
    1726      * support for it.
    1727      *
    1728      * Returns: %TRUE to stop other handlers from being invoked. %FALSE otherwise.
    1729      *
    1730      * Since: 2.8
    1731      */
    1732     signals[CLOSE_NOTIFICATION] =
    1733         g_signal_new("close-notification",
    1734             G_TYPE_FROM_CLASS(gObjectClass),
    1735             G_SIGNAL_RUN_LAST,
    1736             G_STRUCT_OFFSET(WebKitWebViewClass, close_notification),
    1737             g_signal_accumulator_true_handled, nullptr /* accumulator data */,
    1738             webkit_marshal_BOOLEAN__OBJECT,
    1739             G_TYPE_BOOLEAN, 1,
    1740             WEBKIT_TYPE_NOTIFICATION);
    17411717}
    17421718
     
    21142090    g_signal_emit(webView, signals[SHOW_NOTIFICATION], 0, webNotification, &handled);
    21152091    return handled;
    2116 }
    2117 
    2118 void webkitWebViewEmitCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)
    2119 {
    2120     gboolean handled;
    2121     g_signal_emit(webView, signals[CLOSE_NOTIFICATION], 0, webNotification, &handled);
    21222092}
    21232093
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r178703 r179745  
    245245    gboolean   (* show_notification)           (WebKitWebView               *web_view,
    246246                                                WebKitNotification          *notification);
    247     gboolean   (* close_notification)          (WebKitWebView               *web_view,
    248                                                 WebKitNotification          *notification);
    249247
    250248    void (*_webkit_reserved0) (void);
     
    252250    void (*_webkit_reserved2) (void);
    253251    void (*_webkit_reserved3) (void);
     252    void (*_webkit_reserved4) (void);
    254253};
    255254
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h

    r178892 r179745  
    6060void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent);
    6161bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*);
    62 void webkitWebViewEmitCloseNotification(WebKitWebView*, WebKitNotification*);
    6362void webkitWebViewWebProcessCrashed(WebKitWebView*);
    6463void webkitWebViewIsPlayingAudioChanged(WebKitWebView*);
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r179111 r179745  
    627627webkit_notification_get_title
    628628webkit_notification_get_body
     629webkit_notification_close
    629630
    630631<SUBSECTION Standard>
  • trunk/Tools/ChangeLog

    r179721 r179745  
     12015-02-06  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Remove WebKitWebView::close-notification signal
     4        https://bugs.webkit.org/show_bug.cgi?id=141330
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        Update notifications unit tests according to the API changes, and
     9        add a test case to check that onclose event is fired when a
     10        notification is closed by the user.
     11
     12        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
     13        (testWebViewNotification):
     14
    1152015-02-05  Alexey Proskuryakov  <ap@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp

    r179248 r179745  
    603603        Permission,
    604604        Shown,
    605         Cancelled
     605        Closed,
     606        OnClosed,
    606607    };
    607608
     
    620621    }
    621622
     623    static gboolean notificationClosedCallback(WebKitNotification* notification, NotificationWebViewTest* test)
     624    {
     625        g_assert(test->m_notification == notification);
     626        test->m_notification = nullptr;
     627        test->m_event = Closed;
     628        if (g_main_loop_is_running(test->m_mainLoop))
     629            g_main_loop_quit(test->m_mainLoop);
     630        return TRUE;
     631    }
     632
    622633    static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test)
    623634    {
    624635        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification));
    625636        test->m_notification = notification;
     637        g_signal_connect(notification, "closed", G_CALLBACK(notificationClosedCallback), test);
    626638        test->m_event = Shown;
    627639        g_main_loop_quit(test->m_mainLoop);
     
    629641    }
    630642
    631     static gboolean closeNotificationCallback(WebKitWebView*, WebKitNotification*, NotificationWebViewTest* test)
    632     {
    633         test->m_notification = nullptr;
    634         test->m_event = Cancelled;
     643    static void notificationsMessageReceivedCallback(WebKitUserContentManager* userContentManager, WebKitJavascriptResult*, NotificationWebViewTest* test)
     644    {
     645        test->m_event = OnClosed;
    635646        g_main_loop_quit(test->m_mainLoop);
    636         return TRUE;
    637647    }
    638648
    639649    NotificationWebViewTest()
    640         : m_event(None)
     650        : WebViewTest(webkit_user_content_manager_new())
     651        , m_notification(nullptr)
     652        , m_event(None)
    641653    {
    642654        g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequestCallback), this);
    643655        g_signal_connect(m_webView, "show-notification", G_CALLBACK(showNotificationCallback), this);
    644         g_signal_connect(m_webView, "close-notification", G_CALLBACK(closeNotificationCallback), this);
    645 
     656        WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView);
     657        webkit_user_content_manager_register_script_message_handler(manager, "notifications");
     658        g_signal_connect(manager, "script-message-received::notifications", G_CALLBACK(notificationsMessageReceivedCallback), this);
    646659    }
    647660
     
    649662    {
    650663        g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
     664        WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView);
     665        g_signal_handlers_disconnect_matched(manager, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
     666        webkit_user_content_manager_unregister_script_message_handler(manager, "notifications");
    651667    }
    652668
     
    668684    }
    669685
    670     void closeNotificationAndWaitUntilCancelled()
     686    void closeNotificationAndWaitUntilClosed()
    671687    {
    672688        m_event = None;
    673689        webkit_web_view_run_javascript(m_webView, "n.close()", nullptr, nullptr, nullptr);
     690        g_main_loop_run(m_mainLoop);
     691    }
     692
     693    void closeNotificationAndWaitUntilOnClosed()
     694    {
     695        g_assert(m_notification);
     696        m_event = None;
     697        runJavaScriptAndWaitUntilFinished("n.onclose = function() { window.webkit.messageHandlers.notifications.postMessage('closed'); }", nullptr);
     698        webkit_notification_close(m_notification);
     699        g_assert(m_event == Closed);
    674700        g_main_loop_run(m_mainLoop);
    675701    }
     
    686712
    687713    test->requestPermissionAndWaitUntilGiven();
    688 
    689714    g_assert(test->m_event == NotificationWebViewTest::Permission);
    690715
     
    698723    g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body);
    699724
    700     test->closeNotificationAndWaitUntilCancelled();
    701 
    702     g_assert(test->m_event == NotificationWebViewTest::Cancelled);
     725    test->closeNotificationAndWaitUntilClosed();
     726    g_assert(test->m_event == NotificationWebViewTest::Closed);
    703727
    704728    test->requestNotificationAndWaitUntilShown(title, body);
    705 
     729    g_assert(test->m_event == NotificationWebViewTest::Shown);
     730
     731    test->closeNotificationAndWaitUntilOnClosed();
     732    g_assert(test->m_event == NotificationWebViewTest::OnClosed);
     733
     734    test->requestNotificationAndWaitUntilShown(title, body);
    706735    g_assert(test->m_event == NotificationWebViewTest::Shown);
    707736
    708737    test->loadURI(gServer->getURIForPath("/").data());
    709738    test->waitUntilLoadFinished();
    710 
    711     g_assert(test->m_event == NotificationWebViewTest::Cancelled);
     739    g_assert(test->m_event == NotificationWebViewTest::Closed);
    712740}
    713741
Note: See TracChangeset for help on using the changeset viewer.