Changeset 60566 in webkit
- Timestamp:
- Jun 2, 2010 7:31:13 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit/qt/Api/qwebpage.cpp
r60410 r60566 300 300 301 301 #if ENABLE(NOTIFICATIONS) 302 notificationPresenterClient = new NotificationPresenterClientQt(q);302 NotificationPresenterClientQt::notificationPresenter()->addClient(); 303 303 #endif 304 304 } … … 316 316 317 317 #if ENABLE(NOTIFICATIONS) 318 delete notificationPresenterClient;318 NotificationPresenterClientQt::notificationPresenter()->removeClient(); 319 319 #endif 320 320 } -
trunk/WebKit/qt/Api/qwebpage_p.h
r58405 r60566 45 45 class Element; 46 46 class InspectorController; 47 class NotificationPresenterClientQt;48 47 class Node; 49 48 class Page; … … 192 191 Qt::DropAction m_lastDropAction; 193 192 194 WebCore::NotificationPresenterClientQt* notificationPresenterClient;195 196 193 QString viewMode; 197 194 -
trunk/WebKit/qt/ChangeLog
r60537 r60566 1 2010-06-01 Yael Aharon <yael.aharon@nokia.com> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] Fix the lifecycle of notification objects 6 https://bugs.webkit.org/show_bug.cgi?id=40003 7 8 Notification objects are not tightly related to the page that created them, 9 and should be decoupled from the page. 10 Create one NotificationPresenter that handles all notifications. 11 Add ref/deref to the notification objects when they are added/removed from 12 the queue of active notifications. The same technique is used for XMLHttpRequest. 13 Instead of deleting all notifications associated with a page when the page is navigated, 14 delete them on a timer, using the same timeout that QSystemTrayIcon is using. 15 Break up the show() method into smaller methods. 16 Use OwnPtr instead of raw pointer for QSystemTrayIcon. 17 Move creating the QIcon to just before showing it in the QSyetemTrayIcon. 18 19 No new tests as this is just a refactoring. Existing notifications test cover the code. 20 21 * Api/qwebpage.cpp: 22 (QWebPagePrivate::QWebPagePrivate): 23 (QWebPagePrivate::~QWebPagePrivate): 24 * Api/qwebpage_p.h: 25 * WebCoreSupport/ChromeClientQt.cpp: 26 (WebCore::ChromeClientQt::notificationPresenter): 27 * WebCoreSupport/DumpRenderTreeSupportQt.cpp: 28 (DumpRenderTreeSupportQt::setNotificationsReceiver): 29 (DumpRenderTreeSupportQt::allowNotificationForOrigin): 30 * WebCoreSupport/DumpRenderTreeSupportQt.h: 31 * WebCoreSupport/FrameLoaderClientQt.cpp: 32 (WebCore::FrameLoaderClientQt::dispatchDidClearWindowObjectInWorld): 33 * WebCoreSupport/NotificationPresenterClientQt.cpp: 34 (WebCore::NotificationPresenterClientQt::notificationPresenter): 35 (WebCore::NotificationIconWrapper::NotificationIconWrapper): 36 (WebCore::NotificationIconWrapper::~NotificationIconWrapper): 37 (WebCore::NotificationIconWrapper::close): 38 (WebCore::NotificationPresenterClientQt::NotificationPresenterClientQt): 39 (WebCore::NotificationPresenterClientQt::removeClient): 40 (WebCore::NotificationPresenterClientQt::show): 41 (WebCore::NotificationPresenterClientQt::displayNotification): 42 (WebCore::NotificationPresenterClientQt::cancel): 43 (WebCore::NotificationPresenterClientQt::notificationObjectDestroyed): 44 (WebCore::NotificationPresenterClientQt::requestPermission): 45 (WebCore::NotificationPresenterClientQt::sendEvent): 46 (WebCore::NotificationPresenterClientQt::removeReplacedNotificationFromQueue): 47 (WebCore::NotificationPresenterClientQt::dumpReplacedIdText): 48 (WebCore::NotificationPresenterClientQt::dumpShowText): 49 * WebCoreSupport/NotificationPresenterClientQt.h: 50 (WebCore::NotificationPresenterClientQt::addClient): 51 1 52 2010-06-01 Noam Rosenthal <noam.rosenthal@nokia.com> 2 53 -
trunk/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp
r59765 r60566 488 488 NotificationPresenter* ChromeClientQt::notificationPresenter() const 489 489 { 490 return m_webPage->d->notificationPresenterClient;490 return NotificationPresenterClientQt::notificationPresenter(); 491 491 } 492 492 #endif -
trunk/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
r60349 r60566 538 538 } 539 539 540 void DumpRenderTreeSupportQt::setNotificationsReceiver(Q WebPage* page, QObject* receiver)540 void DumpRenderTreeSupportQt::setNotificationsReceiver(QObject* receiver) 541 541 { 542 542 #if ENABLE(NOTIFICATIONS) 543 page->d->notificationPresenterClient->setReceiver(receiver);544 #endif 545 } 546 547 void DumpRenderTreeSupportQt::allowNotificationForOrigin( QWebPage* page,const QString& origin)543 NotificationPresenterClientQt::notificationPresenter()->setReceiver(receiver); 544 #endif 545 } 546 547 void DumpRenderTreeSupportQt::allowNotificationForOrigin(const QString& origin) 548 548 { 549 549 #if ENABLE(NOTIFICATIONS) 550 page->d->notificationPresenterClient->allowNotificationForOrigin(origin);550 NotificationPresenterClientQt::notificationPresenter()->allowNotificationForOrigin(origin); 551 551 #endif 552 552 } -
trunk/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
r60348 r60566 38 38 39 39 typedef void (CheckPermissionFunctionType) (QObject* receiver, const QUrl&, NotificationPermission&); 40 typedef void (RequestPermissionFunctionType) (QObject* receiver, QWebPage* page,const QString&);40 typedef void (RequestPermissionFunctionType) (QObject* receiver, const QString&); 41 41 42 42 extern CheckPermissionFunctionType* checkPermissionFunction; … … 115 115 // These functions should eventually turn into public API 116 116 // and the "receiver" concept would go away 117 static void setNotificationsReceiver(Q WebPage* page, QObject* receiver);118 static void allowNotificationForOrigin( QWebPage* page,const QString& origin);117 static void setNotificationsReceiver(QObject* receiver); 118 static void allowNotificationForOrigin(const QString& origin); 119 119 static void setCheckPermissionFunction(CheckPermissionFunctionType*); 120 120 static void setRequestPermissionFunction(RequestPermissionFunctionType*); -
trunk/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
r60348 r60566 52 52 #include "HTMLPlugInElement.h" 53 53 #include "HTTPParsers.h" 54 #include "NotificationPresenterClientQt.h"55 54 #include "NotImplemented.h" 56 55 #include "QNetworkReplyHandler.h" … … 642 641 if (m_webFrame) { 643 642 emit m_webFrame->javaScriptWindowObjectCleared(); 644 #if ENABLE(NOTIFICATIONS)645 m_webFrame->page()->d->notificationPresenterClient->clearNotificationsList();646 #endif647 643 } 648 644 } -
trunk/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
r60348 r60566 39 39 #include "SecurityOrigin.h" 40 40 41 #include "qwebframe.h"42 41 #include "qwebkitglobal.h" 43 #include "qwebpage.h"44 42 #include <QtGui> 45 43 46 47 44 #if ENABLE(NOTIFICATIONS) 48 45 49 using namespace WebCore; 46 namespace WebCore { 47 48 const double notificationTimeout = 10.0; 50 49 51 50 bool NotificationPresenterClientQt::dumpNotification = false; 52 51 52 NotificationPresenterClientQt* s_notificationPresenter = 0; 53 54 NotificationPresenterClientQt* NotificationPresenterClientQt::notificationPresenter() 55 { 56 if (s_notificationPresenter) 57 return s_notificationPresenter; 58 59 s_notificationPresenter = new NotificationPresenterClientQt(); 60 return s_notificationPresenter; 61 } 62 53 63 NotificationIconWrapper::NotificationIconWrapper() 64 : m_closeTimer(this, &NotificationIconWrapper::close) 54 65 { 55 66 #ifndef QT_NO_SYSTEMTRAYICON 56 67 m_notificationIcon = 0; 57 68 #endif 69 m_closeTimer.startOneShot(notificationTimeout); 58 70 } 59 71 60 72 NotificationIconWrapper::~NotificationIconWrapper() 61 73 { 62 #ifndef QT_NO_SYSTEMTRAYICON 63 delete m_notificationIcon; 64 #endif 65 } 66 67 NotificationPresenterClientQt::NotificationPresenterClientQt(QWebPage* page) : m_page(page) 68 { 74 } 75 76 void NotificationIconWrapper::close(Timer<NotificationIconWrapper>*) 77 { 78 NotificationPresenterClientQt::notificationPresenter()->cancel(this); 79 } 80 81 NotificationPresenterClientQt::NotificationPresenterClientQt() : m_clientCount(0) 82 { 83 } 84 85 void NotificationPresenterClientQt::removeClient() 86 { 87 m_clientCount--; 88 if (!m_clientCount) { 89 s_notificationPresenter = 0; 90 delete this; 91 } 69 92 } 70 93 71 94 bool NotificationPresenterClientQt::show(Notification* notification) 72 95 { 73 QHash <Notification*, NotificationIconWrapper*>::Iterator end = m_notifications.end(); 74 QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.begin(); 75 96 // FIXME: workers based notifications are not supported yet. 97 if (notification->scriptExecutionContext()->isWorkerContext()) 98 return false; 99 notification->setPendingActivity(notification); 76 100 if (!notification->replaceId().isEmpty()) { 77 while (iter != end) { 78 Notification* existingNotification = iter.key(); 79 if (existingNotification->replaceId() == notification->replaceId() && existingNotification->url().protocol() == notification->url().protocol() && existingNotification->url().host() == notification->url().host()) 80 break; 81 iter++; 82 } 83 } else 84 iter = end; 85 86 if (dumpNotification) { 87 if (iter != end) { 88 Notification* oldNotification = iter.key(); 89 printf("REPLACING NOTIFICATION %s\n", oldNotification->isHTML() ? QString(oldNotification->url().string()).toUtf8().constData() : QString(oldNotification->contents().title()).toUtf8().constData()); 90 } 91 if (notification->isHTML()) 92 printf("DESKTOP NOTIFICATION: contents at %s\n", QString(notification->url().string()).toUtf8().constData()); 93 else { 94 printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n", 95 notification->dir() == "rtl" ? "(RTL)" : "", 96 QString(notification->contents().icon().string()).toUtf8().constData(), QString(notification->contents().title()).toUtf8().constData(), 97 QString(notification->contents().body()).toUtf8().constData()); 98 } 99 } 100 101 if (iter != end) { 102 sendEvent(iter.key(), eventNames().closeEvent); 103 delete m_notifications.take(iter.key()); 104 } 101 removeReplacedNotificationFromQueue(notification); 102 } 103 if (dumpNotification) 104 dumpShowText(notification); 105 displayNotification(notification, QByteArray()); 106 return true; 107 } 108 109 void NotificationPresenterClientQt::displayNotification(Notification* notification, const QByteArray& bytes) 110 { 105 111 NotificationIconWrapper* wrapper = new NotificationIconWrapper(); 106 112 m_notifications.insert(notification, wrapper); 113 QString title; 114 QString message; 115 // FIXME: download & display HTML notifications 116 if (notification->isHTML()) 117 message = notification->url().string(); 118 else { 119 title = notification->contents().title(); 120 message = notification->contents().body(); 121 } 122 123 #ifndef QT_NO_SYSTEMTRAYICON 124 QPixmap pixmap; 125 if (bytes.length() && pixmap.loadFromData(bytes)) { 126 QIcon icon(pixmap); 127 wrapper->m_notificationIcon = new QSystemTrayIcon(icon); 128 } else 129 wrapper->m_notificationIcon = new QSystemTrayIcon(); 130 #endif 131 107 132 sendEvent(notification, "display"); 108 133 134 // Make sure the notification was not cancelled during handling the display event 135 if (m_notifications.find(notification) == m_notifications.end()) 136 return; 137 109 138 #ifndef QT_NO_SYSTEMTRAYICON 110 wrapper->m_notificationIcon = new QSystemTrayIcon;111 139 wrapper->m_notificationIcon->show(); 112 140 wrapper->m_notificationIcon->showMessage(notification->contents().title(), notification->contents().body()); 113 141 #endif 114 return true;115 142 } 116 143 117 144 void NotificationPresenterClientQt::cancel(Notification* notification) 118 { 145 { 119 146 if (dumpNotification) { 120 147 if (notification->isHTML()) … … 124 151 } 125 152 126 QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.find(notification); 127 if (iter != m_notifications.end()) 128 sendEvent(iter.key(), eventNames().closeEvent); 153 NotificationsQueue::Iterator iter = m_notifications.find(notification); 154 if (iter != m_notifications.end()) { 155 sendEvent(notification, eventNames().closeEvent); 156 delete m_notifications.take(notification); 157 notification->unsetPendingActivity(notification); 158 } 159 } 160 161 void NotificationPresenterClientQt::cancel(NotificationIconWrapper* wrapper) 162 { 163 NotificationsQueue::Iterator end = m_notifications.end(); 164 NotificationsQueue::Iterator iter = m_notifications.begin(); 165 while (iter != end && iter.value() != wrapper) 166 iter++; 167 if (iter != end) 168 cancel(iter.key()); 129 169 } 130 170 … … 132 172 { 133 173 // Called from ~Notification(), Remove the entry from the notifications list and delete the icon. 134 QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.find(notification);174 NotificationsQueue::Iterator iter = m_notifications.find(notification); 135 175 if (iter != m_notifications.end()) 136 176 delete m_notifications.take(notification); … … 140 180 { 141 181 if (dumpNotification) 142 printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", QString(origin->toString()).toUtf8().constData());182 printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", QString(origin->toString()).toUtf8().constData()); 143 183 144 184 QString originString = origin->toString(); … … 152 192 m_pendingPermissionRequests.insert(originString, callbacks); 153 193 if (requestPermissionFunction) 154 requestPermissionFunction(m_receiver, m_page,originString);194 requestPermissionFunction(m_receiver, originString); 155 195 } 156 196 } … … 185 225 } 186 226 187 void NotificationPresenterClientQt::clearNotificationsList()188 {189 m_pendingPermissionRequests.clear();190 while (!m_notifications.isEmpty()) {191 QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.begin();192 delete m_notifications.take(iter.key());193 }194 }195 196 227 void NotificationPresenterClientQt::sendEvent(Notification* notification, const AtomicString& eventName) 197 228 { 198 RefPtr<Event> event = Event::create(eventName, false, true); 199 notification->dispatchEvent(event.release()); 200 } 201 229 notification->dispatchEvent(Event::create(eventName, false, true)); 230 } 231 232 void NotificationPresenterClientQt::removeReplacedNotificationFromQueue(Notification* notification) 233 { 234 Notification* oldNotification = 0; 235 NotificationsQueue::Iterator end = m_notifications.end(); 236 NotificationsQueue::Iterator iter = m_notifications.begin(); 237 238 while (iter != end) { 239 Notification* existingNotification = iter.key(); 240 if (existingNotification->replaceId() == notification->replaceId() && existingNotification->url().protocol() == notification->url().protocol() && existingNotification->url().host() == notification->url().host()) { 241 oldNotification = iter.key(); 242 break; 243 } 244 iter++; 245 } 246 247 if (oldNotification) { 248 if (dumpNotification) 249 dumpReplacedIdText(oldNotification); 250 sendEvent(oldNotification, eventNames().closeEvent); 251 delete m_notifications.take(oldNotification); 252 oldNotification->unsetPendingActivity(oldNotification); 253 } 254 } 255 256 void NotificationPresenterClientQt::dumpReplacedIdText(Notification* notification) 257 { 258 if (notification) 259 printf("REPLACING NOTIFICATION %s\n", notification->isHTML() ? QString(notification->url().string()).toUtf8().constData() : QString(notification->contents().title()).toUtf8().constData()); 260 } 261 262 void NotificationPresenterClientQt::dumpShowText(Notification* notification) 263 { 264 if (notification->isHTML()) 265 printf("DESKTOP NOTIFICATION: contents at %s\n", QString(notification->url().string()).toUtf8().constData()); 266 else { 267 printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n", 268 notification->dir() == "rtl" ? "(RTL)" : "", 269 QString(notification->contents().icon().string()).toUtf8().constData(), QString(notification->contents().title()).toUtf8().constData(), 270 QString(notification->contents().body()).toUtf8().constData()); 271 } 272 } 273 274 } 202 275 #endif // ENABLE(NOTIFICATIONS) -
trunk/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
r60348 r60566 35 35 #include "Notification.h" 36 36 #include "NotificationPresenter.h" 37 #include "Timer.h" 37 38 38 39 #include <QMultiHash> 39 40 #include <QSystemTrayIcon> 40 41 41 42 42 #if ENABLE(NOTIFICATIONS) 43 class QWebPage;44 43 45 44 namespace WebCore { 45 46 46 class Document; 47 47 class KURL; 48 48 49 struct NotificationIconWrapper { 49 class NotificationIconWrapper { 50 public: 50 51 NotificationIconWrapper(); 51 52 ~NotificationIconWrapper(); 53 void close(); 54 void close(Timer<NotificationIconWrapper>*); 52 55 #ifndef QT_NO_SYSTEMTRAYICON 53 QSystemTrayIcon*m_notificationIcon;56 OwnPtr<QSystemTrayIcon> m_notificationIcon; 54 57 #endif 58 Timer<NotificationIconWrapper> m_closeTimer; 55 59 }; 60 61 typedef QHash <Notification*, NotificationIconWrapper*> NotificationsQueue; 56 62 57 63 class NotificationPresenterClientQt : public NotificationPresenter { 58 64 public: 59 NotificationPresenterClientQt( QWebPage*);65 NotificationPresenterClientQt(); 60 66 ~NotificationPresenterClientQt() {} 61 67 … … 67 73 virtual NotificationPresenter::Permission checkPermission(const KURL&); 68 74 75 void cancel(NotificationIconWrapper*); 76 69 77 void allowNotificationForOrigin(const QString& origin); 70 void clearNotificationsList();71 78 72 79 static bool dumpNotification; … … 74 81 void setReceiver(QObject* receiver) { m_receiver = receiver; } 75 82 83 void addClient() { m_clientCount++; } 84 void removeClient(); 85 static NotificationPresenterClientQt* notificationPresenter(); 86 76 87 private: 77 88 void sendEvent(Notification*, const AtomicString& eventName); 78 QWebPage* m_page; 79 QMultiHash<QString, QList<RefPtr<VoidCallback> > > m_pendingPermissionRequests; 80 QHash <Notification*, NotificationIconWrapper*> m_notifications; 89 void displayNotification(Notification*, const QByteArray&); 90 void removeReplacedNotificationFromQueue(Notification*); 91 void dumpReplacedIdText(Notification*); 92 void dumpShowText(Notification*); 93 94 int m_clientCount; 95 QHash<QString, QList<RefPtr<VoidCallback> > > m_pendingPermissionRequests; 96 NotificationsQueue m_notifications; 81 97 QObject* m_receiver; 82 98 }; 99 83 100 } 84 101 85 102 #endif 86 103 #endif 87 -
trunk/WebKitTools/ChangeLog
r60560 r60566 1 2010-06-01 Yael Aharon <yael.aharon@nokia.com> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] Fix the lifecycle of notification objects 6 https://bugs.webkit.org/show_bug.cgi?id=40003 7 8 Remove the dependency of notifications on QWebPage. 9 10 * DumpRenderTree/qt/DumpRenderTreeQt.cpp: 11 (WebCore::requestPermissionCallback): 12 (WebCore::WebPage::WebPage): 13 (WebCore::DumpRenderTree::requestPermission): 14 * DumpRenderTree/qt/DumpRenderTreeQt.h: 15 1 16 2010-06-02 Sheriff Bot <webkit.review.bot@gmail.com> 2 17 -
trunk/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
r60525 r60566 136 136 } 137 137 138 void requestPermissionCallback(QObject* receiver, QWebPage* page,const QString& origin)139 { 140 qobject_cast<DumpRenderTree*>(receiver)->requestPermission( page,origin);138 void requestPermissionCallback(QObject* receiver, const QString& origin) 139 { 140 qobject_cast<DumpRenderTree*>(receiver)->requestPermission(origin); 141 141 } 142 142 … … 168 168 setPluginFactory(new TestPlugin(this)); 169 169 170 DumpRenderTreeSupportQt::setNotificationsReceiver( this,m_drt);170 DumpRenderTreeSupportQt::setNotificationsReceiver(m_drt); 171 171 DumpRenderTreeSupportQt::setCheckPermissionFunction(checkPermissionCallback); 172 172 DumpRenderTreeSupportQt::setRequestPermissionFunction(requestPermissionCallback); … … 920 920 } 921 921 922 void DumpRenderTree::requestPermission( QWebPage* page,const QString& origin)923 { 924 DumpRenderTreeSupportQt::allowNotificationForOrigin( page,origin);922 void DumpRenderTree::requestPermission(const QString& origin) 923 { 924 DumpRenderTreeSupportQt::allowNotificationForOrigin(origin); 925 925 } 926 926 -
trunk/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
r60348 r60566 116 116 void windowCloseRequested(); 117 117 void checkPermission(const QUrl&, NotificationPermission&); 118 void requestPermission( QWebPage* page,const QString&);118 void requestPermission(const QString&); 119 119 120 120 Q_SIGNALS:
Note: See TracChangeset
for help on using the changeset viewer.