From 65da983ccbc573dd340f6d8eeae574759bafd047 Mon Sep 17 00:00:00 2001 From: rreimann Date: Fri, 19 May 2017 11:49:22 +0200 Subject: [PATCH] Move preferences check to OnPdfResourceIntercepted --- .../atom_resource_dispatcher_host_delegate.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index f673672544ab..12038ff1bf50 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -4,6 +4,7 @@ #include "atom/browser/atom_resource_dispatcher_host_delegate.h" +#include "atom/browser/atom_browser_context.h" #include "atom/browser/login_handler.h" #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" @@ -12,6 +13,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/download_manager.h" #include "content/public/browser/stream_info.h" #include "net/base/escape.h" #include "net/ssl/client_cert_store.h" @@ -70,6 +72,17 @@ void OnPdfResourceIntercepted( if (!web_contents) return; + if (!WebContentsPreferences::IsPluginsEnabled(web_contents)) { + auto browser_context = web_contents->GetBrowserContext(); + auto download_manager = + content::BrowserContext::GetDownloadManager(browser_context); + + download_manager->DownloadUrl( + content::DownloadUrlParameters::CreateForWebContentsMainFrame( + web_contents, original_url)); + return; + } + // The URL passes the original pdf resource url, that will be requested // by the webui page. // chrome://pdf-viewer/index.html?src=https://somepage/123.pdf @@ -125,10 +138,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( std::string* payload) { const content::ResourceRequestInfo* info = content::ResourceRequestInfo::ForRequest(request); - content::WebContents* web_contents = - info->GetWebContentsGetterForRequest().Run(); - if (mime_type == "application/pdf" && info->IsMainFrame() && - WebContentsPreferences::IsPluginsEnabled(web_contents)) { + if (mime_type == "application/pdf" && info->IsMainFrame()) { *origin = GURL(kPdfViewerUIOrigin); content::BrowserThread::PostTask( BrowserThread::UI, FROM_HERE,