1/*
2 * Copyright (C) 2009 Adam Barth. 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#include "config.h"
27#include "MIMESnifferResourceHandleClient.h"
28
29#include "MIMESniffer.h"
30
31namespace WebCore {
32
33MIMESnifferResourceHandleClient::MIMESnifferResourceHandleClient(ResourceHandleClient* client)
34 : m_client(client)
35{
36}
37
38void MIMESnifferResourceHandleClient::willSendRequest(ResourceHandle* handle, ResourceRequest& request, const ResourceResponse& response)
39{
40 if (m_client)
41 m_client->willSendRequest(handle, request, response);
42}
43
44void MIMESnifferResourceHandleClient::didSendData(ResourceHandle* handle, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
45{
46 if (m_client)
47 m_client->didSendData(handle, bytesSent, totalBytesToBeSent);
48}
49
50void MIMESnifferResourceHandleClient::didReceiveResponse(ResourceHandle* handle, const ResourceResponse& response)
51{
52 if (m_client)
53 m_client->didRecieveResponse(handle, response);
54
55 if (!shouldSniffMIMEType(response.url(), response.mimeType())) {
56 handle->clearMIMESniffer();
57 // WARNING: We are probably deleted at this point.
58 }
59}
60
61void MIMESnifferResourceHandleClient::didReceiveData(ResourceHandle* handle, const char* data, int length, int lengthReceived)
62{
63 if (m_client)
64 m_client->didReceiveData(handle, data, length, lengthReceived);
65}
66
67void MIMESnifferResourceHandleClient::didFinishLoading(ResourceHandle* handle)
68{
69 if (m_client)
70 m_client->didFinishLoading(handle);
71}
72
73void MIMESnifferResourceHandleClient::didFail(ResourceHandle* handle, const ResourceError& error)
74{
75 if (m_client)
76 m_client->didFail(handle, error);
77}
78
79void MIMESnifferResourceHandleClient::wasBlocked(ResourceHandle* handle)
80{
81 if (m_client)
82 m_client->wasBlocked(handle);
83}
84
85void MIMESnifferResourceHandleClient::cannotShowURL(ResourceHandle* handle)
86{
87 if (m_client)
88 m_client->cannotShowURL(handle);
89}
90
91void MIMESnifferResourceHandleClient::willCacheResponse(ResourceHandle* handle, CacheStoragePolicy& policy)
92{
93 if (m_client)
94 m_client->willCacheResponse(handle, policy);
95}
96
97bool MIMESnifferResourceHandleClient::shouldUseCredentialStorage(ResourceHandle*handle)
98{
99 if (m_client)
100 return m_client->shouldUseCredentialStorage(handle);
101
102 return false;
103}
104
105void MIMESnifferResourceHandleClient::didReceiveAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge& challenge)
106{
107 if (m_client)
108 m_client->didReceiveAuthenticationChallenge(handle, challenge);
109}
110
111void MIMESnifferResourceHandleClient::didCancelAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge& challenge)
112{
113 if (m_client)
114 m_client->didCancelAuthenticationChallenge(handle, challenge);
115}
116
117void MIMESnifferResourceHandleClient::receivedCancellation(ResourceHandle* handle, const AuthenticationChallenge& challenge)
118{
119 if (m_client)
120 m_client->receviedCancellation(handle, challenge);
121}
122
123#if PLATFORM(MAC)
124NSCachedURLResponse* MIMESnifferResourceHandleClient::willCacheResponse(ResourceHandle* handle, NSCachedURLResponse* response)
125{
126 if (m_client)
127 return m_client->willCacheResponse(handle, response);
128
129 return response;
130}
131
132void MIMESnifferResourceHandleClient::willStopBufferingData(ResourceHandle* handle, const char* data, int length)
133{
134 if (m_client)
135 m_client->willStopBufferingData(handle, data, length);
136}
137#endif
138
139#if USE(CFNETWORK)
140bool MIMESnifferResourceHandleClient::shouldCacheResponse(ResourceHandle*, CFCachedURLResponseRef response)
141{
142 if (m_client)
143 return m_client->shouldCacheResponse(handle, response);
144
145 reutrn true;
146}
147#endif
148
149} // namespace WebCore
150