| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/buffered_resource_handler.h" | 5 #include "chrome/browser/renderer_host/buffered_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "net/base/mime_sniffer.h" | 8 #include "net/base/mime_sniffer.h" |
| 9 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" | 9 #include "chrome/browser/renderer_host/download_throttling_resource_handler.h" |
| 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 10 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 bool BufferedResourceHandler::OnResponseStarted(int request_id, | 62 bool BufferedResourceHandler::OnResponseStarted(int request_id, |
| 63 ResourceResponse* response) { | 63 ResourceResponse* response) { |
| 64 response_ = response; | 64 response_ = response; |
| 65 if (!DelayResponse()) | 65 if (!DelayResponse()) |
| 66 return CompleteResponseStarted(request_id, false); | 66 return CompleteResponseStarted(request_id, false); |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 bool BufferedResourceHandler::OnResponseCompleted( | 71 bool BufferedResourceHandler::OnResponseCompleted( |
| 72 int request_id, const URLRequestStatus& status) { | 72 int request_id, |
| 73 return real_handler_->OnResponseCompleted(request_id, status); | 73 const URLRequestStatus& status, |
| 74 const std::string& security_info) { |
| 75 return real_handler_->OnResponseCompleted(request_id, status, security_info); |
| 74 } | 76 } |
| 75 | 77 |
| 76 // We'll let the original event handler provide a buffer, and reuse it for | 78 // We'll let the original event handler provide a buffer, and reuse it for |
| 77 // subsequent reads until we're done buffering. | 79 // subsequent reads until we're done buffering. |
| 78 bool BufferedResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, | 80 bool BufferedResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, |
| 79 int* buf_size, int min_size) { | 81 int* buf_size, int min_size) { |
| 80 if (buffering_) { | 82 if (buffering_) { |
| 81 DCHECK(!my_buffer_.get()); | 83 DCHECK(!my_buffer_.get()); |
| 82 my_buffer_ = new net::IOBuffer(kMaxBytesToSniff); | 84 my_buffer_ = new net::IOBuffer(kMaxBytesToSniff); |
| 83 *buf = my_buffer_.get(); | 85 *buf = my_buffer_.get(); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 if (info->allow_download && | 234 if (info->allow_download && |
| 233 host_->ShouldDownload(response_->response_head.mime_type, | 235 host_->ShouldDownload(response_->response_head.mime_type, |
| 234 content_disposition)) { | 236 content_disposition)) { |
| 235 if (response_->response_head.headers && // Can be NULL if FTP. | 237 if (response_->response_head.headers && // Can be NULL if FTP. |
| 236 response_->response_head.headers->response_code() / 100 != 2) { | 238 response_->response_head.headers->response_code() / 100 != 2) { |
| 237 // The response code indicates that this is an error page, but we don't | 239 // The response code indicates that this is an error page, but we don't |
| 238 // know how to display the content. We follow Firefox here and show our | 240 // know how to display the content. We follow Firefox here and show our |
| 239 // own error page instead of triggering a download. | 241 // own error page instead of triggering a download. |
| 240 // TODO(abarth): We should abstract the response_code test, but this kind | 242 // TODO(abarth): We should abstract the response_code test, but this kind |
| 241 // of check is scattered throughout our codebase. | 243 // of check is scattered throughout our codebase. |
| 242 request_->CancelWithError(net::ERR_FILE_NOT_FOUND); | 244 request_->SimulateError(net::ERR_FILE_NOT_FOUND); |
| 243 return false; | 245 return false; |
| 244 } | 246 } |
| 245 | 247 |
| 246 info->is_download = true; | 248 info->is_download = true; |
| 247 | 249 |
| 248 scoped_refptr<DownloadThrottlingResourceHandler> download_handler = | 250 scoped_refptr<DownloadThrottlingResourceHandler> download_handler = |
| 249 new DownloadThrottlingResourceHandler(host_, | 251 new DownloadThrottlingResourceHandler(host_, |
| 250 request_, | 252 request_, |
| 251 request_->url(), | 253 request_->url(), |
| 252 info->render_process_host_id, | 254 info->render_process_host_id, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 270 real_handler_ = download_handler; | 272 real_handler_ = download_handler; |
| 271 } | 273 } |
| 272 return real_handler_->OnResponseStarted(request_id, response_); | 274 return real_handler_->OnResponseStarted(request_id, response_); |
| 273 } | 275 } |
| 274 | 276 |
| 275 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) { | 277 bool BufferedResourceHandler::DidBufferEnough(int bytes_read) { |
| 276 const int kRequiredLength = 256; | 278 const int kRequiredLength = 256; |
| 277 | 279 |
| 278 return bytes_read >= kRequiredLength; | 280 return bytes_read >= kRequiredLength; |
| 279 } | 281 } |
| OLD | NEW |