diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.cc b/atom/browser/atom_resource_dispatcher_host_delegate.cc index 571208e3e6e..12abd8e8157 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.cc +++ b/atom/browser/atom_resource_dispatcher_host_delegate.cc @@ -65,6 +65,7 @@ void HandleExternalProtocolInUI( void OnPdfStreamCreated( std::unique_ptr stream, + const std::string& stream_id, const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, int render_process_id, int render_frame_id) { @@ -75,7 +76,6 @@ void OnPdfStreamCreated( auto browser_context = static_cast(web_contents->GetBrowserContext()); auto stream_manager = browser_context->stream_manager(); - std::string stream_id = base::GenerateGUID(); GURL original_url = stream->original_url; stream_manager->AddStream(std::move(stream), stream_id, render_process_id, render_frame_id); @@ -136,6 +136,7 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( std::string* payload) { if (mime_type == "application/pdf") { *origin = GURL(kPdfViewerUIOrigin); + stream_info_[request] = base::GenerateGUID(); return true; } return false; @@ -144,13 +145,17 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( void AtomResourceDispatcherHostDelegate::OnStreamCreated( net::URLRequest* request, std::unique_ptr stream) { + auto it = stream_info_.find(request); + if (it == stream_info_.end()) + return; const content::ResourceRequestInfo* info = content::ResourceRequestInfo::ForRequest(request); content::BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(&OnPdfStreamCreated, base::Passed(&stream), + base::Bind(&OnPdfStreamCreated, base::Passed(&stream), it->second, info->GetWebContentsGetterForRequest(), info->GetChildID(), info->GetRenderFrameID())); + stream_info_.erase(it); } } // namespace atom diff --git a/atom/browser/atom_resource_dispatcher_host_delegate.h b/atom/browser/atom_resource_dispatcher_host_delegate.h index 65735f18f8d..e1bb80359c3 100644 --- a/atom/browser/atom_resource_dispatcher_host_delegate.h +++ b/atom/browser/atom_resource_dispatcher_host_delegate.h @@ -5,6 +5,7 @@ #ifndef ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ #define ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_ +#include #include #include "content/public/browser/resource_dispatcher_host_delegate.h" @@ -31,6 +32,12 @@ class AtomResourceDispatcherHostDelegate std::string* payload) override; void OnStreamCreated(net::URLRequest* request, std::unique_ptr stream) override; + + private: + // Map between intercepted request and its generated stream id. + std::map stream_info_; + + DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate); }; } // namespace atom