Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebKitLegacy / mac / WebCoreSupport / WebPlatformStrategies.mm
1 /*
2  * Copyright (C) 2010-2017 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 #import "WebPlatformStrategies.h"
27
28 #import "WebFrameNetworkingContext.h"
29 #import "WebPluginPackage.h"
30 #import "WebResourceLoadScheduler.h"
31 #import <WebCore/BlobRegistryImpl.h>
32 #import <WebCore/Color.h>
33 #import <WebCore/Frame.h>
34 #import <WebCore/NetworkStorageSession.h>
35 #import <WebCore/PasteboardItemInfo.h>
36 #import <WebCore/PlatformPasteboard.h>
37 #import <WebCore/SharedBuffer.h>
38 #import <WebCore/SubframeLoader.h>
39
40 using namespace WebCore;
41
42 void WebPlatformStrategies::initializeIfNecessary()
43 {
44     static WebPlatformStrategies* platformStrategies;
45     if (!platformStrategies) {
46         platformStrategies = new WebPlatformStrategies;
47         setPlatformStrategies(platformStrategies);
48     }
49 }
50
51 WebPlatformStrategies::WebPlatformStrategies()
52 {
53 }
54
55 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
56 {
57     return this;
58 }
59
60 LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
61 {
62     return new WebResourceLoadScheduler;
63 }
64
65 PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
66 {
67     return this;
68 }
69
70 BlobRegistry* WebPlatformStrategies::createBlobRegistry()
71 {
72     return new WebCore::BlobRegistryImpl;
73 }
74
75 std::pair<String, bool> WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
76 {
77     return session.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
78 }
79
80 void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
81 {
82     session.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
83 }
84
85 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session)
86 {
87     return session.cookiesEnabled();
88 }
89
90 std::pair<String, bool> WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
91 {
92     return session.cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
93 }
94
95 std::pair<String, bool> WebPlatformStrategies::cookieRequestHeaderFieldValue(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
96 {
97     auto& session = sessionID.isEphemeral() ? WebFrameNetworkingContext::ensurePrivateBrowsingSession() : NetworkStorageSession::defaultStorageSession();
98     return session.cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
99 }
100
101 bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
102 {
103     return session.getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
104 }
105
106 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName)
107 {
108     session.deleteCookie(url, cookieName);
109 }
110
111 void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
112 {
113     PlatformPasteboard(pasteboardName).getTypes(types);
114 }
115
116 RefPtr<SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
117 {
118     return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
119 }
120
121 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
122 {
123     PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
124 }
125
126 Vector<String> WebPlatformStrategies::allStringsForType(const String& pasteboardType, const String& pasteboardName)
127 {
128     return PlatformPasteboard(pasteboardName).allStringsForType(pasteboardType);
129 }
130
131 String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
132 {
133     return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
134 }
135
136 long WebPlatformStrategies::changeCount(const String &pasteboardName)
137 {
138     return PlatformPasteboard(pasteboardName).changeCount();
139 }
140
141 String WebPlatformStrategies::uniqueName()
142 {
143     return PlatformPasteboard::uniqueName();
144 }
145
146 Color WebPlatformStrategies::color(const String& pasteboardName)
147 {
148     return PlatformPasteboard(pasteboardName).color();    
149 }
150
151 URL WebPlatformStrategies::url(const String& pasteboardName)
152 {
153     return PlatformPasteboard(pasteboardName).url();
154 }
155
156 long WebPlatformStrategies::addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
157 {
158     return PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes);
159 }
160
161 long WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
162 {
163     return PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
164 }
165
166 long WebPlatformStrategies::setBufferForType(SharedBuffer* buffer, const String& pasteboardType, const String& pasteboardName)
167 {
168     return PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
169 }
170
171 long WebPlatformStrategies::setURL(const PasteboardURL& pasteboardURL, const String& pasteboardName)
172 {
173     return PlatformPasteboard(pasteboardName).setURL(pasteboardURL);
174 }
175
176 long WebPlatformStrategies::setColor(const Color& color, const String& pasteboardName)
177 {
178     return PlatformPasteboard(pasteboardName).setColor(color);
179 }
180
181 long WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
182 {
183     return PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);
184 }
185
186 int WebPlatformStrategies::getNumberOfFiles(const String& pasteboardName)
187 {
188     return PlatformPasteboard(pasteboardName).numberOfFiles();
189 }
190
191 Vector<String> WebPlatformStrategies::typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin)
192 {
193     return PlatformPasteboard(pasteboardName).typesSafeForDOMToReadAndWrite(origin);
194 }
195
196 long WebPlatformStrategies::writeCustomData(const WebCore::PasteboardCustomData& data, const String& pasteboardName)
197 {
198     return PlatformPasteboard(pasteboardName).write(data);
199 }
200
201 #if PLATFORM(IOS_FAMILY)
202 void WebPlatformStrategies::getTypesByFidelityForItemAtIndex(Vector<String>& types, uint64_t index, const String& pasteboardName)
203 {
204     PlatformPasteboard(pasteboardName).getTypesByFidelityForItemAtIndex(types, index);
205 }
206
207 void WebPlatformStrategies::writeToPasteboard(const PasteboardURL& url, const String& pasteboardName)
208 {
209     PlatformPasteboard(pasteboardName).write(url);
210 }
211
212 void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName)
213 {
214     PlatformPasteboard(pasteboardName).write(content);
215 }
216
217 void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardImage& image, const String& pasteboardName)
218 {
219     PlatformPasteboard(pasteboardName).write(image);
220 }
221
222 void WebPlatformStrategies::writeToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName)
223 {
224     PlatformPasteboard(pasteboardName).write(pasteboardType, text);
225 }
226
227 int WebPlatformStrategies::getPasteboardItemsCount(const String& pasteboardName)
228 {
229     return PlatformPasteboard(pasteboardName).count();
230 }
231
232 void WebPlatformStrategies::updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName)
233 {
234     PlatformPasteboard(pasteboardName).updateSupportedTypeIdentifiers(identifiers);
235 }
236
237 RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(int index, const String& type, const String& pasteboardName)
238 {
239     return PlatformPasteboard(pasteboardName).readBuffer(index, type);
240 }
241
242 URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardName, String& title)
243 {
244     return PlatformPasteboard(pasteboardName).readURL(index, title);
245 }
246
247 String WebPlatformStrategies::readStringFromPasteboard(int index, const String& type, const String& pasteboardName)
248 {
249     return PlatformPasteboard(pasteboardName).readString(index, type);
250 }
251
252 Vector<WebCore::PasteboardItemInfo> WebPlatformStrategies::allPasteboardItemInfo(const String& pasteboardName)
253 {
254     return PlatformPasteboard(pasteboardName).allPasteboardItemInfo();
255 }
256
257 WebCore::PasteboardItemInfo WebPlatformStrategies::informationForItemAtIndex(int index, const String& pasteboardName)
258 {
259     return PlatformPasteboard(pasteboardName).informationForItemAtIndex(index);
260 }
261 #endif // PLATFORM(IOS_FAMILY)