Changeset 106592 in webkit


Ignore:
Timestamp:
Feb 2, 2012 2:16:14 PM (12 years ago)
Author:
jonlee@apple.com
Message:

Clear shown notifications when context is no longer active
https://bugs.webkit.org/show_bug.cgi?id=77363
<rdar://problem/10568907>

Reviewed by Darin Adler.

Source/WebCore:

  • notifications/NotificationPresenter.h: Add new virtual function to clear notifications

associated with a given execution context. By default the notifications are left alone, as
before. Individual implementations can override to allow notifications to clear them.

  • notifications/NotificationCenter.cpp:

(WebCore::NotificationCenter::disconnectFrame): When disconnecting the page from the frame, we
call clearNotifications().

  • page/Frame.cpp:

(WebCore::Frame::pageDestroyed): When the page is destroyed, tell the DOM window to reset notifications.

Source/WebKit/win:

  • WebCoreSupport/WebDesktopNotificationsDelegate.h:

(WebDesktopNotificationsDelegate): Add previously missing virtual functions.

  • WebCoreSupport/WebDesktopNotificationsDelegate.cpp:

(WebDesktopNotificationsDelegate::notificationControllerDestroyed):
(WebDesktopNotificationsDelegate::cancelRequestsForPermission):

Source/WebKit2:

  • WebProcess/WebCoreSupport/WebNotificationClient.cpp:

(WebKit::WebNotificationClient::clearNotifications): Forward the call to
WebNotificationManager.

  • WebProcess/WebCoreSupport/WebNotificationClient.h:

(WebNotificationClient):

  • WebProcess/Notifications/WebNotificationManager.h: Add an additional map that maps

all notifications associated with a given ScriptExecutionContext instance.

  • WebProcess/Notifications/WebNotificationManager.cpp:

(WebKit::WebNotificationManager::show): Create a map entry for the notification's
context if it doesn't exist already, and note that notification's ID. Also, correct
the return value of show() if notifications are not enabled, to return false.
(WebKit::WebNotificationManager::didCloseNotifications): When the notification is closed,
we remove that notification from the map.
(WebKit::WebNotificationManager::clearNotifications): Use the map entry for the given
context, and pass that along to the proxy so that all of the notifications with those IDs
can be cleared. In the meantime, we remove that context's map entry.

  • UIProcess/Notifications/WebNotificationManagerProxy.messages.in: New ClearNotifications()

message.

  • UIProcess/Notifications/WebNotificationManagerProxy.h:
  • UIProcess/Notifications/WebNotificationManagerProxy.cpp:

(WebKit::WebNotificationManagerProxy::clearNotifications): Forward the call to the provider.
Then remove this proxy's entries for the given notification IDs.

  • UIProcess/Notifications/WebNotificationProvider.cpp:

(WebKit::WebNotificationProvider::clearNotifications): Convert the vector of IDs to a mutable
array.

  • UIProcess/Notifications/WebNotificationProvider.h:

(WebNotificationProvider):

  • UIProcess/API/C/WKNotificationProvider.h: Add WK API to tell the platform to clear the notifications.

Remove the #if guard since they already exist in WebNotificationManager functions:

  • WebProcess/WebCoreSupport/WebNotificationClient.cpp:

(WebKit::WebNotificationClient::show):
(WebKit::WebNotificationClient::cancel):
(WebKit::WebNotificationClient::notificationObjectDestroyed):

Location:
trunk/Source
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106588 r106592  
     12012-02-02  Jon Lee  <jonlee@apple.com>
     2
     3        Clear shown notifications when context is no longer active
     4        https://bugs.webkit.org/show_bug.cgi?id=77363
     5        <rdar://problem/10568907>
     6
     7        Reviewed by Darin Adler.
     8
     9        * notifications/NotificationPresenter.h: Add new virtual function to clear notifications
     10        associated with a given execution context. By default the notifications are left alone, as
     11        before. Individual implementations can override to allow notifications to clear them.
     12
     13        * notifications/NotificationCenter.cpp:
     14        (WebCore::NotificationCenter::disconnectFrame): When disconnecting the page from the frame, we
     15        call clearNotifications().
     16        * page/Frame.cpp:
     17        (WebCore::Frame::pageDestroyed): When the page is destroyed, tell the DOM window to reset notifications.
     18
    1192012-02-02  Anders Carlsson  <andersca@apple.com>
    220
  • trunk/Source/WebCore/notifications/NotificationCenter.cpp

    r97667 r106592  
    6767        return;
    6868    m_notificationPresenter->cancelRequestsForPermission(scriptExecutionContext());
     69    m_notificationPresenter->clearNotifications(scriptExecutionContext());
    6970    m_notificationPresenter = 0;
    7071}
  • trunk/Source/WebCore/notifications/NotificationPresenter.h

    r103975 r106592  
    5858    virtual void cancel(Notification*) = 0;
    5959
     60    // When the user closes a page, or quits the client application, all of the page's
     61    // associated notifications are cleared.
     62    virtual void clearNotifications(ScriptExecutionContext*) { }
     63   
    6064    // Informs the presenter that a Notification object has been destroyed
    6165    // (such as by a page transition). The presenter may continue showing
  • trunk/Source/WebCore/page/Frame.cpp

    r104372 r106592  
    669669    if (m_domWindow) {
    670670        m_domWindow->resetGeolocation();
     671#if ENABLE(NOTIFICATIONS)
     672        m_domWindow->resetNotifications();
     673#endif
    671674        m_domWindow->pageDestroyed();
    672675    }
  • trunk/Source/WebKit/win/ChangeLog

    r106513 r106592  
     12012-02-02  Jon Lee  <jonlee@apple.com>
     2
     3        Clear shown notifications when context is no longer active
     4        https://bugs.webkit.org/show_bug.cgi?id=77363
     5        <rdar://problem/10568907>
     6
     7        Reviewed by Darin Adler.
     8
     9        * WebCoreSupport/WebDesktopNotificationsDelegate.h:
     10        (WebDesktopNotificationsDelegate): Add previously missing virtual functions.
     11        * WebCoreSupport/WebDesktopNotificationsDelegate.cpp:
     12        (WebDesktopNotificationsDelegate::notificationControllerDestroyed):
     13        (WebDesktopNotificationsDelegate::cancelRequestsForPermission):
     14
    1152012-02-01  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/Source/WebKit/win/WebCoreSupport/WebDesktopNotificationsDelegate.cpp

    r82120 r106592  
    166166}
    167167
     168void WebDesktopNotificationsDelegate::notificationControllerDestroyed()
     169{
     170}
     171
    168172void WebDesktopNotificationsDelegate::requestPermission(SecurityOrigin* origin, PassRefPtr<VoidCallback> callback)
    169173{
     
    171175    if (hasNotificationDelegate())
    172176        notificationDelegate()->requestNotificationPermission(org);
     177}
     178
     179void WebDesktopNotificationsDelegate::cancelRequestsForPermission(ScriptExecutionContext* context)
     180{
    173181}
    174182
  • trunk/Source/WebKit/win/WebCoreSupport/WebDesktopNotificationsDelegate.h

    r82120 r106592  
    5050    virtual void cancel(WebCore::Notification* object);
    5151    virtual void notificationObjectDestroyed(WebCore::Notification* object);
     52    virtual void notificationControllerDestroyed();
    5253    virtual void requestPermission(WebCore::SecurityOrigin* origin, PassRefPtr<WebCore::VoidCallback> callback);
     54    virtual void cancelRequestsForPermission(WebCore::ScriptExecutionContext*);
    5355    virtual WebCore::NotificationPresenter::Permission checkPermission(const KURL& url);
    5456
  • trunk/Source/WebKit2/ChangeLog

    r106572 r106592  
     12012-02-02  Jon Lee  <jonlee@apple.com>
     2
     3        Clear shown notifications when context is no longer active
     4        https://bugs.webkit.org/show_bug.cgi?id=77363
     5        <rdar://problem/10568907>
     6
     7        Reviewed by Darin Adler.
     8
     9        * WebProcess/WebCoreSupport/WebNotificationClient.cpp:
     10        (WebKit::WebNotificationClient::clearNotifications): Forward the call to
     11        WebNotificationManager.
     12        * WebProcess/WebCoreSupport/WebNotificationClient.h:
     13        (WebNotificationClient):
     14
     15        * WebProcess/Notifications/WebNotificationManager.h: Add an additional map that maps
     16        all notifications associated with a given ScriptExecutionContext instance.
     17        * WebProcess/Notifications/WebNotificationManager.cpp:
     18        (WebKit::WebNotificationManager::show): Create a map entry for the notification's
     19        context if it doesn't exist already, and note that notification's ID. Also, correct
     20        the return value of show() if notifications are not enabled, to return false.
     21        (WebKit::WebNotificationManager::didCloseNotifications): When the notification is closed,
     22        we remove that notification from the map.
     23        (WebKit::WebNotificationManager::clearNotifications): Use the map entry for the given
     24        context, and pass that along to the proxy so that all of the notifications with those IDs
     25        can be cleared. In the meantime, we remove that context's map entry.
     26
     27        * UIProcess/Notifications/WebNotificationManagerProxy.messages.in: New ClearNotifications()
     28        message.
     29        * UIProcess/Notifications/WebNotificationManagerProxy.h:
     30        * UIProcess/Notifications/WebNotificationManagerProxy.cpp:
     31        (WebKit::WebNotificationManagerProxy::clearNotifications): Forward the call to the provider.
     32        Then remove this proxy's entries for the given notification IDs.
     33
     34        * UIProcess/Notifications/WebNotificationProvider.cpp:
     35        (WebKit::WebNotificationProvider::clearNotifications): Convert the vector of IDs to a mutable
     36        array.
     37        * UIProcess/Notifications/WebNotificationProvider.h:
     38        (WebNotificationProvider):
     39
     40        * UIProcess/API/C/WKNotificationProvider.h: Add WK API to tell the platform to clear the notifications.
     41
     42        Remove the #if guard since they already exist in WebNotificationManager functions:
     43        * WebProcess/WebCoreSupport/WebNotificationClient.cpp:
     44        (WebKit::WebNotificationClient::show):
     45        (WebKit::WebNotificationClient::cancel):
     46        (WebKit::WebNotificationClient::notificationObjectDestroyed):
     47
    1482012-02-02  Anders Carlsson  <andersca@apple.com>
    249
  • trunk/Source/WebKit2/UIProcess/API/C/WKNotificationProvider.h

    r105364 r106592  
    3939typedef void (*WKNotificationProviderRemoveNotificationManagerCallback)(WKNotificationManagerRef manager, const void* clientInfo);
    4040typedef WKDictionaryRef (*WKNotificationProviderNotificationPermissionsCallback)(const void* clientInfo);
     41typedef void (*WKNotificationProviderClearNotificationsCallback)(WKArrayRef notificationIDs, const void* clientInfo);
    4142
    4243struct WKNotificationProvider {
     
    4950    WKNotificationProviderRemoveNotificationManagerCallback               removeNotificationManager;
    5051    WKNotificationProviderNotificationPermissionsCallback                 notificationPermissions;
     52    WKNotificationProviderClearNotificationsCallback                      clearNotifications;
    5153};
    5254typedef struct WKNotificationProvider WKNotificationProvider;
  • trunk/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.cpp

    r105364 r106592  
    112112}
    113113
     114void WebNotificationManagerProxy::clearNotifications(const Vector<uint64_t>& notificationIDs)
     115{
     116    m_provider.clearNotifications(notificationIDs);
     117    size_t count = notificationIDs.size();
     118    for (size_t i = 0; i < count; ++i)
     119        m_notifications.remove(notificationIDs[i]);
     120}
     121
    114122void WebNotificationManagerProxy::providerDidShowNotification(uint64_t notificationID)
    115123{
  • trunk/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.h

    r105364 r106592  
    8181    void cancel(uint64_t notificationID);
    8282    void didDestroyNotification(uint64_t notificationID);
     83    void clearNotifications(const Vector<uint64_t>& notificationIDs);
    8384
    8485    typedef HashMap<uint64_t, RefPtr<WebNotification> > WebNotificationMap;
  • trunk/Source/WebKit2/UIProcess/Notifications/WebNotificationManagerProxy.messages.in

    r105364 r106592  
    2424    Cancel(uint64_t notificationID);
    2525    DidDestroyNotification(uint64_t notificationID);
     26    ClearNotifications(Vector<uint64_t> notificationIDs);
    2627}
  • trunk/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.cpp

    r105364 r106592  
    2828
    2929#include "ImmutableDictionary.h"
     30#include "MutableArray.h"
    3031#include "WKAPICast.h"
    3132#include "WebNotification.h"
    3233#include "WebNotificationManagerProxy.h"
     34#include "WebNumber.h"
    3335#include "WebSecurityOrigin.h"
    3436
     
    5961}
    6062
     63void WebNotificationProvider::clearNotifications(const Vector<uint64_t>& notificationIDs)
     64{
     65    if (!m_client.clearNotifications)
     66        return;
     67
     68    RefPtr<MutableArray> arrayIDs = MutableArray::create();
     69    size_t count = notificationIDs.size();
     70    arrayIDs->reserveCapacity(count);
     71    for (size_t i = 0; i < count; ++i)
     72        arrayIDs->append(WebUInt64::create(notificationIDs[i]).leakRef());
     73
     74    m_client.clearNotifications(toAPI(arrayIDs.get()), m_client.clientInfo);
     75}
     76
    6177void WebNotificationProvider::addNotificationManager(WebNotificationManagerProxy* manager)
    6278{
  • trunk/Source/WebKit2/UIProcess/Notifications/WebNotificationProvider.h

    r105364 r106592  
    3030#include "WKNotificationProvider.h"
    3131#include <wtf/Forward.h>
     32#include <wtf/Vector.h>
    3233
    3334namespace WebKit {
     
    4445    void cancel(WebNotification*);
    4546    void didDestroyNotification(WebNotification*);
     47    void clearNotifications(const Vector<uint64_t>& notificationIDs);
    4648
    4749    void addNotificationManager(WebNotificationManagerProxy*);
  • trunk/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.cpp

    r105367 r106592  
    3434#include "WebNotificationManagerProxyMessages.h"
    3535#include "WebPageProxyMessages.h"
     36#include <WebCore/Document.h>
    3637#include <WebCore/Notification.h>
    3738#include <WebCore/Page.h>
     
    114115    m_notificationIDMap.set(notificationID, notification);
    115116   
     117    NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
     118    if (it == m_notificationContextMap.end()) {
     119        pair<NotificationContextMap::iterator, bool> addedPair = m_notificationContextMap.add(notification->scriptExecutionContext(), Vector<uint64_t>());
     120        it = addedPair.first;
     121    }
     122    it->second.append(notificationID);
     123   
    116124    m_process->connection()->send(Messages::WebPageProxy::ShowNotification(notification->contents().title, notification->contents().body, notification->scriptExecutionContext()->securityOrigin()->toString(), notificationID), page->pageID());
    117 #endif
    118125    return true;
     126#else
     127    return false;
     128#endif
    119129}
    120130
     
    130140   
    131141    m_process->connection()->send(Messages::WebNotificationManagerProxy::Cancel(notificationID), page->pageID());
     142#endif
     143}
     144
     145void WebNotificationManager::clearNotifications(WebCore::ScriptExecutionContext* context, WebPage* page)
     146{
     147#if ENABLE(NOTIFICATIONS)
     148    NotificationContextMap::iterator it = m_notificationContextMap.find(context);
     149    if (it == m_notificationContextMap.end())
     150        return;
     151   
     152    m_process->connection()->send(Messages::WebNotificationManagerProxy::ClearNotifications(it->second), page->pageID());
     153    m_notificationContextMap.remove(it);
    132154#endif
    133155}
     
    186208            continue;
    187209
     210        NotificationContextMap::iterator it = m_notificationContextMap.find(notification->scriptExecutionContext());
     211        ASSERT(it != m_notificationContextMap.end());
     212        size_t index = it->second.find(notificationID);
     213        ASSERT(index != notFound);
     214        it->second.remove(index);
     215
    188216        notification->dispatchCloseEvent();
    189217    }
  • trunk/Source/WebKit2/WebProcess/Notifications/WebNotificationManager.h

    r105364 r106592  
    6060    bool show(WebCore::Notification*, WebPage*);
    6161    void cancel(WebCore::Notification*, WebPage*);
     62    void clearNotifications(WebCore::ScriptExecutionContext*, WebPage*);
    6263    // This callback comes from WebCore, not messaged from the UI process.
    6364    void didDestroyNotification(WebCore::Notification*, WebPage*);
     
    8788    NotificationIDMap m_notificationIDMap;
    8889   
     90    typedef HashMap<RefPtr<WebCore::ScriptExecutionContext>, Vector<uint64_t> > NotificationContextMap;
     91    NotificationContextMap m_notificationContextMap;
     92   
    8993    HashMap<String, bool> m_permissionsMap;
    9094#endif
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebNotificationClient.cpp

    r103975 r106592  
    3333#include "WebPage.h"
    3434#include "WebProcess.h"
    35 #include <WebCore/NotImplemented.h>
    3635#include <WebCore/ScriptExecutionContext.h>
    3736
     
    5150bool WebNotificationClient::show(Notification* notification)
    5251{
    53 #if ENABLE(NOTIFICATIONS)
    5452    return WebProcess::shared().notificationManager().show(notification, m_page);
    55 #else
    56     notImplemented();
    57     return false;
    58 #endif
    5953}
    6054
    6155void WebNotificationClient::cancel(Notification* notification)
    6256{
    63 #if ENABLE(NOTIFICATIONS)
    6457    WebProcess::shared().notificationManager().cancel(notification, m_page);
    65 #else
    66     notImplemented();
    67 #endif
     58}
     59
     60void WebNotificationClient::clearNotifications(ScriptExecutionContext* context)
     61{
     62    WebProcess::shared().notificationManager().clearNotifications(context, m_page);
    6863}
    6964
    7065void WebNotificationClient::notificationObjectDestroyed(Notification* notification)
    7166{
    72 #if ENABLE(NOTIFICATIONS)
    7367    WebProcess::shared().notificationManager().didDestroyNotification(notification, m_page);
    74 #else
    75     UNUSED_PARAM(notification);
    76     notImplemented();
    77 #endif
    7868}
    7969
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebNotificationClient.h

    r103975 r106592  
    4848    virtual bool show(WebCore::Notification*) OVERRIDE;
    4949    virtual void cancel(WebCore::Notification*) OVERRIDE;
     50    virtual void clearNotifications(WebCore::ScriptExecutionContext*) OVERRIDE;
    5051    virtual void notificationObjectDestroyed(WebCore::Notification*) OVERRIDE;
    5152    virtual void notificationControllerDestroyed() OVERRIDE;
Note: See TracChangeset for help on using the changeset viewer.