Browse Source

Move preferences check to OnPdfResourceIntercepted

(cherry picked from commit 65da983ccbc573dd340f6d8eeae574759bafd047)
rreimann 8 years ago
parent
commit
1612ebc539
1 changed files with 14 additions and 4 deletions
  1. 14 4
      atom/browser/atom_resource_dispatcher_host_delegate.cc

+ 14 - 4
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,