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 "WKProcessPoolInternal.h"
31 #import "CacheModel.h"
32 #import "HistoryClient.h"
33 #import "ProcessModel.h"
35 #import "WKProcessPoolConfigurationPrivate.h"
36 #import "WebCertificateInfo.h"
37 #import "WebContext.h"
38 #import "WebCookieManagerProxy.h"
39 #import "WebProcessMessages.h"
40 #import <WebCore/CertificateInfo.h>
41 #import <wtf/RetainPtr.h>
44 #import <WebCore/WebCoreThreadSystemInterface.h>
47 #if __has_include(<CFNetwork/CFNSURLConnection.h>)
48 #import <CFNetwork/CFNSURLConnection.h>
51 NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
55 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED == 1080
56 @interface NSKeyedArchiver (WKDetails)
57 - (void)setRequiresSecureCoding:(BOOL)b;
61 @implementation WKProcessPool
65 return [self _initWithConfiguration:adoptNS([[_WKProcessPoolConfiguration alloc] init]).get()];
70 _context->~WebContext();
75 - (NSString *)description
77 return [NSString stringWithFormat:@"<%@: %p; configuration = %@>", NSStringFromClass(self.class), self, _configuration.get()];
80 - (_WKProcessPoolConfiguration *)_configuration
82 return [[_configuration copy] autorelease];
85 - (API::Object&)_apiObject
92 @implementation WKProcessPool (WKPrivate)
94 - (instancetype)_initWithConfiguration:(_WKProcessPoolConfiguration *)configuration
96 if (!(self = [super init]))
99 _configuration = adoptNS([configuration copy]);
102 // FIXME: Remove once <rdar://problem/15256572> is fixed.
103 InitWebCoreThreadSystemInterface();
107 if (NSURL *bundleURL = [_configuration injectedBundleURL]) {
108 if (!bundleURL.isFileURL)
109 [NSException raise:NSInvalidArgumentException format:@"Injected Bundle URL must be a file URL"];
111 bundlePath = bundleURL.path;
114 API::Object::constructInWrapper<WebKit::WebContext>(self, bundlePath);
115 _context->setHistoryClient(std::make_unique<WebKit::HistoryClient>());
116 _context->setUsesNetworkProcess(true);
117 _context->setProcessModel(WebKit::ProcessModelMultipleSecondaryProcesses);
119 // FIXME: Add a way to configure the cache model, see <rdar://problem/16206857>.
120 _context->setCacheModel(WebKit::CacheModelPrimaryWebBrowser);
125 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host
127 _context->allowSpecificHTTPSCertificateForHost(WebKit::WebCertificateInfo::create(WebCore::CertificateInfo((CFArrayRef)certificateChain)).get(), host);
130 static WebKit::HTTPCookieAcceptPolicy toHTTPCookieAcceptPolicy(NSHTTPCookieAcceptPolicy policy)
132 switch (static_cast<NSUInteger>(policy)) {
133 case NSHTTPCookieAcceptPolicyAlways:
134 return WebKit::HTTPCookieAcceptPolicyAlways;
135 case NSHTTPCookieAcceptPolicyNever:
136 return WebKit::HTTPCookieAcceptPolicyNever;
137 case NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain:
138 return WebKit::HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
139 case NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain:
140 return WebKit::HTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain;
143 ASSERT_NOT_REACHED();
144 return WebKit::HTTPCookieAcceptPolicyAlways;
147 - (void)_setCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
149 _context->supplement<WebKit::WebCookieManagerProxy>()->setHTTPCookieAcceptPolicy(toHTTPCookieAcceptPolicy(policy));
152 - (id)_objectForBundleParameter:(NSString *)parameter
154 return [_context->bundleParameters() objectForKey:parameter];
157 - (void)_setObject:(id <NSCopying, NSSecureCoding>)object forBundleParameter:(NSString *)parameter
159 auto copy = adoptNS([(NSObject *)object copy]);
161 auto data = adoptNS([[NSMutableData alloc] init]);
162 auto keyedArchiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);
163 [keyedArchiver setRequiresSecureCoding:YES];
166 [keyedArchiver encodeObject:copy.get() forKey:@"parameter"];
167 [keyedArchiver finishEncoding];
168 } @catch (NSException *exception) {
169 LOG_ERROR("Failed to encode bundle parameter: %@", exception);
172 [_context->ensureBundleParameters() setObject:copy.get() forKey:parameter];
173 _context->sendToAllProcesses(Messages::WebProcess::SetInjectedBundleParameter(parameter, IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length])));
178 #endif // WK_API_ENABLED