Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/loader/buffered_resource_handler.h" | 5 #include "content/browser/loader/buffered_resource_handler.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "content/browser/download/download_resource_handler.h" | 13 #include "content/browser/download/download_resource_handler.h" |
| 14 #include "content/browser/download/download_stats.h" | 14 #include "content/browser/download/download_stats.h" |
| 15 #include "content/browser/loader/certificate_resource_handler.h" | 15 #include "content/browser/loader/certificate_resource_handler.h" |
| 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 17 #include "content/browser/loader/resource_request_info_impl.h" | 17 #include "content/browser/loader/resource_request_info_impl.h" |
| 18 #include "content/browser/loader/stream_resource_handler.h" | |
| 18 #include "content/browser/plugin_service_impl.h" | 19 #include "content/browser/plugin_service_impl.h" |
| 20 #include "content/browser/resource_context_impl.h" | |
| 21 #include "content/browser/streams/stream.h" | |
| 22 #include "content/browser/streams/stream_context.h" | |
| 23 #include "content/browser/streams/stream_registry.h" | |
| 19 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/download_id.h" | 25 #include "content/public/browser/download_id.h" |
| 21 #include "content/public/browser/download_save_info.h" | 26 #include "content/public/browser/download_save_info.h" |
| 22 #include "content/public/browser/resource_context.h" | 27 #include "content/public/browser/resource_context.h" |
| 23 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 28 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 29 #include "content/public/browser/stream_handle.h" | |
| 24 #include "content/public/common/resource_response.h" | 30 #include "content/public/common/resource_response.h" |
| 25 #include "net/base/io_buffer.h" | 31 #include "net/base/io_buffer.h" |
| 26 #include "net/base/mime_sniffer.h" | 32 #include "net/base/mime_sniffer.h" |
| 27 #include "net/base/mime_util.h" | 33 #include "net/base/mime_util.h" |
| 28 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 29 #include "net/http/http_content_disposition.h" | 35 #include "net/http/http_content_disposition.h" |
| 30 #include "net/http/http_response_headers.h" | 36 #include "net/http/http_response_headers.h" |
| 31 #include "webkit/plugins/webplugininfo.h" | 37 #include "webkit/plugins/webplugininfo.h" |
| 32 | 38 |
| 33 namespace content { | 39 namespace content { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 } | 319 } |
| 314 | 320 |
| 315 if (!info->allow_download()) | 321 if (!info->allow_download()) |
| 316 return true; | 322 return true; |
| 317 | 323 |
| 318 bool must_download = MustDownload(); | 324 bool must_download = MustDownload(); |
| 319 if (!must_download) { | 325 if (!must_download) { |
| 320 if (net::IsSupportedMimeType(mime_type)) | 326 if (net::IsSupportedMimeType(mime_type)) |
| 321 return true; | 327 return true; |
| 322 | 328 |
| 329 scoped_ptr<ResourceHandler> handler(MaybeInterceptAsStream()); | |
| 330 if (handler) | |
| 331 return UseAlternateNextHandler(handler.Pass()); | |
| 332 | |
| 323 #if defined(ENABLE_PLUGINS) | 333 #if defined(ENABLE_PLUGINS) |
| 324 bool stale; | 334 bool stale; |
| 325 bool has_plugin = HasSupportingPlugin(&stale); | 335 bool has_plugin = HasSupportingPlugin(&stale); |
| 326 if (stale) { | 336 if (stale) { |
| 327 // Refresh the plugins asynchronously. | 337 // Refresh the plugins asynchronously. |
| 328 PluginServiceImpl::GetInstance()->GetPlugins( | 338 PluginServiceImpl::GetInstance()->GetPlugins( |
| 329 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, | 339 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, |
| 330 weak_ptr_factory_.GetWeakPtr())); | 340 weak_ptr_factory_.GetWeakPtr())); |
| 331 *defer = true; | 341 *defer = true; |
| 332 return true; | 342 return true; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 next_handler_->OnResponseCompleted(request_id, status, std::string()); | 385 next_handler_->OnResponseCompleted(request_id, status, std::string()); |
| 376 | 386 |
| 377 // This is handled entirely within the new ResourceHandler, so just reset the | 387 // This is handled entirely within the new ResourceHandler, so just reset the |
| 378 // original ResourceHandler. | 388 // original ResourceHandler. |
| 379 next_handler_ = new_handler.Pass(); | 389 next_handler_ = new_handler.Pass(); |
| 380 next_handler_->SetController(this); | 390 next_handler_->SetController(this); |
| 381 | 391 |
| 382 return CopyReadBufferToNextHandler(request_id); | 392 return CopyReadBufferToNextHandler(request_id); |
| 383 } | 393 } |
| 384 | 394 |
| 395 scoped_ptr<ResourceHandler> BufferedResourceHandler::MaybeInterceptAsStream() { | |
| 396 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_); | |
| 397 const std::string& mime_type = response_->head.mime_type; | |
| 398 | |
| 399 GURL security_origin; | |
| 400 std::string target_id; | |
| 401 if (host_->delegate() && | |
| 402 host_->delegate()->ShouldInterceptResourceAsStream(info->GetContext(), | |
|
darin (slow to review)
2013/03/19 06:12:51
nit: return early to reduce overall indentation
Zachary Kuznia
2013/03/19 06:59:35
Done.
| |
| 403 request_->url(), | |
| 404 mime_type, | |
| 405 &security_origin, | |
| 406 &target_id)) { | |
| 407 StreamContext* stream_context = | |
|
darin (slow to review)
2013/03/19 06:12:51
you might consider modeling this code after Create
Zachary Kuznia
2013/03/19 06:59:35
Done.
| |
| 408 GetStreamContextForResourceContext(info->GetContext()); | |
| 409 | |
| 410 | |
| 411 scoped_ptr<StreamResourceHandler> handler( | |
| 412 new StreamResourceHandler(request_, | |
| 413 stream_context->registry(), | |
| 414 security_origin)); | |
| 415 | |
| 416 info->set_is_stream(true); | |
| 417 host_->delegate()->OnStreamCreated( | |
| 418 info->GetContext(), | |
| 419 info->GetChildID(), | |
| 420 info->GetRouteID(), | |
| 421 target_id, | |
| 422 handler->stream()->CreateHandle(), | |
| 423 mime_type, | |
| 424 request_->url()); | |
| 425 return (scoped_ptr<ResourceHandler>(handler.release())).Pass(); | |
| 426 } | |
| 427 return scoped_ptr<ResourceHandler>(); | |
| 428 } | |
| 429 | |
| 385 bool BufferedResourceHandler::ReplayReadCompleted(bool* defer) { | 430 bool BufferedResourceHandler::ReplayReadCompleted(bool* defer) { |
| 386 DCHECK(read_buffer_); | 431 DCHECK(read_buffer_); |
| 387 | 432 |
| 388 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID(); | 433 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID(); |
| 389 bool result = next_handler_->OnReadCompleted(request_id, bytes_read_, defer); | 434 bool result = next_handler_->OnReadCompleted(request_id, bytes_read_, defer); |
| 390 | 435 |
| 391 read_buffer_ = NULL; | 436 read_buffer_ = NULL; |
| 392 read_buffer_size_ = 0; | 437 read_buffer_size_ = 0; |
| 393 bytes_read_ = 0; | 438 bytes_read_ = 0; |
| 394 | 439 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 const std::vector<webkit::WebPluginInfo>& plugins) { | 503 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 459 bool defer = false; | 504 bool defer = false; |
| 460 if (!ProcessResponse(&defer)) { | 505 if (!ProcessResponse(&defer)) { |
| 461 controller()->Cancel(); | 506 controller()->Cancel(); |
| 462 } else if (!defer) { | 507 } else if (!defer) { |
| 463 controller()->Resume(); | 508 controller()->Resume(); |
| 464 } | 509 } |
| 465 } | 510 } |
| 466 | 511 |
| 467 } // namespace content | 512 } // namespace content |
| OLD | NEW |