diff options
author | Christian Strømme <[email protected]> | 2015-01-26 18:26:51 +0100 |
---|---|---|
committer | Christian Stromme <[email protected]> | 2015-02-10 12:20:20 +0000 |
commit | 083323c8b7c37092fedcec4fd34f568c4a674c03 (patch) | |
tree | 530fdea8e737cb0aef3b29490647991e8f0c78d8 | |
parent | e59d6a79fd5cd208fece67f79e544807bd2d72f9 (diff) |
Add loadRequest item and necessary classes to enable status reporting.
This makes it possible to listen and check the load status through the
loadingChanges signal. The new loadRequest type contains information
about the load status (started, succeeded or failed) for a specific url
and an error string if available.
[ChangeLog][WebView] Improved status reporting through a new
loadRequest item.
Task-number: QTBUG-43767
Change-Id: I65ffb91524b2e0d57875d6728b0558087d91cc0f
Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
-rw-r--r-- | src/imports/plugins.qmltypes | 14 | ||||
-rw-r--r-- | src/imports/webview.cpp | 3 | ||||
-rw-r--r-- | src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java | 12 | ||||
-rw-r--r-- | src/webview/qquickwebview.cpp | 10 | ||||
-rw-r--r-- | src/webview/qquickwebview.h | 14 | ||||
-rw-r--r-- | src/webview/qquickwebviewloadrequest.cpp | 103 | ||||
-rw-r--r-- | src/webview/qquickwebviewloadrequest.h | 71 | ||||
-rw-r--r-- | src/webview/qwebview.cpp | 2 | ||||
-rw-r--r-- | src/webview/qwebview_android.cpp | 38 | ||||
-rw-r--r-- | src/webview/qwebview_ios.mm | 20 | ||||
-rw-r--r-- | src/webview/qwebview_p.h | 11 | ||||
-rw-r--r-- | src/webview/qwebview_p_p.h | 3 | ||||
-rw-r--r-- | src/webview/qwebviewloadrequest.cpp | 61 | ||||
-rw-r--r-- | src/webview/qwebviewloadrequest_p.h | 65 | ||||
-rw-r--r-- | src/webview/webview-lib.pri | 8 | ||||
-rw-r--r-- | tests/auto/webview/qwebview/tst_qwebview.cpp | 58 |
16 files changed, 476 insertions, 17 deletions
diff --git a/src/imports/plugins.qmltypes b/src/imports/plugins.qmltypes index 3532199..896d803 100644 --- a/src/imports/plugins.qmltypes +++ b/src/imports/plugins.qmltypes @@ -5,6 +5,16 @@ import QtQuick.tooling 1.1 Module { Component { + name: "QQuickWebViewLoadRequest" + prototype: "QObject" + exports: ["QtWebView/WebViewLoadRequest 1.0"] + isCreatable: false + exportMetaObjectRevisions: [0] + Property { name: "url"; type: "QUrl"; isReadonly: true } + Property { name: "status"; type: "QQuickWebView::LoadStatus"; isReadonly: true } + Property { name: "errorString"; type: "string"; isReadonly: true } + } + Component { name: "QWebView" defaultProperty: "data" prototype: "QQuickItem" @@ -20,6 +30,10 @@ Module { Method { name: "goForward" } Method { name: "reload" } Method { name: "stop" } + Signal { + name: "loadingChanged" + Parameter { name: "loadRequest"; type: "QQuickWebViewLoadRequest"; isPointer: true } + } Method { name: "loadHtml" Parameter { name: "html"; type: "string" } diff --git a/src/imports/webview.cpp b/src/imports/webview.cpp index 72396f2..7ceb3fe 100644 --- a/src/imports/webview.cpp +++ b/src/imports/webview.cpp @@ -38,6 +38,7 @@ #include <QtQml/qqml.h> #include <QtWebView/qquickwebview.h> +#include <QtWebView/qquickwebviewloadrequest.h> QT_BEGIN_NAMESPACE @@ -52,6 +53,8 @@ public: // @uri QtWebView qmlRegisterType<QQuickWebView>(uri, 1, 0, "WebView"); + const QString &msg = QObject::tr("Cannot create separate instance of WebViewLoadRequest"); + qmlRegisterUncreatableType<QQuickWebViewLoadRequest>(uri, 1, 0, "WebViewLoadRequest", msg); } void initializeEngine(QQmlEngine *engine, const char *uri) diff --git a/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java index dde2fff..13fbd77 100644 --- a/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java +++ b/src/jar/src/org/qtproject/qt5/android/view/QtAndroidWebViewController.java @@ -76,6 +76,7 @@ public class QtAndroidWebViewController private native void c_onReceivedIcon(long id, Bitmap icon); private native void c_onReceivedTitle(long id, String title); private native void c_onRunJavaScriptResult(long id, long callbackId, String result); + private native void c_onReceivedError(long id, int errorCode, String description, String url); private void resetLoadingState() { @@ -113,6 +114,17 @@ public class QtAndroidWebViewController c_onPageStarted(m_id, url, favicon); } } + + @Override + public void onReceivedError(WebView view, + int errorCode, + String description, + String url) + { + super.onReceivedError(view, errorCode, description, url); + resetLoadingState(); + c_onReceivedError(m_id, errorCode, description, url); + } } private class QtAndroidWebChromeClient extends WebChromeClient diff --git a/src/webview/qquickwebview.cpp b/src/webview/qquickwebview.cpp index d825d2f..cc48489 100644 --- a/src/webview/qquickwebview.cpp +++ b/src/webview/qquickwebview.cpp @@ -35,6 +35,8 @@ ****************************************************************************/ #include "qquickwebview.h" +#include "qquickwebviewloadrequest.h" +#include <QtWebView/private/qwebviewloadrequest_p.h> #include <QtQml/qqmlengine.h> #include <QtCore/qmutex.h> @@ -93,8 +95,8 @@ QQuickWebView::QQuickWebView(QQuickItem *parent) setView(m_webView.data()); connect(m_webView.data(), &QWebView::titleChanged, this, &QQuickWebView::titleChanged); connect(m_webView.data(), &QWebView::urlChanged, this, &QQuickWebView::urlChanged); - connect(m_webView.data(), &QWebView::loadingChanged, this, &QQuickWebView::loadingChanged); connect(m_webView.data(), &QWebView::loadProgressChanged, this, &QQuickWebView::loadProgressChanged); + connect(m_webView.data(), &QWebView::loadingChanged, this, &QQuickWebView::onLoadingChanged); connect(m_webView.data(), &QWebView::requestFocus, this, &QQuickWebView::onFocusRequest); connect(m_webView.data(), &QWebView::javaScriptResult, this, &QQuickWebView::onRunJavaScriptResult); } @@ -285,3 +287,9 @@ void QQuickWebView::onFocusRequest(bool focus) { setFocus(focus); } + +void QQuickWebView::onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest) +{ + QQuickWebViewLoadRequest qqLoadRequest(loadRequest); + Q_EMIT loadingChanged(&qqLoadRequest); +} diff --git a/src/webview/qquickwebview.h b/src/webview/qquickwebview.h index 8b2207a..004fe10 100644 --- a/src/webview/qquickwebview.h +++ b/src/webview/qquickwebview.h @@ -57,6 +57,9 @@ QT_BEGIN_NAMESPACE +class QQuickWebViewLoadRequest; +class QWebViewLoadRequestPrivate; + class Q_WEBVIEW_EXPORT QQuickWebView : public QQuickViewController, public QWebViewInterface { Q_OBJECT @@ -66,8 +69,16 @@ class Q_WEBVIEW_EXPORT QQuickWebView : public QQuickViewController, public QWebV Q_PROPERTY(QString title READ title NOTIFY titleChanged) Q_PROPERTY(bool canGoBack READ canGoBack NOTIFY loadingChanged) Q_PROPERTY(bool canGoForward READ canGoForward NOTIFY loadingChanged) + Q_ENUMS(LoadStatus) public: + enum LoadStatus { // Changes here needs to be done in QWebView as well + LoadStartedStatus, + LoadStoppedStatus, + LoadSucceededStatus, + LoadFailedStatus + }; + QQuickWebView(QQuickItem *parent = 0); ~QQuickWebView(); @@ -91,7 +102,7 @@ public Q_SLOTS: Q_SIGNALS: void titleChanged(); void urlChanged(); - void loadingChanged(); + void loadingChanged(QQuickWebViewLoadRequest *loadRequest); void loadProgressChanged(); protected: @@ -101,6 +112,7 @@ protected: private Q_SLOTS: void onRunJavaScriptResult(int id, const QVariant &variant); void onFocusRequest(bool focus); + void onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest); private: QScopedPointer<QWebView> m_webView; diff --git a/src/webview/qquickwebviewloadrequest.cpp b/src/webview/qquickwebviewloadrequest.cpp new file mode 100644 index 0000000..e1dd64d --- /dev/null +++ b/src/webview/qquickwebviewloadrequest.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qquickwebviewloadrequest.h" +#include <QtWebView/private/qwebviewloadrequest_p.h> + +QT_BEGIN_NAMESPACE + +/*! + \qmltype WebViewLoadRequest + \instantiates QQuickWebViewLoadRequest + \inqmlmodule QtWebView + + \brief A utility class for the QtWebView::WebView::loadingChanged signal. + + This class contains load status information for the requested URL. + + \sa QtWebView::WebView::loadingChanged +*/ +QQuickWebViewLoadRequest::QQuickWebViewLoadRequest(const QWebViewLoadRequestPrivate &d) + : d_ptr(new QWebViewLoadRequestPrivate(d)) +{ + +} + +QQuickWebViewLoadRequest::~QQuickWebViewLoadRequest() +{ + +} + +/*! + \qmlproperty url QtWebView::WebView::WebViewLoadRequest::url + + The URL of the load request. + */ +QUrl QQuickWebViewLoadRequest::url() const +{ + Q_D(const QWebViewLoadRequest); + return d->m_url; +} + +/*! + \qmlproperty enumeration WebViewLoadRequest::status + + This enumeration represents the load status of a web page load request. + + \value QtWebView::WebView::LoadStartedStatus The page is currently loading. + \value QtWebView::WebView::LoadSucceededStatus The page was loaded successfully. + \value QtWebView::WebView::LoadFailedStatus The page could not be loaded. + + \sa QtWebView::WebView::loadingChanged +*/ +QQuickWebView::LoadStatus QQuickWebViewLoadRequest::status() const +{ + Q_D(const QWebViewLoadRequest); + return QQuickWebView::LoadStatus(d->m_status); +} + +/*! + \qmlproperty string QtWebView::WebView::WebViewLoadRequest::errorString + + Holds the error message if the load request fails. +*/ +QString QQuickWebViewLoadRequest::errorString() const +{ + Q_D(const QWebViewLoadRequest); + return d->m_errorString; +} + +QT_END_NAMESPACE diff --git a/src/webview/qquickwebviewloadrequest.h b/src/webview/qquickwebviewloadrequest.h new file mode 100644 index 0000000..7659de2 --- /dev/null +++ b/src/webview/qquickwebviewloadrequest.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBVIEWREQUEST_H +#define QQUICKWEBVIEWREQUEST_H + +#include "qquickwebview.h" +#include <QtWebView/qwebview_global.h> +#include <QObject> + +QT_BEGIN_NAMESPACE + +class QWebViewLoadRequestPrivate; + +class Q_WEBVIEW_EXPORT QQuickWebViewLoadRequest : public QObject +{ + Q_OBJECT + Q_PROPERTY(QUrl url READ url) + Q_PROPERTY(QQuickWebView::LoadStatus status READ status) + Q_PROPERTY(QString errorString READ errorString) + +public: + ~QQuickWebViewLoadRequest(); + + QUrl url() const; + QQuickWebView::LoadStatus status() const; + QString errorString() const; + +private: + friend class QQuickWebView; + explicit QQuickWebViewLoadRequest(const QWebViewLoadRequestPrivate &d); + Q_DECLARE_PRIVATE(QWebViewLoadRequest) + QScopedPointer<QWebViewLoadRequestPrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#endif // QQUICKWEBVIEWREQUEST_H diff --git a/src/webview/qwebview.cpp b/src/webview/qwebview.cpp index 92090ab..04e8b15 100644 --- a/src/webview/qwebview.cpp +++ b/src/webview/qwebview.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include "qwebview_p.h" +#include <QtWebView/private/qwebviewloadrequest_p.h> QT_BEGIN_NAMESPACE @@ -42,6 +43,7 @@ QWebView::QWebView(QObject *p) : QObject(p), d_ptr(QWebViewPrivate::create(this)) { + qRegisterMetaType<QWebViewLoadRequestPrivate>(); Q_D(QWebView); connect(d, &QWebViewPrivate::titleChanged, this, &QWebView::titleChanged); connect(d, &QWebViewPrivate::urlChanged, this, &QWebView::urlChanged); diff --git a/src/webview/qwebview_android.cpp b/src/webview/qwebview_android.cpp index 22c7f75..a471d6a 100644 --- a/src/webview/qwebview_android.cpp +++ b/src/webview/qwebview_android.cpp @@ -36,6 +36,7 @@ #include "qwebview_android_p.h" #include "qwebview_p.h" +#include "qwebviewloadrequest_p.h" // TODO: #include <QtCore/private/qjnihelpers_p.h> #include <QtCore/private/qjni_p.h> @@ -277,8 +278,10 @@ static void c_onPageFinished(JNIEnv *env, if (!wc) return; - Q_UNUSED(url) // TODO: - Q_EMIT wc->loadingChanged(); + QWebViewLoadRequestPrivate loadRequest(QUrl(QJNIObjectPrivate(url).toString()), + QWebView::LoadSucceededStatus, + QString()); + Q_EMIT wc->loadingChanged(loadRequest); } static void c_onPageStarted(JNIEnv *env, @@ -294,9 +297,10 @@ static void c_onPageStarted(JNIEnv *env, QAndroidWebViewPrivate *wc = wv[id]; if (!wc) return; - - Q_UNUSED(url) // TODO: - Q_EMIT wc->loadingChanged(); + QWebViewLoadRequestPrivate loadRequest(QUrl(QJNIObjectPrivate(url).toString()), + QWebView::LoadStartedStatus, + QString()); + Q_EMIT wc->loadingChanged(loadRequest); // if (!icon) // return; @@ -361,6 +365,27 @@ static void c_onReceivedTitle(JNIEnv *env, Q_EMIT wc->titleChanged(); } +static void c_onReceivedError(JNIEnv *env, + jobject thiz, + jlong id, + jint errorCode, + jstring description, + jstring url) +{ + Q_UNUSED(env) + Q_UNUSED(thiz) + Q_UNUSED(errorCode) + + const WebViews &wv = (*g_webViews); + QAndroidWebViewPrivate *wc = wv[id]; + if (!wc) + return; + QWebViewLoadRequestPrivate loadRequest(QUrl(QJNIObjectPrivate(url).toString()), + QWebView::LoadFailedStatus, + QJNIObjectPrivate(description).toString()); + Q_EMIT wc->loadingChanged(loadRequest); +} + JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) { typedef union { @@ -386,7 +411,8 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/) {"c_onProgressChanged", "(JI)V", reinterpret_cast<void *>(c_onProgressChanged)}, {"c_onReceivedIcon", "(JLandroid/graphics/Bitmap;)V", reinterpret_cast<void *>(c_onReceivedIcon)}, {"c_onReceivedTitle", "(JLjava/lang/String;)V", reinterpret_cast<void *>(c_onReceivedTitle)}, - {"c_onRunJavaScriptResult", "(JJLjava/lang/String;)V", reinterpret_cast<void *>(c_onRunJavaScriptResult)} + {"c_onRunJavaScriptResult", "(JJLjava/lang/String;)V", reinterpret_cast<void *>(c_onRunJavaScriptResult)}, + {"c_onReceivedError", "(JILjava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void *>(c_onReceivedError)} }; const int nMethods = sizeof(methods) / sizeof(methods[0]); diff --git a/src/webview/qwebview_ios.mm b/src/webview/qwebview_ios.mm index c2c09c9..a550de2 100644 --- a/src/webview/qwebview_ios.mm +++ b/src/webview/qwebview_ios.mm @@ -36,6 +36,7 @@ #include "qwebview_ios_p.h" #include "qwebview_p.h" +#include "qwebviewloadrequest_p.h" #include <QtQuick/qquickitem.h> #include <QtCore/qmap.h> @@ -136,7 +137,6 @@ class QWebViewInterface; - (void)pageDone { Q_EMIT qIosWebViewPrivate->loadProgressChanged(); - Q_EMIT qIosWebViewPrivate->loadingChanged(); Q_EMIT qIosWebViewPrivate->titleChanged(); Q_EMIT qIosWebViewPrivate->urlChanged(); } @@ -148,23 +148,33 @@ class QWebViewInterface; // should provide per-page notifications. Keep track of started frame loads // and emit notifications when the final frame completes. ++qIosWebViewPrivate->requestFrameCount; - Q_EMIT qIosWebViewPrivate->loadingChanged(); + Q_EMIT qIosWebViewPrivate->loadingChanged(QWebViewLoadRequestPrivate(qIosWebViewPrivate->url(), + QWebView::LoadStartedStatus, + QString())); Q_EMIT qIosWebViewPrivate->loadProgressChanged(); } - (void)webViewDidFinishLoad:(UIWebView *)webView { Q_UNUSED(webView); - if (--qIosWebViewPrivate->requestFrameCount == 0) + if (--qIosWebViewPrivate->requestFrameCount == 0) { [self pageDone]; + Q_EMIT qIosWebViewPrivate->loadingChanged(QWebViewLoadRequestPrivate(qIosWebViewPrivate->url(), + QWebView::LoadSucceededStatus, + QString())); + } } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { Q_UNUSED(webView); - Q_UNUSED(error); - if (--qIosWebViewPrivate->requestFrameCount == 0) + if (--qIosWebViewPrivate->requestFrameCount == 0) { [self pageDone]; + NSString *errorString = [error localizedFailureReason]; + Q_EMIT qIosWebViewPrivate->loadingChanged(QWebViewLoadRequestPrivate(qIosWebViewPrivate->url(), + QWebView::LoadFailedStatus, + QString::fromNSString(errorString))); + } } @end diff --git a/src/webview/qwebview_p.h b/src/webview/qwebview_p.h index 7ecacd8..8be3ae5 100644 --- a/src/webview/qwebview_p.h +++ b/src/webview/qwebview_p.h @@ -58,6 +58,8 @@ QT_BEGIN_NAMESPACE +class QWebViewLoadRequestPrivate; + class Q_WEBVIEW_EXPORT QWebView : public QObject , public QWebViewInterface @@ -65,6 +67,13 @@ class Q_WEBVIEW_EXPORT QWebView { Q_OBJECT public: + enum LoadStatus { // Changes here needs to be done in QQuickWebView as well + LoadStartedStatus, + LoadStoppedStatus, + LoadSucceededStatus, + LoadFailedStatus + }; + explicit QWebView(QObject *p = 0); ~QWebView() Q_DECL_OVERRIDE; @@ -92,7 +101,7 @@ public Q_SLOTS: Q_SIGNALS: void titleChanged(); void urlChanged(); - void loadingChanged(); + void loadingChanged(const QWebViewLoadRequestPrivate &loadRequest); void loadProgressChanged(); void javaScriptResult(int id, const QVariant &result); void requestFocus(bool focus); diff --git a/src/webview/qwebview_p_p.h b/src/webview/qwebview_p_p.h index e0b8431..e0bb3b2 100644 --- a/src/webview/qwebview_p_p.h +++ b/src/webview/qwebview_p_p.h @@ -43,6 +43,7 @@ QT_BEGIN_NAMESPACE class QWebView; +class QWebViewLoadRequestPrivate; class Q_WEBVIEW_EXPORT QWebViewPrivate : public QObject @@ -56,7 +57,7 @@ public: Q_SIGNALS: void titleChanged(); void urlChanged(); - void loadingChanged(); + void loadingChanged(const QWebViewLoadRequestPrivate &loadRequest); void loadProgressChanged(); void javaScriptResult(int id, const QVariant &result); void requestFocus(bool focus); diff --git a/src/webview/qwebviewloadrequest.cpp b/src/webview/qwebviewloadrequest.cpp new file mode 100644 index 0000000..3ab205c --- /dev/null +++ b/src/webview/qwebviewloadrequest.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWebView/private/qwebviewloadrequest_p.h> + +QT_BEGIN_NAMESPACE + +QWebViewLoadRequestPrivate::QWebViewLoadRequestPrivate() +{ + +} + +QWebViewLoadRequestPrivate::QWebViewLoadRequestPrivate(const QUrl &url, + QWebView::LoadStatus status, + const QString &errorString) + : m_url(url) + , m_status(status) + , m_errorString(errorString) +{ + +} + +QWebViewLoadRequestPrivate::~QWebViewLoadRequestPrivate() +{ + +} + +QT_END_NAMESPACE diff --git a/src/webview/qwebviewloadrequest_p.h b/src/webview/qwebviewloadrequest_p.h new file mode 100644 index 0000000..d0874ca --- /dev/null +++ b/src/webview/qwebviewloadrequest_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWebView module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms and +** conditions see http://www.qt.io/terms-conditions. For further information +** use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QWEBVIEWLOADREQUESTPRIVATE_H +#define QWEBVIEWLOADREQUESTPRIVATE_H + +#include <QtWebView/private/qwebview_p.h> +#include <QtCore/qstring.h> +#include <QtCore/qurl.h> + +QT_BEGIN_NAMESPACE + +class Q_WEBVIEW_EXPORT QWebViewLoadRequestPrivate +{ +public: + QWebViewLoadRequestPrivate(); + QWebViewLoadRequestPrivate(const QUrl &url, + QWebView::LoadStatus status, + const QString &errorString); + ~QWebViewLoadRequestPrivate(); + + QUrl m_url; + QWebView::LoadStatus m_status; + QString m_errorString; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QWebViewLoadRequestPrivate) + +#endif // QWEBVIEWLOADREQUESTPRIVATE_H diff --git a/src/webview/webview-lib.pri b/src/webview/webview-lib.pri index 653e2e9..64753cd 100644 --- a/src/webview/webview-lib.pri +++ b/src/webview/webview-lib.pri @@ -14,12 +14,16 @@ COMMON_HEADERS += \ qquickwebview.h \ qnativeviewcontroller_p.h \ qwebview_p_p.h \ - qquickviewcontroller_p.h + qquickviewcontroller_p.h \ + qwebviewloadrequest_p.h \ + qquickwebviewloadrequest.h COMMON_SOURCES += \ qwebview.cpp \ qquickwebview.cpp \ - qquickviewcontroller.cpp + qquickviewcontroller.cpp \ + qquickwebviewloadrequest.cpp \ + qwebviewloadrequest.cpp android { QT += core-private diff --git a/tests/auto/webview/qwebview/tst_qwebview.cpp b/tests/auto/webview/qwebview/tst_qwebview.cpp index bde8545..c646339 100644 --- a/tests/auto/webview/qwebview/tst_qwebview.cpp +++ b/tests/auto/webview/qwebview/tst_qwebview.cpp @@ -41,6 +41,7 @@ #include <QtCore/qfileinfo.h> #include <QtWebView/private/qwebview_p.h> #include <QtQml/qqmlengine.h> +#include <QtWebView/private/qwebviewloadrequest_p.h> #ifndef QT_NO_QQUICKWEBVIEW_TESTS #include <QtWebView/qquickwebview.h> @@ -61,6 +62,7 @@ private slots: void load(); void runJavaScript(); void loadHtml(); + void loadRequest(); private: const QString m_cacheLocation; @@ -134,6 +136,62 @@ void tst_QWebView::loadHtml() QCOMPARE(view.title(), QStringLiteral("WebViewTitle")); } +void tst_QWebView::loadRequest() +{ + // LoadSucceeded + { + QTemporaryFile file(m_cacheLocation + QStringLiteral("/XXXXXXfile.html")); + QVERIFY2(file.open(), + qPrintable(QStringLiteral("Cannot create temporary file:") + file.errorString())); + + file.write("<html><head><title>FooBar</title></head><body />"); + const QString fileName = file.fileName(); + file.close(); + QWebView view; + QCOMPARE(view.loadProgress(), 0); + const QUrl url = QUrl::fromLocalFile(fileName); + QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(const QWebViewLoadRequestPrivate &))); + view.setUrl(url); + QTRY_VERIFY(!view.isLoading()); + QTRY_COMPARE(view.loadProgress(), 100); + QTRY_COMPARE(view.title(), QStringLiteral("FooBar")); + QCOMPARE(view.url(), url); + QTRY_COMPARE(loadChangedSingalSpy.count(), 2); + { + const QList<QVariant> &loadStartedArgs = loadChangedSingalSpy.takeFirst(); + const QWebViewLoadRequestPrivate &lr = loadStartedArgs.at(0).value<QWebViewLoadRequestPrivate>(); + QCOMPARE(lr.m_status, QWebView::LoadStartedStatus); + } + { + const QList<QVariant> &loadStartedArgs = loadChangedSingalSpy.takeFirst(); + const QWebViewLoadRequestPrivate &lr = loadStartedArgs.at(0).value<QWebViewLoadRequestPrivate>(); + QCOMPARE(lr.m_status, QWebView::LoadSucceededStatus); + } + } + + // LoadFailed + { + QWebView view; + QCOMPARE(view.loadProgress(), 0); + QSignalSpy loadChangedSingalSpy(&view, SIGNAL(loadingChanged(const QWebViewLoadRequestPrivate &))); + view.setUrl(QUrl(QStringLiteral("file:///file_that_does_not_exist.html"))); + QTRY_VERIFY(!view.isLoading()); + QTRY_COMPARE(loadChangedSingalSpy.count(), 2); + { + const QList<QVariant> &loadStartedArgs = loadChangedSingalSpy.takeFirst(); + const QWebViewLoadRequestPrivate &lr = loadStartedArgs.at(0).value<QWebViewLoadRequestPrivate>(); + QCOMPARE(lr.m_status, QWebView::LoadStartedStatus); + } + { + const QList<QVariant> &loadStartedArgs = loadChangedSingalSpy.takeFirst(); + const QWebViewLoadRequestPrivate &lr = loadStartedArgs.at(0).value<QWebViewLoadRequestPrivate>(); + QCOMPARE(lr.m_status, QWebView::LoadFailedStatus); + } + + QCOMPARE(view.loadProgress(), 0); + } +} + QTEST_MAIN(tst_QWebView) #include "tst_qwebview.moc" |