summaryrefslogtreecommitdiffstats
path: root/src/core
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 /src/core
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>
Diffstat (limited to 'src/core')
-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
3 files changed, 30 insertions, 3 deletions
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 0583060c6..0a6adf4d6 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 2e48a806a..a652469cb 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 06a7a6004..8ed727524 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.