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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 2005273002: Move MimeTypeResourceHandler before ThrottlingResourceHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing file Created 4 years, 4 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
OLDNEW
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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "content/browser/download/download_resource_handler.h" 42 #include "content/browser/download/download_resource_handler.h"
43 #include "content/browser/download/save_file_manager.h" 43 #include "content/browser/download/save_file_manager.h"
44 #include "content/browser/download/save_file_resource_handler.h" 44 #include "content/browser/download/save_file_resource_handler.h"
45 #include "content/browser/frame_host/frame_tree.h" 45 #include "content/browser/frame_host/frame_tree.h"
46 #include "content/browser/frame_host/navigation_request_info.h" 46 #include "content/browser/frame_host/navigation_request_info.h"
47 #include "content/browser/frame_host/navigator.h" 47 #include "content/browser/frame_host/navigator.h"
48 #include "content/browser/loader/async_resource_handler.h" 48 #include "content/browser/loader/async_resource_handler.h"
49 #include "content/browser/loader/async_revalidation_manager.h" 49 #include "content/browser/loader/async_revalidation_manager.h"
50 #include "content/browser/loader/cross_site_resource_handler.h" 50 #include "content/browser/loader/cross_site_resource_handler.h"
51 #include "content/browser/loader/detachable_resource_handler.h" 51 #include "content/browser/loader/detachable_resource_handler.h"
52 #include "content/browser/loader/intercepting_resource_handler.h"
52 #include "content/browser/loader/loader_delegate.h" 53 #include "content/browser/loader/loader_delegate.h"
53 #include "content/browser/loader/mime_type_resource_handler.h" 54 #include "content/browser/loader/mime_sniffing_resource_handler.h"
54 #include "content/browser/loader/navigation_resource_handler.h" 55 #include "content/browser/loader/navigation_resource_handler.h"
55 #include "content/browser/loader/navigation_resource_throttle.h" 56 #include "content/browser/loader/navigation_resource_throttle.h"
56 #include "content/browser/loader/navigation_url_loader_impl_core.h" 57 #include "content/browser/loader/navigation_url_loader_impl_core.h"
57 #include "content/browser/loader/power_save_block_resource_throttle.h" 58 #include "content/browser/loader/power_save_block_resource_throttle.h"
58 #include "content/browser/loader/redirect_to_file_resource_handler.h" 59 #include "content/browser/loader/redirect_to_file_resource_handler.h"
59 #include "content/browser/loader/resource_message_filter.h" 60 #include "content/browser/loader/resource_message_filter.h"
60 #include "content/browser/loader/resource_request_info_impl.h" 61 #include "content/browser/loader/resource_request_info_impl.h"
61 #include "content/browser/loader/stream_resource_handler.h" 62 #include "content/browser/loader/stream_resource_handler.h"
62 #include "content/browser/loader/sync_resource_handler.h" 63 #include "content/browser/loader/sync_resource_handler.h"
63 #include "content/browser/loader/throttling_resource_handler.h" 64 #include "content/browser/loader/throttling_resource_handler.h"
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 std::unique_ptr<ResourceHandler> handler) { 1650 std::unique_ptr<ResourceHandler> handler) {
1650 // PlzNavigate: do not add ResourceThrottles for main resource requests from 1651 // PlzNavigate: do not add ResourceThrottles for main resource requests from
1651 // the renderer. Decisions about the navigation should have been done in the 1652 // the renderer. Decisions about the navigation should have been done in the
1652 // initial request. 1653 // initial request.
1653 if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type) && 1654 if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type) &&
1654 child_id != -1) { 1655 child_id != -1) {
1655 DCHECK(request->url().SchemeIs(url::kBlobScheme)); 1656 DCHECK(request->url().SchemeIs(url::kBlobScheme));
1656 return handler; 1657 return handler;
1657 } 1658 }
1658 1659
1659 PluginService* plugin_service = nullptr; 1660 // The InterceptingResourceHandler will replace its next handler with an
1660 #if defined(ENABLE_PLUGINS) 1661 // appropriate one based on the MIME type of the response if needed. It
1661 plugin_service = PluginService::GetInstance(); 1662 // should be placed at the end of the chain, just before |handler|.
1662 #endif 1663 handler.reset(new InterceptingResourceHandler(std::move(handler), request));
1663 // Insert a buffered event handler before the actual one. 1664 InterceptingResourceHandler* intercepting_handler =
1664 handler.reset(new MimeTypeResourceHandler(std::move(handler), this, 1665 static_cast<InterceptingResourceHandler*>(handler.get());
1665 plugin_service, request));
1666 1666
1667 ScopedVector<ResourceThrottle> throttles; 1667 ScopedVector<ResourceThrottle> throttles;
1668 1668
1669 // Add a NavigationResourceThrottle for navigations. 1669 // Add a NavigationResourceThrottle for navigations.
1670 // PlzNavigate: the throttle is unnecessary as communication with the UI 1670 // PlzNavigate: the throttle is unnecessary as communication with the UI
1671 // thread is handled by the NavigationURLloader. 1671 // thread is handled by the NavigationURLloader.
1672 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) 1672 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type))
1673 throttles.push_back(new NavigationResourceThrottle(request, delegate())); 1673 throttles.push_back(new NavigationResourceThrottle(request, delegate()));
1674 1674
1675 if (delegate_) { 1675 if (delegate_) {
(...skipping 10 matching lines...) Expand all
1686 request->url().host(), 1686 request->url().host(),
1687 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), 1687 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI),
1688 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); 1688 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)));
1689 } 1689 }
1690 1690
1691 // TODO(ricea): Stop looking this up so much. 1691 // TODO(ricea): Stop looking this up so much.
1692 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 1692 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
1693 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, 1693 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id,
1694 info->IsAsync(), request)); 1694 info->IsAsync(), request));
1695 1695
1696 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, 1696 // Split the handler in two groups: the ones that need to execute
1697 std::move(throttles))); 1697 // WillProcessResponse before mime sniffing and the others.
1698 // TODO(clamy): ScopedVector is deprecated. The interface should be changed
1699 // to use vectors instead.
1700 ScopedVector<ResourceThrottle> pre_mime_sniffing_throttles;
1701 ScopedVector<ResourceThrottle> post_mime_sniffing_throttles;
1702 for (auto throttle : throttles) {
1703 if (throttle->MustProcessResponseBeforeMimeSniffing())
1704 pre_mime_sniffing_throttles.push_back(throttle);
1705 else
1706 post_mime_sniffing_throttles.push_back(throttle);
mmenke 2016/07/27 19:34:01 nit: Use braces with else-if.
clamy 2016/08/17 12:47:35 Done.
1707 }
1708 throttles.weak_clear();
1709
1710 // Add the post mime sniffing throttles.
1711 handler.reset(new ThrottlingResourceHandler(
1712 std::move(handler), request, std::move(post_mime_sniffing_throttles)));
1713
1714 PluginService* plugin_service = nullptr;
1715 #if defined(ENABLE_PLUGINS)
1716 plugin_service = PluginService::GetInstance();
1717 #endif
1718
1719 // Insert a buffered event handler to sniff the mime type.
1720 // Note: all ResourceHandler following the MimeSniffingResourceHandler should
1721 // expect OnWillRead to be called *before* OnResponseStarted as part of the
1722 // mime sniffing process.
1723 handler.reset(new MimeSniffingResourceHandler(
1724 std::move(handler), this, plugin_service, intercepting_handler, request));
1725
1726 // Add the pre mime sniffing throttles.
1727 handler.reset(new ThrottlingResourceHandler(
1728 std::move(handler), request, std::move(pre_mime_sniffing_throttles)));
1698 1729
1699 return handler; 1730 return handler;
1700 } 1731 }
1701 1732
1702 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { 1733 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) {
1703 UnregisterDownloadedTempFile(filter_->child_id(), request_id); 1734 UnregisterDownloadedTempFile(filter_->child_id(), request_id);
1704 } 1735 }
1705 1736
1706 void ResourceDispatcherHostImpl::OnDidChangePriority( 1737 void ResourceDispatcherHostImpl::OnDidChangePriority(
1707 int request_id, 1738 int request_id,
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2627 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2597 response->head.security_info = SerializeSecurityInfo(ssl); 2628 response->head.security_info = SerializeSecurityInfo(ssl);
2598 } 2629 }
2599 2630
2600 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2631 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2601 return cert_store_for_testing_ ? cert_store_for_testing_ 2632 return cert_store_for_testing_ ? cert_store_for_testing_
2602 : CertStore::GetInstance(); 2633 : CertStore::GetInstance();
2603 } 2634 }
2604 2635
2605 } // namespace content 2636 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698