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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/ResourceFetcher.cpp

Issue 2816403002: test all
Patch Set: fix sharedworker Created 3 years, 8 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 /* 1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All 5 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6 rights reserved. 6 rights reserved.
7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ 7 Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // Fall back to the network if the archive doesn't contain the resource. 414 // Fall back to the network if the archive doesn't contain the resource.
415 if (!archive_resource) 415 if (!archive_resource)
416 return nullptr; 416 return nullptr;
417 data = archive_resource->Data(); 417 data = archive_resource->Data();
418 response.SetURL(url); 418 response.SetURL(url);
419 response.SetMimeType(archive_resource->MimeType()); 419 response.SetMimeType(archive_resource->MimeType());
420 response.SetExpectedContentLength(data->size()); 420 response.SetExpectedContentLength(data->size());
421 response.SetTextEncodingName(archive_resource->TextEncoding()); 421 response.SetTextEncodingName(archive_resource->TextEncoding());
422 } 422 }
423 423
424 Resource* resource = factory.Create(params.GetResourceRequest(), 424 Resource* resource =
425 params.Options(), params.Charset()); 425 factory.Create(params.GetResourceRequest(), params.Options(),
426 params.Charset(), &Context());
426 resource->SetNeedsSynchronousCacheHit(substitute_data.ForceSynchronousLoad()); 427 resource->SetNeedsSynchronousCacheHit(substitute_data.ForceSynchronousLoad());
427 // FIXME: We should provide a body stream here. 428 // FIXME: We should provide a body stream here.
428 resource->ResponseReceived(response, nullptr); 429 resource->ResponseReceived(response, nullptr);
429 resource->SetDataBufferingPolicy(kBufferData); 430 resource->SetDataBufferingPolicy(kBufferData);
430 if (data->size()) 431 if (data->size())
431 resource->SetResourceBuffer(data); 432 resource->SetResourceBuffer(data);
432 resource->SetIdentifier(CreateUniqueIdentifier()); 433 resource->SetIdentifier(CreateUniqueIdentifier());
433 resource->SetCacheIdentifier(cache_identifier); 434 resource->SetCacheIdentifier(cache_identifier);
434 resource->Finish(); 435 resource->Finish();
435 436
436 if (!substitute_data.IsValid()) 437 if (!substitute_data.IsValid())
437 GetMemoryCache()->Add(resource); 438 GetMemoryCache()->Add(resource);
438 439
439 return resource; 440 return resource;
440 } 441 }
441 442
442 Resource* ResourceFetcher::ResourceForBlockedRequest( 443 Resource* ResourceFetcher::ResourceForBlockedRequest(
443 const FetchParameters& params, 444 const FetchParameters& params,
444 const ResourceFactory& factory, 445 const ResourceFactory& factory,
445 ResourceRequestBlockedReason blocked_reason) { 446 ResourceRequestBlockedReason blocked_reason) {
446 Resource* resource = factory.Create(params.GetResourceRequest(), 447 Resource* resource =
447 params.Options(), params.Charset()); 448 factory.Create(params.GetResourceRequest(), params.Options(),
449 params.Charset(), &Context());
448 resource->GetError(ResourceError::CancelledDueToAccessCheckError( 450 resource->GetError(ResourceError::CancelledDueToAccessCheckError(
449 params.Url(), blocked_reason)); 451 params.Url(), blocked_reason));
450 return resource; 452 return resource;
451 } 453 }
452 454
453 void ResourceFetcher::MakePreloadedResourceBlockOnloadIfNeeded( 455 void ResourceFetcher::MakePreloadedResourceBlockOnloadIfNeeded(
454 Resource* resource, 456 Resource* resource,
455 const FetchParameters& params) { 457 const FetchParameters& params) {
456 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue 458 // TODO(yoav): Test that non-blocking resources (video/audio/track) continue
457 // to not-block even after being preloaded and discovered. 459 // to not-block even after being preloaded and discovered.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 bool is_static_data = is_data_url || substitute_data.IsValid() || archive_; 580 bool is_static_data = is_data_url || substitute_data.IsValid() || archive_;
579 if (is_static_data) { 581 if (is_static_data) {
580 resource = ResourceForStaticData(params, factory, substitute_data); 582 resource = ResourceForStaticData(params, factory, substitute_data);
581 // Abort the request if the archive doesn't contain the resource, except in 583 // Abort the request if the archive doesn't contain the resource, except in
582 // the case of data URLs which might have resources such as fonts that need 584 // the case of data URLs which might have resources such as fonts that need
583 // to be decoded only on demand. These data URLs are allowed to be 585 // to be decoded only on demand. These data URLs are allowed to be
584 // processed using the normal ResourceFetcher machinery. 586 // processed using the normal ResourceFetcher machinery.
585 if (!resource && !is_data_url && archive_) 587 if (!resource && !is_data_url && archive_)
586 return nullptr; 588 return nullptr;
587 } 589 }
588 if (!resource) { 590 if (!resource && IsMainThread()) {
589 resource = 591 resource =
590 GetMemoryCache()->ResourceForURL(params.Url(), GetCacheIdentifier()); 592 GetMemoryCache()->ResourceForURL(params.Url(), GetCacheIdentifier());
591 } 593 }
592 594
593 // If we got a preloaded resource from the cache for a non-preload request, 595 // If we got a preloaded resource from the cache for a non-preload request,
594 // we may need to make it block the onload event. 596 // we may need to make it block the onload event.
595 MakePreloadedResourceBlockOnloadIfNeeded(resource, params); 597 MakePreloadedResourceBlockOnloadIfNeeded(resource, params);
596 598
597 const RevalidationPolicy policy = DetermineRevalidationPolicy( 599 const RevalidationPolicy policy = DetermineRevalidationPolicy(
598 factory.GetType(), params, resource, is_static_data); 600 factory.GetType(), params, resource, is_static_data);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 revalidating_request.SetHTTPHeaderField(HTTPNames::If_None_Match, e_tag); 729 revalidating_request.SetHTTPHeaderField(HTTPNames::If_None_Match, e_tag);
728 730
729 resource->SetRevalidatingRequest(revalidating_request); 731 resource->SetRevalidatingRequest(revalidating_request);
730 } 732 }
731 733
732 Resource* ResourceFetcher::CreateResourceForLoading( 734 Resource* ResourceFetcher::CreateResourceForLoading(
733 FetchParameters& params, 735 FetchParameters& params,
734 const String& charset, 736 const String& charset,
735 const ResourceFactory& factory) { 737 const ResourceFactory& factory) {
736 const String cache_identifier = GetCacheIdentifier(); 738 const String cache_identifier = GetCacheIdentifier();
737 DCHECK(!GetMemoryCache()->ResourceForURL(params.GetResourceRequest().Url(), 739 DCHECK(!IsMainThread() ||
740 !GetMemoryCache()->ResourceForURL(params.GetResourceRequest().Url(),
738 cache_identifier)); 741 cache_identifier));
739 742
740 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for " 743 RESOURCE_LOADING_DVLOG(1) << "Loading Resource for "
741 << params.GetResourceRequest().Url().ElidedString(); 744 << params.GetResourceRequest().Url().ElidedString();
742 745
743 Resource* resource = 746 Resource* resource = factory.Create(params.GetResourceRequest(),
744 factory.Create(params.GetResourceRequest(), params.Options(), charset); 747 params.Options(), charset, &Context());
745 resource->SetLinkPreload(params.IsLinkPreload()); 748 resource->SetLinkPreload(params.IsLinkPreload());
746 if (params.IsSpeculativePreload()) { 749 if (params.IsSpeculativePreload()) {
747 resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime()); 750 resource->SetPreloadDiscoveryTime(params.PreloadDiscoveryTime());
748 } 751 }
749 resource->SetCacheIdentifier(cache_identifier); 752 resource->SetCacheIdentifier(cache_identifier);
750 753
751 // - Don't add main resource to cache to prevent reuse. 754 // - Don't add main resource to cache to prevent reuse.
752 // - Don't add the resource if its body will not be stored. 755 // - Don't add the resource if its body will not be stored.
753 if (factory.GetType() != Resource::kMainResource && 756 if (IsMainThread() && factory.GetType() != Resource::kMainResource &&
754 params.Options().data_buffering_policy != kDoNotBufferData) { 757 params.Options().data_buffering_policy != kDoNotBufferData) {
755 GetMemoryCache()->Add(resource); 758 GetMemoryCache()->Add(resource);
756 } 759 }
757 return resource; 760 return resource;
758 } 761 }
759 762
760 void ResourceFetcher::StorePerformanceTimingInitiatorInformation( 763 void ResourceFetcher::StorePerformanceTimingInitiatorInformation(
761 Resource* resource) { 764 Resource* resource) {
762 const AtomicString& fetch_initiator = resource->Options().initiator_info.name; 765 const AtomicString& fetch_initiator = resource->Options().initiator_info.name;
763 if (fetch_initiator == FetchInitiatorTypeNames::internal) 766 if (fetch_initiator == FetchInitiatorTypeNames::internal)
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 DCHECK(loader); 1256 DCHECK(loader);
1254 // TODO(yoav): Convert CHECK to DCHECK if no crash reports come in. 1257 // TODO(yoav): Convert CHECK to DCHECK if no crash reports come in.
1255 CHECK(loaders_.Contains(loader)); 1258 CHECK(loaders_.Contains(loader));
1256 non_blocking_loaders_.insert(loader); 1259 non_blocking_loaders_.insert(loader);
1257 loaders_.erase(loader); 1260 loaders_.erase(loader);
1258 } 1261 }
1259 1262
1260 bool ResourceFetcher::StartLoad(Resource* resource) { 1263 bool ResourceFetcher::StartLoad(Resource* resource) {
1261 DCHECK(resource); 1264 DCHECK(resource);
1262 DCHECK(resource->StillNeedsLoad()); 1265 DCHECK(resource->StillNeedsLoad());
1263 if (!Context().ShouldLoadNewResource(resource->GetType())) { 1266 if (IsMainThread() && !Context().ShouldLoadNewResource(resource->GetType())) {
1264 GetMemoryCache()->Remove(resource); 1267 GetMemoryCache()->Remove(resource);
1265 return false; 1268 return false;
1266 } 1269 }
1267 1270
1268 ResourceRequest request(resource->GetResourceRequest()); 1271 ResourceRequest request(resource->GetResourceRequest());
1269 ResourceResponse response; 1272 ResourceResponse response;
1270 1273
1271 blink::probe::PlatformSendRequest probe(&Context(), resource->Identifier(), 1274 blink::probe::PlatformSendRequest probe(&Context(), resource->Identifier(),
1272 request, response, 1275 request, response,
1273 resource->Options().initiator_info); 1276 resource->Options().initiator_info);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 visitor->Trace(context_); 1580 visitor->Trace(context_);
1578 visitor->Trace(archive_); 1581 visitor->Trace(archive_);
1579 visitor->Trace(loaders_); 1582 visitor->Trace(loaders_);
1580 visitor->Trace(non_blocking_loaders_); 1583 visitor->Trace(non_blocking_loaders_);
1581 visitor->Trace(document_resources_); 1584 visitor->Trace(document_resources_);
1582 visitor->Trace(preloads_); 1585 visitor->Trace(preloads_);
1583 visitor->Trace(resource_timing_info_map_); 1586 visitor->Trace(resource_timing_info_map_);
1584 } 1587 }
1585 1588
1586 } // namespace blink 1589 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698