diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-12 22:57:54 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-12 22:57:54 +0000 |
commit | 6edb648820e11ef8e822f65813c19c386ca6bffb (patch) | |
tree | 0e5860c19f51b074cc31d05017bb3563ba1d9c93 /content/browser/loader | |
parent | 03bbb697f8bea8de7005b367b916c29a57cf21eb (diff) | |
download | chromium_src-6edb648820e11ef8e822f65813c19c386ca6bffb.zip chromium_src-6edb648820e11ef8e822f65813c19c386ca6bffb.tar.gz chromium_src-6edb648820e11ef8e822f65813c19c386ca6bffb.tar.bz2 |
Forward MIME types to BrowserPlugin when a viewer is specified.
When the mime_type_handler key is available in an extension, this creates a
BrowserPlugin and gives the ID of it to the background page.
BUG=368514
Review URL: https://codereview.chromium.org/263513004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276841 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/loader')
4 files changed, 46 insertions, 24 deletions
diff --git a/content/browser/loader/buffered_resource_handler.cc b/content/browser/loader/buffered_resource_handler.cc index e8ea684..f609cbf 100644 --- a/content/browser/loader/buffered_resource_handler.cc +++ b/content/browser/loader/buffered_resource_handler.cc @@ -15,6 +15,7 @@ #include "content/browser/loader/certificate_resource_handler.h" #include "content/browser/loader/resource_dispatcher_host_impl.h" #include "content/browser/loader/resource_request_info_impl.h" +#include "content/browser/loader/stream_resource_handler.h" #include "content/browser/plugin_service_impl.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/download_item.h" @@ -305,7 +306,7 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) { info->set_is_download(true); scoped_ptr<ResourceHandler> handler( new CertificateResourceHandler(request())); - return UseAlternateNextHandler(handler.Pass()); + return UseAlternateNextHandler(handler.Pass(), std::string()); } if (!info->allow_download()) @@ -316,10 +317,12 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) { if (net::IsSupportedMimeType(mime_type)) return true; + std::string payload; scoped_ptr<ResourceHandler> handler( - host_->MaybeInterceptAsStream(request(), response_.get())); - if (handler) - return UseAlternateNextHandler(handler.Pass()); + host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); + if (handler) { + return UseAlternateNextHandler(handler.Pass(), payload); + } #if defined(ENABLE_PLUGINS) bool stale; @@ -348,11 +351,12 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) { content::DownloadItem::kInvalidId, scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo()), DownloadUrlParameters::OnStartedCallback())); - return UseAlternateNextHandler(handler.Pass()); + return UseAlternateNextHandler(handler.Pass(), std::string()); } bool BufferedResourceHandler::UseAlternateNextHandler( - scoped_ptr<ResourceHandler> new_handler) { + scoped_ptr<ResourceHandler> new_handler, + const std::string& payload_for_old_handler) { if (response_->head.headers.get() && // Can be NULL if FTP. response_->head.headers->response_code() / 100 != 2) { // The response code indicates that this is an error page, but we don't @@ -373,10 +377,29 @@ bool BufferedResourceHandler::UseAlternateNextHandler( // which does so is CrossSiteResourceHandler. Cross-site transitions should // not trigger when switching handlers. DCHECK(!defer_ignored); - net::URLRequestStatus status(net::URLRequestStatus::CANCELED, - net::ERR_ABORTED); - next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored); - DCHECK(!defer_ignored); + if (payload_for_old_handler.empty()) { + net::URLRequestStatus status(net::URLRequestStatus::CANCELED, + net::ERR_ABORTED); + next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored); + DCHECK(!defer_ignored); + } else { + scoped_refptr<net::IOBuffer> buf; + int size = 0; + + next_handler_->OnWillRead(&buf, &size, payload_for_old_handler.length()); + CHECK_GE(size, static_cast<int>(payload_for_old_handler.length())); + + memcpy(buf->data(), payload_for_old_handler.c_str(), + payload_for_old_handler.length()); + + next_handler_->OnReadCompleted(payload_for_old_handler.length(), + &defer_ignored); + DCHECK(!defer_ignored); + + net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); + next_handler_->OnResponseCompleted(status, std::string(), &defer_ignored); + DCHECK(!defer_ignored); + } // This is handled entirely within the new ResourceHandler, so just reset the // original ResourceHandler. diff --git a/content/browser/loader/buffered_resource_handler.h b/content/browser/loader/buffered_resource_handler.h index a6ddff1..0b6d698 100644 --- a/content/browser/loader/buffered_resource_handler.h +++ b/content/browser/loader/buffered_resource_handler.h @@ -54,7 +54,8 @@ class BufferedResourceHandler bool ShouldSniffContent(); bool DetermineMimeType(); bool SelectNextHandler(bool* defer); - bool UseAlternateNextHandler(scoped_ptr<ResourceHandler> handler); + bool UseAlternateNextHandler(scoped_ptr<ResourceHandler> handler, + const std::string& payload_for_old_handler); bool ReplayReadCompleted(bool* defer); void CallReplayReadCompleted(); diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc index 86d5e5f..09644d6 100644 --- a/content/browser/loader/resource_dispatcher_host_impl.cc +++ b/content/browser/loader/resource_dispatcher_host_impl.cc @@ -608,18 +608,17 @@ ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( scoped_ptr<ResourceHandler> ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request, - ResourceResponse* response) { + ResourceResponse* response, + std::string* payload) { ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); const std::string& mime_type = response->head.mime_type; GURL origin; - std::string target_id; if (!delegate_ || - !delegate_->ShouldInterceptResourceAsStream(info->GetContext(), - request->url(), + !delegate_->ShouldInterceptResourceAsStream(request, mime_type, &origin, - &target_id)) { + payload)) { return scoped_ptr<ResourceHandler>(); } @@ -633,15 +632,11 @@ ResourceDispatcherHostImpl::MaybeInterceptAsStream(net::URLRequest* request, info->set_is_stream(true); delegate_->OnStreamCreated( - info->GetContext(), - info->GetChildID(), - info->GetRouteID(), - target_id, + request, handler->stream()->CreateHandle( request->url(), mime_type, - response->head.headers), - request->GetExpectedContentSize()); + response->head.headers)); return handler.PassAs<ResourceHandler>(); } diff --git a/content/browser/loader/resource_dispatcher_host_impl.h b/content/browser/loader/resource_dispatcher_host_impl.h index 185fb0b..3cc7b4f 100644 --- a/content/browser/loader/resource_dispatcher_host_impl.h +++ b/content/browser/loader/resource_dispatcher_host_impl.h @@ -210,10 +210,13 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl const DownloadUrlParameters::OnStartedCallback& started_cb); // Must be called after the ResourceRequestInfo has been created - // and associated with the request. + // and associated with the request. If |payload| is set to a non-empty value, + // the value will be sent to the old resource handler instead of cancelling + // it, except on HTTP errors. scoped_ptr<ResourceHandler> MaybeInterceptAsStream( net::URLRequest* request, - ResourceResponse* response); + ResourceResponse* response, + std::string* payload); void ClearSSLClientAuthHandlerForRequest(net::URLRequest* request); |