source: webkit/trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm@ 286777

Last change on this file since 286777 was 286777, checked in by commit-queue@webkit.org, 3 years ago

Unreviewed, reverting r286764.
https://bugs.webkit.org/show_bug.cgi?id=234081

broke the build

Reverted changeset:

"Add ability to inject messages into webpushd"
https://bugs.webkit.org/show_bug.cgi?id=233988
https://commits.webkit.org/r286764

File size: 27.1 KB
Line 
1/*
2 * Copyright (C) 2014-2019 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 "config.h"
27#import "WKWebsiteDataStoreInternal.h"
28
29#import "APIString.h"
30#import "AuthenticationChallengeDispositionCocoa.h"
31#import "CompletionHandlerCallChecker.h"
32#import "NetworkProcessProxy.h"
33#import "ShouldGrandfatherStatistics.h"
34#import "WKError.h"
35#import "WKHTTPCookieStoreInternal.h"
36#import "WKNSArray.h"
37#import "WKNSURLAuthenticationChallenge.h"
38#import "WKSecurityOriginInternal.h"
39#import "WKWebViewInternal.h"
40#import "WKWebsiteDataRecordInternal.h"
41#import "WebPageProxy.h"
42#import "WebResourceLoadStatisticsStore.h"
43#import "WebsiteDataFetchOption.h"
44#import "_WKResourceLoadStatisticsThirdPartyInternal.h"
45#import "_WKWebsiteDataStoreConfigurationInternal.h"
46#import "_WKWebsiteDataStoreDelegate.h"
47#import <WebCore/Credential.h>
48#import <WebCore/RegistrationDatabase.h>
49#import <WebCore/VersionChecks.h>
50#import <WebCore/WebCoreObjCExtras.h>
51#import <wtf/BlockPtr.h>
52#import <wtf/URL.h>
53#import <wtf/WeakObjCPtr.h>
54
55class WebsiteDataStoreClient final : public WebKit::WebsiteDataStoreClient {
56public:
57 explicit WebsiteDataStoreClient(id <_WKWebsiteDataStoreDelegate> delegate)
58 : m_delegate(delegate)
59 , m_hasRequestStorageSpaceSelector([m_delegate.get() respondsToSelector:@selector(requestStorageSpace: frameOrigin: quota: currentSize: spaceRequired: decisionHandler:)])
60 , m_hasAuthenticationChallengeSelector([m_delegate.get() respondsToSelector:@selector(didReceiveAuthenticationChallenge: completionHandler:)])
61 {
62 }
63
64private:
65 void requestStorageSpace(const WebCore::SecurityOriginData& topOrigin, const WebCore::SecurityOriginData& frameOrigin, uint64_t quota, uint64_t currentSize, uint64_t spaceRequired, CompletionHandler<void(std::optional<uint64_t>)>&& completionHandler) final
66 {
67 if (!m_hasRequestStorageSpaceSelector || !m_delegate) {
68 completionHandler({ });
69 return;
70 }
71
72 auto checker = WebKit::CompletionHandlerCallChecker::create(m_delegate.getAutoreleased(), @selector(requestStorageSpace: frameOrigin: quota: currentSize: spaceRequired: decisionHandler:));
73 auto decisionHandler = makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)](unsigned long long quota) mutable {
74 if (checker->completionHandlerHasBeenCalled())
75 return;
76 checker->didCallCompletionHandler();
77 completionHandler(quota);
78 });
79
80 URL mainFrameURL { URL(), topOrigin.toString() };
81 URL frameURL { URL(), frameOrigin.toString() };
82
83 [m_delegate.getAutoreleased() requestStorageSpace:mainFrameURL frameOrigin:frameURL quota:quota currentSize:currentSize spaceRequired:spaceRequired decisionHandler:decisionHandler.get()];
84 }
85
86 void didReceiveAuthenticationChallenge(Ref<WebKit::AuthenticationChallengeProxy>&& challenge) final
87 {
88 if (!m_hasAuthenticationChallengeSelector || !m_delegate) {
89 challenge->listener().completeChallenge(WebKit::AuthenticationChallengeDisposition::PerformDefaultHandling);
90 return;
91 }
92
93 auto nsURLChallenge = wrapper(challenge);
94 auto checker = WebKit::CompletionHandlerCallChecker::create(m_delegate.getAutoreleased(), @selector(didReceiveAuthenticationChallenge: completionHandler:));
95 auto completionHandler = makeBlockPtr([challenge = WTFMove(challenge), checker = WTFMove(checker)](NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential) mutable {
96 if (checker->completionHandlerHasBeenCalled())
97 return;
98 checker->didCallCompletionHandler();
99 challenge->listener().completeChallenge(WebKit::toAuthenticationChallengeDisposition(disposition), WebCore::Credential(credential));
100 });
101
102 [m_delegate.getAutoreleased() didReceiveAuthenticationChallenge:nsURLChallenge completionHandler:completionHandler.get()];
103 }
104
105 WeakObjCPtr<id <_WKWebsiteDataStoreDelegate> > m_delegate;
106 bool m_hasRequestStorageSpaceSelector { false };
107 bool m_hasAuthenticationChallengeSelector { false };
108};
109
110@implementation WKWebsiteDataStore
111
112+ (WKWebsiteDataStore *)defaultDataStore
113{
114 return wrapper(WebKit::WebsiteDataStore::defaultDataStore());
115}
116
117+ (WKWebsiteDataStore *)nonPersistentDataStore
118{
119 return wrapper(WebKit::WebsiteDataStore::createNonPersistent());
120}
121
122- (instancetype)init
123{
124 if (WebCore::linkedOnOrAfter(WebCore::SDKVersion::FirstWithWKWebsiteDataStoreInitReturningNil))
125 [NSException raise:NSGenericException format:@"Calling [WKWebsiteDataStore init] is not supported."];
126
127 if (!(self = [super init]))
128 return nil;
129
130 RELEASE_LOG_ERROR(Storage, "Application is calling [WKWebsiteDataStore init], which is not supported");
131 API::Object::constructInWrapper<WebKit::WebsiteDataStore>(self, WebKit::WebsiteDataStoreConfiguration::create(WebKit::IsPersistent::No), PAL::SessionID::generateEphemeralSessionID());
132
133 return self;
134}
135
136- (void)dealloc
137{
138 if (WebCoreObjCScheduleDeallocateOnMainRunLoop(WKWebsiteDataStore.class, self))
139 return;
140
141 _websiteDataStore->WebKit::WebsiteDataStore::~WebsiteDataStore();
142
143 [super dealloc];
144}
145
146+ (BOOL)supportsSecureCoding
147{
148 return YES;
149}
150
151- (instancetype)initWithCoder:(NSCoder *)coder
152{
153 if ([coder decodeBoolForKey:@"isDefaultDataStore"])
154 return [[WKWebsiteDataStore defaultDataStore] retain];
155 return [[WKWebsiteDataStore nonPersistentDataStore] retain];
156}
157
158- (void)encodeWithCoder:(NSCoder *)coder
159{
160 if (self == [WKWebsiteDataStore defaultDataStore]) {
161 [coder encodeBool:YES forKey:@"isDefaultDataStore"];
162 return;
163 }
164
165 ASSERT(!self.persistent);
166}
167
168- (BOOL)isPersistent
169{
170 return _websiteDataStore->isPersistent();
171}
172
173+ (NSSet *)allWebsiteDataTypes
174{
175 static dispatch_once_t onceToken;
176 static NeverDestroyed<RetainPtr<NSSet>> allWebsiteDataTypes;
177 dispatch_once(&onceToken, ^{
178 allWebsiteDataTypes.get() = adoptNS([[NSSet alloc] initWithArray:@[ WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeFetchCache, WKWebsiteDataTypeMemoryCache, WKWebsiteDataTypeOfflineWebApplicationCache, WKWebsiteDataTypeCookies, WKWebsiteDataTypeSessionStorage, WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, WKWebsiteDataTypeServiceWorkerRegistrations, WKWebsiteDataTypeWebSQLDatabases ]]);
179 });
180
181 return allWebsiteDataTypes.get().get();
182}
183
184- (WKHTTPCookieStore *)httpCookieStore
185{
186 return wrapper(_websiteDataStore->cookieStore());
187}
188
189static WallTime toSystemClockTime(NSDate *date)
190{
191 ASSERT(date);
192 return WallTime::fromRawSeconds(date.timeIntervalSince1970);
193}
194
195- (void)fetchDataRecordsOfTypes:(NSSet *)dataTypes completionHandler:(void (^)(NSArray<WKWebsiteDataRecord *> *))completionHandler
196{
197 [self _fetchDataRecordsOfTypes:dataTypes withOptions:0 completionHandler:completionHandler];
198}
199
200- (void)removeDataOfTypes:(NSSet *)dataTypes modifiedSince:(NSDate *)date completionHandler:(void (^)(void))completionHandler
201{
202 auto completionHandlerCopy = makeBlockPtr(completionHandler);
203 _websiteDataStore->removeData(WebKit::toWebsiteDataTypes(dataTypes), toSystemClockTime(date ? date : [NSDate distantPast]), [completionHandlerCopy] {
204 completionHandlerCopy();
205 });
206}
207
208static Vector<WebKit::WebsiteDataRecord> toWebsiteDataRecords(NSArray *dataRecords)
209{
210 Vector<WebKit::WebsiteDataRecord> result;
211
212 for (WKWebsiteDataRecord *dataRecord in dataRecords)
213 result.append(dataRecord->_websiteDataRecord->websiteDataRecord());
214
215 return result;
216}
217
218- (void)removeDataOfTypes:(NSSet *)dataTypes forDataRecords:(NSArray *)dataRecords completionHandler:(void (^)(void))completionHandler
219{
220 auto completionHandlerCopy = makeBlockPtr(completionHandler);
221
222 _websiteDataStore->removeData(WebKit::toWebsiteDataTypes(dataTypes), toWebsiteDataRecords(dataRecords), [completionHandlerCopy] {
223 completionHandlerCopy();
224 });
225}
226
227#pragma mark WKObject protocol implementation
228
229- (API::Object&)_apiObject
230{
231 return *_websiteDataStore;
232}
233
234@end
235
236@implementation WKWebsiteDataStore (WKPrivate)
237
238+ (NSSet<NSString *> *)_allWebsiteDataTypesIncludingPrivate
239{
240 static dispatch_once_t onceToken;
241 static NeverDestroyed<RetainPtr<NSSet>> allWebsiteDataTypes;
242 dispatch_once(&onceToken, ^ {
243 auto *privateTypes = @[
244 _WKWebsiteDataTypeHSTSCache,
245 _WKWebsiteDataTypeMediaKeys,
246 _WKWebsiteDataTypeSearchFieldRecentSearches,
247 _WKWebsiteDataTypeResourceLoadStatistics,
248 _WKWebsiteDataTypeCredentials,
249 _WKWebsiteDataTypeAdClickAttributions,
250 _WKWebsiteDataTypePrivateClickMeasurements,
251 _WKWebsiteDataTypeAlternativeServices,
252 _WKWebsiteDataTypeFileSystem
253#if !TARGET_OS_IPHONE
254 , _WKWebsiteDataTypePlugInData
255#endif
256 ];
257
258 allWebsiteDataTypes.get() = [[self allWebsiteDataTypes] setByAddingObjectsFromArray:privateTypes];
259 });
260
261 return allWebsiteDataTypes.get().get();
262}
263
264+ (BOOL)_defaultDataStoreExists
265{
266 return WebKit::WebsiteDataStore::defaultDataStoreExists();
267}
268
269+ (void)_deleteDefaultDataStoreForTesting
270{
271 return WebKit::WebsiteDataStore::deleteDefaultDataStoreForTesting();
272}
273
274- (instancetype)_initWithConfiguration:(_WKWebsiteDataStoreConfiguration *)configuration
275{
276 if (!(self = [super init]))
277 return nil;
278
279 auto sessionID = configuration.isPersistent ? PAL::SessionID::generatePersistentSessionID() : PAL::SessionID::generateEphemeralSessionID();
280 API::Object::constructInWrapper<WebKit::WebsiteDataStore>(self, configuration->_configuration->copy(), sessionID);
281
282 return self;
283}
284
285- (void)_fetchDataRecordsOfTypes:(NSSet<NSString *> *)dataTypes withOptions:(_WKWebsiteDataStoreFetchOptions)options completionHandler:(void (^)(NSArray<WKWebsiteDataRecord *> *))completionHandler
286{
287 auto completionHandlerCopy = makeBlockPtr(completionHandler);
288
289 OptionSet<WebKit::WebsiteDataFetchOption> fetchOptions;
290 if (options & _WKWebsiteDataStoreFetchOptionComputeSizes)
291 fetchOptions.add(WebKit::WebsiteDataFetchOption::ComputeSizes);
292
293 _websiteDataStore->fetchData(WebKit::toWebsiteDataTypes(dataTypes), fetchOptions, [completionHandlerCopy = WTFMove(completionHandlerCopy)](auto websiteDataRecords) {
294 Vector<RefPtr<API::Object>> elements;
295 elements.reserveInitialCapacity(websiteDataRecords.size());
296
297 for (auto& websiteDataRecord : websiteDataRecords)
298 elements.uncheckedAppend(API::WebsiteDataRecord::create(WTFMove(websiteDataRecord)));
299
300 completionHandlerCopy(wrapper(API::Array::create(WTFMove(elements))));
301 });
302}
303
304- (BOOL)_resourceLoadStatisticsEnabled
305{
306 return _websiteDataStore->resourceLoadStatisticsEnabled();
307}
308
309- (void)_setResourceLoadStatisticsEnabled:(BOOL)enabled
310{
311 _websiteDataStore->useExplicitITPState();
312 _websiteDataStore->setResourceLoadStatisticsEnabled(enabled);
313}
314
315- (BOOL)_resourceLoadStatisticsDebugMode
316{
317#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
318 return _websiteDataStore->resourceLoadStatisticsDebugMode();
319#else
320 return NO;
321#endif
322}
323
324- (void)_setResourceLoadStatisticsDebugMode:(BOOL)enabled
325{
326#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
327 _websiteDataStore->setResourceLoadStatisticsDebugMode(enabled);
328#else
329 UNUSED_PARAM(enabled);
330#endif
331}
332
333- (NSUInteger)_perOriginStorageQuota
334{
335 return 0;
336}
337
338- (void)_setPerOriginStorageQuota:(NSUInteger)size
339{
340}
341
342- (void)_setBoundInterfaceIdentifier:(NSString *)identifier
343{
344}
345
346- (NSString *)_boundInterfaceIdentifier
347{
348 return nil;
349}
350
351- (void)_setAllowsCellularAccess:(BOOL)allows
352{
353}
354
355- (BOOL)_allowsCellularAccess
356{
357 return YES;
358}
359
360- (void)_setProxyConfiguration:(NSDictionary *)configuration
361{
362}
363
364- (void)_setAllowsTLSFallback:(BOOL)allows
365{
366}
367
368- (BOOL)_allowsTLSFallback
369{
370 return NO;
371}
372
373- (NSDictionary *)_proxyConfiguration
374{
375 return nil;
376}
377
378- (NSURL *)_indexedDBDatabaseDirectory
379{
380 return [NSURL fileURLWithPath:_websiteDataStore->configuration().indexedDBDatabaseDirectory() isDirectory:YES];
381}
382
383- (void)_setResourceLoadStatisticsTestingCallback:(void (^)(WKWebsiteDataStore *, NSString *))callback
384{
385#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
386 if (!_websiteDataStore->isPersistent())
387 return;
388
389 if (callback) {
390 _websiteDataStore->setStatisticsTestingCallback([callback = makeBlockPtr(callback), self](const String& event) {
391 callback(self, event);
392 });
393 return;
394 }
395
396 _websiteDataStore->setStatisticsTestingCallback(nullptr);
397#endif
398}
399
400+ (void)_allowWebsiteDataRecordsForAllOrigins
401{
402 WebKit::WebsiteDataStore::allowWebsiteDataRecordsForAllOrigins();
403}
404
405- (void)_loadedSubresourceDomainsFor:(WKWebView *)webView completionHandler:(void (^)(NSArray<NSString *> *domains))completionHandler
406{
407#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
408 if (!webView) {
409 completionHandler(nil);
410 return;
411 }
412
413 auto webPageProxy = [webView _page];
414 if (!webPageProxy) {
415 completionHandler(nil);
416 return;
417 }
418
419 webPageProxy->getLoadedSubresourceDomains([completionHandler = makeBlockPtr(completionHandler)] (Vector<WebCore::RegistrableDomain>&& loadedSubresourceDomains) {
420 Vector<RefPtr<API::Object>> apiDomains = WTF::map(loadedSubresourceDomains, [](auto& domain) {
421 return RefPtr<API::Object>(API::String::create(WTFMove(domain.string())));
422 });
423 completionHandler(wrapper(API::Array::create(WTFMove(apiDomains))));
424 });
425#else
426 completionHandler(nil);
427#endif
428}
429
430- (void)_clearLoadedSubresourceDomainsFor:(WKWebView *)webView
431{
432#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
433 if (!webView)
434 return;
435
436 auto webPageProxy = [webView _page];
437 if (!webPageProxy)
438 return;
439
440 webPageProxy->clearLoadedSubresourceDomains();
441#endif
442}
443
444
445- (void)_getAllStorageAccessEntriesFor:(WKWebView *)webView completionHandler:(void (^)(NSArray<NSString *> *domains))completionHandler
446{
447 if (!webView) {
448 completionHandler({ });
449 return;
450 }
451
452 auto webPageProxy = [webView _page];
453 if (!webPageProxy) {
454 completionHandler({ });
455 return;
456 }
457
458#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
459 _websiteDataStore->getAllStorageAccessEntries(webPageProxy->identifier(), [completionHandler = makeBlockPtr(completionHandler)](auto domains) {
460 Vector<RefPtr<API::Object>> apiDomains;
461 apiDomains.reserveInitialCapacity(domains.size());
462 for (auto& domain : domains)
463 apiDomains.uncheckedAppend(API::String::create(domain));
464 completionHandler(wrapper(API::Array::create(WTFMove(apiDomains))));
465 });
466#else
467 completionHandler({ });
468#endif
469}
470
471- (void)_scheduleCookieBlockingUpdate:(void (^)(void))completionHandler
472{
473#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
474 _websiteDataStore->scheduleCookieBlockingUpdate([completionHandler = makeBlockPtr(completionHandler)]() {
475 completionHandler();
476 });
477#else
478 completionHandler();
479#endif
480}
481
482- (void)_logUserInteraction:(NSURL *)domain completionHandler:(void (^)(void))completionHandler
483{
484#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
485 _websiteDataStore->logUserInteraction(domain, [completionHandler = makeBlockPtr(completionHandler)] {
486 completionHandler();
487 });
488#else
489 completionHandler();
490#endif
491}
492
493- (void)_setPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler
494{
495#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
496 _websiteDataStore->setPrevalentResource(URL(domain), [completionHandler = makeBlockPtr(completionHandler)]() {
497 completionHandler();
498 });
499#else
500 completionHandler();
501#endif
502}
503
504- (void)_getIsPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(BOOL))completionHandler
505{
506#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
507 _websiteDataStore->isPrevalentResource(URL(domain), [completionHandler = makeBlockPtr(completionHandler)](bool enabled) {
508 completionHandler(enabled);
509 });
510#else
511 completionHandler(NO);
512#endif
513}
514
515- (void)_clearPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler
516{
517#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
518 _websiteDataStore->clearPrevalentResource(URL(domain), [completionHandler = makeBlockPtr(completionHandler)]() {
519 completionHandler();
520 });
521#else
522 completionHandler();
523#endif
524}
525
526- (void)_clearResourceLoadStatistics:(void (^)(void))completionHandler
527{
528#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
529 _websiteDataStore->scheduleClearInMemoryAndPersistent(WebKit::ShouldGrandfatherStatistics::No, [completionHandler = makeBlockPtr(completionHandler)]() {
530 completionHandler();
531 });
532#else
533 completionHandler();
534#endif
535}
536
537- (void)_getResourceLoadStatisticsDataSummary:(void (^)(NSArray<_WKResourceLoadStatisticsThirdParty *> *))completionHandler
538{
539#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
540 _websiteDataStore->getResourceLoadStatisticsDataSummary([completionHandler = makeBlockPtr(completionHandler)] (auto&& thirdPartyDomains) {
541 completionHandler(createNSArray(thirdPartyDomains, [] (auto&& domain) {
542 return wrapper(API::ResourceLoadStatisticsThirdParty::create(WTFMove(domain)));
543 }).get());
544 });
545#else
546 completionHandler(nil);
547#endif
548}
549
550+ (void)_setCachedProcessSuspensionDelayForTesting:(double)delayInSeconds
551{
552 WebKit::WebsiteDataStore::setCachedProcessSuspensionDelayForTesting(Seconds(delayInSeconds));
553}
554
555- (void)_isRelationshipOnlyInDatabaseOnce:(NSURL *)firstPartyURL thirdParty:(NSURL *)thirdPartyURL completionHandler:(void (^)(BOOL))completionHandler
556{
557#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
558 _websiteDataStore->isRelationshipOnlyInDatabaseOnce(thirdPartyURL, firstPartyURL, [completionHandler = makeBlockPtr(completionHandler)] (bool result) {
559 completionHandler(result);
560 });
561#else
562 completionHandler(NO);
563#endif
564}
565
566- (void)_isRegisteredAsSubresourceUnderFirstParty:(NSURL *)firstPartyURL thirdParty:(NSURL *)thirdPartyURL completionHandler:(void (^)(BOOL))completionHandler
567{
568#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
569 _websiteDataStore->isRegisteredAsSubresourceUnder(thirdPartyURL, firstPartyURL, [completionHandler = makeBlockPtr(completionHandler)](bool enabled) {
570 completionHandler(enabled);
571 });
572#else
573 completionHandler(NO);
574#endif
575}
576
577- (void)_statisticsDatabaseHasAllTables:(void (^)(BOOL))completionHandler
578{
579#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
580 _websiteDataStore->statisticsDatabaseHasAllTables([completionHandler = makeBlockPtr(completionHandler)](bool hasAllTables) {
581 completionHandler(hasAllTables);
582 });
583#else
584 completionHandler(NO);
585#endif
586}
587
588- (void)_processStatisticsAndDataRecords:(void (^)(void))completionHandler
589{
590#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
591 _websiteDataStore->scheduleStatisticsAndDataRecordsProcessing([completionHandler = makeBlockPtr(completionHandler)]() {
592 completionHandler();
593 });
594#else
595 completionHandler();
596#endif
597}
598
599- (void)_setThirdPartyCookieBlockingMode:(BOOL)enabled onlyOnSitesWithoutUserInteraction:(BOOL)onlyOnSitesWithoutUserInteraction completionHandler:(void (^)(void))completionHandler
600{
601#if ENABLE(INTELLIGENT_TRACKING_PREVENTION)
602 _websiteDataStore->setResourceLoadStatisticsShouldBlockThirdPartyCookiesForTesting(enabled, onlyOnSitesWithoutUserInteraction, [completionHandler = makeBlockPtr(completionHandler)]() {
603 completionHandler();
604 });
605#else
606 completionHandler();
607#endif
608}
609
610- (bool)_hasRegisteredServiceWorker
611{
612#if ENABLE(SERVICE_WORKER)
613 return FileSystem::fileExists(WebCore::serviceWorkerRegistrationDatabaseFilename(_websiteDataStore->configuration().serviceWorkerRegistrationDirectory()));
614#else
615 return NO;
616#endif
617}
618
619- (void)_renameOrigin:(NSURL *)oldName to:(NSURL *)newName forDataOfTypes:(NSSet<NSString *> *)dataTypes completionHandler:(void (^)(void))completionHandler
620{
621 if (!dataTypes.count)
622 return completionHandler();
623
624 NSSet *supportedTypes = [NSSet setWithObjects:WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, nil];
625 if (![dataTypes isSubsetOfSet:supportedTypes])
626 [NSException raise:NSInvalidArgumentException format:@"_renameOrigin can only be called with WKWebsiteDataTypeLocalStorage and WKWebsiteDataTypeIndexedDBDatabases right now."];
627
628 _websiteDataStore->renameOriginInWebsiteData(oldName, newName, WebKit::toWebsiteDataTypes(dataTypes), [completionHandler = makeBlockPtr(completionHandler)] {
629 completionHandler();
630 });
631}
632
633- (BOOL)_networkProcessHasEntitlementForTesting:(NSString *)entitlement
634{
635 return _websiteDataStore->networkProcessHasEntitlementForTesting(entitlement);
636}
637
638- (id <_WKWebsiteDataStoreDelegate>)_delegate
639{
640 return _delegate.get().get();
641}
642
643- (void)set_delegate:(id <_WKWebsiteDataStoreDelegate>)delegate
644{
645 _delegate = delegate;
646 _websiteDataStore->setClient(makeUniqueRef<WebsiteDataStoreClient>(delegate));
647}
648
649- (_WKWebsiteDataStoreConfiguration *)_configuration
650{
651 return wrapper(_websiteDataStore->configuration().copy());
652}
653
654- (void)_allowTLSCertificateChain:(NSArray *)certificateChain forHost:(NSString *)host
655{
656 _websiteDataStore->allowSpecificHTTPSCertificateForHost(WebCore::CertificateInfo((__bridge CFArrayRef)certificateChain), host);
657}
658
659- (void)_trustServerForLocalPCMTesting:(SecTrustRef)serverTrust
660{
661 _websiteDataStore->allowTLSCertificateChainForLocalPCMTesting(WebCore::CertificateInfo(serverTrust));
662}
663
664- (void)_setPrivateClickMeasurementDebugModeEnabledForTesting:(BOOL)enabled
665{
666 _websiteDataStore->setPrivateClickMeasurementDebugMode(enabled);
667}
668
669- (void)_appBoundDomains:(void (^)(NSArray<NSString *> *))completionHandler
670{
671#if ENABLE(APP_BOUND_DOMAINS)
672 _websiteDataStore->getAppBoundDomains([completionHandler = makeBlockPtr(completionHandler)](auto& domains) mutable {
673 Vector<RefPtr<API::Object>> apiDomains;
674 apiDomains.reserveInitialCapacity(domains.size());
675 for (auto& domain : domains)
676 apiDomains.uncheckedAppend(API::String::create(domain.string()));
677 completionHandler(wrapper(API::Array::create(WTFMove(apiDomains))));
678 });
679#else
680 completionHandler({ });
681#endif
682}
683
684- (void)_appBoundSchemes:(void (^)(NSArray<NSString *> *))completionHandler
685{
686#if ENABLE(APP_BOUND_DOMAINS)
687 _websiteDataStore->getAppBoundSchemes([completionHandler = makeBlockPtr(completionHandler)](auto& schemes) mutable {
688 Vector<RefPtr<API::Object>> apiSchemes;
689 apiSchemes.reserveInitialCapacity(schemes.size());
690 for (auto& scheme : schemes)
691 apiSchemes.uncheckedAppend(API::String::create(scheme));
692 completionHandler(wrapper(API::Array::create(WTFMove(apiSchemes))));
693 });
694#else
695 completionHandler({ });
696#endif
697}
698
699- (void)_terminateNetworkProcess
700{
701 _websiteDataStore->terminateNetworkProcess();
702}
703
704- (void)_sendNetworkProcessPrepareToSuspend:(void(^)(void))completionHandler
705{
706 _websiteDataStore->sendNetworkProcessPrepareToSuspendForTesting([completionHandler = makeBlockPtr(completionHandler)] {
707 completionHandler();
708 });
709}
710
711- (void)_sendNetworkProcessWillSuspendImminently
712{
713 _websiteDataStore->sendNetworkProcessWillSuspendImminentlyForTesting();
714
715}
716
717- (void)_sendNetworkProcessDidResume
718{
719 _websiteDataStore->sendNetworkProcessDidResume();
720}
721
722- (void)_synthesizeAppIsBackground:(BOOL)background
723{
724 _websiteDataStore->networkProcess().synthesizeAppIsBackground(background);
725}
726
727- (pid_t)_networkProcessIdentifier
728{
729 return _websiteDataStore->networkProcess().processIdentifier();
730}
731
732+ (void)_makeNextNetworkProcessLaunchFailForTesting
733{
734 WebKit::WebsiteDataStore::makeNextNetworkProcessLaunchFailForTesting();
735}
736
737+ (void)_setNetworkProcessSuspensionAllowedForTesting:(BOOL)allowed
738{
739 WebKit::NetworkProcessProxy::setSuspensionAllowedForTesting(allowed);
740}
741
742- (BOOL)_networkProcessExists
743{
744 return !!_websiteDataStore->networkProcessIfExists();
745}
746
747+ (BOOL)_defaultNetworkProcessExists
748{
749 return !!WebKit::NetworkProcessProxy::defaultNetworkProcess();
750}
751
752- (void)_countNonDefaultSessionSets:(void(^)(size_t))completionHandler
753{
754 _websiteDataStore->countNonDefaultSessionSets([completionHandler = makeBlockPtr(completionHandler)] (size_t count) {
755 completionHandler(count);
756 });
757}
758
759-(bool)_hasServiceWorkerBackgroundActivityForTesting
760{
761 return _websiteDataStore->hasServiceWorkerBackgroundActivityForTesting();
762}
763
764-(void)_processPushMessage:(NSData*) message registration:(NSURL *)registration completionHandler:(void(^)(bool wasProcessed))completionHandler
765{
766#if ENABLE(SERVICE_WORKER)
767 std::optional<Span<const uint8_t>> data;
768 if (message)
769 data = Span<const uint8_t> { reinterpret_cast<const uint8_t*>(message.bytes), message.length };
770 _websiteDataStore->networkProcess().processPushMessage(_websiteDataStore->sessionID(), data, registration, [completionHandler = makeBlockPtr(completionHandler)] (bool wasProcessed) {
771 completionHandler(wasProcessed);
772 });
773#endif
774}
775
776-(void)_deletePushAndNotificationRegistration:(WKSecurityOrigin *)securityOrigin completionHandler:(void(^)(NSError *))completionHandler
777{
778 auto completionHandlerCopy = makeBlockPtr(completionHandler);
779 _websiteDataStore->networkProcess().deletePushAndNotificationRegistration(_websiteDataStore->sessionID(), securityOrigin->_securityOrigin->securityOrigin(), [completionHandlerCopy](const String& errorString) {
780 if (errorString.isEmpty()) {
781 completionHandlerCopy(nil);
782 return;
783 }
784 completionHandlerCopy([NSError errorWithDomain:@"WKWebSiteDataStore" code:WKErrorUnknown userInfo:@{ NSLocalizedDescriptionKey:(NSString *)errorString }]);
785 });
786}
787
788-(void)_getOriginsWithPushAndNotificationPermissions:(void(^)(NSSet<WKSecurityOrigin *> *))completionHandler
789{
790 auto completionHandlerCopy = makeBlockPtr(completionHandler);
791 _websiteDataStore->networkProcess().getOriginsWithPushAndNotificationPermissions(_websiteDataStore->sessionID(), [completionHandlerCopy](const Vector<WebCore::SecurityOriginData>& origins) {
792 auto set = adoptNS([[NSMutableSet alloc] initWithCapacity:origins.size()]);
793 for (auto& origin : origins) {
794 auto apiOrigin = API::SecurityOrigin::create(origin);
795 [set addObject:wrapper(apiOrigin.get())];
796 }
797 completionHandlerCopy(set.get());
798 });
799}
800
801@end
Note: See TracBrowser for help on using the repository browser.