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