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 WebKit::WeakObjCPtr<WKWebView> _alternateWebViewForNavigationGestures;
77 RetainPtr<NSString> _groupIdentifier;
79 LazyInitialized<WKWebViewContentProviderRegistry> _contentProviderRegistry;
85 if (!(self = [super init]))
89 _mediaPlaybackRequiresUserAction = YES;
90 _mediaPlaybackAllowsAirPlay = YES;
96 - (NSString *)description
98 return [NSString stringWithFormat:@"<%@: %p; processPool = %@; preferences = %@>", NSStringFromClass(self.class), self, self.processPool, self.preferences];
101 - (id)copyWithZone:(NSZone *)zone
103 WKWebViewConfiguration *configuration = [[[self class] allocWithZone:zone] init];
105 configuration.processPool = self.processPool;
106 configuration.preferences = self.preferences;
107 configuration.userContentController = self.userContentController;
108 configuration._visitedLinkProvider = self._visitedLinkProvider;
109 configuration._websiteDataStore = self._websiteDataStore;
110 configuration._relatedWebView = _relatedWebView.get().get();
111 configuration._alternateWebViewForNavigationGestures = _alternateWebViewForNavigationGestures.get().get();
113 configuration._contentProviderRegistry = self._contentProviderRegistry;
116 configuration->_suppressesIncrementalRendering = self->_suppressesIncrementalRendering;
118 configuration->_allowsInlineMediaPlayback = self->_allowsInlineMediaPlayback;
119 configuration->_mediaPlaybackRequiresUserAction = self->_mediaPlaybackRequiresUserAction;
120 configuration->_mediaPlaybackAllowsAirPlay = self->_mediaPlaybackAllowsAirPlay;
121 configuration->_selectionGranularity = self->_selectionGranularity;
124 return configuration;
127 - (WKProcessPool *)processPool
129 return _processPool.get([] { return adoptNS([[WKProcessPool alloc] init]); });
132 - (void)setProcessPool:(WKProcessPool *)processPool
134 _processPool.set(processPool);
137 - (WKPreferences *)preferences
139 return _preferences.get([] { return adoptNS([[WKPreferences alloc] init]); });
142 - (void)setPreferences:(WKPreferences *)preferences
144 _preferences.set(preferences);
147 - (WKUserContentController *)userContentController
149 return _userContentController.get([] { return adoptNS([[WKUserContentController alloc] init]); });
152 - (void)setUserContentController:(WKUserContentController *)userContentController
154 _userContentController.set(userContentController);
157 - (_WKVisitedLinkProvider *)_visitedLinkProvider
159 return _visitedLinkProvider.get([] { return adoptNS([[_WKVisitedLinkProvider alloc] init]); });
162 - (void)_setVisitedLinkProvider:(_WKVisitedLinkProvider *)visitedLinkProvider
164 _visitedLinkProvider.set(visitedLinkProvider);
167 - (_WKWebsiteDataStore *)_websiteDataStore
169 return _websiteDataStore.get([] { return [_WKWebsiteDataStore defaultDataStore]; });
172 - (void)_setWebsiteDataStore:(_WKWebsiteDataStore *)websiteDataStore
174 _websiteDataStore.set(websiteDataStore);
178 - (WKWebViewContentProviderRegistry *)_contentProviderRegistry
180 return _contentProviderRegistry.get([] { return adoptNS([[WKWebViewContentProviderRegistry alloc] init]); });
183 - (void)_setContentProviderRegistry:(WKWebViewContentProviderRegistry *)registry
185 _contentProviderRegistry.set(registry);
191 if (!self.processPool)
192 [NSException raise:NSInvalidArgumentException format:@"configuration.processPool is nil"];
194 if (!self.preferences)
195 [NSException raise:NSInvalidArgumentException format:@"configuration.preferences is nil"];
197 if (!self.userContentController)
198 [NSException raise:NSInvalidArgumentException format:@"configuration.userContentController is nil"];
200 if (!self._visitedLinkProvider)
201 [NSException raise:NSInvalidArgumentException format:@"configuration._visitedLinkProvider is nil"];
203 if (!self._websiteDataStore)
204 [NSException raise:NSInvalidArgumentException format:@"configuration._websiteDataStore is nil"];
207 if (!self._contentProviderRegistry)
208 [NSException raise:NSInvalidArgumentException format:@"configuration._contentProviderRegistry is nil"];
214 @implementation WKWebViewConfiguration (WKPrivate)
216 - (WKWebView *)_relatedWebView
218 return _relatedWebView.getAutoreleased();
221 - (void)_setRelatedWebView:(WKWebView *)relatedWebView
223 _relatedWebView = relatedWebView;
226 - (WKWebView *)_alternateWebViewForNavigationGestures
228 return _alternateWebViewForNavigationGestures.getAutoreleased();
231 - (void)_setAlternateWebViewForNavigationGestures:(WKWebView *)alternateView
233 _alternateWebViewForNavigationGestures = alternateView;
236 - (NSString *)_groupIdentifier
238 return _groupIdentifier.get();
241 - (void)_setGroupIdentifier:(NSString *)groupIdentifier
243 _groupIdentifier = groupIdentifier;
248 #endif // WK_API_ENABLED