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

Side by Side Diff: content/browser/appcache/appcache_request_handler.cc

Issue 2902653002: Get main frame and subframe AppCache loads to work. (Closed)
Patch Set: Rebase to tip to sync to the independent URLLoader patch for browser navigation 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 (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
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Main-resource handling ---------------------------------------------- 329 // Main-resource handling ----------------------------------------------
310 330
311 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( 331 std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource(
312 net::NetworkDelegate* network_delegate) { 332 net::NetworkDelegate* network_delegate) {
313 DCHECK(!job_.get()); 333 DCHECK(!job_.get());
314 DCHECK(host_); 334 DCHECK(host_);
315 335
316 // If a page falls into the scope of a ServiceWorker, any matching AppCaches 336 // 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 337 // should be ignored. This depends on the ServiceWorker handler being invoked
318 // prior to the AppCache handler. 338 // prior to the AppCache handler.
319 if (ServiceWorkerRequestHandler::IsControlledByServiceWorker( 339 // TODO(ananta)
340 // We need to handle this for AppCache requests initiated for the network
341 // service
342 if (request_->GetURLRequest() &&
343 ServiceWorkerRequestHandler::IsControlledByServiceWorker(
320 request_->GetURLRequest())) { 344 request_->GetURLRequest())) {
321 host_->enable_cache_selection(false); 345 host_->enable_cache_selection(false);
322 return nullptr; 346 return nullptr;
323 } 347 }
324 348
349 if (storage()->IsInitialized() &&
350 service_->storage()->usage_map()->find(request_->GetURL().GetOrigin()) ==
351 service_->storage()->usage_map()->end()) {
352 return nullptr;
353 }
354
325 host_->enable_cache_selection(true); 355 host_->enable_cache_selection(true);
326 356
327 const AppCacheHost* spawning_host = 357 const AppCacheHost* spawning_host =
328 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ? 358 (resource_type_ == RESOURCE_TYPE_SHARED_WORKER) ?
329 host_ : host_->GetSpawningHost(); 359 host_ : host_->GetSpawningHost();
330 GURL preferred_manifest_url = spawning_host ? 360 GURL preferred_manifest_url = spawning_host ?
331 spawning_host->preferred_manifest_url() : GURL(); 361 spawning_host->preferred_manifest_url() : GURL();
332 362
333 // We may have to wait for our storage query to complete, but 363 // We may have to wait for our storage query to complete, but
334 // this query can also complete syncrhonously. 364 // this query can also complete syncrhonously.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 526
497 if (!host_->associated_cache() || 527 if (!host_->associated_cache() ||
498 !host_->associated_cache()->is_complete()) { 528 !host_->associated_cache()->is_complete()) {
499 DeliverNetworkResponse(); 529 DeliverNetworkResponse();
500 return; 530 return;
501 } 531 }
502 532
503 ContinueMaybeLoadSubResource(); 533 ContinueMaybeLoadSubResource();
504 } 534 }
505 535
536 void AppCacheRequestHandler::MaybeCreateLoader(
537 const ResourceRequest& resource_request,
538 ResourceContext* resource_context,
539 LoaderCallback callback) {
540 navigation_request_job_ = MaybeLoadMainResource(nullptr);
541 if (!navigation_request_job_.get()) {
542 std::move(callback).Run(StartLoaderCallback());
543 return;
544 }
545 navigation_request_job_->AsURLLoaderJob()->SetURLLoaderFactoryGetter(
546 url_loader_factory_getter_.get());
547 navigation_request_job_->AsURLLoaderJob()->set_loader_callback(
548 std::move(callback));
kinuko 2017/06/08 10:31:21 nit: for readability maybe could we have a comment
ananta 2017/06/08 13:48:55 Done.
549 }
550
506 } // namespace content 551 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698