ed067ac3daabb1931a952c9932b5a106afee5e24
[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::initializeIfNecessary()
42 {
43     static WebPlatformStrategies* platformStrategies;
44     if (!platformStrategies) {
45         platformStrategies = new WebPlatformStrategies;
46         setPlatformStrategies(platformStrategies);
47     }
48 }
49
50 WebPlatformStrategies::WebPlatformStrategies()
51 {
52 }
53
54 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
55 {
56     return this;
57 }
58
59 DatabaseStrategy* WebPlatformStrategies::createDatabaseStrategy()
60 {
61     return this;
62 }
63
64 LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
65 {
66     return this;
67 }
68
69 PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
70 {
71     return this;
72 }
73
74 PluginStrategy* WebPlatformStrategies::createPluginStrategy()
75 {
76     return this;
77 }
78
79 SharedWorkerStrategy* WebPlatformStrategies::createSharedWorkerStrategy()
80 {
81     return this;
82 }
83
84 StorageStrategy* WebPlatformStrategies::createStorageStrategy()
85 {
86     return this;
87 }
88
89 VisitedLinkStrategy* WebPlatformStrategies::createVisitedLinkStrategy()
90 {
91     return this;
92 }
93
94 String WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
95 {
96     return WebCore::cookiesForDOM(session, firstParty, url);
97 }
98
99 void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, const String& cookieString)
100 {
101     WebCore::setCookiesFromDOM(session, firstParty, url, cookieString);
102 }
103
104 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
105 {
106     return WebCore::cookiesEnabled(session, firstParty, url);
107 }
108
109 String WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url)
110 {
111     return WebCore::cookieRequestHeaderFieldValue(session, firstParty, url);
112 }
113
114 bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const KURL& firstParty, const KURL& url, Vector<Cookie>& rawCookies)
115 {
116     return WebCore::getRawCookies(session, firstParty, url, rawCookies);
117 }
118
119 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const KURL& url, const String& cookieName)
120 {
121     WebCore::deleteCookie(session, url, cookieName);
122 }
123
124 void WebPlatformStrategies::refreshPlugins()
125 {
126     [[WebPluginDatabase sharedDatabase] refresh];
127 }
128
129 void WebPlatformStrategies::getPluginInfo(const Page* page, Vector<PluginInfo>& plugins)
130 {
131     BEGIN_BLOCK_OBJC_EXCEPTIONS;
132
133     // WebKit1 has no application plug-ins, so we don't need to add them here.
134     if (!page->mainFrame()->loader()->subframeLoader()->allowPlugins(NotAboutToInstantiatePlugin))
135         return;
136
137     NSArray* pluginsArray = [[WebPluginDatabase sharedDatabase] plugins];
138     for (unsigned int i = 0; i < [pluginsArray count]; ++i) {
139         WebPluginPackage *plugin = [pluginsArray objectAtIndex:i];
140
141         plugins.append([plugin pluginInfo]);
142     }
143     
144     END_BLOCK_OBJC_EXCEPTIONS;
145 }
146
147 bool WebPlatformStrategies::isLinkVisited(Page* page, LinkHash hash, const KURL&, const AtomicString&)
148 {
149     return page->group().isLinkVisited(hash);
150 }
151
152 void WebPlatformStrategies::addVisitedLink(Page* page, LinkHash hash)
153 {
154     return page->group().addVisitedLinkHash(hash);
155 }
156
157 void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
158 {
159     PlatformPasteboard(pasteboardName).getTypes(types);
160 }
161
162 PassRefPtr<SharedBuffer> WebPlatformStrategies::bufferForType(const String& pasteboardType, const String& pasteboardName)
163 {
164     return PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
165 }
166
167 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
168 {
169     PlatformPasteboard(pasteboardName).getPathnamesForType(pathnames, pasteboardType);
170 }
171
172 String WebPlatformStrategies::stringForType(const String& pasteboardType, const String& pasteboardName)
173 {
174     return PlatformPasteboard(pasteboardName).stringForType(pasteboardType);
175 }
176
177 void WebPlatformStrategies::copy(const String& fromPasteboard, const String& toPasteboard)
178 {
179     PlatformPasteboard(toPasteboard).copy(fromPasteboard);
180 }
181
182 int WebPlatformStrategies::changeCount(const String &pasteboardName)
183 {
184     return PlatformPasteboard(pasteboardName).changeCount();
185 }
186
187 String WebPlatformStrategies::uniqueName()
188 {
189     return PlatformPasteboard::uniqueName();
190 }
191
192 Color WebPlatformStrategies::color(const String& pasteboardName)
193 {
194     return PlatformPasteboard(pasteboardName).color();    
195 }
196
197 KURL WebPlatformStrategies::url(const String& pasteboardName)
198 {
199     return PlatformPasteboard(pasteboardName).url();
200 }
201
202 void WebPlatformStrategies::addTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
203 {
204     PlatformPasteboard(pasteboardName).addTypes(pasteboardTypes);
205 }
206
207 void WebPlatformStrategies::setTypes(const Vector<String>& pasteboardTypes, const String& pasteboardName)
208 {
209     PlatformPasteboard(pasteboardName).setTypes(pasteboardTypes);
210 }
211
212 void WebPlatformStrategies::setBufferForType(PassRefPtr<SharedBuffer> buffer, const String& pasteboardType, const String& pasteboardName)
213 {
214     PlatformPasteboard(pasteboardName).setBufferForType(buffer, pasteboardType);
215 }
216
217 void WebPlatformStrategies::setPathnamesForType(const Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName)
218 {
219     PlatformPasteboard(pasteboardName).setPathnamesForType(pathnames, pasteboardType);
220 }
221
222 void WebPlatformStrategies::setStringForType(const String& string, const String& pasteboardType, const String& pasteboardName)
223 {
224     PlatformPasteboard(pasteboardName).setStringForType(string, pasteboardType);    
225 }