check if target stream is intercepted for correct request

This commit is contained in:
deepak1556 2017-02-14 04:11:04 +05:30
parent ed89a603f3
commit 6987e3ecd0
2 changed files with 14 additions and 2 deletions

View file

@ -65,6 +65,7 @@ void HandleExternalProtocolInUI(
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) {
@ -75,7 +76,6 @@ void OnPdfStreamCreated(
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);
@ -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<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

View file

@ -5,6 +5,7 @@
#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"
@ -31,6 +32,12 @@ class AtomResourceDispatcherHostDelegate
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