bf196b765547de356e3fc2c0427560739f85db1b
[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 WKTypeID WKContextGetTypeID()
40 {
41     return toAPI(WebContext::APIType);
42 }
43
44 WKContextRef WKContextCreate()
45 {
46     RefPtr<WebContext> context = WebContext::create(String());
47     return toAPI(context.release().releaseRef());
48 }
49
50 WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef pathRef)
51 {
52     RefPtr<WebContext> context = WebContext::create(toImpl(pathRef)->string());
53     return toAPI(context.release().releaseRef());
54 }
55
56 WKContextRef WKContextGetSharedProcessContext()
57 {
58     return toAPI(WebContext::sharedProcessContext());
59 }
60
61 WKContextRef WKContextGetSharedThreadContext()
62 {
63     return toAPI(WebContext::sharedThreadContext());
64 }
65
66 void WKContextSetInjectedBundleClient(WKContextRef contextRef, const WKContextInjectedBundleClient* wkClient)
67 {
68     if (wkClient && wkClient->version)
69         return;
70     toImpl(contextRef)->initializeInjectedBundleClient(wkClient);
71 }
72
73 void WKContextSetHistoryClient(WKContextRef contextRef, const WKContextHistoryClient* wkClient)
74 {
75     if (wkClient && wkClient->version)
76         return;
77     toImpl(contextRef)->initializeHistoryClient(wkClient);
78 }
79
80 void WKContextSetDownloadClient(WKContextRef contextRef, const WKContextDownloadClient* wkClient)
81 {
82     if (wkClient && wkClient->version)
83         return;
84     toImpl(contextRef)->initializeDownloadClient(wkClient);
85 }
86
87 void WKContextDownloadURLRequest(WKContextRef contextRef, const WKURLRequestRef requestRef)
88 {
89     toImpl(contextRef)->download(0, toImpl(requestRef)->resourceRequest());
90 }
91
92 void WKContextSetInitializationUserDataForInjectedBundle(WKContextRef contextRef,  WKTypeRef userDataRef)
93 {
94     toImpl(contextRef)->setInjectedBundleInitializationUserData(toImpl(userDataRef));
95 }
96
97 void WKContextPostMessageToInjectedBundle(WKContextRef contextRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef)
98 {
99     toImpl(contextRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef));
100 }
101
102 void WKContextGetGlobalStatistics(WKContextStatistics* statistics)
103 {
104     const WebContext::Statistics& webContextStatistics = WebContext::statistics();
105
106     statistics->wkViewCount = webContextStatistics.wkViewCount;
107     statistics->wkPageCount = webContextStatistics.wkPageCount;
108     statistics->wkFrameCount = webContextStatistics.wkViewCount;
109 }
110
111 void WKContextAddVisitedLink(WKContextRef contextRef, WKStringRef visitedURL)
112 {
113     toImpl(contextRef)->addVisitedLink(toImpl(visitedURL)->string());
114 }
115
116 void WKContextSetCacheModel(WKContextRef contextRef, WKCacheModel cacheModel)
117 {
118     toImpl(contextRef)->setCacheModel(toCacheModel(cacheModel));
119 }
120
121 WKCacheModel WKContextGetCacheModel(WKContextRef contextRef)
122 {
123     return toAPI(toImpl(contextRef)->cacheModel());
124 }
125
126 void _WKContextSetAlwaysUsesComplexTextCodePath(WKContextRef contextRef, bool alwaysUseComplexTextCodePath)
127 {
128     toImpl(contextRef)->setAlwaysUsesComplexTextCodePath(alwaysUseComplexTextCodePath);
129 }
130
131 void _WKContextSetAdditionalPluginsDirectory(WKContextRef contextRef, WKStringRef pluginsDirectory)
132 {
133     toImpl(contextRef)->setAdditionalPluginsDirectory(toImpl(pluginsDirectory)->string());
134 }
135
136 void _WKContextRegisterURLSchemeAsEmptyDocument(WKContextRef contextRef, WKStringRef urlScheme)
137 {
138     toImpl(contextRef)->registerURLSchemeAsEmptyDocument(toImpl(urlScheme)->string());
139 }
140
141 void WKContextRegisterURLSchemeAsSecure(WKContextRef contextRef, WKStringRef urlScheme)
142 {
143     toImpl(contextRef)->registerURLSchemeAsSecure(toImpl(urlScheme)->string());
144 }
145
146 void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef contextRef, WKStringRef urlScheme)
147 {
148     toImpl(contextRef)->setDomainRelaxationForbiddenForURLScheme(toImpl(urlScheme)->string());
149 }
150
151 void WKContextClearResourceCaches(WKContextRef contextRef, WKResourceCachesToClear cachesToClear)
152 {
153     toImpl(contextRef)->clearResourceCaches(toResourceCachesToClear(cachesToClear));
154 }
155
156 void WKContextClearApplicationCache(WKContextRef contextRef)
157 {
158     toImpl(contextRef)->clearApplicationCache();
159 }
160
161 WKCookieManagerRef WKContextGetCookieManager(WKContextRef contextRef)
162 {
163     return toAPI(toImpl(contextRef)->cookieManagerProxy());
164 }
165
166 WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef contextRef)
167 {
168     return toAPI(toImpl(contextRef)->applicationCacheManagerProxy());
169 }
170
171 WKDatabaseManagerRef WKContextGetDatabaseManager(WKContextRef contextRef)
172 {
173     return toAPI(toImpl(contextRef)->databaseManagerProxy());
174 }
175
176 WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef contextRef)
177 {
178     return toAPI(toImpl(contextRef)->geolocationManagerProxy());
179 }
180
181 WKIconDatabaseRef WKContextGetIconDatabase(WKContextRef contextRef)
182 {
183     return toAPI(toImpl(contextRef)->iconDatabase());
184 }
185
186 WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef contextRef)
187 {
188     return toAPI(toImpl(contextRef)->keyValueStorageManagerProxy());
189 }
190
191 WKMediaCacheManagerRef WKContextGetMediaCacheManager(WKContextRef contextRef)
192 {
193     return toAPI(toImpl(contextRef)->mediaCacheManagerProxy());
194 }
195
196 WKPluginSiteDataManagerRef WKContextGetPluginSiteDataManager(WKContextRef contextRef)
197 {
198     return toAPI(toImpl(contextRef)->pluginSiteDataManager());
199 }
200
201 WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef contextRef)
202 {
203     return toAPI(toImpl(contextRef)->resourceCacheManagerProxy());
204 }
205
206 void WKContextStartMemorySampler(WKContextRef contextRef, WKDoubleRef interval)
207 {
208     toImpl(contextRef)->startMemorySampler(toImpl(interval)->value());
209 }
210
211 void WKContextStopMemorySampler(WKContextRef contextRef)
212 {
213     toImpl(contextRef)->stopMemorySampler();
214 }
215
216 void WKContextSetIconDatabasePath(WKContextRef contextRef, WKStringRef iconDatabasePath)
217 {
218     toImpl(contextRef)->setIconDatabasePath(toImpl(iconDatabasePath)->string());
219 }
220
221 void WKContextSetDatabaseDirectory(WKContextRef contextRef, WKStringRef databaseDirectory)
222 {
223     toImpl(contextRef)->setDatabaseDirectory(toImpl(databaseDirectory)->string());
224 }
225
226 void WKContextSetLocalStorageDirectory(WKContextRef contextRef, WKStringRef localStorageDirectory)
227 {
228     toImpl(contextRef)->setLocalStorageDirectory(toImpl(localStorageDirectory)->string());
229 }