Chromium Code Reviews| Index: content/browser/loader/buffered_resource_handler.cc |
| diff --git a/content/browser/loader/buffered_resource_handler.cc b/content/browser/loader/buffered_resource_handler.cc |
| index a160eed36f46ab453ee278ac324b60d4c8ad3297..c3c182a4594fdaa725ab2a5e58320d2a2c340fc6 100644 |
| --- a/content/browser/loader/buffered_resource_handler.cc |
| +++ b/content/browser/loader/buffered_resource_handler.cc |
| @@ -294,6 +294,60 @@ bool BufferedResourceHandler::DetermineMimeType() { |
| return made_final_decision; |
| } |
| +bool BufferedResourceHandler::IsHandledByPlugin(bool* defer, |
| + bool* request_handled) { |
| +#if defined(ENABLE_PLUGINS) |
| + bool stale; |
| + WebPluginInfo plugin; |
| + bool allow_wildcard = false; |
| + ResourceRequestInfoImpl* info = GetRequestInfo(); |
| + bool has_plugin = plugin_service_->GetPluginInfo( |
| + info->GetChildID(), info->GetRenderFrameID(), info->GetContext(), |
| + request()->url(), GURL(), response_->head.mime_type, allow_wildcard, |
| + &stale, &plugin, NULL); |
| + |
| + if (stale) { |
| + // Refresh the plugins asynchronously. |
| + plugin_service_->GetPlugins( |
| + base::Bind(&BufferedResourceHandler::OnPluginsLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + request()->LogBlockedBy("BufferedResourceHandler"); |
| + *defer = true; |
| + return true; |
| + } |
| + |
| + if (has_plugin) { |
| + if (plugin.type == WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN) { |
| + // If it is a MimeHandlerView plugin, intercept the stream. |
| + std::string payload; |
| + scoped_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream( |
| + plugin.path, request(), response_.get(), &payload)); |
|
mmenke
2015/06/11 19:38:04
This exactly matches the fallthrough logic. Maybe
raymes
2015/07/01 05:13:18
That's much simpler, thanks!
|
| + if (handler) { |
| + *request_handled = UseAlternateNextHandler(handler.Pass(), payload); |
| + return true; |
| + } |
| + // If the plugin is a MimeHandlerView plugin it should always be |
| + // intercepted as a stream so this point should never be reached. |
|
mmenke
2015/06/11 19:38:04
This is content/, not chrome/. I assume MimeHandl
raymes
2015/07/01 05:13:18
Done.
|
| + NOTREACHED(); |
| + return false; |
| + } else { |
| + return true; |
| + } |
| + } |
| + |
| + // If execution reaches here then try intercepting the stream for the old |
| + // streamsPrivate extensions API. This API is deprecated and should go away. |
|
mmenke
2015/06/11 19:38:04
The streamsPrivate API is a chrome feature. We're
raymes
2015/07/01 05:13:18
Done.
|
| + std::string payload; |
| + scoped_ptr<ResourceHandler> handler(host_->MaybeInterceptAsStream( |
| + base::FilePath(), request(), response_.get(), &payload)); |
| + if (handler) { |
| + *request_handled = UseAlternateNextHandler(handler.Pass(), payload); |
| + return true; |
| + } |
| +#endif |
| + return false; |
| +} |
| + |
| bool BufferedResourceHandler::SelectNextHandler(bool* defer) { |
| DCHECK(!response_->head.mime_type.empty()); |
| @@ -311,13 +365,13 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) { |
| // Allow requests for object/embed tags to be intercepted as streams. |
| if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { |
| DCHECK(!info->allow_download()); |
| - std::string payload; |
| - scoped_ptr<ResourceHandler> handler( |
| - host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); |
| - if (handler) { |
| - DCHECK(!mime_util::IsSupportedMimeType(mime_type)); |
| - return UseAlternateNextHandler(handler.Pass(), payload); |
| - } |
| + |
| + bool request_handled = true; |
| + bool handled_by_plugin = IsHandledByPlugin(defer, &request_handled); |
| + if (!request_handled) |
| + return false; |
| + if (handled_by_plugin) |
|
mmenke
2015/06/11 19:38:04
If |defer| is set to true, the method also must re
raymes
2015/07/01 05:13:18
Done.
|
| + return true; |
| } |
| if (!info->allow_download()) |
| @@ -334,28 +388,12 @@ bool BufferedResourceHandler::SelectNextHandler(bool* defer) { |
| if (mime_util::IsSupportedMimeType(mime_type)) |
| return true; |
| - std::string payload; |
| - scoped_ptr<ResourceHandler> handler( |
| - host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); |
| - if (handler) { |
| - return UseAlternateNextHandler(handler.Pass(), payload); |
| - } |
| - |
| -#if defined(ENABLE_PLUGINS) |
| - bool stale; |
| - bool has_plugin = HasSupportingPlugin(&stale); |
| - if (stale) { |
| - // Refresh the plugins asynchronously. |
| - plugin_service_->GetPlugins( |
| - base::Bind(&BufferedResourceHandler::OnPluginsLoaded, |
| - weak_ptr_factory_.GetWeakPtr())); |
| - request()->LogBlockedBy("BufferedResourceHandler"); |
| - *defer = true; |
| - return true; |
| - } |
| - if (has_plugin) |
| + bool request_handled = true; |
| + bool handled_by_plugin = IsHandledByPlugin(defer, &request_handled); |
| + if (!request_handled) |
| + return false; |
| + if (handled_by_plugin) |
| return true; |
| -#endif |
| } |
| // Install download handler |
| @@ -472,23 +510,6 @@ bool BufferedResourceHandler::MustDownload() { |
| return must_download_; |
| } |
| -bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) { |
| -#if defined(ENABLE_PLUGINS) |
| - ResourceRequestInfoImpl* info = GetRequestInfo(); |
| - |
| - bool allow_wildcard = false; |
| - WebPluginInfo plugin; |
| - return plugin_service_->GetPluginInfo( |
| - info->GetChildID(), info->GetRenderFrameID(), info->GetContext(), |
| - request()->url(), GURL(), response_->head.mime_type, allow_wildcard, |
| - stale, &plugin, NULL); |
| -#else |
| - if (stale) |
| - *stale = false; |
| - return false; |
| -#endif |
| -} |
| - |
| bool BufferedResourceHandler::CopyReadBufferToNextHandler() { |
| if (!read_buffer_.get()) |
| return true; |