[Qt][WK2] Make QWebError more friendly to QML.
authoralexis.menard@openbossa.org <alexis.menard@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2011 16:54:57 +0000 (16:54 +0000)
committeralexis.menard@openbossa.org <alexis.menard@openbossa.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Sep 2011 16:54:57 +0000 (16:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67785

Reviewed by Simon Hausmann.

Make sure that we can use the loading errors in QML. We send it via a QJSValue which
has the properties needed to get the error code, the url and the type of error.

* UIProcess/API/qt/qdesktopwebview.cpp:
(QDesktopWebViewPrivate::loadDidFail):
(QDesktopWebViewPrivate::engine):
* UIProcess/API/qt/qdesktopwebview.h:
* UIProcess/API/qt/qdesktopwebview_p.h:
* UIProcess/API/qt/qtouchwebpage.h:
* UIProcess/API/qt/tests/commonviewtests/tst_commonviewtests.cpp:
(tst_CommonViewTests::loadNonexistentFileUrl):
* UIProcess/API/qt/tests/commonviewtests/webviewabstraction.cpp:
(WebViewAbstraction::WebViewAbstraction):
(WebViewAbstraction::touchViewLoadFailed):
(WebViewAbstraction::desktopViewLoadFailed):
* UIProcess/API/qt/tests/commonviewtests/webviewabstraction.h:
* UIProcess/API/qt/tests/testwindow.h:
* UIProcess/qt/QtWebPageProxy.cpp:
(QtWebPageProxy::loadDidFail):
* UIProcess/qt/QtWebPageProxy.h:
* UIProcess/qt/TouchViewInterface.cpp:
(WebKit::TouchViewInterface::loadDidFail):
(WebKit::TouchViewInterface::engine):
* UIProcess/qt/TouchViewInterface.h:
* UIProcess/qt/ViewInterface.h:

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/qdesktopwebview.cpp
Source/WebKit2/UIProcess/API/qt/qdesktopwebview.h
Source/WebKit2/UIProcess/API/qt/qdesktopwebview_p.h
Source/WebKit2/UIProcess/API/qt/qtouchwebpage.h
Source/WebKit2/UIProcess/API/qt/tests/commonviewtests/tst_commonviewtests.cpp
Source/WebKit2/UIProcess/API/qt/tests/commonviewtests/webviewabstraction.cpp
Source/WebKit2/UIProcess/API/qt/tests/commonviewtests/webviewabstraction.h
Source/WebKit2/UIProcess/API/qt/tests/testwindow.h
Source/WebKit2/UIProcess/qt/QtWebPageProxy.cpp
Source/WebKit2/UIProcess/qt/QtWebPageProxy.h
Source/WebKit2/UIProcess/qt/TouchViewInterface.cpp
Source/WebKit2/UIProcess/qt/TouchViewInterface.h
Source/WebKit2/UIProcess/qt/ViewInterface.h

index df17a2c..08f29bd 100644 (file)
@@ -1,3 +1,36 @@
+2011-09-15  Alexis Menard  <alexis.menard@openbossa.org>
+
+        [Qt][WK2] Make QWebError more friendly to QML.
+        https://bugs.webkit.org/show_bug.cgi?id=67785
+
+        Reviewed by Simon Hausmann.
+
+        Make sure that we can use the loading errors in QML. We send it via a QJSValue which
+        has the properties needed to get the error code, the url and the type of error.
+
+        * UIProcess/API/qt/qdesktopwebview.cpp:
+        (QDesktopWebViewPrivate::loadDidFail):
+        (QDesktopWebViewPrivate::engine):
+        * UIProcess/API/qt/qdesktopwebview.h:
+        * UIProcess/API/qt/qdesktopwebview_p.h:
+        * UIProcess/API/qt/qtouchwebpage.h:
+        * UIProcess/API/qt/tests/commonviewtests/tst_commonviewtests.cpp:
+        (tst_CommonViewTests::loadNonexistentFileUrl):
+        * UIProcess/API/qt/tests/commonviewtests/webviewabstraction.cpp:
+        (WebViewAbstraction::WebViewAbstraction):
+        (WebViewAbstraction::touchViewLoadFailed):
+        (WebViewAbstraction::desktopViewLoadFailed):
+        * UIProcess/API/qt/tests/commonviewtests/webviewabstraction.h:
+        * UIProcess/API/qt/tests/testwindow.h:
+        * UIProcess/qt/QtWebPageProxy.cpp:
+        (QtWebPageProxy::loadDidFail):
+        * UIProcess/qt/QtWebPageProxy.h:
+        * UIProcess/qt/TouchViewInterface.cpp:
+        (WebKit::TouchViewInterface::loadDidFail):
+        (WebKit::TouchViewInterface::engine):
+        * UIProcess/qt/TouchViewInterface.h:
+        * UIProcess/qt/ViewInterface.h:
+
 2011-09-15  Adam Roben  <aroben@apple.com>
 
         Remove WebKit2-specific knowledge from the Message class
index 976afe8..df787f6 100644 (file)
 
 #include <QGraphicsSceneResizeEvent>
 #include <QStyleOptionGraphicsItem>
+#include <QtDeclarative/qdeclarativeengine.h>
 #include <QtDeclarative/qsgcanvas.h>
 #include <QtDeclarative/qsgevent.h>
 #include <QtDeclarative/qsgitem.h>
+#include <QtDeclarative/qsgview.h>
 #include <QtGui/QCursor>
 #include <QtGui/QFileDialog>
 #include <QtGui/QFocusEvent>
@@ -142,7 +144,7 @@ void QDesktopWebViewPrivate::loadDidSucceed()
     emit q->loadSucceeded();
 }
 
-void QDesktopWebViewPrivate::loadDidFail(const QWebError& error)
+void QDesktopWebViewPrivate::loadDidFail(const QJSValue& error)
 {
     emit q->loadFailed(error);
 }
@@ -382,6 +384,14 @@ void QDesktopWebViewPrivate::didRelaunchProcess()
     q->update();
 }
 
+QJSEngine* QDesktopWebViewPrivate::engine()
+{
+    QSGView* view = qobject_cast<QSGView*>(q->canvas());
+    if (view)
+        return view->engine();
+    return 0;
+}
+
 void QDesktopWebViewPrivate::chooseFiles(WKOpenPanelResultListenerRef listenerRef, const QStringList& selectedFileNames, ViewInterface::FileChooserType type)
 {
 #ifndef QT_NO_FILEDIALOG
index 034c216..b7e7bda 100644 (file)
@@ -28,7 +28,6 @@
 #include <WebKit2/WKBase.h>
 
 class QDesktopWebViewPrivate;
-class QWebError;
 class QWebNavigationController;
 
 QT_BEGIN_NAMESPACE
@@ -80,7 +79,8 @@ Q_SIGNALS:
     void statusBarMessageChanged(const QString&);
     void loadStarted();
     void loadSucceeded();
-    void loadFailed(const QWebError&);
+    // The parameter needs to be explicitly named to work in QML.
+    void loadFailed(const QJSValue& error);
     void loadProgressChanged(int progress);
     void urlChanged(const QUrl&);
 
index 62498bb..275c204 100644 (file)
@@ -71,7 +71,7 @@ private:
     virtual void loadDidBegin();
     virtual void loadDidCommit();
     virtual void loadDidSucceed();
-    virtual void loadDidFail(const QWebError&);
+    virtual void loadDidFail(const QJSValue&);
     virtual void didChangeLoadProgress(int);
 
     virtual void showContextMenu(QSharedPointer<QMenu>);
@@ -80,6 +80,8 @@ private:
     virtual void processDidCrash();
     virtual void didRelaunchProcess();
 
+    virtual QJSEngine* engine();
+
     virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, ViewInterface::FileChooserType);
 
     // PolicyInterface.
index 608c753..ec9f033 100644 (file)
@@ -29,7 +29,6 @@
 
 class QTouchWebPagePrivate;
 class QTouchWebPageProxy;
-class QWebError;
 class QWebNavigationController;
 
 namespace WebKit {
@@ -64,7 +63,8 @@ Q_SIGNALS:
     void titleChanged(const QString&);
     void loadStarted();
     void loadSucceeded();
-    void loadFailed(const QWebError&);
+    // The parameter needs to be explicitly named to work in QML.
+    void loadFailed(const QJSValue& error);
     void loadProgressChanged(int progress);
 
 protected:
index 281feff..a7b33c4 100644 (file)
@@ -97,7 +97,7 @@ void tst_CommonViewTests::loadNonexistentFileUrl()
     QSignalSpy loadFailedSpy(viewAbstraction.data(), SIGNAL(loadStarted()));
 
     viewAbstraction->load(QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/file_that_does_not_exist.html")));
-    QVERIFY(waitForSignal(viewAbstraction.data(), SIGNAL(loadFailed(QWebError))));
+    QVERIFY(waitForSignal(viewAbstraction.data(), SIGNAL(loadFailed(QJSValue))));
 
     QCOMPARE(loadFailedSpy.size(), 1);
 }
index f4e3042..fa2c9f6 100644 (file)
@@ -35,7 +35,7 @@ WebViewAbstraction::WebViewAbstraction()
     m_touchWebViewWindow.setWindowTitle(QLatin1String("TouchWebView"));
     connect(touchWebView()->page(), SIGNAL(loadStarted()), this, SLOT(touchViewLoadStarted()));
     connect(touchWebView()->page(), SIGNAL(loadSucceeded()), this, SLOT(touchViewLoadSucceeded()));
-    connect(touchWebView()->page(), SIGNAL(loadFailed(QWebError)), this, SLOT(touchViewLoadFailed(QWebError)));
+    connect(touchWebView()->page(), SIGNAL(loadFailed(QJSValue)), this, SLOT(touchViewLoadFailed(QJSValue)));
     connect(touchWebView()->page(), SIGNAL(loadProgressChanged(int)), this, SLOT(touchViewLoadProgressChanged(int)));
 
     screenHalf.moveLeft(screenHalf.right());
@@ -43,7 +43,7 @@ WebViewAbstraction::WebViewAbstraction()
     m_desktopWebViewWindow.setWindowTitle(QLatin1String("DesktopWebView"));
     connect(desktopWebView(), SIGNAL(loadStarted()), this, SLOT(desktopViewLoadStarted()));
     connect(desktopWebView(), SIGNAL(loadSucceeded()), this, SLOT(desktopViewLoadSucceeded()));
-    connect(desktopWebView(), SIGNAL(loadFailed(QWebError)), this, SLOT(desktopViewLoadFailed(QWebError)));
+    connect(desktopWebView(), SIGNAL(loadFailed(QJSValue)), this, SLOT(desktopViewLoadFailed(QJSValue)));
     connect(desktopWebView(), SIGNAL(loadProgressChanged(int)), this, SLOT(desktopViewLoadProgressChanged(int)));
 }
 
@@ -133,17 +133,17 @@ void WebViewAbstraction::desktopViewLoadSucceeded()
         emit loadSucceeded();
 }
 
-void WebViewAbstraction::touchViewLoadFailed(const QWebError& error)
+void WebViewAbstraction::touchViewLoadFailed(const QJSValue& error)
 {
-    m_touchViewSignalsCounter[SIGNAL(loadFailed(QWebError))]++;
-    if (m_touchViewSignalsCounter[SIGNAL(loadFailed(QWebError))] == m_desktopViewSignalsCounter[SIGNAL(loadFailed(QWebError))])
+    m_touchViewSignalsCounter[SIGNAL(loadFailed(QJSValue))]++;
+    if (m_touchViewSignalsCounter[SIGNAL(loadFailed(QJSValue))] == m_desktopViewSignalsCounter[SIGNAL(loadFailed(QJSValue))])
         emit loadFailed(error);
 }
 
-void WebViewAbstraction::desktopViewLoadFailed(const QWebError& error)
+void WebViewAbstraction::desktopViewLoadFailed(const QJSValue& error)
 {
-    m_desktopViewSignalsCounter[SIGNAL(loadFailed(QWebError))]++;
-    if (m_touchViewSignalsCounter[SIGNAL(loadFailed(QWebError))] == m_desktopViewSignalsCounter[SIGNAL(loadFailed(QWebError))])
+    m_desktopViewSignalsCounter[SIGNAL(loadFailed(QJSValue))]++;
+    if (m_touchViewSignalsCounter[SIGNAL(loadFailed(QJSValue))] == m_desktopViewSignalsCounter[SIGNAL(loadFailed(QJSValue))])
         emit loadFailed(error);
 }
 
index 57e13ae..ffe87ef 100644 (file)
@@ -46,7 +46,7 @@ public:
 Q_SIGNALS:
     void loadStarted();
     void loadSucceeded();
-    void loadFailed(const QWebError&);
+    void loadFailed(const QJSValue&);
     void loadProgressChanged(int);
 
 private Q_SLOTS:
@@ -54,8 +54,8 @@ private Q_SLOTS:
     void desktopViewLoadStarted();
     void touchViewLoadSucceeded();
     void desktopViewLoadSucceeded();
-    void touchViewLoadFailed(const QWebError&);
-    void desktopViewLoadFailed(const QWebError&);
+    void touchViewLoadFailed(const QJSValue&);
+    void desktopViewLoadFailed(const QJSValue&);
     void touchViewLoadProgressChanged(int);
     void desktopViewLoadProgressChanged(int);
 
index 18c13e5..6cedb0c 100644 (file)
 
 #include <QResizeEvent>
 #include <QScopedPointer>
-#include <QtDeclarative/qsgcanvas.h>
+#include <QtDeclarative/qsgview.h>
 #include <QtDeclarative/qsgitem.h>
 
 // TestWindow: Utility class to ignore QGraphicsView details.
-class TestWindow : public QSGCanvas {
+class TestWindow : public QSGView {
 public:
     inline TestWindow(QSGItem* webView);
     QScopedPointer<QSGItem> webView;
index fe36ae7..0ba79bb 100644 (file)
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "QtWebPageProxy.h"
 
+#include "qweberror.h"
 #include "qwkpreferences_p.h"
 
 #include "ClientImpl.h"
@@ -44,6 +45,7 @@
 #include <QAction>
 #include <QApplication>
 #include <QGraphicsSceneMouseEvent>
+#include <QJSEngine>
 #include <QStyle>
 #include <QTouchEvent>
 #include <QUndoStack>
@@ -405,7 +407,15 @@ void QtWebPageProxy::loadDidSucceed()
 
 void QtWebPageProxy::loadDidFail(const QWebError& error)
 {
-    m_viewInterface->loadDidFail(error);
+    QJSEngine* engine = m_viewInterface->engine();
+    QJSValue value;
+    if (engine) {
+        value = engine->newObject();
+        value.setProperty(QLatin1String("errorCode"), error.errorCode());
+        value.setProperty(QLatin1String("url"), error.url().toString());
+        value.setProperty(QLatin1String("type"), error.type());
+    }
+    m_viewInterface->loadDidFail(value);
 }
 
 void QtWebPageProxy::didChangeLoadProgress(int newLoadProgress)
index a6c8653..fbd6415 100644 (file)
@@ -43,6 +43,7 @@ QT_BEGIN_NAMESPACE
 class QUndoStack;
 QT_END_NAMESPACE
 
+class QWebError;
 class QWKHistory;
 class QWKPreferences;
 
index 9133701..56e4c09 100644 (file)
@@ -26,6 +26,9 @@
 #include "qtouchwebview.h"
 #include "qtouchwebview_p.h"
 
+#include <QDeclarativeEngine>
+#include <QSGView>
+
 namespace WebKit {
 
 TouchViewInterface::TouchViewInterface(QTouchWebView* viewportView, QTouchWebPage* pageView)
@@ -128,7 +131,7 @@ void TouchViewInterface::loadDidSucceed()
     emit m_pageView->loadSucceeded();
 }
 
-void TouchViewInterface::loadDidFail(const QWebError& error)
+void TouchViewInterface::loadDidFail(const QJSValue& error)
 {
     emit m_pageView->loadFailed(error);
 }
@@ -158,4 +161,12 @@ void TouchViewInterface::didRelaunchProcess()
     // FIXME
 }
 
+QJSEngine* TouchViewInterface::engine()
+{
+    QSGView* view = qobject_cast<QSGView*>(m_pageView->canvas());
+    if (view)
+        return view->engine();
+    return 0;
+}
+
 }
index 237a28d..d7baeb0 100644 (file)
@@ -66,7 +66,7 @@ private:
     virtual void loadDidBegin();
     virtual void loadDidCommit();
     virtual void loadDidSucceed();
-    virtual void loadDidFail(const QWebError&);
+    virtual void loadDidFail(const QJSValue&);
     virtual void didChangeLoadProgress(int);
 
     virtual void showContextMenu(QSharedPointer<QMenu>);
@@ -75,6 +75,8 @@ private:
     virtual void processDidCrash();
     virtual void didRelaunchProcess();
 
+    virtual QJSEngine* engine();
+
     virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList&, FileChooserType) { }
 
 private:
index a64c166..5517ca4 100644 (file)
 #include <QtGui/QMenu>
 #include <WebKit2/WKBase.h>
 
-class QWebError;
-
 QT_BEGIN_NAMESPACE
 class QCursor;
 class QGraphicsWidget;
 class QImage;
+class QJSEngine;
+class QJSValue;
 class QMimeData;
 class QPoint;
 class QRect;
@@ -75,7 +75,7 @@ public:
     virtual void loadDidBegin() = 0;
     virtual void loadDidCommit() = 0;
     virtual void loadDidSucceed() = 0;
-    virtual void loadDidFail(const QWebError&) = 0;
+    virtual void loadDidFail(const QJSValue&) = 0;
     virtual void didChangeLoadProgress(int) = 0;
 
     virtual void showContextMenu(QSharedPointer<QMenu>) = 0;
@@ -84,6 +84,8 @@ public:
     virtual void processDidCrash() = 0;
     virtual void didRelaunchProcess() = 0;
 
+    virtual QJSEngine* engine() = 0;
+
     virtual void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, FileChooserType) = 0;
 };