Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: content/browser/renderer_host/buffered_resource_handler.cc

Issue 7980011: Convert the PluginService interface to be an async wrapper around PluginList. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New interface as discussed Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "webkit/plugins/webplugininfo.h"
27 28
28 namespace { 29 namespace {
29 30
30 void RecordSnifferMetrics(bool sniffing_blocked, 31 void RecordSnifferMetrics(bool sniffing_blocked,
31 bool we_would_like_to_sniff, 32 bool we_would_like_to_sniff,
32 const std::string& mime_type) { 33 const std::string& mime_type) {
33 static base::Histogram* nosniff_usage(NULL); 34 static base::Histogram* nosniff_usage(NULL);
34 if (!nosniff_usage) 35 if (!nosniff_usage)
35 nosniff_usage = base::BooleanHistogram::FactoryGet( 36 nosniff_usage = base::BooleanHistogram::FactoryGet(
36 "nosniff.usage", base::Histogram::kUmaTargetedHistogramFlag); 37 "nosniff.usage", base::Histogram::kUmaTargetedHistogramFlag);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 bool BufferedResourceHandler::ShouldWaitForPlugins() { 336 bool BufferedResourceHandler::ShouldWaitForPlugins() {
336 bool need_plugin_list; 337 bool need_plugin_list;
337 if (!ShouldDownload(&need_plugin_list) || !need_plugin_list) 338 if (!ShouldDownload(&need_plugin_list) || !need_plugin_list)
338 return false; 339 return false;
339 340
340 // We don't want to keep buffering as our buffer will fill up. 341 // We don't want to keep buffering as our buffer will fill up.
341 ResourceDispatcherHostRequestInfo* info = 342 ResourceDispatcherHostRequestInfo* info =
342 ResourceDispatcherHost::InfoForRequest(request_); 343 ResourceDispatcherHost::InfoForRequest(request_);
343 host_->PauseRequest(info->child_id(), info->request_id(), true); 344 host_->PauseRequest(info->child_id(), info->request_id(), true);
344 345
345 // Schedule plugin loading on the file thread. 346 // Get the plugins asynchronously.
346 BrowserThread::PostTask( 347 PluginService::GetInstance()->LoadPluginList(false,
347 BrowserThread::FILE, FROM_HERE, 348 base::Bind(&BufferedResourceHandler::OnPluginsLoaded, this));
348 NewRunnableMethod(this, &BufferedResourceHandler::LoadPlugins));
349 return true; 349 return true;
350 } 350 }
351 351
352 // This test mirrors the decision that WebKit makes in 352 // This test mirrors the decision that WebKit makes in
353 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType. 353 // WebFrameLoaderClient::dispatchDecidePolicyForMIMEType.
354 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) { 354 bool BufferedResourceHandler::ShouldDownload(bool* need_plugin_list) {
355 if (need_plugin_list) 355 if (need_plugin_list)
356 *need_plugin_list = false; 356 *need_plugin_list = false;
357 std::string type = StringToLowerASCII(response_->response_head.mime_type); 357 std::string type = StringToLowerASCII(response_->response_head.mime_type);
358 std::string disposition; 358 std::string disposition;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // Remove the non-owning pointer to the CrossSiteResourceHandler, if any, 444 // Remove the non-owning pointer to the CrossSiteResourceHandler, if any,
445 // from the extra request info because the CrossSiteResourceHandler (part of 445 // from the extra request info because the CrossSiteResourceHandler (part of
446 // the original ResourceHandler chain) will be deleted by the next statement. 446 // the original ResourceHandler chain) will be deleted by the next statement.
447 info->set_cross_site_handler(NULL); 447 info->set_cross_site_handler(NULL);
448 448
449 // This is handled entirely within the new ResourceHandler, so just reset the 449 // This is handled entirely within the new ResourceHandler, so just reset the
450 // original ResourceHandler. 450 // original ResourceHandler.
451 real_handler_ = handler; 451 real_handler_ = handler;
452 } 452 }
453 453
454 void BufferedResourceHandler::LoadPlugins() {
455 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() { 454 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698