Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1122)

Unified Diff: chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.cc

Issue 263513004: Forward MIME types to BrowserPlugin when a viewer is specified. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unittests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d79ad2d6b277f3cd440215c06a454bb2b25751e7..03d06a481ceab2b13fcd8f7c83f3fc201a553f08 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,23 +157,12 @@ 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::WebContents* web_contents =
@@ -196,7 +186,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,
@@ -264,6 +255,7 @@ ChromeResourceDispatcherHostDelegate::ChromeResourceDispatcherHostDelegate(
}
ChromeResourceDispatcherHostDelegate::~ChromeResourceDispatcherHostDelegate() {
+ CHECK(stream_target_info_.empty());
}
bool ChromeResourceDispatcherHostDelegate::ShouldBeginRequest(
@@ -549,14 +541,14 @@ bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource(
}
bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
- content::ResourceContext* resource_context,
- const GURL& url,
+ net::URLRequest* request,
const std::string& mime_type,
GURL* origin,
- std::string* target_id) {
+ std::string* payload) {
#if !defined(OS_ANDROID)
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
ProfileIOData* io_data =
- ProfileIOData::FromResourceContext(resource_context);
+ ProfileIOData::FromResourceContext(info->GetContext());
bool profile_is_off_the_record = io_data->IsOffTheRecord();
const scoped_refptr<const extensions::InfoMap> extension_info_map(
io_data->GetExtensionInfoMap());
@@ -575,9 +567,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;
return true;
}
}
@@ -586,18 +586,20 @@ bool ChromeResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
}
void ChromeResourceDispatcherHostDelegate::OnStreamCreated(
- 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) {
+ net::URLRequest* request,
+ scoped_ptr<content::StreamHandle> stream) {
#if !defined(OS_ANDROID)
+ const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
+ 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(),
+ info->GetChildID(), info->GetRouteID(),
+ ix->second.extension_id, ix->second.view_id));
+ stream_target_info_.erase(request);
#endif
}

Powered by Google App Engine
This is Rietveld 408576698