1/*
2 * Copyright (C) 2012 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. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef NetworkStorageSession_h
27#define NetworkStorageSession_h
28
29#include <wtf/RetainPtr.h>
30#include <wtf/text/WTFString.h>
31
32#if PLATFORM(COCOA) || USE(CFNETWORK)
33typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
34typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
35#endif
36
37namespace WebCore {
38
39class NetworkingContext;
40class SoupNetworkSession;
41
42class NetworkStorageSession {
43    WTF_MAKE_NONCOPYABLE(NetworkStorageSession); WTF_MAKE_FAST_ALLOCATED;
44public:
45    static NetworkStorageSession& defaultStorageSession();
46    static std::unique_ptr<NetworkStorageSession> createPrivateBrowsingSession(const String& identifierBase = String());
47
48    static void switchToNewTestingSession();
49
50#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(SOUP)
51    bool isPrivateBrowsingSession() const { return m_isPrivate; }
52#endif
53
54#if PLATFORM(COCOA) || USE(CFNETWORK)
55    NetworkStorageSession(RetainPtr<CFURLStorageSessionRef>);
56    // May be null, in which case a Foundation default should be used.
57    CFURLStorageSessionRef platformSession() { return m_platformSession.get(); }
58    RetainPtr<CFHTTPCookieStorageRef> cookieStorage() const;
59#elif USE(SOUP)
60    NetworkStorageSession(std::unique_ptr<SoupNetworkSession>);
61    ~NetworkStorageSession();
62    SoupNetworkSession& soupNetworkSession() const;
63    void setSoupNetworkSession(std::unique_ptr<SoupNetworkSession>);
64#else
65    NetworkStorageSession(NetworkingContext*);
66    ~NetworkStorageSession();
67    NetworkingContext* context() const;
68#endif
69
70private:
71#if PLATFORM(COCOA) || USE(CFNETWORK)
72    NetworkStorageSession();
73    RetainPtr<CFURLStorageSessionRef> m_platformSession;
74#elif USE(SOUP)
75    std::unique_ptr<SoupNetworkSession> m_session;
76#else
77    RefPtr<NetworkingContext> m_context;
78#endif
79
80#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(SOUP)
81    bool m_isPrivate;
82#endif
83};
84
85#if PLATFORM(WIN) && USE(CFNETWORK)
86// Needed for WebKit1 API only.
87void overrideCookieStorage(CFHTTPCookieStorageRef);
88CFHTTPCookieStorageRef overridenCookieStorage();
89#endif
90
91}
92
93#endif // NetworkStorageSession_h
94