2 * Copyright (C) 2014 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #import "WKWebViewConfigurationInternal.h"
31 #import "WKPreferences.h"
32 #import "WKProcessPool.h"
33 #import "WKUserContentController.h"
34 #import "WKWebViewContentProviderRegistry.h"
35 #import "WeakObjCPtr.h"
36 #import "_WKVisitedLinkProvider.h"
37 #import "_WKWebsiteDataStore.h"
38 #import <wtf/RetainPtr.h>
40 template<typename T> class LazyInitialized {
45 if (!m_isInitialized) {
47 m_isInitialized = true;
56 m_isInitialized = true;
65 bool m_isInitialized = false;
69 @implementation WKWebViewConfiguration {
70 LazyInitialized<WKProcessPool> _processPool;
71 LazyInitialized<WKPreferences> _preferences;
72 LazyInitialized<WKUserContentController> _userContentController;
73 LazyInitialized<_WKVisitedLinkProvider> _visitedLinkProvider;
74 LazyInitialized<_WKWebsiteDataStore> _websiteDataStore;
75 WebKit::WeakObjCPtr<WKWebView> _relatedWebView;
76 RetainPtr<NSString> _groupIdentifier;
78 LazyInitialized<WKWebViewContentProviderRegistry> _contentProviderRegistry;
82 - (NSString *)description
84 return [NSString stringWithFormat:@"<%@: %p; processPool = %@; preferences = %@>", NSStringFromClass(self.class), self, self.processPool, self.preferences];
87 - (id)copyWithZone:(NSZone *)zone
89 WKWebViewConfiguration *configuration = [[[self class] allocWithZone:zone] init];
91 configuration.processPool = self.processPool;
92 configuration.preferences = self.preferences;
93 configuration.userContentController = self.userContentController;
94 configuration._visitedLinkProvider = self._visitedLinkProvider;
95 configuration._websiteDataStore = self._websiteDataStore;
96 configuration._relatedWebView = _relatedWebView.get().get();
98 configuration._contentProviderRegistry = self._contentProviderRegistry;
101 configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
103 configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
104 configuration->_mediaPlaybackRequiresUserAction = self->_mediaPlaybackRequiresUserAction;
105 configuration->_mediaPlaybackAllowsAirPlay = self->_mediaPlaybackAllowsAirPlay;
108 return configuration;
111 - (WKProcessPool *)processPool
113 return _processPool.get([] { return adoptNS([[WKProcessPool alloc] init]); });
116 - (void)setProcessPool:(WKProcessPool *)processPool
118 _processPool.set(processPool);
121 - (WKPreferences *)preferences
123 return _preferences.get([] { return adoptNS([[WKPreferences alloc] init]); });
126 - (void)setPreferences:(WKPreferences *)preferences
128 _preferences.set(preferences);
131 - (WKUserContentController *)userContentController
133 return _userContentController.get([] { return adoptNS([[WKUserContentController alloc] init]); });
136 - (void)setUserContentController:(WKUserContentController *)userContentController
138 _userContentController.set(userContentController);
141 - (_WKVisitedLinkProvider *)_visitedLinkProvider
143 return _visitedLinkProvider.get([] { return adoptNS([[_WKVisitedLinkProvider alloc] init]); });
146 - (void)_setVisitedLinkProvider:(_WKVisitedLinkProvider *)visitedLinkProvider
148 _visitedLinkProvider.set(visitedLinkProvider);
151 - (_WKWebsiteDataStore *)_websiteDataStore
153 return _websiteDataStore.get([] { return [_WKWebsiteDataStore defaultDataStore]; });
156 - (void)_setWebsiteDataStore:(_WKWebsiteDataStore *)websiteDataStore
158 _websiteDataStore.set(websiteDataStore);
162 - (WKWebViewContentProviderRegistry *)_contentProviderRegistry
164 return _contentProviderRegistry.get([] { return adoptNS([[WKWebViewContentProviderRegistry alloc] init]); });
167 - (void)_setContentProviderRegistry:(WKWebViewContentProviderRegistry *)registry
169 _contentProviderRegistry.set(registry);
175 if (!self.processPool)
176 [NSException raise:NSInvalidArgumentException format:@"configuration.processPool is nil"];
178 if (!self.preferences)
179 [NSException raise:NSInvalidArgumentException format:@"configuration.preferences is nil"];
181 if (!self.userContentController)
182 [NSException raise:NSInvalidArgumentException format:@"configuration.userContentController is nil"];
184 if (!self._visitedLinkProvider)
185 [NSException raise:NSInvalidArgumentException format:@"configuration._visitedLinkProvider is nil"];
187 if (!self._websiteDataStore)
188 [NSException raise:NSInvalidArgumentException format:@"configuration._websiteDataStore is nil"];
191 if (!self._contentProviderRegistry)
192 [NSException raise:NSInvalidArgumentException format:@"configuration._contentProviderRegistry is nil"];
198 @implementation WKWebViewConfiguration (WKPrivate)
200 - (WKWebView *)_relatedWebView
202 return _relatedWebView.getAutoreleased();
205 - (void)_setRelatedWebView:(WKWebView *)relatedWebView
207 _relatedWebView = relatedWebView;
210 - (NSString *)_groupIdentifier
212 return _groupIdentifier.get();
215 - (void)_setGroupIdentifier:(NSString *)groupIdentifier
217 _groupIdentifier = groupIdentifier;
222 #endif // WK_API_ENABLED