[Qt] Move notification icon download out of WebCore
authoryael.aharon@nokia.com <yael.aharon@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2012 08:35:44 +0000 (08:35 +0000)
committeryael.aharon@nokia.com <yael.aharon@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Apr 2012 08:35:44 +0000 (08:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=80700

Reviewed by Simon Hausmann.

Source/WebCore:

Remove the code that downloads the notification's icon out of WebCore.
Other ports let the client decide if to download the icon or not.
No new tests. This patch is only removing code.

* notifications/Notification.cpp:
(WebCore::Notification::~Notification):
(WebCore::Notification::show):
(WebCore::Notification::close):
(WebCore::Notification::contextDestroyed):
* notifications/Notification.h:
(Notification):

Source/WebKit/qt:

Remove the code that handles the notification's icon and use the icon url instead.
The "display" event has to be asynchronous, so a timer was added to achieve that.
The platform plugin API and example were updated to reflect this change.
This change does not address the recent changes in web notifications spec.

* Api/qwebkitplatformplugin.h:
(QWebNotificationData):
* WebCoreSupport/NotificationPresenterClientQt.cpp:
(WebCore::NotificationWrapper::NotificationWrapper):
(WebCore::NotificationWrapper::sendDisplayEvent):
(WebCore):
(WebCore::NotificationWrapper::iconUrl):
(WebCore::NotificationPresenterClientQt::show):
(WebCore::NotificationPresenterClientQt::displayNotification):
(WebCore::NotificationPresenterClientQt::sendDisplayEvent):
* WebCoreSupport/NotificationPresenterClientQt.h:
(NotificationWrapper):
(NotificationPresenterClientQt):
* examples/platformplugin/WebNotificationPresenter.cpp:
(WebNotificationWidget::showNotification):
* examples/platformplugin/qwebkitplatformplugin.h:
(QWebNotificationData):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@115011 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/notifications/Notification.cpp
Source/WebCore/notifications/Notification.h
Source/WebKit/qt/Api/qwebkitplatformplugin.h
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
Source/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
Source/WebKit/qt/examples/platformplugin/WebNotificationPresenter.cpp
Source/WebKit/qt/examples/platformplugin/qwebkitplatformplugin.h

index e1ea673..7e55a85 100644 (file)
@@ -1,3 +1,22 @@
+2012-04-24  Yael Aharon  <yael.aharon@nokia.com>
+
+        [Qt] Move notification icon download out of WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=80700
+
+        Reviewed by Simon Hausmann.
+
+        Remove the code that downloads the notification's icon out of WebCore.
+        Other ports let the client decide if to download the icon or not.
+        No new tests. This patch is only removing code.
+
+        * notifications/Notification.cpp:
+        (WebCore::Notification::~Notification):
+        (WebCore::Notification::show):
+        (WebCore::Notification::close):
+        (WebCore::Notification::contextDestroyed):
+        * notifications/Notification.h:
+        (Notification):
+
 2012-04-24  Rakesh KN  <rakesh.kn@motorola.com>
 
         RadioNodeList support in HTMLFormElement::elements
index 48b1c20..14b0792 100644 (file)
@@ -116,10 +116,6 @@ Notification::Notification(ScriptExecutionContext* context, const String& title)
 
 Notification::~Notification() 
 {
-    if (m_state == LoadingIcon) {
-        ASSERT_NOT_REACHED();
-        close();
-    }
 }
 
 #if ENABLE(LEGACY_NOTIFICATIONS)
@@ -171,26 +167,11 @@ const AtomicString& Notification::interfaceName() const
 
 void Notification::show() 
 {
-#if PLATFORM(QT)
-    if (iconURL().isEmpty()) {
-        // Set the state before actually showing, because
-        // handling of ondisplay may rely on that.
-        if (m_state == Idle) {
-            m_state = Showing;
-            if (m_notificationCenter->client()) {
-                m_notificationCenter->client()->show(this);
-                setPendingActivity(this);
-            }
-        }
-    } else
-        startLoadingIcon();
-#else
     // prevent double-showing
     if (m_state == Idle && m_notificationCenter->client() && m_notificationCenter->client()->show(this)) {
         m_state = Showing;
         setPendingActivity(this);
     }
-#endif
 }
 
 void Notification::close()
@@ -198,15 +179,10 @@ void Notification::close()
     switch (m_state) {
     case Idle:
         break;
-    case LoadingIcon:
-        m_state = CancelledIcon;
-        stopLoadingIcon();
-        break;
     case Showing:
         if (m_notificationCenter->client())
             m_notificationCenter->client()->cancel(this);
         break;
-    case CancelledIcon:
     case Closed:
         break;
     }
@@ -229,66 +205,6 @@ void Notification::contextDestroyed()
         m_notificationCenter->client()->notificationObjectDestroyed(this);
 }
 
-void Notification::startLoadingIcon()
-{
-    if (m_state != Idle)
-        return;
-    setPendingActivity(this);
-    m_state = LoadingIcon;
-    ThreadableLoaderOptions options;
-    options.sendLoadCallbacks = DoNotSendCallbacks;
-    options.sniffContent = DoNotSniffContent;
-    options.preflightPolicy = ConsiderPreflight;
-    options.allowCredentials = AllowStoredCredentials;
-    options.crossOriginRequestPolicy = AllowCrossOriginRequests;
-    m_loader = ThreadableLoader::create(scriptExecutionContext(), this, ResourceRequest(iconURL()), options);
-}
-
-void Notification::stopLoadingIcon()
-{
-    m_iconData = 0;
-    RefPtr<ThreadableLoader> protect(m_loader);
-    m_loader->cancel();
-}
-
-void Notification::didReceiveResponse(unsigned long, const ResourceResponse& response)
-{
-    int status = response.httpStatusCode();
-    if (status && (status < 200 || status > 299)) {
-        stopLoadingIcon();
-        return;
-    }
-    m_iconData = SharedBuffer::create();
-}
-
-void Notification::didReceiveData(const char* data, int dataLength)
-{
-    m_iconData->append(data, dataLength);
-}
-
-void Notification::didFinishLoading(unsigned long, double)
-{
-    finishLoadingIcon();
-}
-
-void Notification::didFail(const ResourceError&)
-{
-    finishLoadingIcon();
-}
-
-void Notification::didFailRedirectCheck()
-{
-    finishLoadingIcon();
-}
-
-void Notification::finishLoadingIcon()
-{
-    if (m_state == LoadingIcon) {
-        if (m_notificationCenter->client() && m_notificationCenter->client()->show(this))
-            m_state = Showing;
-    }
-}
-
 void Notification::finalize()
 {
     if (m_state == Closed)
index 9ecf8c6..5b034cc 100644 (file)
@@ -61,7 +61,7 @@ class ThreadableLoader;
 
 typedef int ExceptionCode;
 
-class Notification : public RefCounted<Notification>, public ActiveDOMObject, public ThreadableLoaderClient, public EventTarget {
+class Notification : public RefCounted<Notification>, public ActiveDOMObject, public EventTarget {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     Notification();
@@ -130,18 +130,9 @@ public:
 
     void stopLoadingIcon();
 
-    SharedBuffer* iconData() { return m_iconData.get(); }
-    void releaseIconData() { m_iconData = 0; }
-
     // Deprecated. Use functions from NotificationCenter.
     void detachPresenter() { }
 
-    virtual void didReceiveResponse(unsigned long, const ResourceResponse&);
-    virtual void didReceiveData(const char* data, int dataLength);
-    virtual void didFinishLoading(unsigned long identifier, double finishTime);
-    virtual void didFail(const ResourceError&);
-    virtual void didFailRedirectCheck();
-
     void finalize();
 
 private:
@@ -182,10 +173,8 @@ private:
 
     enum NotificationState {
         Idle = 0,
-        LoadingIcon = 1,
-        Showing = 2,
-        CancelledIcon = 3,
-        Closed = 4,
+        Showing = 1,
+        Closed = 2,
     };
 
     NotificationState m_state;
@@ -194,8 +183,6 @@ private:
     
     EventTargetData m_eventTargetData;
 
-    RefPtr<ThreadableLoader> m_loader;
-    RefPtr<SharedBuffer> m_iconData;
 #if ENABLE(NOTIFICATIONS)
     OwnPtr<Timer<Notification> > m_showTaskTimer;
 #endif
index b28c058..aa8ec7e 100644 (file)
@@ -75,7 +75,7 @@ public:
 
     virtual const QString title() const = 0;
     virtual const QString message() const = 0;
-    virtual const QByteArray iconData() const = 0;
+    virtual const QUrl iconUrl() const = 0;
     virtual const QUrl openerPageUrl() const = 0;
 };
 
@@ -180,7 +180,7 @@ public:
 };
 
 QT_BEGIN_NAMESPACE
-Q_DECLARE_INTERFACE(QWebKitPlatformPlugin, "com.nokia.Qt.WebKit.PlatformPlugin/1.8");
+Q_DECLARE_INTERFACE(QWebKitPlatformPlugin, "com.nokia.Qt.WebKit.PlatformPlugin/1.9");
 QT_END_NAMESPACE
 
 #endif // QWEBKITPLATFORMPLUGIN_H
index 277035b..5fc338f 100644 (file)
@@ -1,3 +1,33 @@
+2012-04-24  Yael Aharon  <yael.aharon@nokia.com>
+
+        [Qt] Move notification icon download out of WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=80700
+
+        Reviewed by Simon Hausmann.
+
+        Remove the code that handles the notification's icon and use the icon url instead.
+        The "display" event has to be asynchronous, so a timer was added to achieve that.
+        The platform plugin API and example were updated to reflect this change.
+        This change does not address the recent changes in web notifications spec.
+
+        * Api/qwebkitplatformplugin.h:
+        (QWebNotificationData):
+        * WebCoreSupport/NotificationPresenterClientQt.cpp:
+        (WebCore::NotificationWrapper::NotificationWrapper):
+        (WebCore::NotificationWrapper::sendDisplayEvent):
+        (WebCore):
+        (WebCore::NotificationWrapper::iconUrl):
+        (WebCore::NotificationPresenterClientQt::show):
+        (WebCore::NotificationPresenterClientQt::displayNotification):
+        (WebCore::NotificationPresenterClientQt::sendDisplayEvent):
+        * WebCoreSupport/NotificationPresenterClientQt.h:
+        (NotificationWrapper):
+        (NotificationPresenterClientQt):
+        * examples/platformplugin/WebNotificationPresenter.cpp:
+        (WebNotificationWidget::showNotification):
+        * examples/platformplugin/qwebkitplatformplugin.h:
+        (QWebNotificationData):
+
 2012-04-18  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
 
         Clean-up WheelEvent Conversion.
index a5eb0ce..d693c4a 100644 (file)
@@ -69,6 +69,7 @@ NotificationPresenterClientQt* NotificationPresenterClientQt::notificationPresen
 
 NotificationWrapper::NotificationWrapper()
     : m_closeTimer(this, &NotificationWrapper::close)
+    , m_displayEventTimer(this, &NotificationWrapper::sendDisplayEvent)
 {
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
 
@@ -86,6 +87,13 @@ void NotificationWrapper::close(Timer<NotificationWrapper>*)
 #endif
 }
 
+void NotificationWrapper::sendDisplayEvent(Timer<NotificationWrapper>*)
+{
+#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
+    NotificationPresenterClientQt::notificationPresenter()->sendDisplayEvent(this);
+#endif
+}
+
 const QString NotificationWrapper::title() const
 {
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
@@ -106,17 +114,14 @@ const QString NotificationWrapper::message() const
     return QString();
 }
 
-const QByteArray NotificationWrapper::iconData() const
+const QUrl NotificationWrapper::iconUrl() const
 {
-    QByteArray iconData;
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
     Notification* notification = NotificationPresenterClientQt::notificationPresenter()->notificationForWrapper(this);
-    if (notification) {
-        if (notification->iconData())
-            iconData = QByteArray::fromRawData(notification->iconData()->data(), notification->iconData()->size());
-    }
+    if (notification)
+        return notification->iconURL();
 #endif
-    return iconData;
+    return QUrl();
 }
 
 const QUrl NotificationWrapper::openerPageUrl() const
@@ -179,15 +184,11 @@ bool NotificationPresenterClientQt::show(Notification* notification)
         removeReplacedNotificationFromQueue(notification);
     if (dumpNotification)
         dumpShowText(notification);
-    QByteArray iconData;
-    if (notification->iconData())
-        iconData = QByteArray::fromRawData(notification->iconData()->data(), notification->iconData()->size());
-    displayNotification(notification, iconData);
-    notification->releaseIconData();
+    displayNotification(notification);
     return true;
 }
 
-void NotificationPresenterClientQt::displayNotification(Notification* notification, const QByteArray& bytes)
+void NotificationPresenterClientQt::displayNotification(Notification* notification)
 {
     NotificationWrapper* wrapper = new NotificationWrapper();
     m_notifications.insert(notification, wrapper);
@@ -208,16 +209,11 @@ void NotificationPresenterClientQt::displayNotification(Notification* notificati
 #ifndef QT_NO_SYSTEMTRAYICON
         if (!dumpNotification)
             wrapper->m_closeTimer.startOneShot(notificationTimeout);
-        QPixmap pixmap;
-        if (bytes.length() && pixmap.loadFromData(bytes)) {
-            QIcon icon(pixmap);
-            wrapper->m_notificationIcon = adoptPtr(new QSystemTrayIcon(icon));
-        } else
             wrapper->m_notificationIcon = adoptPtr(new QSystemTrayIcon());
 #endif
     }
 
-    sendEvent(notification, "display");
+    wrapper->m_displayEventTimer.startOneShot(0);
 
     // Make sure the notification was not cancelled during handling the display event
     if (m_notifications.find(notification) == m_notifications.end())
@@ -384,6 +380,14 @@ void NotificationPresenterClientQt::allowNotificationForFrame(Frame* frame)
     m_pendingPermissionRequests.remove(iter.key());
 }
 
+void NotificationPresenterClientQt::sendDisplayEvent(NotificationWrapper* wrapper)
+{
+    Notification* notification = notificationForWrapper(wrapper);
+    if (notification)
+        sendEvent(notification, "display");
+}
+
+
 void NotificationPresenterClientQt::sendEvent(Notification* notification, const AtomicString& eventName)
 {
     if (notification->scriptExecutionContext())
index 874dd60..97eee15 100644 (file)
@@ -59,9 +59,10 @@ public:
 
     void close();
     void close(Timer<NotificationWrapper>*);
+    void sendDisplayEvent(Timer<NotificationWrapper>*);
     const QString title() const;
     const QString message() const;
-    const QByteArray iconData() const;
+    const QUrl iconUrl() const;
     const QUrl openerPageUrl() const;
 
 public Q_SLOTS:
@@ -75,6 +76,7 @@ public:
 
     OwnPtr<QWebNotificationPresenter> m_presenter;
     Timer<NotificationWrapper> m_closeTimer;
+    Timer<NotificationWrapper> m_displayEventTimer;
 };
 
 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
@@ -108,10 +110,11 @@ public:
     Notification* notificationForWrapper(const NotificationWrapper*) const;
     void notificationClicked(NotificationWrapper*);
     void notificationClicked(const QString& title);
+    void sendDisplayEvent(NotificationWrapper*);
 
 private:
     void sendEvent(Notification*, const AtomicString& eventName);
-    void displayNotification(Notification*, const QByteArray&);
+    void displayNotification(Notification*);
     void removeReplacedNotificationFromQueue(Notification*);
     void detachNotification(Notification*);
     void dumpReplacedIdText(Notification*);
index d991ab1..339bade 100644 (file)
@@ -39,13 +39,7 @@ void WebNotificationWidget::showNotification(const QWebNotificationData* data)
     QGridLayout* layout = new QGridLayout(this);
     layout->addWidget(new QLabel(data->title()), 0, 0, 1, 5);
     int messagePosition = 0;
-    QPixmap pixmap;
-    if (data->iconData().length() && pixmap.loadFromData(data->iconData())) {
-        QLabel* label = new QLabel;
-        label->setPixmap(pixmap);
-        layout->addWidget(label, 1, 0, 1, 1);
-        messagePosition++;
-    }
+
     QLabel* messageLabel = new QLabel(data->message());
     messageLabel->setMask(bitmap);
     messageLabel->setWordWrap(true);
index b28c058..aa8ec7e 100644 (file)
@@ -75,7 +75,7 @@ public:
 
     virtual const QString title() const = 0;
     virtual const QString message() const = 0;
-    virtual const QByteArray iconData() const = 0;
+    virtual const QUrl iconUrl() const = 0;
     virtual const QUrl openerPageUrl() const = 0;
 };
 
@@ -180,7 +180,7 @@ public:
 };
 
 QT_BEGIN_NAMESPACE
-Q_DECLARE_INTERFACE(QWebKitPlatformPlugin, "com.nokia.Qt.WebKit.PlatformPlugin/1.8");
+Q_DECLARE_INTERFACE(QWebKitPlatformPlugin, "com.nokia.Qt.WebKit.PlatformPlugin/1.9");
 QT_END_NAMESPACE
 
 #endif // QWEBKITPLATFORMPLUGIN_H