Expose SPI to disable synchronously blocking on painting after parenting a WKWebView
[WebKit-https.git] / Source / WebKit2 / 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 "WKWebViewContentProviderRegistry.h"
37 #import "WeakObjCPtr.h"
38 #import "_WKVisitedLinkStore.h"
39 #import "_WKWebsiteDataStoreInternal.h"
40 #import <WebCore/RuntimeApplicationChecks.h>
41 #import <wtf/RetainPtr.h>
42
43 #if PLATFORM(IOS)
44 #import "UIKitSPI.h"
45 #import <WebCore/Device.h>
46 #endif
47
48 using namespace WebCore;
49
50 template<typename T> class LazyInitialized {
51 public:
52     typedef typename WTF::GetPtrHelper<T>::PtrType PtrType;
53
54     template<typename F>
55     PtrType get(F&& f)
56     {
57         if (!m_isInitialized) {
58             m_value = f();
59             m_isInitialized = true;
60         }
61
62         return m_value.get();
63     }
64
65     void set(PtrType t)
66     {
67         m_value = t;
68         m_isInitialized = true;
69     }
70
71     void set(T&& t)
72     {
73         m_value = WTFMove(t);
74         m_isInitialized = true;
75     }
76
77     PtrType peek()
78     {
79         return m_value.get();
80     }
81
82 private:
83     bool m_isInitialized = false;
84     T m_value;
85 };
86
87 @implementation WKWebViewConfiguration {
88     LazyInitialized<RetainPtr<WKProcessPool>> _processPool;
89     LazyInitialized<RetainPtr<WKPreferences>> _preferences;
90     LazyInitialized<RetainPtr<WKUserContentController>> _userContentController;
91     LazyInitialized<RetainPtr<_WKVisitedLinkStore>> _visitedLinkStore;
92     LazyInitialized<RetainPtr<WKWebsiteDataStore>> _websiteDataStore;
93     WebKit::WeakObjCPtr<WKWebView> _relatedWebView;
94     WebKit::WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures;
95     RetainPtr<NSString> _groupIdentifier;
96     LazyInitialized<RetainPtr<NSString>> _applicationNameForUserAgent;
97     NSTimeInterval _incrementalRenderingSuppressionTimeout;
98     BOOL _treatsSHA1SignedCertificatesAsInsecure;
99     BOOL _respectsImageOrientation;
100     BOOL _printsBackgrounds;
101     BOOL _allowsJavaScriptMarkup;
102     BOOL _convertsPositionStyleOnCopy;
103     BOOL _allowsMetaRefresh;
104     BOOL _allowUniversalAccessFromFileURLs;
105
106 #if PLATFORM(IOS)
107     LazyInitialized<RetainPtr<WKWebViewContentProviderRegistry>> _contentProviderRegistry;
108     BOOL _alwaysRunsAtForegroundPriority;
109     BOOL _allowsInlineMediaPlayback;
110     BOOL _inlineMediaPlaybackRequiresPlaysInlineAttribute;
111     BOOL _allowsInlineMediaPlaybackAfterFullscreen;
112 #endif
113
114     BOOL _invisibleAutoplayNotPermitted;
115     BOOL _mediaDataLoadsAutomatically;
116     BOOL _attachmentElementEnabled;
117     BOOL _mainContentUserGestureOverrideEnabled;
118
119 #if PLATFORM(MAC)
120     BOOL _showsURLsInToolTips;
121     BOOL _serviceControlsEnabled;
122     BOOL _imageControlsEnabled;
123     BOOL _requiresUserActionForEditingControlsManager;
124 #endif
125     BOOL _initialCapitalizationEnabled;
126     BOOL _shouldWaitForPaintAfterViewDidMoveToWindow;
127
128 #if ENABLE(APPLE_PAY)
129     BOOL _applePayEnabled;
130 #endif
131 }
132
133 - (instancetype)init
134 {
135     if (!(self = [super init]))
136         return nil;
137     
138 #if PLATFORM(IOS)
139     _allowsPictureInPictureMediaPlayback = YES;
140     _allowsInlineMediaPlayback = WebCore::deviceClass() == MGDeviceClassiPad;
141     _inlineMediaPlaybackRequiresPlaysInlineAttribute = !_allowsInlineMediaPlayback;
142     _allowsInlineMediaPlaybackAfterFullscreen = !_allowsInlineMediaPlayback;
143     _mediaDataLoadsAutomatically = NO;
144     if (linkedOnOrAfter(WebKit::LibraryVersion::FirstWithMediaTypesRequiringUserActionForPlayback))
145         _mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAudio;
146     else
147         _mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll;
148     _ignoresViewportScaleLimits = NO;
149 #else
150     _mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
151     _mediaDataLoadsAutomatically = YES;
152     _userInterfaceDirectionPolicy = WKUserInterfaceDirectionPolicyContent;
153 #endif
154     _mainContentUserGestureOverrideEnabled = NO;
155     _invisibleAutoplayNotPermitted = NO;
156
157 // FIXME: <rdar://problem/25135244> Should default to NO once clients have adopted the setting.
158 #if PLATFORM(IOS)
159     _attachmentElementEnabled = IOSApplication::isMobileMail();
160 #else
161     _attachmentElementEnabled = MacApplication::isAppleMail();
162 #endif
163
164 #if PLATFORM(IOS)
165     _respectsImageOrientation = YES;
166     _printsBackgrounds = YES;
167 #endif
168
169 #if PLATFORM(MAC)
170     _printsBackgrounds = NO;
171     _respectsImageOrientation = NO;
172     _showsURLsInToolTips = NO;
173     _serviceControlsEnabled = NO;
174     _imageControlsEnabled = NO;
175     _requiresUserActionForEditingControlsManager = NO;
176 #endif
177     _initialCapitalizationEnabled = YES;
178     _shouldWaitForPaintAfterViewDidMoveToWindow = YES;
179
180 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
181     _allowsAirPlayForMediaPlayback = YES;
182 #endif
183
184     _incrementalRenderingSuppressionTimeout = 5;
185     _allowsJavaScriptMarkup = YES;
186     _convertsPositionStyleOnCopy = NO;
187     _allowsMetaRefresh = YES;
188     _allowUniversalAccessFromFileURLs = NO;
189     _treatsSHA1SignedCertificatesAsInsecure = YES;
190
191     return self;
192 }
193
194 - (NSString *)description
195 {
196     return [NSString stringWithFormat:@"<%@: %p; processPool = %@; preferences = %@>", NSStringFromClass(self.class), self, self.processPool, self.preferences];
197 }
198
199 // FIXME: Encode the process pool, user content controller and website data store.
200
201 - (void)encodeWithCoder:(NSCoder *)coder
202 {
203     [coder encodeObject:self.processPool forKey:@"processPool"];
204     [coder encodeObject:self.preferences forKey:@"preferences"];
205     [coder encodeObject:self.userContentController forKey:@"userContentController"];
206     [coder encodeObject:self.websiteDataStore forKey:@"websiteDataStore"];
207
208     [coder encodeBool:self.suppressesIncrementalRendering forKey:@"suppressesIncrementalRendering"];
209     [coder encodeObject:self.applicationNameForUserAgent forKey:@"applicationNameForUserAgent"];
210     [coder encodeBool:self.allowsAirPlayForMediaPlayback forKey:@"allowsAirPlayForMediaPlayback"];
211
212 #if PLATFORM(IOS)
213     [coder encodeInteger:self.dataDetectorTypes forKey:@"dataDetectorTypes"];
214     [coder encodeBool:self.allowsInlineMediaPlayback forKey:@"allowsInlineMediaPlayback"];
215     [coder encodeBool:self._allowsInlineMediaPlaybackAfterFullscreen forKey:@"allowsInlineMediaPlaybackAfterFullscreen"];
216     [coder encodeBool:self.mediaTypesRequiringUserActionForPlayback forKey:@"mediaTypesRequiringUserActionForPlayback"];
217     [coder encodeInteger:self.selectionGranularity forKey:@"selectionGranularity"];
218     [coder encodeBool:self.allowsPictureInPictureMediaPlayback forKey:@"allowsPictureInPictureMediaPlayback"];
219     [coder encodeBool:self.ignoresViewportScaleLimits forKey:@"ignoresViewportScaleLimits"];
220 #else
221     [coder encodeInteger:self.userInterfaceDirectionPolicy forKey:@"userInterfaceDirectionPolicy"];
222 #endif
223 }
224
225 - (instancetype)initWithCoder:(NSCoder *)coder
226 {
227     if (!(self = [self init]))
228         return nil;
229
230     self.processPool = [coder decodeObjectForKey:@"processPool"];
231     self.preferences = [coder decodeObjectForKey:@"preferences"];
232     self.userContentController = [coder decodeObjectForKey:@"userContentController"];
233     self.websiteDataStore = [coder decodeObjectForKey:@"websiteDataStore"];
234
235     self.suppressesIncrementalRendering = [coder decodeBoolForKey:@"suppressesIncrementalRendering"];
236     self.applicationNameForUserAgent = [coder decodeObjectForKey:@"applicationNameForUserAgent"];
237     self.allowsAirPlayForMediaPlayback = [coder decodeBoolForKey:@"allowsAirPlayForMediaPlayback"];
238
239 #if PLATFORM(IOS)
240     self.dataDetectorTypes = [coder decodeIntegerForKey:@"dataDetectorTypes"];
241     self.allowsInlineMediaPlayback = [coder decodeBoolForKey:@"allowsInlineMediaPlayback"];
242     self._allowsInlineMediaPlaybackAfterFullscreen = [coder decodeBoolForKey:@"allowsInlineMediaPlaybackAfterFullscreen"];
243     self.mediaTypesRequiringUserActionForPlayback = [coder decodeBoolForKey:@"mediaTypesRequiringUserActionForPlayback"];
244     self.selectionGranularity = static_cast<WKSelectionGranularity>([coder decodeIntegerForKey:@"selectionGranularity"]);
245     self.allowsPictureInPictureMediaPlayback = [coder decodeBoolForKey:@"allowsPictureInPictureMediaPlayback"];
246     self.ignoresViewportScaleLimits = [coder decodeBoolForKey:@"ignoresViewportScaleLimits"];
247 #else
248     auto userInterfaceDirectionPolicyCandidate = static_cast<WKUserInterfaceDirectionPolicy>([coder decodeIntegerForKey:@"userInterfaceDirectionPolicy"]);
249     if (userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicyContent || userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicySystem)
250         self.userInterfaceDirectionPolicy = userInterfaceDirectionPolicyCandidate;
251 #endif
252
253     return self;
254 }
255
256 - (id)copyWithZone:(NSZone *)zone
257 {
258     WKWebViewConfiguration *configuration = [(WKWebViewConfiguration *)[[self class] allocWithZone:zone] init];
259
260     configuration.processPool = self.processPool;
261     configuration.preferences = self.preferences;
262     configuration.userContentController = self.userContentController;
263     configuration.websiteDataStore = self.websiteDataStore;
264     configuration._visitedLinkStore = self._visitedLinkStore;
265     configuration._relatedWebView = _relatedWebView.get().get();
266     configuration._alternateWebViewForNavigationGestures = _alternateWebViewForNavigationGestures.get().get();
267     configuration->_treatsSHA1SignedCertificatesAsInsecure = _treatsSHA1SignedCertificatesAsInsecure;
268 #if PLATFORM(IOS)
269     configuration._contentProviderRegistry = self._contentProviderRegistry;
270 #endif
271
272     configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
273     configuration.applicationNameForUserAgent = self.applicationNameForUserAgent;
274
275     configuration->_respectsImageOrientation = self->_respectsImageOrientation;
276     configuration->_printsBackgrounds = self->_printsBackgrounds;
277     configuration->_incrementalRenderingSuppressionTimeout = self->_incrementalRenderingSuppressionTimeout;
278     configuration->_allowsJavaScriptMarkup = self->_allowsJavaScriptMarkup;
279     configuration->_convertsPositionStyleOnCopy = self->_convertsPositionStyleOnCopy;
280     configuration->_allowsMetaRefresh = self->_allowsMetaRefresh;
281     configuration->_allowUniversalAccessFromFileURLs = self->_allowUniversalAccessFromFileURLs;
282
283     configuration->_invisibleAutoplayNotPermitted = self->_invisibleAutoplayNotPermitted;
284     configuration->_mediaDataLoadsAutomatically = self->_mediaDataLoadsAutomatically;
285     configuration->_attachmentElementEnabled = self->_attachmentElementEnabled;
286     configuration->_mediaTypesRequiringUserActionForPlayback = self->_mediaTypesRequiringUserActionForPlayback;
287     configuration->_mainContentUserGestureOverrideEnabled = self->_mainContentUserGestureOverrideEnabled;
288     configuration->_initialCapitalizationEnabled = self->_initialCapitalizationEnabled;
289     configuration->_shouldWaitForPaintAfterViewDidMoveToWindow = self->_shouldWaitForPaintAfterViewDidMoveToWindow;
290
291 #if PLATFORM(IOS)
292     configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
293     configuration->_allowsInlineMediaPlaybackAfterFullscreen = self->_allowsInlineMediaPlaybackAfterFullscreen;
294     configuration->_inlineMediaPlaybackRequiresPlaysInlineAttribute = self->_inlineMediaPlaybackRequiresPlaysInlineAttribute;
295     configuration->_allowsPictureInPictureMediaPlayback = self->_allowsPictureInPictureMediaPlayback;
296     configuration->_alwaysRunsAtForegroundPriority = _alwaysRunsAtForegroundPriority;
297     configuration->_selectionGranularity = self->_selectionGranularity;
298     configuration->_ignoresViewportScaleLimits = self->_ignoresViewportScaleLimits;
299 #endif
300 #if PLATFORM(MAC)
301     configuration->_userInterfaceDirectionPolicy = self->_userInterfaceDirectionPolicy;
302     configuration->_showsURLsInToolTips = self->_showsURLsInToolTips;
303     configuration->_serviceControlsEnabled = self->_serviceControlsEnabled;
304     configuration->_imageControlsEnabled = self->_imageControlsEnabled;
305     configuration->_requiresUserActionForEditingControlsManager = self->_requiresUserActionForEditingControlsManager;
306 #endif
307 #if ENABLE(DATA_DETECTION) && PLATFORM(IOS)
308     configuration->_dataDetectorTypes = self->_dataDetectorTypes;
309 #endif
310 #if ENABLE(WIRELESS_TARGET_PLAYBACK)
311     configuration->_allowsAirPlayForMediaPlayback = self->_allowsAirPlayForMediaPlayback;
312 #endif
313 #if ENABLE(APPLE_PAY)
314     configuration->_applePayEnabled = self->_applePayEnabled;
315 #endif
316
317     return configuration;
318 }
319
320 - (WKProcessPool *)processPool
321 {
322     return _processPool.get([] { return adoptNS([[WKProcessPool alloc] init]); });
323 }
324
325 - (void)setProcessPool:(WKProcessPool *)processPool
326 {
327     _processPool.set(processPool);
328 }
329
330 - (WKPreferences *)preferences
331 {
332     return _preferences.get([] { return adoptNS([[WKPreferences alloc] init]); });
333 }
334
335 - (void)setPreferences:(WKPreferences *)preferences
336 {
337     _preferences.set(preferences);
338 }
339
340 - (WKUserContentController *)userContentController
341 {
342     return _userContentController.get([] { return adoptNS([[WKUserContentController alloc] init]); });
343 }
344
345 - (void)setUserContentController:(WKUserContentController *)userContentController
346 {
347     _userContentController.set(userContentController);
348 }
349
350 - (WKWebsiteDataStore *)websiteDataStore
351 {
352     return _websiteDataStore.get([] { return [WKWebsiteDataStore defaultDataStore]; });
353 }
354
355 - (void)setWebsiteDataStore:(WKWebsiteDataStore *)websiteDataStore
356 {
357     _websiteDataStore.set(websiteDataStore);
358 }
359
360 static NSString *defaultApplicationNameForUserAgent()
361 {
362 #if PLATFORM(IOS)
363     return [@"Mobile/" stringByAppendingString:[UIDevice currentDevice].buildVersion];
364 #else
365     return nil;
366 #endif
367 }
368
369 - (NSString *)applicationNameForUserAgent
370 {
371     return _applicationNameForUserAgent.get([] { return defaultApplicationNameForUserAgent(); });
372 }
373
374 - (void)setApplicationNameForUserAgent:(NSString *)applicationNameForUserAgent
375 {
376     _applicationNameForUserAgent.set(adoptNS([applicationNameForUserAgent copy]));
377 }
378
379 - (_WKVisitedLinkStore *)_visitedLinkStore
380 {
381     return _visitedLinkStore.get([] { return adoptNS([[_WKVisitedLinkStore alloc] init]); });
382 }
383
384 - (void)_setVisitedLinkStore:(_WKVisitedLinkStore *)visitedLinkStore
385 {
386     _visitedLinkStore.set(visitedLinkStore);
387 }
388
389 #pragma clang diagnostic push
390 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
391
392 - (_WKWebsiteDataStore *)_websiteDataStore
393 {
394     return self.websiteDataStore ? adoptNS([[_WKWebsiteDataStore alloc] initWithDataStore:self.websiteDataStore]).autorelease() : nullptr;
395 }
396
397 - (void)_setWebsiteDataStore:(_WKWebsiteDataStore *)websiteDataStore
398 {
399     self.websiteDataStore = websiteDataStore ? websiteDataStore->_dataStore.get() : nullptr;
400 }
401
402 #pragma clang diagnostic pop
403
404 #if PLATFORM(IOS)
405 - (WKWebViewContentProviderRegistry *)_contentProviderRegistry
406 {
407     return _contentProviderRegistry.get([] { return adoptNS([[WKWebViewContentProviderRegistry alloc] init]); });
408 }
409
410 - (void)_setContentProviderRegistry:(WKWebViewContentProviderRegistry *)registry
411 {
412     _contentProviderRegistry.set(registry);
413 }
414 #endif
415
416 - (void)_validate
417 {
418     if (!self.processPool)
419         [NSException raise:NSInvalidArgumentException format:@"configuration.processPool is nil"];
420
421     if (!self.preferences)
422         [NSException raise:NSInvalidArgumentException format:@"configuration.preferences is nil"];
423
424     if (!self.userContentController)
425         [NSException raise:NSInvalidArgumentException format:@"configuration.userContentController is nil"];
426
427     if (!self.websiteDataStore)
428         [NSException raise:NSInvalidArgumentException format:@"configuration.websiteDataStore is nil"];
429
430     if (!self._visitedLinkStore)
431         [NSException raise:NSInvalidArgumentException format:@"configuration._visitedLinkStore is nil"];
432
433 #if PLATFORM(IOS)
434     if (!self._contentProviderRegistry)
435         [NSException raise:NSInvalidArgumentException format:@"configuration._contentProviderRegistry is nil"];
436 #endif
437 }
438
439 @end
440
441 @implementation WKWebViewConfiguration (WKPrivate)
442
443 - (WKWebView *)_relatedWebView
444 {
445     return _relatedWebView.getAutoreleased();
446 }
447
448 - (void)_setRelatedWebView:(WKWebView *)relatedWebView
449 {
450     _relatedWebView = relatedWebView;
451 }
452
453 - (WKWebView *)_alternateWebViewForNavigationGestures
454 {
455     return _alternateWebViewForNavigationGestures.getAutoreleased();
456 }
457
458 - (void)_setAlternateWebViewForNavigationGestures:(WKWebView *)alternateView
459 {
460     _alternateWebViewForNavigationGestures = alternateView;
461 }
462
463 - (NSString *)_groupIdentifier
464 {
465     return _groupIdentifier.get();
466 }
467
468 - (void)_setGroupIdentifier:(NSString *)groupIdentifier
469 {
470     _groupIdentifier = groupIdentifier;
471 }
472
473 - (BOOL)_treatsSHA1SignedCertificatesAsInsecure
474 {
475     return _treatsSHA1SignedCertificatesAsInsecure;
476 }
477
478 - (void)_setTreatsSHA1SignedCertificatesAsInsecure:(BOOL)insecure
479 {
480     _treatsSHA1SignedCertificatesAsInsecure = insecure;
481 }
482
483 - (BOOL)_respectsImageOrientation
484 {
485     return _respectsImageOrientation;
486 }
487
488 - (void)_setRespectsImageOrientation:(BOOL)respectsImageOrientation
489 {
490     _respectsImageOrientation = respectsImageOrientation;
491 }
492
493 - (BOOL)_printsBackgrounds
494 {
495     return _printsBackgrounds;
496 }
497
498 - (void)_setPrintsBackgrounds:(BOOL)printsBackgrounds
499 {
500     _printsBackgrounds = printsBackgrounds;
501 }
502
503 - (NSTimeInterval)_incrementalRenderingSuppressionTimeout
504 {
505     return _incrementalRenderingSuppressionTimeout;
506 }
507
508 - (void)_setIncrementalRenderingSuppressionTimeout:(NSTimeInterval)incrementalRenderingSuppressionTimeout
509 {
510     _incrementalRenderingSuppressionTimeout = incrementalRenderingSuppressionTimeout;
511 }
512
513 - (BOOL)_allowsJavaScriptMarkup
514 {
515     return _allowsJavaScriptMarkup;
516 }
517
518 - (void)_setAllowsJavaScriptMarkup:(BOOL)allowsJavaScriptMarkup
519 {
520     _allowsJavaScriptMarkup = allowsJavaScriptMarkup;
521 }
522
523 - (BOOL)_allowUniversalAccessFromFileURLs
524 {
525     return _allowUniversalAccessFromFileURLs;
526 }
527
528 - (void)_setAllowUniversalAccessFromFileURLs:(BOOL)allowUniversalAccessFromFileURLs
529 {
530     _allowUniversalAccessFromFileURLs = allowUniversalAccessFromFileURLs;
531 }
532
533 - (BOOL)_convertsPositionStyleOnCopy
534 {
535     return _convertsPositionStyleOnCopy;
536 }
537
538 - (void)_setConvertsPositionStyleOnCopy:(BOOL)convertsPositionStyleOnCopy
539 {
540     _convertsPositionStyleOnCopy = convertsPositionStyleOnCopy;
541 }
542
543 - (BOOL)_allowsMetaRefresh
544 {
545     return _allowsMetaRefresh;
546 }
547
548 - (void)_setAllowsMetaRefresh:(BOOL)allowsMetaRefresh
549 {
550     _allowsMetaRefresh = allowsMetaRefresh;
551 }
552
553 #if PLATFORM(IOS)
554 - (BOOL)_alwaysRunsAtForegroundPriority
555 {
556     return _alwaysRunsAtForegroundPriority;
557 }
558
559 - (void)_setAlwaysRunsAtForegroundPriority:(BOOL)alwaysRunsAtForegroundPriority
560 {
561     _alwaysRunsAtForegroundPriority = alwaysRunsAtForegroundPriority;
562 }
563
564 - (BOOL)_inlineMediaPlaybackRequiresPlaysInlineAttribute
565 {
566     return _inlineMediaPlaybackRequiresPlaysInlineAttribute;
567 }
568
569 - (void)_setInlineMediaPlaybackRequiresPlaysInlineAttribute:(BOOL)requires
570 {
571     _inlineMediaPlaybackRequiresPlaysInlineAttribute = requires;
572 }
573
574 - (BOOL)_allowsInlineMediaPlaybackAfterFullscreen
575 {
576     return _allowsInlineMediaPlaybackAfterFullscreen;
577 }
578
579 - (void)_setAllowsInlineMediaPlaybackAfterFullscreen:(BOOL)allows
580 {
581     _allowsInlineMediaPlaybackAfterFullscreen = allows;
582 }
583 #endif // PLATFORM(IOS)
584
585 - (BOOL)_invisibleAutoplayNotPermitted
586 {
587     return _invisibleAutoplayNotPermitted;
588 }
589
590 - (void)_setInvisibleAutoplayNotPermitted:(BOOL)notPermitted
591 {
592     _invisibleAutoplayNotPermitted = notPermitted;
593 }
594
595 - (BOOL)_mediaDataLoadsAutomatically
596 {
597     return _mediaDataLoadsAutomatically;
598 }
599
600 - (void)_setMediaDataLoadsAutomatically:(BOOL)mediaDataLoadsAutomatically
601 {
602     _mediaDataLoadsAutomatically = mediaDataLoadsAutomatically;
603 }
604
605 - (BOOL)_attachmentElementEnabled
606 {
607     return _attachmentElementEnabled;
608 }
609
610 - (void)_setAttachmentElementEnabled:(BOOL)attachmentElementEnabled
611 {
612     _attachmentElementEnabled = attachmentElementEnabled;
613 }
614
615 - (BOOL)_requiresUserActionForVideoPlayback
616 {
617     return self.mediaTypesRequiringUserActionForPlayback & WKAudiovisualMediaTypeVideo;
618 }
619
620 - (void)_setRequiresUserActionForVideoPlayback:(BOOL)requiresUserActionForVideoPlayback
621 {
622     if (requiresUserActionForVideoPlayback)
623         self.mediaTypesRequiringUserActionForPlayback |= WKAudiovisualMediaTypeVideo;
624     else
625         self.mediaTypesRequiringUserActionForPlayback &= ~WKAudiovisualMediaTypeVideo;
626 }
627
628 - (BOOL)_requiresUserActionForAudioPlayback
629 {
630     return self.mediaTypesRequiringUserActionForPlayback & WKAudiovisualMediaTypeAudio;
631 }
632
633 - (void)_setRequiresUserActionForAudioPlayback:(BOOL)requiresUserActionForAudioPlayback
634 {
635     if (requiresUserActionForAudioPlayback)
636         self.mediaTypesRequiringUserActionForPlayback |= WKAudiovisualMediaTypeAudio;
637     else
638         self.mediaTypesRequiringUserActionForPlayback &= ~WKAudiovisualMediaTypeAudio;
639 }
640
641 - (BOOL)_mainContentUserGestureOverrideEnabled
642 {
643     return _mainContentUserGestureOverrideEnabled;
644 }
645
646 - (void)_setMainContentUserGestureOverrideEnabled:(BOOL)mainContentUserGestureOverrideEnabled
647 {
648     _mainContentUserGestureOverrideEnabled = mainContentUserGestureOverrideEnabled;
649 }
650
651 - (BOOL)_initialCapitalizationEnabled
652 {
653     return _initialCapitalizationEnabled;
654 }
655
656 - (void)_setInitialCapitalizationEnabled:(BOOL)initialCapitalizationEnabled
657 {
658     _initialCapitalizationEnabled = initialCapitalizationEnabled;
659 }
660
661 - (BOOL)_shouldWaitForPaintAfterViewDidMoveToWindow
662 {
663     return _shouldWaitForPaintAfterViewDidMoveToWindow;
664 }
665
666 - (void)_setShouldWaitForPaintAfterViewDidMoveToWindow:(BOOL)shouldSynchronize
667 {
668     _shouldWaitForPaintAfterViewDidMoveToWindow = shouldSynchronize;
669 }
670
671 #if PLATFORM(MAC)
672 - (BOOL)_showsURLsInToolTips
673 {
674     return _showsURLsInToolTips;
675 }
676
677 - (void)_setShowsURLsInToolTips:(BOOL)showsURLsInToolTips
678 {
679     _showsURLsInToolTips = showsURLsInToolTips;
680 }
681
682 - (BOOL)_serviceControlsEnabled
683 {
684     return _serviceControlsEnabled;
685 }
686
687 - (void)_setServiceControlsEnabled:(BOOL)serviceControlsEnabled
688 {
689     _serviceControlsEnabled = serviceControlsEnabled;
690 }
691
692 - (BOOL)_imageControlsEnabled
693 {
694     return _imageControlsEnabled;
695 }
696
697 - (void)_setImageControlsEnabled:(BOOL)imageControlsEnabled
698 {
699     _imageControlsEnabled = imageControlsEnabled;
700 }
701
702 - (BOOL)_requiresUserActionForEditingControlsManager
703 {
704     return _requiresUserActionForEditingControlsManager;
705 }
706
707 - (void)_setRequiresUserActionForEditingControlsManager:(BOOL)requiresUserAction
708 {
709     _requiresUserActionForEditingControlsManager = requiresUserAction;
710 }
711
712 #endif // PLATFORM(MAC)
713
714 - (BOOL)_applePayEnabled
715 {
716 #if ENABLE(APPLE_PAY)
717     return _applePayEnabled;
718 #else
719     return NO;
720 #endif
721 }
722
723 - (void)_setApplePayEnabled:(BOOL)applePayEnabled
724 {
725 #if ENABLE(APPLE_PAY)
726     _applePayEnabled = applePayEnabled;
727 #endif
728 }
729
730 @end
731
732 @implementation WKWebViewConfiguration (WKDeprecated)
733
734 #if PLATFORM(IOS)
735 - (BOOL)mediaPlaybackAllowsAirPlay
736 {
737     return self.allowsAirPlayForMediaPlayback;
738 }
739
740 - (void)setMediaPlaybackAllowsAirPlay:(BOOL)allowed
741 {
742     self.allowsAirPlayForMediaPlayback = allowed;
743 }
744
745 - (BOOL)mediaPlaybackRequiresUserAction
746 {
747     return self.requiresUserActionForMediaPlayback;
748 }
749
750 - (void)setMediaPlaybackRequiresUserAction:(BOOL)required
751 {
752     self.requiresUserActionForMediaPlayback = required;
753 }
754
755 - (BOOL)requiresUserActionForMediaPlayback
756 {
757     return self.mediaTypesRequiringUserActionForPlayback == WKAudiovisualMediaTypeAll;
758 }
759
760 - (void)setRequiresUserActionForMediaPlayback:(BOOL)requiresUserActionForMediaPlayback
761 {
762     self.mediaTypesRequiringUserActionForPlayback = requiresUserActionForMediaPlayback ? WKAudiovisualMediaTypeAll : WKAudiovisualMediaTypeNone;
763 }
764
765 #endif // PLATFORM(IOS)
766
767 @end
768
769 @implementation WKWebViewConfiguration (WKBinaryCompatibilityWithIOS10)
770
771 -(_WKVisitedLinkStore *)_visitedLinkProvider
772 {
773     return self._visitedLinkStore;
774 }
775
776 - (void)_setVisitedLinkProvider:(_WKVisitedLinkStore *)visitedLinkProvider
777 {
778     self._visitedLinkStore = visitedLinkProvider;
779 }
780
781 @end
782
783 #endif // WK_API_ENABLED