| 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 30 matching lines...) Expand all Loading... |
| 41 #include "content/browser/child_process_security_policy_impl.h" | 41 #include "content/browser/child_process_security_policy_impl.h" |
| 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_resource_handler.h" | 43 #include "content/browser/download/save_file_resource_handler.h" |
| 44 #include "content/browser/frame_host/frame_tree.h" | 44 #include "content/browser/frame_host/frame_tree.h" |
| 45 #include "content/browser/frame_host/navigation_request_info.h" | 45 #include "content/browser/frame_host/navigation_request_info.h" |
| 46 #include "content/browser/frame_host/navigator.h" | 46 #include "content/browser/frame_host/navigator.h" |
| 47 #include "content/browser/loader/async_resource_handler.h" | 47 #include "content/browser/loader/async_resource_handler.h" |
| 48 #include "content/browser/loader/async_revalidation_manager.h" | 48 #include "content/browser/loader/async_revalidation_manager.h" |
| 49 #include "content/browser/loader/cross_site_resource_handler.h" | 49 #include "content/browser/loader/cross_site_resource_handler.h" |
| 50 #include "content/browser/loader/detachable_resource_handler.h" | 50 #include "content/browser/loader/detachable_resource_handler.h" |
| 51 #include "content/browser/loader/intercepting_resource_handler.h" |
| 51 #include "content/browser/loader/loader_delegate.h" | 52 #include "content/browser/loader/loader_delegate.h" |
| 52 #include "content/browser/loader/mime_type_resource_handler.h" | 53 #include "content/browser/loader/mime_sniffing_resource_handler.h" |
| 53 #include "content/browser/loader/mojo_async_resource_handler.h" | 54 #include "content/browser/loader/mojo_async_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" |
| (...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 std::unique_ptr<ResourceHandler> handler) { | 1687 std::unique_ptr<ResourceHandler> handler) { |
| 1687 // PlzNavigate: do not add ResourceThrottles for main resource requests from | 1688 // PlzNavigate: do not add ResourceThrottles for main resource requests from |
| 1688 // the renderer. Decisions about the navigation should have been done in the | 1689 // the renderer. Decisions about the navigation should have been done in the |
| 1689 // initial request. | 1690 // initial request. |
| 1690 if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type) && | 1691 if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type) && |
| 1691 child_id != -1) { | 1692 child_id != -1) { |
| 1692 DCHECK(request->url().SchemeIs(url::kBlobScheme)); | 1693 DCHECK(request->url().SchemeIs(url::kBlobScheme)); |
| 1693 return handler; | 1694 return handler; |
| 1694 } | 1695 } |
| 1695 | 1696 |
| 1696 PluginService* plugin_service = nullptr; | 1697 // The InterceptingResourceHandler will replace its next handler with an |
| 1697 #if defined(ENABLE_PLUGINS) | 1698 // appropriate one based on the MIME type of the response if needed. It |
| 1698 plugin_service = PluginService::GetInstance(); | 1699 // should be placed at the end of the chain, just before |handler|. |
| 1699 #endif | 1700 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); |
| 1700 // Insert a buffered event handler before the actual one. | 1701 InterceptingResourceHandler* intercepting_handler = |
| 1701 handler.reset(new MimeTypeResourceHandler(std::move(handler), this, | 1702 static_cast<InterceptingResourceHandler*>(handler.get()); |
| 1702 plugin_service, request)); | |
| 1703 | 1703 |
| 1704 ScopedVector<ResourceThrottle> throttles; | 1704 ScopedVector<ResourceThrottle> throttles; |
| 1705 | 1705 |
| 1706 // Add a NavigationResourceThrottle for navigations. | 1706 // Add a NavigationResourceThrottle for navigations. |
| 1707 // PlzNavigate: the throttle is unnecessary as communication with the UI | 1707 // PlzNavigate: the throttle is unnecessary as communication with the UI |
| 1708 // thread is handled by the NavigationURLloader. | 1708 // thread is handled by the NavigationURLloader. |
| 1709 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { | 1709 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { |
| 1710 throttles.push_back(new NavigationResourceThrottle( | 1710 throttles.push_back(new NavigationResourceThrottle( |
| 1711 request, delegate(), fetch_request_context_type)); | 1711 request, delegate(), fetch_request_context_type)); |
| 1712 } | 1712 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1725 request->url().host(), | 1725 request->url().host(), |
| 1726 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 1726 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 1727 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 1727 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 // TODO(ricea): Stop looking this up so much. | 1730 // TODO(ricea): Stop looking this up so much. |
| 1731 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 1731 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
| 1732 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, | 1732 throttles.push_back(scheduler_->ScheduleRequest(child_id, route_id, |
| 1733 info->IsAsync(), request)); | 1733 info->IsAsync(), request)); |
| 1734 | 1734 |
| 1735 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 1735 // Split the handler in two groups: the ones that need to execute |
| 1736 std::move(throttles))); | 1736 // WillProcessResponse before mime sniffing and the others. |
| 1737 // TODO(clamy): ScopedVector is deprecated. The interface should be changed |
| 1738 // to use vectors instead. |
| 1739 ScopedVector<ResourceThrottle> pre_mime_sniffing_throttles; |
| 1740 ScopedVector<ResourceThrottle> post_mime_sniffing_throttles; |
| 1741 for (auto throttle : throttles) { |
| 1742 if (throttle->MustProcessResponseBeforeReadingBody()) { |
| 1743 pre_mime_sniffing_throttles.push_back(throttle); |
| 1744 } else { |
| 1745 post_mime_sniffing_throttles.push_back(throttle); |
| 1746 } |
| 1747 } |
| 1748 throttles.weak_clear(); |
| 1749 |
| 1750 // Add the post mime sniffing throttles. |
| 1751 handler.reset(new ThrottlingResourceHandler( |
| 1752 std::move(handler), request, std::move(post_mime_sniffing_throttles))); |
| 1753 |
| 1754 PluginService* plugin_service = nullptr; |
| 1755 #if defined(ENABLE_PLUGINS) |
| 1756 plugin_service = PluginService::GetInstance(); |
| 1757 #endif |
| 1758 |
| 1759 // Insert a buffered event handler to sniff the mime type. |
| 1760 // Note: all ResourceHandler following the MimeSniffingResourceHandler should |
| 1761 // expect OnWillRead to be called *before* OnResponseStarted as part of the |
| 1762 // mime sniffing process. |
| 1763 handler.reset(new MimeSniffingResourceHandler( |
| 1764 std::move(handler), this, plugin_service, intercepting_handler, request)); |
| 1765 |
| 1766 // Add the pre mime sniffing throttles. |
| 1767 handler.reset(new ThrottlingResourceHandler( |
| 1768 std::move(handler), request, std::move(pre_mime_sniffing_throttles))); |
| 1737 | 1769 |
| 1738 return handler; | 1770 return handler; |
| 1739 } | 1771 } |
| 1740 | 1772 |
| 1741 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { | 1773 void ResourceDispatcherHostImpl::OnReleaseDownloadedFile(int request_id) { |
| 1742 UnregisterDownloadedTempFile(filter_->child_id(), request_id); | 1774 UnregisterDownloadedTempFile(filter_->child_id(), request_id); |
| 1743 } | 1775 } |
| 1744 | 1776 |
| 1745 void ResourceDispatcherHostImpl::OnDidChangePriority( | 1777 void ResourceDispatcherHostImpl::OnDidChangePriority( |
| 1746 int request_id, | 1778 int request_id, |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2719 << iter->filesystem_url().spec(); | 2751 << iter->filesystem_url().spec(); |
| 2720 return false; | 2752 return false; |
| 2721 } | 2753 } |
| 2722 } | 2754 } |
| 2723 } | 2755 } |
| 2724 } | 2756 } |
| 2725 return true; | 2757 return true; |
| 2726 } | 2758 } |
| 2727 | 2759 |
| 2728 } // namespace content | 2760 } // namespace content |
| OLD | NEW |