Changeset 208974 in webkit
- Timestamp:
- Nov 24, 2016 12:10:25 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r208961 r208974 1 2016-11-24 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 [GTK] Notifications API does not expose or respect the "tag" attribute 4 https://bugs.webkit.org/show_bug.cgi?id=164771 5 6 Reviewed by Gustavo Noronha Silva. 7 8 Expose a tag property on WebKitNotification. Ensure that any previous notification with the 9 same tag is closed when showing a new notification with that tag. 10 11 * UIProcess/API/gtk/WebKitNotification.cpp: 12 (webkit_notification_class_init): 13 (webkitNotificationCreate): 14 (webkit_notification_get_tag): 15 * UIProcess/API/gtk/WebKitNotification.h: 16 * UIProcess/API/gtk/WebKitNotificationProvider.cpp: 17 (WebKitNotificationProvider::withdrawAnyPreviousNotificationMatchingTag): 18 (WebKitNotificationProvider::show): 19 * UIProcess/API/gtk/WebKitNotificationProvider.h: 20 * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: 21 1 22 2016-11-22 Sergio Villar Senin <svillar@igalia.com> 2 23 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp
r193721 r208974 40 40 PROP_ID, 41 41 PROP_TITLE, 42 PROP_BODY 42 PROP_BODY, 43 PROP_TAG 43 44 }; 44 45 … … 53 54 CString title; 54 55 CString body; 56 CString tag; 55 57 guint64 id; 56 58 … … 76 78 g_value_set_string(value, webkit_notification_get_body(notification)); 77 79 break; 80 case PROP_TAG: 81 g_value_set_string(value, webkit_notification_get_tag(notification)); 82 break; 78 83 default: 79 84 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); … … 132 137 133 138 /** 139 * WebKitNotification:tag: 140 * 141 * The tag identifier for the notification. 142 * 143 * Since: 2.16 144 */ 145 g_object_class_install_property(objectClass, 146 PROP_TAG, 147 g_param_spec_string("tag", 148 _("Tag"), 149 _("The tag identifier for the notification"), 150 nullptr, 151 WEBKIT_PARAM_READABLE)); 152 153 /** 134 154 * WebKitNotification::closed: 135 155 * @notification: the #WebKitNotification on which the signal is emitted … … 177 197 notification->priv->title = webNotification.title().utf8(); 178 198 notification->priv->body = webNotification.body().utf8(); 199 notification->priv->tag = webNotification.tag().utf8(); 179 200 notification->priv->webView = webView; 180 201 return notification; … … 238 259 239 260 /** 261 * webkit_notification_get_tag: 262 * @notification: a #WebKitNotification 263 * 264 * Obtains the tag identifier for the notification. 265 * 266 * Returns: (allow-none): the tag for the notification 267 * 268 * Since: 2.16 269 */ 270 const gchar* webkit_notification_get_tag(WebKitNotification* notification) 271 { 272 g_return_val_if_fail(WEBKIT_IS_NOTIFICATION(notification), nullptr); 273 274 const gchar* tag = notification->priv->tag.data(); 275 return strlen(tag) > 0 ? tag : nullptr; 276 } 277 278 /** 240 279 * webkit_notification_close: 241 280 * @notification: a #WebKitNotification -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h
r193721 r208974 71 71 webkit_notification_get_body (WebKitNotification *notification); 72 72 73 WEBKIT_API const gchar * 74 webkit_notification_get_tag (WebKitNotification *notification); 75 73 76 WEBKIT_API void 74 77 webkit_notification_close (WebKitNotification *notification); -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp
r194496 r208974 103 103 } 104 104 105 void WebKitNotificationProvider::withdrawAnyPreviousNotificationMatchingTag(const String& tag) 106 { 107 if (tag.isEmpty()) 108 return; 109 110 for (auto& notification : m_notifications.values()) { 111 if (tag == webkit_notification_get_tag(notification.get())) { 112 webkit_notification_close(notification.get()); 113 break; 114 } 115 } 116 117 #ifndef NDEBUG 118 for (auto& notification : m_notifications.values()) 119 ASSERT(tag != webkit_notification_get_tag(notification.get())); 120 #endif 121 } 122 105 123 void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification) 106 124 { … … 108 126 109 127 if (!notification) { 128 withdrawAnyPreviousNotificationMatchingTag(webNotification.tag()); 110 129 notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification)); 111 130 g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this); -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h
r204466 r208974 49 49 static void notificationClickedCallback(WebKitNotification*, WebKitNotificationProvider*); 50 50 51 void withdrawAnyPreviousNotificationMatchingTag(const String&); 52 51 53 RefPtr<WebNotificationManagerProxy> m_notificationManager; 52 54 HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications; -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt
r199795 r208974 671 671 webkit_notification_get_title 672 672 webkit_notification_get_body 673 webkit_notification_get_tag 673 674 webkit_notification_close 674 675 webkit_notification_clicked -
trunk/Tools/ChangeLog
r208972 r208974 1 2016-11-24 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 [GTK] Notifications API does not expose or respect the "tag" attribute 4 https://bugs.webkit.org/show_bug.cgi?id=164771 5 6 Reviewed by Gustavo Noronha Silva. 7 8 Verify that showing a notification with the same tag as another notification closes the 9 previous notification before the new notification is shown. 10 11 * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp: 12 (testWebViewNotification): 13 1 14 2016-11-24 Carlos Garcia Campos <cgarcia@igalia.com> 2 15 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp
r206302 r208974 678 678 static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test) 679 679 { 680 g_assert(!test->m_notification); 680 681 test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification)); 681 682 test->m_notification = notification; … … 733 734 } 734 735 736 void requestNotificationAndWaitUntilShown(const char* title, const char* body, const char* tag) 737 { 738 m_event = None; 739 740 GUniquePtr<char> jscode(g_strdup_printf("n = new Notification('%s', { body: '%s', tag: '%s'});", title, body, tag)); 741 webkit_web_view_run_javascript(m_webView, jscode.get(), nullptr, nullptr, nullptr); 742 743 g_main_loop_run(m_mainLoop); 744 } 745 735 746 void clickNotificationAndWaitUntilClicked() 736 747 { … … 774 785 static const char* title = "This is a notification"; 775 786 static const char* body = "This is the body."; 776 test->requestNotificationAndWaitUntilShown(title, body); 787 static const char* tag = "This is the tag."; 788 test->requestNotificationAndWaitUntilShown(title, body, tag); 777 789 778 790 g_assert(test->m_event == NotificationWebViewTest::Shown); … … 780 792 g_assert_cmpstr(webkit_notification_get_title(test->m_notification), ==, title); 781 793 g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body); 794 g_assert_cmpstr(webkit_notification_get_tag(test->m_notification), ==, tag); 782 795 783 796 test->clickNotificationAndWaitUntilClicked(); … … 789 802 test->requestNotificationAndWaitUntilShown(title, body); 790 803 g_assert(test->m_event == NotificationWebViewTest::Shown); 804 g_assert_cmpstr(webkit_notification_get_tag(test->m_notification), ==, nullptr); 791 805 792 806 test->closeNotificationAndWaitUntilOnClosed(); 793 807 g_assert(test->m_event == NotificationWebViewTest::OnClosed); 794 808 795 test->requestNotificationAndWaitUntilShown(title, body); 809 // The first notification should be closed automatically because the tag is 810 // the same. It will crash in showNotificationCallback on failure. 811 test->requestNotificationAndWaitUntilShown(title, body, tag); 812 test->requestNotificationAndWaitUntilShown(title, body, tag); 796 813 g_assert(test->m_event == NotificationWebViewTest::Shown); 797 814 815 // Notification should be closed when navigating to a different webpage. 798 816 test->loadURI(gServer->getURIForPath("/").data()); 799 817 test->waitUntilLoadFinished();
Note: See TracChangeset
for help on using the changeset viewer.