Changeset 228892 in webkit
- Timestamp:
- Feb 21, 2018 12:21:59 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r228886 r228892 1 2018-02-21 Youenn Fablet <youenn@apple.com> 2 3 Use ResourceLoader to load appcache manifest 4 https://bugs.webkit.org/show_bug.cgi?id=182861 5 6 Reviewed by Alex Christensen. 7 8 * http/tests/appcache/fail-on-update-2-expected.txt: 9 * http/tests/appcache/manifest-redirect-2-expected.txt: 10 * http/tests/appcache/offline-access-expected.txt: 11 1 12 2018-02-21 Chris Dumez <cdumez@apple.com> 2 13 -
trunk/LayoutTests/http/tests/appcache/fail-on-update-2-expected.txt
r228591 r228892 1 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 2 CONSOLE MESSAGE: Application Cache manifest could not be fetched, because the manifest had a 404 response. 1 3 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 2 4 CONSOLE MESSAGE: Application Cache manifest could not be fetched, because the manifest had a 404 response. 3 5 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 4 6 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 5 CONSOLE MESSAGE: Application Cache manifest could not be fetched, because the manifest had a 404 response.6 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead.7 7 SUCCESS: No crash. -
trunk/LayoutTests/http/tests/appcache/manifest-redirect-2-expected.txt
r228591 r228892 1 1 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 2 CONSOLE MESSAGE: Application Cache manifest could not be fetched, because a redirection was attempted. 2 3 Test that a redirect makes resource caching fail. 3 4 -
trunk/LayoutTests/http/tests/appcache/offline-access-expected.txt
r228591 r228892 1 1 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 2 2 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 3 CONSOLE MESSAGE: Application Cache manifest could not be fetched, because a redirection was attempted. 3 4 CONSOLE MESSAGE: line 1: ApplicationCache is deprecated. Please use ServiceWorkers instead. 4 5 Test that offline applications work when there is no network access (simulated). -
trunk/Source/WebCore/ChangeLog
r228891 r228892 1 2018-02-21 Youenn Fablet <youenn@apple.com> 2 3 Use ResourceLoader to load appcache manifest 4 https://bugs.webkit.org/show_bug.cgi?id=182861 5 6 Reviewed by Alex Christensen. 7 8 Covered by updated tests. 9 10 Add ApplicationCacheResourceLoader to load an ApplicationCacheResource from a ResourceLoader. 11 Make use of it to load the app cache manifest. 12 Future work should load entries using the same loader. 13 14 Remove manifest handle. 15 Ensure that DocumentLoader does not register the manifest resource loader as its lifetime 16 is handled by its ApplicationCacheGroup. 17 18 Add a ResourceLoader option to bypass the application cache. 19 Use it for manifest loading. 20 21 * Sources.txt: 22 * WebCore.xcodeproj/project.pbxproj: 23 * loader/DocumentLoader.cpp: 24 (WebCore::DocumentLoader::addSubresourceLoader): 25 * loader/ResourceLoaderOptions.h: 26 * loader/appcache/ApplicationCacheGroup.cpp: 27 (WebCore::ApplicationCacheGroup::stopLoading): 28 (WebCore::ApplicationCacheGroup::update): 29 (WebCore::ApplicationCacheGroup::createRequest): 30 (WebCore::ApplicationCacheGroup::didReceiveResponseAsync): 31 (WebCore::ApplicationCacheGroup::didReceiveData): 32 (WebCore::ApplicationCacheGroup::didFinishLoading): 33 (WebCore::ApplicationCacheGroup::didFail): 34 (WebCore::ApplicationCacheGroup::didFinishLoadingManifest): 35 (WebCore::ApplicationCacheGroup::checkIfLoadIsComplete): 36 * loader/appcache/ApplicationCacheGroup.h: 37 * loader/appcache/ApplicationCacheHost.cpp: 38 (WebCore::ApplicationCacheHost::maybeLoadResource): 39 (WebCore::ApplicationCacheHost::maybeLoadFallbackForRedirect): 40 (WebCore::ApplicationCacheHost::maybeLoadFallbackForResponse): 41 (WebCore::ApplicationCacheHost::maybeLoadFallbackForError): 42 * loader/appcache/ApplicationCacheResourceLoader.cpp: Added. 43 * loader/appcache/ApplicationCacheResourceLoader.h: Added. 44 1 45 2018-02-21 Don Olmstead <don.olmstead@sony.com> 2 46 -
trunk/Source/WebCore/Sources.txt
r228862 r228892 1253 1253 loader/appcache/ApplicationCacheHost.cpp 1254 1254 loader/appcache/ApplicationCacheResource.cpp 1255 loader/appcache/ApplicationCacheResourceLoader.cpp 1255 1256 loader/appcache/ApplicationCacheStorage.cpp 1256 1257 loader/appcache/DOMApplicationCache.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r228862 r228892 7109 7109 418F88020FF957AE0080F045 /* JSAbstractWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAbstractWorker.cpp; sourceTree = "<group>"; }; 7110 7110 418F88030FF957AE0080F045 /* JSAbstractWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbstractWorker.h; sourceTree = "<group>"; }; 7111 41945694203502A5004BA277 /* ApplicationCacheResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationCacheResourceLoader.cpp; sourceTree = "<group>"; }; 7112 41945696203502A6004BA277 /* ApplicationCacheResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplicationCacheResourceLoader.h; sourceTree = "<group>"; }; 7111 7113 419ACF8E1F97E7D5009F1A83 /* ServiceWorkerFetch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerFetch.h; sourceTree = "<group>"; }; 7112 7114 419ACF901F97E7D6009F1A83 /* ServiceWorkerFetch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerFetch.cpp; sourceTree = "<group>"; }; … … 15703 15705 1A8F6BB50DB55CDC001DB794 /* ApplicationCacheResource.cpp */, 15704 15706 1A8F6BB60DB55CDC001DB794 /* ApplicationCacheResource.h */, 15707 41945694203502A5004BA277 /* ApplicationCacheResourceLoader.cpp */, 15708 41945696203502A6004BA277 /* ApplicationCacheResourceLoader.h */, 15705 15709 1A2AAC560DC2A3B100A20D9A /* ApplicationCacheStorage.cpp */, 15706 15710 1A2AAC570DC2A3B100A20D9A /* ApplicationCacheStorage.h */, -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r228852 r228892 1544 1544 ASSERT(!mainResourceLoader() || mainResourceLoader() != loader); 1545 1545 1546 // Application Cache loaders are handled by their ApplicationCacheGroup directly. 1547 if (loader->options().applicationCacheMode == ApplicationCacheMode::Bypass) 1548 return; 1549 1546 1550 // A page in the PageCache or about to enter PageCache should not be able to start loads. 1547 1551 ASSERT_WITH_SECURITY_IMPLICATION(!document() || document()->pageCacheState() == Document::NotInPageCache); -
trunk/Source/WebCore/loader/ResourceLoaderOptions.h
r228591 r228892 102 102 }; 103 103 104 enum class ApplicationCacheMode { 105 Use, 106 Bypass 107 }; 108 104 109 enum class ContentEncodingSniffingPolicy { 105 110 Sniff, … … 141 146 InitiatorContext initiatorContext { InitiatorContext::Document }; 142 147 ServiceWorkersMode serviceWorkersMode { ServiceWorkersMode::All }; 148 ApplicationCacheMode applicationCacheMode { ApplicationCacheMode::Use }; 143 149 #if ENABLE(SERVICE_WORKER) 144 150 std::optional<ServiceWorkerRegistrationIdentifier> serviceWorkerRegistrationIdentifier; -
trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp
r228591 r228892 30 30 #include "ApplicationCacheHost.h" 31 31 #include "ApplicationCacheResource.h" 32 #include "ApplicationCacheResourceLoader.h" 32 33 #include "ApplicationCacheStorage.h" 33 34 #include "Chrome.h" … … 315 316 void ApplicationCacheGroup::stopLoading() 316 317 { 317 if (m_manifestHandle) { 318 ASSERT(!m_currentHandle); 319 320 ASSERT(m_manifestHandle->client() == this); 321 m_manifestHandle->clearClient(); 322 323 m_manifestHandle->cancel(); 324 m_manifestHandle = nullptr; 325 } 326 318 if (m_loader) { 319 m_loader->cancel(); 320 m_loader = nullptr; 321 } 322 327 323 if (m_currentHandle) { 328 ASSERT(!m_ manifestHandle);324 ASSERT(!m_loader); 329 325 ASSERT(m_cacheBeingUpdated); 330 326 … … 437 433 } 438 434 439 ASSERT(!m_ manifestHandle);435 ASSERT(!m_loader); 440 436 ASSERT(!m_manifestResource); 441 437 ASSERT(!m_currentHandle); … … 444 440 445 441 // FIXME: Handle defer loading 446 m_manifestHandle = createResourceHandle(m_manifestURL, m_newestCache ? m_newestCache->manifestResource() : 0); 442 443 auto request = createRequest(URL { m_manifestURL }, m_newestCache ? m_newestCache->manifestResource() : nullptr); 444 445 m_currentResourceIdentifier = m_frame->page()->progress().createUniqueIdentifier(); 446 InspectorInstrumentation::willSendRequest(m_frame, m_currentResourceIdentifier, m_frame->loader().documentLoader(), request, ResourceResponse { }); 447 448 m_loader = ApplicationCacheResourceLoader::create(documentLoader.cachedResourceLoader(), WTFMove(request), [this] (auto&& resourceOrError) { 449 // 'this' is only valid if returned value is not Error::Abort. 450 if (!resourceOrError.has_value()) { 451 auto error = resourceOrError.error(); 452 if (error == ApplicationCacheResourceLoader::Error::Abort) 453 return; 454 if (error == ApplicationCacheResourceLoader::Error::CannotCreateResource) { 455 // FIXME: We should get back the error from ApplicationCacheResourceLoader level. 456 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, ResourceError { ResourceError::Type::General }); 457 this->cacheUpdateFailed(); 458 return; 459 } 460 this->didFailLoadingManifest(error); 461 return; 462 } 463 464 m_manifestResource = WTFMove(resourceOrError.value()); 465 this->didFinishLoadingManifest(); 466 }); 467 } 468 469 ResourceRequest ApplicationCacheGroup::createRequest(URL&& url, ApplicationCacheResource* resource) 470 { 471 ResourceRequest request { WTFMove(url) }; 472 m_frame->loader().applyUserAgentIfNeeded(request); 473 request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "max-age=0"); 474 475 if (resource) { 476 const String& lastModified = resource->response().httpHeaderField(HTTPHeaderName::LastModified); 477 if (!lastModified.isEmpty()) 478 request.setHTTPHeaderField(HTTPHeaderName::IfModifiedSince, lastModified); 479 480 const String& eTag = resource->response().httpHeaderField(HTTPHeaderName::ETag); 481 if (!eTag.isEmpty()) 482 request.setHTTPHeaderField(HTTPHeaderName::IfNoneMatch, eTag); 483 } 484 return request; 447 485 } 448 486 … … 494 532 ASSERT(m_frame); 495 533 InspectorInstrumentation::didReceiveResourceResponse(*m_frame, m_currentResourceIdentifier, m_frame->loader().documentLoader(), response, nullptr); 496 497 if (handle == m_manifestHandle) {498 didReceiveManifestResponse(response);499 completionHandler();500 return;501 }502 534 503 535 ASSERT(handle == m_currentHandle); … … 579 611 { 580 612 UNUSED_PARAM(encodedDataLength); 613 ASSERT_UNUSED(handle, handle == m_currentHandle); 581 614 582 615 InspectorInstrumentation::didReceiveData(m_frame, m_currentResourceIdentifier, 0, length, 0); 583 616 584 if (handle == m_manifestHandle) {585 didReceiveManifestData(data, length);586 return;587 }588 589 ASSERT(handle == m_currentHandle);590 591 617 ASSERT(m_currentResource); 592 618 m_currentResource->data().append(data, length); … … 598 624 NetworkLoadMetrics emptyMetrics; 599 625 InspectorInstrumentation::didFinishLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, emptyMetrics, nullptr); 600 601 if (handle == m_manifestHandle) {602 didFinishLoadingManifest();603 return;604 }605 626 606 627 ASSERT(m_currentHandle == handle); … … 633 654 { 634 655 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, error); 635 636 if (handle == m_manifestHandle) {637 // A network error is logged elsewhere, no need to log again. Also, it's normal for manifest fetching to fail when working offline.638 cacheUpdateFailed();639 return;640 }641 656 642 657 ASSERT(handle == m_currentHandle); … … 666 681 } 667 682 668 void ApplicationCacheGroup::didReceiveManifestResponse(const ResourceResponse& response)669 {670 ASSERT(!m_manifestResource);671 ASSERT(m_manifestHandle);672 673 if (response.httpStatusCode() == 404 || response.httpStatusCode() == 410) {674 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, m_frame->loader().cancelledError(m_manifestHandle->firstRequest()));675 m_frame->document()->addConsoleMessage(MessageSource::AppCache, MessageLevel::Error, makeString("Application Cache manifest could not be fetched, because the manifest had a ", String::number(response.httpStatusCode()), " response."));676 manifestNotFound();677 return;678 }679 680 if (response.httpStatusCode() == 304)681 return;682 683 if (response.httpStatusCode() / 100 != 2) {684 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, m_frame->loader().cancelledError(m_manifestHandle->firstRequest()));685 m_frame->document()->addConsoleMessage(MessageSource::AppCache, MessageLevel::Error, makeString("Application Cache manifest could not be fetched, because the manifest had a ", String::number(response.httpStatusCode()), " response."));686 cacheUpdateFailed();687 return;688 }689 690 if (response.url() != m_manifestHandle->firstRequest().url()) {691 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, m_frame->loader().cancelledError(m_manifestHandle->firstRequest()));692 m_frame->document()->addConsoleMessage(MessageSource::AppCache, MessageLevel::Error, ASCIILiteral("Application Cache manifest could not be fetched, because a redirection was attempted."));693 cacheUpdateFailed();694 return;695 }696 697 m_manifestResource = ApplicationCacheResource::create(m_manifestHandle->firstRequest().url(), response, ApplicationCacheResource::Manifest);698 }699 700 void ApplicationCacheGroup::didReceiveManifestData(const char* data, int length)701 {702 if (m_manifestResource)703 m_manifestResource->data().append(data, length);704 }705 706 683 void ApplicationCacheGroup::didFinishLoadingManifest() 707 684 { … … 715 692 } 716 693 717 m_ manifestHandle= nullptr;694 m_loader = nullptr; 718 695 719 696 // Check if the manifest was not modified. … … 779 756 780 757 startLoadingEntry(); 758 } 759 760 void ApplicationCacheGroup::didFailLoadingManifest(ApplicationCacheResourceLoader::Error error) 761 { 762 ASSERT(error != ApplicationCacheResourceLoader::Error::Abort && error != ApplicationCacheResourceLoader::Error::CannotCreateResource); 763 764 InspectorInstrumentation::didReceiveResourceResponse(*m_frame, m_currentResourceIdentifier, m_frame->loader().documentLoader(), m_loader->resource()->response(), nullptr); 765 switch (error) { 766 case ApplicationCacheResourceLoader::Error::NetworkError: 767 cacheUpdateFailed(); 768 break; 769 case ApplicationCacheResourceLoader::Error::NotFound: 770 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, m_frame->loader().cancelledError(m_loader->resource()->resourceRequest())); 771 m_frame->document()->addConsoleMessage(MessageSource::AppCache, MessageLevel::Error, makeString("Application Cache manifest could not be fetched, because the manifest had a ", String::number(m_loader->resource()->response().httpStatusCode()), " response.")); 772 manifestNotFound(); 773 break; 774 case ApplicationCacheResourceLoader::Error::NotOK: 775 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, m_frame->loader().cancelledError(m_loader->resource()->resourceRequest())); 776 m_frame->document()->addConsoleMessage(MessageSource::AppCache, MessageLevel::Error, makeString("Application Cache manifest could not be fetched, because the manifest had a ", String::number(m_loader->resource()->response().httpStatusCode()), " response.")); 777 cacheUpdateFailed(); 778 break; 779 case ApplicationCacheResourceLoader::Error::RedirectForbidden: 780 InspectorInstrumentation::didFailLoading(m_frame, m_frame->loader().documentLoader(), m_currentResourceIdentifier, m_frame->loader().cancelledError(m_loader->resource()->resourceRequest())); 781 m_frame->document()->addConsoleMessage(MessageSource::AppCache, MessageLevel::Error, makeString("Application Cache manifest could not be fetched, because a redirection was attempted.")); 782 cacheUpdateFailed(); 783 break; 784 case ApplicationCacheResourceLoader::Error::CannotCreateResource: 785 case ApplicationCacheResourceLoader::Error::Abort: 786 break; 787 } 781 788 } 782 789 … … 849 856 void ApplicationCacheGroup::checkIfLoadIsComplete() 850 857 { 851 if (m_ manifestHandle|| !m_pendingEntries.isEmpty() || m_downloadingPendingMasterResourceLoadersCount)852 return; 853 858 if (m_loader || !m_pendingEntries.isEmpty() || m_downloadingPendingMasterResourceLoadersCount) 859 return; 860 854 861 // We're done, all resources have finished downloading (successfully or not). 855 862 -
trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.h
r228591 r228892 26 26 #pragma once 27 27 28 #include "ApplicationCacheResourceLoader.h" 28 29 #include "DOMApplicationCache.h" 29 30 #include "URL.h" … … 119 120 void didFail(ResourceHandle*, const ResourceError&) final; 120 121 121 void didReceiveManifestResponse(const ResourceResponse&);122 void didReceiveManifestData(const char*, int);123 122 void didFinishLoadingManifest(); 123 void didFailLoadingManifest(ApplicationCacheResourceLoader::Error); 124 124 125 void didReachMaxAppCacheSize(); 125 126 void didReachOriginQuota(int64_t totalSpaceNeeded); … … 137 138 138 139 void stopLoading(); 140 141 ResourceRequest createRequest(URL&&, ApplicationCacheResource*); 139 142 140 143 Ref<ApplicationCacheStorage> m_storage; … … 196 199 197 200 RefPtr<ApplicationCacheResource> m_manifestResource; 198 RefPtr<ResourceHandle> m_manifestHandle; 201 202 RefPtr<ApplicationCacheResourceLoader> m_loader; 199 203 200 204 int64_t m_availableSpaceInQuota; -
trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp
r228591 r228892 170 170 bool ApplicationCacheHost::maybeLoadResource(ResourceLoader& loader, const ResourceRequest& request, const URL& originalURL) 171 171 { 172 if (loader.options().applicationCacheMode != ApplicationCacheMode::Use) 173 return false; 174 172 175 if (!isApplicationCacheEnabled() && !isApplicationCacheBlockedForRequest(request)) 173 176 return false; … … 186 189 bool ApplicationCacheHost::maybeLoadFallbackForRedirect(ResourceLoader* resourceLoader, ResourceRequest& request, const ResourceResponse& redirectResponse) 187 190 { 191 if (resourceLoader && resourceLoader->options().applicationCacheMode != ApplicationCacheMode::Use) 192 return false; 193 188 194 if (!redirectResponse.isNull() && !protocolHostAndPortAreEqual(request.url(), redirectResponse.url())) { 189 195 if (scheduleLoadFallbackResourceFromApplicationCache(resourceLoader)) … … 195 201 bool ApplicationCacheHost::maybeLoadFallbackForResponse(ResourceLoader* resourceLoader, const ResourceResponse& response) 196 202 { 203 if (resourceLoader && resourceLoader->options().applicationCacheMode != ApplicationCacheMode::Use) 204 return false; 205 197 206 if (response.httpStatusCode() / 100 == 4 || response.httpStatusCode() / 100 == 5) { 198 207 if (scheduleLoadFallbackResourceFromApplicationCache(resourceLoader)) … … 204 213 bool ApplicationCacheHost::maybeLoadFallbackForError(ResourceLoader* resourceLoader, const ResourceError& error) 205 214 { 215 if (resourceLoader && resourceLoader->options().applicationCacheMode != ApplicationCacheMode::Use) 216 return false; 217 206 218 if (!error.isCancellation()) { 207 219 if (resourceLoader == m_documentLoader.mainResourceLoader())
Note: See TracChangeset
for help on using the changeset viewer.