void OnPdfStreamCreated(
std::unique_ptr<content::StreamInfo> stream,
+ const std::string& stream_id,
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
int render_process_id,
int render_frame_id) {
auto browser_context =
static_cast<AtomBrowserContext*>(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);
std::string* payload) {
if (mime_type == "application/pdf") {
*origin = GURL(kPdfViewerUIOrigin);
+ stream_info_[request] = base::GenerateGUID();
return true;
}
return false;
void AtomResourceDispatcherHostDelegate::OnStreamCreated(
net::URLRequest* request,
std::unique_ptr<content::StreamInfo> 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
#ifndef ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
#define ATOM_BROWSER_ATOM_RESOURCE_DISPATCHER_HOST_DELEGATE_H_
+#include <map>
#include <string>
#include "content/public/browser/resource_dispatcher_host_delegate.h"
std::string* payload) override;
void OnStreamCreated(net::URLRequest* request,
std::unique_ptr<content::StreamInfo> stream) override;
+
+ private:
+ // Map between intercepted request and its generated stream id.
+ std::map<net::URLRequest*, std::string> stream_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate);
};
} // namespace atom