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 "components/mime_util/mime_util.h" |
13 #include "content/browser/download/download_resource_handler.h" | 14 #include "content/browser/download/download_resource_handler.h" |
14 #include "content/browser/download/download_stats.h" | 15 #include "content/browser/download/download_stats.h" |
15 #include "content/browser/loader/certificate_resource_handler.h" | 16 #include "content/browser/loader/certificate_resource_handler.h" |
16 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 17 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
17 #include "content/browser/loader/resource_request_info_impl.h" | 18 #include "content/browser/loader/resource_request_info_impl.h" |
18 #include "content/browser/loader/stream_resource_handler.h" | 19 #include "content/browser/loader/stream_resource_handler.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" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 290 |
290 return made_final_decision; | 291 return made_final_decision; |
291 } | 292 } |
292 | 293 |
293 bool BufferedResourceHandler::SelectNextHandler(bool* defer) { | 294 bool BufferedResourceHandler::SelectNextHandler(bool* defer) { |
294 DCHECK(!response_->head.mime_type.empty()); | 295 DCHECK(!response_->head.mime_type.empty()); |
295 | 296 |
296 ResourceRequestInfoImpl* info = GetRequestInfo(); | 297 ResourceRequestInfoImpl* info = GetRequestInfo(); |
297 const std::string& mime_type = response_->head.mime_type; | 298 const std::string& mime_type = response_->head.mime_type; |
298 | 299 |
299 if (net::IsSupportedCertificateMimeType(mime_type)) { | 300 if (mime_util::IsSupportedCertificateMimeType(mime_type)) { |
300 // Install certificate file. | 301 // Install certificate file. |
301 info->set_is_download(true); | 302 info->set_is_download(true); |
302 scoped_ptr<ResourceHandler> handler( | 303 scoped_ptr<ResourceHandler> handler( |
303 new CertificateResourceHandler(request())); | 304 new CertificateResourceHandler(request())); |
304 return UseAlternateNextHandler(handler.Pass(), std::string()); | 305 return UseAlternateNextHandler(handler.Pass(), std::string()); |
305 } | 306 } |
306 | 307 |
307 // Allow requests for object/embed tags to be intercepted as streams. | 308 // Allow requests for object/embed tags to be intercepted as streams. |
308 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { | 309 if (info->GetResourceType() == content::RESOURCE_TYPE_OBJECT) { |
309 DCHECK(!info->allow_download()); | 310 DCHECK(!info->allow_download()); |
310 std::string payload; | 311 std::string payload; |
311 scoped_ptr<ResourceHandler> handler( | 312 scoped_ptr<ResourceHandler> handler( |
312 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); | 313 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); |
313 if (handler) { | 314 if (handler) { |
314 DCHECK(!net::IsSupportedMimeType(mime_type)); | 315 DCHECK(!mime_util::IsSupportedMimeType(mime_type)); |
315 return UseAlternateNextHandler(handler.Pass(), payload); | 316 return UseAlternateNextHandler(handler.Pass(), payload); |
316 } | 317 } |
317 } | 318 } |
318 | 319 |
319 if (!info->allow_download()) | 320 if (!info->allow_download()) |
320 return true; | 321 return true; |
321 | 322 |
322 // info->allow_download() == true implies | 323 // info->allow_download() == true implies |
323 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or | 324 // info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME or |
324 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME. | 325 // info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME. |
325 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME || | 326 DCHECK(info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME || |
326 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME); | 327 info->GetResourceType() == RESOURCE_TYPE_SUB_FRAME); |
327 | 328 |
328 bool must_download = MustDownload(); | 329 bool must_download = MustDownload(); |
329 if (!must_download) { | 330 if (!must_download) { |
330 if (net::IsSupportedMimeType(mime_type)) | 331 if (mime_util::IsSupportedMimeType(mime_type)) |
331 return true; | 332 return true; |
332 | 333 |
333 std::string payload; | 334 std::string payload; |
334 scoped_ptr<ResourceHandler> handler( | 335 scoped_ptr<ResourceHandler> handler( |
335 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); | 336 host_->MaybeInterceptAsStream(request(), response_.get(), &payload)); |
336 if (handler) { | 337 if (handler) { |
337 return UseAlternateNextHandler(handler.Pass(), payload); | 338 return UseAlternateNextHandler(handler.Pass(), payload); |
338 } | 339 } |
339 | 340 |
340 #if defined(ENABLE_PLUGINS) | 341 #if defined(ENABLE_PLUGINS) |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 request()->LogUnblocked(); | 505 request()->LogUnblocked(); |
505 bool defer = false; | 506 bool defer = false; |
506 if (!ProcessResponse(&defer)) { | 507 if (!ProcessResponse(&defer)) { |
507 controller()->Cancel(); | 508 controller()->Cancel(); |
508 } else if (!defer) { | 509 } else if (!defer) { |
509 controller()->Resume(); | 510 controller()->Resume(); |
510 } | 511 } |
511 } | 512 } |
512 | 513 |
513 } // namespace content | 514 } // namespace content |
OLD | NEW |