Changeset 208974 in webkit


Ignore:
Timestamp:
Nov 24, 2016 12:10:25 PM (7 years ago)
Author:
Michael Catanzaro
Message:

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

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r208961 r208974  
     12016-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
    1222016-11-22  Sergio Villar Senin  <svillar@igalia.com>
    223
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.cpp

    r193721 r208974  
    4040    PROP_ID,
    4141    PROP_TITLE,
    42     PROP_BODY
     42    PROP_BODY,
     43    PROP_TAG
    4344};
    4445
     
    5354    CString title;
    5455    CString body;
     56    CString tag;
    5557    guint64 id;
    5658
     
    7678        g_value_set_string(value, webkit_notification_get_body(notification));
    7779        break;
     80    case PROP_TAG:
     81        g_value_set_string(value, webkit_notification_get_tag(notification));
     82        break;
    7883    default:
    7984        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     
    132137
    133138    /**
     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    /**
    134154     * WebKitNotification::closed:
    135155     * @notification: the #WebKitNotification on which the signal is emitted
     
    177197    notification->priv->title = webNotification.title().utf8();
    178198    notification->priv->body = webNotification.body().utf8();
     199    notification->priv->tag = webNotification.tag().utf8();
    179200    notification->priv->webView = webView;
    180201    return notification;
     
    238259
    239260/**
     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 */
     270const 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/**
    240279 * webkit_notification_close:
    241280 * @notification: a #WebKitNotification
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotification.h

    r193721 r208974  
    7171webkit_notification_get_body                 (WebKitNotification *notification);
    7272
     73WEBKIT_API const gchar *
     74webkit_notification_get_tag                  (WebKitNotification *notification);
     75
    7376WEBKIT_API void
    7477webkit_notification_close                    (WebKitNotification *notification);
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.cpp

    r194496 r208974  
    103103}
    104104
     105void 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
    105123void WebKitNotificationProvider::show(WebPageProxy* page, const WebNotification& webNotification)
    106124{
     
    108126
    109127    if (!notification) {
     128        withdrawAnyPreviousNotificationMatchingTag(webNotification.tag());
    110129        notification = adoptGRef(webkitNotificationCreate(WEBKIT_WEB_VIEW(page->viewWidget()), webNotification));
    111130        g_signal_connect(notification.get(), "closed", G_CALLBACK(notificationCloseCallback), this);
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitNotificationProvider.h

    r204466 r208974  
    4949    static void notificationClickedCallback(WebKitNotification*, WebKitNotificationProvider*);
    5050
     51    void withdrawAnyPreviousNotificationMatchingTag(const String&);
     52
    5153    RefPtr<WebNotificationManagerProxy> m_notificationManager;
    5254    HashMap<uint64_t, GRefPtr<WebKitNotification>> m_notifications;
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r199795 r208974  
    671671webkit_notification_get_title
    672672webkit_notification_get_body
     673webkit_notification_get_tag
    673674webkit_notification_close
    674675webkit_notification_clicked
  • trunk/Tools/ChangeLog

    r208972 r208974  
     12016-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
    1142016-11-24  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebView.cpp

    r206302 r208974  
    678678    static gboolean showNotificationCallback(WebKitWebView*, WebKitNotification* notification, NotificationWebViewTest* test)
    679679    {
     680        g_assert(!test->m_notification);
    680681        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(notification));
    681682        test->m_notification = notification;
     
    733734    }
    734735
     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
    735746    void clickNotificationAndWaitUntilClicked()
    736747    {
     
    774785    static const char* title = "This is a notification";
    775786    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);
    777789
    778790    g_assert(test->m_event == NotificationWebViewTest::Shown);
     
    780792    g_assert_cmpstr(webkit_notification_get_title(test->m_notification), ==, title);
    781793    g_assert_cmpstr(webkit_notification_get_body(test->m_notification), ==, body);
     794    g_assert_cmpstr(webkit_notification_get_tag(test->m_notification), ==, tag);
    782795
    783796    test->clickNotificationAndWaitUntilClicked();
     
    789802    test->requestNotificationAndWaitUntilShown(title, body);
    790803    g_assert(test->m_event == NotificationWebViewTest::Shown);
     804    g_assert_cmpstr(webkit_notification_get_tag(test->m_notification), ==, nullptr);
    791805
    792806    test->closeNotificationAndWaitUntilOnClosed();
    793807    g_assert(test->m_event == NotificationWebViewTest::OnClosed);
    794808
    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);
    796813    g_assert(test->m_event == NotificationWebViewTest::Shown);
    797814
     815    // Notification should be closed when navigating to a different webpage.
    798816    test->loadURI(gServer->getURIForPath("/").data());
    799817    test->waitUntilLoadFinished();
Note: See TracChangeset for help on using the changeset viewer.