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