OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/appcache/appcache_request_handler.h" | 5 #include "content/browser/appcache/appcache_request_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "content/browser/appcache/appcache.h" | 10 #include "content/browser/appcache/appcache.h" |
11 #include "content/browser/appcache/appcache_backend_impl.h" | 11 #include "content/browser/appcache/appcache_backend_impl.h" |
12 #include "content/browser/appcache/appcache_host.h" | |
13 #include "content/browser/appcache/appcache_navigation_handle_core.h" | |
12 #include "content/browser/appcache/appcache_policy.h" | 14 #include "content/browser/appcache/appcache_policy.h" |
13 #include "content/browser/appcache/appcache_request.h" | 15 #include "content/browser/appcache/appcache_request.h" |
16 #include "content/browser/appcache/appcache_url_loader_factory.h" | |
17 #include "content/browser/appcache/appcache_url_loader_job.h" | |
18 #include "content/browser/appcache/appcache_url_loader_request.h" | |
14 #include "content/browser/appcache/appcache_url_request_job.h" | 19 #include "content/browser/appcache/appcache_url_request_job.h" |
15 #include "content/browser/service_worker/service_worker_request_handler.h" | 20 #include "content/browser/service_worker/service_worker_request_handler.h" |
21 #include "content/browser/url_loader_factory_getter.h" | |
16 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
17 #include "net/url_request/url_request_job.h" | 23 #include "net/url_request/url_request_job.h" |
18 | 24 |
19 namespace content { | 25 namespace content { |
20 | 26 |
21 AppCacheRequestHandler::AppCacheRequestHandler( | 27 AppCacheRequestHandler::AppCacheRequestHandler( |
22 AppCacheHost* host, | 28 AppCacheHost* host, |
23 ResourceType resource_type, | 29 ResourceType resource_type, |
24 bool should_reset_appcache, | 30 bool should_reset_appcache, |
25 std::unique_ptr<AppCacheRequest> request) | 31 std::unique_ptr<AppCacheRequest> request) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 222 |
217 void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess( | 223 void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess( |
218 int old_process_id) { | 224 int old_process_id) { |
219 if (!host_ || !host_for_cross_site_transfer_.get() || | 225 if (!host_ || !host_for_cross_site_transfer_.get() || |
220 old_process_id != old_process_id_) { | 226 old_process_id != old_process_id_) { |
221 return; | 227 return; |
222 } | 228 } |
223 CompleteCrossSiteTransfer(old_process_id_, old_host_id_); | 229 CompleteCrossSiteTransfer(old_process_id_, old_host_id_); |
224 } | 230 } |
225 | 231 |
232 // static | |
233 std::unique_ptr<AppCacheRequestHandler> | |
234 AppCacheRequestHandler::InitializeForNavigationNetworkService( | |
235 const ResourceRequest& request, | |
236 AppCacheNavigationHandleCore* appcache_handle_core, | |
237 URLLoaderFactoryGetter* url_loader_factory_getter) { | |
238 std::unique_ptr<AppCacheRequestHandler> handler = | |
239 appcache_handle_core->host()->CreateRequestHandler( | |
240 AppCacheURLLoaderRequest::Create(request), request.resource_type, | |
241 request.should_reset_appcache); | |
242 handler->url_loader_factory_getter_ = url_loader_factory_getter; | |
243 return handler; | |
244 } | |
245 | |
226 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { | 246 void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { |
227 storage()->CancelDelegateCallbacks(this); | 247 storage()->CancelDelegateCallbacks(this); |
228 host_ = NULL; // no need to RemoveObserver, the host is being deleted | 248 host_ = NULL; // no need to RemoveObserver, the host is being deleted |
229 | 249 |
230 // Since the host is being deleted, we don't have to complete any job | 250 // Since the host is being deleted, we don't have to complete any job |
231 // that is current running. It's destined for the bit bucket anyway. | 251 // that is current running. It's destined for the bit bucket anyway. |
232 if (job_.get()) { | 252 if (job_.get()) { |
233 job_->Kill(); | 253 job_->Kill(); |
234 job_.reset(); | 254 job_.reset(); |
235 } | 255 } |
(...skipping 21 matching lines...) Expand all Loading... | |
257 DCHECK(host_ && job_.get() && job_->IsWaiting()); | 277 DCHECK(host_ && job_.get() && job_->IsWaiting()); |
258 DCHECK(entry.has_response_id()); | 278 DCHECK(entry.has_response_id()); |
259 | 279 |
260 // Cache information about the response, for use by GetExtraResponseInfo. | 280 // Cache information about the response, for use by GetExtraResponseInfo. |
261 cache_id_ = cache_id; | 281 cache_id_ = cache_id; |
262 manifest_url_ = manifest_url; | 282 manifest_url_ = manifest_url; |
263 | 283 |
264 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) | 284 if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) |
265 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); | 285 host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); |
266 | 286 |
287 if (navigation_request_job_.get()) { | |
288 AppCacheURLLoaderFactory::CreateURLLoaderFactory( | |
289 mojo::MakeRequest(&appcache_factory_), | |
290 url_loader_factory_getter_.get(), | |
291 navigation_request_job_.release()); | |
292 std::move(loader_factory_callback_).Run(appcache_factory_.get()); | |
293 } | |
267 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); | 294 job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); |
268 } | 295 } |
269 | 296 |
270 void AppCacheRequestHandler::DeliverErrorResponse() { | 297 void AppCacheRequestHandler::DeliverErrorResponse() { |
271 DCHECK(job_.get() && job_->IsWaiting()); | 298 DCHECK(job_.get() && job_->IsWaiting()); |
272 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); | 299 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); |
273 DCHECK(manifest_url_.is_empty()); | 300 DCHECK(manifest_url_.is_empty()); |
274 job_->DeliverErrorResponse(); | 301 job_->DeliverErrorResponse(); |
275 } | 302 } |
276 | 303 |
277 void AppCacheRequestHandler::DeliverNetworkResponse() { | 304 void AppCacheRequestHandler::DeliverNetworkResponse() { |
278 DCHECK(job_.get() && job_->IsWaiting()); | 305 DCHECK(job_.get() && job_->IsWaiting()); |
279 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); | 306 DCHECK_EQ(kAppCacheNoCacheId, cache_id_); |
280 DCHECK(manifest_url_.is_empty()); | 307 DCHECK(manifest_url_.is_empty()); |
308 | |
309 // In network service land, if we are processing a navigation request, we | |
310 // need to inform the loader callback that we are not going to handle this | |
311 // request. | |
312 if (navigation_request_job_.get()) { | |
313 std::move(loader_factory_callback_).Run(nullptr); | |
314 navigation_request_job_.reset(nullptr); | |
315 return; | |
316 } | |
317 | |
281 job_->DeliverNetworkResponse(); | 318 job_->DeliverNetworkResponse(); |
282 } | 319 } |
283 | 320 |
284 void AppCacheRequestHandler::OnPrepareToRestart() { | 321 void AppCacheRequestHandler::OnPrepareToRestart() { |
285 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); | 322 DCHECK(job_->IsDeliveringNetworkResponse() || job_->IsCacheEntryNotFound()); |
286 | 323 |
287 // Any information about the source of the response is no longer relevant. | 324 // Any information about the source of the response is no longer relevant. |
288 cache_id_ = kAppCacheNoCacheId; | 325 cache_id_ = kAppCacheNoCacheId; |
289 manifest_url_ = GURL(); | 326 manifest_url_ = GURL(); |
290 | 327 |
(...skipping 18 matching lines...) Expand all Loading... | |
309 // Main-resource handling ---------------------------------------------- | 346 // Main-resource handling ---------------------------------------------- |
310 | 347 |
311 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( | 348 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( |
312 net::NetworkDelegate* network_delegate) { | 349 net::NetworkDelegate* network_delegate) { |
313 DCHECK(!job_.get()); | 350 DCHECK(!job_.get()); |
314 DCHECK(host_); | 351 DCHECK(host_); |
315 | 352 |
316 // If a page falls into the scope of a ServiceWorker, any matching AppCaches | 353 // If a page falls into the scope of a ServiceWorker, any matching AppCaches |
317 // should be ignored. This depends on the ServiceWorker handler being invoked | 354 // should be ignored. This depends on the ServiceWorker handler being invoked |
318 // prior to the AppCache handler. | 355 // prior to the AppCache handler. |
319 if (ServiceWorkerRequestHandler::IsControlledByServiceWorker( | 356 // TODO(ananta) |
357 // We need to handle this for AppCache requests initiated for the network | |
358 // service | |
359 if (request_->GetURLRequest() && | |
360 ServiceWorkerRequestHandler::IsControlledByServiceWorker( | |
320 request_->GetURLRequest())) { | 361 request_->GetURLRequest())) { |
321 host_->enable_cache_selection(false); | 362 host_->enable_cache_selection(false); |
322 return nullptr; | 363 return nullptr; |
323 } | 364 } |
324 | 365 |
366 if (storage()->IsInitialized() && | |
367 service_->storage()->usage_map()->find(request_->GetURL().GetOrigin()) == | |
368 service_->storage()->usage_map()->end()) { | |
369 return nullptr; | |
370 } | |
371 | |
325 host_->enable_cache_selection(true); | 372 host_->enable_cache_selection(true); |
326 | 373 |
327 const AppCacheHost* spawning_host = | 374 const AppCacheHost* spawning_host = |
328 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? | 375 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? |
329 host_ : host_->GetSpawningHost(); | 376 host_ : host_->GetSpawningHost(); |
330 GURL preferred_manifest_url = spawning_host ? | 377 GURL preferred_manifest_url = spawning_host ? |
331 spawning_host->preferred_manifest_url() : GURL(); | 378 spawning_host->preferred_manifest_url() : GURL(); |
332 | 379 |
333 // We may have to wait for our storage query to complete, but | 380 // We may have to wait for our storage query to complete, but |
334 // this query can also complete syncrhonously. | 381 // this query can also complete syncrhonously. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 | 543 |
497 if (!host_->associated_cache() || | 544 if (!host_->associated_cache() || |
498 !host_->associated_cache()->is_complete()) { | 545 !host_->associated_cache()->is_complete()) { |
499 DeliverNetworkResponse(); | 546 DeliverNetworkResponse(); |
500 return; | 547 return; |
501 } | 548 } |
502 | 549 |
503 ContinueMaybeLoadSubResource(); | 550 ContinueMaybeLoadSubResource(); |
504 } | 551 } |
505 | 552 |
553 void AppCacheRequestHandler::MaybeCreateLoaderFactory( | |
554 const ResourceRequest& resource_request, | |
555 ResourceContext* resource_context, | |
556 LoaderFactoryCallback callback) { | |
kinuko
2017/06/06 08:07:30
(As michael wrote we're likely changing this part,
ananta
2017/06/06 20:49:15
Will keep an eye out :)
| |
557 navigation_request_job_ = MaybeLoadMainResource(nullptr); | |
558 if (!navigation_request_job_.get()) { | |
559 std::move(callback).Run(nullptr); | |
560 return; | |
561 } | |
562 navigation_request_job_->AsURLLoaderJob()->SetURLLoaderFactoryGetter( | |
563 url_loader_factory_getter_.get()); | |
564 loader_factory_callback_ = std::move(callback); | |
565 } | |
566 | |
506 } // namespace content | 567 } // namespace content |
OLD | NEW |