[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

yael.aharon at nokia.com yael.aharon at nokia.com
Wed Dec 22 11:25:23 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 17417c27ac21b462893d7d7c1ff119c43c354015
Author: yael.aharon at nokia.com <yael.aharon at nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jul 22 23:52:15 2010 +0000

    2010-07-22  Yael Aharon  <yael.aharon at nokia.com>
    
            Reviewed by Laszlo Gombos.
    
            [Qt] QtWebKit needs public API for Notifications.
            https://bugs.webkit.org/show_bug.cgi?id=41413
    
            Add a DRT API to set a flag so that notification requests are ignored,
            and add a test for cancelling a pending notification request.
            New API and test are disabled for Chromium port.
    
            * fast/notifications/notifications-cancel-request-permission-expected.txt: Added.
            * fast/notifications/notifications-cancel-request-permission.html: Added.
            * fast/notifications/resources: Added.
            * fast/notifications/resources/notifications-cancel-request-permission.html: Added.
            * platform/chromium/test_expectations.txt:
    2010-07-22  Yael Aharon  <yael.aharon at nokia.com>
    
            Reviewed by Laszlo Gombos.
    
            [Qt] QtWebKit needs public API for Notifications.
            https://bugs.webkit.org/show_bug.cgi?id=41413
    
            Remove DumpRenderTree private API and introduce new API.
            Also add support for informing the UI when a notification request is cancelled.
    
            * Api/qwebpage.cpp:
            (QWebPage::setUserPermission):
            * Api/qwebpage.h:
            * WebCoreSupport/DumpRenderTreeSupportQt.cpp:
            * WebCoreSupport/DumpRenderTreeSupportQt.h:
            * WebCoreSupport/NotificationPresenterClientQt.cpp:
            (WebCore::NotificationPresenterClientQt::requestPermission):
            (WebCore::NotificationPresenterClientQt::checkPermission):
            (WebCore::NotificationPresenterClientQt::cancelRequestsForPermission):
            (WebCore::NotificationPresenterClientQt::allowNotificationForFrame):
            (WebCore::NotificationPresenterClientQt::toPage):
            (WebCore::NotificationPresenterClientQt::toFrame):
            * WebCoreSupport/NotificationPresenterClientQt.h:
    2010-07-22  Yael Aharon  <yael.aharon at nokia.com>
    
            Reviewed by Laszlo Gombos.
    
            [Qt] QtWebKit needs public API for Notifications.
            https://bugs.webkit.org/show_bug.cgi?id=41413
    
            Update DumpRenderTree and QtTestBrowser to use the new API.
            Add new DRT API to flag that notifications permission requests should be ignored.
    
            * DumpRenderTree/qt/DumpRenderTreeQt.cpp:
            (WebCore::WebPage::WebPage):
            (WebCore::WebPage::requestPermission):
            (WebCore::WebPage::checkPermission):
            (WebCore::WebPage::cancelRequestsForPermission):
            * DumpRenderTree/qt/DumpRenderTreeQt.h:
            * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
            (LayoutTestController::reset):
            (LayoutTestController::ignoreDesktopNotificationPermissionRequests):
            (LayoutTestController::checkDesktopNotificationPermission):
            * DumpRenderTree/qt/LayoutTestControllerQt.h:
            (LayoutTestController::ignoreReqestForPermission):
            * QtTestBrowser/main.cpp:
            (LauncherWindow::LauncherWindow):
            * QtTestBrowser/webpage.cpp:
            (WebPage::WebPage):
            (WebPage::requestPermission):
            (WebPage::checkPermission):
            (WebPage::cancelRequestsForPermission):
            * QtTestBrowser/webpage.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63921 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index a281ca8..79155ed 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,20 @@
+2010-07-22  Yael Aharon  <yael.aharon at nokia.com>
+
+        Reviewed by Laszlo Gombos.
+
+        [Qt] QtWebKit needs public API for Notifications.
+        https://bugs.webkit.org/show_bug.cgi?id=41413
+
+        Add a DRT API to set a flag so that notification requests are ignored,
+        and add a test for cancelling a pending notification request.
+        New API and test are disabled for Chromium port.
+
+        * fast/notifications/notifications-cancel-request-permission-expected.txt: Added.
+        * fast/notifications/notifications-cancel-request-permission.html: Added.
+        * fast/notifications/resources: Added.
+        * fast/notifications/resources/notifications-cancel-request-permission.html: Added.
+        * platform/chromium/test_expectations.txt:
+
 2010-07-22  Ryosuke Niwa  <rniwa at webkit.org>
 
         Reviewed by Ojan Vafai.
diff --git a/LayoutTests/fast/notifications/notifications-cancel-request-permission-expected.txt b/LayoutTests/fast/notifications/notifications-cancel-request-permission-expected.txt
new file mode 100644
index 0000000..ab4d054
--- /dev/null
+++ b/LayoutTests/fast/notifications/notifications-cancel-request-permission-expected.txt
@@ -0,0 +1,5 @@
+DESKTOP NOTIFICATION PERMISSION REQUESTED: file://
+DESKTOP NOTIFICATION PERMISSION REQUEST CANCELLED: file://
+Requesting and cancelling notification permission...
+
+Pass if notification is cancelled
diff --git a/LayoutTests/fast/notifications/notifications-cancel-request-permission.html b/LayoutTests/fast/notifications/notifications-cancel-request-permission.html
new file mode 100644
index 0000000..81f3b52
--- /dev/null
+++ b/LayoutTests/fast/notifications/notifications-cancel-request-permission.html
@@ -0,0 +1,44 @@
+<html>
+<head>
+    <script type="text/javascript">
+
+        // Timeout is to ensure that the iframe was removed.
+        setTimeout(isDone,500);
+
+        function log(message)
+        {
+            document.getElementById("result").innerHTML += message + "<br>";
+        }
+        
+        function runTests()
+        {
+            if (window.layoutTestController) {
+                layoutTestController.dumpAsText();
+                layoutTestController.waitUntilDone();
+            }
+
+            if (!window.webkitNotifications) {
+                log("FAIL: No webkitNotifications interface!");
+            }
+            
+            document.getElementById("test").innerHTML="Pass if notification is cancelled";
+        }
+
+        function isDone()
+        {
+            if (window.layoutTestController) {
+                layoutTestController.notifyDone();
+            }
+        }
+
+    </script>
+</head>
+<body onload="runTests();">
+    <p>Requesting and cancelling notification permission...</p>
+    
+<div id="result"></div>
+<div id="test">
+<iframe src="resources/notifications-cancel-request-permission.html" width=800 height=800></iframe>
+</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/notifications/resources/notifications-cancel-request-permission.html b/LayoutTests/fast/notifications/resources/notifications-cancel-request-permission.html
new file mode 100644
index 0000000..f2263ee
--- /dev/null
+++ b/LayoutTests/fast/notifications/resources/notifications-cancel-request-permission.html
@@ -0,0 +1,28 @@
+<html>
+<head>
+    <script type="text/javascript">
+        function log(message)
+        {
+            parent.document.getElementById("result").innerHTML += message + "<br>";
+        }
+        
+        function runTests()
+        {
+            if (window.layoutTestController) {
+                layoutTestController.dumpAsText();
+            }
+
+            if (window.layoutTestController) {
+                layoutTestController.ignoreDesktopNotificationPermissionRequests();
+            }
+
+            window.webkitNotifications.requestPermission(
+                function() { log("FAIL: Permission callback invoked."); }
+            );
+
+        }
+    </script>
+</head>
+<body onload="runTests();">
+</body>
+</html>
diff --git a/LayoutTests/platform/chromium/test_expectations.txt b/LayoutTests/platform/chromium/test_expectations.txt
index a42f2ea..0601d9d 100644
--- a/LayoutTests/platform/chromium/test_expectations.txt
+++ b/LayoutTests/platform/chromium/test_expectations.txt
@@ -2828,6 +2828,9 @@ BUG46157 WIN RELEASE : transforms/2d/transform-value-types.html = PASS TEXT
 // Chromium does not use the icon loader in WebCore for loading notifications.
 WONTFIX SKIP : http/tests/notifications = FAIL
 
+// Chromium does not support cancel for notifications permissions.
+BUGWK42798 SKIP : fast/notifications/notifications-cancel-request-permission.html = FAIL
+
 BUG46276 WIN : fast/text/international/khmer-selection.html = IMAGE+TEXT
 
 // HTML5 Geolocation API does not use window.clientInformation.
diff --git a/WebKit/qt/Api/qwebpage.cpp b/WebKit/qt/Api/qwebpage.cpp
index 45d6bc0..70e132c 100644
--- a/WebKit/qt/Api/qwebpage.cpp
+++ b/WebKit/qt/Api/qwebpage.cpp
@@ -2108,6 +2108,20 @@ bool QWebPage::allowGeolocationRequest(QWebFrame *frame)
 #endif
 }
 
+void QWebPage::setUserPermission(QWebFrame* frame, PermissionDomain domain, PermissionPolicy policy)
+{
+    switch (domain) {
+    case NotificationsPermissionDomain:
+#if ENABLE(NOTIFICATIONS)
+        if (policy == PermissionGranted)
+            NotificationPresenterClientQt::notificationPresenter()->allowNotificationForFrame(frame);
+#endif
+        break;
+    default:
+        break;
+    }
+}
+
 /*!
     This function is called whenever WebKit wants to create a new window of the given \a type, for
     example when a JavaScript program requests to open a document in a new window.
diff --git a/WebKit/qt/Api/qwebpage.h b/WebKit/qt/Api/qwebpage.h
index fcaa302..f0d2438 100644
--- a/WebKit/qt/Api/qwebpage.h
+++ b/WebKit/qt/Api/qwebpage.h
@@ -195,6 +195,16 @@ public:
         WebModalDialog
     };
 
+    enum PermissionPolicy {
+        PermissionGranted,
+        PermissionUnknown,
+        PermissionDenied
+    };
+
+    enum PermissionDomain {
+        NotificationsPermissionDomain
+    };
+
     class ViewportHints {
     public:
         ViewportHints();
@@ -290,6 +300,8 @@ public:
 
     QMenu *createStandardContextMenu();
 
+    void setUserPermission(QWebFrame* frame, PermissionDomain domain, PermissionPolicy policy);
+
     enum Extension {
         ChooseMultipleFilesExtension,
         ErrorPageExtension
@@ -371,6 +383,10 @@ Q_SIGNALS:
 
     void viewportChangeRequested(const QWebPage::ViewportHints& hints);
 
+    void requestPermissionFromUser(QWebFrame* frame, QWebPage::PermissionDomain domain);
+    void checkPermissionFromUser(QWebFrame* frame, QWebPage::PermissionDomain domain, QWebPage::PermissionPolicy& policy);
+    void cancelRequestsForPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
+
 protected:
     virtual QWebPage *createWindow(WebWindowType type);
     virtual QObject *createPlugin(const QString &classid, const QUrl &url, const QStringList &paramNames, const QStringList &paramValues);
diff --git a/WebKit/qt/ChangeLog b/WebKit/qt/ChangeLog
index e5cf357..4f1706e 100644
--- a/WebKit/qt/ChangeLog
+++ b/WebKit/qt/ChangeLog
@@ -1,3 +1,27 @@
+2010-07-22  Yael Aharon  <yael.aharon at nokia.com>
+
+        Reviewed by Laszlo Gombos.
+
+        [Qt] QtWebKit needs public API for Notifications.
+        https://bugs.webkit.org/show_bug.cgi?id=41413
+
+        Remove DumpRenderTree private API and introduce new API.
+        Also add support for informing the UI when a notification request is cancelled.
+
+        * Api/qwebpage.cpp:
+        (QWebPage::setUserPermission):
+        * Api/qwebpage.h:
+        * WebCoreSupport/DumpRenderTreeSupportQt.cpp:
+        * WebCoreSupport/DumpRenderTreeSupportQt.h:
+        * WebCoreSupport/NotificationPresenterClientQt.cpp:
+        (WebCore::NotificationPresenterClientQt::requestPermission):
+        (WebCore::NotificationPresenterClientQt::checkPermission):
+        (WebCore::NotificationPresenterClientQt::cancelRequestsForPermission):
+        (WebCore::NotificationPresenterClientQt::allowNotificationForFrame):
+        (WebCore::NotificationPresenterClientQt::toPage):
+        (WebCore::NotificationPresenterClientQt::toFrame):
+        * WebCoreSupport/NotificationPresenterClientQt.h:
+
 2010-07-22  Jamey Hicks  <jamey.hicks at nokia.com>
 
         Reviewed by Kenneth Rohde Christiansen.
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
index a83e1a5..ddc9d7a 100644
--- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
+++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.cpp
@@ -70,8 +70,6 @@
 
 using namespace WebCore;
 
-CheckPermissionFunctionType* checkPermissionFunction = 0;
-RequestPermissionFunctionType* requestPermissionFunction = 0;
 QMap<int, QWebScriptWorld*> m_worldMap;
 
 DumpRenderTreeSupportQt::DumpRenderTreeSupportQt()
@@ -575,20 +573,6 @@ void DumpRenderTreeSupportQt::dumpNotification(bool b)
 #endif
 }
 
-void DumpRenderTreeSupportQt::setNotificationsReceiver(QObject* receiver)
-{
-#if ENABLE(NOTIFICATIONS)
-    NotificationPresenterClientQt::notificationPresenter()->setReceiver(receiver);
-#endif
-}
-
-void DumpRenderTreeSupportQt::allowNotificationForOrigin(const QString& origin)
-{
-#if ENABLE(NOTIFICATIONS)
-    NotificationPresenterClientQt::notificationPresenter()->allowNotificationForOrigin(origin);
-#endif
-}
-
 void DumpRenderTreeSupportQt::setMockGeolocationPosition(double latitude, double longitude, double accuracy)
 {
 #if ENABLE(GEOLOCATION)
@@ -605,16 +589,6 @@ void DumpRenderTreeSupportQt::setMockGeolocationError(int errorCode, const QStri
 #endif
 }
 
-void DumpRenderTreeSupportQt::setCheckPermissionFunction(CheckPermissionFunctionType* f)
-{
-    checkPermissionFunction = f;
-}
-
-void DumpRenderTreeSupportQt::setRequestPermissionFunction(RequestPermissionFunctionType* f)
-{
-    requestPermissionFunction = f;
-}
-
 bool DumpRenderTreeSupportQt::isTargetItem(const QWebHistoryItem& historyItem)
 {
     QWebHistoryItem it = historyItem;
diff --git a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
index 188c405..3a92158 100644
--- a/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
+++ b/WebKit/qt/WebCoreSupport/DumpRenderTreeSupportQt.h
@@ -32,17 +32,6 @@ class QWebPage;
 class QWebHistoryItem;
 class QWebScriptWorld;
 
-enum NotificationPermission {
-    NotificationAllowed,
-    NotificationNotAllowed,
-    NotificationDenied
-};
-
-typedef void (CheckPermissionFunctionType) (QObject* receiver, const QUrl&, NotificationPermission&);
-typedef void (RequestPermissionFunctionType) (QObject* receiver, const QString&);
-
-extern CheckPermissionFunctionType* checkPermissionFunction;
-extern RequestPermissionFunctionType* requestPermissionFunction;
 extern QMap<int, QWebScriptWorld*> m_worldMap;
 
 class QWEBKIT_EXPORT DumpRenderTreeSupportQt {
@@ -123,13 +112,6 @@ public:
 
     static void dumpNotification(bool b);
 
-    // These functions should eventually turn into public API
-    // and the "receiver" concept would go away
-    static void setNotificationsReceiver(QObject* receiver);
-    static void allowNotificationForOrigin(const QString& origin);
-    static void setCheckPermissionFunction(CheckPermissionFunctionType*);
-    static void setRequestPermissionFunction(RequestPermissionFunctionType*);
-
     static QMap<QString, QWebHistoryItem> getChildHistoryItems(const QWebHistoryItem& historyItem);
     static bool isTargetItem(const QWebHistoryItem& historyItem);
     static QString historyItemTarget(const QWebHistoryItem& historyItem);
diff --git a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
index ee69103..477e205 100644
--- a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
+++ b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.cpp
@@ -36,11 +36,14 @@
 #include "DumpRenderTreeSupportQt.h"
 #include "EventNames.h"
 #include "KURL.h"
+#include "Page.h"
 #include "QtPlatformPlugin.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
 
+#include "qwebframe_p.h"
 #include "qwebkitglobal.h"
+#include "qwebpage.h"
 #include <QtGui>
 
 namespace WebCore {
@@ -259,53 +262,77 @@ void NotificationPresenterClientQt::requestPermission(ScriptExecutionContext* co
     if (dumpNotification)
         printf("DESKTOP NOTIFICATION PERMISSION REQUESTED: %s\n", QString(context->securityOrigin()->toString()).toUtf8().constData());
 
-    QString originString = context->securityOrigin()->toString();
-    QHash<QString, QList<RefPtr<VoidCallback> > >::iterator iter = m_pendingPermissionRequests.find(originString);
+    QHash<ScriptExecutionContext*, CallbacksInfo >::iterator iter = m_pendingPermissionRequests.find(context);
     if (iter != m_pendingPermissionRequests.end())
-        iter.value().append(callback);
+        iter.value().m_callbacks.append(callback);
     else {
-        QList<RefPtr<VoidCallback> > callbacks;
         RefPtr<VoidCallback> cb = callback;
-        callbacks.append(cb);
-        m_pendingPermissionRequests.insert(originString, callbacks);
-        if (requestPermissionFunction)
-            requestPermissionFunction(m_receiver, originString);
+        CallbacksInfo info;
+        info.m_frame = toFrame(context);
+        info.m_callbacks.append(cb);
+        m_pendingPermissionRequests.insert(context, info);
+
+        if (toPage(context) && toFrame(context)) {
+            m_pendingPermissionRequests.insert(context, info);
+            emit toPage(context)->requestPermissionFromUser(toFrame(context), QWebPage::NotificationsPermissionDomain);
+        }
     }
 }
 
 NotificationPresenter::Permission NotificationPresenterClientQt::checkPermission(ScriptExecutionContext* context)
 {
-    NotificationPermission permission = NotificationNotAllowed;
-    QString origin = context->url().string();
-    if (checkPermissionFunction)
-        checkPermissionFunction(m_receiver, origin, permission);
-    switch (permission) {
-    case NotificationAllowed:
+    QWebPage::PermissionPolicy policy = QWebPage::PermissionUnknown;
+    if (toPage(context) && toFrame(context))
+        emit toPage(context)->checkPermissionFromUser(toFrame(context), QWebPage::NotificationsPermissionDomain, policy);
+
+    switch (policy) {
+    case QWebPage::PermissionGranted:
         return NotificationPresenter::PermissionAllowed;
-    case NotificationNotAllowed:
+    case QWebPage::PermissionUnknown:
         return NotificationPresenter::PermissionNotAllowed;
-    case NotificationDenied:
+    case QWebPage::PermissionDenied:
         return NotificationPresenter::PermissionDenied;
     }
     ASSERT_NOT_REACHED();
     return NotificationPresenter::PermissionNotAllowed;
 }
 
-void NotificationPresenterClientQt::cancelRequestsForPermission(ScriptExecutionContext*)
+void NotificationPresenterClientQt::cancelRequestsForPermission(ScriptExecutionContext* context)
 {
-    // FIXME: This will be implemented for https://bugs.webkit.org/show_bug.cgi?id=41413
-    // to avoid adding and removing new private API
+    QHash<ScriptExecutionContext*, CallbacksInfo >::iterator iter = m_pendingPermissionRequests.find(context);
+    if (iter == m_pendingPermissionRequests.end())
+        return;
+
+    QWebFrame* frame = iter.value().m_frame;
+    if (!frame)
+        return;
+    QWebPage* page = frame->page();
+    m_pendingPermissionRequests.erase(iter);
+
+    if (!page)
+        return;
+
+    if (dumpNotification)
+        printf("DESKTOP NOTIFICATION PERMISSION REQUEST CANCELLED: %s\n", QString(context->securityOrigin()->toString()).toUtf8().constData());
+
+    emit page->cancelRequestsForPermission(frame, QWebPage::NotificationsPermissionDomain);
 }
 
-void NotificationPresenterClientQt::allowNotificationForOrigin(const QString& origin)
+void NotificationPresenterClientQt::allowNotificationForFrame(QWebFrame* frame)
 {
-    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);
+    QHash<ScriptExecutionContext*,  CallbacksInfo>::iterator iter = m_pendingPermissionRequests.begin();
+    while (iter != m_pendingPermissionRequests.end()) {
+        if (toFrame(iter.key()) == frame)
+            break;
     }
+
+    if (iter == m_pendingPermissionRequests.end())
+        return;
+
+    QList<RefPtr<VoidCallback> >& callbacks = iter.value().m_callbacks;
+    for (int i = 0; i < callbacks.size(); i++)
+        callbacks.at(i)->handleEvent();
+    m_pendingPermissionRequests.remove(iter.key());
 }
 
 void NotificationPresenterClientQt::sendEvent(Notification* notification, const AtomicString& eventName)
@@ -362,6 +389,34 @@ void NotificationPresenterClientQt::dumpShowText(Notification* notification)
     }
 }
 
+QWebPage* NotificationPresenterClientQt::toPage(ScriptExecutionContext* context)
+{
+    if (!context || context->isWorkerContext())
+        return 0;
+
+    Document* document = static_cast<Document*>(context);
+    if (!document)
+        return 0;
+
+    Page* page = document->page();
+    if (!page || !page->mainFrame())
+        return 0;
+
+    return QWebFramePrivate::kit(page->mainFrame())->page();
+}
+
+QWebFrame* NotificationPresenterClientQt::toFrame(ScriptExecutionContext* context)
+{
+    if (!context || context->isWorkerContext())
+        return 0;
+
+    Document* document = static_cast<Document*>(context);
+    if (!document || !document->frame())
+        return 0;
+
+    return QWebFramePrivate::kit(document->frame());
+}
+
 #endif // ENABLE(NOTIFICATIONS)
 }
 
diff --git a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
index b99393b..e8481d4 100644
--- a/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
+++ b/WebKit/qt/WebCoreSupport/NotificationPresenterClientQt.h
@@ -42,6 +42,9 @@
 #include <QMultiHash>
 #include <QSystemTrayIcon>
 
+class QWebFrame;
+class QWebPage;
+
 namespace WebCore {
 
 class Document;
@@ -90,12 +93,10 @@ public:
 
     void cancel(NotificationWrapper*);
 
-    void allowNotificationForOrigin(const QString& origin);
+    void allowNotificationForFrame(QWebFrame*);
 
     static bool dumpNotification;
 
-    void setReceiver(QObject* receiver) { m_receiver = receiver; }
-
     void addClient() { m_clientCount++; }
     void removeClient();
     static NotificationPresenterClientQt* notificationPresenter();
@@ -109,11 +110,17 @@ private:
     void detachNotification(Notification*);
     void dumpReplacedIdText(Notification*);
     void dumpShowText(Notification*);
+    QWebPage* toPage(ScriptExecutionContext*);
+    QWebFrame* toFrame(ScriptExecutionContext*);
 
     int m_clientCount;
-    QHash<QString,  QList<RefPtr<VoidCallback> > > m_pendingPermissionRequests;
+    struct CallbacksInfo {
+        QWebFrame* m_frame;
+        QList<RefPtr<VoidCallback> > m_callbacks;
+    };
+    QHash<ScriptExecutionContext*,  CallbacksInfo > m_pendingPermissionRequests;
+
     NotificationsQueue m_notifications;
-    QObject* m_receiver;
     QtPlatformPlugin m_platformPlugin;
 };
 
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index f79e7b1..a4d598f 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,34 @@
+2010-07-22  Yael Aharon  <yael.aharon at nokia.com>
+
+        Reviewed by Laszlo Gombos.
+
+        [Qt] QtWebKit needs public API for Notifications.
+        https://bugs.webkit.org/show_bug.cgi?id=41413
+
+        Update DumpRenderTree and QtTestBrowser to use the new API.
+        Add new DRT API to flag that notifications permission requests should be ignored.
+
+        * DumpRenderTree/qt/DumpRenderTreeQt.cpp:
+        (WebCore::WebPage::WebPage):
+        (WebCore::WebPage::requestPermission):
+        (WebCore::WebPage::checkPermission):
+        (WebCore::WebPage::cancelRequestsForPermission):
+        * DumpRenderTree/qt/DumpRenderTreeQt.h:
+        * DumpRenderTree/qt/LayoutTestControllerQt.cpp:
+        (LayoutTestController::reset):
+        (LayoutTestController::ignoreDesktopNotificationPermissionRequests):
+        (LayoutTestController::checkDesktopNotificationPermission):
+        * DumpRenderTree/qt/LayoutTestControllerQt.h:
+        (LayoutTestController::ignoreReqestForPermission):
+        * QtTestBrowser/main.cpp:
+        (LauncherWindow::LauncherWindow):
+        * QtTestBrowser/webpage.cpp:
+        (WebPage::WebPage):
+        (WebPage::requestPermission):
+        (WebPage::checkPermission):
+        (WebPage::cancelRequestsForPermission):
+        * QtTestBrowser/webpage.h:
+
 2010-07-22  Darin Adler  <darin at apple.com>
 
         Reviewed by Sam Weinig.
diff --git a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
index 022a867..c6c39b5 100644
--- a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
+++ b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.cpp
@@ -130,16 +130,6 @@ public:
 };
 #endif
 
-void checkPermissionCallback(QObject* receiver, const QUrl& url, NotificationPermission& permission)
-{
-    qobject_cast<DumpRenderTree*>(receiver)->checkPermission(url, permission);
-}
-
-void requestPermissionCallback(QObject* receiver, const QString& origin)
-{
-    qobject_cast<DumpRenderTree*>(receiver)->requestPermission(origin);
-}
-
 WebPage::WebPage(QObject* parent, DumpRenderTree* drt)
     : QWebPage(parent)
     , m_webInspector(0)
@@ -167,10 +157,9 @@ WebPage::WebPage(QObject* parent, DumpRenderTree* drt)
     setNetworkAccessManager(m_drt->networkAccessManager());
     setPluginFactory(new TestPlugin(this));
 
-    DumpRenderTreeSupportQt::setNotificationsReceiver(m_drt);
-    DumpRenderTreeSupportQt::setCheckPermissionFunction(checkPermissionCallback);
-    DumpRenderTreeSupportQt::setRequestPermissionFunction(requestPermissionCallback);
-
+    connect(this, SIGNAL(requestPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain)), this, SLOT(requestPermission(QWebFrame*, QWebPage::PermissionDomain)));
+    connect(this, SIGNAL(checkPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain, QWebPage::PermissionPolicy&)), this, SLOT(checkPermission(QWebFrame*, QWebPage::PermissionDomain, QWebPage::PermissionPolicy&)));
+    connect(this, SIGNAL(cancelRequestsForPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain)), this, SLOT(cancelRequestsForPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain)));
 }
 
 WebPage::~WebPage()
@@ -228,6 +217,36 @@ void WebPage::javaScriptAlert(QWebFrame*, const QString& message)
     fprintf(stdout, "ALERT: %s\n", message.toUtf8().constData());
 }
 
+void WebPage::requestPermission(QWebFrame* frame, QWebPage::PermissionDomain domain)
+{
+    switch (domain) {
+    case NotificationsPermissionDomain:
+        if (!m_drt->layoutTestController()->ignoreReqestForPermission())
+            setUserPermission(frame, domain, PermissionGranted);
+        break;
+    default:
+        break;
+    }
+}
+
+void WebPage::checkPermission(QWebFrame* frame, QWebPage::PermissionDomain domain, QWebPage::PermissionPolicy& policy)
+{
+    switch (domain) {
+    case NotificationsPermissionDomain:
+        {
+        QUrl url = frame->url();
+        policy = m_drt->layoutTestController()->checkDesktopNotificationPermission(url.scheme() + "://" + url.host()) ? PermissionGranted : PermissionDenied;
+        break;
+        }
+    default:
+        break;
+    }
+}
+
+void WebPage::cancelRequestsForPermission(QWebFrame*, QWebPage::PermissionDomain)
+{
+}
+
 static QString urlSuitableForTestResult(const QString& url)
 {
     if (url.isEmpty() || !url.startsWith(QLatin1String("file://")))
@@ -992,16 +1011,6 @@ void DumpRenderTree::switchFocus(bool focused)
 
 }
 
-void DumpRenderTree::checkPermission(const QUrl& url, NotificationPermission& permission)
-{
-    permission = m_controller->checkDesktopNotificationPermission(url.scheme() + "://" + url.host()) ? NotificationAllowed : NotificationDenied;
-}
-
-void DumpRenderTree::requestPermission(const QString& origin)
-{
-    DumpRenderTreeSupportQt::allowNotificationForOrigin(origin);
-}
-
 #if defined(Q_WS_X11)
 void DumpRenderTree::initializeFonts()
 {
diff --git a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
index f258189..de0c6c5 100644
--- a/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
+++ b/WebKitTools/DumpRenderTree/qt/DumpRenderTreeQt.h
@@ -119,8 +119,6 @@ public Q_SLOTS:
     void dumpDatabaseQuota(QWebFrame* frame, const QString& dbName);
     void statusBarMessage(const QString& message);
     void windowCloseRequested();
-    void checkPermission(const QUrl&, NotificationPermission&);
-    void requestPermission(const QString&);
 
 Q_SIGNALS:
     void quit();
@@ -193,6 +191,9 @@ public:
 public slots:
     bool shouldInterruptJavaScript() { return false; }
     bool allowGeolocationRequest(QWebFrame *frame);
+    void requestPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
+    void checkPermission(QWebFrame* frame, QWebPage::PermissionDomain domain, QWebPage::PermissionPolicy& policy);
+    void cancelRequestsForPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
 
 protected:
     bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, NavigationType type);
diff --git a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
index 3a6229f..8ebdbae 100644
--- a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
+++ b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.cpp
@@ -67,6 +67,7 @@ void LayoutTestController::reset()
     m_globalFlag = false;
     m_userStyleSheetEnabled = false;
     m_desktopNotificationAllowedOrigins.clear();
+    m_ignoreDesktopNotification = false;
 
     DumpRenderTreeSupportQt::dumpEditingCallbacks(false);
     DumpRenderTreeSupportQt::dumpFrameLoader(false);
@@ -193,9 +194,14 @@ void LayoutTestController::grantDesktopNotificationPermission(const QString& ori
     m_desktopNotificationAllowedOrigins.append(origin);
 }
 
+void LayoutTestController::ignoreDesktopNotificationPermissionRequests()
+{
+    m_ignoreDesktopNotification = true;
+}
+
 bool LayoutTestController::checkDesktopNotificationPermission(const QString& origin)
 {
-    return m_desktopNotificationAllowedOrigins.contains(origin);
+    return !m_ignoreDesktopNotification && m_desktopNotificationAllowedOrigins.contains(origin);
 }
 
 void LayoutTestController::display()
diff --git a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h
index 4e95381..4ebf99d 100644
--- a/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h
+++ b/WebKitTools/DumpRenderTree/qt/LayoutTestControllerQt.h
@@ -70,6 +70,7 @@ public:
     bool canOpenWindows() const { return m_canOpenWindows; }
     bool shouldDumpTitleChanges() const { return m_dumpTitleChanges; }
     bool waitForPolicy() const { return m_waitForPolicy; }
+    bool ignoreReqestForPermission() const { return m_ignoreDesktopNotification; }
 
     void reset();
 
@@ -120,6 +121,7 @@ public slots:
     void setCloseRemainingWindowsWhenComplete(bool = false) {}
     int windowCount();
     void grantDesktopNotificationPermission(const QString& origin);
+    void ignoreDesktopNotificationPermissionRequests();
     bool checkDesktopNotificationPermission(const QString& origin);
     void display();
     void clearBackForwardList();
@@ -252,6 +254,7 @@ private:
     WebCore::DumpRenderTree* m_drt;
     QWebHistory* m_webHistory;
     QStringList m_desktopNotificationAllowedOrigins;
+    bool m_ignoreDesktopNotification;
 };
 
 #endif // LayoutTestControllerQt_h
diff --git a/WebKitTools/QtTestBrowser/main.cpp b/WebKitTools/QtTestBrowser/main.cpp
index 25765be..6254c21 100644
--- a/WebKitTools/QtTestBrowser/main.cpp
+++ b/WebKitTools/QtTestBrowser/main.cpp
@@ -92,29 +92,6 @@ static bool gUseFrameFlattening = false;
 static bool gUseQGLWidgetViewport = false;
 #endif
 
-class NotificationsPermissionController : public QObject {
-    Q_OBJECT
-public:
-    NotificationsPermissionController(QObject* parent) : QObject(parent) 
-    {
-        DumpRenderTreeSupportQt::setNotificationsReceiver(this);
-        DumpRenderTreeSupportQt::setCheckPermissionFunction(checkPermission);
-        DumpRenderTreeSupportQt::setRequestPermissionFunction(requestPermission);
-    }
-
-    static void checkPermission(QObject*, const QUrl&, NotificationPermission& permission)
-    {
-        permission = NotificationAllowed;
-    }
-
-    static void requestPermission(QObject*, const QString& origin)
-    {
-        DumpRenderTreeSupportQt::allowNotificationForOrigin(origin);
-    }
-};
-
-NotificationsPermissionController* notificationsPermissionController = 0;
-
 class LauncherWindow : public MainWindow {
     Q_OBJECT
 
@@ -233,8 +210,6 @@ LauncherWindow::LauncherWindow(LauncherWindow* other, bool shareScene)
     }
 
     createChrome();
-    if (!notificationsPermissionController)
-        notificationsPermissionController = new NotificationsPermissionController(QCoreApplication::instance());
 }
 
 LauncherWindow::~LauncherWindow()
diff --git a/WebKitTools/QtTestBrowser/webpage.cpp b/WebKitTools/QtTestBrowser/webpage.cpp
index 2a3aae6..ee0232b 100644
--- a/WebKitTools/QtTestBrowser/webpage.cpp
+++ b/WebKitTools/QtTestBrowser/webpage.cpp
@@ -48,6 +48,9 @@ WebPage::WebPage(QObject* parent)
 
     connect(networkAccessManager(), SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
             this, SLOT(authenticationRequired(QNetworkReply*, QAuthenticator*)));
+    connect(this, SIGNAL(requestPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain)), this, SLOT(requestPermission(QWebFrame*, QWebPage::PermissionDomain)));
+    connect(this, SIGNAL(checkPermissionFromUser(QWebFrame*, QWebPage::PermissionDomain, QWebPage::PermissionPolicy&)), this, SLOT(checkPermission(QWebFrame*, QWebPage::PermissionDomain, QWebPage::PermissionPolicy&)));
+    connect(this, SIGNAL(cancelRequestsForPermission(QWebFrame*, QWebPage::PermissionDomain)), this, SLOT(cancelRequestsForPermission(QWebFrame*, QWebPage::PermissionDomain)));
 }
 
 void WebPage::applyProxy()
@@ -162,3 +165,23 @@ void WebPage::authenticationRequired(QNetworkReply* reply, QAuthenticator* authe
 
     delete dialog;
 }
+
+void WebPage::requestPermission(QWebFrame* frame, QWebPage::PermissionDomain domain)
+{
+    setUserPermission(frame, domain, PermissionGranted);
+}
+
+void WebPage::checkPermission(QWebFrame* frame, QWebPage::PermissionDomain domain, QWebPage::PermissionPolicy& policy)
+{
+    switch (domain) {
+    case NotificationsPermissionDomain:
+        policy = PermissionGranted;
+        break;
+    default:
+        break;
+    }
+}
+
+void WebPage::cancelRequestsForPermission(QWebFrame*, QWebPage::PermissionDomain)
+{
+}
diff --git a/WebKitTools/QtTestBrowser/webpage.h b/WebKitTools/QtTestBrowser/webpage.h
index 03cde43..15ae369 100644
--- a/WebKitTools/QtTestBrowser/webpage.h
+++ b/WebKitTools/QtTestBrowser/webpage.h
@@ -57,6 +57,9 @@ public slots:
     void setUserAgent(const QString& ua) { m_userAgent = ua; }
     bool shouldInterruptJavaScript();
     void authenticationRequired(QNetworkReply*, QAuthenticator*);
+    void requestPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
+    void checkPermission(QWebFrame* frame, QWebPage::PermissionDomain domain, QWebPage::PermissionPolicy& policy);
+    void cancelRequestsForPermission(QWebFrame* frame, QWebPage::PermissionDomain domain);
 
 private:
     void applyProxy();

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list