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