Title: [193721] trunk
Revision
193721
Author
g...@gnome.org
Date
2015-12-08 00:26:16 -0800 (Tue, 08 Dec 2015)

Log Message

[GTK] Notify WebCore when notification is clicked
https://bugs.webkit.org/show_bug.cgi?id=151951

Reviewed by Carlos Garcia Campos.

Source/WebKit2:

* UIProcess/API/gtk/WebKitNotification.cpp:
(webkit_notification_class_init): new clicked signal.
(webkit_notification_clicked): method to emit the clicked signal.
* UIProcess/API/gtk/WebKitNotification.h:
* UIProcess/API/gtk/WebKitNotificationProvider.cpp:
(WebKitNotificationProvider::notificationClickedCallback): handle the clicked signal and tell WebProcess about the click.
(WebKitNotificationProvider::show): connect to the clicked signal in addition to closed.
* UIProcess/API/gtk/WebKitNotificationProvider.h:
* UIProcess/API/gtk/WebKitWebView.cpp:
(notifyNotificationClicked): handle the click on our libnotify notification.
(webkitWebViewShowNotification): add the "default" action to our libnotify notification to be notified of the click.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:

Tools:

* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
(testWebViewNotification): test the new API.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (193720 => 193721)


--- trunk/Source/WebKit2/ChangeLog	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/ChangeLog	2015-12-08 08:26:16 UTC (rev 193721)
@@ -1,3 +1,23 @@
+2015-12-07  Gustavo Noronha Silva  <g...@gnome.org>
+
+        [GTK] Notify WebCore when notification is clicked
+        https://bugs.webkit.org/show_bug.cgi?id=151951
+
+        Reviewed by Carlos Garcia Campos.
+
+        * UIProcess/API/gtk/WebKitNotification.cpp:
+        (webkit_notification_class_init): new clicked signal.
+        (webkit_notification_clicked): method to emit the clicked signal.
+        * UIProcess/API/gtk/WebKitNotification.h:
+        * UIProcess/API/gtk/WebKitNotificationProvider.cpp:
+        (WebKitNotificationProvider::notificationClickedCallback): handle the clicked signal and tell WebProcess about the click.
+        (WebKitNotificationProvider::show): connect to the clicked signal in addition to closed.
+        * UIProcess/API/gtk/WebKitNotificationProvider.h:
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (notifyNotificationClicked): handle the click on our libnotify notification.
+        (webkitWebViewShowNotification): add the "default" action to our libnotify notification to be notified of the click.
+        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+
 2015-12-07  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r193655.

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp	2015-12-08 08:26:16 UTC (rev 193721)
@@ -44,6 +44,7 @@
 
 enum {
     CLOSED,
+    CLICKED,
 
     LAST_SIGNAL
 };
@@ -149,6 +150,24 @@
             nullptr,
             g_cclosure_marshal_VOID__VOID,
             G_TYPE_NONE, 0);
+
+    /**
+     * WebKitNotification::clicked:
+     * @notification: the #WebKitNotification on which the signal is emitted
+     *
+     * Emitted when a notification has been clicked. See webkit_notification_clicked().
+     *
+     * Since: 2.12
+     */
+    signals[CLICKED] =
+        g_signal_new(
+            "clicked",
+            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)
@@ -231,3 +250,19 @@
 
     g_signal_emit(notification, signals[CLOSED], 0);
 }
+
+/**
+ * webkit_notification_clicked:
+ * @notification: a #WebKitNotification
+ *
+ * Tells WebKit the notification has been clicked. This will emit the
+ * #WebKitNotification::clicked signal.
+ *
+ * Since: 2.12
+ */
+void webkit_notification_clicked(WebKitNotification* notification)
+{
+    g_return_if_fail(WEBKIT_IS_NOTIFICATION(notification));
+
+    g_signal_emit(notification, signals[CLICKED], 0);
+}

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h	2015-12-08 08:26:16 UTC (rev 193721)
@@ -71,8 +71,11 @@
 webkit_notification_get_body                 (WebKitNotification *notification);
 
 WEBKIT_API void
-webkit_notification_close                    (WebKitNotification* notification);
+webkit_notification_close                    (WebKitNotification *notification);
 
+WEBKIT_API void
+webkit_notification_clicked                  (WebKitNotification *notification);
+
 G_END_DECLS
 
 #endif

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp	2015-12-08 08:26:16 UTC (rev 193721)
@@ -97,6 +97,11 @@
     provider->m_notifications.remove(notificationID);
 }
 
+void WebKitNotificationProvider::notificationClickedCallback(WebKitNotification* notification, WebKitNotificationProvider* provider)
+{
+    provider->m_notificationManager->providerDidClickNotification(webkit_notification_get_id(notification));
+}
+
 void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
 {
     GRefPtr<WebKitNotification> notification = m_notifications.get(webNotification.notificationID());
@@ -104,6 +109,7 @@
     if (!notification) {
         notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
         g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
+        g_signal_connect(notification.get(), "clicked", G_CALLBACK(notificationClickedCallback), this);
         m_notifications.set(webNotification.notificationID(), notification);
     }
 

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h	2015-12-08 08:26:16 UTC (rev 193721)
@@ -46,6 +46,7 @@
 
     void cancelNotificationByID(uint64_t);
     static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*);
+    static void notificationClickedCallback(WebKitNotification*, WebKitNotificationProvider*);
 
     RefPtr<WebNotificationManagerProxy> m_notificationManager;
     HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications;

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2015-12-08 08:26:16 UTC (rev 193721)
@@ -594,6 +594,11 @@
     webkit_notification_close(webNotification);
 }
 
+static void notifyNotificationClicked(NotifyNotification*, char*, WebKitNotification* webNotification)
+{
+    webkit_notification_clicked(webNotification);
+}
+
 static void webNotificationClosed(WebKitNotification* webNotification)
 {
     NotifyNotification* notification = NOTIFY_NOTIFICATION(g_object_get_data(G_OBJECT(webNotification), gNotifyNotificationID));
@@ -616,6 +621,8 @@
         notification = notify_notification_new(webkit_notification_get_title(webNotification),
             webkit_notification_get_body(webNotification), nullptr);
 
+        notify_notification_add_action(notification, "default", _("Acknowledge"), NOTIFY_ACTION_CALLBACK(notifyNotificationClicked), webNotification, nullptr);
+
         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));

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt	2015-12-08 08:26:16 UTC (rev 193721)
@@ -657,6 +657,7 @@
 webkit_notification_get_title
 webkit_notification_get_body
 webkit_notification_close
+webkit_notification_clicked
 
 <SUBSECTION Standard>
 WebKitNotificationClass

Modified: trunk/Tools/ChangeLog (193720 => 193721)


--- trunk/Tools/ChangeLog	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Tools/ChangeLog	2015-12-08 08:26:16 UTC (rev 193721)
@@ -1,3 +1,13 @@
+2015-12-07  Gustavo Noronha Silva  <g...@gnome.org>
+
+        [GTK] Notify WebCore when notification is clicked
+        https://bugs.webkit.org/show_bug.cgi?id=151951
+
+        Reviewed by Carlos Garcia Campos.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
+        (testWebViewNotification): test the new API.
+
 2015-12-07  Michael Catanzaro  <mcatanz...@igalia.com>
 
         'jhbuild build' should fail immediately when building any module fails

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp (193720 => 193721)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp	2015-12-08 08:17:53 UTC (rev 193720)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp	2015-12-08 08:26:16 UTC (rev 193721)
@@ -638,6 +638,8 @@
         None,
         Permission,
         Shown,
+        Clicked,
+        OnClicked,
         Closed,
         OnClosed,
     };
@@ -666,19 +668,33 @@
         return TRUE;
     }
 
+    static gboolean notificationClickedCallback(WebKitNotification* notification, NotificationWebViewTest* test)
+    {
+        g_assert(test->m_notification == notification);
+        test->m_event = Clicked;
+        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);
+        g_signal_connect(notification, "clicked", G_CALLBACK(notificationClickedCallback), test);
         test->m_event = Shown;
         g_main_loop_quit(test->m_mainLoop);
         return TRUE;
     }
 
-    static void notificationsMessageReceivedCallback(WebKitUserContentManager* userContentManager, WebKitJavascriptResult*, NotificationWebViewTest* test)
+    static void notificationsMessageReceivedCallback(WebKitUserContentManager* userContentManager, WebKitJavascriptResult* _javascript_Result, NotificationWebViewTest* test)
     {
-        test->m_event = OnClosed;
+        GUniquePtr<char> valueString(WebViewTest::_javascript_ResultToCString(_javascript_Result));
+
+        if (g_str_equal(valueString.get(), "clicked"))
+            test->m_event = OnClicked;
+        else if (g_str_equal(valueString.get(), "closed"))
+            test->m_event = OnClosed;
+
         g_main_loop_quit(test->m_mainLoop);
     }
 
@@ -719,6 +735,15 @@
         g_main_loop_run(m_mainLoop);
     }
 
+    void clickNotificationAndWaitUntilClicked()
+    {
+        m_event = None;
+        runJavaScriptAndWaitUntilFinished("n._onclick_ = function() { window.webkit.messageHandlers.notifications.postMessage('clicked'); }", nullptr);
+        webkit_notification_clicked(m_notification);
+        g_assert(m_event == Clicked);
+        g_main_loop_run(m_mainLoop);
+    }
+
     void closeNotificationAndWaitUntilClosed()
     {
         m_event = None;
@@ -758,6 +783,9 @@
     g_assert_cmpstr(webkit_notification_get_title(test->m_notification), ==, title);
     g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body);
 
+    test->clickNotificationAndWaitUntilClicked();
+    g_assert(test->m_event == NotificationWebViewTest::OnClicked);
+
     test->closeNotificationAndWaitUntilClosed();
     g_assert(test->m_event == NotificationWebViewTest::Closed);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to