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