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 GURL security_origin; |
| 329 if (host_->delegate() && |
| 330 host_->delegate()->ShouldCreateStream(info->GetContext(), |
| 331 request_->url(), |
| 332 mime_type, |
| 333 &security_origin)) { |
| 334 StreamContext* stream_context = |
| 335 GetStreamContextForResourceContext(info->GetContext()); |
| 336 |
| 337 scoped_ptr<StreamResourceHandler> handler( |
| 338 new StreamResourceHandler(request_, |
| 339 stream_context->registry(), |
| 340 security_origin)); |
| 341 |
| 342 info->set_is_stream(true); |
| 343 host_->delegate()->OnStreamCreated( |
| 344 info->GetContext(), |
| 345 info->GetChildID(), |
| 346 info->GetRouteID(), |
| 347 handler->stream()->url(), |
| 348 mime_type, |
| 349 request_->url()); |
| 350 return UseAlternateNextHandler( |
| 351 (scoped_ptr<ResourceHandler>(handler.release())).Pass()); |
| 352 } |
| 353 |
323 #if defined(ENABLE_PLUGINS) | 354 #if defined(ENABLE_PLUGINS) |
324 bool stale; | 355 bool stale; |
325 bool has_plugin = HasSupportingPlugin(&stale); | 356 bool has_plugin = HasSupportingPlugin(&stale); |
326 if (stale) { | 357 if (stale) { |
327 // Refresh the plugins asynchronously. | 358 // Refresh the plugins asynchronously. |
328 PluginServiceImpl::GetInstance()->GetPlugins( | 359 PluginServiceImpl::GetInstance()->GetPlugins( |
329 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, | 360 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, |
330 weak_ptr_factory_.GetWeakPtr())); | 361 weak_ptr_factory_.GetWeakPtr())); |
331 *defer = true; | 362 *defer = true; |
332 return true; | 363 return true; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 const std::vector<webkit::WebPluginInfo>& plugins) { | 489 const std::vector<webkit::WebPluginInfo>& plugins) { |
459 bool defer = false; | 490 bool defer = false; |
460 if (!ProcessResponse(&defer)) { | 491 if (!ProcessResponse(&defer)) { |
461 controller()->Cancel(); | 492 controller()->Cancel(); |
462 } else if (!defer) { | 493 } else if (!defer) { |
463 controller()->Resume(); | 494 controller()->Resume(); |
464 } | 495 } |
465 } | 496 } |
466 | 497 |
467 } // namespace content | 498 } // namespace content |
OLD | NEW |