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

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

Issue 2860903006: Handle webuis when using the network service. (Closed)
Patch Set: nits Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "content/browser/loader/navigation_url_loader_network_service.h" 5 #include "content/browser/loader/navigation_url_loader_network_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
13 #include "content/browser/frame_host/frame_tree_node.h"
13 #include "content/browser/frame_host/navigation_request_info.h" 14 #include "content/browser/frame_host/navigation_request_info.h"
14 #include "content/browser/loader/navigation_resource_handler.h" 15 #include "content/browser/loader/navigation_resource_handler.h"
15 #include "content/browser/loader/navigation_resource_throttle.h" 16 #include "content/browser/loader/navigation_resource_throttle.h"
16 #include "content/browser/loader/navigation_url_loader_delegate.h" 17 #include "content/browser/loader/navigation_url_loader_delegate.h"
18 #include "content/browser/webui/web_ui_url_loader_factory.h"
17 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/global_request_id.h" 20 #include "content/public/browser/global_request_id.h"
19 #include "content/public/browser/navigation_data.h" 21 #include "content/public/browser/navigation_data.h"
20 #include "content/public/browser/navigation_ui_data.h" 22 #include "content/public/browser/navigation_ui_data.h"
21 #include "content/public/browser/ssl_status.h" 23 #include "content/public/browser/ssl_status.h"
22 #include "content/public/browser/stream_handle.h" 24 #include "content/public/browser/stream_handle.h"
23 #include "content/public/common/referrer.h" 25 #include "content/public/common/referrer.h"
24 #include "content/public/common/service_manager_connection.h" 26 #include "content/public/common/service_manager_connection.h"
25 #include "content/public/common/service_names.mojom.h" 27 #include "content/public/common/service_names.mojom.h"
28 #include "content/public/common/url_constants.h"
26 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
27 #include "net/url_request/url_request_context.h" 30 #include "net/url_request/url_request_context.h"
28 #include "services/service_manager/public/cpp/connector.h" 31 #include "services/service_manager/public/cpp/connector.h"
29 32
30 namespace content { 33 namespace content {
31 34
32 namespace { 35 namespace {
33 36
34 static base::LazyInstance<mojom::URLLoaderFactoryPtr>::Leaky 37 static base::LazyInstance<mojom::URLLoaderFactoryPtr>::Leaky
35 g_url_loader_factory = LAZY_INSTANCE_INITIALIZER; 38 g_url_loader_factory = LAZY_INSTANCE_INITIALIZER;
(...skipping 18 matching lines...) Expand all
54 } // namespace 57 } // namespace
55 58
56 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( 59 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService(
57 ResourceContext* resource_context, 60 ResourceContext* resource_context,
58 StoragePartition* storage_partition, 61 StoragePartition* storage_partition,
59 std::unique_ptr<NavigationRequestInfo> request_info, 62 std::unique_ptr<NavigationRequestInfo> request_info,
60 std::unique_ptr<NavigationUIData> navigation_ui_data, 63 std::unique_ptr<NavigationUIData> navigation_ui_data,
61 ServiceWorkerNavigationHandle* service_worker_handle, 64 ServiceWorkerNavigationHandle* service_worker_handle,
62 AppCacheNavigationHandle* appcache_handle, 65 AppCacheNavigationHandle* appcache_handle,
63 NavigationURLLoaderDelegate* delegate) 66 NavigationURLLoaderDelegate* delegate)
64 : delegate_(delegate), binding_(this), weak_factory_(this) { 67 : delegate_(delegate),
68 binding_(this),
69 request_info_(std::move(request_info)),
70 weak_factory_(this) {
65 DCHECK_CURRENTLY_ON(BrowserThread::UI); 71 DCHECK_CURRENTLY_ON(BrowserThread::UI);
66 72
67 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( 73 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1(
68 "navigation", "Navigation timeToResponseStarted", this, 74 "navigation", "Navigation timeToResponseStarted", this,
69 request_info->common_params.navigation_start, "FrameTreeNode id", 75 request_info_->common_params.navigation_start, "FrameTreeNode id",
70 request_info->frame_tree_node_id); 76 request_info_->frame_tree_node_id);
71 77
72 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. 78 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here.
73 auto new_request = base::MakeUnique<ResourceRequest>(); 79 auto new_request = base::MakeUnique<ResourceRequest>();
74 80
75 new_request->method = request_info->common_params.method; 81 new_request->method = request_info_->common_params.method;
76 new_request->url = request_info->common_params.url; 82 new_request->url = request_info_->common_params.url;
77 new_request->first_party_for_cookies = request_info->first_party_for_cookies; 83 new_request->first_party_for_cookies = request_info_->first_party_for_cookies;
78 new_request->priority = net::HIGHEST; 84 new_request->priority = net::HIGHEST;
79 85
80 // The code below to set fields like request_initiator, referrer, etc has 86 // The code below to set fields like request_initiator, referrer, etc has
81 // been copied from ResourceDispatcherHostImpl. We did not refactor the 87 // been copied from ResourceDispatcherHostImpl. We did not refactor the
82 // common code into a function, because RDHI uses accessor functions on the 88 // common code into a function, because RDHI uses accessor functions on the
83 // URLRequest class to set these fields. whereas we use ResourceRequest here. 89 // URLRequest class to set these fields. whereas we use ResourceRequest here.
84 new_request->request_initiator = request_info->begin_params.initiator_origin; 90 new_request->request_initiator = request_info_->begin_params.initiator_origin;
85 new_request->referrer = request_info->common_params.referrer.url; 91 new_request->referrer = request_info_->common_params.referrer.url;
86 new_request->referrer_policy = request_info->common_params.referrer.policy; 92 new_request->referrer_policy = request_info_->common_params.referrer.policy;
87 new_request->headers = request_info->begin_params.headers; 93 new_request->headers = request_info_->begin_params.headers;
88 94
89 int load_flags = request_info->begin_params.load_flags; 95 int load_flags = request_info_->begin_params.load_flags;
90 load_flags |= net::LOAD_VERIFY_EV_CERT; 96 load_flags |= net::LOAD_VERIFY_EV_CERT;
91 if (request_info->is_main_frame) 97 if (request_info_->is_main_frame)
92 load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED; 98 load_flags |= net::LOAD_MAIN_FRAME_DEPRECATED;
93 99
94 // Sync loads should have maximum priority and should be the only 100 // Sync loads should have maximum priority and should be the only
95 // requests that have the ignore limits flag set. 101 // requests that have the ignore limits flag set.
96 DCHECK(!(load_flags & net::LOAD_IGNORE_LIMITS)); 102 DCHECK(!(load_flags & net::LOAD_IGNORE_LIMITS));
97 103
98 new_request->load_flags = load_flags; 104 new_request->load_flags = load_flags;
99 105
100 new_request->request_body = request_info->common_params.post_data.get(); 106 new_request->request_body = request_info_->common_params.post_data.get();
101 if (new_request->request_body.get()) { 107 if (new_request->request_body.get()) {
102 // The request body may need blob handles to be added to it. This 108 // The request body may need blob handles to be added to it. This
103 // functionality has to be invoked on the IO thread. 109 // functionality has to be invoked on the IO thread.
104 BrowserThread::PostTask( 110 BrowserThread::PostTask(
105 BrowserThread::IO, FROM_HERE, 111 BrowserThread::IO, FROM_HERE,
106 base::Bind(&HandleRequestsWithBody, 112 base::Bind(&HandleRequestsWithBody,
107 base::Passed(&new_request), 113 base::Passed(&new_request),
108 resource_context, 114 resource_context,
109 weak_factory_.GetWeakPtr())); 115 weak_factory_.GetWeakPtr()));
110 return; 116 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 198 }
193 } 199 }
194 200
195 void NavigationURLLoaderNetworkService::StartURLRequest( 201 void NavigationURLLoaderNetworkService::StartURLRequest(
196 std::unique_ptr<ResourceRequest> request) { 202 std::unique_ptr<ResourceRequest> request) {
197 DCHECK_CURRENTLY_ON(BrowserThread::UI); 203 DCHECK_CURRENTLY_ON(BrowserThread::UI);
198 204
199 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; 205 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass;
200 binding_.Bind(&url_loader_client_ptr_to_pass); 206 binding_.Bind(&url_loader_client_ptr_to_pass);
201 207
202 GetURLLoaderFactory().CreateLoaderAndStart( 208 mojom::URLLoaderFactory* factory = nullptr;
203 mojo::MakeRequest(&url_loader_associated_ptr_), 0 /* routing_id? */, 209 mojom::URLLoaderFactoryPtr factory_ptr;
yzshen1 2017/05/05 19:54:07 This |factory_ptr| will be destroyed when it goes
jam 2017/05/05 22:19:39 Thanks, I didn't realize this. Added comment. agre
204 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, *request, 210 if (request->url.SchemeIs(kChromeUIScheme)) {
205 std::move(url_loader_client_ptr_to_pass)); 211 FrameTreeNode* frame_tree_node =
212 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id);
213 factory_ptr = GetWebUIURLLoader(frame_tree_node);
214 factory = factory_ptr.get();
215 }
216
217 if (!factory)
218 factory = GetURLLoaderFactory();
219
220 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_associated_ptr_),
221 0 /* routing_id? */, 0 /* request_id? */,
222 mojom::kURLLoadOptionSendSSLInfo, *request,
223 std::move(url_loader_client_ptr_to_pass));
206 } 224 }
207 225
208 mojom::URLLoaderFactory& 226 mojom::URLLoaderFactory*
209 NavigationURLLoaderNetworkService::GetURLLoaderFactory() { 227 NavigationURLLoaderNetworkService::GetURLLoaderFactory() {
210 // TODO(yzshen): We will need the ability to customize the factory per frame 228 // TODO(yzshen): We will need the ability to customize the factory per frame
211 // e.g., for appcache or service worker. 229 // e.g., for appcache or service worker.
212 if (!g_url_loader_factory.Get()) { 230 if (!g_url_loader_factory.Get()) {
213 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( 231 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface(
214 mojom::kNetworkServiceName, &g_url_loader_factory.Get()); 232 mojom::kNetworkServiceName, &g_url_loader_factory.Get());
215 } 233 }
216 234
217 return *g_url_loader_factory.Get(); 235 return g_url_loader_factory.Get().get();
218 } 236 }
219 237
220 } // namespace content 238 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698