summaryrefslogtreecommitdiffstats
path: root/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp
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/renderer_host/resource_dispatcher_host_delegate_qt.cpp
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/renderer_host/resource_dispatcher_host_delegate_qt.cpp')
-rw-r--r--src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp27
1 files changed, 24 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();