summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-10-02 16:23:09 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-10-22 18:03:15 +0200
commit229621361562d0e89aeb5f2d2f0ace0115bf164c (patch)
tree4bf2425711971e24a83138cd20811cecf676eb33
parentb3f9b66e6b43087873c7fc6518c0197201fd04c7 (diff)
Merge remote-tracking branch 'origin/5.13' into 5.14
Conflicts: examples/webengine/minimal/main.cpp src/3rdparty src/core/net/url_request_custom_job.cpp tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp Change-Id: I33994024a4be5ed787800c5718a0a443b970c36d Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
-rw-r--r--examples/webengine/customdialogs/main.cpp3
-rw-r--r--examples/webengine/minimal/main.cpp3
-rw-r--r--examples/webengine/quicknanobrowser/main.cpp3
-rw-r--r--examples/webengine/recipebrowser/main.cpp3
-rw-r--r--examples/webengine/webengineaction/main.cpp4
-rw-r--r--src/core/api/qtwebenginecoreglobal.cpp2
-rw-r--r--src/core/content_browser_client_qt.cpp2
-rw-r--r--src/core/net/url_request_custom_job.cpp20
-rw-r--r--src/webengine/api/qtwebengineglobal.cpp15
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp9
-rw-r--r--tests/auto/quick/dialogs/tst_dialogs.cpp5
-rw-r--r--tests/auto/quick/shared/util.h12
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp109
13 files changed, 162 insertions, 28 deletions
diff --git a/examples/webengine/customdialogs/main.cpp b/examples/webengine/customdialogs/main.cpp
index 82a3eca63..5aad8affb 100644
--- a/examples/webengine/customdialogs/main.cpp
+++ b/examples/webengine/customdialogs/main.cpp
@@ -67,9 +67,10 @@ int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("QtExamples");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- Application app(argc, argv);
QtWebEngine::initialize();
+ Application app(argc, argv);
+
QQmlApplicationEngine engine;
Server *server = new Server(&engine);
diff --git a/examples/webengine/minimal/main.cpp b/examples/webengine/minimal/main.cpp
index 8bcd0e0e9..86109f97a 100644
--- a/examples/webengine/minimal/main.cpp
+++ b/examples/webengine/minimal/main.cpp
@@ -57,9 +57,8 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationName("QtExamples");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
- QGuiApplication app(argc, argv);
-
QtWebEngine::initialize();
+ QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
diff --git a/examples/webengine/quicknanobrowser/main.cpp b/examples/webengine/quicknanobrowser/main.cpp
index 8d032f5d8..d09abba3c 100644
--- a/examples/webengine/quicknanobrowser/main.cpp
+++ b/examples/webengine/quicknanobrowser/main.cpp
@@ -80,11 +80,10 @@ int main(int argc, char **argv)
{
QCoreApplication::setOrganizationName("QtExamples");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QtWebEngine::initialize();
Application app(argc, argv);
- QtWebEngine::initialize();
-
QQmlApplicationEngine appEngine;
Utils utils;
appEngine.rootContext()->setContextProperty("utils", &utils);
diff --git a/examples/webengine/recipebrowser/main.cpp b/examples/webengine/recipebrowser/main.cpp
index 6e6d69804..e61b9e0f5 100644
--- a/examples/webengine/recipebrowser/main.cpp
+++ b/examples/webengine/recipebrowser/main.cpp
@@ -58,9 +58,10 @@ int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("QtExamples");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QGuiApplication app(argc, argv);
QtWebEngine::initialize();
+ QGuiApplication app(argc, argv);
+
QQuickStyle::setStyle(QStringLiteral("Material"));
QQmlApplicationEngine engine;
diff --git a/examples/webengine/webengineaction/main.cpp b/examples/webengine/webengineaction/main.cpp
index ce723a99b..f2dec9655 100644
--- a/examples/webengine/webengineaction/main.cpp
+++ b/examples/webengine/webengineaction/main.cpp
@@ -56,10 +56,10 @@ int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationName("QtExamples");
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QGuiApplication app(argc, argv);
-
QtWebEngine::initialize();
+ QGuiApplication app(argc, argv);
+
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp
index 0fddacb15..b27de4c23 100644
--- a/src/core/api/qtwebenginecoreglobal.cpp
+++ b/src/core/api/qtwebenginecoreglobal.cpp
@@ -108,7 +108,7 @@ Q_WEBENGINECORE_PRIVATE_EXPORT void initialize()
QCoreApplication *app = QCoreApplication::instance();
if (!app) {
- qFatal("QtWebEngine::initialize() must be called after the construction of the application object.");
+ qFatal("QtWebEngine::initialize() but no core application instance.");
return;
}
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index 6fcd9ad5b..29b6e09ed 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -252,7 +252,7 @@ void ShareGroupQtQuick::AboutToAddFirstContext()
// This currently has to be setup by ::main in all applications using QQuickWebEngineView with delegated rendering.
QOpenGLContext *shareContext = qt_gl_global_share_context();
if (!shareContext) {
- qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function.");
+ qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function before QCoreApplication is created.");
}
m_shareContextQtQuick = new QtShareGLContext(shareContext);
#endif
diff --git a/src/core/net/url_request_custom_job.cpp b/src/core/net/url_request_custom_job.cpp
index 56ba79f35..0e640766f 100644
--- a/src/core/net/url_request_custom_job.cpp
+++ b/src/core/net/url_request_custom_job.cpp
@@ -41,6 +41,7 @@
#include "url_request_custom_job_proxy.h"
#include "api/qwebengineurlscheme.h"
+
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
@@ -146,17 +147,22 @@ void URLRequestCustomJob::GetResponseInfo(HttpResponseInfo* info)
{
// Based on net::URLRequestRedirectJob::StartAsync()
- if (!m_corsEnabled)
+ if (m_error)
return;
std::string headers;
- headers += base::StringPrintf("HTTP/1.1 %i OK\n", m_httpStatusCode);
- if (m_redirect.is_valid())
+ if (m_redirect.is_valid()) {
+ headers += "HTTP/1.1 303 See Other\n";
headers += base::StringPrintf("Location: %s\n", m_redirect.spec().c_str());
- std::string origin;
- if (request_->extra_request_headers().GetHeader("Origin", &origin)) {
- headers += base::StringPrintf("Access-Control-Allow-Origin: %s\n", origin.c_str());
- headers += "Access-Control-Allow-Credentials: true\n";
+ } else {
+ headers += base::StringPrintf("HTTP/1.1 %i OK\n", m_httpStatusCode);
+ }
+ if (m_corsEnabled) {
+ std::string origin;
+ if (request_->extra_request_headers().GetHeader("Origin", &origin)) {
+ headers += base::StringPrintf("Access-Control-Allow-Origin: %s\n", origin.c_str());
+ headers += "Access-Control-Allow-Credentials: true\n";
+ }
}
info->headers = new HttpResponseHeaders(HttpUtil::AssembleRawHeaders(headers));
diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp
index a11618dba..4346832c9 100644
--- a/src/webengine/api/qtwebengineglobal.cpp
+++ b/src/webengine/api/qtwebengineglobal.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qtwebengineglobal.h"
+#include <QCoreApplication>
namespace QtWebEngineCore
{
@@ -62,8 +63,8 @@ namespace QtWebEngine {
/*!
\fn QtWebEngine::initialize()
- Sets up an OpenGL Context that can be shared between threads. This has to be done after
- QGuiApplication is created, but before a Qt Quick window is created.
+ Sets up an OpenGL Context that can be shared between threads. This has to be done before
+ QGuiApplication is created and before window's QPlatformOpenGLContext is created.
This has the same effect as setting the Qt::AA_ShareOpenGLContexts
attribute with QCoreApplication::setAttribute before constructing
@@ -71,7 +72,15 @@ namespace QtWebEngine {
*/
void initialize()
{
- QtWebEngineCore::initialize();
+ QCoreApplication *app = QCoreApplication::instance();
+ if (app) {
+ qWarning("QtWebEngine::initialize() called with QCoreApplication object already created and should be call before. "\
+ "This is depreciated and may fail in the future.");
+ QtWebEngineCore::initialize();
+ return;
+ }
+ // call initialize the same way as widgets do
+ qAddPreRoutine(QtWebEngineCore::initialize);
}
} // namespace QtWebEngine
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index db3efa521..524df0425 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -2671,16 +2671,13 @@ void QContextMenuBuilder::addMenuItem(ContextMenuItem menuItem)
switch (menuItem) {
case ContextMenuItem::Back:
- action = new QAction(QIcon::fromTheme(QStringLiteral("go-previous")), QWebEnginePage::tr("&Back"), m_menu);
- QObject::connect(action, &QAction::triggered, thisRef->d_ptr->view, &QWebEngineView::back);
+ action = thisRef->action(QWebEnginePage::Back);
break;
case ContextMenuItem::Forward:
- action = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), QWebEnginePage::tr("&Forward"), m_menu);
- QObject::connect(action, &QAction::triggered, thisRef->d_ptr->view, &QWebEngineView::forward);
+ action = thisRef->action(QWebEnginePage::Forward);
break;
case ContextMenuItem::Reload:
- action = new QAction(QIcon::fromTheme(QStringLiteral("view-refresh")), QWebEnginePage::tr("&Reload"), m_menu);
- QObject::connect(action, &QAction::triggered, thisRef->d_ptr->view, &QWebEngineView::reload);
+ action = thisRef->action(QWebEnginePage::Reload);
break;
case ContextMenuItem::Cut:
action = thisRef->action(QWebEnginePage::Cut);
diff --git a/tests/auto/quick/dialogs/tst_dialogs.cpp b/tests/auto/quick/dialogs/tst_dialogs.cpp
index eee6b2bb6..82ea3be37 100644
--- a/tests/auto/quick/dialogs/tst_dialogs.cpp
+++ b/tests/auto/quick/dialogs/tst_dialogs.cpp
@@ -28,6 +28,7 @@
#include "testhandler.h"
#include "server.h"
+#include "util.h"
#include <QtWebEngine/private/qquickwebenginedialogrequests_p.h>
#include <QtWebEngine/private/qquickwebenginecontextmenurequest_p.h>
#include <QQuickWebEngineProfile>
@@ -43,6 +44,7 @@ class tst_Dialogs : public QObject {
public:
tst_Dialogs(){}
+
private slots:
void initTestCase();
void init();
@@ -64,7 +66,6 @@ private:
void tst_Dialogs::initTestCase()
{
- QtWebEngine::initialize();
QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true);
qmlRegisterType<TestHandler>("io.qt.tester", 1, 0, "TestHandler");
m_engine.reset(new QQmlApplicationEngine());
@@ -230,5 +231,5 @@ void tst_Dialogs::javaScriptDialogRequested()
}
#include "tst_dialogs.moc"
-QTEST_MAIN(tst_Dialogs)
+W_QTEST_MAIN(tst_Dialogs)
diff --git a/tests/auto/quick/shared/util.h b/tests/auto/quick/shared/util.h
index c2e7d3e19..bc5ae445b 100644
--- a/tests/auto/quick/shared/util.h
+++ b/tests/auto/quick/shared/util.h
@@ -36,6 +36,7 @@
#include <QtTest/QtTest>
#include <QtWebEngine/private/qquickwebengineview_p.h>
#include <QtWebEngine/private/qquickwebengineloadrequest_p.h>
+#include <QGuiApplication>
#if !defined(TESTS_SOURCE_DIR)
#define TESTS_SOURCE_DIR ""
@@ -182,4 +183,15 @@ inline QString activeElementId(QQuickWebEngineView *webEngineView)
return arguments.at(1).toString();
}
+#define W_QTEST_MAIN(TestObject) \
+int main(int argc, char *argv[]) \
+{ \
+ QtWebEngine::initialize(); \
+ QGuiApplication app(argc, argv); \
+ app.setAttribute(Qt::AA_Use96Dpi, true); \
+ TestObject tc; \
+ QTEST_SET_MAIN_SOURCE_PATH \
+ return QTest::qExec(&tc, argc, argv); \
+}
#endif /* UTIL_H */
+
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 25afa5849..3e92385d0 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -40,6 +40,11 @@
#include <QtWebEngineWidgets/qwebengineview.h>
#include <QtWebEngineWidgets/qwebenginedownloaditem.h>
+#if QT_CONFIG(webengine_webchannel)
+#include <QWebChannel>
+#endif
+
+#include <map>
#include <mutex>
class tst_QWebEngineProfile : public QObject
@@ -60,6 +65,7 @@ private Q_SLOTS:
void urlSchemeHandlerStreaming();
void urlSchemeHandlerRequestHeaders();
void urlSchemeHandlerInstallation();
+ void urlSchemeHandlerXhrStatus();
void customUserAgent();
void httpAcceptLanguage();
void downloadItem();
@@ -575,6 +581,109 @@ void tst_QWebEngineProfile::urlSchemeHandlerInstallation()
profile.removeUrlScheme("tst");
}
+#if QT_CONFIG(webengine_webchannel)
+class XhrStatusHost : public QObject
+{
+ Q_OBJECT
+public:
+ std::map<QUrl, int> requests;
+
+ bool isReady()
+ {
+ static const auto sig = QMetaMethod::fromSignal(&XhrStatusHost::load);
+ return isSignalConnected(sig);
+ }
+
+Q_SIGNALS:
+ void load(QUrl url);
+
+public Q_SLOTS:
+ void loadFinished(QUrl url, int status)
+ {
+ requests[url] = status;
+ }
+
+private:
+};
+
+class XhrStatusUrlSchemeHandler : public QWebEngineUrlSchemeHandler
+{
+public:
+ void requestStarted(QWebEngineUrlRequestJob *job)
+ {
+ QString path = job->requestUrl().path();
+ if (path == "/") {
+ QBuffer *buffer = new QBuffer(job);
+ buffer->open(QBuffer::ReadWrite);
+ buffer->write(QByteArrayLiteral(R"(
+<html>
+ <body>
+ <script src="qwebchannel.js"></script>
+ <script>
+ new QWebChannel(qt.webChannelTransport, (channel) => {
+ const host = channel.objects.host;
+ host.load.connect((url) => {
+ const xhr = new XMLHttpRequest();
+ xhr.onload = () => { host.loadFinished(url, xhr.status); };
+ xhr.onerror = () => { host.loadFinished(url, -1); };
+ xhr.open("GET", url, true);
+ xhr.send();
+ });
+ });
+ </script>
+ </body>
+</html>
+)"));
+ buffer->seek(0);
+ job->reply("text/html", buffer);
+ } else if (path == "/qwebchannel.js") {
+ QFile *file = new QFile(":/qtwebchannel/qwebchannel.js", job);
+ file->open(QFile::ReadOnly);
+ job->reply("application/javascript", file);
+ } else if (path == "/ok") {
+ QBuffer *buffer = new QBuffer(job);
+ buffer->buffer() = QByteArrayLiteral("ok");
+ job->reply("text/plain", buffer);
+ } else if (path == "/redirect") {
+ QUrl url = job->requestUrl();
+ url.setPath("/ok");
+ job->redirect(url);
+ } else if (path == "/fail") {
+ job->fail(QWebEngineUrlRequestJob::RequestFailed);
+ } else {
+ job->fail(QWebEngineUrlRequestJob::UrlNotFound);
+ }
+ }
+};
+#endif
+
+void tst_QWebEngineProfile::urlSchemeHandlerXhrStatus()
+{
+#if QT_CONFIG(webengine_webchannel)
+ XhrStatusUrlSchemeHandler handler;
+ XhrStatusHost host;
+ QWebEngineProfile profile;
+ QWebEnginePage page(&profile);
+ QWebChannel channel;
+ channel.registerObject("host", &host);
+ profile.installUrlSchemeHandler("aviancarrier", &handler);
+ page.setWebChannel(&channel);
+ page.load(QUrl("aviancarrier:/"));
+ QTRY_VERIFY(host.isReady());
+ host.load(QUrl("aviancarrier:/ok"));
+ host.load(QUrl("aviancarrier:/redirect"));
+ host.load(QUrl("aviancarrier:/fail"));
+ host.load(QUrl("aviancarrier:/notfound"));
+ QTRY_COMPARE(host.requests.size(), 4u);
+ QCOMPARE(host.requests[QUrl("aviancarrier:/ok")], 200);
+ QCOMPARE(host.requests[QUrl("aviancarrier:/redirect")], 200);
+ QCOMPARE(host.requests[QUrl("aviancarrier:/fail")], -1);
+ QCOMPARE(host.requests[QUrl("aviancarrier:/notfound")], -1);
+#else
+ QSKIP("No QtWebChannel");
+#endif
+}
+
void tst_QWebEngineProfile::customUserAgent()
{
QString defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();