| 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/strings/string_util.h" | 12 #include "base/strings/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/plugin_service_impl.h" | 18 #include "content/browser/plugin_service_impl.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/download_item.h" | 20 #include "content/public/browser/download_item.h" |
| 21 #include "content/public/browser/download_save_info.h" | 21 #include "content/public/browser/download_save_info.h" |
| 22 #include "content/public/browser/download_url_parameters.h" | 22 #include "content/public/browser/download_url_parameters.h" |
| 23 #include "content/public/browser/resource_context.h" | 23 #include "content/public/browser/resource_context.h" |
| 24 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 24 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 25 #include "content/public/common/resource_response.h" | 25 #include "content/public/common/resource_response.h" |
| 26 #include "content/public/common/webplugininfo.h" |
| 26 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
| 27 #include "net/base/mime_sniffer.h" | 28 #include "net/base/mime_sniffer.h" |
| 28 #include "net/base/mime_util.h" | 29 #include "net/base/mime_util.h" |
| 29 #include "net/base/net_errors.h" | 30 #include "net/base/net_errors.h" |
| 30 #include "net/http/http_content_disposition.h" | 31 #include "net/http/http_content_disposition.h" |
| 31 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 32 #include "webkit/plugins/webplugininfo.h" | |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 void RecordSnifferMetrics(bool sniffing_blocked, | 38 void RecordSnifferMetrics(bool sniffing_blocked, |
| 39 bool we_would_like_to_sniff, | 39 bool we_would_like_to_sniff, |
| 40 const std::string& mime_type) { | 40 const std::string& mime_type) { |
| 41 static base::HistogramBase* nosniff_usage(NULL); | 41 static base::HistogramBase* nosniff_usage(NULL); |
| 42 if (!nosniff_usage) | 42 if (!nosniff_usage) |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 must_download_ = false; | 432 must_download_ = false; |
| 433 } | 433 } |
| 434 | 434 |
| 435 return must_download_; | 435 return must_download_; |
| 436 } | 436 } |
| 437 | 437 |
| 438 bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) { | 438 bool BufferedResourceHandler::HasSupportingPlugin(bool* stale) { |
| 439 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_); | 439 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_); |
| 440 | 440 |
| 441 bool allow_wildcard = false; | 441 bool allow_wildcard = false; |
| 442 webkit::WebPluginInfo plugin; | 442 WebPluginInfo plugin; |
| 443 return PluginServiceImpl::GetInstance()->GetPluginInfo( | 443 return PluginServiceImpl::GetInstance()->GetPluginInfo( |
| 444 info->GetChildID(), info->GetRouteID(), info->GetContext(), | 444 info->GetChildID(), info->GetRouteID(), info->GetContext(), |
| 445 request_->url(), GURL(), response_->head.mime_type, allow_wildcard, | 445 request_->url(), GURL(), response_->head.mime_type, allow_wildcard, |
| 446 stale, &plugin, NULL); | 446 stale, &plugin, NULL); |
| 447 } | 447 } |
| 448 | 448 |
| 449 bool BufferedResourceHandler::CopyReadBufferToNextHandler(int request_id) { | 449 bool BufferedResourceHandler::CopyReadBufferToNextHandler(int request_id) { |
| 450 if (!bytes_read_) | 450 if (!bytes_read_) |
| 451 return true; | 451 return true; |
| 452 | 452 |
| 453 net::IOBuffer* buf = NULL; | 453 net::IOBuffer* buf = NULL; |
| 454 int buf_len = 0; | 454 int buf_len = 0; |
| 455 if (!next_handler_->OnWillRead(request_id, &buf, &buf_len, bytes_read_)) | 455 if (!next_handler_->OnWillRead(request_id, &buf, &buf_len, bytes_read_)) |
| 456 return false; | 456 return false; |
| 457 | 457 |
| 458 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0)); | 458 CHECK((buf_len >= bytes_read_) && (bytes_read_ >= 0)); |
| 459 memcpy(buf->data(), read_buffer_->data(), bytes_read_); | 459 memcpy(buf->data(), read_buffer_->data(), bytes_read_); |
| 460 return true; | 460 return true; |
| 461 } | 461 } |
| 462 | 462 |
| 463 void BufferedResourceHandler::OnPluginsLoaded( | 463 void BufferedResourceHandler::OnPluginsLoaded( |
| 464 const std::vector<webkit::WebPluginInfo>& plugins) { | 464 const std::vector<WebPluginInfo>& plugins) { |
| 465 bool defer = false; | 465 bool defer = false; |
| 466 if (!ProcessResponse(&defer)) { | 466 if (!ProcessResponse(&defer)) { |
| 467 controller()->Cancel(); | 467 controller()->Cancel(); |
| 468 } else if (!defer) { | 468 } else if (!defer) { |
| 469 controller()->Resume(); | 469 controller()->Resume(); |
| 470 } | 470 } |
| 471 } | 471 } |
| 472 | 472 |
| 473 } // namespace content | 473 } // namespace content |
| OLD | NEW |