| 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/loader/stream_resource_handler.h" | 18 #include "content/browser/loader/stream_resource_handler.h" |
| 19 #include "content/common/mime_util.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/download_item.h" | 21 #include "content/public/browser/download_item.h" |
| 21 #include "content/public/browser/download_save_info.h" | 22 #include "content/public/browser/download_save_info.h" |
| 22 #include "content/public/browser/download_url_parameters.h" | 23 #include "content/public/browser/download_url_parameters.h" |
| 23 #include "content/public/browser/plugin_service.h" | 24 #include "content/public/browser/plugin_service.h" |
| 24 #include "content/public/browser/resource_context.h" | 25 #include "content/public/browser/resource_context.h" |
| 25 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 26 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 26 #include "content/public/common/resource_response.h" | 27 #include "content/public/common/resource_response.h" |
| 27 #include "content/public/common/webplugininfo.h" | 28 #include "content/public/common/webplugininfo.h" |
| 28 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 return UseAlternateNextHandler(handler.Pass(), std::string()); | 312 return UseAlternateNextHandler(handler.Pass(), std::string()); |
| 312 } | 313 } |
| 313 | 314 |
| 314 // Allow requests for object/embed tags to be intercepted as streams. | 315 // Allow requests for object/embed tags to be intercepted as streams. |
| 315 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { | 316 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { |
| 316 DCHECK(!info->allow_download()); | 317 DCHECK(!info->allow_download()); |
| 317 std::string payload; | 318 std::string payload; |
| 318 scoped_ptr<ResourceHandler> handler( | 319 scoped_ptr<ResourceHandler> handler( |
| 319 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); | 320 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); |
| 320 if (handler) { | 321 if (handler) { |
| 321 DCHECK(!net::IsSupportedMimeType(mime_type)); | 322 DCHECK(!content::IsSupportedMimeType(mime_type)); |
| 322 return UseAlternateNextHandler(handler.Pass(), payload); | 323 return UseAlternateNextHandler(handler.Pass(), payload); |
| 323 } | 324 } |
| 324 } | 325 } |
| 325 | 326 |
| 326 if (!info->allow_download()) | 327 if (!info->allow_download()) |
| 327 return true; | 328 return true; |
| 328 | 329 |
| 329 // info->allow_download() == true implies | 330 // info->allow_download() == true implies |
| 330 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or | 331 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or |
| 331 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME. | 332 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME. |
| 332 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME || | 333 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME || |
| 333 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME); | 334 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME); |
| 334 | 335 |
| 335 bool must_download = MustDownload(); | 336 bool must_download = MustDownload(); |
| 336 if (!must_download) { | 337 if (!must_download) { |
| 337 if (net::IsSupportedMimeType(mime_type)) | 338 if (content::IsSupportedMimeType(mime_type)) |
| 338 return true; | 339 return true; |
| 339 | 340 |
| 340 std::string payload; | 341 std::string payload; |
| 341 scoped_ptr<ResourceHandler> handler( | 342 scoped_ptr<ResourceHandler> handler( |
| 342 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); | 343 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); |
| 343 if (handler) { | 344 if (handler) { |
| 344 return UseAlternateNextHandler(handler.Pass(), payload); | 345 return UseAlternateNextHandler(handler.Pass(), payload); |
| 345 } | 346 } |
| 346 | 347 |
| 347 #if defined(ENABLE_PLUGINS) | 348 #if defined(ENABLE_PLUGINS) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 request()->LogUnblocked(); | 512 request()->LogUnblocked(); |
| 512 bool defer = false; | 513 bool defer = false; |
| 513 if (!ProcessResponse(&defer)) { | 514 if (!ProcessResponse(&defer)) { |
| 514 controller()->Cancel(); | 515 controller()->Cancel(); |
| 515 } else if (!defer) { | 516 } else if (!defer) { |
| 516 controller()->Resume(); | 517 controller()->Resume(); |
| 517 } | 518 } |
| 518 } | 519 } |
| 519 | 520 |
| 520 } // namespace content | 521 } // namespace content |
| OLD | NEW |