Move logCookieInformation bool from NetworkProcess to NetworkSession
[WebKit-https.git] / Source / WebKit / UIProcess / Cocoa / WebProcessPoolCocoa.mm
1 /*
2  * Copyright (C) 2010-2018 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 "WebProcessPool.h"
28
29 #import "CookieStorageUtilsCF.h"
30 #import "LegacyCustomProtocolManagerClient.h"
31 #import "NetworkProcessCreationParameters.h"
32 #import "NetworkProcessMessages.h"
33 #import "NetworkProcessProxy.h"
34 #import "PluginProcessManager.h"
35 #import "SandboxUtilities.h"
36 #import "TextChecker.h"
37 #import "VersionChecks.h"
38 #import "WKBrowsingContextControllerInternal.h"
39 #import "WebMemoryPressureHandlerCocoa.h"
40 #import "WebPageGroup.h"
41 #import "WebPreferencesKeys.h"
42 #import "WebProcessCreationParameters.h"
43 #import "WebProcessMessages.h"
44 #import "WindowServerConnection.h"
45 #import <WebCore/Color.h>
46 #import <WebCore/FileSystem.h>
47 #import <WebCore/NetworkStorageSession.h>
48 #import <WebCore/NotImplemented.h>
49 #import <WebCore/PlatformPasteboard.h>
50 #import <WebCore/RuntimeApplicationChecks.h>
51 #import <WebCore/SharedBuffer.h>
52 #import <pal/spi/cf/CFNetworkSPI.h>
53 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
54 #import <sys/param.h>
55 #import <wtf/ProcessPrivilege.h>
56 #import <wtf/cocoa/Entitlements.h>
57 #import <wtf/spi/darwin/dyldSPI.h>
58
59 #if PLATFORM(MAC)
60 #import <QuartzCore/CARemoteLayerServer.h>
61 #endif
62
63 NSString *WebServiceWorkerRegistrationDirectoryDefaultsKey = @"WebServiceWorkerRegistrationDirectory";
64 NSString *WebKitLocalCacheDefaultsKey = @"WebKitLocalCache";
65 NSString *WebKitJSCJITEnabledDefaultsKey = @"WebKitJSCJITEnabledDefaultsKey";
66 NSString *WebKitJSCFTLJITEnabledDefaultsKey = @"WebKitJSCFTLJITEnabledDefaultsKey";
67
68 #if !PLATFORM(IOS_FAMILY)
69 static NSString *WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification = @"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
70 #endif
71
72 static NSString * const WebKit2HTTPProxyDefaultsKey = @"WebKit2HTTPProxy";
73 static NSString * const WebKit2HTTPSProxyDefaultsKey = @"WebKit2HTTPSProxy";
74
75 static NSString * const WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey = @"WebKitNetworkCacheEfficacyLoggingEnabled";
76
77 static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
78 static NSString * const WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey = @"WebKitNetworkLoadThrottleLatencyMilliseconds";
79
80 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
81 static NSString * const WebKitLogCookieInformationDefaultsKey = @"WebKitLogCookieInformation";
82 #endif
83
84 #if ENABLE(NETWORK_CAPTURE)
85 static NSString * const WebKitRecordReplayModeDefaultsKey = @"WebKitRecordReplayMode";
86 static NSString * const WebKitRecordReplayCacheLocationDefaultsKey = @"WebKitRecordReplayCacheLocation";
87 #endif
88
89 namespace WebKit {
90 using namespace WebCore;
91
92 static void registerUserDefaultsIfNeeded()
93 {
94     static bool didRegister;
95     if (didRegister)
96         return;
97
98     didRegister = true;
99     NSMutableDictionary *registrationDictionary = [NSMutableDictionary dictionary];
100     
101     [registrationDictionary setObject:@YES forKey:WebKitJSCJITEnabledDefaultsKey];
102     [registrationDictionary setObject:@YES forKey:WebKitJSCFTLJITEnabledDefaultsKey];
103
104     [registrationDictionary setObject:@NO forKey:WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey];
105
106     [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDictionary];
107 }
108
109 void WebProcessPool::updateProcessSuppressionState()
110 {
111     if (m_networkProcess)
112         m_networkProcess->setProcessSuppressionEnabled(processSuppressionEnabled());
113
114 #if ENABLE(NETSCAPE_PLUGIN_API)
115     if (!m_processSuppressionDisabledForPageCounter.value())
116         m_pluginProcessManagerProcessSuppressionDisabledToken = nullptr;
117     else if (!m_pluginProcessManagerProcessSuppressionDisabledToken)
118         m_pluginProcessManagerProcessSuppressionDisabledToken = PluginProcessManager::singleton().processSuppressionDisabledToken();
119 #endif
120 }
121
122 NSMutableDictionary *WebProcessPool::ensureBundleParameters()
123 {
124     if (!m_bundleParameters)
125         m_bundleParameters = adoptNS([[NSMutableDictionary alloc] init]);
126
127     return m_bundleParameters.get();
128 }
129
130 void WebProcessPool::platformInitialize()
131 {
132     registerUserDefaultsIfNeeded();
133     registerNotificationObservers();
134
135     installMemoryPressureHandler();
136
137     setLegacyCustomProtocolManagerClient(std::make_unique<LegacyCustomProtocolManagerClient>());
138 }
139
140 #if PLATFORM(IOS_FAMILY)
141 String WebProcessPool::cookieStorageDirectory() const
142 {
143     String path = pathForProcessContainer();
144     if (path.isEmpty())
145         path = NSHomeDirectory();
146
147     path = path + "/Library/Cookies";
148     path = stringByResolvingSymlinksInPath(path);
149     return path;
150 }
151 #endif
152
153 void WebProcessPool::platformResolvePathsForSandboxExtensions()
154 {
155     m_resolvedPaths.uiProcessBundleResourcePath = resolvePathForSandboxExtension([[NSBundle mainBundle] resourcePath]);
156
157 #if PLATFORM(IOS_FAMILY)
158     m_resolvedPaths.cookieStorageDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(cookieStorageDirectory());
159     m_resolvedPaths.containerCachesDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(webContentCachesDirectory());
160     m_resolvedPaths.containerTemporaryDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(containerTemporaryDirectory());
161 #endif
162 }
163
164 void WebProcessPool::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
165 {
166 #if PLATFORM(MAC)
167     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
168     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
169     parameters.accessibilityEnhancedUserInterfaceEnabled = [[NSApp accessibilityAttributeValue:@"AXEnhancedUserInterface"] boolValue];
170     ALLOW_DEPRECATED_DECLARATIONS_END
171 #else
172     parameters.accessibilityEnhancedUserInterfaceEnabled = false;
173 #endif
174
175     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
176
177     parameters.shouldEnableJIT = [defaults boolForKey:WebKitJSCJITEnabledDefaultsKey];
178     parameters.shouldEnableFTLJIT = [defaults boolForKey:WebKitJSCFTLJITEnabledDefaultsKey];
179     parameters.shouldEnableMemoryPressureReliefLogging = [defaults boolForKey:@"LogMemoryJetsamDetails"];
180     parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
181
182 #if HAVE(HOSTED_CORE_ANIMATION)
183 #if !PLATFORM(IOS_FAMILY)
184     parameters.acceleratedCompositingPort = MachSendRight::create([CARemoteLayerServer sharedServer].serverPort);
185 #endif
186 #endif
187
188     // FIXME: This should really be configurable; we shouldn't just blindly allow read access to the UI process bundle.
189     parameters.uiProcessBundleResourcePath = m_resolvedPaths.uiProcessBundleResourcePath;
190     SandboxExtension::createHandleWithoutResolvingPath(parameters.uiProcessBundleResourcePath, SandboxExtension::Type::ReadOnly, parameters.uiProcessBundleResourcePathExtensionHandle);
191
192     parameters.uiProcessBundleIdentifier = String([[NSBundle mainBundle] bundleIdentifier]);
193     parameters.uiProcessSDKVersion = dyld_get_program_sdk_version();
194
195 #if PLATFORM(IOS_FAMILY)
196     if (!m_resolvedPaths.cookieStorageDirectory.isEmpty())
197         SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.cookieStorageDirectory, SandboxExtension::Type::ReadWrite, parameters.cookieStorageDirectoryExtensionHandle);
198
199     if (!m_resolvedPaths.containerCachesDirectory.isEmpty())
200         SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.containerCachesDirectory, SandboxExtension::Type::ReadWrite, parameters.containerCachesDirectoryExtensionHandle);
201
202     if (!m_resolvedPaths.containerTemporaryDirectory.isEmpty())
203         SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.containerTemporaryDirectory, SandboxExtension::Type::ReadWrite, parameters.containerTemporaryDirectoryExtensionHandle);
204 #endif
205
206     parameters.fontWhitelist = m_fontWhitelist;
207
208     if (m_bundleParameters) {
209         auto keyedArchiver = secureArchiver();
210
211         @try {
212             [keyedArchiver encodeObject:m_bundleParameters.get() forKey:@"parameters"];
213             [keyedArchiver finishEncoding];
214         } @catch (NSException *exception) {
215             LOG_ERROR("Failed to encode bundle parameters: %@", exception);
216         }
217
218         auto data = keyedArchiver.get().encodedData;
219
220         parameters.bundleParameterData = API::Data::createWithoutCopying(WTFMove(data));
221     }
222     parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
223
224 #if PLATFORM(MAC)
225     ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
226     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
227     parameters.uiProcessCookieStorageIdentifier = identifyingDataFromCookieStorage([[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]);
228 #endif
229 #if ENABLE(MEDIA_STREAM)
230     // Allow microphone access if either preference is set because WebRTC requires microphone access.
231     bool mediaDevicesEnabled = m_defaultPageGroup->preferences().mediaDevicesEnabled();
232     bool webRTCEnabled = m_defaultPageGroup->preferences().peerConnectionEnabled();
233     if ([defaults objectForKey:@"ExperimentalPeerConnectionEnabled"])
234         webRTCEnabled = [defaults boolForKey:@"ExperimentalPeerConnectionEnabled"];
235
236     bool isSafari = false;
237 #if PLATFORM(IOS_FAMILY)
238     if (WebCore::IOSApplication::isMobileSafari())
239         isSafari = true;
240 #elif PLATFORM(MAC)
241     if (WebCore::MacApplication::isSafari())
242         isSafari = true;
243 #endif
244
245 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
246     parameters.webCoreLoggingChannels = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebCoreLogging"];
247     parameters.webKitLoggingChannels = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebKit2Logging"];
248 #endif
249
250     // FIXME: Remove this and related parameter when <rdar://problem/29448368> is fixed.
251     if (isSafari && !parameters.shouldCaptureAudioInUIProcess && mediaDevicesEnabled)
252         SandboxExtension::createHandleForGenericExtension("com.apple.webkit.microphone", parameters.audioCaptureExtensionHandle);
253 #endif
254
255 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
256     parameters.shouldLogUserInteraction = [defaults boolForKey:WebKitLogCookieInformationDefaultsKey];
257 #endif
258     
259 #if PLATFORM(MAC)
260     auto screenProperties = WebCore::collectScreenProperties();
261     parameters.screenProperties = WTFMove(screenProperties);
262     parameters.useOverlayScrollbars = ([NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay);
263 #endif
264 }
265
266 void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters)
267 {
268     parameters.uiProcessBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
269     parameters.uiProcessSDKVersion = dyld_get_program_sdk_version();
270
271     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
272
273     parameters.httpProxy = [defaults stringForKey:WebKit2HTTPProxyDefaultsKey];
274     parameters.httpsProxy = [defaults stringForKey:WebKit2HTTPSProxyDefaultsKey];
275     parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
276
277     parameters.shouldEnableNetworkCacheEfficacyLogging = [defaults boolForKey:WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey];
278
279     parameters.sourceApplicationBundleIdentifier = m_configuration->sourceApplicationBundleIdentifier();
280     parameters.sourceApplicationSecondaryIdentifier = m_configuration->sourceApplicationSecondaryIdentifier();
281 #if PLATFORM(IOS_FAMILY)
282     parameters.ctDataConnectionServiceType = m_configuration->ctDataConnectionServiceType();
283 #endif
284
285     parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
286     parameters.loadThrottleLatency = Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. };
287
288 #if PLATFORM(MAC)
289     ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
290     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
291     parameters.uiProcessCookieStorageIdentifier = identifyingDataFromCookieStorage([[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]);
292 #endif
293
294     parameters.storageAccessAPIEnabled = storageAccessAPIEnabled();
295     parameters.suppressesConnectionTerminationOnSystemChange = m_configuration->suppressesConnectionTerminationOnSystemChange();
296
297 #if ENABLE(NETWORK_CAPTURE)
298     parameters.recordReplayMode = [defaults stringForKey:WebKitRecordReplayModeDefaultsKey];
299     parameters.recordReplayCacheLocation = [defaults stringForKey:WebKitRecordReplayCacheLocationDefaultsKey];
300     if (parameters.recordReplayCacheLocation.isEmpty())
301         parameters.recordReplayCacheLocation = parameters.diskCacheDirectory;
302 #endif
303
304 #if ENABLE(PROXIMITY_NETWORKING)
305     parameters.wirelessContextIdentifier = m_configuration->wirelessContextIdentifier();
306 #endif
307 }
308
309 void WebProcessPool::platformInvalidateContext()
310 {
311     unregisterNotificationObservers();
312 }
313
314 #if PLATFORM(IOS_FAMILY)
315 String WebProcessPool::parentBundleDirectory() const
316 {
317     return [[[NSBundle mainBundle] bundlePath] stringByStandardizingPath];
318 }
319
320 String WebProcessPool::networkingCachesDirectory() const
321 {
322     String path = pathForProcessContainer();
323     if (path.isEmpty())
324         path = NSHomeDirectory();
325
326     path = path + "/Library/Caches/com.apple.WebKit.Networking/";
327     path = stringByResolvingSymlinksInPath(path);
328
329     NSError *error = nil;
330     NSString* nsPath = path;
331     if (![[NSFileManager defaultManager] createDirectoryAtPath:nsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
332         NSLog(@"could not create networking caches directory \"%@\", error %@", nsPath, error);
333         return String();
334     }
335
336     return path;
337 }
338
339 String WebProcessPool::webContentCachesDirectory() const
340 {
341     String path = pathForProcessContainer();
342     if (path.isEmpty())
343         path = NSHomeDirectory();
344
345     path = path + "/Library/Caches/com.apple.WebKit.WebContent/";
346     path = stringByResolvingSymlinksInPath(path);
347
348     NSError *error = nil;
349     NSString* nsPath = path;
350     if (![[NSFileManager defaultManager] createDirectoryAtPath:nsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
351         NSLog(@"could not create web content caches directory \"%@\", error %@", nsPath, error);
352         return String();
353     }
354
355     return path;
356 }
357
358 String WebProcessPool::containerTemporaryDirectory() const
359 {
360     String path = NSTemporaryDirectory();
361     return stringByResolvingSymlinksInPath(path);
362 }
363 #endif
364
365 #if PLATFORM(IOS_FAMILY)
366 void WebProcessPool::setJavaScriptConfigurationFileEnabledFromDefaults()
367 {
368     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
369
370     setJavaScriptConfigurationFileEnabled([defaults boolForKey:@"WebKitJavaScriptCoreUseConfigFile"]);
371 }
372 #endif
373
374 bool WebProcessPool::omitPDFSupport()
375 {
376     // Since this is a "secret default" we don't bother registering it.
377     return [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
378 }
379
380 bool WebProcessPool::processSuppressionEnabled() const
381 {
382     return !m_userObservablePageCounter.value() && !m_processSuppressionDisabledForPageCounter.value();
383 }
384
385 bool WebProcessPool::networkProcessHasEntitlementForTesting(const String& entitlement)
386 {
387     return WTF::hasEntitlement(ensureNetworkProcess().connection()->xpcConnection(), entitlement.utf8().data());
388 }
389
390 void WebProcessPool::registerNotificationObservers()
391 {
392 #if !PLATFORM(IOS_FAMILY)
393     // Listen for enhanced accessibility changes and propagate them to the WebProcess.
394     m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
395         setEnhancedAccessibility([[[note userInfo] objectForKey:@"AXEnhancedUserInterface"] boolValue]);
396     }];
397
398     m_automaticTextReplacementNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticTextReplacementNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
399         TextChecker::didChangeAutomaticTextReplacementEnabled();
400         textCheckerStateChanged();
401     }];
402     
403     m_automaticSpellingCorrectionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
404         TextChecker::didChangeAutomaticSpellingCorrectionEnabled();
405         textCheckerStateChanged();
406     }];
407
408     m_automaticQuoteSubstitutionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticQuoteSubstitutionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
409         TextChecker::didChangeAutomaticQuoteSubstitutionEnabled();
410         textCheckerStateChanged();
411     }];
412
413     m_automaticDashSubstitutionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticDashSubstitutionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
414         TextChecker::didChangeAutomaticDashSubstitutionEnabled();
415         textCheckerStateChanged();
416     }];
417
418     m_accessibilityDisplayOptionsNotificationObserver = [[NSWorkspace.sharedWorkspace notificationCenter] addObserverForName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
419         screenPropertiesStateChanged();
420     }];
421
422 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
423     m_scrollerStyleNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSPreferredScrollerStyleDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
424         auto scrollbarStyle = [NSScroller preferredScrollerStyle];
425         sendToAllProcesses(Messages::WebProcess::ScrollerStylePreferenceChanged(scrollbarStyle));
426     }];
427 #endif
428
429 #endif // !PLATFORM(IOS_FAMILY)
430 }
431
432 void WebProcessPool::unregisterNotificationObservers()
433 {
434 #if !PLATFORM(IOS_FAMILY)
435     [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];    
436     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticTextReplacementNotificationObserver.get()];
437     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticSpellingCorrectionNotificationObserver.get()];
438     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticQuoteSubstitutionNotificationObserver.get()];
439     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticDashSubstitutionNotificationObserver.get()];
440     [[NSWorkspace.sharedWorkspace notificationCenter] removeObserver:m_accessibilityDisplayOptionsNotificationObserver.get()];
441 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
442     [[NSNotificationCenter defaultCenter] removeObserver:m_scrollerStyleNotificationObserver.get()];
443 #endif
444 #endif // !PLATFORM(IOS_FAMILY)
445 }
446
447 static CFURLStorageSessionRef privateBrowsingSession()
448 {
449     static CFURLStorageSessionRef session;
450     static dispatch_once_t once;
451     dispatch_once(&once, ^{
452         NSString *identifier = [NSString stringWithFormat:@"%@.PrivateBrowsing", [[NSBundle mainBundle] bundleIdentifier]];
453         session = createPrivateStorageSession((__bridge CFStringRef)identifier);
454     });
455
456     return session;
457 }
458
459 bool WebProcessPool::isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const
460 {
461     RetainPtr<CFURLRef> url = URL(URL(), urlString).createCFURL();
462
463     return _CFNetworkIsKnownHSTSHostWithSession(url.get(), privateBrowsingEnabled ? privateBrowsingSession() : nullptr);
464 }
465
466 void WebProcessPool::resetHSTSHosts()
467 {
468     _CFNetworkResetHSTSHostsWithSession(nullptr);
469     _CFNetworkResetHSTSHostsWithSession(privateBrowsingSession());
470 }
471
472 void WebProcessPool::resetHSTSHostsAddedAfterDate(double startDateIntervalSince1970)
473 {
474     NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:startDateIntervalSince1970];
475     _CFNetworkResetHSTSHostsSinceDate(nullptr, (__bridge CFDateRef)startDate);
476     _CFNetworkResetHSTSHostsSinceDate(privateBrowsingSession(), (__bridge CFDateRef)startDate);
477 }
478
479 // FIXME: Deprecated. Left here until a final decision is made.
480 void WebProcessPool::setCookieStoragePartitioningEnabled(bool enabled)
481 {
482     m_cookieStoragePartitioningEnabled = enabled;
483 }
484
485 void WebProcessPool::setStorageAccessAPIEnabled(bool enabled)
486 {
487     m_storageAccessAPIEnabled = enabled;
488     sendToNetworkingProcess(Messages::NetworkProcess::SetStorageAccessAPIEnabled(enabled));
489 }
490
491 int networkProcessLatencyQOS()
492 {
493     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitNetworkProcessLatencyQOS"];
494     return qos;
495 }
496
497 int networkProcessThroughputQOS()
498 {
499     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitNetworkProcessThroughputQOS"];
500     return qos;
501 }
502
503 int webProcessLatencyQOS()
504 {
505     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitWebProcessLatencyQOS"];
506     return qos;
507 }
508
509 int webProcessThroughputQOS()
510 {
511     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitWebProcessThroughputQOS"];
512     return qos;
513 }
514
515 } // namespace WebKit