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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 GURL origin; | 517 GURL origin; |
518 if (!delegate_ || | 518 if (!delegate_ || |
519 !delegate_->ShouldInterceptResourceAsStream( | 519 !delegate_->ShouldInterceptResourceAsStream( |
520 request, plugin_path, mime_type, &origin, payload)) { | 520 request, plugin_path, mime_type, &origin, payload)) { |
521 return std::unique_ptr<ResourceHandler>(); | 521 return std::unique_ptr<ResourceHandler>(); |
522 } | 522 } |
523 | 523 |
524 StreamContext* stream_context = | 524 StreamContext* stream_context = |
525 GetStreamContextForResourceContext(info->GetContext()); | 525 GetStreamContextForResourceContext(info->GetContext()); |
526 | 526 |
527 std::unique_ptr<StreamResourceHandler> handler( | 527 std::unique_ptr<StreamResourceHandler> handler(new StreamResourceHandler( |
528 new StreamResourceHandler(request, stream_context->registry(), origin)); | 528 request, stream_context->registry(), origin, false)); |
529 | 529 |
530 info->set_is_stream(true); | 530 info->set_is_stream(true); |
531 std::unique_ptr<StreamInfo> stream_info(new StreamInfo); | 531 std::unique_ptr<StreamInfo> stream_info(new StreamInfo); |
532 stream_info->handle = handler->stream()->CreateHandle(); | 532 stream_info->handle = handler->stream()->CreateHandle(); |
533 stream_info->original_url = request->url(); | 533 stream_info->original_url = request->url(); |
534 stream_info->mime_type = mime_type; | 534 stream_info->mime_type = mime_type; |
535 // Make a copy of the response headers so it is safe to pass across threads; | 535 // Make a copy of the response headers so it is safe to pass across threads; |
536 // the old handler (AsyncResourceHandler) may modify it in parallel via the | 536 // the old handler (AsyncResourceHandler) may modify it in parallel via the |
537 // ResourceDispatcherHostDelegate. | 537 // ResourceDispatcherHostDelegate. |
538 if (response->head.headers.get()) { | 538 if (response->head.headers.get()) { |
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1470 IsResourceTypeFrame(request_data.resource_type)) { | 1470 IsResourceTypeFrame(request_data.resource_type)) { |
1471 DCHECK(request->url().SchemeIs(url::kBlobScheme)); | 1471 DCHECK(request->url().SchemeIs(url::kBlobScheme)); |
1472 return handler; | 1472 return handler; |
1473 } | 1473 } |
1474 | 1474 |
1475 return AddStandardHandlers(request, request_data.resource_type, | 1475 return AddStandardHandlers(request, request_data.resource_type, |
1476 resource_context, | 1476 resource_context, |
1477 request_data.fetch_request_context_type, | 1477 request_data.fetch_request_context_type, |
1478 request_data.fetch_mixed_content_context_type, | 1478 request_data.fetch_mixed_content_context_type, |
1479 requester_info->appcache_service(), child_id, | 1479 requester_info->appcache_service(), child_id, |
1480 route_id, std::move(handler)); | 1480 route_id, std::move(handler), nullptr, nullptr); |
1481 } | 1481 } |
1482 | 1482 |
1483 std::unique_ptr<ResourceHandler> | 1483 std::unique_ptr<ResourceHandler> |
1484 ResourceDispatcherHostImpl::AddStandardHandlers( | 1484 ResourceDispatcherHostImpl::AddStandardHandlers( |
1485 net::URLRequest* request, | 1485 net::URLRequest* request, |
1486 ResourceType resource_type, | 1486 ResourceType resource_type, |
1487 ResourceContext* resource_context, | 1487 ResourceContext* resource_context, |
1488 RequestContextType fetch_request_context_type, | 1488 RequestContextType fetch_request_context_type, |
1489 blink::WebMixedContentContextType fetch_mixed_content_context_type, | 1489 blink::WebMixedContentContextType fetch_mixed_content_context_type, |
1490 AppCacheService* appcache_service, | 1490 AppCacheService* appcache_service, |
1491 int child_id, | 1491 int child_id, |
1492 int route_id, | 1492 int route_id, |
1493 std::unique_ptr<ResourceHandler> handler) { | 1493 std::unique_ptr<ResourceHandler> handler, |
1494 NavigationURLLoaderImplCore* loader, | |
mmenke
2017/04/28 16:02:21
Can we give this a name that makes it clearer this
clamy
2017/05/02 15:05:44
Done.
| |
1495 std::unique_ptr<StreamHandle> stream_handle) { | |
1494 // The InterceptingResourceHandler will replace its next handler with an | 1496 // The InterceptingResourceHandler will replace its next handler with an |
1495 // appropriate one based on the MIME type of the response if needed. It | 1497 // appropriate one based on the MIME type of the response if needed. It |
1496 // should be placed at the end of the chain, just before |handler|. | 1498 // should be placed at the end of the chain, just before |handler|. |
1497 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); | 1499 handler.reset(new InterceptingResourceHandler(std::move(handler), request)); |
1498 InterceptingResourceHandler* intercepting_handler = | 1500 InterceptingResourceHandler* intercepting_handler = |
1499 static_cast<InterceptingResourceHandler*>(handler.get()); | 1501 static_cast<InterceptingResourceHandler*>(handler.get()); |
1500 | 1502 |
1501 std::vector<std::unique_ptr<ResourceThrottle>> throttles; | 1503 std::vector<std::unique_ptr<ResourceThrottle>> throttles; |
1502 | 1504 |
1503 // Add a NavigationResourceThrottle for navigations. | 1505 // Add a NavigationResourceThrottle for navigations. |
1504 // PlzNavigate: the throttle is unnecessary as communication with the UI | 1506 // PlzNavigate: the throttle is unnecessary as communication with the UI |
1505 // thread is handled by the NavigationURLloader. | 1507 // thread is handled by the NavigationResourceHandler below. |
1506 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { | 1508 if (!IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { |
1507 throttles.push_back(base::MakeUnique<NavigationResourceThrottle>( | 1509 throttles.push_back(base::MakeUnique<NavigationResourceThrottle>( |
1508 request, delegate_, fetch_request_context_type, | 1510 request, delegate_, fetch_request_context_type, |
1509 fetch_mixed_content_context_type)); | 1511 fetch_mixed_content_context_type)); |
1510 } | 1512 } |
1511 | 1513 |
1512 if (delegate_) { | 1514 if (delegate_) { |
1513 delegate_->RequestBeginning(request, | 1515 delegate_->RequestBeginning(request, |
1514 resource_context, | 1516 resource_context, |
1515 appcache_service, | 1517 appcache_service, |
(...skipping 23 matching lines...) Expand all Loading... | |
1539 } else { | 1541 } else { |
1540 post_mime_sniffing_throttles.push_back(std::move(throttle)); | 1542 post_mime_sniffing_throttles.push_back(std::move(throttle)); |
1541 } | 1543 } |
1542 } | 1544 } |
1543 throttles.clear(); | 1545 throttles.clear(); |
1544 | 1546 |
1545 // Add the post mime sniffing throttles. | 1547 // Add the post mime sniffing throttles. |
1546 handler.reset(new ThrottlingResourceHandler( | 1548 handler.reset(new ThrottlingResourceHandler( |
1547 std::move(handler), request, std::move(post_mime_sniffing_throttles))); | 1549 std::move(handler), request, std::move(post_mime_sniffing_throttles))); |
1548 | 1550 |
1551 if (IsBrowserSideNavigationEnabled() && IsResourceTypeFrame(resource_type)) { | |
mmenke
2017/04/28 16:02:21
DCHECK(loader);
DCHECK(stream_handle);
Alternativ
clamy
2017/05/02 15:05:44
Done.
| |
1552 // PlzNavigate | |
1553 // Add a NavigationResourceHandler that will control the flow of navigation. | |
1554 handler.reset(new NavigationResourceHandler(request, std::move(handler), | |
1555 loader, delegate(), | |
1556 std::move(stream_handle))); | |
1557 } | |
mmenke
2017/04/28 16:02:21
} else {
DCHECK(!loader);
DCHECK(!stream_handl
clamy
2017/05/02 15:05:44
Done.
| |
1558 | |
1549 PluginService* plugin_service = nullptr; | 1559 PluginService* plugin_service = nullptr; |
1550 #if BUILDFLAG(ENABLE_PLUGINS) | 1560 #if BUILDFLAG(ENABLE_PLUGINS) |
1551 plugin_service = PluginService::GetInstance(); | 1561 plugin_service = PluginService::GetInstance(); |
1552 #endif | 1562 #endif |
1553 | 1563 |
1554 // Insert a buffered event handler to sniff the mime type. | 1564 // Insert a buffered event handler to sniff the mime type. |
1555 // Note: all ResourceHandler following the MimeSniffingResourceHandler | 1565 // Note: all ResourceHandler following the MimeSniffingResourceHandler |
1556 // should expect OnWillRead to be called *before* OnResponseStarted as | 1566 // should expect OnWillRead to be called *before* OnResponseStarted as |
1557 // part of the mime sniffing process. | 1567 // part of the mime sniffing process. |
1558 handler.reset(new MimeSniffingResourceHandler( | 1568 handler.reset(new MimeSniffingResourceHandler( |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2065 info.begin_params.request_context_type, frame_type, | 2075 info.begin_params.request_context_type, frame_type, |
2066 info.are_ancestors_secure, info.common_params.post_data, | 2076 info.are_ancestors_secure, info.common_params.post_data, |
2067 extra_info->GetWebContentsGetterForRequest()); | 2077 extra_info->GetWebContentsGetterForRequest()); |
2068 | 2078 |
2069 // Have the appcache associate its extra info with the request. | 2079 // Have the appcache associate its extra info with the request. |
2070 if (appcache_handle_core) { | 2080 if (appcache_handle_core) { |
2071 AppCacheInterceptor::SetExtraRequestInfoForHost( | 2081 AppCacheInterceptor::SetExtraRequestInfoForHost( |
2072 new_request.get(), appcache_handle_core->host(), resource_type, false); | 2082 new_request.get(), appcache_handle_core->host(), resource_type, false); |
2073 } | 2083 } |
2074 | 2084 |
2085 StreamContext* stream_context = | |
2086 GetStreamContextForResourceContext(extra_info->GetContext()); | |
mmenke
2017/04/28 16:02:21
extra_info->GetContext() is just resource_context.
clamy
2017/05/02 15:05:44
Done.
| |
2075 std::unique_ptr<ResourceHandler> handler( | 2087 std::unique_ptr<ResourceHandler> handler( |
2076 new NavigationResourceHandler(new_request.get(), loader, delegate())); | 2088 new StreamResourceHandler(new_request.get(), stream_context->registry(), |
2089 new_request->url().GetOrigin(), true)); | |
mmenke
2017/04/28 16:02:21
Maybe a comment on the use of immediate mode?
clamy
2017/05/02 15:05:44
Done.
| |
2090 std::unique_ptr<StreamHandle> stream_handle = | |
2091 static_cast<StreamResourceHandler*>(handler.get()) | |
mmenke
2017/04/28 16:02:21
Remove this cast, and just make handler a unqiue_p
clamy
2017/05/02 15:05:44
This require creating another std::unique_ptr<Reso
| |
2092 ->stream() | |
2093 ->CreateHandle(); | |
2077 | 2094 |
2078 // TODO(davidben): Fix the dependency on child_id/route_id. Those are used | 2095 // TODO(davidben): Fix the dependency on child_id/route_id. Those are used |
2079 // by the ResourceScheduler. currently it's a no-op. | 2096 // by the ResourceScheduler. currently it's a no-op. |
2080 handler = AddStandardHandlers( | 2097 handler = AddStandardHandlers( |
2081 new_request.get(), resource_type, resource_context, | 2098 new_request.get(), resource_type, resource_context, |
2082 info.begin_params.request_context_type, | 2099 info.begin_params.request_context_type, |
2083 info.begin_params.mixed_content_context_type, | 2100 info.begin_params.mixed_content_context_type, |
2084 appcache_handle_core ? appcache_handle_core->GetAppCacheService() | 2101 appcache_handle_core ? appcache_handle_core->GetAppCacheService() |
2085 : nullptr, | 2102 : nullptr, |
2086 -1, // child_id | 2103 -1, // child_id |
2087 -1, // route_id | 2104 -1, // route_id |
2088 std::move(handler)); | 2105 std::move(handler), loader, std::move(stream_handle)); |
2089 | 2106 |
2090 BeginRequestInternal(std::move(new_request), std::move(handler)); | 2107 BeginRequestInternal(std::move(new_request), std::move(handler)); |
2091 } | 2108 } |
2092 | 2109 |
2093 void ResourceDispatcherHostImpl::SetLoaderDelegate( | 2110 void ResourceDispatcherHostImpl::SetLoaderDelegate( |
2094 LoaderDelegate* loader_delegate) { | 2111 LoaderDelegate* loader_delegate) { |
2095 loader_delegate_ = loader_delegate; | 2112 loader_delegate_ = loader_delegate; |
2096 } | 2113 } |
2097 | 2114 |
2098 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( | 2115 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2614 &throttles); | 2631 &throttles); |
2615 if (!throttles.empty()) { | 2632 if (!throttles.empty()) { |
2616 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, | 2633 handler.reset(new ThrottlingResourceHandler(std::move(handler), request, |
2617 std::move(throttles))); | 2634 std::move(throttles))); |
2618 } | 2635 } |
2619 } | 2636 } |
2620 return handler; | 2637 return handler; |
2621 } | 2638 } |
2622 | 2639 |
2623 } // namespace content | 2640 } // namespace content |
OLD | NEW |