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