<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[208974] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208974">208974</a></dd>
<dt>Author</dt> <dd>mcatanzaro@igalia.com</dd>
<dt>Date</dt> <dd>2016-11-24 12:10:25 -0800 (Thu, 24 Nov 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[GTK] Notifications API does not expose or respect the "tag" attribute
https://bugs.webkit.org/show_bug.cgi?id=164771
Reviewed by Gustavo Noronha Silva.
Source/WebKit2:
Expose a tag property on WebKitNotification. Ensure that any previous notification with the
same tag is closed when showing a new notification with that tag.
* UIProcess/API/gtk/WebKitNotification.cpp:
(webkit_notification_class_init):
(webkitNotificationCreate):
(webkit_notification_get_tag):
* UIProcess/API/gtk/WebKitNotification.h:
* UIProcess/API/gtk/WebKitNotificationProvider.cpp:
(WebKitNotificationProvider::withdrawAnyPreviousNotificationMatchingTag):
(WebKitNotificationProvider::show):
* UIProcess/API/gtk/WebKitNotificationProvider.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
Tools:
Verify that showing a notification with the same tag as another notification closes the
previous notification before the new notification is shown.
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
(testWebViewNotification):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationcpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationh">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationProvidercpp">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationProviderh">trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPIgtkdocswebkit2gtk40sectionstxt">trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitWebViewcpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Source/WebKit2/ChangeLog        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2016-11-24 Michael Catanzaro <mcatanzaro@igalia.com>
+
+ [GTK] Notifications API does not expose or respect the "tag" attribute
+ https://bugs.webkit.org/show_bug.cgi?id=164771
+
+ Reviewed by Gustavo Noronha Silva.
+
+ Expose a tag property on WebKitNotification. Ensure that any previous notification with the
+ same tag is closed when showing a new notification with that tag.
+
+ * UIProcess/API/gtk/WebKitNotification.cpp:
+ (webkit_notification_class_init):
+ (webkitNotificationCreate):
+ (webkit_notification_get_tag):
+ * UIProcess/API/gtk/WebKitNotification.h:
+ * UIProcess/API/gtk/WebKitNotificationProvider.cpp:
+ (WebKitNotificationProvider::withdrawAnyPreviousNotificationMatchingTag):
+ (WebKitNotificationProvider::show):
+ * UIProcess/API/gtk/WebKitNotificationProvider.h:
+ * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
+
</ins><span class="cx"> 2016-11-22 Sergio Villar Senin <svillar@igalia.com>
</span><span class="cx">
</span><span class="cx"> [GTK] Fix introspection warning
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -39,7 +39,8 @@
</span><span class="cx">
</span><span class="cx"> PROP_ID,
</span><span class="cx"> PROP_TITLE,
</span><del>- PROP_BODY
</del><ins>+ PROP_BODY,
+ PROP_TAG
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> enum {
</span><span class="lines">@@ -52,6 +53,7 @@
</span><span class="cx"> struct _WebKitNotificationPrivate {
</span><span class="cx"> CString title;
</span><span class="cx"> CString body;
</span><ins>+ CString tag;
</ins><span class="cx"> guint64 id;
</span><span class="cx">
</span><span class="cx"> WebKitWebView* webView;
</span><span class="lines">@@ -75,6 +77,9 @@
</span><span class="cx"> case PROP_BODY:
</span><span class="cx"> g_value_set_string(value, webkit_notification_get_body(notification));
</span><span class="cx"> break;
</span><ins>+ case PROP_TAG:
+ g_value_set_string(value, webkit_notification_get_tag(notification));
+ break;
</ins><span class="cx"> default:
</span><span class="cx"> G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
</span><span class="cx"> }
</span><span class="lines">@@ -131,6 +136,21 @@
</span><span class="cx"> WEBKIT_PARAM_READABLE));
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * WebKitNotification:tag:
+ *
+ * The tag identifier for the notification.
+ *
+ * Since: 2.16
+ */
+ g_object_class_install_property(objectClass,
+ PROP_TAG,
+ g_param_spec_string("tag",
+ _("Tag"),
+ _("The tag identifier for the notification"),
+ nullptr,
+ WEBKIT_PARAM_READABLE));
+
+ /**
</ins><span class="cx"> * WebKitNotification::closed:
</span><span class="cx"> * @notification: the #WebKitNotification on which the signal is emitted
</span><span class="cx"> *
</span><span class="lines">@@ -176,6 +196,7 @@
</span><span class="cx"> notification->priv->id = webNotification.notificationID();
</span><span class="cx"> notification->priv->title = webNotification.title().utf8();
</span><span class="cx"> notification->priv->body = webNotification.body().utf8();
</span><ins>+ notification->priv->tag = webNotification.tag().utf8();
</ins><span class="cx"> notification->priv->webView = webView;
</span><span class="cx"> return notification;
</span><span class="cx"> }
</span><span class="lines">@@ -237,6 +258,24 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * webkit_notification_get_tag:
+ * @notification: a #WebKitNotification
+ *
+ * Obtains the tag identifier for the notification.
+ *
+ * Returns: (allow-none): the tag for the notification
+ *
+ * Since: 2.16
+ */
+const gchar* webkit_notification_get_tag(WebKitNotification* notification)
+{
+ g_return_val_if_fail(WEBKIT_IS_NOTIFICATION(notification), nullptr);
+
+ const gchar* tag = notification->priv->tag.data();
+ return strlen(tag) > 0 ? tag : nullptr;
+}
+
+/**
</ins><span class="cx"> * webkit_notification_close:
</span><span class="cx"> * @notification: a #WebKitNotification
</span><span class="cx"> *
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -70,6 +70,9 @@
</span><span class="cx"> WEBKIT_API const gchar *
</span><span class="cx"> webkit_notification_get_body (WebKitNotification *notification);
</span><span class="cx">
</span><ins>+WEBKIT_API const gchar *
+webkit_notification_get_tag (WebKitNotification *notification);
+
</ins><span class="cx"> WEBKIT_API void
</span><span class="cx"> webkit_notification_close (WebKitNotification *notification);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationProvidercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -102,11 +102,30 @@
</span><span class="cx"> provider->m_notificationManager->providerDidClickNotification(webkit_notification_get_id(notification));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void WebKitNotificationProvider::withdrawAnyPreviousNotificationMatchingTag(const String& tag)
+{
+ if (tag.isEmpty())
+ return;
+
+ for (auto& notification : m_notifications.values()) {
+ if (tag == webkit_notification_get_tag(notification.get())) {
+ webkit_notification_close(notification.get());
+ break;
+ }
+ }
+
+#ifndef NDEBUG
+ for (auto& notification : m_notifications.values())
+ ASSERT(tag != webkit_notification_get_tag(notification.get()));
+#endif
+}
+
</ins><span class="cx"> void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
</span><span class="cx"> {
</span><span class="cx"> GRefPtr<WebKitNotification> notification = m_notifications.get(webNotification.notificationID());
</span><span class="cx">
</span><span class="cx"> if (!notification) {
</span><ins>+ withdrawAnyPreviousNotificationMatchingTag(webNotification.tag());
</ins><span class="cx"> notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
</span><span class="cx"> g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
</span><span class="cx"> g_signal_connect(notification.get(), "clicked", G_CALLBACK(notificationClickedCallback), this);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkWebKitNotificationProviderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -48,6 +48,8 @@
</span><span class="cx"> static void notificationCloseCallback(WebKitNotification*, WebKitNotificationProvider*);
</span><span class="cx"> static void notificationClickedCallback(WebKitNotification*, WebKitNotificationProvider*);
</span><span class="cx">
</span><ins>+ void withdrawAnyPreviousNotificationMatchingTag(const String&);
+
</ins><span class="cx"> RefPtr<WebNotificationManagerProxy> m_notificationManager;
</span><span class="cx"> HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPIgtkdocswebkit2gtk40sectionstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -670,6 +670,7 @@
</span><span class="cx"> webkit_notification_get_id
</span><span class="cx"> webkit_notification_get_title
</span><span class="cx"> webkit_notification_get_body
</span><ins>+webkit_notification_get_tag
</ins><span class="cx"> webkit_notification_close
</span><span class="cx"> webkit_notification_clicked
</span><span class="cx">
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Tools/ChangeLog        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-11-24 Michael Catanzaro <mcatanzaro@igalia.com>
+
+ [GTK] Notifications API does not expose or respect the "tag" attribute
+ https://bugs.webkit.org/show_bug.cgi?id=164771
+
+ Reviewed by Gustavo Noronha Silva.
+
+ Verify that showing a notification with the same tag as another notification closes the
+ previous notification before the new notification is shown.
+
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp:
+ (testWebViewNotification):
+
</ins><span class="cx"> 2016-11-24 Carlos Garcia Campos <cgarcia@igalia.com>
</span><span class="cx">
</span><span class="cx"> Unreviewed. Fix GTK+ test /webkit2/WebKitWebContext/get-plugins after r208429.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp (208973 => 208974)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp        2016-11-24 15:08:11 UTC (rev 208973)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp        2016-11-24 20:10:25 UTC (rev 208974)
</span><span class="lines">@@ -677,6 +677,7 @@
</span><span class="cx">
</span><span class="cx"> static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test)
</span><span class="cx"> {
</span><ins>+ g_assert(!test->m_notification);
</ins><span class="cx"> test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification));
</span><span class="cx"> test->m_notification = notification;
</span><span class="cx"> g_signal_connect(notification, "closed", G_CALLBACK(notificationClosedCallback), test);
</span><span class="lines">@@ -732,6 +733,16 @@
</span><span class="cx"> g_main_loop_run(m_mainLoop);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ void requestNotificationAndWaitUntilShown(const char* title, const char* body, const char* tag)
+ {
+ m_event = None;
+
+ GUniquePtr<char> jscode(g_strdup_printf("n = new Notification('%s', { body: '%s', tag: '%s'});", title, body, tag));
+ webkit_web_view_run_javascript(m_webView, jscode.get(), nullptr, nullptr, nullptr);
+
+ g_main_loop_run(m_mainLoop);
+ }
+
</ins><span class="cx"> void clickNotificationAndWaitUntilClicked()
</span><span class="cx"> {
</span><span class="cx"> m_event = None;
</span><span class="lines">@@ -773,12 +784,14 @@
</span><span class="cx">
</span><span class="cx"> static const char* title = "This is a notification";
</span><span class="cx"> static const char* body = "This is the body.";
</span><del>- test->requestNotificationAndWaitUntilShown(title, body);
</del><ins>+ static const char* tag = "This is the tag.";
+ test->requestNotificationAndWaitUntilShown(title, body, tag);
</ins><span class="cx">
</span><span class="cx"> g_assert(test->m_event == NotificationWebViewTest::Shown);
</span><span class="cx"> g_assert(test->m_notification);
</span><span class="cx"> g_assert_cmpstr(webkit_notification_get_title(test->m_notification), ==, title);
</span><span class="cx"> g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body);
</span><ins>+ g_assert_cmpstr(webkit_notification_get_tag(test->m_notification), ==, tag);
</ins><span class="cx">
</span><span class="cx"> test->clickNotificationAndWaitUntilClicked();
</span><span class="cx"> g_assert(test->m_event == NotificationWebViewTest::OnClicked);
</span><span class="lines">@@ -788,13 +801,18 @@
</span><span class="cx">
</span><span class="cx"> test->requestNotificationAndWaitUntilShown(title, body);
</span><span class="cx"> g_assert(test->m_event == NotificationWebViewTest::Shown);
</span><ins>+ g_assert_cmpstr(webkit_notification_get_tag(test->m_notification), ==, nullptr);
</ins><span class="cx">
</span><span class="cx"> test->closeNotificationAndWaitUntilOnClosed();
</span><span class="cx"> g_assert(test->m_event == NotificationWebViewTest::OnClosed);
</span><span class="cx">
</span><del>- test->requestNotificationAndWaitUntilShown(title, body);
</del><ins>+ // The first notification should be closed automatically because the tag is
+ // the same. It will crash in showNotificationCallback on failure.
+ test->requestNotificationAndWaitUntilShown(title, body, tag);
+ test->requestNotificationAndWaitUntilShown(title, body, tag);
</ins><span class="cx"> g_assert(test->m_event == NotificationWebViewTest::Shown);
</span><span class="cx">
</span><ins>+ // Notification should be closed when navigating to a different webpage.
</ins><span class="cx"> test->loadURI(gServer->getURIForPath("/").data());
</span><span class="cx"> test->waitUntilLoadFinished();
</span><span class="cx"> g_assert(test->m_event == NotificationWebViewTest::Closed);
</span></span></pre>
</div>
</div>
</body>
</html>