Re-landing patch for "Introducing the DatabaseStrategy and database servers".
[WebKit-https.git] / Source / WebKit / mac / WebCoreSupport / WebPlatformStrategies.mm
1 /*
2  * Copyright (C) 2010 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 "WebPluginDatabase.h"
30 #import "WebPluginPackage.h"
31 #import <WebCore/BlockExceptions.h>
32 #import <WebCore/Color.h>
33 #import <WebCore/Page.h>
34 #import <WebCore/PageGroup.h>
35 #import <WebCore/PlatformCookieJar.h>
36 #import <WebCore/PlatformPasteboard.h>
37 #import <WebKitSystemInterface.h>
38
39 using namespace WebCore;
40
41 void WebPlatformStrategies::initialize()
42 {
43     DEFINE_STATIC_LOCAL(WebPlatformStrategies, platformStrategies, ());
44     setPlatformStrategies(&platformStrategies);
45 }
46
47 WebPlatformStrategies::WebPlatformStrategies()
48 {
49 }
50
51 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
52 {
53     return this;
54 }
55
56 DatabaseStrategy* WebPlatformStrategies::createDatabaseStrategy()
57 {
58     return this;
59 }
60
61 LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
62 {
63     return this;
64 }
65
66 PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
67 {
68     return this;
69 }
70
71 PluginStrategy* WebPlatformStrategies::createPluginStrategy()
72 {
73     return this;
74 }
75
76 SharedWorkerStrategy* WebPlatformStrategies::createSharedWorkerStrategy()
77 {
78     return this;
79 }
80
81 VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy()
82 {
83     return this;
84 }
85
86 void WebPlatformStrategies::notifyCookiesChanged()
87 {
88 }
89
90 RetainPtr<CFHTTPCookieStorageRef> WebPlatformStrategies::defaultCookieStorage()
91 {
92     if (CFURLStorageSessionRef session = WebFrameNetworkingContext::defaultStorageSession())
93         return adoptCF(WKCopyHTTPCookieStorage(session));
94
95 #if USE(CFNETWORK)
96     return WKGetDefaultHTTPCookieStorage();
97 #else
98     // When using NSURLConnection, we also use its shared cookie storage.
99     return 0;
100 #endif
101 }
102
103 String WebPlatformStrategies::cookiesForDOM(NetworkingContext* context, const KURL& firstParty, const KURL& url)
104 {
105     return WebCore::cookiesForDOM(context, firstParty, url);
106 }
107
108 void WebPlatformStrategies::setCookiesFromDOM(NetworkingContext* context, const KURL& firstParty, const KURL& url, const String& cookieString)
109 {
110     WebCore::setCookiesFromDOM(context, firstParty, url, cookieString);
111 }
112
113 bool WebPlatformStrategies::cookiesEnabled(NetworkingContext* context, const KURL& firstParty, const KURL& url)
114 {
115     return WebCore::cookiesEnabled(context, firstParty, url);
116 }
117
118 String WebPlatformStrategies::cookieRequestHeaderFieldValue(NetworkingContext* context, const KURL& firstParty, const KURL& url)
119 {
120     return WebCore::cookieRequestHeaderFieldValue(context, firstParty, url);
121 }
122
123 bool WebPlatformStrategies::getRawCookies(NetworkingContext* context, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
124 {
125     return WebCore::getRawCookies(context, firstParty, url, rawCookies);
126 }
127
128 void WebPlatformStrategies::deleteCookie(NetworkingContext* context, const KURL& url, const String& cookieName)
129 {
130     WebCore::deleteCookie(context, url, cookieName);
131 }
132
133 void WebPlatformStrategies::getHostnamesWithCookies(NetworkingContext* context, HashSet<String>& hostnames)
134 {
135     WebCore::getHostnamesWithCookies(context, hostnames);
136 }
137
138 void WebPlatformStrategies::deleteCookiesForHostname(NetworkingContext* context, const String& hostname)
139 {
140     WebCore::deleteCookiesForHostname(context, hostname);
141 }
142
143 void WebPlatformStrategies::deleteAllCookies(NetworkingContext* context)
144 {
145     WebCore::deleteAllCookies(context);
146 }
147
148 void WebPlatformStrategies::refreshPlugins()
149 {
150     [[WebPluginDatabase sharedDatabase] refresh];
151 }
152
153 void WebPlatformStrategies::getPluginInfo(const Page*, Vector<PluginInfo>& plugins)
154 {
155     BEGIN_BLOCK_OBJC_EXCEPTIONS;
156
157     NSArray* pluginsArray = [[WebPluginDatabase sharedDatabase] plugins];
158     for (unsigned int i = 0; i < [pluginsArray count]; ++i) {
159         WebPluginPackage *plugin = [pluginsArray objectAtIndex:i];
160
161         plugins.append([plugin pluginInfo]);
162     }
163     
164     END_BLOCK_OBJC_EXCEPTIONS;
165 }
166
167 bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
168 {
169     return page->group().isLinkVisited(hash);
170 }
171
172 void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash hash)
173 {
174     return page->group().addVisitedLinkHash(hash);
175 }
176
177 void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
178 {
179     PlatformPasteboard(pasteboardName).getTypes(types);
180 }
181
182 PassRefPtr<SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
183 {
184     return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
185 }
186
187 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
188 {
189     PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
190 }
191
192 String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
193 {
194     return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
195 }
196
197 void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
198 {
199     PlatformPasteboard(toPasteboard).copy(fromPasteboard);
200 }
201
202 int WebPlatformStrategies::changeCount(const String &pasteboardName)
203 {
204     return PlatformPasteboard(pasteboardName).changeCount();
205 }
206
207 String WebPlatformStrategies::uniqueName()
208 {
209     return PlatformPasteboard::uniqueName();
210 }
211
212 Color WebPlatformStrategies::color(const String& pasteboardName)
213 {
214     return PlatformPasteboard(pasteboardName).color();    
215 }
216
217 KURL WebPlatformStrategies::url(const String& pasteboardName)
218 {
219     return PlatformPasteboard(pasteboardName).url();
220 }
221
222 void WebPlatformStrategies::addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
223 {
224     PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes);
225 }
226
227 void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
228 {
229     PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
230 }
231
232 void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
233 {
234     PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
235 }
236
237 void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
238 {
239     PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
240 }
241
242 void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
243 {
244     PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);    
245 }