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

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

Issue 2906543002: Add support for reading blobs when using the network service. (Closed)
Patch Set: review comment Created 3 years, 6 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/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 // Kept around during the lifetime of the navigation request, and is 60 // Kept around during the lifetime of the navigation request, and is
61 // responsible for dispatching a ResourceRequest to the appropriate 61 // responsible for dispatching a ResourceRequest to the appropriate
62 // URLLoaderFactory. In order to get the right URLLoaderFactory it 62 // URLLoaderFactory. In order to get the right URLLoaderFactory it
63 // builds a vector of URLLoaderRequestHandler's and successively calls 63 // builds a vector of URLLoaderRequestHandler's and successively calls
64 // MaybeCreateLoaderFactory on each until the request is successfully 64 // MaybeCreateLoaderFactory on each until the request is successfully
65 // handled. The same sequence may be performed multiple times when 65 // handled. The same sequence may be performed multiple times when
66 // redirects happen. 66 // redirects happen.
67 class NavigationURLLoaderNetworkService::URLLoaderRequestController { 67 class NavigationURLLoaderNetworkService::URLLoaderRequestController {
68 public: 68 public:
69 URLLoaderRequestController(std::unique_ptr<ResourceRequest> resource_request, 69 URLLoaderRequestController(
70 ResourceContext* resource_context) 70 std::unique_ptr<ResourceRequest> resource_request,
71 ResourceContext* resource_context,
72 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter)
71 : resource_request_(std::move(resource_request)), 73 : resource_request_(std::move(resource_request)),
72 resource_context_(resource_context), 74 resource_context_(resource_context),
73 network_factory_(nullptr) {} 75 url_loader_factory_getter_(url_loader_factory_getter) {}
74 76
75 virtual ~URLLoaderRequestController() { 77 virtual ~URLLoaderRequestController() {
76 DCHECK_CURRENTLY_ON(BrowserThread::IO); 78 DCHECK_CURRENTLY_ON(BrowserThread::IO);
77 } 79 }
78 80
79 void Start( 81 void Start(
80 ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core, 82 ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core,
81 AppCacheNavigationHandleCore* appcache_handle_core, 83 AppCacheNavigationHandleCore* appcache_handle_core,
82 std::unique_ptr<NavigationRequestInfo> request_info, 84 std::unique_ptr<NavigationRequestInfo> request_info,
83 mojom::URLLoaderFactoryPtrInfo factory_for_webui, 85 mojom::URLLoaderFactoryPtrInfo factory_for_webui,
84 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter,
85 const base::Callback<WebContents*(void)>& web_contents_getter, 86 const base::Callback<WebContents*(void)>& web_contents_getter,
86 mojom::URLLoaderRequest url_loader_request, 87 mojom::URLLoaderRequest url_loader_request,
87 mojom::URLLoaderClientPtr url_loader_client_ptr, 88 mojom::URLLoaderClientPtr url_loader_client_ptr,
88 std::unique_ptr<service_manager::Connector> connector) { 89 std::unique_ptr<service_manager::Connector> connector) {
89 DCHECK_CURRENTLY_ON(BrowserThread::IO); 90 DCHECK_CURRENTLY_ON(BrowserThread::IO);
90 const ResourceType resource_type = request_info->is_main_frame 91 const ResourceType resource_type = request_info->is_main_frame
91 ? RESOURCE_TYPE_MAIN_FRAME 92 ? RESOURCE_TYPE_MAIN_FRAME
92 : RESOURCE_TYPE_SUB_FRAME; 93 : RESOURCE_TYPE_SUB_FRAME;
93 94
94 if (resource_request_->request_body) { 95 if (resource_request_->request_body) {
95 AttachRequestBodyBlobDataHandles(resource_request_->request_body.get(), 96 AttachRequestBodyBlobDataHandles(resource_request_->request_body.get(),
96 resource_context_); 97 resource_context_);
97 } 98 }
98 99
99 // Requests to WebUI scheme won't get redirected to/from other schemes 100 // Requests to WebUI scheme won't get redirected to/from other schemes
100 // or be intercepted, so we just let it go here. 101 // or be intercepted, so we just let it go here.
101 if (factory_for_webui.is_valid()) { 102 if (factory_for_webui.is_valid()) {
102 mojom::URLLoaderFactoryPtr factory_ptr; 103 mojom::URLLoaderFactoryPtr factory_ptr;
103 factory_ptr.Bind(std::move(factory_for_webui)); 104 factory_ptr.Bind(std::move(factory_for_webui));
104 factory_ptr->CreateLoaderAndStart( 105 factory_ptr->CreateLoaderAndStart(
105 std::move(url_loader_request), 0 /* routing_id? */, 106 std::move(url_loader_request), 0 /* routing_id? */,
106 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo, 107 0 /* request_id? */, mojom::kURLLoadOptionSendSSLInfo,
107 *resource_request_, std::move(url_loader_client_ptr)); 108 *resource_request_, std::move(url_loader_client_ptr));
108 return; 109 return;
109 } 110 }
kinuko 2017/05/30 06:27:32 Should we have blob url handling case here? ...hm,
jam 2017/05/30 15:54:18 yep, that's why I didn't put it here
110 111
111 DCHECK(handlers_.empty()); 112 DCHECK(handlers_.empty());
112 if (service_worker_navigation_handle_core) { 113 if (service_worker_navigation_handle_core) {
113 RequestContextFrameType frame_type = 114 RequestContextFrameType frame_type =
114 request_info->is_main_frame ? REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL 115 request_info->is_main_frame ? REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL
115 : REQUEST_CONTEXT_FRAME_TYPE_NESTED; 116 : REQUEST_CONTEXT_FRAME_TYPE_NESTED;
116 117
117 storage::BlobStorageContext* blob_storage_context = GetBlobStorageContext( 118 storage::BlobStorageContext* blob_storage_context = GetBlobStorageContext(
118 GetChromeBlobStorageContextForResourceContext(resource_context_)); 119 GetChromeBlobStorageContextForResourceContext(resource_context_));
119 std::unique_ptr<URLLoaderRequestHandler> service_worker_handler = 120 std::unique_ptr<URLLoaderRequestHandler> service_worker_handler =
120 ServiceWorkerRequestHandler::InitializeForNavigationNetworkService( 121 ServiceWorkerRequestHandler::InitializeForNavigationNetworkService(
121 *resource_request_, resource_context_, 122 *resource_request_, resource_context_,
122 service_worker_navigation_handle_core, blob_storage_context, 123 service_worker_navigation_handle_core, blob_storage_context,
123 request_info->begin_params.skip_service_worker, resource_type, 124 request_info->begin_params.skip_service_worker, resource_type,
124 request_info->begin_params.request_context_type, frame_type, 125 request_info->begin_params.request_context_type, frame_type,
125 request_info->are_ancestors_secure, 126 request_info->are_ancestors_secure,
126 request_info->common_params.post_data, web_contents_getter); 127 request_info->common_params.post_data, web_contents_getter);
127 if (service_worker_handler) 128 if (service_worker_handler)
128 handlers_.push_back(std::move(service_worker_handler)); 129 handlers_.push_back(std::move(service_worker_handler));
129 } 130 }
130 131
131 if (appcache_handle_core) { 132 if (appcache_handle_core) {
132 // TODO: add appcache code here. 133 // TODO: add appcache code here.
133 } 134 }
134 135
135 DCHECK(!network_factory_);
136 network_factory_ = url_loader_factory_getter->GetNetworkFactory()->get();
137
138 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr)); 136 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr));
139 } 137 }
140 138
141 // This could be called multiple times. 139 // This could be called multiple times.
142 void Restart(mojom::URLLoaderRequest url_loader_request, 140 void Restart(mojom::URLLoaderRequest url_loader_request,
143 mojom::URLLoaderClientPtr url_loader_client_ptr) { 141 mojom::URLLoaderClientPtr url_loader_client_ptr) {
144 url_loader_request_ = std::move(url_loader_request); 142 url_loader_request_ = std::move(url_loader_request);
145 url_loader_client_ptr_ = std::move(url_loader_client_ptr); 143 url_loader_client_ptr_ = std::move(url_loader_client_ptr);
146 handler_index_ = 0; 144 handler_index_ = 0;
147 MaybeStartLoader(nullptr); 145 MaybeStartLoader(nullptr);
(...skipping 12 matching lines...) Expand all
160 158
161 if (handler_index_ < handlers_.size()) { 159 if (handler_index_ < handlers_.size()) {
162 handlers_[handler_index_++]->MaybeCreateLoaderFactory( 160 handlers_[handler_index_++]->MaybeCreateLoaderFactory(
163 *resource_request_, resource_context_, 161 *resource_request_, resource_context_,
164 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader, 162 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader,
165 base::Unretained(this))); 163 base::Unretained(this)));
166 return; 164 return;
167 } 165 }
168 166
169 DCHECK_EQ(handlers_.size(), handler_index_); 167 DCHECK_EQ(handlers_.size(), handler_index_);
170 DCHECK(network_factory_ != nullptr); 168 if (resource_request_->url.SchemeIs(url::kBlobScheme)) {
171 MaybeStartLoader(network_factory_); 169 factory = url_loader_factory_getter_->GetBlobFactory()->get();
170 } else {
171 factory = url_loader_factory_getter_->GetNetworkFactory()->get();
172 }
173 MaybeStartLoader(factory);
172 } 174 }
173 175
174 private: 176 private:
175 std::vector<std::unique_ptr<URLLoaderRequestHandler>> handlers_; 177 std::vector<std::unique_ptr<URLLoaderRequestHandler>> handlers_;
176 size_t handler_index_ = 0; 178 size_t handler_index_ = 0;
177 179
178 std::unique_ptr<ResourceRequest> resource_request_; 180 std::unique_ptr<ResourceRequest> resource_request_;
179 ResourceContext* resource_context_; 181 ResourceContext* resource_context_;
180 182
181 // The factory for doing a vanilla network request, called when 183 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_;
182 // any of other request handlers handle the given request.
183 mojom::URLLoaderFactory* network_factory_;
184 184
185 // Kept around until we create a loader. 185 // Kept around until we create a loader.
186 mojom::URLLoaderRequest url_loader_request_; 186 mojom::URLLoaderRequest url_loader_request_;
187 mojom::URLLoaderClientPtr url_loader_client_ptr_; 187 mojom::URLLoaderClientPtr url_loader_client_ptr_;
188 188
189 DISALLOW_COPY_AND_ASSIGN(URLLoaderRequestController); 189 DISALLOW_COPY_AND_ASSIGN(URLLoaderRequestController);
190 }; 190 };
191 191
192 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( 192 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService(
193 ResourceContext* resource_context, 193 ResourceContext* resource_context,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; 241 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass;
242 binding_.Bind(mojo::MakeRequest(&url_loader_client_ptr_to_pass)); 242 binding_.Bind(mojo::MakeRequest(&url_loader_client_ptr_to_pass));
243 243
244 // Check if a web UI scheme wants to handle this request. 244 // Check if a web UI scheme wants to handle this request.
245 mojom::URLLoaderFactoryPtrInfo factory_for_webui; 245 mojom::URLLoaderFactoryPtrInfo factory_for_webui;
246 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); 246 const auto& schemes = URLDataManagerBackend::GetWebUISchemes();
247 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) != 247 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) !=
248 schemes.end()) { 248 schemes.end()) {
249 FrameTreeNode* frame_tree_node = 249 FrameTreeNode* frame_tree_node =
250 FrameTreeNode::GloballyFindByID(frame_tree_node_id); 250 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
251 factory_for_webui = GetWebUIURLLoader(frame_tree_node).PassInterface(); 251 factory_for_webui = CreateWebUIURLLoader(frame_tree_node).PassInterface();
252 } 252 }
253 253
254 g_next_request_id--; 254 g_next_request_id--;
255 255
256 DCHECK(!request_controller_); 256 DCHECK(!request_controller_);
257 request_controller_ = base::MakeUnique<URLLoaderRequestController>( 257 request_controller_ = base::MakeUnique<URLLoaderRequestController>(
258 std::move(new_request), resource_context); 258 std::move(new_request), resource_context,
259 static_cast<StoragePartitionImpl*>(storage_partition)
260 ->url_loader_factory_getter());
259 BrowserThread::PostTask( 261 BrowserThread::PostTask(
260 BrowserThread::IO, FROM_HERE, 262 BrowserThread::IO, FROM_HERE,
261 base::Bind( 263 base::Bind(
262 &URLLoaderRequestController::Start, 264 &URLLoaderRequestController::Start,
263 base::Unretained(request_controller_.get()), 265 base::Unretained(request_controller_.get()),
264 service_worker_navigation_handle 266 service_worker_navigation_handle
265 ? service_worker_navigation_handle->core() 267 ? service_worker_navigation_handle->core()
266 : nullptr, 268 : nullptr,
267 appcache_handle ? appcache_handle->core() : nullptr, 269 appcache_handle ? appcache_handle->core() : nullptr,
268 base::Passed(std::move(request_info)), 270 base::Passed(std::move(request_info)),
269 base::Passed(std::move(factory_for_webui)), 271 base::Passed(std::move(factory_for_webui)),
270 static_cast<StoragePartitionImpl*>(storage_partition)
271 ->url_loader_factory_getter(),
272 base::Bind(&GetWebContentsFromFrameTreeNodeID, frame_tree_node_id), 272 base::Bind(&GetWebContentsFromFrameTreeNodeID, frame_tree_node_id),
273 base::Passed(std::move(loader_request)), 273 base::Passed(std::move(loader_request)),
274 base::Passed(std::move(url_loader_client_ptr_to_pass)), 274 base::Passed(std::move(url_loader_client_ptr_to_pass)),
275 base::Passed(ServiceManagerConnection::GetForProcess() 275 base::Passed(ServiceManagerConnection::GetForProcess()
276 ->GetConnector() 276 ->GetConnector()
277 ->Clone()))); 277 ->Clone())));
278 } 278 }
279 279
280 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() { 280 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() {
281 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 281 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", 350 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted",
351 this, "&NavigationURLLoaderNetworkService", this, 351 this, "&NavigationURLLoaderNetworkService", this,
352 "success", false); 352 "success", false);
353 353
354 delegate_->OnRequestFailed(completion_status.exists_in_cache, 354 delegate_->OnRequestFailed(completion_status.exists_in_cache,
355 completion_status.error_code); 355 completion_status.error_code);
356 } 356 }
357 } 357 }
358 358
359 } // namespace content 359 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698