1 | /* |
2 | * Copyright (C) 2011, 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. 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 | #pragma once |
27 | |
28 | #include "APIObject.h" |
29 | #include "GenericCallback.h" |
30 | #include "MessageReceiver.h" |
31 | #include "WebContextSupplement.h" |
32 | #include "WebCookieManagerProxyClient.h" |
33 | #include <pal/SessionID.h> |
34 | #include <wtf/Forward.h> |
35 | #include <wtf/HashMap.h> |
36 | #include <wtf/RefPtr.h> |
37 | |
38 | #if USE(SOUP) |
39 | #include "SoupCookiePersistentStorageType.h" |
40 | #endif |
41 | |
42 | namespace API { |
43 | class Array; |
44 | } |
45 | |
46 | namespace WebCore { |
47 | struct Cookie; |
48 | } |
49 | |
50 | namespace WebKit { |
51 | |
52 | class WebProcessPool; |
53 | class WebProcessProxy; |
54 | |
55 | typedef GenericCallback<API::Array*> ArrayCallback; |
56 | typedef GenericCallback<HTTPCookieAcceptPolicy> HTTPCookieAcceptPolicyCallback; |
57 | typedef GenericCallback<const Vector<WebCore::Cookie>&> GetCookiesCallback; |
58 | |
59 | class WebCookieManagerProxy : public API::ObjectImpl<API::Object::Type::CookieManager>, public WebContextSupplement, private IPC::MessageReceiver { |
60 | public: |
61 | static const char* supplementName(); |
62 | |
63 | static Ref<WebCookieManagerProxy> create(WebProcessPool*); |
64 | virtual ~WebCookieManagerProxy(); |
65 | |
66 | void initializeClient(const WKCookieManagerClientBase*); |
67 | |
68 | void getHostnamesWithCookies(PAL::SessionID, Function<void (API::Array*, CallbackBase::Error)>&&); |
69 | void deleteCookie(PAL::SessionID, const WebCore::Cookie&, Function<void (CallbackBase::Error)>&&); |
70 | void deleteCookiesForHostnames(PAL::SessionID, const Vector<String>&); |
71 | void deleteAllCookies(PAL::SessionID); |
72 | void deleteAllCookiesModifiedSince(PAL::SessionID, WallTime, Function<void (CallbackBase::Error)>&&); |
73 | |
74 | void setCookies(PAL::SessionID, const Vector<WebCore::Cookie>&, Function<void(CallbackBase::Error)>&&); |
75 | void setCookies(PAL::SessionID, const Vector<WebCore::Cookie>&, const URL&, const URL& mainDocumentURL, Function<void(CallbackBase::Error)>&&); |
76 | |
77 | void getAllCookies(PAL::SessionID, Function<void (const Vector<WebCore::Cookie>&, CallbackBase::Error)>&& completionHandler); |
78 | void getCookies(PAL::SessionID, const URL&, Function<void(const Vector<WebCore::Cookie>&, CallbackBase::Error)>&& completionHandler); |
79 | |
80 | void setHTTPCookieAcceptPolicy(PAL::SessionID, HTTPCookieAcceptPolicy, Function<void (CallbackBase::Error)>&&); |
81 | void getHTTPCookieAcceptPolicy(PAL::SessionID, Function<void (HTTPCookieAcceptPolicy, CallbackBase::Error)>&&); |
82 | |
83 | void setStorageAccessAPIEnabled(bool); |
84 | |
85 | void startObservingCookieChanges(PAL::SessionID); |
86 | void stopObservingCookieChanges(PAL::SessionID); |
87 | |
88 | void setCookieObserverCallback(PAL::SessionID, WTF::Function<void ()>&&); |
89 | |
90 | class Observer { |
91 | public: |
92 | virtual ~Observer() { } |
93 | virtual void cookiesDidChange() = 0; |
94 | virtual void managerDestroyed() = 0; |
95 | }; |
96 | |
97 | void registerObserver(PAL::SessionID, Observer&); |
98 | void unregisterObserver(PAL::SessionID, Observer&); |
99 | |
100 | #if USE(SOUP) |
101 | void setCookiePersistentStorage(PAL::SessionID, const String& storagePath, SoupCookiePersistentStorageType); |
102 | void getCookiePersistentStorage(PAL::SessionID, String& storagePath, SoupCookiePersistentStorageType&) const; |
103 | #endif |
104 | |
105 | using API::Object::ref; |
106 | using API::Object::deref; |
107 | |
108 | private: |
109 | WebCookieManagerProxy(WebProcessPool*); |
110 | |
111 | void didGetHostnamesWithCookies(const Vector<String>&, WebKit::CallbackID); |
112 | void didGetHTTPCookieAcceptPolicy(uint32_t policy, WebKit::CallbackID); |
113 | |
114 | void didSetHTTPCookieAcceptPolicy(WebKit::CallbackID); |
115 | void didSetCookies(WebKit::CallbackID); |
116 | void didGetCookies(const Vector<WebCore::Cookie>&, WebKit::CallbackID); |
117 | void didDeleteCookies(WebKit::CallbackID); |
118 | |
119 | void cookiesDidChange(PAL::SessionID); |
120 | |
121 | // WebContextSupplement |
122 | void processPoolDestroyed() override; |
123 | void processDidClose(WebProcessProxy*) override; |
124 | void processDidClose(NetworkProcessProxy*) override; |
125 | void refWebContextSupplement() override; |
126 | void derefWebContextSupplement() override; |
127 | |
128 | // IPC::MessageReceiver |
129 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
130 | |
131 | #if PLATFORM(COCOA) |
132 | void persistHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy); |
133 | #endif |
134 | |
135 | CallbackMap m_callbacks; |
136 | |
137 | HashMap<PAL::SessionID, WTF::Function<void ()>> m_legacyCookieObservers; |
138 | HashMap<PAL::SessionID, HashSet<Observer*>> m_cookieObservers; |
139 | |
140 | WebCookieManagerProxyClient m_client; |
141 | |
142 | #if USE(SOUP) |
143 | using CookiePersistentStorageMap = HashMap<PAL::SessionID, std::pair<String, SoupCookiePersistentStorageType>>; |
144 | CookiePersistentStorageMap m_cookiePersistentStorageMap; |
145 | #endif |
146 | }; |
147 | |
148 | } // namespace WebKit |
149 | |