Source/WebCore: Use a platform strategy for local storage
[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 StorageStrategy* WebPlatformStrategies::createStorageStrategy()
82 {
83     return this;
84 }
85
86 VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy()
87 {
88     return this;
89 }
90
91 String WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
92 {
93     return WebCore::cookiesForDOM(session, firstParty, url);
94 }
95
96 void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, const String& cookieString)
97 {
98     WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
99 }
100
101 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
102 {
103     return WebCore::cookiesEnabled(session, firstParty, url);
104 }
105
106 String WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
107 {
108     return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
109 }
110
111 bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
112 {
113     return WebCore::getRawCookies(session, firstParty, url, rawCookies);
114 }
115
116 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& cookieName)
117 {
118     WebCore::deleteCookie(session, url, cookieName);
119 }
120
121 void WebPlatformStrategies::refreshPlugins()
122 {
123     [[WebPluginDatabase sharedDatabase] refresh];
124 }
125
126 void WebPlatformStrategies::getPluginInfo(const Page*, Vector<PluginInfo>& plugins)
127 {
128     BEGIN_BLOCK_OBJC_EXCEPTIONS;
129
130     NSArray* pluginsArray = [[WebPluginDatabase sharedDatabase] plugins];
131     for (unsigned int i = 0; i < [pluginsArray count]; ++i) {
132         WebPluginPackage *plugin = [pluginsArray objectAtIndex:i];
133
134         plugins.append([plugin pluginInfo]);
135     }
136     
137     END_BLOCK_OBJC_EXCEPTIONS;
138 }
139
140 bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
141 {
142     return page->group().isLinkVisited(hash);
143 }
144
145 void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash hash)
146 {
147     return page->group().addVisitedLinkHash(hash);
148 }
149
150 void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
151 {
152     PlatformPasteboard(pasteboardName).getTypes(types);
153 }
154
155 PassRefPtr<SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
156 {
157     return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
158 }
159
160 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
161 {
162     PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
163 }
164
165 String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
166 {
167     return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
168 }
169
170 void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
171 {
172     PlatformPasteboard(toPasteboard).copy(fromPasteboard);
173 }
174
175 int WebPlatformStrategies::changeCount(const String &pasteboardName)
176 {
177     return PlatformPasteboard(pasteboardName).changeCount();
178 }
179
180 String WebPlatformStrategies::uniqueName()
181 {
182     return PlatformPasteboard::uniqueName();
183 }
184
185 Color WebPlatformStrategies::color(const String& pasteboardName)
186 {
187     return PlatformPasteboard(pasteboardName).color();    
188 }
189
190 KURL WebPlatformStrategies::url(const String& pasteboardName)
191 {
192     return PlatformPasteboard(pasteboardName).url();
193 }
194
195 void WebPlatformStrategies::addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
196 {
197     PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes);
198 }
199
200 void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
201 {
202     PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
203 }
204
205 void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
206 {
207     PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
208 }
209
210 void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
211 {
212     PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
213 }
214
215 void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
216 {
217     PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);    
218 }