summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2016-11-10 17:10:20 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2016-11-11 13:39:59 +0000
commite83c722db43351329e451e84420a6b69591bc076 (patch)
tree1bac6d506b8e87fdf269a548c19a2bbbed608c26
parentc27374541e289962df6947967b97178bfa63e9f7 (diff)
Make view source working with qrc URLs
Task-number: QTBUG-56353 Change-Id: I9c5dc3a6ba4e6b08ecbb4e44d38a53d24010807b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/content_browser_client_qt.cpp6
-rw-r--r--src/core/content_browser_client_qt.h1
-rw-r--r--src/core/qrc_protocol_handler_qt.cpp2
-rw-r--r--src/core/qrc_protocol_handler_qt.h2
-rw-r--r--src/core/url_request_context_getter_qt.cpp2
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp27
6 files changed, 28 insertions, 12 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index c3800e9ff..787586540 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -85,6 +85,7 @@
#if defined(ENABLE_BASIC_PRINTING)
#include "printing_message_filter_qt.h"
#endif // defined(ENABLE_BASIC_PRINTING)
+#include "qrc_protocol_handler_qt.h"
#include "renderer_host/resource_dispatcher_host_delegate_qt.h"
#include "renderer_host/user_resource_controller_host.h"
#include "web_contents_delegate_qt.h"
@@ -507,6 +508,11 @@ void ContentBrowserClientQt::AppendExtraCommandLineSwitches(base::CommandLine* c
command_line->AppendSwitchASCII(switches::kLang, GetApplicationLocale());
}
+void ContentBrowserClientQt::GetAdditionalWebUISchemes(std::vector<std::string>* additional_schemes)
+{
+ additional_schemes->push_back(kQrcSchemeQt);
+}
+
#if defined(Q_OS_LINUX)
void ContentBrowserClientQt::GetAdditionalMappedFilesForChildProcess(const base::CommandLine& command_line, int child_process_id, content::FileDescriptorInfo* mappings)
{
diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h
index 47b880643..a13d14ff2 100644
--- a/src/core/content_browser_client_qt.h
+++ b/src/core/content_browser_client_qt.h
@@ -108,6 +108,7 @@ public:
virtual std::string GetApplicationLocale() Q_DECL_OVERRIDE;
std::string GetAcceptLangs(content::BrowserContext* context) Q_DECL_OVERRIDE;
virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line, int child_process_id) Q_DECL_OVERRIDE;
+ virtual void GetAdditionalWebUISchemes(std::vector<std::string>* additional_schemes) Q_DECL_OVERRIDE;
#if defined(Q_OS_LINUX)
virtual void GetAdditionalMappedFilesForChildProcess(const base::CommandLine& command_line, int child_process_id, content::FileDescriptorInfo* mappings) Q_DECL_OVERRIDE;
diff --git a/src/core/qrc_protocol_handler_qt.cpp b/src/core/qrc_protocol_handler_qt.cpp
index 222961762..eb716f182 100644
--- a/src/core/qrc_protocol_handler_qt.cpp
+++ b/src/core/qrc_protocol_handler_qt.cpp
@@ -46,6 +46,8 @@
namespace QtWebEngineCore {
+const char kQrcSchemeQt[] = "qrc";
+
QrcProtocolHandlerQt::QrcProtocolHandlerQt()
{
}
diff --git a/src/core/qrc_protocol_handler_qt.h b/src/core/qrc_protocol_handler_qt.h
index 53d063810..a2e0cc00b 100644
--- a/src/core/qrc_protocol_handler_qt.h
+++ b/src/core/qrc_protocol_handler_qt.h
@@ -53,6 +53,8 @@ class URLRequestJob;
namespace QtWebEngineCore {
+extern const char kQrcSchemeQt[];
+
// Implements a ProtocolHandler for qrc file jobs. If |network_delegate_| is NULL,
// then all file requests will fail with ERR_ACCESS_DENIED.
class QrcProtocolHandlerQt : public net::URLRequestJobFactory::ProtocolHandler {
diff --git a/src/core/url_request_context_getter_qt.cpp b/src/core/url_request_context_getter_qt.cpp
index 61f359a87..bf4661102 100644
--- a/src/core/url_request_context_getter_qt.cpp
+++ b/src/core/url_request_context_getter_qt.cpp
@@ -91,8 +91,6 @@
namespace QtWebEngineCore {
-static const char kQrcSchemeQt[] = "qrc";
-
using content::BrowserThread;
URLRequestContextGetterQt::URLRequestContextGetterQt(QSharedPointer<BrowserContextAdapter> browserContext, content::ProtocolHandlerMap *protocolHandlers, content::URLRequestInterceptorScopedVector request_interceptors)
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 166c5a499..99905a712 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -4992,6 +4992,8 @@ void tst_QWebEnginePage::viewSource()
QCOMPARE(page.createdWindows.size(), 1);
QTRY_COMPARE(page.createdWindows[0]->url().toString(), QStringLiteral("view-source:%1").arg(url.toString()));
+ // The requested URL should not be about:blank if the qrc scheme is supported
+ QTRY_COMPARE(page.createdWindows[0]->requestedUrl(), url);
QTRY_COMPARE(page.createdWindows[0]->title(), QStringLiteral("view-source:%1").arg(url.toString()));
QVERIFY(!page.createdWindows[0]->action(QWebEnginePage::ViewSource)->isEnabled());
}
@@ -5001,21 +5003,24 @@ void tst_QWebEnginePage::viewSourceURL_data()
QTest::addColumn<QUrl>("userInputUrl");
QTest::addColumn<bool>("loadSucceed");
QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QUrl>("requestedUrl");
QTest::addColumn<QString>("title");
- QTest::newRow("view-source:") << QUrl("view-source:") << true << QUrl("view-source:") << QString("view-source:");
- QTest::newRow("view-source:about:blank") << QUrl("view-source:about:blank") << true << QUrl("view-source:about:blank") << QString("view-source:about:blank");
+ QTest::newRow("view-source:") << QUrl("view-source:") << true << QUrl("view-source:") << QUrl("about:blank") << QString("view-source:");
+ QTest::newRow("view-source:about:blank") << QUrl("view-source:about:blank") << true << QUrl("view-source:about:blank") << QUrl("about:blank") << QString("view-source:about:blank");
- QUrl testLocalUrl = QUrl(QString("view-source:%1").arg(QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebenginepage/resources/test1.html")).toString()));
- QUrl testLocalUrlWithoutScheme = QUrl(QString("view-source:%1").arg(TESTS_SOURCE_DIR + QLatin1String("qwebenginepage/resources/test1.html")));
- QTest::newRow(testLocalUrl.toString().toStdString().c_str()) << testLocalUrl << true << testLocalUrl << QString("test1.html");
- QTest::newRow(testLocalUrlWithoutScheme.toString().toStdString().c_str()) << testLocalUrlWithoutScheme << true << testLocalUrl << QString("test1.html");
+ QString localFilePath = QString("%1qwebenginepage/resources/test1.html").arg(TESTS_SOURCE_DIR);
+ QUrl testLocalUrl = QUrl(QString("view-source:%1").arg(QUrl::fromLocalFile(localFilePath).toString()));
+ QUrl testLocalUrlWithoutScheme = QUrl(QString("view-source:%1").arg(localFilePath));
+ QTest::newRow(testLocalUrl.toString().toStdString().c_str()) << testLocalUrl << true << testLocalUrl << QUrl::fromLocalFile(localFilePath) << QString("test1.html");
+ QTest::newRow(testLocalUrlWithoutScheme.toString().toStdString().c_str()) << testLocalUrlWithoutScheme << true << testLocalUrl << QUrl::fromLocalFile(localFilePath) << QString("test1.html");
- QUrl testResourceUrl = QUrl("view-source:qrc:/resources/test1.html");
- QTest::newRow(testResourceUrl.toString().toStdString().c_str()) << testResourceUrl << true << testResourceUrl << testResourceUrl.toString();
+ QString resourcePath = QLatin1String("qrc:/resources/test1.html");
+ QUrl testResourceUrl = QUrl(QString("view-source:%1").arg(resourcePath));
+ QTest::newRow(testResourceUrl.toString().toStdString().c_str()) << testResourceUrl << true << testResourceUrl << QUrl(resourcePath) << testResourceUrl.toString();
- QTest::newRow("view-source:http://non.existent") << QUrl("view-source:non.existent") << false << QUrl("view-source:http://non.existent/") << QString("http://non.existent/ is not available");
- QTest::newRow("view-source:non.existent") << QUrl("view-source:non.existent") << false << QUrl("view-source:http://non.existent/") << QString("http://non.existent/ is not available");
+ QTest::newRow("view-source:http://non.existent") << QUrl("view-source:non.existent") << false << QUrl("view-source:http://non.existent/") << QUrl("http://non.existent/") << QString("http://non.existent/ is not available");
+ QTest::newRow("view-source:non.existent") << QUrl("view-source:non.existent") << false << QUrl("view-source:http://non.existent/") << QUrl("http://non.existent/") << QString("http://non.existent/ is not available");
}
void tst_QWebEnginePage::viewSourceURL()
@@ -5026,6 +5031,7 @@ void tst_QWebEnginePage::viewSourceURL()
QFETCH(QUrl, userInputUrl);
QFETCH(bool, loadSucceed);
QFETCH(QUrl, url);
+ QFETCH(QUrl, requestedUrl);
QFETCH(QString, title);
QWebEnginePage *page = new QWebEnginePage;
@@ -5037,6 +5043,7 @@ void tst_QWebEnginePage::viewSourceURL()
QCOMPARE(arguments.at(0).toBool(), loadSucceed);
QCOMPARE(page->url(), url);
+ QCOMPARE(page->requestedUrl(), requestedUrl);
QCOMPARE(page->title(), title);
QVERIFY(!page->action(QWebEnginePage::ViewSource)->isEnabled());