summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2019-02-18 17:56:56 +0100
committerMichael BrĂ¼ning <michael.bruning@qt.io>2019-02-22 16:32:20 +0000
commitd2ff59ffb4967eb34a04133ce9090da9499d4ff1 (patch)
tree96674420a1eb25a2ea48d74b319a9855fb24ab69
parent228ba503b7c5474759fe3254210c3713665c2e9c (diff)
Add a setting to control if the PDF viewer is enabled
[ChangeLog] Introduces a setting to control if the internal PDF viewer is enabled. By default, PDF documents will now be opened in the viewer instead of being downloaded. Change-Id: I78b3b3702ae3be3da58c9635720ba861db3de661 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Michal Klocek <michal.klocek@qt.io>
-rw-r--r--examples/webengine/quicknanobrowser/BrowserWindow.qml8
-rw-r--r--src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp27
-rw-r--r--src/core/web_engine_settings.cpp5
-rw-r--r--src/core/web_engine_settings.h1
-rw-r--r--src/webengine/api/qquickwebenginesettings.cpp22
-rw-r--r--src/webengine/api/qquickwebenginesettings_p.h4
-rw-r--r--src/webenginewidgets/api/qwebenginesettings.cpp3
-rw-r--r--src/webenginewidgets/api/qwebenginesettings.h1
-rw-r--r--src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc4
9 files changed, 70 insertions, 5 deletions
diff --git a/examples/webengine/quicknanobrowser/BrowserWindow.qml b/examples/webengine/quicknanobrowser/BrowserWindow.qml
index c0cb4283..94e7ac37 100644
--- a/examples/webengine/quicknanobrowser/BrowserWindow.qml
+++ b/examples/webengine/quicknanobrowser/BrowserWindow.qml
@@ -89,6 +89,7 @@ ApplicationWindow {
property alias touchIconsEnabled: touchIconsEnabled.checked
property alias webRTCPublicInterfacesOnly : webRTCPublicInterfacesOnly.checked
property alias devToolsEnabled: devToolsEnabled.checked
+ property alias pdfViewerEnabled: pdfViewerEnabled.checked
}
Action {
@@ -333,6 +334,12 @@ ApplicationWindow {
checkable: true
checked: false
}
+ MenuItem {
+ id: pdfViewerEnabled
+ text: "PDF viewer enabled"
+ checkable: true
+ checked: WebEngine.settings.pdfViewerEnabled
+ }
}
}
}
@@ -410,6 +417,7 @@ ApplicationWindow {
settings.autoLoadIconsForPage: appSettings.autoLoadIconsForPage
settings.touchIconsEnabled: appSettings.touchIconsEnabled
settings.webRTCPublicInterfacesOnly: appSettings.webRTCPublicInterfacesOnly
+ settings.pdfViewerEnabled: appSettings.pdfViewerEnabled
onCertificateError: function(error) {
error.defer();
diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp
index 0583060c..0a6adf4d 100644
--- a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp
+++ b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp
@@ -47,8 +47,11 @@
#include "base/guid.h"
#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/download_manager.h"
+#include "content/public/browser/download_request_utils.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/render_frame_host.h"
@@ -69,6 +72,8 @@
#include "resource_context_qt.h"
#include "type_conversion.h"
+#include "web_contents_delegate_qt.h"
+#include "web_engine_settings.h"
namespace QtWebEngineCore {
@@ -82,6 +87,23 @@ void OnPdfStreamIntercepted(
if (!web_contents)
return;
+ WebContentsDelegateQt *contentsDelegate = static_cast<WebContentsDelegateQt*>(web_contents->GetDelegate());
+ if (!contentsDelegate)
+ return;
+
+ WebEngineSettings *settings = contentsDelegate->webEngineSettings();
+ if (!settings->testAttribute(WebEngineSettings::PDFViewerEnabled)
+ || !settings->testAttribute(WebEngineSettings::PluginsEnabled)) {
+ // If the applications has been set up to always download PDF files to open them in an
+ // external viewer, trigger the download.
+ std::unique_ptr<download::DownloadUrlParameters> params(
+ content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame(
+ web_contents, original_url, NO_TRAFFIC_ANNOTATION_YET));
+ content::BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())
+ ->DownloadUrl(std::move(params));
+ return;
+ }
+
// The URL passes the original pdf resource url, that will be requested
// by the pdf viewer extension page.
content::NavigationController::LoadURLParams params(
@@ -103,9 +125,8 @@ bool ResourceDispatcherHostDelegateQt::ShouldInterceptResourceAsStream(net::URLR
int render_process_host_id = -1;
int render_frame_id = -1;
- if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_host_id, &render_frame_id)) {
- return false;
- }
+ if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_host_id, &render_frame_id))
+ return false;
ResourceContextQt *context = static_cast<ResourceContextQt *>(info->GetContext());
std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp
index 2e48a806..a652469c 100644
--- a/src/core/web_engine_settings.cpp
+++ b/src/core/web_engine_settings.cpp
@@ -299,6 +299,11 @@ void WebEngineSettings::initDefaults()
s_defaultAttributes.insert(WebRTCPublicInterfacesOnly, false);
s_defaultAttributes.insert(JavascriptCanPaste, false);
s_defaultAttributes.insert(DnsPrefetchEnabled, false);
+#if QT_CONFIG(webengine_extensions)
+ s_defaultAttributes.insert(PDFViewerEnabled, true);
+#else
+ s_defaultAttributes.insert(PDFViewerEnabled, false);
+#endif
}
if (s_defaultFontFamilies.isEmpty()) {
diff --git a/src/core/web_engine_settings.h b/src/core/web_engine_settings.h
index 06a7a600..8ed72752 100644
--- a/src/core/web_engine_settings.h
+++ b/src/core/web_engine_settings.h
@@ -103,6 +103,7 @@ public:
WebRTCPublicInterfacesOnly,
JavascriptCanPaste,
DnsPrefetchEnabled,
+ PDFViewerEnabled,
};
// Must match the values from the public API in qwebenginesettings.h.
diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp
index 6e96e76c..4f6a8c14 100644
--- a/src/webengine/api/qquickwebenginesettings.cpp
+++ b/src/webengine/api/qquickwebenginesettings.cpp
@@ -457,6 +457,20 @@ bool QQuickWebEngineSettings::dnsPrefetchEnabled() const
}
/*!
+ \qmlproperty bool WebEngineSettings::pdfViewerEnabled
+ \since QtWebEngine 1.9
+
+ Specifies that PDF documents will be opened in the internal PDF viewer
+ instead of being downloaded.
+
+ Enabled by default.
+*/
+bool QQuickWebEngineSettings::pdfViewerEnabled() const
+{
+ return d_ptr->testAttribute(WebEngineSettings::PDFViewerEnabled);
+}
+
+/*!
\qmlproperty string WebEngineSettings::defaultTextEncoding
\since QtWebEngine 1.2
@@ -714,6 +728,14 @@ void QQuickWebEngineSettings::setDnsPrefetchEnabled(bool on)
Q_EMIT dnsPrefetchEnabledChanged();
}
+void QQuickWebEngineSettings::setPDFViewerEnabled(bool on)
+{
+ bool wasOn = d_ptr->testAttribute(WebEngineSettings::PDFViewerEnabled);
+ d_ptr->setAttribute(WebEngineSettings::PDFViewerEnabled, on);
+ if (wasOn != on)
+ Q_EMIT pdfViewerEnabledChanged();
+}
+
void QQuickWebEngineSettings::setUnknownUrlSchemePolicy(QQuickWebEngineSettings::UnknownUrlSchemePolicy policy)
{
WebEngineSettings::UnknownUrlSchemePolicy oldPolicy = d_ptr->unknownUrlSchemePolicy();
diff --git a/src/webengine/api/qquickwebenginesettings_p.h b/src/webengine/api/qquickwebenginesettings_p.h
index 6e1aaca3..ae6703bd 100644
--- a/src/webengine/api/qquickwebenginesettings_p.h
+++ b/src/webengine/api/qquickwebenginesettings_p.h
@@ -93,6 +93,7 @@ class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineSettings : public QObject {
Q_PROPERTY(bool webRTCPublicInterfacesOnly READ webRTCPublicInterfacesOnly WRITE setWebRTCPublicInterfacesOnly NOTIFY webRTCPublicInterfacesOnlyChanged REVISION 6 FINAL)
Q_PROPERTY(bool javascriptCanPaste READ javascriptCanPaste WRITE setJavascriptCanPaste NOTIFY javascriptCanPasteChanged REVISION 6 FINAL)
Q_PROPERTY(bool dnsPrefetchEnabled READ dnsPrefetchEnabled WRITE setDnsPrefetchEnabled NOTIFY dnsPrefetchEnabledChanged REVISION 7 FINAL)
+ Q_PROPERTY(bool pdfViewerEnabled READ pdfViewerEnabled WRITE setPDFViewerEnabled NOTIFY pdfViewerEnabledChanged REVISION 8 FINAL)
public:
enum UnknownUrlSchemePolicy {
@@ -135,6 +136,7 @@ public:
bool webRTCPublicInterfacesOnly() const;
bool javascriptCanPaste() const;
bool dnsPrefetchEnabled() const;
+ bool pdfViewerEnabled() const;
void setAutoLoadImages(bool on);
void setJavascriptEnabled(bool on);
@@ -166,6 +168,7 @@ public:
void setWebRTCPublicInterfacesOnly(bool on);
void setJavascriptCanPaste(bool on);
void setDnsPrefetchEnabled(bool on);
+ void setPDFViewerEnabled(bool on);
signals:
void autoLoadImagesChanged();
@@ -198,6 +201,7 @@ signals:
Q_REVISION(6) void webRTCPublicInterfacesOnlyChanged();
Q_REVISION(6) void javascriptCanPasteChanged();
Q_REVISION(7) void dnsPrefetchEnabledChanged();
+ Q_REVISION(8) void pdfViewerEnabledChanged();
private:
explicit QQuickWebEngineSettings(QQuickWebEngineSettings *parentSettings = 0);
diff --git a/src/webenginewidgets/api/qwebenginesettings.cpp b/src/webenginewidgets/api/qwebenginesettings.cpp
index d91eb3f9..5c91511b 100644
--- a/src/webenginewidgets/api/qwebenginesettings.cpp
+++ b/src/webenginewidgets/api/qwebenginesettings.cpp
@@ -109,7 +109,8 @@ static WebEngineSettings::Attribute toWebEngineAttribute(QWebEngineSettings::Web
return WebEngineSettings::JavascriptCanPaste;
case QWebEngineSettings::DnsPrefetchEnabled:
return WebEngineSettings::DnsPrefetchEnabled;
-
+ case QWebEngineSettings::PDFViewerEnabled:
+ return WebEngineSettings::PDFViewerEnabled;
default:
return WebEngineSettings::UnsupportedInCoreSettings;
}
diff --git a/src/webenginewidgets/api/qwebenginesettings.h b/src/webenginewidgets/api/qwebenginesettings.h
index 9100e32d..3657702d 100644
--- a/src/webenginewidgets/api/qwebenginesettings.h
+++ b/src/webenginewidgets/api/qwebenginesettings.h
@@ -96,6 +96,7 @@ public:
WebRTCPublicInterfacesOnly,
JavascriptCanPaste,
DnsPrefetchEnabled,
+ PDFViewerEnabled,
};
enum FontSize {
diff --git a/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc
index 88f6e05c..34fdcb30 100644
--- a/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebenginesettings_lgpl.qdoc
@@ -188,7 +188,9 @@
\value DnsPrefetchEnabled Specifies whether WebEngine will try to pre-fetch DNS entries to
speed up browsing.
Disabled by default. (Added in Qt 5.12)
-
+ \value EnablePDFViewer Specifies that PDF documents will be opened in the internal PDF viewer
+ instead of being downloaded.
+ Enabled by default. (Added in Qt 5.13)
*/
/*!