Chromium Code Reviews| Index: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc |
| diff --git a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc |
| index 65e68968ad4bbc4e38fb795a3d78b2fcd5b9b3ba..2b8b177b948f1fc2aeb11c4f8ab2601c39ebc7ec 100644 |
| --- a/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc |
| +++ b/chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc |
| @@ -8,6 +8,7 @@ |
| #include <vector> |
| #include "base/base64.h" |
| +#include "base/guid.h" |
| #include "base/logging.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| @@ -156,25 +157,19 @@ void UpdatePrerenderNetworkBytesCallback(int render_process_id, |
| } |
| #if !defined(OS_ANDROID) |
| -// Goes through the extension's file browser handlers and checks if there is one |
| -// that can handle the |mime_type|. |
| -// |extension| must not be NULL. |
| -bool ExtensionCanHandleMimeType(const Extension* extension, |
| - const std::string& mime_type) { |
| - MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| - if (!handler) |
| - return false; |
| - |
| - return handler->CanHandleMIMEType(mime_type); |
| -} |
| - |
| void SendExecuteMimeTypeHandlerEvent(scoped_ptr<content::StreamHandle> stream, |
| int64 expected_content_size, |
| int render_process_id, |
| int render_view_id, |
| - const std::string& extension_id) { |
| + const std::string& extension_id, |
| + const std::string& view_id) { |
| DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + content::RenderViewHost* render_view_host = |
| + content::RenderViewHost::FromID(render_process_id, render_view_id); |
| + if (!render_view_host) |
| + return; |
| + |
| content::WebContents* web_contents = |
| tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| if (!web_contents) |
| @@ -196,7 +191,8 @@ void SendExecuteMimeTypeHandlerEvent(scoped_ptr<content::StreamHandle> stream, |
| if (!streams_private) |
| return; |
| streams_private->ExecuteMimeTypeHandler( |
| - extension_id, web_contents, stream.Pass(), expected_content_size); |
| + extension_id, web_contents, stream.Pass(), view_id, |
| + expected_content_size); |
| } |
| void LaunchURL(const GURL& url, int render_process_id, int render_view_id, |
| @@ -549,11 +545,11 @@ bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( |
| } |
| bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
| + net::URLRequest* request, |
| content::ResourceContext* resource_context, |
| - const GURL& url, |
| const std::string& mime_type, |
| GURL* origin, |
| - std::string* target_id) { |
| + std::string* payload) { |
| #if !defined(OS_ANDROID) |
| ProfileIOData* io_data = |
| ProfileIOData::FromResourceContext(resource_context); |
| @@ -575,9 +571,17 @@ bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
| continue; |
| } |
| - if (ExtensionCanHandleMimeType(extension, mime_type)) { |
| + MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| + if (handler && handler->CanHandleMIMEType(mime_type)) { |
| + StreamTargetInfo target_info; |
| *origin = Extension::GetBaseURLFromExtensionId(extension_id); |
| - *target_id = extension_id; |
| + target_info.extension_id = extension_id; |
| + if (!handler->handler_url().empty()) { |
| + target_info.view_id = base::GenerateGUID(); |
| + *payload = origin->spec() + handler->handler_url() + |
| + "?id=" + target_info.view_id; |
| + } |
| + stream_target_info_[request] = target_info; |
|
jam
2014/06/06 15:00:40
nit: check in the destructor of this class that th
Zachary Kuznia
2014/06/07 01:45:36
Done.
|
| return true; |
| } |
| } |
| @@ -586,18 +590,22 @@ bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream( |
| } |
| void ChromeResourceDispatcherHostDelegate::OnStreamCreated( |
| + net::URLRequest* request, |
| content::ResourceContext* resource_context, |
| int render_process_id, |
| int render_view_id, |
| - const std::string& target_id, |
| - scoped_ptr<content::StreamHandle> stream, |
| - int64 expected_content_size) { |
| + scoped_ptr<content::StreamHandle> stream) { |
| #if !defined(OS_ANDROID) |
| + std::map<net::URLRequest*, StreamTargetInfo>::iterator ix = |
| + stream_target_info_.find(request); |
| + CHECK(ix != stream_target_info_.end()); |
| content::BrowserThread::PostTask( |
| content::BrowserThread::UI, FROM_HERE, |
| base::Bind(&SendExecuteMimeTypeHandlerEvent, base::Passed(&stream), |
| - expected_content_size, render_process_id, render_view_id, |
| - target_id)); |
| + request->GetExpectedContentSize(), render_process_id, |
|
jam
2014/06/06 15:00:40
nit: once you don't take in the render_process_id
Zachary Kuznia
2014/06/07 01:45:36
Done.
|
| + render_view_id, |
| + ix->second.extension_id, ix->second.view_id)); |
| + stream_target_info_.erase(request); |
| #endif |
| } |