ResourceLoader.h 8.23 KB
Newer Older
ddkilzer's avatar
WebKit:  
ddkilzer committed
1
/*
darin's avatar
darin committed
2
 * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
ddkilzer's avatar
WebKit:  
ddkilzer committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * 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.
 */

darin's avatar
darin committed
29 30 31
#ifndef ResourceLoader_h
#define ResourceLoader_h

andersca's avatar
andersca committed
32
#include "ResourceHandleClient.h"
andersca's avatar
andersca committed
33
#include "ResourceRequest.h"
andersca's avatar
andersca committed
34
#include "ResourceResponse.h"
andersca's avatar
andersca committed
35

andersca's avatar
andersca committed
36
#include <wtf/Forward.h>
37
#include <wtf/RefCounted.h>
ddkilzer's avatar
WebKit:  
ddkilzer committed
38

darin's avatar
darin committed
39 40
namespace WebCore {

41
    class AuthenticationChallenge;
andersca's avatar
andersca committed
42
    class DocumentLoader;
darin's avatar
darin committed
43 44
    class Frame;
    class FrameLoader;
45
    class KURL;
andersca's avatar
andersca committed
46
    class ResourceHandle;
andersca's avatar
andersca committed
47
    class SharedBuffer;
andersca's avatar
andersca committed
48
    
ggaren@apple.com's avatar
ggaren@apple.com committed
49
    class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHandleClient {
darin's avatar
darin committed
50
    public:
darin's avatar
darin committed
51
        virtual ~ResourceLoader();
darin's avatar
darin committed
52

darin's avatar
darin committed
53 54
        void cancel();

55
        virtual bool init(const ResourceRequest&);
darin's avatar
darin committed
56

andersca's avatar
andersca committed
57 58 59
        FrameLoader* frameLoader() const;
        DocumentLoader* documentLoader() const { return m_documentLoader.get(); }
        
andersca's avatar
andersca committed
60 61
        virtual void cancel(const ResourceError&);
        ResourceError cancelledError();
beidson's avatar
beidson committed
62
        ResourceError blockedError();
63
        ResourceError cannotShowURLError();
beidson's avatar
beidson committed
64
        
darin's avatar
darin committed
65
        virtual void setDefersLoading(bool);
ddkilzer's avatar
WebKit:  
ddkilzer committed
66

andersca's avatar
andersca committed
67 68
        void setIdentifier(unsigned long identifier) { m_identifier = identifier; }
        unsigned long identifier() const { return m_identifier; }
ddkilzer's avatar
WebKit:  
ddkilzer committed
69

darin's avatar
darin committed
70
        virtual void releaseResources();
andersca's avatar
andersca committed
71
        const ResourceResponse& response() const;
ddkilzer's avatar
WebKit:  
ddkilzer committed
72

andersca's avatar
andersca committed
73
        virtual void addData(const char*, int, bool allAtOnce);
andersca's avatar
andersca committed
74
        virtual PassRefPtr<SharedBuffer> resourceData();
darin's avatar
darin committed
75
        void clearResourceData();
beidson's avatar
beidson committed
76
        
andersca's avatar
andersca committed
77
        virtual void willSendRequest(ResourceRequest&, const ResourceResponse& redirectResponse);
weinig@apple.com's avatar
weinig@apple.com committed
78
        virtual void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
andersca's avatar
andersca committed
79
        virtual void didReceiveResponse(const ResourceResponse&);
80
        virtual void didReceiveData(const char*, int, long long encodedDataLength, bool allAtOnce);
81
        virtual void didReceiveCachedMetadata(const char*, int) { }
andersca's avatar
andersca committed
82
        void willStopBufferingData(const char*, int);
83
        virtual void didFinishLoading(double finishTime);
andersca's avatar
andersca committed
84
        virtual void didFail(const ResourceError&);
85 86 87
#if HAVE(CFNETWORK_DATA_ARRAY_CALLBACK)
        virtual void didReceiveDataArray(CFArrayRef dataArray);
#endif
darin's avatar
darin committed
88

mitz@apple.com's avatar
mitz@apple.com committed
89
        virtual bool shouldUseCredentialStorage();
beidson@apple.com's avatar
beidson@apple.com committed
90
        virtual void didReceiveAuthenticationChallenge(const AuthenticationChallenge&);
beidson's avatar
beidson committed
91
        void didCancelAuthenticationChallenge(const AuthenticationChallenge&);
92 93 94
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
        virtual bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace&);
#endif
andersca's avatar
andersca committed
95
        virtual void receivedCancellation(const AuthenticationChallenge&);
beidson's avatar
beidson committed
96

andersca's avatar
andersca committed
97
        // ResourceHandleClient
weinig@apple.com's avatar
weinig@apple.com committed
98 99
        virtual void willSendRequest(ResourceHandle*, ResourceRequest&, const ResourceResponse& redirectResponse);
        virtual void didSendData(ResourceHandle*, unsigned long long bytesSent, unsigned long long totalBytesToBeSent);
andersca's avatar
andersca committed
100
        virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
101
        virtual void didReceiveData(ResourceHandle*, const char*, int, int encodedDataLength);
102
        virtual void didReceiveCachedMetadata(ResourceHandle*, const char* data, int length) { didReceiveCachedMetadata(data, length); }
103
        virtual void didFinishLoading(ResourceHandle*, double finishTime);
andersca's avatar
andersca committed
104
        virtual void didFail(ResourceHandle*, const ResourceError&);
beidson's avatar
beidson committed
105
        virtual void wasBlocked(ResourceHandle*);
106
        virtual void cannotShowURL(ResourceHandle*);
andersca's avatar
andersca committed
107
        virtual void willStopBufferingData(ResourceHandle*, const char* data, int length) { willStopBufferingData(data, length); } 
mitz@apple.com's avatar
mitz@apple.com committed
108
        virtual bool shouldUseCredentialStorage(ResourceHandle*) { return shouldUseCredentialStorage(); }
beidson's avatar
beidson committed
109 110
        virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) { didReceiveAuthenticationChallenge(challenge); } 
        virtual void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) { didCancelAuthenticationChallenge(challenge); } 
111 112 113
#if HAVE(CFNETWORK_DATA_ARRAY_CALLBACK)
        virtual void didReceiveDataArray(ResourceHandle*, CFArrayRef dataArray);
#endif
114 115 116
#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
        virtual bool canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace& protectionSpace) { return canAuthenticateAgainstProtectionSpace(protectionSpace); }
#endif
beidson's avatar
beidson committed
117
        virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) { receivedCancellation(challenge); }
andersca's avatar
andersca committed
118
        virtual void willCacheResponse(ResourceHandle*, CacheStoragePolicy&);
beidson's avatar
beidson committed
119
#if PLATFORM(MAC)
120 121 122
#if USE(CFNETWORK)
        virtual CFCachedURLResponseRef willCacheResponse(ResourceHandle*, CFCachedURLResponseRef);
#else
beidson's avatar
beidson committed
123 124
        virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*);
#endif
125 126 127
#endif // PLATFORM(MAC)
#if PLATFORM(WIN) && USE(CFNETWORK)
        // FIXME: Windows should use willCacheResponse - <https://bugs.webkit.org/show_bug.cgi?id=57257>.
mitz@apple.com's avatar
mitz@apple.com committed
128 129
        virtual bool shouldCacheResponse(ResourceHandle*, CFCachedURLResponseRef);
#endif
jianli@chromium.org's avatar
jianli@chromium.org committed
130 131 132
#if ENABLE(BLOB)
        virtual AsyncFileStream* createAsyncFileStream(FileStreamClient*);
#endif
andersca's avatar
andersca committed
133

134
        const KURL& url() const { return m_request.url(); } 
andersca's avatar
andersca committed
135
        ResourceHandle* handle() const { return m_handle.get(); }
andersca's avatar
andersca committed
136
        bool sendResourceLoadCallbacks() const { return m_sendResourceLoadCallbacks; }
ggaren's avatar
ggaren committed
137

138
        bool reachedTerminalState() const { return m_reachedTerminalState; }
139

andersca@apple.com's avatar
andersca@apple.com committed
140
        void setShouldBufferData(bool shouldBufferData);
andersca's avatar
andersca committed
141

darin's avatar
darin committed
142
    protected:
andersca's avatar
andersca committed
143
        ResourceLoader(Frame*, bool sendResourceLoadCallbacks, bool shouldContentSniff);
darin's avatar
darin committed
144

ap@webkit.org's avatar
ap@webkit.org committed
145
#if ENABLE(OFFLINE_WEB_APPLICATIONS)
146
        friend class ApplicationCacheHost;  // for access to request()
ap@webkit.org's avatar
ap@webkit.org committed
147
#endif
148 149 150 151 152
        friend class ResourceLoadScheduler; // for access to start()
        // start() actually sends the load to the network (unless the load is being 
        // deferred) and should only be called by ResourceLoadScheduler or setDefersLoading().
        void start();
        
andersca's avatar
andersca committed
153
        virtual void didCancel(const ResourceError&);
154
        void didFinishLoadingOnePart(double finishTime);
darin's avatar
darin committed
155

andersca's avatar
andersca committed
156
        const ResourceRequest& request() const { return m_request; }
darin's avatar
darin committed
157
        bool cancelled() const { return m_cancelled; }
darin's avatar
darin committed
158
        bool defersLoading() const { return m_defersLoading; }
darin's avatar
darin committed
159

andersca's avatar
andersca committed
160
        RefPtr<ResourceHandle> m_handle;
161 162
        RefPtr<Frame> m_frame;
        RefPtr<DocumentLoader> m_documentLoader;
163
        ResourceResponse m_response;
164
        
darin's avatar
darin committed
165
    private:
andersca's avatar
andersca committed
166
        ResourceRequest m_request;
167 168
        RefPtr<SharedBuffer> m_resourceData;
        
169
        unsigned long m_identifier;
darin's avatar
darin committed
170

darin's avatar
darin committed
171 172
        bool m_reachedTerminalState;
        bool m_cancelled;
darin's avatar
darin committed
173
        bool m_calledDidFinishLoad;
darin's avatar
darin committed
174

andersca's avatar
andersca committed
175
        bool m_sendResourceLoadCallbacks;
andersca's avatar
andersca committed
176
        bool m_shouldContentSniff;
andersca's avatar
andersca committed
177
        bool m_shouldBufferData;
darin's avatar
darin committed
178
        bool m_defersLoading;
gdennis's avatar
gdennis committed
179
        ResourceRequest m_deferredRequest;
darin's avatar
darin committed
180 181 182
    };

}
darin's avatar
darin committed
183 184

#endif