Title: [179745] trunk
Revision
179745
Author
[email protected]
Date
2015-02-06 06:50:20 -0800 (Fri, 06 Feb 2015)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (179744 => 179745)


--- trunk/Source/WebKit2/ChangeLog	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/ChangeLog	2015-02-06 14:50:20 UTC (rev 179745)
@@ -1,5 +1,46 @@
 2015-02-06  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Remove WebKitWebView::close-notification signal
+        https://bugs.webkit.org/show_bug.cgi?id=141330
+
+        Reviewed by Gustavo Noronha Silva.
+
+        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.
+
+2015-02-06  Carlos Garcia Campos  <[email protected]>
+
         ASSERTION FAILED: !m_adoptionIsRequired in WTF::RefCountedBase::ref
         https://bugs.webkit.org/show_bug.cgi?id=141035
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp	2015-02-06 14:50:20 UTC (rev 179745)
@@ -42,6 +42,12 @@
     PROP_BODY
 };
 
+enum {
+    CLOSED,
+
+    LAST_SIGNAL
+};
+
 struct _WebKitNotificationPrivate {
     CString title;
     CString body;
@@ -50,6 +56,8 @@
     WebKitWebView* webView;
 };
 
+static guint signals[LAST_SIGNAL] = { 0, };
+
 WEBKIT_DEFINE_TYPE(WebKitNotification, webkit_notification, G_TYPE_OBJECT)
 
 static void webkitNotificationGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
@@ -120,6 +128,27 @@
             _("The body for the notification"),
             nullptr,
             WEBKIT_PARAM_READABLE));
+
+    /**
+     * WebKitNotification::closed:
+     * @notification: the #WebKitNotification on which the signal is emitted
+     *
+     * Emitted when a notification has been withdrawn.
+     *
+     * The default handler will close the notification using libnotify, if built with
+     * support for it.
+     *
+     * Since: 2.8
+     */
+    signals[CLOSED] =
+        g_signal_new(
+            "closed",
+            G_TYPE_FROM_CLASS(notificationClass),
+            G_SIGNAL_RUN_LAST,
+            0, 0,
+            nullptr,
+            g_cclosure_marshal_VOID__VOID,
+            G_TYPE_NONE, 0);
 }
 
 WebKitNotification* webkitNotificationCreate(WebKitWebView* webView, const WebKit::WebNotification& webNotification)
@@ -187,3 +216,18 @@
 
     return notification->priv->body.data();
 }
+
+/**
+ * webkit_notification_close:
+ * @notification: a #WebKitNotification
+ *
+ * Closes the notification.
+ *
+ * Since: 2.8
+ */
+void webkit_notification_close(WebKitNotification* notification)
+{
+    g_return_if_fail(WEBKIT_IS_NOTIFICATION(notification));
+
+    g_signal_emit(notification, signals[CLOSED], 0);
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h	2015-02-06 14:50:20 UTC (rev 179745)
@@ -70,6 +70,9 @@
 WEBKIT_API const gchar *
 webkit_notification_get_body                 (WebKitNotification *notification);
 
+WEBKIT_API void
+webkit_notification_close                    (WebKitNotification* notification);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp	2015-02-06 14:50:20 UTC (rev 179745)
@@ -86,12 +86,22 @@
     WKNotificationManagerSetProvider(toAPI(notificationManager), reinterpret_cast<WKNotificationProviderBase*>(&wkNotificationProvider));
 }
 
+void WebKitNotificationProvider::notificationCloseCallback(WebKitNotification* notification, WebKitNotificationProvider* provider)
+{
+    uint64_t notificationID = webkit_notification_get_id(notification);
+    Vector<RefPtr<API::Object>, 1> arrayIDs;
+    arrayIDs.uncheckedAppend(API::UInt64::create(notificationID));
+    provider->m_notificationManager->providerDidCloseNotifications(API::Array::create(WTF::move(arrayIDs)).get());
+    provider->m_notifications.remove(notificationID);
+}
+
 void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
 {
     GRefPtr<WebKitNotification> notification = m_notifications.get(webNotification.notificationID());
 
     if (!notification) {
         notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
+        g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
         m_notifications.set(webNotification.notificationID(), notification);
     }
 
@@ -102,9 +112,7 @@
 void WebKitNotificationProvider::cancelNotificationByID(uint64_t notificationID)
 {
     if (GRefPtr<WebKitNotification> notification = m_notifications.get(notificationID))
-        webkitWebViewEmitCloseNotification(webkitNotificationGetWebView(notification.get()), notification.get());
-
-    m_notifications.remove(notificationID);
+        webkit_notification_close(notification.get());
 }
 
 void WebKitNotificationProvider::cancel(const WebNotification& webNotification)

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h	2015-02-06 14:50:20 UTC (rev 179745)
@@ -45,6 +45,7 @@
     WebKitNotificationProvider(WebNotificationManagerProxy*);
 
     void cancelNotificationByID(uint64_t);
+    static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*);
 
     RefPtr<WebNotificationManagerProxy> m_notificationManager;
     HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications;

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2015-02-06 14:50:20 UTC (rev 179745)
@@ -131,7 +131,6 @@
     AUTHENTICATE,
 
     SHOW_NOTIFICATION,
-    CLOSE_NOTIFICATION,
 
     LAST_SIGNAL
 };
@@ -155,9 +154,7 @@
 
 typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap;
 typedef HashMap<uint64_t, GRefPtr<GTask> > SnapshotResultsMap;
-#if USE(LIBNOTIFY)
-typedef HashMap<uint64_t, GRefPtr<NotifyNotification>> NotifyNotificationsMap;
-#endif
+
 class PageLoadStateObserver;
 
 struct _WebKitWebViewPrivate {
@@ -209,9 +206,6 @@
     SnapshotResultsMap snapshotResultsMap;
     GRefPtr<WebKitAuthenticationRequest> authenticationRequest;
 
-#if USE(LIBNOTIFY)
-    NotifyNotificationsMap notifyNotificationsMap;
-#endif
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -583,46 +577,53 @@
     webkitDownloadSetWebView(download.get(), WEBKIT_WEB_VIEW(webViewBase));
 }
 
-static gboolean webkitWebViewShowNotification(WebKitWebView* webView, WebKitNotification* webNotification)
+#if USE(LIBNOTIFY)
+static const char* gNotifyNotificationID = "wk-notify-notification";
+
+static void notifyNotificationClosed(NotifyNotification*, WebKitNotification* webNotification)
 {
+    g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr);
+    webkit_notification_close(webNotification);
+}
+
+static void webNotificationClosed(WebKitNotification* webNotification)
+{
+    NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID));
+    if (!notification)
+        return;
+
+    notify_notification_close(notification, nullptr);
+    g_object_set_data(G_OBJECT(webNotification), gNotifyNotificationID, nullptr);
+}
+#endif // USE(LIBNOTIFY)
+
+static gboolean webkitWebViewShowNotification(WebKitWebView*, WebKitNotification* webNotification)
+{
 #if USE(LIBNOTIFY)
     if (!notify_is_initted())
         notify_init(g_get_prgname());
 
-    GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification));
+    NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID));
     if (!notification) {
-        notification = adoptGRef(notify_notification_new(webkit_notification_get_title(webNotification),
-            webkit_notification_get_body(webNotification), nullptr));
+        notification = notify_notification_new(webkit_notification_get_title(webNotification),
+            webkit_notification_get_body(webNotification), nullptr);
 
-        webView->priv->notifyNotificationsMap.set(webkit_notification_get_id(webNotification), notification);
-    } else
-        notify_notification_update(notification.get(), webkit_notification_get_title(webNotification),
+        g_signal_connect_object(notification, "closed", G_CALLBACK(notifyNotificationClosed), webNotification, static_cast<GConnectFlags>(0));
+        g_signal_connect(webNotification, "closed", G_CALLBACK(webNotificationClosed), nullptr);
+        g_object_set_data_full(G_OBJECT(webNotification), gNotifyNotificationID, notification, static_cast<GDestroyNotify>(g_object_unref));
+    } else {
+        notify_notification_update(notification, webkit_notification_get_title(webNotification),
             webkit_notification_get_body(webNotification), nullptr);
+    }
 
-    notify_notification_show(notification.get(), nullptr);
+    notify_notification_show(notification, nullptr);
     return TRUE;
 #else
-    UNUSED_PARAM(webView);
     UNUSED_PARAM(webNotification);
     return FALSE;
 #endif
 }
 
-static gboolean webkitWebViewCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)
-{
-#if USE(LIBNOTIFY)
-    if (GRefPtr<NotifyNotification> notification = webView->priv->notifyNotificationsMap.get(webkit_notification_get_id(webNotification))) {
-        notify_notification_close(notification.get(), nullptr);
-        webView->priv->notifyNotificationsMap.remove(webkit_notification_get_id(webNotification));
-    }
-    return TRUE;
-#else
-    UNUSED_PARAM(webView);
-    UNUSED_PARAM(webNotification);
-    return FALSE;
-#endif
-}
-
 static void webkitWebViewConstructed(GObject* object)
 {
     G_OBJECT_CLASS(webkit_web_view_parent_class)->constructed(object);
@@ -784,7 +785,6 @@
     webViewClass->run_file_chooser = webkitWebViewRunFileChooser;
     webViewClass->authenticate = webkitWebViewAuthenticate;
     webViewClass->show_notification = webkitWebViewShowNotification;
-    webViewClass->close_notification = webkitWebViewCloseNotification;
 
     /**
      * WebKitWebView:web-context:
@@ -1714,30 +1714,6 @@
             webkit_marshal_BOOLEAN__OBJECT,
             G_TYPE_BOOLEAN, 1,
             WEBKIT_TYPE_NOTIFICATION);
-
-    /**
-     * WebKitNotification::close-notification:
-     * @web_view: the #WebKitWebView
-     * @notification: a #WebKitNofication
-     *
-     * This signal is emitted when a notification should be withdrawn.
-     *
-     * The default handler will close the notification using libnotify, if built with
-     * support for it.
-     *
-     * Returns: %TRUE to stop other handlers from being invoked. %FALSE otherwise.
-     *
-     * Since: 2.8
-     */
-    signals[CLOSE_NOTIFICATION] =
-        g_signal_new("close-notification",
-            G_TYPE_FROM_CLASS(gObjectClass),
-            G_SIGNAL_RUN_LAST,
-            G_STRUCT_OFFSET(WebKitWebViewClass, close_notification),
-            g_signal_accumulator_true_handled, nullptr /* accumulator data */,
-            webkit_marshal_BOOLEAN__OBJECT,
-            G_TYPE_BOOLEAN, 1,
-            WEBKIT_TYPE_NOTIFICATION);
 }
 
 static void webkitWebViewCancelAuthenticationRequest(WebKitWebView* webView)
@@ -2115,12 +2091,6 @@
     return handled;
 }
 
-void webkitWebViewEmitCloseNotification(WebKitWebView* webView, WebKitNotification* webNotification)
-{
-    gboolean handled;
-    g_signal_emit(webView, signals[CLOSE_NOTIFICATION], 0, webNotification, &handled);
-}
-
 /**
  * webkit_web_view_new:
  *

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2015-02-06 14:50:20 UTC (rev 179745)
@@ -244,13 +244,12 @@
                                                 GTlsCertificateFlags         errors);
     gboolean   (* show_notification)           (WebKitWebView               *web_view,
                                                 WebKitNotification          *notification);
-    gboolean   (* close_notification)          (WebKitWebView               *web_view,
-                                                WebKitNotification          *notification);
 
     void (*_webkit_reserved0) (void);
     void (*_webkit_reserved1) (void);
     void (*_webkit_reserved2) (void);
     void (*_webkit_reserved3) (void);
+    void (*_webkit_reserved4) (void);
 };
 
 WEBKIT_API GType

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h	2015-02-06 14:50:20 UTC (rev 179745)
@@ -59,7 +59,6 @@
 void webkitWebViewHandleAuthenticationChallenge(WebKitWebView*, WebKit::AuthenticationChallengeProxy*);
 void webkitWebViewInsecureContentDetected(WebKitWebView*, WebKitInsecureContentEvent);
 bool webkitWebViewEmitShowNotification(WebKitWebView*, WebKitNotification*);
-void webkitWebViewEmitCloseNotification(WebKitWebView*, WebKitNotification*);
 void webkitWebViewWebProcessCrashed(WebKitWebView*);
 void webkitWebViewIsPlayingAudioChanged(WebKitWebView*);
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (179744 => 179745)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-02-06 14:50:20 UTC (rev 179745)
@@ -626,6 +626,7 @@
 webkit_notification_get_id
 webkit_notification_get_title
 webkit_notification_get_body
+webkit_notification_close
 
 <SUBSECTION Standard>
 WebKitNotificationClass

Modified: trunk/Tools/ChangeLog (179744 => 179745)


--- trunk/Tools/ChangeLog	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Tools/ChangeLog	2015-02-06 14:50:20 UTC (rev 179745)
@@ -1,3 +1,17 @@
+2015-02-06  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Remove WebKitWebView::close-notification signal
+        https://bugs.webkit.org/show_bug.cgi?id=141330
+
+        Reviewed by Gustavo Noronha Silva.
+
+        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):
+
 2015-02-05  Alexey Proskuryakov  <[email protected]>
 
         Dashboard doesn't consider building ASan a productive step

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp (179744 => 179745)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp	2015-02-06 14:46:17 UTC (rev 179744)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp	2015-02-06 14:50:20 UTC (rev 179745)
@@ -602,7 +602,8 @@
         None,
         Permission,
         Shown,
-        Cancelled
+        Closed,
+        OnClosed,
     };
 
     static gboolean permissionRequestCallback(WebKitWebView*, WebKitPermissionRequest *request, NotificationWebViewTest* test)
@@ -619,35 +620,50 @@
         return TRUE;
     }
 
+    static gboolean notificationClosedCallback(WebKitNotification* notification, NotificationWebViewTest* test)
+    {
+        g_assert(test->m_notification == notification);
+        test->m_notification = nullptr;
+        test->m_event = Closed;
+        if (g_main_loop_is_running(test->m_mainLoop))
+            g_main_loop_quit(test->m_mainLoop);
+        return TRUE;
+    }
+
     static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test)
     {
         test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification));
         test->m_notification = notification;
+        g_signal_connect(notification, "closed", G_CALLBACK(notificationClosedCallback), test);
         test->m_event = Shown;
         g_main_loop_quit(test->m_mainLoop);
         return TRUE;
     }
 
-    static gboolean closeNotificationCallback(WebKitWebView*, WebKitNotification*, NotificationWebViewTest* test)
+    static void notificationsMessageReceivedCallback(WebKitUserContentManager* userContentManager, WebKitJavascriptResult*, NotificationWebViewTest* test)
     {
-        test->m_notification = nullptr;
-        test->m_event = Cancelled;
+        test->m_event = OnClosed;
         g_main_loop_quit(test->m_mainLoop);
-        return TRUE;
     }
 
     NotificationWebViewTest()
-        : m_event(None)
+        : WebViewTest(webkit_user_content_manager_new())
+        , m_notification(nullptr)
+        , m_event(None)
     {
         g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequestCallback), this);
         g_signal_connect(m_webView, "show-notification", G_CALLBACK(showNotificationCallback), this);
-        g_signal_connect(m_webView, "close-notification", G_CALLBACK(closeNotificationCallback), this);
-
+        WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView);
+        webkit_user_content_manager_register_script_message_handler(manager, "notifications");
+        g_signal_connect(manager, "script-message-received::notifications", G_CALLBACK(notificationsMessageReceivedCallback), this);
     }
 
     ~NotificationWebViewTest()
     {
         g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
+        WebKitUserContentManager* manager = webkit_web_view_get_user_content_manager(m_webView);
+        g_signal_handlers_disconnect_matched(manager, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
+        webkit_user_content_manager_unregister_script_message_handler(manager, "notifications");
     }
 
    void requestPermissionAndWaitUntilGiven()
@@ -667,13 +683,23 @@
         g_main_loop_run(m_mainLoop);
     }
 
-    void closeNotificationAndWaitUntilCancelled()
+    void closeNotificationAndWaitUntilClosed()
     {
         m_event = None;
         webkit_web_view_run_javascript(m_webView, "n.close()", nullptr, nullptr, nullptr);
         g_main_loop_run(m_mainLoop);
     }
 
+    void closeNotificationAndWaitUntilOnClosed()
+    {
+        g_assert(m_notification);
+        m_event = None;
+        runJavaScriptAndWaitUntilFinished("n._onclose_ = function() { window.webkit.messageHandlers.notifications.postMessage('closed'); }", nullptr);
+        webkit_notification_close(m_notification);
+        g_assert(m_event == Closed);
+        g_main_loop_run(m_mainLoop);
+    }
+
     NotificationEvent m_event;
     WebKitNotification* m_notification;
 };
@@ -685,7 +711,6 @@
     test->waitUntilLoadFinished();
 
     test->requestPermissionAndWaitUntilGiven();
-
     g_assert(test->m_event == NotificationWebViewTest::Permission);
 
     static const char* title = "This is a notification";
@@ -697,18 +722,21 @@
     g_assert_cmpstr(webkit_notification_get_title(test->m_notification), ==, title);
     g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body);
 
-    test->closeNotificationAndWaitUntilCancelled();
+    test->closeNotificationAndWaitUntilClosed();
+    g_assert(test->m_event == NotificationWebViewTest::Closed);
 
-    g_assert(test->m_event == NotificationWebViewTest::Cancelled);
+    test->requestNotificationAndWaitUntilShown(title, body);
+    g_assert(test->m_event == NotificationWebViewTest::Shown);
 
+    test->closeNotificationAndWaitUntilOnClosed();
+    g_assert(test->m_event == NotificationWebViewTest::OnClosed);
+
     test->requestNotificationAndWaitUntilShown(title, body);
-
     g_assert(test->m_event == NotificationWebViewTest::Shown);
 
     test->loadURI(gServer->getURIForPath("/").data());
     test->waitUntilLoadFinished();
-
-    g_assert(test->m_event == NotificationWebViewTest::Cancelled);
+    g_assert(test->m_event == NotificationWebViewTest::Closed);
 }
 
 static void testWebViewIsPlayingAudio(IsPlayingAudioWebViewTest* test, gconstpointer)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to