Remove allowBlockSelection as block selection is not supported anymore
[WebKit-https.git] / Source / WebKit / UIProcess / API / Cocoa / WKWebViewConfiguration.mm
1 /*
2  * Copyright (C) 2014-2016 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 "WKWebViewConfigurationInternal.h"
28
29 #if WK_API_ENABLED
30
31 #import "APIPageConfiguration.h"
32 #import "VersionChecks.h"
33 #import "WKPreferences.h"
34 #import "WKProcessPool.h"
35 #import "WKUserContentController.h"
36 #import "WKWebView.h"
37 #import "WKWebViewContentProviderRegistry.h"
38 #import "WeakObjCPtr.h"
39 #import "WebKit2Initialize.h"
40 #import "_WKVisitedLinkStore.h"
41 #import "_WKWebsiteDataStoreInternal.h"
42 #import <WebCore/RuntimeApplicationChecks.h>
43 #import <WebCore/Settings.h>
44 #import <WebCore/URLParser.h>
45 #import <wtf/RetainPtr.h>
46
47 #if PLATFORM(IOS)
48 #import "UIKitSPI.h"
49 #import <WebCore/Device.h>
50 #endif
51
52 using namespace WebCore;
53
54 template<typename T> class LazyInitialized {
55 public:
56     typedef typename WTF::GetPtrHelper<T>::PtrType PtrType;
57
58     template<typename F>
59     PtrType get(F&& f)
60     {
61         if (!m_isInitialized) {
62             m_value = f();
63             m_isInitialized = true;
64         }
65
66         return m_value.get();
67     }
68
69     void set(PtrType t)
70     {
71         m_value = t;
72         m_isInitialized = true;
73     }
74
75     void set(T&& t)
76     {
77         m_value = WTFMove(t);
78         m_isInitialized = true;
79     }
80
81     PtrType peek()
82     {
83         return m_value.get();
84     }
85
86 private:
87     bool m_isInitialized = false;
88     T m_value;
89 };
90
91 #if PLATFORM(IOS)
92
93 static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
94 {
95     if (value == _WKDragLiftDelayMedium)
96         return _WKDragLiftDelayMedium;
97     if (value == _WKDragLiftDelayLong)
98         return _WKDragLiftDelayLong;
99     return _WKDragLiftDelayShort;
100 }
101
102 #endif
103
104 @implementation WKWebViewConfiguration {
105     LazyInitialized<RetainPtr<WKProcessPool>> _processPool;
106     LazyInitialized<RetainPtr<WKPreferences>> _preferences;
107     LazyInitialized<RetainPtr<WKUserContentController>> _userContentController;
108     LazyInitialized<RetainPtr<_WKVisitedLinkStore>> _visitedLinkStore;
109     LazyInitialized<RetainPtr<WKWebsiteDataStore>> _websiteDataStore;
110     WebKit::WeakObjCPtr<WKWebView> _relatedWebView;
111     WebKit::WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures;
112     RetainPtr<NSString> _groupIdentifier;
113     LazyInitialized<RetainPtr<NSString>> _applicationNameForUserAgent;
114     LazyInitialized<RetainPtr<NSMutableDictionary<NSString *, id <WKURLSchemeHandler>>>> _urlSchemeHandlers;
115     NSTimeInterval _incrementalRenderingSuppressionTimeout;
116     BOOL _treatsSHA1SignedCertificatesAsInsecure;
117     BOOL _respectsImageOrientation;
118     BOOL _printsBackgrounds;
119     BOOL _allowsJavaScriptMarkup;
120     BOOL _convertsPositionStyleOnCopy;
121     BOOL _allowsMetaRefresh;
122     BOOL _allowUniversalAccessFromFileURLs;
123
124 #if PLATFORM(IOS)
125     LazyInitialized<RetainPtr<WKWebViewContentProviderRegistry>> _contentProviderRegistry;
126     BOOL _alwaysRunsAtForegroundPriority;
127     BOOL _allowsInlineMediaPlayback;
128     BOOL _inlineMediaPlaybackRequiresPlaysInlineAttribute;
129     BOOL _allowsInlineMediaPlaybackAfterFullscreen;
130     _WKDragLiftDelay _dragLiftDelay;
131 #endif
132
133     BOOL _invisibleAutoplayNotPermitted;
134     BOOL _mediaDataLoadsAutomatically;
135     BOOL _attachmentElementEnabled;
136     BOOL _mainContentUserGestureOverrideEnabled;
137
138 #if PLATFORM(MAC)
139     double _cpuLimit;
140     BOOL _showsURLsInToolTips;
141     BOOL _serviceControlsEnabled;
142     BOOL _imageControlsEnabled;
143     BOOL _requiresUserActionForEditingControlsManager;
144 #endif
145     BOOL _initialCapitalizationEnabled;
146     BOOL _waitsForPaintAfterViewDidMoveToWindow;
147     BOOL _controlledByAutomation;
148
149 #if ENABLE(APPLE_PAY)
150     BOOL _applePayEnabled;
151 #endif
152     BOOL _needsStorageAccessFromFileURLsQuirk;
153     BOOL _legacyEncryptedMediaAPIEnabled;
154     BOOL _allowMediaContentTypesRequiringHardwareSupportAsFallback;
155
156     RetainPtr<NSString> _overrideContentSecurityPolicy;
157     RetainPtr<NSString> _mediaContentTypesRequiringHardwareSupport;
158 }
159
160 - (instancetype)init
161 {
162     if (!(self = [super init]))
163         return nil;
164
165     WebKit::InitializeWebKit2();
166
167 #if PLATFORM(IOS)
168     _allowsPictureInPictureMediaPlayback = YES;
169     _allowsInlineMediaPlayback = WebCore::deviceClass() == MGDeviceClassiPad;
170     _inlineMediaPlaybackRequiresPlaysInlineAttribute = !_allowsInlineMediaPlayback;
171     _allowsInlineMediaPlaybackAfterFullscreen = !_allowsInlineMediaPlayback;
172     _mediaDataLoadsAutomatically = NO;
173     if (WebKit::linkedOnOrAfter(WebKit::SDKVersion::FirstWithMediaTypesRequiringUserActionForPlayback))
174         _mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAudio;
175     else
176         _mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
177     _ignoresViewportScaleLimits = NO;
178     _legacyEncryptedMediaAPIEnabled = NO;
179 #else
180     _mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
181     _mediaDataLoadsAutomatically = YES;
182     _userInterfaceDirectionPolicy = WKUserInterfaceDirectionPolicyContent;
183     _legacyEncryptedMediaAPIEnabled = YES;
184 #endif
185     _mainContentUserGestureOverrideEnabled = NO;
186     _invisibleAutoplayNotPermitted = NO;
187     _attachmentElementEnabled = NO;
188
189 #if PLATFORM(IOS)
190     _respectsImageOrientation = YES;
191     _printsBackgrounds = YES;
192 #endif
193
194 #if PLATFORM(MAC)
195     _cpuLimit = 0;
196     _printsBackgrounds = NO;
197     _respectsImageOrientation = NO;
198     _showsURLsInToolTips = NO;
199     _serviceControlsEnabled = NO;
200     _imageControlsEnabled = NO;
201     _requiresUserActionForEditingControlsManager = NO;
202 #endif
203     _initialCapitalizationEnabled = YES;
204     _waitsForPaintAfterViewDidMoveToWindow = YES;
205
206 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
207     _allowsAirPlayForMediaPlayback = YES;
208 #endif
209
210     _incrementalRenderingSuppressionTimeout = 5;
211     _allowsJavaScriptMarkup = YES;
212     _convertsPositionStyleOnCopy = NO;
213     _allowsMetaRefresh = YES;
214     _allowUniversalAccessFromFileURLs = NO;
215     _treatsSHA1SignedCertificatesAsInsecure = YES;
216     _needsStorageAccessFromFileURLsQuirk = YES;
217
218 #if PLATFORM(IOS)
219     _selectionGranularity = WKSelectionGranularityDynamic;
220     _dragLiftDelay = toDragLiftDelay([[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitDebugDragLiftDelay"]);
221 #endif
222
223     _mediaContentTypesRequiringHardwareSupport = Settings::defaultMediaContentTypesRequiringHardwareSupport();
224     _allowMediaContentTypesRequiringHardwareSupportAsFallback = YES;
225
226     return self;
227 }
228
229 - (NSString *)description
230 {
231     return [NSString stringWithFormat:@"<%@: %p; processPool = %@; preferences = %@>", NSStringFromClass(self.class), self, self.processPool, self.preferences];
232 }
233
234 // FIXME: Encode the process pool, user content controller and website data store.
235
236 - (void)encodeWithCoder:(NSCoder *)coder
237 {
238     [coder encodeObject:self.processPool forKey:@"processPool"];
239     [coder encodeObject:self.preferences forKey:@"preferences"];
240     [coder encodeObject:self.userContentController forKey:@"userContentController"];
241     [coder encodeObject:self.websiteDataStore forKey:@"websiteDataStore"];
242
243     [coder encodeBool:self.suppressesIncrementalRendering forKey:@"suppressesIncrementalRendering"];
244     [coder encodeObject:self.applicationNameForUserAgent forKey:@"applicationNameForUserAgent"];
245     [coder encodeBool:self.allowsAirPlayForMediaPlayback forKey:@"allowsAirPlayForMediaPlayback"];
246
247 #if PLATFORM(IOS)
248     [coder encodeInteger:self.dataDetectorTypes forKey:@"dataDetectorTypes"];
249     [coder encodeBool:self.allowsInlineMediaPlayback forKey:@"allowsInlineMediaPlayback"];
250     [coder encodeBool:self._allowsInlineMediaPlaybackAfterFullscreen forKey:@"allowsInlineMediaPlaybackAfterFullscreen"];
251     [coder encodeBool:self.mediaTypesRequiringUserActionForPlayback forKey:@"mediaTypesRequiringUserActionForPlayback"];
252     [coder encodeInteger:self.selectionGranularity forKey:@"selectionGranularity"];
253     [coder encodeBool:self.allowsPictureInPictureMediaPlayback forKey:@"allowsPictureInPictureMediaPlayback"];
254     [coder encodeBool:self.ignoresViewportScaleLimits forKey:@"ignoresViewportScaleLimits"];
255     [coder encodeInteger:self._dragLiftDelay forKey:@"dragLiftDelay"];
256 #else
257     [coder encodeInteger:self.userInterfaceDirectionPolicy forKey:@"userInterfaceDirectionPolicy"];
258 #endif
259 }
260
261 - (instancetype)initWithCoder:(NSCoder *)coder
262 {
263     if (!(self = [self init]))
264         return nil;
265
266     self.processPool = [coder decodeObjectForKey:@"processPool"];
267     self.preferences = [coder decodeObjectForKey:@"preferences"];
268     self.userContentController = [coder decodeObjectForKey:@"userContentController"];
269     self.websiteDataStore = [coder decodeObjectForKey:@"websiteDataStore"];
270
271     self.suppressesIncrementalRendering = [coder decodeBoolForKey:@"suppressesIncrementalRendering"];
272     self.applicationNameForUserAgent = [coder decodeObjectForKey:@"applicationNameForUserAgent"];
273     self.allowsAirPlayForMediaPlayback = [coder decodeBoolForKey:@"allowsAirPlayForMediaPlayback"];
274
275 #if PLATFORM(IOS)
276     self.dataDetectorTypes = [coder decodeIntegerForKey:@"dataDetectorTypes"];
277     self.allowsInlineMediaPlayback = [coder decodeBoolForKey:@"allowsInlineMediaPlayback"];
278     self._allowsInlineMediaPlaybackAfterFullscreen = [coder decodeBoolForKey:@"allowsInlineMediaPlaybackAfterFullscreen"];
279     self.mediaTypesRequiringUserActionForPlayback = [coder decodeBoolForKey:@"mediaTypesRequiringUserActionForPlayback"];
280     self.selectionGranularity = static_cast<WKSelectionGranularity>([coder decodeIntegerForKey:@"selectionGranularity"]);
281     self.allowsPictureInPictureMediaPlayback = [coder decodeBoolForKey:@"allowsPictureInPictureMediaPlayback"];
282     self.ignoresViewportScaleLimits = [coder decodeBoolForKey:@"ignoresViewportScaleLimits"];
283     self._dragLiftDelay = toDragLiftDelay([coder decodeIntegerForKey:@"dragLiftDelay"]);
284 #else
285     auto userInterfaceDirectionPolicyCandidate = static_cast<WKUserInterfaceDirectionPolicy>([coder decodeIntegerForKey:@"userInterfaceDirectionPolicy"]);
286     if (userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicyContent || userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicySystem)
287         self.userInterfaceDirectionPolicy = userInterfaceDirectionPolicyCandidate;
288 #endif
289
290     return self;
291 }
292
293 - (id)copyWithZone:(NSZone *)zone
294 {
295     WKWebViewConfiguration *configuration = [(WKWebViewConfiguration *)[[self class] allocWithZone:zone] init];
296
297     configuration.processPool = self.processPool;
298     configuration.preferences = self.preferences;
299     configuration.userContentController = self.userContentController;
300     configuration.websiteDataStore = self.websiteDataStore;
301     configuration._visitedLinkStore = self._visitedLinkStore;
302     configuration._relatedWebView = _relatedWebView.get().get();
303     configuration._alternateWebViewForNavigationGestures = _alternateWebViewForNavigationGestures.get().get();
304     configuration->_treatsSHA1SignedCertificatesAsInsecure = _treatsSHA1SignedCertificatesAsInsecure;
305 #if PLATFORM(IOS)
306     configuration._contentProviderRegistry = self._contentProviderRegistry;
307 #endif
308
309     configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
310     configuration.applicationNameForUserAgent = self.applicationNameForUserAgent;
311
312     configuration->_respectsImageOrientation = self->_respectsImageOrientation;
313     configuration->_printsBackgrounds = self->_printsBackgrounds;
314     configuration->_incrementalRenderingSuppressionTimeout = self->_incrementalRenderingSuppressionTimeout;
315     configuration->_allowsJavaScriptMarkup = self->_allowsJavaScriptMarkup;
316     configuration->_convertsPositionStyleOnCopy = self->_convertsPositionStyleOnCopy;
317     configuration->_allowsMetaRefresh = self->_allowsMetaRefresh;
318     configuration->_allowUniversalAccessFromFileURLs = self->_allowUniversalAccessFromFileURLs;
319
320     configuration->_invisibleAutoplayNotPermitted = self->_invisibleAutoplayNotPermitted;
321     configuration->_mediaDataLoadsAutomatically = self->_mediaDataLoadsAutomatically;
322     configuration->_attachmentElementEnabled = self->_attachmentElementEnabled;
323     configuration->_mediaTypesRequiringUserActionForPlayback = self->_mediaTypesRequiringUserActionForPlayback;
324     configuration->_mainContentUserGestureOverrideEnabled = self->_mainContentUserGestureOverrideEnabled;
325     configuration->_initialCapitalizationEnabled = self->_initialCapitalizationEnabled;
326     configuration->_waitsForPaintAfterViewDidMoveToWindow = self->_waitsForPaintAfterViewDidMoveToWindow;
327     configuration->_controlledByAutomation = self->_controlledByAutomation;
328
329 #if PLATFORM(IOS)
330     configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
331     configuration->_allowsInlineMediaPlaybackAfterFullscreen = self->_allowsInlineMediaPlaybackAfterFullscreen;
332     configuration->_inlineMediaPlaybackRequiresPlaysInlineAttribute = self->_inlineMediaPlaybackRequiresPlaysInlineAttribute;
333     configuration->_allowsPictureInPictureMediaPlayback = self->_allowsPictureInPictureMediaPlayback;
334     configuration->_alwaysRunsAtForegroundPriority = _alwaysRunsAtForegroundPriority;
335     configuration->_selectionGranularity = self->_selectionGranularity;
336     configuration->_ignoresViewportScaleLimits = self->_ignoresViewportScaleLimits;
337     configuration->_dragLiftDelay = self->_dragLiftDelay;
338 #endif
339 #if PLATFORM(MAC)
340     configuration->_cpuLimit = self->_cpuLimit;
341     configuration->_userInterfaceDirectionPolicy = self->_userInterfaceDirectionPolicy;
342     configuration->_showsURLsInToolTips = self->_showsURLsInToolTips;
343     configuration->_serviceControlsEnabled = self->_serviceControlsEnabled;
344     configuration->_imageControlsEnabled = self->_imageControlsEnabled;
345     configuration->_requiresUserActionForEditingControlsManager = self->_requiresUserActionForEditingControlsManager;
346 #endif
347 #if ENABLE(DATA_DETECTION) && PLATFORM(IOS)
348     configuration->_dataDetectorTypes = self->_dataDetectorTypes;
349 #endif
350 #if ENABLE(WIRELESS_TARGET_PLAYBACK)
351     configuration->_allowsAirPlayForMediaPlayback = self->_allowsAirPlayForMediaPlayback;
352 #endif
353 #if ENABLE(APPLE_PAY)
354     configuration->_applePayEnabled = self->_applePayEnabled;
355 #endif
356     configuration->_needsStorageAccessFromFileURLsQuirk = self->_needsStorageAccessFromFileURLsQuirk;
357     configuration->_overrideContentSecurityPolicy = adoptNS([self->_overrideContentSecurityPolicy copyWithZone:zone]);
358
359     configuration->_urlSchemeHandlers.set(adoptNS([self._urlSchemeHandlers mutableCopyWithZone:zone]));
360     configuration->_mediaContentTypesRequiringHardwareSupport = adoptNS([self._mediaContentTypesRequiringHardwareSupport copyWithZone:zone]);
361     configuration->_legacyEncryptedMediaAPIEnabled = self->_legacyEncryptedMediaAPIEnabled;
362     configuration->_allowMediaContentTypesRequiringHardwareSupportAsFallback = self->_allowMediaContentTypesRequiringHardwareSupportAsFallback;
363
364     return configuration;
365 }
366
367 - (WKProcessPool *)processPool
368 {
369     return _processPool.get([] { return adoptNS([[WKProcessPool alloc] init]); });
370 }
371
372 - (void)setProcessPool:(WKProcessPool *)processPool
373 {
374     _processPool.set(processPool);
375 }
376
377 - (WKPreferences *)preferences
378 {
379     return _preferences.get([] { return adoptNS([[WKPreferences alloc] init]); });
380 }
381
382 - (void)setPreferences:(WKPreferences *)preferences
383 {
384     _preferences.set(preferences);
385 }
386
387 - (WKUserContentController *)userContentController
388 {
389     return _userContentController.get([] { return adoptNS([[WKUserContentController alloc] init]); });
390 }
391
392 - (void)setUserContentController:(WKUserContentController *)userContentController
393 {
394     _userContentController.set(userContentController);
395 }
396
397 - (WKWebsiteDataStore *)websiteDataStore
398 {
399     return _websiteDataStore.get([] { return [WKWebsiteDataStore defaultDataStore]; });
400 }
401
402 - (void)setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore
403 {
404     _websiteDataStore.set(websiteDataStore);
405 }
406
407 static NSString *defaultApplicationNameForUserAgent()
408 {
409 #if PLATFORM(IOS)
410     return [@"Mobile/" stringByAppendingString:[UIDevice currentDevice].buildVersion];
411 #else
412     return nil;
413 #endif
414 }
415
416 - (NSString *)applicationNameForUserAgent
417 {
418     return _applicationNameForUserAgent.get([] { return defaultApplicationNameForUserAgent(); });
419 }
420
421 - (void)setApplicationNameForUserAgent:(NSString *)applicationNameForUserAgent
422 {
423     _applicationNameForUserAgent.set(adoptNS([applicationNameForUserAgent copy]));
424 }
425
426 - (_WKVisitedLinkStore *)_visitedLinkStore
427 {
428     return _visitedLinkStore.get([] { return adoptNS([[_WKVisitedLinkStore alloc] init]); });
429 }
430
431 - (void)_setVisitedLinkStore:(_WKVisitedLinkStore *)visitedLinkStore
432 {
433     _visitedLinkStore.set(visitedLinkStore);
434 }
435
436 - (void)setURLSchemeHandler:(id <WKURLSchemeHandler>)urlSchemeHandler forURLScheme:(NSString *)urlScheme
437 {
438     auto *urlSchemeHandlers = _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
439
440     if ([WKWebView handlesURLScheme:urlScheme])
441         [NSException raise:NSInvalidArgumentException format:@"'%@' is a URL scheme that WKWebView handles natively", urlScheme];
442
443     auto canonicalScheme = WebCore::URLParser::maybeCanonicalizeScheme(urlScheme);
444     if (!canonicalScheme)
445         [NSException raise:NSInvalidArgumentException format:@"'%@' is not a valid URL scheme", urlScheme];
446
447     if ([urlSchemeHandlers objectForKey:(NSString *)canonicalScheme.value()])
448         [NSException raise:NSInvalidArgumentException format:@"URL scheme '%@' already has a registered URL scheme handler", urlScheme];
449
450     [urlSchemeHandlers setObject:urlSchemeHandler forKey:(NSString *)canonicalScheme.value()];
451 }
452
453 - (nullable id <WKURLSchemeHandler>)urlSchemeHandlerForURLScheme:(NSString *)urlScheme
454 {
455     auto canonicalScheme = WebCore::URLParser::maybeCanonicalizeScheme(urlScheme);
456     if (!canonicalScheme)
457         return nil;
458
459     auto *urlSchemeHandlers = _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
460     return [urlSchemeHandlers objectForKey:(NSString *)canonicalScheme.value()];
461 }
462
463 #pragma clang diagnostic push
464 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
465
466 - (_WKWebsiteDataStore *)_websiteDataStore
467 {
468     return self.websiteDataStore ? adoptNS([[_WKWebsiteDataStore alloc] initWithDataStore:self.websiteDataStore]).autorelease() : nullptr;
469 }
470
471 - (void)_setWebsiteDataStore:(_WKWebsiteDataStore *)websiteDataStore
472 {
473     self.websiteDataStore = websiteDataStore ? websiteDataStore->_dataStore.get() : nullptr;
474 }
475
476 #pragma clang diagnostic pop
477
478 - (NSMutableDictionary<NSString *, id <WKURLSchemeHandler>> *)_urlSchemeHandlers
479 {
480     return _urlSchemeHandlers.get([] { return adoptNS([[NSMutableDictionary alloc] init]); });
481 }
482
483 #if PLATFORM(IOS)
484 - (WKWebViewContentProviderRegistry *)_contentProviderRegistry
485 {
486     return _contentProviderRegistry.get([] { return adoptNS([[WKWebViewContentProviderRegistry alloc] init]); });
487 }
488
489 - (void)_setContentProviderRegistry:(WKWebViewContentProviderRegistry *)registry
490 {
491     _contentProviderRegistry.set(registry);
492 }
493 #endif
494
495 @end
496
497 @implementation WKWebViewConfiguration (WKPrivate)
498
499 - (WKWebView *)_relatedWebView
500 {
501     return _relatedWebView.getAutoreleased();
502 }
503
504 - (void)_setRelatedWebView:(WKWebView *)relatedWebView
505 {
506     _relatedWebView = relatedWebView;
507 }
508
509 - (WKWebView *)_alternateWebViewForNavigationGestures
510 {
511     return _alternateWebViewForNavigationGestures.getAutoreleased();
512 }
513
514 - (void)_setAlternateWebViewForNavigationGestures:(WKWebView *)alternateView
515 {
516     _alternateWebViewForNavigationGestures = alternateView;
517 }
518
519 - (NSString *)_groupIdentifier
520 {
521     return _groupIdentifier.get();
522 }
523
524 - (void)_setGroupIdentifier:(NSString *)groupIdentifier
525 {
526     _groupIdentifier = groupIdentifier;
527 }
528
529 - (BOOL)_treatsSHA1SignedCertificatesAsInsecure
530 {
531     return _treatsSHA1SignedCertificatesAsInsecure;
532 }
533
534 - (void)_setTreatsSHA1SignedCertificatesAsInsecure:(BOOL)insecure
535 {
536     _treatsSHA1SignedCertificatesAsInsecure = insecure;
537 }
538
539 - (BOOL)_respectsImageOrientation
540 {
541     return _respectsImageOrientation;
542 }
543
544 - (void)_setRespectsImageOrientation:(BOOL)respectsImageOrientation
545 {
546     _respectsImageOrientation = respectsImageOrientation;
547 }
548
549 - (BOOL)_printsBackgrounds
550 {
551     return _printsBackgrounds;
552 }
553
554 - (void)_setPrintsBackgrounds:(BOOL)printsBackgrounds
555 {
556     _printsBackgrounds = printsBackgrounds;
557 }
558
559 - (NSTimeInterval)_incrementalRenderingSuppressionTimeout
560 {
561     return _incrementalRenderingSuppressionTimeout;
562 }
563
564 - (void)_setIncrementalRenderingSuppressionTimeout:(NSTimeInterval)incrementalRenderingSuppressionTimeout
565 {
566     _incrementalRenderingSuppressionTimeout = incrementalRenderingSuppressionTimeout;
567 }
568
569 - (BOOL)_allowsJavaScriptMarkup
570 {
571     return _allowsJavaScriptMarkup;
572 }
573
574 - (void)_setAllowsJavaScriptMarkup:(BOOL)allowsJavaScriptMarkup
575 {
576     _allowsJavaScriptMarkup = allowsJavaScriptMarkup;
577 }
578
579 - (BOOL)_allowUniversalAccessFromFileURLs
580 {
581     return _allowUniversalAccessFromFileURLs;
582 }
583
584 - (void)_setAllowUniversalAccessFromFileURLs:(BOOL)allowUniversalAccessFromFileURLs
585 {
586     _allowUniversalAccessFromFileURLs = allowUniversalAccessFromFileURLs;
587 }
588
589 - (BOOL)_convertsPositionStyleOnCopy
590 {
591     return _convertsPositionStyleOnCopy;
592 }
593
594 - (void)_setConvertsPositionStyleOnCopy:(BOOL)convertsPositionStyleOnCopy
595 {
596     _convertsPositionStyleOnCopy = convertsPositionStyleOnCopy;
597 }
598
599 - (BOOL)_allowsMetaRefresh
600 {
601     return _allowsMetaRefresh;
602 }
603
604 - (void)_setAllowsMetaRefresh:(BOOL)allowsMetaRefresh
605 {
606     _allowsMetaRefresh = allowsMetaRefresh;
607 }
608
609 #if PLATFORM(IOS)
610 - (BOOL)_alwaysRunsAtForegroundPriority
611 {
612     return _alwaysRunsAtForegroundPriority;
613 }
614
615 - (void)_setAlwaysRunsAtForegroundPriority:(BOOL)alwaysRunsAtForegroundPriority
616 {
617     _alwaysRunsAtForegroundPriority = alwaysRunsAtForegroundPriority;
618 }
619
620 - (BOOL)_inlineMediaPlaybackRequiresPlaysInlineAttribute
621 {
622     return _inlineMediaPlaybackRequiresPlaysInlineAttribute;
623 }
624
625 - (void)_setInlineMediaPlaybackRequiresPlaysInlineAttribute:(BOOL)requires
626 {
627     _inlineMediaPlaybackRequiresPlaysInlineAttribute = requires;
628 }
629
630 - (BOOL)_allowsInlineMediaPlaybackAfterFullscreen
631 {
632     return _allowsInlineMediaPlaybackAfterFullscreen;
633 }
634
635 - (void)_setAllowsInlineMediaPlaybackAfterFullscreen:(BOOL)allows
636 {
637     _allowsInlineMediaPlaybackAfterFullscreen = allows;
638 }
639
640 - (_WKDragLiftDelay)_dragLiftDelay
641 {
642     return _dragLiftDelay;
643 }
644
645 - (void)_setDragLiftDelay:(_WKDragLiftDelay)dragLiftDelay
646 {
647     _dragLiftDelay = dragLiftDelay;
648 }
649 #endif // PLATFORM(IOS)
650
651 - (BOOL)_invisibleAutoplayNotPermitted
652 {
653     return _invisibleAutoplayNotPermitted;
654 }
655
656 - (void)_setInvisibleAutoplayNotPermitted:(BOOL)notPermitted
657 {
658     _invisibleAutoplayNotPermitted = notPermitted;
659 }
660
661 - (BOOL)_mediaDataLoadsAutomatically
662 {
663     return _mediaDataLoadsAutomatically;
664 }
665
666 - (void)_setMediaDataLoadsAutomatically:(BOOL)mediaDataLoadsAutomatically
667 {
668     _mediaDataLoadsAutomatically = mediaDataLoadsAutomatically;
669 }
670
671 - (BOOL)_attachmentElementEnabled
672 {
673     return _attachmentElementEnabled;
674 }
675
676 - (void)_setAttachmentElementEnabled:(BOOL)attachmentElementEnabled
677 {
678     _attachmentElementEnabled = attachmentElementEnabled;
679 }
680
681 - (BOOL)_requiresUserActionForVideoPlayback
682 {
683     return self.mediaTypesRequiringUserActionForPlayback & WKAudiovisualMediaTypeVideo;
684 }
685
686 - (void)_setRequiresUserActionForVideoPlayback:(BOOL)requiresUserActionForVideoPlayback
687 {
688     if (requiresUserActionForVideoPlayback)
689         self.mediaTypesRequiringUserActionForPlayback |= WKAudiovisualMediaTypeVideo;
690     else
691         self.mediaTypesRequiringUserActionForPlayback &= ~WKAudiovisualMediaTypeVideo;
692 }
693
694 - (BOOL)_requiresUserActionForAudioPlayback
695 {
696     return self.mediaTypesRequiringUserActionForPlayback & WKAudiovisualMediaTypeAudio;
697 }
698
699 - (void)_setRequiresUserActionForAudioPlayback:(BOOL)requiresUserActionForAudioPlayback
700 {
701     if (requiresUserActionForAudioPlayback)
702         self.mediaTypesRequiringUserActionForPlayback |= WKAudiovisualMediaTypeAudio;
703     else
704         self.mediaTypesRequiringUserActionForPlayback &= ~WKAudiovisualMediaTypeAudio;
705 }
706
707 - (BOOL)_mainContentUserGestureOverrideEnabled
708 {
709     return _mainContentUserGestureOverrideEnabled;
710 }
711
712 - (void)_setMainContentUserGestureOverrideEnabled:(BOOL)mainContentUserGestureOverrideEnabled
713 {
714     _mainContentUserGestureOverrideEnabled = mainContentUserGestureOverrideEnabled;
715 }
716
717 - (BOOL)_initialCapitalizationEnabled
718 {
719     return _initialCapitalizationEnabled;
720 }
721
722 - (void)_setInitialCapitalizationEnabled:(BOOL)initialCapitalizationEnabled
723 {
724     _initialCapitalizationEnabled = initialCapitalizationEnabled;
725 }
726
727 - (BOOL)_waitsForPaintAfterViewDidMoveToWindow
728 {
729     return _waitsForPaintAfterViewDidMoveToWindow;
730 }
731
732 - (void)_setWaitsForPaintAfterViewDidMoveToWindow:(BOOL)shouldSynchronize
733 {
734     _waitsForPaintAfterViewDidMoveToWindow = shouldSynchronize;
735 }
736
737 - (BOOL)_isControlledByAutomation
738 {
739     return _controlledByAutomation;
740 }
741
742 - (void)_setControlledByAutomation:(BOOL)controlledByAutomation
743 {
744     _controlledByAutomation = controlledByAutomation;
745 }
746
747 #if PLATFORM(MAC)
748 - (BOOL)_showsURLsInToolTips
749 {
750     return _showsURLsInToolTips;
751 }
752
753 - (void)_setShowsURLsInToolTips:(BOOL)showsURLsInToolTips
754 {
755     _showsURLsInToolTips = showsURLsInToolTips;
756 }
757
758 - (BOOL)_serviceControlsEnabled
759 {
760     return _serviceControlsEnabled;
761 }
762
763 - (void)_setServiceControlsEnabled:(BOOL)serviceControlsEnabled
764 {
765     _serviceControlsEnabled = serviceControlsEnabled;
766 }
767
768 - (BOOL)_imageControlsEnabled
769 {
770     return _imageControlsEnabled;
771 }
772
773 - (void)_setImageControlsEnabled:(BOOL)imageControlsEnabled
774 {
775     _imageControlsEnabled = imageControlsEnabled;
776 }
777
778 - (BOOL)_requiresUserActionForEditingControlsManager
779 {
780     return _requiresUserActionForEditingControlsManager;
781 }
782
783 - (void)_setRequiresUserActionForEditingControlsManager:(BOOL)requiresUserAction
784 {
785     _requiresUserActionForEditingControlsManager = requiresUserAction;
786 }
787
788 - (void)_setCPULimit:(double)cpuLimit
789 {
790     _cpuLimit = cpuLimit;
791 }
792
793 - (double)_cpuLimit
794 {
795     return _cpuLimit;
796 }
797
798 #endif // PLATFORM(MAC)
799
800 - (BOOL)_applePayEnabled
801 {
802 #if ENABLE(APPLE_PAY)
803     return _applePayEnabled;
804 #else
805     return NO;
806 #endif
807 }
808
809 - (void)_setApplePayEnabled:(BOOL)applePayEnabled
810 {
811 #if ENABLE(APPLE_PAY)
812     _applePayEnabled = applePayEnabled;
813 #endif
814 }
815
816 - (BOOL)_needsStorageAccessFromFileURLsQuirk
817 {
818     return _needsStorageAccessFromFileURLsQuirk;
819 }
820
821 - (void)_setNeedsStorageAccessFromFileURLsQuirk:(BOOL)needsLocalStorageQuirk
822 {
823     _needsStorageAccessFromFileURLsQuirk = needsLocalStorageQuirk;
824 }
825
826 - (NSString *)_overrideContentSecurityPolicy
827 {
828     return _overrideContentSecurityPolicy.get();
829 }
830
831 - (void)_setOverrideContentSecurityPolicy:(NSString *)overrideContentSecurityPolicy
832 {
833     _overrideContentSecurityPolicy = adoptNS([overrideContentSecurityPolicy copy]);
834 }
835
836 - (NSString *)_mediaContentTypesRequiringHardwareSupport
837 {
838     return _mediaContentTypesRequiringHardwareSupport.get();
839 }
840
841 - (void)_setMediaContentTypesRequiringHardwareSupport:(NSString *)mediaContentTypesRequiringHardwareSupport
842 {
843     _mediaContentTypesRequiringHardwareSupport = adoptNS([mediaContentTypesRequiringHardwareSupport copy]);
844 }
845
846 - (void)_setLegacyEncryptedMediaAPIEnabled:(BOOL)enabled
847 {
848     _legacyEncryptedMediaAPIEnabled = enabled;
849 }
850
851 - (BOOL)_legacyEncryptedMediaAPIEnabled
852 {
853     return _legacyEncryptedMediaAPIEnabled;
854 }
855
856 - (void)_setAllowMediaContentTypesRequiringHardwareSupportAsFallback:(BOOL)allow
857 {
858     _allowMediaContentTypesRequiringHardwareSupportAsFallback = allow;
859 }
860
861 - (BOOL)_allowMediaContentTypesRequiringHardwareSupportAsFallback
862 {
863     return _allowMediaContentTypesRequiringHardwareSupportAsFallback;
864 }
865
866 @end
867
868 @implementation WKWebViewConfiguration (WKDeprecated)
869
870 #if PLATFORM(IOS)
871 - (BOOL)mediaPlaybackAllowsAirPlay
872 {
873     return self.allowsAirPlayForMediaPlayback;
874 }
875
876 - (void)setMediaPlaybackAllowsAirPlay:(BOOL)allowed
877 {
878     self.allowsAirPlayForMediaPlayback = allowed;
879 }
880
881 - (BOOL)mediaPlaybackRequiresUserAction
882 {
883     return self.requiresUserActionForMediaPlayback;
884 }
885
886 - (void)setMediaPlaybackRequiresUserAction:(BOOL)required
887 {
888     self.requiresUserActionForMediaPlayback = required;
889 }
890
891 - (BOOL)requiresUserActionForMediaPlayback
892 {
893     return self.mediaTypesRequiringUserActionForPlayback == WKAudiovisualMediaTypeAll;
894 }
895
896 - (void)setRequiresUserActionForMediaPlayback:(BOOL)requiresUserActionForMediaPlayback
897 {
898     self.mediaTypesRequiringUserActionForPlayback = requiresUserActionForMediaPlayback ? WKAudiovisualMediaTypeAll : WKAudiovisualMediaTypeNone;
899 }
900
901 #endif // PLATFORM(IOS)
902
903 @end
904
905 @implementation WKWebViewConfiguration (WKBinaryCompatibilityWithIOS10)
906
907 -(_WKVisitedLinkStore *)_visitedLinkProvider
908 {
909     return self._visitedLinkStore;
910 }
911
912 - (void)_setVisitedLinkProvider:(_WKVisitedLinkStore *)visitedLinkProvider
913 {
914     self._visitedLinkStore = visitedLinkProvider;
915 }
916
917 @end
918
919 #endif // WK_API_ENABLED