feaddbcd1d0c74bb2eeea72aeea5b8a65226d37f
[WebKit-https.git] / Source / WebKit / NetworkProcess / ios / NetworkProcessIOS.mm
1 /*
2  * Copyright (C) 2013 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 "NetworkProcess.h"
28
29 #if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
30
31 #import "NetworkCache.h"
32 #import "NetworkProcessCreationParameters.h"
33 #import "ResourceCachesToClear.h"
34 #import "SandboxInitializationParameters.h"
35 #import "SecItemShim.h"
36 #import <WebCore/CertificateInfo.h>
37 #import <WebCore/NotImplemented.h>
38 #import <WebCore/WebCoreThreadSystemInterface.h>
39 #import <pal/spi/cf/CFNetworkSPI.h>
40 #import <wtf/cocoa/Entitlements.h>
41
42 #define ENABLE_MANUAL_NETWORK_SANDBOXING 0
43
44 namespace WebKit {
45 using namespace WebCore;
46
47 void NetworkProcess::initializeProcess(const AuxiliaryProcessInitializationParameters&)
48 {
49     InitWebCoreThreadSystemInterface();
50 }
51
52 void NetworkProcess::initializeProcessName(const AuxiliaryProcessInitializationParameters&)
53 {
54     notImplemented();
55 }
56
57 void NetworkProcess::initializeSandbox(const AuxiliaryProcessInitializationParameters& parameters, SandboxInitializationParameters& sandboxParameters)
58 {
59 #if ENABLE_MANUAL_NETWORK_SANDBOXING
60     // Need to override the default, because service has a different bundle ID.
61     NSBundle *webkit2Bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];
62     sandboxParameters.setOverrideSandboxProfilePath([webkit2Bundle pathForResource:@"com.apple.WebKit.NetworkProcess" ofType:@"sb"]);
63
64     AuxiliaryProcess::initializeSandbox(parameters, sandboxParameters);
65 #else
66     UNUSED_PARAM(parameters);
67     UNUSED_PARAM(sandboxParameters);
68 #endif
69 }
70
71 void NetworkProcess::allowSpecificHTTPSCertificateForHost(const CertificateInfo& certificateInfo, const String& host)
72 {
73     [NSURLRequest setAllowsSpecificHTTPSCertificate:(NSArray *)certificateInfo.certificateChain() forHost:host];
74 }
75
76 void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
77 {
78     ResourceCachesToClear resourceCachesToClear = static_cast<ResourceCachesToClear>(cachesToClear);
79     if (resourceCachesToClear == InMemoryResourceCachesOnly)
80         return;
81     forEachNetworkSession([](NetworkSession& session) {
82         if (auto* cache = session.cache())
83             cache->clear();
84     });
85 }
86
87 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
88 {
89 #if ENABLE(SEC_ITEM_SHIM)
90     // SecItemShim is needed for CFNetwork APIs that query Keychains beneath us.
91     initializeSecItemShim(*this);
92 #endif
93     platformInitializeNetworkProcessCocoa(parameters);
94 }
95
96 void NetworkProcess::platformTerminate()
97 {
98     notImplemented();
99 }
100
101 bool NetworkProcess::parentProcessHasServiceWorkerEntitlement() const
102 {
103     static bool hasEntitlement = WTF::hasEntitlement(parentProcessConnection()->xpcConnection(), "com.apple.developer.WebKit.ServiceWorkers");
104     return hasEntitlement;
105 }
106
107 } // namespace WebKit
108
109 #endif // PLATFORM(IOS_FAMILY)