summaryrefslogtreecommitdiffstats
path: root/WebKit/qt/WebCoreSupport
diff options
context:
space:
mode:
authorLeon Clarke <leonclarke@google.com>2010-06-03 14:33:32 +0100
committerLeon Clarke <leonclarke@google.com>2010-06-08 12:24:51 +0100
commit5af96e2c7b73ebc627c6894727826a7576d31758 (patch)
treef9d5e6f6175ccd7e3d14de9b290f08937a0d17ba /WebKit/qt/WebCoreSupport
parent8cc4fcf4f6adcbc0e0aebfc24fbad9a4cddf2cfb (diff)
downloadexternal_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.zip
external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.gz
external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.bz2
Merge webkit.org at r60469 : Initial merge by git.
Change-Id: I66a0047aa2af802f66bb0c7f2a8b02247a596234
Diffstat (limited to 'WebKit/qt/WebCoreSupport')
-rw-r--r--WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp49
-rw-r--r--WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h21
-rw-r--r--WebKit/qt/WebCoreSupport/EditorClientQt.cpp219
-rw-r--r--WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp7
-rw-r--r--WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp121
-rw-r--r--WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h34
6 files changed, 322 insertions, 129 deletions
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
index 9d335b8..0b2e9a5 100644
--- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
+++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
@@ -60,6 +60,9 @@
using namespace WebCore;
+CheckPermissionFunctionType* checkPermissionFunction = 0;
+RequestPermissionFunctionType* requestPermissionFunction = 0;
+
DumpRenderTreeSupportQt::DumpRenderTreeSupportQt()
{
}
@@ -332,6 +335,11 @@ void DumpRenderTreeSupportQt::whiteListAccessFromOrigin(const QString& sourceOri
SecurityOrigin::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
}
+void DumpRenderTreeSupportQt::removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains)
+{
+ SecurityOrigin::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains);
+}
+
void DumpRenderTreeSupportQt::resetOriginAccessWhiteLists()
{
SecurityOrigin::resetOriginAccessWhitelists();
@@ -466,6 +474,22 @@ bool DumpRenderTreeSupportQt::elementDoesAutoCompleteForElementWithId(QWebFrame*
&& inputElement->autoComplete());
}
+void DumpRenderTreeSupportQt::setEditingBehavior(QWebPage* page, const QString& editingBehavior)
+{
+ WebCore::EditingBehavior coreEditingBehavior;
+
+ if (editingBehavior == "win")
+ coreEditingBehavior = EditingWindowsBehavior;
+ else if (editingBehavior == "mac")
+ coreEditingBehavior = EditingMacBehavior;
+
+ Page* corePage = QWebPagePrivate::core(page);
+ if (!corePage)
+ return;
+
+ corePage->settings()->setEditingBehavior(coreEditingBehavior);
+}
+
void DumpRenderTreeSupportQt::dumpFrameLoader(bool b)
{
FrameLoaderClientQt::dumpFrameLoaderCallbacks = b;
@@ -512,6 +536,31 @@ void DumpRenderTreeSupportQt::dumpNotification(bool b)
NotificationPresenterClientQt::dumpNotification = b;
#endif
}
+
+void DumpRenderTreeSupportQt::setNotificationsReceiver(QWebPage* page, QObject* receiver)
+{
+#if ENABLE(NOTIFICATIONS)
+ page->d->notificationPresenterClient->setReceiver(receiver);
+#endif
+}
+
+void DumpRenderTreeSupportQt::allowNotificationForOrigin(QWebPage* page, const QString& origin)
+{
+#if ENABLE(NOTIFICATIONS)
+ page->d->notificationPresenterClient->allowNotificationForOrigin(origin);
+#endif
+}
+
+void DumpRenderTreeSupportQt::setCheckPermissionFunction(CheckPermissionFunctionType* f)
+{
+ checkPermissionFunction = f;
+}
+
+void DumpRenderTreeSupportQt::setRequestPermissionFunction(RequestPermissionFunctionType* f)
+{
+ requestPermissionFunction = f;
+}
+
// Provide a backward compatibility with previously exported private symbols as of QtWebKit 4.6 release
void QWEBKIT_EXPORT qt_resumeActiveDOMObjects(QWebFrame* frame)
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
index 6045463..0d348cf 100644
--- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
+++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
@@ -30,6 +30,18 @@ class QWebElement;
class QWebFrame;
class QWebPage;
+enum NotificationPermission {
+ NotificationAllowed,
+ NotificationNotAllowed,
+ NotificationDenied
+};
+
+typedef void (CheckPermissionFunctionType) (QObject* receiver, const QUrl&, NotificationPermission&);
+typedef void (RequestPermissionFunctionType) (QObject* receiver, QWebPage* page, const QString&);
+
+extern CheckPermissionFunctionType* checkPermissionFunction;
+extern RequestPermissionFunctionType* requestPermissionFunction;
+
class QWEBKIT_EXPORT DumpRenderTreeSupportQt {
public:
@@ -78,8 +90,10 @@ public:
static int pageNumberForElementById(QWebFrame* frame, const QString& id, float width, float height);
static bool hasDocumentElement(QWebFrame* frame);
static bool elementDoesAutoCompleteForElementWithId(QWebFrame* frame, const QString& elementId);
+ static void setEditingBehavior(QWebPage* page, const QString& editingBehavior);
static void whiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
+ static void removeWhiteListAccessFromOrigin(const QString& sourceOrigin, const QString& destinationProtocol, const QString& destinationHost, bool allowDestinationSubdomains);
static void resetOriginAccessWhiteLists();
static int workerThreadCount();
@@ -98,7 +112,12 @@ public:
static void dumpSetAcceptsEditing(bool b);
static void dumpNotification(bool b);
-
+ // These functions should eventually turn into public API
+ // and the "receiver" concept would go away
+ static void setNotificationsReceiver(QWebPage* page, QObject* receiver);
+ static void allowNotificationForOrigin(QWebPage* page, const QString& origin);
+ static void setCheckPermissionFunction(CheckPermissionFunctionType*);
+ static void setRequestPermissionFunction(RequestPermissionFunctionType*);
};
#endif
diff --git a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
index 83aa2a9..0f54e21 100644
--- a/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
@@ -31,9 +31,6 @@
#include "config.h"
#include "EditorClientQt.h"
-#include "qwebpage.h"
-#include "qwebpage_p.h"
-
#include "CSSStyleDeclaration.h"
#include "Document.h"
#include "EditCommandQt.h"
@@ -46,15 +43,16 @@
#include "KeyboardEvent.h"
#include "NotImplemented.h"
#include "Page.h"
-#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "QWebPageClient.h"
#include "Range.h"
#include "WindowsKeyboardCodes.h"
+#include "qwebpage.h"
+#include "qwebpage_p.h"
+#include <QUndoStack>
#include <stdio.h>
-#include <QUndoStack>
#define methodDebug() qDebug("EditorClientQt: %s", __FUNCTION__);
static QString dumpPath(WebCore::Node *node)
@@ -247,9 +245,8 @@ void EditorClientQt::registerCommandForUndo(WTF::PassRefPtr<WebCore::EditCommand
{
#ifndef QT_NO_UNDOSTACK
Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame();
- if (m_inUndoRedo || (frame && !frame->editor()->lastEditCommand() /* HACK!! Don't recreate undos */)) {
+ if (m_inUndoRedo || (frame && !frame->editor()->lastEditCommand() /* HACK!! Don't recreate undos */))
return;
- }
m_page->undoStack()->push(new EditCommandQt(cmd));
#endif // QT_NO_UNDOSTACK
}
@@ -378,118 +375,120 @@ void EditorClientQt::handleKeyboardEvent(KeyboardEvent* event)
} else
#endif // QT_NO_SHORTCUT
switch (kevent->windowsVirtualKeyCode()) {
- case VK_BACK:
- frame->editor()->deleteWithDirection(SelectionController::BACKWARD,
- CharacterGranularity, false, true);
- break;
- case VK_DELETE:
- frame->editor()->deleteWithDirection(SelectionController::FORWARD,
- CharacterGranularity, false, true);
- break;
- case VK_LEFT:
- if (kevent->shiftKey())
- frame->editor()->command("MoveLeftAndModifySelection").execute();
- else
- frame->editor()->command("MoveLeft").execute();
- break;
- case VK_RIGHT:
- if (kevent->shiftKey())
- frame->editor()->command("MoveRightAndModifySelection").execute();
- else
- frame->editor()->command("MoveRight").execute();
- break;
- case VK_UP:
- if (kevent->shiftKey())
- frame->editor()->command("MoveUpAndModifySelection").execute();
- else
- frame->editor()->command("MoveUp").execute();
- break;
- case VK_DOWN:
- if (kevent->shiftKey())
- frame->editor()->command("MoveDownAndModifySelection").execute();
- else
- frame->editor()->command("MoveDown").execute();
- break;
- case VK_PRIOR: // PageUp
- if (kevent->shiftKey())
- frame->editor()->command("MovePageUpAndModifySelection").execute();
- else
- frame->editor()->command("MovePageUp").execute();
- break;
- case VK_NEXT: // PageDown
- if (kevent->shiftKey())
- frame->editor()->command("MovePageDownAndModifySelection").execute();
- else
- frame->editor()->command("MovePageDown").execute();
- break;
- case VK_TAB:
- return;
- default:
- if (kevent->type() != PlatformKeyboardEvent::KeyDown && !kevent->ctrlKey()
+ case VK_BACK:
+ frame->editor()->deleteWithDirection(SelectionController::DirectionBackward,
+ CharacterGranularity, false, true);
+ break;
+ case VK_DELETE:
+ frame->editor()->deleteWithDirection(SelectionController::DirectionForward,
+ CharacterGranularity, false, true);
+ break;
+ case VK_LEFT:
+ if (kevent->shiftKey())
+ frame->editor()->command("MoveLeftAndModifySelection").execute();
+ else
+ frame->editor()->command("MoveLeft").execute();
+ break;
+ case VK_RIGHT:
+ if (kevent->shiftKey())
+ frame->editor()->command("MoveRightAndModifySelection").execute();
+ else
+ frame->editor()->command("MoveRight").execute();
+ break;
+ case VK_UP:
+ if (kevent->shiftKey())
+ frame->editor()->command("MoveUpAndModifySelection").execute();
+ else
+ frame->editor()->command("MoveUp").execute();
+ break;
+ case VK_DOWN:
+ if (kevent->shiftKey())
+ frame->editor()->command("MoveDownAndModifySelection").execute();
+ else
+ frame->editor()->command("MoveDown").execute();
+ break;
+ case VK_PRIOR: // PageUp
+ if (kevent->shiftKey())
+ frame->editor()->command("MovePageUpAndModifySelection").execute();
+ else
+ frame->editor()->command("MovePageUp").execute();
+ break;
+ case VK_NEXT: // PageDown
+ if (kevent->shiftKey())
+ frame->editor()->command("MovePageDownAndModifySelection").execute();
+ else
+ frame->editor()->command("MovePageDown").execute();
+ break;
+ case VK_TAB:
+ return;
+ default:
+ if (kevent->type() != PlatformKeyboardEvent::KeyDown && !kevent->ctrlKey()
#ifndef Q_WS_MAC
- // We need to exclude checking for Alt because it is just a different Shift
- && !kevent->altKey()
+ // We need to exclude checking for Alt because it is just a different Shift
+ && !kevent->altKey()
#endif
- && !kevent->text().isEmpty()) {
- frame->editor()->insertText(kevent->text(), event);
- } else if (kevent->ctrlKey()) {
- switch (kevent->windowsVirtualKeyCode()) {
- case VK_A:
- frame->editor()->command("SelectAll").execute();
- break;
- case VK_B:
- frame->editor()->command("ToggleBold").execute();
- break;
- case VK_I:
- frame->editor()->command("ToggleItalic").execute();
- break;
- default:
- // catch combination AltGr+key or Ctrl+Alt+key
- if (kevent->type() != PlatformKeyboardEvent::KeyDown && kevent->altKey() && !kevent->text().isEmpty()) {
- frame->editor()->insertText(kevent->text(), event);
- break;
- }
- return;
+ && !kevent->text().isEmpty()) {
+ frame->editor()->insertText(kevent->text(), event);
+ } else if (kevent->ctrlKey()) {
+ switch (kevent->windowsVirtualKeyCode()) {
+ case VK_A:
+ frame->editor()->command("SelectAll").execute();
+ break;
+ case VK_B:
+ frame->editor()->command("ToggleBold").execute();
+ break;
+ case VK_I:
+ frame->editor()->command("ToggleItalic").execute();
+ break;
+ default:
+ // catch combination AltGr+key or Ctrl+Alt+key
+ if (kevent->type() != PlatformKeyboardEvent::KeyDown && kevent->altKey() && !kevent->text().isEmpty()) {
+ frame->editor()->insertText(kevent->text(), event);
+ break;
}
- } else return;
+ return;
+ }
+ } else
+ return;
}
} else {
#ifndef QT_NO_SHORTCUT
- if (kevent->qtEvent() == QKeySequence::Copy) {
+ if (kevent->qtEvent() == QKeySequence::Copy)
m_page->triggerAction(QWebPage::Copy);
- } else
+ else
#endif // QT_NO_SHORTCUT
switch (kevent->windowsVirtualKeyCode()) {
- case VK_UP:
- frame->editor()->command("MoveUp").execute();
- break;
- case VK_DOWN:
- frame->editor()->command("MoveDown").execute();
- break;
- case VK_PRIOR: // PageUp
- frame->editor()->command("MovePageUp").execute();
- break;
- case VK_NEXT: // PageDown
- frame->editor()->command("MovePageDown").execute();
- break;
- case VK_HOME:
- if (kevent->ctrlKey())
- frame->editor()->command("MoveToBeginningOfDocument").execute();
- break;
- case VK_END:
- if (kevent->ctrlKey())
- frame->editor()->command("MoveToEndOfDocument").execute();
- break;
- default:
- if (kevent->ctrlKey()) {
- switch (kevent->windowsVirtualKeyCode()) {
- case VK_A:
- frame->editor()->command("SelectAll").execute();
- break;
- default:
- return;
- }
- } else return;
+ case VK_UP:
+ frame->editor()->command("MoveUp").execute();
+ break;
+ case VK_DOWN:
+ frame->editor()->command("MoveDown").execute();
+ break;
+ case VK_PRIOR: // PageUp
+ frame->editor()->command("MovePageUp").execute();
+ break;
+ case VK_NEXT: // PageDown
+ frame->editor()->command("MovePageDown").execute();
+ break;
+ case VK_HOME:
+ if (kevent->ctrlKey())
+ frame->editor()->command("MoveToBeginningOfDocument").execute();
+ break;
+ case VK_END:
+ if (kevent->ctrlKey())
+ frame->editor()->command("MoveToEndOfDocument").execute();
+ break;
+ default:
+ if (kevent->ctrlKey()) {
+ switch (kevent->windowsVirtualKeyCode()) {
+ case VK_A:
+ frame->editor()->command("SelectAll").execute();
+ break;
+ default:
+ return;
+ }
+ } else
+ return;
}
}
event->setDefaultHandled();
diff --git a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
index 00359c0..3cf19a6 100644
--- a/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/FrameLoaderClientQt.cpp
@@ -51,6 +51,7 @@
#include "HTMLFormElement.h"
#include "HTMLPlugInElement.h"
#include "HTTPParsers.h"
+#include "NotificationPresenterClientQt.h"
#include "NotImplemented.h"
#include "QNetworkReplyHandler.h"
#include "ResourceHandleInternal.h"
@@ -638,8 +639,12 @@ void FrameLoaderClientQt::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld* w
if (world != mainThreadNormalWorld())
return;
- if (m_webFrame)
+ if (m_webFrame) {
emit m_webFrame->javaScriptWindowObjectCleared();
+#if ENABLE(NOTIFICATIONS)
+ m_webFrame->page()->d->notificationPresenterClient->clearNotificationsList();
+#endif
+ }
}
void FrameLoaderClientQt::documentElementAvailable()
diff --git a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
index d6546ae..f76868d 100644
--- a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
@@ -32,13 +32,15 @@
#include "config.h"
#include "NotificationPresenterClientQt.h"
+#include "DumpRenderTreeSupportQt.h"
#include "Document.h"
+#include "EventNames.h"
#include "KURL.h"
-#include "NotImplemented.h"
#include "SecurityOrigin.h"
+#include "qwebframe.h"
#include "qwebkitglobal.h"
-
+#include "qwebpage.h"
#include <QtGui>
@@ -48,25 +50,66 @@ using namespace WebCore;
bool NotificationPresenterClientQt::dumpNotification = false;
-NotificationPresenterClientQt::NotificationPresenterClientQt()
+NotificationIconWrapper::NotificationIconWrapper()
+{
+#ifndef QT_NO_SYSTEMTRAYICON
+ m_notificationIcon = 0;
+#endif
+}
+
+NotificationIconWrapper::~NotificationIconWrapper()
+{
+#ifndef QT_NO_SYSTEMTRAYICON
+ delete m_notificationIcon;
+#endif
+}
+
+NotificationPresenterClientQt::NotificationPresenterClientQt(QWebPage* page) : m_page(page)
{
}
bool NotificationPresenterClientQt::show(Notification* notification)
{
+ QHash <Notification*, NotificationIconWrapper*>::Iterator end = m_notifications.end();
+ QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.begin();
+
+ if (!notification->replaceId().isEmpty()) {
+ while (iter != end) {
+ Notification* existingNotification = iter.key();
+ if (existingNotification->replaceId() == notification->replaceId() && existingNotification->url().protocol() == notification->url().protocol() && existingNotification->url().host() == notification->url().host())
+ break;
+ iter++;
+ }
+ } else
+ iter = end;
+
if (dumpNotification) {
+ if (iter != end) {
+ Notification* oldNotification = iter.key();
+ printf("REPLACING NOTIFICATION %s\n", oldNotification->isHTML() ? QString(oldNotification->url().string()).toUtf8().constData() : QString(oldNotification->contents().title()).toUtf8().constData());
+ }
if (notification->isHTML())
printf("DESKTOP NOTIFICATION: contents at %s\n", QString(notification->url().string()).toUtf8().constData());
else {
- printf("DESKTOP NOTIFICATION: icon %s, title %s, text %s\n",
+ printf("DESKTOP NOTIFICATION:%s icon %s, title %s, text %s\n",
+ notification->dir() == "rtl" ? "(RTL)" : "",
QString(notification->contents().icon().string()).toUtf8().constData(), QString(notification->contents().title()).toUtf8().constData(),
QString(notification->contents().body()).toUtf8().constData());
}
}
+ if (iter != end) {
+ sendEvent(iter.key(), eventNames().closeEvent);
+ delete m_notifications.take(iter.key());
+ }
+ NotificationIconWrapper* wrapper = new NotificationIconWrapper();
+ m_notifications.insert(notification, wrapper);
+ sendEvent(notification, "display");
+
#ifndef QT_NO_SYSTEMTRAYICON
- m_tray.show();
- m_tray.showMessage(notification->contents().title(), notification->contents().body(), QSystemTrayIcon::Information);
+ wrapper->m_notificationIcon = new QSystemTrayIcon;
+ wrapper->m_notificationIcon->show();
+ wrapper->m_notificationIcon->showMessage(notification->contents().title(), notification->contents().body());
#endif
return true;
}
@@ -80,12 +123,17 @@ void NotificationPresenterClientQt::cancel(Notification* notification)
printf("DESKTOP NOTIFICATION CLOSED: %s\n", QString(notification->contents().title()).toUtf8().constData());
}
- notImplemented();
+ QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.find(notification);
+ if (iter != m_notifications.end())
+ sendEvent(iter.key(), eventNames().closeEvent);
}
void NotificationPresenterClientQt::notificationObjectDestroyed(Notification* notification)
{
- notImplemented();
+ // Called from ~Notification(), Remove the entry from the notifications list and delete the icon.
+ QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.find(notification);
+ if (iter != m_notifications.end())
+ delete m_notifications.take(notification);
}
void NotificationPresenterClientQt::requestPermission(SecurityOrigin* origin, PassRefPtr<VoidCallback> callback)
@@ -93,13 +141,62 @@ void NotificationPresenterClientQt::requestPermission(SecurityOrigin* origin, Pa
if (dumpNotification)
printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", QString(origin->toString()).toUtf8().constData());
- notImplemented();
+ QString originString = origin->toString();
+ QHash<QString, QList<RefPtr<VoidCallback> > >::iterator iter = m_pendingPermissionRequests.find(originString);
+ if (iter != m_pendingPermissionRequests.end())
+ iter.value().append(callback);
+ else {
+ QList<RefPtr<VoidCallback> > callbacks;
+ RefPtr<VoidCallback> cb = callback;
+ callbacks.append(cb);
+ m_pendingPermissionRequests.insert(originString, callbacks);
+ if (requestPermissionFunction)
+ requestPermissionFunction(m_receiver, m_page, originString);
+ }
+}
+
+NotificationPresenter::Permission NotificationPresenterClientQt::checkPermission(const KURL& url)
+{
+ NotificationPermission permission = NotificationNotAllowed;
+ QString origin = url.string();
+ if (checkPermissionFunction)
+ checkPermissionFunction(m_receiver, origin, permission);
+ switch (permission) {
+ case NotificationAllowed:
+ return NotificationPresenter::PermissionAllowed;
+ case NotificationNotAllowed:
+ return NotificationPresenter::PermissionNotAllowed;
+ case NotificationDenied:
+ return NotificationPresenter::PermissionDenied;
+ }
+ ASSERT_NOT_REACHED();
+ return NotificationPresenter::PermissionNotAllowed;
+}
+
+void NotificationPresenterClientQt::allowNotificationForOrigin(const QString& origin)
+{
+ QHash<QString, QList<RefPtr<VoidCallback> > >::iterator iter = m_pendingPermissionRequests.find(origin);
+ if (iter != m_pendingPermissionRequests.end()) {
+ QList<RefPtr<VoidCallback> >& callbacks = iter.value();
+ for (int i = 0; i < callbacks.size(); i++)
+ callbacks.at(i)->handleEvent();
+ m_pendingPermissionRequests.remove(origin);
+ }
+}
+
+void NotificationPresenterClientQt::clearNotificationsList()
+{
+ m_pendingPermissionRequests.clear();
+ while (!m_notifications.isEmpty()) {
+ QHash <Notification*, NotificationIconWrapper*>::Iterator iter = m_notifications.begin();
+ delete m_notifications.take(iter.key());
+ }
}
-NotificationPresenter::Permission NotificationPresenterClientQt::checkPermission(const KURL&)
+void NotificationPresenterClientQt::sendEvent(Notification* notification, const AtomicString& eventName)
{
- // FIXME Implement permission policy
- return NotificationPresenter::PermissionAllowed;
+ RefPtr<Event> event = Event::create(eventName, false, true);
+ notification->dispatchEvent(event.release());
}
#endif // ENABLE(NOTIFICATIONS)
diff --git a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
index 5967867..c949513 100644
--- a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
+++ b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
@@ -29,20 +29,35 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef NotificationPresenterClientQt_h
+#define NotificationPresenterClientQt_h
+
#include "Notification.h"
#include "NotificationPresenter.h"
+#include <QMultiHash>
#include <QSystemTrayIcon>
+
#if ENABLE(NOTIFICATIONS)
+class QWebPage;
namespace WebCore {
class Document;
class KURL;
+struct NotificationIconWrapper {
+ NotificationIconWrapper();
+ ~NotificationIconWrapper();
+#ifndef QT_NO_SYSTEMTRAYICON
+ QSystemTrayIcon* m_notificationIcon;
+#endif
+};
+
class NotificationPresenterClientQt : public NotificationPresenter {
public:
- NotificationPresenterClientQt();
+ NotificationPresenterClientQt(QWebPage*);
+ ~NotificationPresenterClientQt() {}
/* WebCore::NotificationPresenter interface */
virtual bool show(Notification*);
@@ -51,13 +66,22 @@ public:
virtual void requestPermission(SecurityOrigin*, PassRefPtr<VoidCallback>);
virtual NotificationPresenter::Permission checkPermission(const KURL&);
+ void allowNotificationForOrigin(const QString& origin);
+ void clearNotificationsList();
+
static bool dumpNotification;
-private:
-#ifndef QT_NO_SYSTEMTRAYICON
- QSystemTrayIcon m_tray;
-#endif
+ void setReceiver(QObject* receiver) { m_receiver = receiver; }
+
+private:
+ void sendEvent(Notification*, const AtomicString& eventName);
+ QWebPage* m_page;
+ QMultiHash<QString, QList<RefPtr<VoidCallback> > > m_pendingPermissionRequests;
+ QHash <Notification*, NotificationIconWrapper*> m_notifications;
+ QObject* m_receiver;
};
}
#endif
+#endif
+