[GStreamer][Soup] Let GStreamer provide the buffer data is downloaded to, to avoid...
[WebKit-https.git] / Source / WebCore / platform / network / ResourceHandleClient.h
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef ResourceHandleClient_h
27 #define ResourceHandleClient_h
28
29 #include <wtf/CurrentTime.h>
30 #include <wtf/RefCounted.h>
31 #include <wtf/RefPtr.h>
32
33 #if USE(CFNETWORK)
34 #include <CFNetwork/CFURLCachePriv.h>
35 #include <CFNetwork/CFURLResponsePriv.h>
36 #endif
37
38 #if USE(SOUP)
39 #include <glib.h>
40 #endif
41
42 #if PLATFORM(WIN) && USE(CFNETWORK)
43 #include <ConditionalMacros.h>
44 #endif
45
46 #if PLATFORM(MAC)
47 OBJC_CLASS NSCachedURLResponse;
48 #endif
49
50 namespace WebCore {
51     class AsyncFileStream;
52     class AuthenticationChallenge;
53     class Credential;
54     class FileStreamClient;
55     class KURL;
56     class ProtectionSpace;
57     class ResourceHandle;
58     class ResourceError;
59     class ResourceRequest;
60     class ResourceResponse;
61
62     enum CacheStoragePolicy {
63         StorageAllowed,
64         StorageAllowedInMemoryOnly,
65         StorageNotAllowed
66     };
67     
68     class ResourceHandleClient {
69     public:
70 #if USE(SOUP)
71         ResourceHandleClient(): m_buffer(0) { }
72
73         virtual ~ResourceHandleClient()
74         {
75             if (m_buffer) {
76                 g_free(m_buffer);
77                 m_buffer = 0;
78             }
79         }
80 #else
81         virtual ~ResourceHandleClient() { }
82 #endif
83
84         // request may be modified
85         virtual void willSendRequest(ResourceHandle*, ResourceRequest&, const ResourceResponse& /*redirectResponse*/) { }
86         virtual void didSendData(ResourceHandle*, unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { }
87
88         virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&) { }
89         virtual void didReceiveData(ResourceHandle*, const char*, int, int /*encodedDataLength*/) { }
90         virtual void didReceiveCachedMetadata(ResourceHandle*, const char*, int) { }
91         virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/) { }
92         virtual void didFail(ResourceHandle*, const ResourceError&) { }
93         virtual void wasBlocked(ResourceHandle*) { }
94         virtual void cannotShowURL(ResourceHandle*) { }
95
96 #if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
97         virtual bool supportsDataArray() { return false; }
98         virtual void didReceiveDataArray(ResourceHandle*, CFArrayRef) { }
99 #endif
100
101 #if USE(SOUP)
102         virtual char* getBuffer(int requestedLength, int* actualLength)
103         {
104             *actualLength = requestedLength;
105
106             if (!m_buffer)
107                 m_buffer = static_cast<char*>(g_malloc(requestedLength));
108
109             return m_buffer;
110         }
111 #endif
112
113         virtual bool shouldUseCredentialStorage(ResourceHandle*) { return false; }
114         virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { }
115         virtual void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { }
116 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
117         virtual bool canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace&) { return false; }
118 #endif
119         virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge&) { }
120
121 #if PLATFORM(MAC)
122 #if USE(CFNETWORK)
123         virtual CFCachedURLResponseRef willCacheResponse(ResourceHandle*, CFCachedURLResponseRef response) { return response; }
124 #else
125         virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse* response) { return response; }
126 #endif
127         virtual void willStopBufferingData(ResourceHandle*, const char*, int) { }
128 #endif // PLATFORM(MAC)
129 #if PLATFORM(WIN) && USE(CFNETWORK)
130         virtual bool shouldCacheResponse(ResourceHandle*, CFCachedURLResponseRef) { return true; }
131 #endif
132 #if PLATFORM(CHROMIUM)
133         virtual void didDownloadData(ResourceHandle*, int /*dataLength*/) { }
134 #endif
135 #if ENABLE(BLOB)
136         virtual AsyncFileStream* createAsyncFileStream(FileStreamClient*) { return 0; }
137 #endif
138
139 #if USE(SOUP)
140 private:
141         char* m_buffer;
142 #endif
143     };
144
145 }
146
147 #endif