This commit is contained in:
Ahmed Mohamed Ali 2017-10-13 10:52:11 +02:00
parent 4ffb6c5f75
commit 1ad95eca4a

View file

@ -15,6 +15,7 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h" #include "content/public/browser/download_manager.h"
#include "content/public/browser/stream_info.h" #include "content/public/browser/stream_info.h"
#include "content/public/browser/render_frame_host.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/ssl/client_cert_store.h" #include "net/ssl/client_cert_store.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
@ -66,6 +67,7 @@ void HandleExternalProtocolInUI(
void OnPdfResourceIntercepted( void OnPdfResourceIntercepted(
const GURL& original_url, const GURL& original_url,
int frame_tree_node_id,
const content::ResourceRequestInfo::WebContentsGetter& const content::ResourceRequestInfo::WebContentsGetter&
web_contents_getter) { web_contents_getter) {
content::WebContents* web_contents = web_contents_getter.Run(); content::WebContents* web_contents = web_contents_getter.Run();
@ -86,12 +88,10 @@ void OnPdfResourceIntercepted(
// The URL passes the original pdf resource url, that will be requested // The URL passes the original pdf resource url, that will be requested
// by the webui page. // by the webui page.
// chrome://pdf-viewer/index.html?src=https://somepage/123.pdf // chrome://pdf-viewer/index.html?src=https://somepage/123.pdf
content::NavigationController::LoadURLParams params( content::NavigationController::LoadURLParams params(GURL(base::StringPrintf(
GURL(base::StringPrintf( "%sindex.html?%s=%s", kPdfViewerUIOrigin, kPdfPluginSrc,
"%sindex.html?%s=%s",
kPdfViewerUIOrigin,
kPdfPluginSrc,
net::EscapeUrlEncodedData(original_url.spec(), false).c_str()))); net::EscapeUrlEncodedData(original_url.spec(), false).c_str())));
params.frame_tree_node_id = frame_tree_node_id;
web_contents->GetController().LoadURLWithParams(params); web_contents->GetController().LoadURLWithParams(params);
} }
@ -141,12 +141,21 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
std::string* payload) { std::string* payload) {
const content::ResourceRequestInfo* info = const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request); content::ResourceRequestInfo::ForRequest(request);
if (mime_type == "application/pdf" && info->IsMainFrame()) {
int render_process_host_id;
int render_frame_id;
info->GetAssociatedRenderFrame(&render_process_host_id, &render_frame_id);
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(render_process_host_id, render_frame_id);
int frame_tree_node_id = rfh->GetFrameTreeNodeId();
if (mime_type == "application/pdf") {
*origin = GURL(kPdfViewerUIOrigin); *origin = GURL(kPdfViewerUIOrigin);
content::BrowserThread::PostTask( content::BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::Bind(&OnPdfResourceIntercepted, request->url(), base::Bind(&OnPdfResourceIntercepted, request->url(),
info->GetWebContentsGetterForRequest())); frame_tree_node_id, info->GetWebContentsGetterForRequest()));
return true; return true;
} }
return false; return false;