2 * Copyright (C) 2004, 2006 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE 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 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.
26 #ifndef ResourceHandleInternal_h
27 #define ResourceHandleInternal_h
29 #include "NetworkingContext.h"
30 #include "ResourceHandle.h"
31 #include "ResourceHandleClient.h"
32 #include "ResourceRequest.h"
33 #include "AuthenticationChallenge.h"
37 #include "ResourceHandleCFURLConnectionDelegate.h"
38 #include <CFNetwork/CFURLConnectionPriv.h>
41 #if USE(CURL) && PLATFORM(WIN)
47 #include <curl/curl.h>
48 #include "FormDataStreamCurl.h"
49 #include "MultipartHandle.h"
53 #include "GUniquePtrSoup.h"
54 #include <libsoup/soup.h>
55 #include <wtf/glib/GMainLoopSource.h>
56 #include <wtf/glib/GRefPtr.h>
60 OBJC_CLASS NSURLAuthenticationChallenge;
61 OBJC_CLASS NSURLConnection;
64 #if PLATFORM(COCOA) || USE(CFNETWORK)
65 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
68 // The allocations and releases in ResourceHandleInternal are
69 // Cocoa-exception-free (either simple Foundation classes or
70 // WebCoreResourceLoaderImp which avoids doing work in dealloc).
74 class ResourceHandleInternal {
75 WTF_MAKE_NONCOPYABLE(ResourceHandleInternal); WTF_MAKE_FAST_ALLOCATED;
77 ResourceHandleInternal(ResourceHandle* loader, NetworkingContext* context, const ResourceRequest& request, ResourceHandleClient* client, bool defersLoading, bool shouldContentSniff)
80 , m_firstRequest(request)
81 , m_lastHTTPMethod(request.httpMethod())
83 , m_defersLoading(defersLoading)
84 , m_shouldContentSniff(shouldContentSniff)
85 , m_usesAsyncCallbacks(client && client->usesAsyncCallbacks())
87 , m_currentRequest(request)
90 , m_formDataStream(loader)
97 , m_previousPosition(0)
98 , m_useAuthenticationManager(true)
101 , m_startWhenScheduled(false)
102 , m_currentMacChallenge(nil)
104 , m_scheduledFailureType(ResourceHandle::NoFailure)
105 , m_failureTimer(*loader, &ResourceHandle::failureTimerFired)
107 const URL& url = m_firstRequest.url();
110 m_firstRequest.removeCredentials();
113 ~ResourceHandleInternal();
115 ResourceHandleClient* client() { return m_client; }
117 RefPtr<NetworkingContext> m_context;
118 ResourceHandleClient* m_client;
119 ResourceRequest m_firstRequest;
120 String m_lastHTTPMethod;
122 // Suggested credentials for the current redirection step.
126 Credential m_initialCredential;
130 bool m_defersLoading;
131 bool m_shouldContentSniff;
132 bool m_usesAsyncCallbacks;
134 RetainPtr<CFURLConnectionRef> m_connection;
135 ResourceRequest m_currentRequest;
136 RefPtr<ResourceHandleCFURLConnectionDelegate> m_connectionDelegate;
138 #if PLATFORM(COCOA) && !USE(CFNETWORK)
139 RetainPtr<NSURLConnection> m_connection;
140 RetainPtr<id> m_delegate;
143 bool m_startWhenScheduled;
145 #if PLATFORM(COCOA) || USE(CFNETWORK)
146 RetainPtr<CFURLStorageSessionRef> m_storageSession;
149 CURL* m_handle { nullptr };
150 char* m_url { nullptr };
151 struct curl_slist* m_customHeaders { nullptr };
152 ResourceResponse m_response;
153 bool m_cancelled { false };
154 unsigned short m_authFailureCount { 0 };
156 FormDataStream m_formDataStream;
157 unsigned m_sslErrors { 0 };
158 Vector<char> m_postBytes;
160 std::unique_ptr<MultipartHandle> m_multipartHandle;
161 bool m_addedCacheValidationHeaders { false };
164 GRefPtr<SoupMessage> m_soupMessage;
165 ResourceResponse m_response;
167 GRefPtr<SoupRequest> m_soupRequest;
168 GRefPtr<GInputStream> m_inputStream;
169 GRefPtr<SoupMultipartInputStream> m_multipartInputStream;
170 GRefPtr<GCancellable> m_cancellable;
171 GRefPtr<GAsyncResult> m_deferredResult;
172 GMainLoopSource m_timeoutSource;
173 GUniquePtr<SoupBuffer> m_soupBuffer;
174 unsigned long m_bodySize;
175 unsigned long m_bodyDataSent;
176 SoupSession* soupSession();
178 size_t m_previousPosition;
179 bool m_useAuthenticationManager;
183 Credential credential;
184 AuthenticationChallenge challenge;
185 } m_credentialDataToSaveInPersistentStore;
189 // We need to keep a reference to the original challenge to be able to cancel it.
190 // It is almost identical to m_currentWebChallenge.nsURLAuthenticationChallenge(), but has a different sender.
191 NSURLAuthenticationChallenge *m_currentMacChallenge;
194 AuthenticationChallenge m_currentWebChallenge;
195 ResourceHandle::FailureType m_scheduledFailureType;
196 Timer m_failureTimer;
199 } // namespace WebCore
201 #endif // ResourceHandleInternal_h