7bfc04aed94b664dea55f38622131cee15256eb5
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / C / WKContext.cpp
1 /*
2  * Copyright (C) 2010, 2011 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 #include "config.h"
27 #include "WKContext.h"
28 #include "WKContextPrivate.h"
29
30 #include "WKAPICast.h"
31 #include "WebContext.h"
32 #include "WebURLRequest.h"
33 #include <wtf/PassRefPtr.h>
34 #include <wtf/RefPtr.h>
35 #include <wtf/text/WTFString.h>
36
37 using namespace WebKit;
38
39 extern "C" {
40 // For binary compatibility with Safari 5.1. Should be removed eventually.
41 WK_EXPORT void _WKContextSetAdditionalPluginsDirectory(WKContextRef context, WKStringRef pluginsDirectory);
42 WK_EXPORT void _WKContextRegisterURLSchemeAsEmptyDocument(WKContextRef context, WKStringRef urlScheme);
43 WK_EXPORT void _WKContextSetAlwaysUsesComplexTextCodePath(WKContextRef context, bool alwaysUseComplexTextCodePath);
44 WK_EXPORT void _WKContextSetHTTPPipeliningEnabled(WKContextRef context, bool enabled);
45 }
46
47 WKTypeID WKContextGetTypeID()
48 {
49     return toAPI(WebContext::APIType);
50 }
51
52 WKContextRef WKContextCreate()
53 {
54     RefPtr<WebContext> context = WebContext::create(String());
55     return toAPI(context.release().leakRef());
56 }
57
58 WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef pathRef)
59 {
60     RefPtr<WebContext> context = WebContext::create(toImpl(pathRef)->string());
61     return toAPI(context.release().leakRef());
62 }
63
64 WKContextRef WKContextGetSharedProcessContext()
65 {
66     return toAPI(WebContext::sharedProcessContext());
67 }
68
69 WKContextRef WKContextGetSharedThreadContext()
70 {
71     return toAPI(WebContext::sharedThreadContext());
72 }
73
74 void WKContextSetInjectedBundleClient(WKContextRef contextRef, const WKContextInjectedBundleClient* wkClient)
75 {
76     toImpl(contextRef)->initializeInjectedBundleClient(wkClient);
77 }
78
79 void WKContextSetHistoryClient(WKContextRef contextRef, const WKContextHistoryClient* wkClient)
80 {
81     toImpl(contextRef)->initializeHistoryClient(wkClient);
82 }
83
84 void WKContextSetDownloadClient(WKContextRef contextRef, const WKContextDownloadClient* wkClient)
85 {
86     toImpl(contextRef)->initializeDownloadClient(wkClient);
87 }
88
89 void WKContextSetConnectionClient(WKContextRef contextRef, const WKContextConnectionClient* wkClient)
90 {
91     toImpl(contextRef)->initializeConnectionClient(wkClient);
92 }
93
94 WKDownloadRef WKContextDownloadURLRequest(WKContextRef contextRef, const WKURLRequestRef requestRef)
95 {
96     return toAPI(toImpl(contextRef)->download(0, toImpl(requestRef)->resourceRequest()));
97 }
98
99 void WKContextSetInitializationUserDataForInjectedBundle(WKContextRef contextRef,  WKTypeRef userDataRef)
100 {
101     toImpl(contextRef)->setInjectedBundleInitializationUserData(toImpl(userDataRef));
102 }
103
104 void WKContextPostMessageToInjectedBundle(WKContextRef contextRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
105 {
106     toImpl(contextRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
107 }
108
109 void WKContextGetGlobalStatistics(WKContextStatistics* statistics)
110 {
111     const WebContext::Statistics& webContextStatistics = WebContext::statistics();
112
113     statistics->wkViewCount = webContextStatistics.wkViewCount;
114     statistics->wkPageCount = webContextStatistics.wkPageCount;
115     statistics->wkFrameCount = webContextStatistics.wkViewCount;
116 }
117
118 void WKContextAddVisitedLink(WKContextRef contextRef, WKStringRef visitedURL)
119 {
120     toImpl(contextRef)->addVisitedLink(toImpl(visitedURL)->string());
121 }
122
123 void WKContextSetCacheModel(WKContextRef contextRef, WKCacheModel cacheModel)
124 {
125     toImpl(contextRef)->setCacheModel(toCacheModel(cacheModel));
126 }
127
128 WKCacheModel WKContextGetCacheModel(WKContextRef contextRef)
129 {
130     return toAPI(toImpl(contextRef)->cacheModel());
131 }
132
133 void WKContextSetAlwaysUsesComplexTextCodePath(WKContextRef contextRef, bool alwaysUseComplexTextCodePath)
134 {
135     toImpl(contextRef)->setAlwaysUsesComplexTextCodePath(alwaysUseComplexTextCodePath);
136 }
137
138 void WKContextSetShouldUseFontSmoothing(WKContextRef contextRef, bool useFontSmoothing)
139 {
140     toImpl(contextRef)->setShouldUseFontSmoothing(useFontSmoothing);
141 }
142
143 void WKContextSetAdditionalPluginsDirectory(WKContextRef contextRef, WKStringRef pluginsDirectory)
144 {
145     toImpl(contextRef)->setAdditionalPluginsDirectory(toImpl(pluginsDirectory)->string());
146 }
147
148 void WKContextRegisterURLSchemeAsEmptyDocument(WKContextRef contextRef, WKStringRef urlScheme)
149 {
150     toImpl(contextRef)->registerURLSchemeAsEmptyDocument(toImpl(urlScheme)->string());
151 }
152
153 void WKContextRegisterURLSchemeAsSecure(WKContextRef contextRef, WKStringRef urlScheme)
154 {
155     toImpl(contextRef)->registerURLSchemeAsSecure(toImpl(urlScheme)->string());
156 }
157
158 void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef contextRef, WKStringRef urlScheme)
159 {
160     toImpl(contextRef)->setDomainRelaxationForbiddenForURLScheme(toImpl(urlScheme)->string());
161 }
162
163 WKCookieManagerRef WKContextGetCookieManager(WKContextRef contextRef)
164 {
165     return toAPI(toImpl(contextRef)->cookieManagerProxy());
166 }
167
168 WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef contextRef)
169 {
170     return toAPI(toImpl(contextRef)->applicationCacheManagerProxy());
171 }
172
173 WKBatteryManagerRef WKContextGetBatteryManager(WKContextRef contextRef)
174 {
175 #if ENABLE(BATTERY_STATUS)
176     return toAPI(toImpl(contextRef)->batteryManagerProxy());
177 #else
178     return 0;
179 #endif
180 }
181
182 WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef contextRef)
183 {
184     return toAPI(toImpl(contextRef)->databaseManagerProxy());
185 }
186
187 WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef contextRef)
188 {
189     return toAPI(toImpl(contextRef)->geolocationManagerProxy());
190 }
191
192 WKIconDatabaseRef WKContextGetIconDatabase(WKContextRef contextRef)
193 {
194     return toAPI(toImpl(contextRef)->iconDatabase());
195 }
196
197 WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef contextRef)
198 {
199     return toAPI(toImpl(contextRef)->keyValueStorageManagerProxy());
200 }
201
202 WKMediaCacheManagerRef WKContextGetMediaCacheManager(WKContextRef contextRef)
203 {
204     return toAPI(toImpl(contextRef)->mediaCacheManagerProxy());
205 }
206
207 WKNotificationManagerRef WKContextGetNotificationManager(WKContextRef contextRef)
208 {
209     return toAPI(toImpl(contextRef)->notificationManagerProxy());
210 }
211
212 WKPluginSiteDataManagerRef WKContextGetPluginSiteDataManager(WKContextRef contextRef)
213 {
214     return toAPI(toImpl(contextRef)->pluginSiteDataManager());
215 }
216
217 WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef contextRef)
218 {
219     return toAPI(toImpl(contextRef)->resourceCacheManagerProxy());
220 }
221
222 void WKContextStartMemorySampler(WKContextRef contextRef, WKDoubleRef interval)
223 {
224     toImpl(contextRef)->startMemorySampler(toImpl(interval)->value());
225 }
226
227 void WKContextStopMemorySampler(WKContextRef contextRef)
228 {
229     toImpl(contextRef)->stopMemorySampler();
230 }
231
232 void WKContextSetIconDatabasePath(WKContextRef contextRef, WKStringRef iconDatabasePath)
233 {
234     toImpl(contextRef)->setIconDatabasePath(toImpl(iconDatabasePath)->string());
235 }
236
237 void WKContextSetDatabaseDirectory(WKContextRef contextRef, WKStringRef databaseDirectory)
238 {
239     toImpl(contextRef)->setDatabaseDirectory(toImpl(databaseDirectory)->string());
240 }
241
242 void WKContextSetLocalStorageDirectory(WKContextRef contextRef, WKStringRef localStorageDirectory)
243 {
244     toImpl(contextRef)->setLocalStorageDirectory(toImpl(localStorageDirectory)->string());
245 }
246
247 void WKContextDisableProcessTermination(WKContextRef contextRef)
248 {
249     toImpl(contextRef)->disableProcessTermination();
250 }
251
252 void WKContextEnableProcessTermination(WKContextRef contextRef)
253 {
254     toImpl(contextRef)->enableProcessTermination();
255 }
256
257 void WKContextSetHTTPPipeliningEnabled(WKContextRef contextRef, bool enabled)
258 {
259     toImpl(contextRef)->setHTTPPipeliningEnabled(enabled);
260 }
261
262 void WKContextWarmInitialProcess(WKContextRef contextRef)
263 {
264     toImpl(contextRef)->warmInitialProcess();
265 }
266
267 void WKContextGetStatistics(WKContextRef contextRef, void* context, WKContextGetStatisticsFunction callback)
268 {
269     toImpl(contextRef)->getWebCoreStatistics(DictionaryCallback::create(context, callback));    
270 }
271
272 void WKContextGarbageCollectJavaScriptObjects(WKContextRef contextRef)
273 {
274     toImpl(contextRef)->garbageCollectJavaScriptObjects();
275 }
276
277 void WKContextSetJavaScriptGarbageCollectorTimerEnabled(WKContextRef contextRef, bool enable)
278 {
279     toImpl(contextRef)->setJavaScriptGarbageCollectorTimerEnabled(enable);
280 }
281 // Deprecated functions.
282 void _WKContextSetAdditionalPluginsDirectory(WKContextRef context, WKStringRef pluginsDirectory)
283 {
284     WKContextSetAdditionalPluginsDirectory(context, pluginsDirectory);
285 }
286
287 void _WKContextRegisterURLSchemeAsEmptyDocument(WKContextRef context, WKStringRef urlScheme)
288 {
289     WKContextRegisterURLSchemeAsEmptyDocument(context, urlScheme);
290 }
291
292 void _WKContextSetAlwaysUsesComplexTextCodePath(WKContextRef context, bool alwaysUseComplexTextCodePath)
293 {
294     WKContextSetAlwaysUsesComplexTextCodePath(context, alwaysUseComplexTextCodePath);
295 }
296
297 void _WKContextSetHTTPPipeliningEnabled(WKContextRef context, bool enabled)
298 {
299     WKContextSetHTTPPipeliningEnabled(context, enabled);
300 }