1 | /* |
2 | * Copyright (C) 2010, 2011, 2012 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 "WKContextPrivate.h" |
28 | |
29 | #include "APIArray.h" |
30 | #include "APIClient.h" |
31 | #include "APIDownloadClient.h" |
32 | #include "APILegacyContextHistoryClient.h" |
33 | #include "APINavigationData.h" |
34 | #include "APIProcessPoolConfiguration.h" |
35 | #include "APIURLRequest.h" |
36 | #include "AuthenticationChallengeProxy.h" |
37 | #include "DownloadProxy.h" |
38 | #include "WKAPICast.h" |
39 | #include "WKArray.h" |
40 | #include "WKContextConfigurationRef.h" |
41 | #include "WKRetainPtr.h" |
42 | #include "WKString.h" |
43 | #include "WebCertificateInfo.h" |
44 | #include "WebContextInjectedBundleClient.h" |
45 | #include "WebProcessPool.h" |
46 | #include <wtf/RefPtr.h> |
47 | #include <wtf/text/WTFString.h> |
48 | |
49 | // Supplements |
50 | #include "WebCookieManagerProxy.h" |
51 | #include "WebGeolocationManagerProxy.h" |
52 | #include "WebNotificationManagerProxy.h" |
53 | |
54 | namespace API { |
55 | template<> struct ClientTraits<WKContextDownloadClientBase> { |
56 | typedef std::tuple<WKContextDownloadClientV0, WKContextDownloadClientV1> Versions; |
57 | }; |
58 | template<> struct ClientTraits<WKContextHistoryClientBase> { |
59 | typedef std::tuple<WKContextHistoryClientV0> Versions; |
60 | }; |
61 | } |
62 | |
63 | WKTypeID WKContextGetTypeID() |
64 | { |
65 | return WebKit::toAPI(WebKit::WebProcessPool::APIType); |
66 | } |
67 | |
68 | WKContextRef WKContextCreate() |
69 | { |
70 | auto configuration = API::ProcessPoolConfiguration::createWithLegacyOptions(); |
71 | return WebKit::toAPI(&WebKit::WebProcessPool::create(configuration).leakRef()); |
72 | } |
73 | |
74 | WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef pathRef) |
75 | { |
76 | auto configuration = API::ProcessPoolConfiguration::createWithLegacyOptions(); |
77 | configuration->setInjectedBundlePath(WebKit::toWTFString(pathRef)); |
78 | |
79 | return WebKit::toAPI(&WebKit::WebProcessPool::create(configuration).leakRef()); |
80 | } |
81 | |
82 | WKContextRef WKContextCreateWithConfiguration(WKContextConfigurationRef configuration) |
83 | { |
84 | RefPtr<API::ProcessPoolConfiguration> apiConfiguration = WebKit::toImpl(configuration); |
85 | if (!apiConfiguration) |
86 | apiConfiguration = API::ProcessPoolConfiguration::create(); |
87 | return WebKit::toAPI(&WebKit::WebProcessPool::create(*apiConfiguration).leakRef()); |
88 | } |
89 | |
90 | void WKContextSetClient(WKContextRef contextRef, const WKContextClientBase* wkClient) |
91 | { |
92 | WebKit::toImpl(contextRef)->initializeClient(wkClient); |
93 | } |
94 | |
95 | void WKContextSetInjectedBundleClient(WKContextRef contextRef, const WKContextInjectedBundleClientBase* wkClient) |
96 | { |
97 | WebKit::toImpl(contextRef)->setInjectedBundleClient(std::make_unique<WebKit::WebContextInjectedBundleClient>(wkClient)); |
98 | } |
99 | |
100 | void WKContextSetHistoryClient(WKContextRef contextRef, const WKContextHistoryClientBase* wkClient) |
101 | { |
102 | class HistoryClient final : public API::Client<WKContextHistoryClientBase>, public API::LegacyContextHistoryClient { |
103 | public: |
104 | explicit HistoryClient(const WKContextHistoryClientBase* client) |
105 | { |
106 | initialize(client); |
107 | } |
108 | |
109 | private: |
110 | void didNavigateWithNavigationData(WebKit::WebProcessPool& processPool, WebKit::WebPageProxy& page, const WebKit::WebNavigationDataStore& navigationDataStore, WebKit::WebFrameProxy& frame) override |
111 | { |
112 | if (!m_client.didNavigateWithNavigationData) |
113 | return; |
114 | |
115 | RefPtr<API::NavigationData> navigationData = API::NavigationData::create(navigationDataStore); |
116 | m_client.didNavigateWithNavigationData(WebKit::toAPI(&processPool), WebKit::toAPI(&page), WebKit::toAPI(navigationData.get()), WebKit::toAPI(&frame), m_client.base.clientInfo); |
117 | } |
118 | |
119 | void didPerformClientRedirect(WebKit::WebProcessPool& processPool, WebKit::WebPageProxy& page, const String& sourceURL, const String& destinationURL, WebKit::WebFrameProxy& frame) override |
120 | { |
121 | if (!m_client.didPerformClientRedirect) |
122 | return; |
123 | |
124 | m_client.didPerformClientRedirect(WebKit::toAPI(&processPool), WebKit::toAPI(&page), WebKit::toURLRef(sourceURL.impl()), WebKit::toURLRef(destinationURL.impl()), WebKit::toAPI(&frame), m_client.base.clientInfo); |
125 | } |
126 | |
127 | void didPerformServerRedirect(WebKit::WebProcessPool& processPool, WebKit::WebPageProxy& page, const String& sourceURL, const String& destinationURL, WebKit::WebFrameProxy& frame) override |
128 | { |
129 | if (!m_client.didPerformServerRedirect) |
130 | return; |
131 | |
132 | m_client.didPerformServerRedirect(WebKit::toAPI(&processPool), WebKit::toAPI(&page), WebKit::toURLRef(sourceURL.impl()), WebKit::toURLRef(destinationURL.impl()), WebKit::toAPI(&frame), m_client.base.clientInfo); |
133 | } |
134 | |
135 | void didUpdateHistoryTitle(WebKit::WebProcessPool& processPool, WebKit::WebPageProxy& page, const String& title, const String& url, WebKit::WebFrameProxy& frame) override |
136 | { |
137 | if (!m_client.didUpdateHistoryTitle) |
138 | return; |
139 | |
140 | m_client.didUpdateHistoryTitle(WebKit::toAPI(&processPool), WebKit::toAPI(&page), WebKit::toAPI(title.impl()), WebKit::toURLRef(url.impl()), WebKit::toAPI(&frame), m_client.base.clientInfo); |
141 | } |
142 | |
143 | void populateVisitedLinks(WebKit::WebProcessPool& processPool) override |
144 | { |
145 | if (!m_client.populateVisitedLinks) |
146 | return; |
147 | |
148 | m_client.populateVisitedLinks(WebKit::toAPI(&processPool), m_client.base.clientInfo); |
149 | } |
150 | |
151 | bool addsVisitedLinks() const override |
152 | { |
153 | return m_client.populateVisitedLinks; |
154 | } |
155 | }; |
156 | |
157 | WebKit::WebProcessPool& processPool = *WebKit::toImpl(contextRef); |
158 | processPool.setHistoryClient(std::make_unique<HistoryClient>(wkClient)); |
159 | |
160 | bool addsVisitedLinks = processPool.historyClient().addsVisitedLinks(); |
161 | |
162 | for (auto& process : processPool.processes()) { |
163 | for (auto& page : process->pages()) |
164 | page->setAddsVisitedLinks(addsVisitedLinks); |
165 | } |
166 | } |
167 | |
168 | void WKContextSetDownloadClient(WKContextRef contextRef, const WKContextDownloadClientBase* wkClient) |
169 | { |
170 | class DownloadClient final : public API::Client<WKContextDownloadClientBase>, public API::DownloadClient { |
171 | public: |
172 | explicit DownloadClient(const WKContextDownloadClientBase* client) |
173 | { |
174 | initialize(client); |
175 | } |
176 | private: |
177 | void didStart(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy) final |
178 | { |
179 | if (!m_client.didStart) |
180 | return; |
181 | |
182 | m_client.didStart(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), m_client.base.clientInfo); |
183 | } |
184 | |
185 | void didReceiveAuthenticationChallenge(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, WebKit::AuthenticationChallengeProxy& authenticationChallengeProxy) final |
186 | { |
187 | if (!m_client.didReceiveAuthenticationChallenge) |
188 | return; |
189 | |
190 | m_client.didReceiveAuthenticationChallenge(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), WebKit::toAPI(&authenticationChallengeProxy), m_client.base.clientInfo); |
191 | } |
192 | |
193 | void didReceiveResponse(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, const WebCore::ResourceResponse& response) final |
194 | { |
195 | if (!m_client.didReceiveResponse) |
196 | return; |
197 | |
198 | m_client.didReceiveResponse(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), WebKit::toAPI(API::URLResponse::create(response).ptr()), m_client.base.clientInfo); |
199 | } |
200 | |
201 | void didReceiveData(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, uint64_t length) final |
202 | { |
203 | if (!m_client.didReceiveData) |
204 | return; |
205 | |
206 | m_client.didReceiveData(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), length, m_client.base.clientInfo); |
207 | } |
208 | |
209 | void decideDestinationWithSuggestedFilename(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, const String& filename, Function<void(WebKit::AllowOverwrite, WTF::String)>&& completionHandler) final |
210 | { |
211 | if (!m_client.decideDestinationWithSuggestedFilename) |
212 | return completionHandler(WebKit::AllowOverwrite::No, { }); |
213 | |
214 | bool allowOverwrite = false; |
215 | auto destination = adoptWK(m_client.decideDestinationWithSuggestedFilename(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), WebKit::toAPI(filename.impl()), &allowOverwrite, m_client.base.clientInfo)); |
216 | completionHandler(allowOverwrite ? WebKit::AllowOverwrite::Yes : WebKit::AllowOverwrite::No, WebKit::toWTFString(destination.get())); |
217 | } |
218 | |
219 | void didCreateDestination(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, const String& path) final |
220 | { |
221 | if (!m_client.didCreateDestination) |
222 | return; |
223 | |
224 | m_client.didCreateDestination(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), WebKit::toAPI(path.impl()), m_client.base.clientInfo); |
225 | } |
226 | |
227 | void didFinish(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy) final |
228 | { |
229 | if (!m_client.didFinish) |
230 | return; |
231 | |
232 | m_client.didFinish(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), m_client.base.clientInfo); |
233 | } |
234 | |
235 | void didFail(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, const WebCore::ResourceError& error) final |
236 | { |
237 | if (!m_client.didFail) |
238 | return; |
239 | |
240 | m_client.didFail(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), WebKit::toAPI(error), m_client.base.clientInfo); |
241 | } |
242 | |
243 | void didCancel(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy) final |
244 | { |
245 | if (!m_client.didCancel) |
246 | return; |
247 | |
248 | m_client.didCancel(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), m_client.base.clientInfo); |
249 | } |
250 | |
251 | void processDidCrash(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy) final |
252 | { |
253 | if (!m_client.processDidCrash) |
254 | return; |
255 | |
256 | m_client.processDidCrash(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), m_client.base.clientInfo); |
257 | } |
258 | |
259 | void willSendRequest(WebKit::WebProcessPool& processPool, WebKit::DownloadProxy& downloadProxy, WebCore::ResourceRequest&& request, const WebCore::ResourceResponse&, CompletionHandler<void(WebCore::ResourceRequest&&)>&& completionHandler) final |
260 | { |
261 | if (m_client.didReceiveServerRedirect) |
262 | m_client.didReceiveServerRedirect(WebKit::toAPI(&processPool), WebKit::toAPI(&downloadProxy), WebKit::toURLRef(request.url().string().impl()), m_client.base.clientInfo); |
263 | |
264 | completionHandler(WTFMove(request)); |
265 | } |
266 | }; |
267 | |
268 | WebKit::toImpl(contextRef)->setDownloadClient(std::make_unique<DownloadClient>(wkClient)); |
269 | } |
270 | |
271 | void WKContextSetConnectionClient(WKContextRef contextRef, const WKContextConnectionClientBase* wkClient) |
272 | { |
273 | WebKit::toImpl(contextRef)->initializeConnectionClient(wkClient); |
274 | } |
275 | |
276 | WKDownloadRef WKContextDownloadURLRequest(WKContextRef contextRef, WKURLRequestRef requestRef) |
277 | { |
278 | return WebKit::toAPI(&WebKit::toImpl(contextRef)->download(0, WebKit::toImpl(requestRef)->resourceRequest())); |
279 | } |
280 | |
281 | WKDownloadRef WKContextResumeDownload(WKContextRef contextRef, WKDataRef resumeData, WKStringRef path) |
282 | { |
283 | return WebKit::toAPI(&WebKit::toImpl(contextRef)->resumeDownload(nullptr, WebKit::toImpl(resumeData), WebKit::toWTFString(path))); |
284 | } |
285 | |
286 | void WKContextSetInitializationUserDataForInjectedBundle(WKContextRef contextRef, WKTypeRef userDataRef) |
287 | { |
288 | WebKit::toImpl(contextRef)->setInjectedBundleInitializationUserData(WebKit::toImpl(userDataRef)); |
289 | } |
290 | |
291 | void WKContextPostMessageToInjectedBundle(WKContextRef contextRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef) |
292 | { |
293 | WebKit::toImpl(contextRef)->postMessageToInjectedBundle(WebKit::toImpl(messageNameRef)->string(), WebKit::toImpl(messageBodyRef)); |
294 | } |
295 | |
296 | void WKContextGetGlobalStatistics(WKContextStatistics* statistics) |
297 | { |
298 | const WebKit::WebProcessPool::Statistics& webContextStatistics = WebKit::WebProcessPool::statistics(); |
299 | |
300 | statistics->wkViewCount = webContextStatistics.wkViewCount; |
301 | statistics->wkPageCount = webContextStatistics.wkPageCount; |
302 | statistics->wkFrameCount = webContextStatistics.wkFrameCount; |
303 | } |
304 | |
305 | void WKContextAddVisitedLink(WKContextRef contextRef, WKStringRef visitedURL) |
306 | { |
307 | String visitedURLString = WebKit::toImpl(visitedURL)->string(); |
308 | if (visitedURLString.isEmpty()) |
309 | return; |
310 | |
311 | WebKit::toImpl(contextRef)->visitedLinkStore().addVisitedLinkHash(WebCore::computeSharedStringHash(visitedURLString)); |
312 | } |
313 | |
314 | void WKContextClearVisitedLinks(WKContextRef contextRef) |
315 | { |
316 | WebKit::toImpl(contextRef)->visitedLinkStore().removeAll(); |
317 | } |
318 | |
319 | void WKContextSetCacheModel(WKContextRef contextRef, WKCacheModel cacheModel) |
320 | { |
321 | WebKit::toImpl(contextRef)->setCacheModel(WebKit::toCacheModel(cacheModel)); |
322 | } |
323 | |
324 | WKCacheModel WKContextGetCacheModel(WKContextRef contextRef) |
325 | { |
326 | return WebKit::toAPI(WebKit::toImpl(contextRef)->cacheModel()); |
327 | } |
328 | |
329 | void WKContextSetMaximumNumberOfProcesses(WKContextRef, unsigned) |
330 | { |
331 | // Deprecated. |
332 | } |
333 | |
334 | unsigned WKContextGetMaximumNumberOfProcesses(WKContextRef) |
335 | { |
336 | // Deprecated. |
337 | return std::numeric_limits<unsigned>::max(); |
338 | } |
339 | |
340 | void WKContextSetAlwaysUsesComplexTextCodePath(WKContextRef contextRef, bool alwaysUseComplexTextCodePath) |
341 | { |
342 | WebKit::toImpl(contextRef)->setAlwaysUsesComplexTextCodePath(alwaysUseComplexTextCodePath); |
343 | } |
344 | |
345 | void WKContextSetShouldUseFontSmoothing(WKContextRef contextRef, bool useFontSmoothing) |
346 | { |
347 | WebKit::toImpl(contextRef)->setShouldUseFontSmoothing(useFontSmoothing); |
348 | } |
349 | |
350 | void WKContextSetAdditionalPluginsDirectory(WKContextRef contextRef, WKStringRef pluginsDirectory) |
351 | { |
352 | #if ENABLE(NETSCAPE_PLUGIN_API) |
353 | WebKit::toImpl(contextRef)->setAdditionalPluginsDirectory(WebKit::toImpl(pluginsDirectory)->string()); |
354 | #else |
355 | UNUSED_PARAM(contextRef); |
356 | UNUSED_PARAM(pluginsDirectory); |
357 | #endif |
358 | } |
359 | |
360 | void WKContextRefreshPlugIns(WKContextRef context) |
361 | { |
362 | #if ENABLE(NETSCAPE_PLUGIN_API) |
363 | WebKit::toImpl(context)->refreshPlugins(); |
364 | #else |
365 | UNUSED_PARAM(context); |
366 | #endif |
367 | } |
368 | |
369 | void WKContextRegisterURLSchemeAsEmptyDocument(WKContextRef contextRef, WKStringRef urlScheme) |
370 | { |
371 | WebKit::toImpl(contextRef)->registerURLSchemeAsEmptyDocument(WebKit::toImpl(urlScheme)->string()); |
372 | } |
373 | |
374 | void WKContextRegisterURLSchemeAsSecure(WKContextRef contextRef, WKStringRef urlScheme) |
375 | { |
376 | WebKit::toImpl(contextRef)->registerURLSchemeAsSecure(WebKit::toImpl(urlScheme)->string()); |
377 | } |
378 | |
379 | void WKContextRegisterURLSchemeAsBypassingContentSecurityPolicy(WKContextRef contextRef, WKStringRef urlScheme) |
380 | { |
381 | WebKit::toImpl(contextRef)->registerURLSchemeAsBypassingContentSecurityPolicy(WebKit::toImpl(urlScheme)->string()); |
382 | } |
383 | |
384 | void WKContextRegisterURLSchemeAsCachePartitioned(WKContextRef contextRef, WKStringRef urlScheme) |
385 | { |
386 | WebKit::toImpl(contextRef)->registerURLSchemeAsCachePartitioned(WebKit::toImpl(urlScheme)->string()); |
387 | } |
388 | |
389 | void WKContextRegisterURLSchemeAsCanDisplayOnlyIfCanRequest(WKContextRef contextRef, WKStringRef urlScheme) |
390 | { |
391 | WebKit::toImpl(contextRef)->registerURLSchemeAsCanDisplayOnlyIfCanRequest(WebKit::toImpl(urlScheme)->string()); |
392 | } |
393 | |
394 | void WKContextSetDomainRelaxationForbiddenForURLScheme(WKContextRef contextRef, WKStringRef urlScheme) |
395 | { |
396 | WebKit::toImpl(contextRef)->setDomainRelaxationForbiddenForURLScheme(WebKit::toImpl(urlScheme)->string()); |
397 | } |
398 | |
399 | void WKContextSetCanHandleHTTPSServerTrustEvaluation(WKContextRef contextRef, bool value) |
400 | { |
401 | WebKit::toImpl(contextRef)->setCanHandleHTTPSServerTrustEvaluation(value); |
402 | } |
403 | |
404 | void WKContextSetPrewarmsProcessesAutomatically(WKContextRef contextRef, bool value) |
405 | { |
406 | WebKit::toImpl(contextRef)->configuration().setIsAutomaticProcessWarmingEnabled(value); |
407 | } |
408 | |
409 | void WKContextSetUsesSingleWebProcess(WKContextRef contextRef, bool value) |
410 | { |
411 | WebKit::toImpl(contextRef)->configuration().setUsesSingleWebProcess(value); |
412 | } |
413 | |
414 | bool WKContextGetUsesSingleWebProcess(WKContextRef contextRef) |
415 | { |
416 | return WebKit::toImpl(contextRef)->configuration().usesSingleWebProcess(); |
417 | } |
418 | |
419 | void WKContextSetCustomWebContentServiceBundleIdentifier(WKContextRef contextRef, WKStringRef name) |
420 | { |
421 | WebKit::toImpl(contextRef)->setCustomWebContentServiceBundleIdentifier(WebKit::toImpl(name)->string()); |
422 | } |
423 | |
424 | void WKContextSetDiskCacheSpeculativeValidationEnabled(WKContextRef contextRef, bool value) |
425 | { |
426 | WebKit::toImpl(contextRef)->configuration().setDiskCacheSpeculativeValidationEnabled(value); |
427 | } |
428 | |
429 | void WKContextPreconnectToServer(WKContextRef contextRef, WKURLRef serverURLRef) |
430 | { |
431 | WebKit::toImpl(contextRef)->preconnectToServer(URL(URL(), WebKit::toWTFString(serverURLRef))); |
432 | } |
433 | |
434 | WKCookieManagerRef WKContextGetCookieManager(WKContextRef contextRef) |
435 | { |
436 | return WebKit::toAPI(WebKit::toImpl(contextRef)->supplement<WebKit::WebCookieManagerProxy>()); |
437 | } |
438 | |
439 | WKWebsiteDataStoreRef WKContextGetWebsiteDataStore(WKContextRef context) |
440 | { |
441 | auto* dataStore = WebKit::toImpl(context)->websiteDataStore(); |
442 | if (!dataStore) { |
443 | auto defaultDataStore = API::WebsiteDataStore::defaultDataStore(); |
444 | WebKit::toImpl(context)->setPrimaryDataStore(defaultDataStore.get()); |
445 | dataStore = defaultDataStore.ptr(); |
446 | } |
447 | |
448 | return WebKit::toAPI(dataStore); |
449 | } |
450 | |
451 | WKApplicationCacheManagerRef WKContextGetApplicationCacheManager(WKContextRef context) |
452 | { |
453 | return reinterpret_cast<WKApplicationCacheManagerRef>(WKContextGetWebsiteDataStore(context)); |
454 | } |
455 | |
456 | WKGeolocationManagerRef WKContextGetGeolocationManager(WKContextRef contextRef) |
457 | { |
458 | return WebKit::toAPI(WebKit::toImpl(contextRef)->supplement<WebKit::WebGeolocationManagerProxy>()); |
459 | } |
460 | |
461 | WKIconDatabaseRef WKContextGetIconDatabase(WKContextRef) |
462 | { |
463 | return nullptr; |
464 | } |
465 | |
466 | WKKeyValueStorageManagerRef WKContextGetKeyValueStorageManager(WKContextRef context) |
467 | { |
468 | return reinterpret_cast<WKKeyValueStorageManagerRef>(WKContextGetWebsiteDataStore(context)); |
469 | } |
470 | |
471 | WKMediaSessionFocusManagerRef WKContextGetMediaSessionFocusManager(WKContextRef context) |
472 | { |
473 | #if ENABLE(MEDIA_SESSION) |
474 | return WebKit::toAPI(WebKit::toImpl(context)->supplement<WebKit::WebMediaSessionFocusManager>()); |
475 | #else |
476 | UNUSED_PARAM(context); |
477 | return nullptr; |
478 | #endif |
479 | } |
480 | |
481 | WKNotificationManagerRef WKContextGetNotificationManager(WKContextRef contextRef) |
482 | { |
483 | return WebKit::toAPI(WebKit::toImpl(contextRef)->supplement<WebKit::WebNotificationManagerProxy>()); |
484 | } |
485 | |
486 | WKResourceCacheManagerRef WKContextGetResourceCacheManager(WKContextRef context) |
487 | { |
488 | return reinterpret_cast<WKResourceCacheManagerRef>(WKContextGetWebsiteDataStore(context)); |
489 | } |
490 | |
491 | void WKContextStartMemorySampler(WKContextRef contextRef, WKDoubleRef interval) |
492 | { |
493 | WebKit::toImpl(contextRef)->startMemorySampler(WebKit::toImpl(interval)->value()); |
494 | } |
495 | |
496 | void WKContextStopMemorySampler(WKContextRef contextRef) |
497 | { |
498 | WebKit::toImpl(contextRef)->stopMemorySampler(); |
499 | } |
500 | |
501 | void WKContextSetIconDatabasePath(WKContextRef, WKStringRef) |
502 | { |
503 | } |
504 | |
505 | void WKContextAllowSpecificHTTPSCertificateForHost(WKContextRef contextRef, WKCertificateInfoRef certificateRef, WKStringRef hostRef) |
506 | { |
507 | WebKit::toImpl(contextRef)->allowSpecificHTTPSCertificateForHost(WebKit::toImpl(certificateRef), WebKit::toImpl(hostRef)->string()); |
508 | } |
509 | |
510 | void WKContextDisableProcessTermination(WKContextRef contextRef) |
511 | { |
512 | WebKit::toImpl(contextRef)->disableProcessTermination(); |
513 | } |
514 | |
515 | void WKContextEnableProcessTermination(WKContextRef contextRef) |
516 | { |
517 | WebKit::toImpl(contextRef)->enableProcessTermination(); |
518 | } |
519 | |
520 | void WKContextSetHTTPPipeliningEnabled(WKContextRef contextRef, bool enabled) |
521 | { |
522 | WebKit::toImpl(contextRef)->setHTTPPipeliningEnabled(enabled); |
523 | } |
524 | |
525 | void WKContextWarmInitialProcess(WKContextRef contextRef) |
526 | { |
527 | WebKit::toImpl(contextRef)->prewarmProcess(); |
528 | } |
529 | |
530 | void WKContextGetStatistics(WKContextRef contextRef, void* context, WKContextGetStatisticsFunction callback) |
531 | { |
532 | WebKit::toImpl(contextRef)->getStatistics(0xFFFFFFFF, WebKit::toGenericCallbackFunction(context, callback)); |
533 | } |
534 | |
535 | void WKContextGetStatisticsWithOptions(WKContextRef contextRef, WKStatisticsOptions optionsMask, void* context, WKContextGetStatisticsFunction callback) |
536 | { |
537 | WebKit::toImpl(contextRef)->getStatistics(optionsMask, WebKit::toGenericCallbackFunction(context, callback)); |
538 | } |
539 | |
540 | bool WKContextJavaScriptConfigurationFileEnabled(WKContextRef contextRef) |
541 | { |
542 | return WebKit::toImpl(contextRef)->javaScriptConfigurationFileEnabled(); |
543 | } |
544 | |
545 | void WKContextSetJavaScriptConfigurationFileEnabled(WKContextRef contextRef, bool enable) |
546 | { |
547 | WebKit::toImpl(contextRef)->setJavaScriptConfigurationFileEnabled(enable); |
548 | } |
549 | |
550 | void WKContextGarbageCollectJavaScriptObjects(WKContextRef contextRef) |
551 | { |
552 | WebKit::toImpl(contextRef)->garbageCollectJavaScriptObjects(); |
553 | } |
554 | |
555 | void WKContextSetJavaScriptGarbageCollectorTimerEnabled(WKContextRef contextRef, bool enable) |
556 | { |
557 | WebKit::toImpl(contextRef)->setJavaScriptGarbageCollectorTimerEnabled(enable); |
558 | } |
559 | |
560 | void WKContextUseTestingNetworkSession(WKContextRef context) |
561 | { |
562 | WebKit::toImpl(context)->useTestingNetworkSession(); |
563 | } |
564 | |
565 | void WKContextSetAllowsAnySSLCertificateForWebSocketTesting(WKContextRef context, bool allows) |
566 | { |
567 | WebKit::toImpl(context)->setAllowsAnySSLCertificateForWebSocket(allows); |
568 | } |
569 | |
570 | void WKContextSetAllowsAnySSLCertificateForServiceWorkerTesting(WKContextRef context, bool allows) |
571 | { |
572 | #if ENABLE(SERVICE_WORKER) |
573 | WebKit::toImpl(context)->setAllowsAnySSLCertificateForServiceWorker(allows); |
574 | #endif |
575 | } |
576 | |
577 | void WKContextClearCachedCredentials(WKContextRef context) |
578 | { |
579 | WebKit::toImpl(context)->clearCachedCredentials(); |
580 | } |
581 | |
582 | WKDictionaryRef WKContextCopyPlugInAutoStartOriginHashes(WKContextRef contextRef) |
583 | { |
584 | return WebKit::toAPI(&WebKit::toImpl(contextRef)->plugInAutoStartOriginHashes().leakRef()); |
585 | } |
586 | |
587 | void WKContextSetPlugInAutoStartOriginHashes(WKContextRef contextRef, WKDictionaryRef dictionaryRef) |
588 | { |
589 | if (!dictionaryRef) |
590 | return; |
591 | WebKit::toImpl(contextRef)->setPlugInAutoStartOriginHashes(*WebKit::toImpl(dictionaryRef)); |
592 | } |
593 | |
594 | void WKContextSetPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(WKContextRef contextRef, WKDictionaryRef dictionaryRef, double time) |
595 | { |
596 | if (!dictionaryRef) |
597 | return; |
598 | WebKit::toImpl(contextRef)->setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(*WebKit::toImpl(dictionaryRef), WallTime::fromRawSeconds(time)); |
599 | } |
600 | |
601 | void WKContextSetPlugInAutoStartOrigins(WKContextRef contextRef, WKArrayRef arrayRef) |
602 | { |
603 | if (!arrayRef) |
604 | return; |
605 | WebKit::toImpl(contextRef)->setPlugInAutoStartOrigins(*WebKit::toImpl(arrayRef)); |
606 | } |
607 | |
608 | void WKContextSetInvalidMessageFunction(WKContextInvalidMessageFunction invalidMessageFunction) |
609 | { |
610 | WebKit::WebProcessPool::setInvalidMessageCallback(invalidMessageFunction); |
611 | } |
612 | |
613 | void WKContextSetMemoryCacheDisabled(WKContextRef contextRef, bool disabled) |
614 | { |
615 | WebKit::toImpl(contextRef)->setMemoryCacheDisabled(disabled); |
616 | } |
617 | |
618 | void WKContextSetFontWhitelist(WKContextRef contextRef, WKArrayRef arrayRef) |
619 | { |
620 | WebKit::toImpl(contextRef)->setFontWhitelist(WebKit::toImpl(arrayRef)); |
621 | } |
622 | |
623 | void WKContextTerminateNetworkProcess(WKContextRef context) |
624 | { |
625 | WebKit::toImpl(context)->terminateNetworkProcess(); |
626 | } |
627 | |
628 | void WKContextTerminateServiceWorkerProcess(WKContextRef context) |
629 | { |
630 | WebKit::toImpl(context)->terminateServiceWorkerProcesses(); |
631 | } |
632 | |
633 | ProcessID WKContextGetNetworkProcessIdentifier(WKContextRef contextRef) |
634 | { |
635 | return WebKit::toImpl(contextRef)->networkProcessIdentifier(); |
636 | } |
637 | |
638 | void WKContextAddSupportedPlugin(WKContextRef contextRef, WKStringRef domainRef, WKStringRef nameRef, WKArrayRef mimeTypesRef, WKArrayRef extensionsRef) |
639 | { |
640 | #if ENABLE(NETSCAPE_PLUGIN_API) |
641 | HashSet<String> mimeTypes; |
642 | HashSet<String> extensions; |
643 | |
644 | size_t count = WKArrayGetSize(mimeTypesRef); |
645 | for (size_t i = 0; i < count; ++i) |
646 | mimeTypes.add(WebKit::toWTFString(static_cast<WKStringRef>(WKArrayGetItemAtIndex(mimeTypesRef, i)))); |
647 | count = WKArrayGetSize(extensionsRef); |
648 | for (size_t i = 0; i < count; ++i) |
649 | extensions.add(WebKit::toWTFString(static_cast<WKStringRef>(WKArrayGetItemAtIndex(extensionsRef, i)))); |
650 | |
651 | WebKit::toImpl(contextRef)->addSupportedPlugin(WebKit::toWTFString(domainRef), WebKit::toWTFString(nameRef), WTFMove(mimeTypes), WTFMove(extensions)); |
652 | #endif |
653 | } |
654 | |
655 | void WKContextClearSupportedPlugins(WKContextRef contextRef) |
656 | { |
657 | #if ENABLE(NETSCAPE_PLUGIN_API) |
658 | WebKit::toImpl(contextRef)->clearSupportedPlugins(); |
659 | #endif |
660 | } |
661 | |
662 | void WKContextSetIDBPerOriginQuota(WKContextRef contextRef, uint64_t quota) |
663 | { |
664 | WebKit::toImpl(contextRef)->setIDBPerOriginQuota(quota); |
665 | } |
666 | |
667 | void WKContextClearCurrentModifierStateForTesting(WKContextRef contextRef) |
668 | { |
669 | WebKit::toImpl(contextRef)->clearCurrentModifierStateForTesting(); |
670 | } |
671 | |