| 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 // 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 29 matching lines...) Expand all Loading... |
| 40 #include "content/browser/cert_store_impl.h" | 40 #include "content/browser/cert_store_impl.h" |
| 41 #include "content/browser/child_process_security_policy_impl.h" | 41 #include "content/browser/child_process_security_policy_impl.h" |
| 42 #include "content/browser/frame_host/frame_tree.h" | 42 #include "content/browser/frame_host/frame_tree.h" |
| 43 #include "content/browser/frame_host/navigation_handle_impl.h" | 43 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 44 #include "content/browser/frame_host/navigation_request_info.h" | 44 #include "content/browser/frame_host/navigation_request_info.h" |
| 45 #include "content/browser/frame_host/navigator.h" | 45 #include "content/browser/frame_host/navigator.h" |
| 46 #include "content/browser/loader/async_resource_handler.h" | 46 #include "content/browser/loader/async_resource_handler.h" |
| 47 #include "content/browser/loader/async_revalidation_manager.h" | 47 #include "content/browser/loader/async_revalidation_manager.h" |
| 48 #include "content/browser/loader/cross_site_resource_handler.h" | 48 #include "content/browser/loader/cross_site_resource_handler.h" |
| 49 #include "content/browser/loader/detachable_resource_handler.h" | 49 #include "content/browser/loader/detachable_resource_handler.h" |
| 50 #include "content/browser/loader/intercepting_resource_handler.h" |
| 50 #include "content/browser/loader/loader_delegate.h" | 51 #include "content/browser/loader/loader_delegate.h" |
| 51 #include "content/browser/loader/mime_type_resource_handler.h" | 52 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
| 52 #include "content/browser/loader/mojo_async_resource_handler.h" | 53 #include "content/browser/loader/mojo_async_resource_handler.h" |
| 53 #include "content/browser/loader/navigation_resource_handler.h" | 54 #include "content/browser/loader/navigation_resource_handler.h" |
| 54 #include "content/browser/loader/navigation_resource_throttle.h" | 55 #include "content/browser/loader/navigation_resource_throttle.h" |
| 55 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 56 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 56 #include "content/browser/loader/power_save_block_resource_throttle.h" | 57 #include "content/browser/loader/power_save_block_resource_throttle.h" |
| 57 #include "content/browser/loader/redirect_to_file_resource_handler.h" | 58 #include "content/browser/loader/redirect_to_file_resource_handler.h" |
| 58 #include "content/browser/loader/resource_message_filter.h" | 59 #include "content/browser/loader/resource_message_filter.h" |
| 59 #include "content/browser/loader/resource_request_info_impl.h" | 60 #include "content/browser/loader/resource_request_info_impl.h" |
| 60 #include "content/browser/loader/stream_resource_handler.h" | 61 #include "content/browser/loader/stream_resource_handler.h" |
| 61 #include "content/browser/loader/sync_resource_handler.h" | 62 #include "content/browser/loader/sync_resource_handler.h" |
| (...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1636 // the renderer. Decisions about the navigation should have been done in the | 1637 // the renderer. Decisions about the navigation should have been done in the |
| 1637 // initial request. | 1638 // initial request. |
| 1638 bool is_renderer = | 1639 bool is_renderer = |
| 1639 filter_ ? (filter_->process_type() == PROCESS_TYPE_RENDERER) : false; | 1640 filter_ ? (filter_->process_type() == PROCESS_TYPE_RENDERER) : false; |
| 1640 if (is_renderer && IsBrowserSideNavigationEnabled() && | 1641 if (is_renderer && IsBrowserSideNavigationEnabled() && |
| 1641 IsResourceTypeFrame(resource_type)) { | 1642 IsResourceTypeFrame(resource_type)) { |
| 1642 DCHECK(request->url().SchemeIs(url::kBlobScheme)); | 1643 DCHECK(request->url().SchemeIs(url::kBlobScheme)); |
| 1643 return handler; | 1644 return handler; |
| 1644 } | 1645 } |
| 1645 | 1646 |
| 1646 PluginService* plugin_service = nullptr; | 1647 // The InterceptingResourceHandler will replace its next handler with an |
| 1647 #if defined(ENABLE_PLUGINS) | 1648 // appropriate one based on the MIME type of the response if needed. It |
| 1648 plugin_service = PluginService::GetInstance(); | 1649 // should be placed at the end of the chain, just before |handler|. |
| 1649 #endif | 1650 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); |
| 1650 // Insert a buffered event handler before the actual one. | 1651 InterceptingResourceHandler* intercepting_handler = |
| 1651 handler.reset(new MimeTypeResourceHandler(std::move(handler), this, | 1652 static_cast<InterceptingResourceHandler*>(handler.get()); |
| 1652 plugin_service, request)); | |
| 1653 | 1653 |
| 1654 ScopedVector<ResourceThrottle> throttles; | 1654 ScopedVector<ResourceThrottle> throttles; |
| 1655 | 1655 |
| 1656 // Add a NavigationResourceThrottle for navigations. | 1656 // Add a NavigationResourceThrottle for navigations. |
| 1657 // PlzNavigate: the throttle is unnecessary as communication with the UI | 1657 // PlzNavigate: the throttle is unnecessary as communication with the UI |
| 1658 // thread is handled by the NavigationURLloader. | 1658 // thread is handled by the NavigationURLloader. |
| 1659 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { | 1659 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { |
| 1660 throttles.push_back(new NavigationResourceThrottle( | 1660 throttles.push_back(new NavigationResourceThrottle( |
| 1661 request, delegate_, GetCertStore(), fetch_request_context_type)); | 1661 request, delegate_, GetCertStore(), fetch_request_context_type)); |
| 1662 } | 1662 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1675 request->url().host(), | 1675 request->url().host(), |
| 1676 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 1676 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 1677 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 1677 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 1678 } | 1678 } |
| 1679 | 1679 |
| 1680 // TODO(ricea): Stop looking this up so much. | 1680 // TODO(ricea): Stop looking this up so much. |
| 1681 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 1681 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 1682 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, | 1682 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, |
| 1683 info->IsAsync(), request)); | 1683 info->IsAsync(), request)); |
| 1684 | 1684 |
| 1685 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 1685 // Split the handler in two groups: the ones that need to execute |
| 1686 std::move(throttles))); | 1686 // WillProcessResponse before mime sniffing and the others. |
| 1687 // TODO(clamy): ScopedVector is deprecated. The interface should be changed |
| 1688 // to use vectors instead. |
| 1689 ScopedVector<ResourceThrottle> pre_mime_sniffing_throttles; |
| 1690 ScopedVector<ResourceThrottle> post_mime_sniffing_throttles; |
| 1691 for (auto throttle : throttles) { |
| 1692 if (throttle->MustProcessResponseBeforeReadingBody()) { |
| 1693 pre_mime_sniffing_throttles.push_back(throttle); |
| 1694 } else { |
| 1695 post_mime_sniffing_throttles.push_back(throttle); |
| 1696 } |
| 1697 } |
| 1698 throttles.weak_clear(); |
| 1699 |
| 1700 // Add the post mime sniffing throttles. |
| 1701 handler.reset(new ThrottlingResourceHandler( |
| 1702 std::move(handler), request, std::move(post_mime_sniffing_throttles))); |
| 1703 |
| 1704 PluginService* plugin_service = nullptr; |
| 1705 #if defined(ENABLE_PLUGINS) |
| 1706 plugin_service = PluginService::GetInstance(); |
| 1707 #endif |
| 1708 |
| 1709 // Insert a buffered event handler to sniff the mime type. |
| 1710 // Note: all ResourceHandler following the MimeSniffingResourceHandler should |
| 1711 // expect OnWillRead to be called *before* OnResponseStarted as part of the |
| 1712 // mime sniffing process. |
| 1713 handler.reset(new MimeSniffingResourceHandler( |
| 1714 std::move(handler), this, plugin_service, intercepting_handler, request)); |
| 1715 |
| 1716 // Add the pre mime sniffing throttles. |
| 1717 handler.reset(new ThrottlingResourceHandler( |
| 1718 std::move(handler), request, std::move(pre_mime_sniffing_throttles))); |
| 1687 | 1719 |
| 1688 return handler; | 1720 return handler; |
| 1689 } | 1721 } |
| 1690 | 1722 |
| 1691 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { | 1723 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { |
| 1692 UnregisterDownloadedTempFile(filter_->child_id(), request_id); | 1724 UnregisterDownloadedTempFile(filter_->child_id(), request_id); |
| 1693 } | 1725 } |
| 1694 | 1726 |
| 1695 void ResourceDispatcherHostImpl::OnDidChangePriority( | 1727 void ResourceDispatcherHostImpl::OnDidChangePriority( |
| 1696 int request_id, | 1728 int request_id, |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2705 request_info->GetRouteID(), is_content_initiated, true, &throttles); | 2737 request_info->GetRouteID(), is_content_initiated, true, &throttles); |
| 2706 if (!throttles.empty()) { | 2738 if (!throttles.empty()) { |
| 2707 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2739 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
| 2708 std::move(throttles))); | 2740 std::move(throttles))); |
| 2709 } | 2741 } |
| 2710 } | 2742 } |
| 2711 return handler; | 2743 return handler; |
| 2712 } | 2744 } |
| 2713 | 2745 |
| 2714 } // namespace content | 2746 } // namespace content |
| OLD | NEW |