Commit a5e83332 authored by beidson's avatar beidson

LayoutTests:

        Reviewed by Tim

        <rdar://problem/5008925>
        Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate

        * http/tests/misc/willCacheResponse-delegate-callback-expected.txt: Added.
        * http/tests/misc/willCacheResponse-delegate-callback.html: Added.

WebCore:

        Reviewed by Tim

        <rdar://problem/5008925>
        Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate

        * WebCore.xcodeproj/project.pbxproj: Added ResourceLoaderMac.mm

        * loader/FrameLoaderClient.h: Add the willCacheResponse SPI for WebKit to implement

        * loader/ResourceLoader.h:
        * loader/mac/ResourceLoaderMac.mm: Added.
        (WebCore::ResourceLoader::willCacheResponse): Return the new cachedResponse from the client

        * platform/graphics/svg/SVGImageEmptyClients.h:
        (WebCore::SVGEmptyFrameLoaderClient::willCacheResponse): Stub

        * platform/network/ResourceHandleClient.h:
        (WebCore::ResourceHandleClient::willCacheResponse):  Return the new cachedResponse from the client

        * platform/network/mac/ResourceHandleMac.mm:
        (-[WebCoreResourceHandleAsDelegate connection:willCacheResponse:]): Call to get the new 
          cachedURLResponse before calling for the cache policy

WebKit:

        Reviewed by Tim

        <rdar://problem/5008925>
        Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate

        * WebCoreSupport/WebFrameLoaderClient.h:
        * WebCoreSupport/WebFrameLoaderClient.mm:
        (WebFrameLoaderClient::willCacheResponse): Call 
          [WebResourceLoadDelegate webView:resource:willCacheResponse:fromDataSource:];

        * WebView/WebView.mm:
        (-[WebView _cacheResourceLoadDelegateImplementations]): Pull out the willCacheResponse impl

        * WebView/WebViewPrivate.h: Add WebResourceLoadDelegatePrivate category for this new SPI

WebKitTools:

        Reviewed by Tim

        <rdar://problem/5008925>
        Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate

        * DumpRenderTree/ResourceLoadDelegate.m:
        (-[ResourceLoadDelegate webView:resource:willCacheResponse:fromDataSource:]): 
          Add the willCacheResponse delegate call



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@20937 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 52c80798
2007-04-18 Brady Eidson <beidson@apple.com>
Reviewed by Tim
<rdar://problem/5008925>
Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate
* http/tests/misc/willCacheResponse-delegate-callback-expected.txt: Added.
* http/tests/misc/willCacheResponse-delegate-callback.html: Added.
2007-04-18 Kevin McCullough <kmccullough@apple.com>
Reviewed by AP.
<unknown> - willCacheResponse: called
This tests for the willCacheResponse resource delegate callback as added for radar 5008925.
The test is only meaningful if you are running it under DumpRenderTree
<html>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.dumpResourceLoadCallbacks();
layoutTestController.waitUntilDone();
}
function loaded() {
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
<body onLoad="loaded();">
This tests for the willCacheResponse resource delegate callback as added for radar 5008925.<br>
The test is only meaningful if you are running it under DumpRenderTree<br>
</body>
</html>
\ No newline at end of file
2007-04-17 Brady Eidson <beidson@apple.com>
Reviewed by Tim
<rdar://problem/5008925>
Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate
* WebCore.xcodeproj/project.pbxproj: Added ResourceLoaderMac.mm
* loader/FrameLoaderClient.h: Add the willCacheResponse SPI for WebKit to implement
* loader/ResourceLoader.h:
* loader/mac/ResourceLoaderMac.mm: Added.
(WebCore::ResourceLoader::willCacheResponse): Return the new cachedResponse from the client
* platform/graphics/svg/SVGImageEmptyClients.h:
(WebCore::SVGEmptyFrameLoaderClient::willCacheResponse): Stub
* platform/network/ResourceHandleClient.h:
(WebCore::ResourceHandleClient::willCacheResponse): Return the new cachedResponse from the client
* platform/network/mac/ResourceHandleMac.mm:
(-[WebCoreResourceHandleAsDelegate connection:willCacheResponse:]): Call to get the new
cachedURLResponse before calling for the cache policy
2007-04-18 Darin Adler <darin@apple.com>
Reviewed by Hyatt.
......@@ -327,6 +327,7 @@
51741D110B07259A00ED442C /* HistoryItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51741D0D0B07259A00ED442C /* HistoryItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
51741D120B07259A00ED442C /* HistoryItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51741D0E0B07259A00ED442C /* HistoryItem.cpp */; };
5186C0560A9C21470034FE94 /* IconDataCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5186C0550A9C21470034FE94 /* IconDataCache.cpp */; };
51AA3F6F0BD5AA9E00892971 /* ResourceLoaderMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51AA3F6E0BD5AA9E00892971 /* ResourceLoaderMac.mm */; };
51D3EA160A3D24D300BADA35 /* SQLDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D3EA130A3D24D300BADA35 /* SQLDatabase.cpp */; };
51D3EA170A3D24D300BADA35 /* SQLDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 51D3EA140A3D24D300BADA35 /* SQLDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
51D3EA180A3D24D300BADA35 /* SQLStatement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51D3EA150A3D24D300BADA35 /* SQLStatement.cpp */; };
......@@ -3439,6 +3440,7 @@
51741D0D0B07259A00ED442C /* HistoryItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HistoryItem.h; sourceTree = "<group>"; };
51741D0E0B07259A00ED442C /* HistoryItem.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HistoryItem.cpp; sourceTree = "<group>"; };
5186C0550A9C21470034FE94 /* IconDataCache.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IconDataCache.cpp; sourceTree = "<group>"; };
51AA3F6E0BD5AA9E00892971 /* ResourceLoaderMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResourceLoaderMac.mm; sourceTree = "<group>"; };
51D3EA130A3D24D300BADA35 /* SQLDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SQLDatabase.cpp; sourceTree = "<group>"; };
51D3EA140A3D24D300BADA35 /* SQLDatabase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SQLDatabase.h; sourceTree = "<group>"; };
51D3EA150A3D24D300BADA35 /* SQLStatement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SQLStatement.cpp; sourceTree = "<group>"; };
......@@ -7994,6 +7996,7 @@
656D371A0ADBA5DE00A4554D /* LoaderNSURLExtras.h */,
656D371B0ADBA5DE00A4554D /* LoaderNSURLExtras.m */,
656D372C0ADBA5DE00A4554D /* NetscapePlugInStreamLoaderMac.mm */,
51AA3F6E0BD5AA9E00892971 /* ResourceLoaderMac.mm */,
656D372D0ADBA5DE00A4554D /* WebPlugInStreamLoaderDelegate.h */,
);
path = mac;
......@@ -12605,6 +12608,7 @@
93F9B7A00BA6032600854064 /* JSCDATASection.cpp in Sources */,
06FC442D0BAE5A9E0090EDE1 /* JavaScriptStatistics.cpp in Sources */,
E1EC299F0BB04C6B00EA187B /* XPathNodeSet.cpp in Sources */,
51AA3F6F0BD5AA9E00892971 /* ResourceLoaderMac.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -33,6 +33,14 @@
#include <wtf/Forward.h>
#include <wtf/Platform.h>
#if PLATFORM(MAC)
#ifdef __OBJC__
@class NSCachedURLResponse;
#else
class NSCachedURLResponse;
#endif
#endif
namespace WebCore {
class AuthenticationChallenge;
......@@ -198,6 +206,10 @@ namespace WebCore {
virtual String overrideMediaType() const = 0;
virtual void windowObjectCleared() const = 0;
#if PLATFORM(MAC)
virtual NSCachedURLResponse* willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse*) const = 0;
#endif
};
} // namespace WebCore
......
......@@ -98,6 +98,9 @@ namespace WebCore {
virtual void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) { didCancelAuthenticationChallenge(challenge); }
virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) { receivedCancellation(challenge); }
virtual void willCacheResponse(ResourceHandle*, CacheStoragePolicy&);
#if PLATFORM(MAC)
virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*);
#endif
ResourceHandle* handle() const { return m_handle.get(); }
......
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "ResourceLoader.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "ResourceHandle.h"
namespace WebCore {
NSCachedURLResponse* ResourceLoader::willCacheResponse(ResourceHandle* handle, NSCachedURLResponse* response)
{
return frameLoader()->client()->willCacheResponse(documentLoader(), identifier(), response);
}
}
......@@ -268,6 +268,11 @@ public:
virtual void redirectDataToPlugin(WebCore::Widget*) {}
virtual void windowObjectCleared() const {}
#if PLATFORM(MAC)
virtual NSCachedURLResponse* willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse* response) const { return response; }
#endif PLATFORM(MAC)
};
class SVGEmptyEditorClient : public EditorClient {
......
......@@ -35,6 +35,14 @@
#include <CFNetwork/CFURLResponsePriv.h>
#endif
#if PLATFORM(MAC)
#ifdef __OBJC__
@class NSCachedURLResponse;
#else
class NSCachedURLResponse;
#endif
#endif
namespace WebCore {
class AuthenticationChallenge;
class Credential;
......@@ -72,6 +80,7 @@ namespace WebCore {
virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge&) { }
#if PLATFORM(MAC)
virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse* response) { return response; }
virtual void willStopBufferingData(ResourceHandle*, const char*, int) { }
#endif
};
......
......@@ -388,18 +388,23 @@ void ResourceHandle::receivedCancellation(const AuthenticationChallenge& challen
if (!m_handle)
return nil;
++inNSURLConnectionCallback;
CacheStoragePolicy policy = static_cast<CacheStoragePolicy>([cachedResponse storagePolicy]);
NSCachedURLResponse * newResponse = m_handle->client()->willCacheResponse(m_handle, cachedResponse);
if (newResponse != cachedResponse)
return newResponse;
CacheStoragePolicy policy = static_cast<CacheStoragePolicy>([newResponse storagePolicy]);
m_handle->client()->willCacheResponse(m_handle, policy);
if (static_cast<NSURLCacheStoragePolicy>(policy) != [cachedResponse storagePolicy])
cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response]
data:[cachedResponse data]
userInfo:[cachedResponse userInfo]
if (static_cast<NSURLCacheStoragePolicy>(policy) != [newResponse storagePolicy])
newResponse = [[[NSCachedURLResponse alloc] initWithResponse:[newResponse response]
data:[newResponse data]
userInfo:[newResponse userInfo]
storagePolicy:static_cast<NSURLCacheStoragePolicy>(policy)] autorelease];
--inNSURLConnectionCallback;
return cachedResponse;
return newResponse;
}
- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
......
2007-04-17 Brady Eidson <beidson@apple.com>
Reviewed by Tim
<rdar://problem/5008925>
Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate
* WebCoreSupport/WebFrameLoaderClient.h:
* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::willCacheResponse): Call
[WebResourceLoadDelegate webView:resource:willCacheResponse:fromDataSource:];
* WebView/WebView.mm:
(-[WebView _cacheResourceLoadDelegateImplementations]): Pull out the willCacheResponse impl
* WebView/WebViewPrivate.h: Add WebResourceLoadDelegatePrivate category for this new SPI
2007-04-18 John Sullivan <sullivan@apple.com>
Reviewed by Adam
......
......@@ -89,6 +89,8 @@ private:
virtual void dispatchDidFinishLoading(WebCore::DocumentLoader*, unsigned long identifier);
virtual void dispatchDidFailLoading(WebCore::DocumentLoader*, unsigned long identifier, const WebCore::ResourceError&);
virtual NSCachedURLResponse* willCacheResponse(WebCore::DocumentLoader*, unsigned long identifier, NSCachedURLResponse*) const;
virtual void dispatchDidHandleOnloadEvents();
virtual void dispatchDidReceiveServerRedirectForProvisionalLoad();
virtual void dispatchDidCancelClientRedirect();
......
......@@ -332,6 +332,17 @@ void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, un
implementations.didReceiveResponseFunc(resourceLoadDelegate, @selector(webView:resource:didReceiveResponse:fromDataSource:), webView, [webView _objectForIdentifier:identifier], response.nsURLResponse(), dataSource(loader));
}
NSCachedURLResponse* WebFrameLoaderClient::willCacheResponse(DocumentLoader* loader, unsigned long identifier, NSCachedURLResponse* response) const
{
WebView *webView = getWebView(m_webFrame.get());
id resourceLoadDelegate = WebViewGetResourceLoadDelegate(webView);
WebResourceDelegateImplementationCache implementations = WebViewGetResourceLoadDelegateImplementations(webView);
if (implementations.delegateImplementsWillCacheResponse)
return implementations.willCacheResponseFunc(resourceLoadDelegate, @selector(webView:resource:willCacheResponse:fromDataSource:), webView, [webView _objectForIdentifier:identifier], response, dataSource(loader));
return response;
}
void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader* loader, unsigned long identifier, int lengthReceived)
{
WebView *webView = getWebView(m_webFrame.get());
......
......@@ -906,6 +906,7 @@ static bool debugWidget = true;
cache->delegateImplementsWillSendRequest = [delegate respondsToSelector:@selector(webView:resource:willSendRequest:redirectResponse:fromDataSource:)];
cache->delegateImplementsIdentifierForRequest = [delegate respondsToSelector:@selector(webView:identifierForInitialRequest:fromDataSource:)];
cache->delegateImplementsDidLoadResourceFromMemoryCache = [delegate respondsToSelector:@selector(webView:didLoadResourceFromMemoryCache:response:length:fromDataSource:)];
cache->delegateImplementsWillCacheResponse = [delegate respondsToSelector:@selector(webView:resource:willCacheResponse:fromDataSource:)];
#if defined(OBJC_API_VERSION) && OBJC_API_VERSION > 0
#define GET_OBJC_METHOD_IMP(class,selector) class_getMethodImplementation(class, selector)
......@@ -929,7 +930,8 @@ static bool debugWidget = true;
cache->identifierForRequestFunc = (WebIdentifierForRequestFunc)GET_OBJC_METHOD_IMP(delegateClass, @selector(webView:identifierForInitialRequest:fromDataSource:));
if (cache->delegateImplementsDidLoadResourceFromMemoryCache)
cache->didLoadResourceFromMemoryCacheFunc = (WebDidLoadResourceFromMemoryCacheFunc)GET_OBJC_METHOD_IMP(delegateClass, @selector(webView:didLoadResourceFromMemoryCache:response:length:fromDataSource:));
if (cache->delegateImplementsWillCacheResponse)
cache->willCacheResponseFunc = (WebWillCacheResponseFunc)GET_OBJC_METHOD_IMP(delegateClass, @selector(webView:resource:willCacheResponse:fromDataSource:));
#undef GET_OBJC_METHOD_IMP
}
......
......@@ -49,6 +49,7 @@ typedef void (*WebDidReceiveResponseFunc)(id, SEL, WebView *, id, NSURLResponse
typedef void (*WebDidReceiveContentLengthFunc)(id, SEL, WebView *, id, WebNSInteger, WebDataSource *);
typedef void (*WebDidFinishLoadingFromDataSourceFunc)(id, SEL, WebView *, id, WebDataSource *);
typedef void (*WebDidLoadResourceFromMemoryCacheFunc)(id, SEL, WebView *, NSURLRequest *, NSURLResponse *, WebNSInteger, WebDataSource *);
typedef NSCachedURLResponse *(*WebWillCacheResponseFunc)(id, SEL, WebView *, id, NSCachedURLResponse *, WebDataSource *);
typedef struct _WebResourceDelegateImplementationCache {
uint delegateImplementsDidCancelAuthenticationChallenge:1;
......@@ -59,6 +60,7 @@ typedef struct _WebResourceDelegateImplementationCache {
uint delegateImplementsWillSendRequest:1;
uint delegateImplementsIdentifierForRequest:1;
uint delegateImplementsDidLoadResourceFromMemoryCache:1;
uint delegateImplementsWillCacheResponse:1;
WebDidCancelAuthenticationChallengeFunc didCancelAuthenticationChallengeFunc;
WebDidReceiveAuthenticationChallengeFunc didReceiveAuthenticationChallengeFunc;
......@@ -68,6 +70,7 @@ typedef struct _WebResourceDelegateImplementationCache {
WebDidReceiveContentLengthFunc didReceiveContentLengthFunc;
WebDidFinishLoadingFromDataSourceFunc didFinishLoadingFromDataSourceFunc;
WebDidLoadResourceFromMemoryCacheFunc didLoadResourceFromMemoryCacheFunc;
WebWillCacheResponseFunc willCacheResponseFunc;
} WebResourceDelegateImplementationCache;
extern NSString *_WebCanGoBackKey;
......@@ -397,8 +400,13 @@ Could be worth adding to the API.
// of its subresources.
- (void)webView:(WebView *)sender didFinishDocumentLoadForFrame:(WebFrame *)frame;
// Addresses 4192534. Private API for now.
// Addresses 4192534. SPI for now.
- (void)webView:(WebView *)sender didHandleOnloadEventsForFrame:(WebFrame *)frame;
@end
@interface NSObject (WebResourceLoadDelegatePrivate)
// Addresses <rdar://problem/5008925> - SPI for now
- (NSCachedURLResponse *)webView:(WebView *)sender resource:(id)identifier willCacheResponse:(NSCachedURLResponse *)respose fromDataSource:(WebDataSource *)dataSource;
@end
#undef WebNSInteger
2007-04-18 Brady Eidson <beidson@apple.com>
Reviewed by Tim
<rdar://problem/5008925>
Expose the NSURLConnection delegate willCacheResponse API to WebResourceLoadDelegate
* DumpRenderTree/ResourceLoadDelegate.m:
(-[ResourceLoadDelegate webView:resource:willCacheResponse:fromDataSource:]):
Add the willCacheResponse delegate call
2007-04-18 Adam Roben <aroben@apple.com>
Reviewed by David Kilzer.
......
......@@ -163,4 +163,13 @@ - (void)webView: (WebView *)wv plugInFailedWithError:(NSError *)error dataSource
{
}
-(NSCachedURLResponse *) webView: (WebView *)wv resource:(id)identifier willCacheResponse:(NSCachedURLResponse *)response fromDataSource:(WebDataSource *)dataSource
{
if (shouldDumpResourceLoadCallbacks && !done) {
NSString *string = [NSString stringWithFormat:@"%@ - willCacheResponse: called", identifier];
printf ("%s\n", [string UTF8String]);
}
return response;
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment