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" |
24 #include "content/public/common/resource_response.h" | 29 #include "content/public/common/resource_response.h" |
25 #include "net/base/io_buffer.h" | 30 #include "net/base/io_buffer.h" |
26 #include "net/base/mime_sniffer.h" | 31 #include "net/base/mime_sniffer.h" |
27 #include "net/base/mime_util.h" | 32 #include "net/base/mime_util.h" |
28 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 318 } |
314 | 319 |
315 if (!info->allow_download()) | 320 if (!info->allow_download()) |
316 return true; | 321 return true; |
317 | 322 |
318 bool must_download = MustDownload(); | 323 bool must_download = MustDownload(); |
319 if (!must_download) { | 324 if (!must_download) { |
320 if (net::IsSupportedMimeType(mime_type)) | 325 if (net::IsSupportedMimeType(mime_type)) |
321 return true; | 326 return true; |
322 | 327 |
| 328 scoped_ptr<ResourceHandler> handler(MaybeInterceptAsStream()); |
| 329 if (handler) |
| 330 return UseAlternateNextHandler(handler.Pass()); |
| 331 |
323 #if defined(ENABLE_PLUGINS) | 332 #if defined(ENABLE_PLUGINS) |
324 bool stale; | 333 bool stale; |
325 bool has_plugin = HasSupportingPlugin(&stale); | 334 bool has_plugin = HasSupportingPlugin(&stale); |
326 if (stale) { | 335 if (stale) { |
327 // Refresh the plugins asynchronously. | 336 // Refresh the plugins asynchronously. |
328 PluginServiceImpl::GetInstance()->GetPlugins( | 337 PluginServiceImpl::GetInstance()->GetPlugins( |
329 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, | 338 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, |
330 weak_ptr_factory_.GetWeakPtr())); | 339 weak_ptr_factory_.GetWeakPtr())); |
331 *defer = true; | 340 *defer = true; |
332 return true; | 341 return true; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 next_handler_->OnResponseCompleted(request_id, status, std::string()); | 384 next_handler_->OnResponseCompleted(request_id, status, std::string()); |
376 | 385 |
377 // This is handled entirely within the new ResourceHandler, so just reset the | 386 // This is handled entirely within the new ResourceHandler, so just reset the |
378 // original ResourceHandler. | 387 // original ResourceHandler. |
379 next_handler_ = new_handler.Pass(); | 388 next_handler_ = new_handler.Pass(); |
380 next_handler_->SetController(this); | 389 next_handler_->SetController(this); |
381 | 390 |
382 return CopyReadBufferToNextHandler(request_id); | 391 return CopyReadBufferToNextHandler(request_id); |
383 } | 392 } |
384 | 393 |
| 394 scoped_ptr<ResourceHandler> BufferedResourceHandler::MaybeInterceptAsStream() { |
| 395 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_); |
| 396 const std::string& mime_type = response_->head.mime_type; |
| 397 |
| 398 GURL security_origin; |
| 399 std::string target_id; |
| 400 if (host_->delegate() && |
| 401 host_->delegate()->ShouldInterceptResourceAsStream(info->GetContext(), |
| 402 request_->url(), |
| 403 mime_type, |
| 404 &security_origin, |
| 405 &target_id)) { |
| 406 StreamContext* stream_context = |
| 407 GetStreamContextForResourceContext(info->GetContext()); |
| 408 |
| 409 |
| 410 scoped_ptr<StreamResourceHandler> handler( |
| 411 new StreamResourceHandler(request_, |
| 412 stream_context->registry(), |
| 413 security_origin)); |
| 414 |
| 415 info->set_is_stream(true); |
| 416 host_->delegate()->OnStreamCreated( |
| 417 info->GetContext(), |
| 418 info->GetChildID(), |
| 419 info->GetRouteID(), |
| 420 target_id, |
| 421 handler->stream()->url(), |
| 422 mime_type, |
| 423 request_->url()); |
| 424 return (scoped_ptr<ResourceHandler>(handler.release())).Pass(); |
| 425 } |
| 426 return scoped_ptr<ResourceHandler>(); |
| 427 } |
| 428 |
385 bool BufferedResourceHandler::ReplayReadCompleted(bool* defer) { | 429 bool BufferedResourceHandler::ReplayReadCompleted(bool* defer) { |
386 DCHECK(read_buffer_); | 430 DCHECK(read_buffer_); |
387 | 431 |
388 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID(); | 432 int request_id = ResourceRequestInfo::ForRequest(request_)->GetRequestID(); |
389 bool result = next_handler_->OnReadCompleted(request_id, bytes_read_, defer); | 433 bool result = next_handler_->OnReadCompleted(request_id, bytes_read_, defer); |
390 | 434 |
391 read_buffer_ = NULL; | 435 read_buffer_ = NULL; |
392 read_buffer_size_ = 0; | 436 read_buffer_size_ = 0; |
393 bytes_read_ = 0; | 437 bytes_read_ = 0; |
394 | 438 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const std::vector<webkit::WebPluginInfo>& plugins) { | 502 const std::vector<webkit::WebPluginInfo>& plugins) { |
459 bool defer = false; | 503 bool defer = false; |
460 if (!ProcessResponse(&defer)) { | 504 if (!ProcessResponse(&defer)) { |
461 controller()->Cancel(); | 505 controller()->Cancel(); |
462 } else if (!defer) { | 506 } else if (!defer) { |
463 controller()->Resume(); | 507 controller()->Resume(); |
464 } | 508 } |
465 } | 509 } |
466 | 510 |
467 } // namespace content | 511 } // namespace content |
OLD | NEW |