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