5b1683047d03af6b0203eee8ca74ac109af02101
[WebKit-https.git] / Source / WebCore / platform / network / cf / ResourceHandleCFURLConnectionDelegate.h
1 /*
2  * Copyright (C) 2004-2013 Apple 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 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.
24  */
25
26 #pragma once
27
28 #if USE(CFURLCONNECTION)
29
30 #include "ResourceRequest.h"
31 #include <CFNetwork/CFURLConnectionPriv.h>
32 #include <wtf/RetainPtr.h>
33 #include <wtf/ThreadSafeRefCounted.h>
34
35 namespace WebCore {
36
37 class ResourceHandle;
38
39 class ResourceHandleCFURLConnectionDelegate : public ThreadSafeRefCounted<ResourceHandleCFURLConnectionDelegate> {
40 public:
41     ResourceHandleCFURLConnectionDelegate(ResourceHandle*);
42     virtual ~ResourceHandleCFURLConnectionDelegate();
43
44     CFURLConnectionClient_V6 makeConnectionClient() const;
45     virtual void setupRequest(CFMutableURLRequestRef) = 0;
46     virtual void setupConnectionScheduling(CFURLConnectionRef) = 0;
47     virtual void releaseHandle();
48
49     virtual void continueDidReceiveResponse() = 0;
50     virtual void continueWillCacheResponse(CFCachedURLResponseRef) = 0;
51 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
52     virtual void continueCanAuthenticateAgainstProtectionSpace(bool) = 0;
53 #endif // USE(PROTECTION_SPACE_AUTH_CALLBACK)
54
55 protected:
56     RetainPtr<CFURLResponseRef> synthesizeRedirectResponseIfNecessary(CFURLRequestRef, CFURLResponseRef);
57     ResourceRequest createResourceRequest(CFURLRequestRef, CFURLResponseRef);
58
59 private:
60     static const void* retain(const void*);
61     static void release(const void*);
62     static CFURLRequestRef willSendRequestCallback(CFURLConnectionRef, CFURLRequestRef, CFURLResponseRef, const void* clientInfo);
63     static void didReceiveResponseCallback(CFURLConnectionRef, CFURLResponseRef, const void* clientInfo);
64     static void didReceiveDataCallback(CFURLConnectionRef, CFDataRef, CFIndex originalLength, const void* clientInfo);
65     static void didFinishLoadingCallback(CFURLConnectionRef, const void* clientInfo);
66     static void didFailCallback(CFURLConnectionRef, CFErrorRef, const void* clientInfo);
67     static CFCachedURLResponseRef willCacheResponseCallback(CFURLConnectionRef, CFCachedURLResponseRef, const void* clientInfo);
68     static void didReceiveChallengeCallback(CFURLConnectionRef, CFURLAuthChallengeRef, const void* clientInfo);
69     static void didSendBodyDataCallback(CFURLConnectionRef, CFIndex, CFIndex totalBytesWritten, CFIndex totalBytesExpectedToWrite, const void *clientInfo);
70     static Boolean shouldUseCredentialStorageCallback(CFURLConnectionRef, const void* clientInfo);
71 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
72     static Boolean canRespondToProtectionSpaceCallback(CFURLConnectionRef, CFURLProtectionSpaceRef, const void* clientInfo);
73 #endif // USE(PROTECTION_SPACE_AUTH_CALLBACK)
74
75     virtual CFURLRequestRef willSendRequest(CFURLRequestRef, CFURLResponseRef) = 0;
76     virtual void didReceiveResponse(CFURLConnectionRef, CFURLResponseRef) = 0;
77     virtual void didReceiveData(CFDataRef, CFIndex originalLength) = 0;
78     virtual void didFinishLoading() = 0;
79     virtual void didFail(CFErrorRef) = 0;
80     virtual CFCachedURLResponseRef willCacheResponse(CFCachedURLResponseRef) = 0;
81     virtual void didReceiveChallenge(CFURLAuthChallengeRef) = 0;
82     virtual void didSendBodyData(CFIndex totalBytesWritten, CFIndex totalBytesExpectedToWrite) = 0;
83     virtual Boolean shouldUseCredentialStorage() = 0;
84 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
85     virtual Boolean canRespondToProtectionSpace(CFURLProtectionSpaceRef) = 0;
86 #endif // USE(PROTECTION_SPACE_AUTH_CALLBACK)
87
88 protected:
89     ResourceHandle* m_handle;
90     RetainPtr<CFStringRef> m_originalScheme;
91 };
92
93 } // namespace WebCore.
94
95 #endif // USE(CFURLCONNECTION)