| 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/common/resource_response.h" | 21 #include "content/common/resource_response.h" |
| 21 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 22 #include "net/base/mime_sniffer.h" | 23 #include "net/base/mime_sniffer.h" |
| 23 #include "net/base/mime_util.h" | 24 #include "net/base/mime_util.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 26 #include "webkit/plugins/npapi/plugin_list.h" | |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 void RecordSnifferMetrics(bool sniffing_blocked, | 30 void RecordSnifferMetrics(bool sniffing_blocked, |
| 31 bool we_would_like_to_sniff, | 31 bool we_would_like_to_sniff, |
| 32 const std::string& mime_type) { | 32 const std::string& mime_type) { |
| 33 static base::Histogram* nosniff_usage(NULL); | 33 static base::Histogram* nosniff_usage(NULL); |
| 34 if (!nosniff_usage) | 34 if (!nosniff_usage) |
| 35 nosniff_usage = base::BooleanHistogram::FactoryGet( | 35 nosniff_usage = base::BooleanHistogram::FactoryGet( |
| 36 "nosniff.usage", base::Histogram::kUmaTargetedHistogramFlag); | 36 "nosniff.usage", base::Histogram::kUmaTargetedHistogramFlag); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 bool BufferedResourceHandler::ShouldWaitForPlugins() { | 335 bool BufferedResourceHandler::ShouldWaitForPlugins() { |
| 336 bool need_plugin_list; | 336 bool need_plugin_list; |
| 337 if (!ShouldDownload(&need_plugin_list) || !need_plugin_list) | 337 if (!ShouldDownload(&need_plugin_list) || !need_plugin_list) |
| 338 return false; | 338 return false; |
| 339 | 339 |
| 340 // We don't want to keep buffering as our buffer will fill up. | 340 // We don't want to keep buffering as our buffer will fill up. |
| 341 ResourceDispatcherHostRequestInfo* info = | 341 ResourceDispatcherHostRequestInfo* info = |
| 342 ResourceDispatcherHost::InfoForRequest(request_); | 342 ResourceDispatcherHost::InfoForRequest(request_); |
| 343 host_->PauseRequest(info->child_id(), info->request_id(), true); | 343 host_->PauseRequest(info->child_id(), info->request_id(), true); |
| 344 | 344 |
| 345 // Schedule plugin loading on the file thread. | 345 // Get the plugins asynchronously. |
| 346 BrowserThread::PostTask( | 346 PluginService::GetInstance()->GetPlugins( |
| 347 BrowserThread::FILE, FROM_HERE, | 347 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, this)); |
| 348 NewRunnableMethod(this, &BufferedResourceHandler::LoadPlugins)); | |
| 349 return true; | 348 return true; |
| 350 } | 349 } |
| 351 | 350 |
| 352 // This test mirrors the decision that WebKit makes in | 351 // This test mirrors the decision that WebKit makes in |
| 353 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType. | 352 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType. |
| 354 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { | 353 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { |
| 355 if (need_plugin_list) | 354 if (need_plugin_list) |
| 356 *need_plugin_list = false; | 355 *need_plugin_list = false; |
| 357 std::string type = StringToLowerASCII(response_->response_head.mime_type); | 356 std::string type = StringToLowerASCII(response_->response_head.mime_type); |
| 358 std::string disposition; | 357 std::string disposition; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // Remove the non-owning pointer to the CrossSiteResourceHandler, if any, | 443 // Remove the non-owning pointer to the CrossSiteResourceHandler, if any, |
| 445 // from the extra request info because the CrossSiteResourceHandler (part of | 444 // from the extra request info because the CrossSiteResourceHandler (part of |
| 446 // the original ResourceHandler chain) will be deleted by the next statement. | 445 // the original ResourceHandler chain) will be deleted by the next statement. |
| 447 info->set_cross_site_handler(NULL); | 446 info->set_cross_site_handler(NULL); |
| 448 | 447 |
| 449 // This is handled entirely within the new ResourceHandler, so just reset the | 448 // This is handled entirely within the new ResourceHandler, so just reset the |
| 450 // original ResourceHandler. | 449 // original ResourceHandler. |
| 451 real_handler_ = handler; | 450 real_handler_ = handler; |
| 452 } | 451 } |
| 453 | 452 |
| 454 void BufferedResourceHandler::LoadPlugins() { | 453 void BufferedResourceHandler::OnPluginsLoaded( |
| 455 std::vector<webkit::WebPluginInfo> plugins; | 454 std::vector<webkit::WebPluginInfo> plugins) { |
| 456 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); | |
| 457 | |
| 458 BrowserThread::PostTask( | |
| 459 BrowserThread::IO, FROM_HERE, | |
| 460 NewRunnableMethod(this, &BufferedResourceHandler::OnPluginsLoaded)); | |
| 461 } | |
| 462 | |
| 463 void BufferedResourceHandler::OnPluginsLoaded() { | |
| 464 wait_for_plugins_ = false; | 455 wait_for_plugins_ = false; |
| 465 if (!request_) | 456 if (!request_) |
| 466 return; | 457 return; |
| 467 | 458 |
| 468 ResourceDispatcherHostRequestInfo* info = | 459 ResourceDispatcherHostRequestInfo* info = |
| 469 ResourceDispatcherHost::InfoForRequest(request_); | 460 ResourceDispatcherHost::InfoForRequest(request_); |
| 470 host_->PauseRequest(info->child_id(), info->request_id(), false); | 461 host_->PauseRequest(info->child_id(), info->request_id(), false); |
| 471 if (!CompleteResponseStarted(info->request_id(), false)) | 462 if (!CompleteResponseStarted(info->request_id(), false)) |
| 472 host_->CancelRequest(info->child_id(), info->request_id(), false); | 463 host_->CancelRequest(info->child_id(), info->request_id(), false); |
| 473 } | 464 } |
| OLD | NEW |