Index: content/browser/loader/navigation_url_loader_network_service.cc |
diff --git a/content/browser/loader/navigation_url_loader_network_service.cc b/content/browser/loader/navigation_url_loader_network_service.cc |
index fc4fb7ebb44b3d03035eeaf15baa705b2ea4cc4b..e82a39da4e07f37a329fdbcd5124fbf3330ce2d4 100644 |
--- a/content/browser/loader/navigation_url_loader_network_service.cc |
+++ b/content/browser/loader/navigation_url_loader_network_service.cc |
@@ -10,10 +10,12 @@ |
#include "base/memory/ptr_util.h" |
#include "base/trace_event/trace_event.h" |
#include "content/browser/blob_storage/chrome_blob_storage_context.h" |
+#include "content/browser/frame_host/frame_tree_node.h" |
#include "content/browser/frame_host/navigation_request_info.h" |
#include "content/browser/loader/navigation_resource_handler.h" |
#include "content/browser/loader/navigation_resource_throttle.h" |
#include "content/browser/loader/navigation_url_loader_delegate.h" |
+#include "content/browser/webui/web_ui_url_loader_factory.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/global_request_id.h" |
#include "content/public/browser/navigation_data.h" |
@@ -23,6 +25,7 @@ |
#include "content/public/common/referrer.h" |
#include "content/public/common/service_manager_connection.h" |
#include "content/public/common/service_names.mojom.h" |
+#include "content/public/common/url_constants.h" |
#include "net/base/load_flags.h" |
#include "net/url_request/url_request_context.h" |
#include "services/service_manager/public/cpp/connector.h" |
@@ -61,34 +64,37 @@ NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( |
ServiceWorkerNavigationHandle* service_worker_handle, |
AppCacheNavigationHandle* appcache_handle, |
NavigationURLLoaderDelegate* delegate) |
- : delegate_(delegate), binding_(this), weak_factory_(this) { |
+ : delegate_(delegate), |
+ binding_(this), |
+ request_info_(std::move(request_info)), |
+ weak_factory_(this) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( |
"navigation", "Navigation timeToResponseStarted", this, |
- request_info->common_params.navigation_start, "FrameTreeNode id", |
- request_info->frame_tree_node_id); |
+ request_info_->common_params.navigation_start, "FrameTreeNode id", |
+ request_info_->frame_tree_node_id); |
// TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. |
auto new_request = base::MakeUnique<ResourceRequest>(); |
- new_request->method = request_info->common_params.method; |
- new_request->url = request_info->common_params.url; |
- new_request->first_party_for_cookies = request_info->first_party_for_cookies; |
+ new_request->method = request_info_->common_params.method; |
+ new_request->url = request_info_->common_params.url; |
+ new_request->first_party_for_cookies = request_info_->first_party_for_cookies; |
new_request->priority = net::HIGHEST; |
// The code below to set fields like request_initiator, referrer, etc has |
// been copied from ResourceDispatcherHostImpl. We did not refactor the |
// common code into a function, because RDHI uses accessor functions on the |
// URLRequest class to set these fields. whereas we use ResourceRequest here. |
- new_request->request_initiator = request_info->begin_params.initiator_origin; |
- new_request->referrer = request_info->common_params.referrer.url; |
- new_request->referrer_policy = request_info->common_params.referrer.policy; |
- new_request->headers = request_info->begin_params.headers; |
+ new_request->request_initiator = request_info_->begin_params.initiator_origin; |
+ new_request->referrer = request_info_->common_params.referrer.url; |
+ new_request->referrer_policy = request_info_->common_params.referrer.policy; |
+ new_request->headers = request_info_->begin_params.headers; |
- int load_flags = request_info->begin_params.load_flags; |
+ int load_flags = request_info_->begin_params.load_flags; |
load_flags |= net::LOAD_VERIFY_EV_CERT; |
- if (request_info->is_main_frame) |
+ if (request_info_->is_main_frame) |
load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED; |
// Sync loads should have maximum priority and should be the only |
@@ -97,7 +103,7 @@ NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( |
new_request->load_flags = load_flags; |
- new_request->request_body = request_info->common_params.post_data.get(); |
+ new_request->request_body = request_info_->common_params.post_data.get(); |
if (new_request->request_body.get()) { |
// The request body may need blob handles to be added to it. This |
// functionality has to be invoked on the IO thread. |
@@ -199,13 +205,32 @@ void NavigationURLLoaderNetworkService::StartURLRequest( |
mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; |
binding_.Bind(&url_loader_client_ptr_to_pass); |
- GetURLLoaderFactory().CreateLoaderAndStart( |
- mojo::MakeRequest(&url_loader_associated_ptr_), 0 /* routing_id? */, |
- 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, *request, |
- std::move(url_loader_client_ptr_to_pass)); |
+ mojom::URLLoaderFactory* factory = nullptr; |
+ // This |factory_ptr| will be destroyed when it goes out of scope. Because |
+ // |url_loader_associated_ptr_| is associated with it, it will be disconnected |
+ // as well. That means NavigationURLLoaderNetworkService::FollowRedirect() |
+ // won't work as expected, the |url_loader_associated_ptr_| will silently drop |
+ // calls. |
+ // This is fine for now since the only user of this is WebUI which doesn't |
+ // need this, but we'll have to fix this when other consumers come up. |
+ mojom::URLLoaderFactoryPtr factory_ptr; |
+ if (request->url.SchemeIs(kChromeUIScheme)) { |
+ FrameTreeNode* frame_tree_node = |
+ FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id); |
+ factory_ptr = GetWebUIURLLoader(frame_tree_node); |
+ factory = factory_ptr.get(); |
+ } |
+ |
+ if (!factory) |
+ factory = GetURLLoaderFactory(); |
+ |
+ factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_associated_ptr_), |
+ 0 /* routing_id? */, 0 /* request_id? */, |
+ mojom::kURLLoadOptionSendSSLInfo, *request, |
+ std::move(url_loader_client_ptr_to_pass)); |
} |
-mojom::URLLoaderFactory& |
+mojom::URLLoaderFactory* |
NavigationURLLoaderNetworkService::GetURLLoaderFactory() { |
// TODO(yzshen): We will need the ability to customize the factory per frame |
// e.g., for appcache or service worker. |
@@ -214,7 +239,7 @@ NavigationURLLoaderNetworkService::GetURLLoaderFactory() { |
mojom::kNetworkServiceName, &g_url_loader_factory.Get()); |
} |
- return *g_url_loader_factory.Get(); |
+ return g_url_loader_factory.Get().get(); |
} |
} // namespace content |