OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer_host/buffered_resource_handler.h" | 5 #include "content/browser/renderer_host/buffered_resource_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
13 #include "content/browser/content_browser_client.h" | 14 #include "content/browser/content_browser_client.h" |
14 #include "content/browser/download/download_resource_handler.h" | 15 #include "content/browser/download/download_resource_handler.h" |
15 #include "content/browser/plugin_service.h" | 16 #include "content/browser/plugin_service.h" |
16 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 17 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
17 #include "content/browser/renderer_host/resource_dispatcher_host_delegate.h" | 18 #include "content/browser/renderer_host/resource_dispatcher_host_delegate.h" |
18 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 19 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
19 #include "content/browser/renderer_host/x509_user_cert_resource_handler.h" | 20 #include "content/browser/renderer_host/x509_user_cert_resource_handler.h" |
20 #include "content/browser/resource_context.h" | 21 #include "content/browser/resource_context.h" |
21 #include "content/common/resource_response.h" | 22 #include "content/common/resource_response.h" |
22 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
23 #include "net/base/mime_sniffer.h" | 24 #include "net/base/mime_sniffer.h" |
24 #include "net/base/mime_util.h" | 25 #include "net/base/mime_util.h" |
25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
26 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
27 #include "webkit/plugins/npapi/plugin_list.h" | 28 #include "webkit/plugins/webplugininfo.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 void RecordSnifferMetrics(bool sniffing_blocked, | 32 void RecordSnifferMetrics(bool sniffing_blocked, |
32 bool we_would_like_to_sniff, | 33 bool we_would_like_to_sniff, |
33 const std::string& mime_type) { | 34 const std::string& mime_type) { |
34 static base::Histogram* nosniff_usage(NULL); | 35 static base::Histogram* nosniff_usage(NULL); |
35 if (!nosniff_usage) | 36 if (!nosniff_usage) |
36 nosniff_usage = base::BooleanHistogram::FactoryGet( | 37 nosniff_usage = base::BooleanHistogram::FactoryGet( |
37 "nosniff.usage", base::Histogram::kUmaTargetedHistogramFlag); | 38 "nosniff.usage", base::Histogram::kUmaTargetedHistogramFlag); |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 bool BufferedResourceHandler::ShouldWaitForPlugins() { | 340 bool BufferedResourceHandler::ShouldWaitForPlugins() { |
340 bool need_plugin_list; | 341 bool need_plugin_list; |
341 if (!ShouldDownload(&need_plugin_list) || !need_plugin_list) | 342 if (!ShouldDownload(&need_plugin_list) || !need_plugin_list) |
342 return false; | 343 return false; |
343 | 344 |
344 // We don't want to keep buffering as our buffer will fill up. | 345 // We don't want to keep buffering as our buffer will fill up. |
345 ResourceDispatcherHostRequestInfo* info = | 346 ResourceDispatcherHostRequestInfo* info = |
346 ResourceDispatcherHost::InfoForRequest(request_); | 347 ResourceDispatcherHost::InfoForRequest(request_); |
347 host_->PauseRequest(info->child_id(), info->request_id(), true); | 348 host_->PauseRequest(info->child_id(), info->request_id(), true); |
348 | 349 |
349 // Schedule plugin loading on the file thread. | 350 // Get the plugins asynchronously. |
350 BrowserThread::PostTask( | 351 PluginService::GetInstance()->GetPlugins( |
351 BrowserThread::FILE, FROM_HERE, | 352 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, this)); |
352 NewRunnableMethod(this, &BufferedResourceHandler::LoadPlugins)); | |
353 return true; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 // This test mirrors the decision that WebKit makes in | 356 // This test mirrors the decision that WebKit makes in |
357 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType. | 357 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType. |
358 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { | 358 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { |
359 if (need_plugin_list) | 359 if (need_plugin_list) |
360 *need_plugin_list = false; | 360 *need_plugin_list = false; |
361 std::string type = StringToLowerASCII(response_->response_head.mime_type); | 361 std::string type = StringToLowerASCII(response_->response_head.mime_type); |
362 std::string disposition; | 362 std::string disposition; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 // Remove the non-owning pointer to the CrossSiteResourceHandler, if any, | 448 // Remove the non-owning pointer to the CrossSiteResourceHandler, if any, |
449 // from the extra request info because the CrossSiteResourceHandler (part of | 449 // from the extra request info because the CrossSiteResourceHandler (part of |
450 // the original ResourceHandler chain) will be deleted by the next statement. | 450 // the original ResourceHandler chain) will be deleted by the next statement. |
451 info->set_cross_site_handler(NULL); | 451 info->set_cross_site_handler(NULL); |
452 | 452 |
453 // This is handled entirely within the new ResourceHandler, so just reset the | 453 // This is handled entirely within the new ResourceHandler, so just reset the |
454 // original ResourceHandler. | 454 // original ResourceHandler. |
455 real_handler_ = handler; | 455 real_handler_ = handler; |
456 } | 456 } |
457 | 457 |
458 void BufferedResourceHandler::LoadPlugins() { | 458 void BufferedResourceHandler::OnPluginsLoaded( |
459 std::vector<webkit::WebPluginInfo> plugins; | 459 const std::vector<webkit::WebPluginInfo>& plugins) { |
460 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); | |
461 | |
462 BrowserThread::PostTask( | |
463 BrowserThread::IO, FROM_HERE, | |
464 NewRunnableMethod(this, &BufferedResourceHandler::OnPluginsLoaded)); | |
465 } | |
466 | |
467 void BufferedResourceHandler::OnPluginsLoaded() { | |
468 wait_for_plugins_ = false; | 460 wait_for_plugins_ = false; |
469 if (!request_) | 461 if (!request_) |
470 return; | 462 return; |
471 | 463 |
472 ResourceDispatcherHostRequestInfo* info = | 464 ResourceDispatcherHostRequestInfo* info = |
473 ResourceDispatcherHost::InfoForRequest(request_); | 465 ResourceDispatcherHost::InfoForRequest(request_); |
474 host_->PauseRequest(info->child_id(), info->request_id(), false); | 466 host_->PauseRequest(info->child_id(), info->request_id(), false); |
475 if (!CompleteResponseStarted(info->request_id(), false)) | 467 if (!CompleteResponseStarted(info->request_id(), false)) |
476 host_->CancelRequest(info->child_id(), info->request_id(), false); | 468 host_->CancelRequest(info->child_id(), info->request_id(), false); |
477 } | 469 } |
OLD | NEW |