Returning NULL from willSendRequest should cancel a load from the memory cache
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Apr 2013 03:09:25 +0000 (03:09 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 6 Apr 2013 03:09:25 +0000 (03:09 +0000)
commit1d905ae4daab56aa0eed8a77966005f5c6b9d690
tree5273396f3cadc46d7e93750c284be817027c9097
parent3271900a7a2197539d1d8c36d32b5f7262c0b508
Returning NULL from willSendRequest should cancel a load from the memory cache
https://bugs.webkit.org/show_bug.cgi?id=114075

Reviewed by Darin Adler.

Source/WebCore:

When a resource is loaded from the memory cache and the client does not
implement the didLoadResourceFromMemoryCache delegate method, WebKit
synthesizes the typical sequence of resource load callbacks. One of
these is willSendRequest, which gives the client the opportunity to
modify the request. We should respect these modifications.

Handling any arbitrary modification is difficult given where in the
loading process we check the memory cache (see <http://webkit.org/b/113251>),
but we can handle the common case where the client cancels the load by
returning a NULL request.

Test: fast/loader/willsendrequest-returns-null-for-memory-cache-load.html

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::willLoadMediaElementURL): Passed request to sendRemainingDelegateMessages.
(WebCore::FrameLoader::commitProvisionalLoad): Ditto.
(WebCore::FrameLoader::loadResourceSynchronously): Ditto.
(WebCore::FrameLoader::loadedResourceFromMemoryCache): Added an out
parameter to pass back a request potentially modified by
requestFromDelegate, which is also passed to sendRemainingDelegateMessages.
* loader/FrameLoader.h:
* loader/ResourceLoadNotifier.cpp:
(WebCore::ResourceLoadNotifier::dispatchDidFailLoading): Added a
function to dispatch didFailLoading and to call the correct InspectorInstrumentation.
(WebCore::ResourceLoadNotifier::sendRemainingDelegateMessages): If the
request is NULL, call dispatchDidFailLoading and return. This matches
the delegate callback sequence of a non memory cache load that is
cancelled by willSendRequest.
* loader/ResourceLoadNotifier.h:
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::shouldContinueAfterNotifyingLoadedFromMemoryCache):
Return false if the memory cache load is cancelled by the client.
(WebCore::CachedResourceLoader::requestResource): Return early if
shouldContinueAfterNotifyingLoadedFromMemoryCache is false.

LayoutTests:

* fast/loader/resources/cached-image.html: Added.
* fast/loader/willsendrequest-returns-null-for-memory-cache-load-expected.txt: Added.
* fast/loader/willsendrequest-returns-null-for-memory-cache-load.html: Added.
* platform/wk2/TestExpectations: Expect the test to fail in WKTR due to <http://webkit.org/b/114074>.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@147829 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/loader/resources/cached-image.html [new file with mode: 0644]
LayoutTests/fast/loader/resources/compass.jpg [new file with mode: 0644]
LayoutTests/fast/loader/willsendrequest-returns-null-for-memory-cache-load-expected.txt [new file with mode: 0644]
LayoutTests/fast/loader/willsendrequest-returns-null-for-memory-cache-load.html [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h
Source/WebCore/loader/ResourceLoadNotifier.cpp
Source/WebCore/loader/ResourceLoadNotifier.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h