Use unified build for UIProcess
[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 = retainPtr(keyedArchiver.get().encodedData);
230 #endif
231
232         parameters.bundleParameterData = API::Data::createWithoutCopying((const unsigned char*)[data bytes], [data length], [] (unsigned char*, const void* data) {
233             [(NSData *)data release];
234         }, data.leakRef());
235     }
236     parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
237
238 #if PLATFORM(MAC)
239     ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
240     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
241     parameters.uiProcessCookieStorageIdentifier = identifyingDataFromCookieStorage([[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]);
242 #endif
243 #if ENABLE(MEDIA_STREAM)
244     // Allow microphone access if either preference is set because WebRTC requires microphone access.
245     bool mediaDevicesEnabled = m_defaultPageGroup->preferences().mediaDevicesEnabled();
246     bool webRTCEnabled = m_defaultPageGroup->preferences().peerConnectionEnabled();
247     if ([defaults objectForKey:@"ExperimentalPeerConnectionEnabled"])
248         webRTCEnabled = [defaults boolForKey:@"ExperimentalPeerConnectionEnabled"];
249
250     bool isSafari = false;
251 #if PLATFORM(IOS)
252     if (WebCore::IOSApplication::isMobileSafari())
253         isSafari = true;
254 #elif PLATFORM(MAC)
255     if (WebCore::MacApplication::isSafari())
256         isSafari = true;
257 #endif
258
259 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
260     parameters.webCoreLoggingChannels = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebCoreLogging"];
261     parameters.webKitLoggingChannels = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebKit2Logging"];
262 #endif
263
264     // FIXME: Remove this and related parameter when <rdar://problem/29448368> is fixed.
265     if (isSafari && !parameters.shouldCaptureAudioInUIProcess && mediaDevicesEnabled)
266         SandboxExtension::createHandleForGenericExtension("com.apple.webkit.microphone", parameters.audioCaptureExtensionHandle);
267 #endif
268
269 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
270     parameters.shouldLogUserInteraction = [defaults boolForKey:WebKitLogCookieInformationDefaultsKey];
271 #endif
272     
273 #if PLATFORM(MAC)
274     auto screenProperties = WebCore::collectScreenProperties();
275     parameters.screenProperties = WTFMove(screenProperties);
276     parameters.useOverlayScrollbars = ([NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay);
277 #endif
278 }
279
280 void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters)
281 {
282     parameters.uiProcessBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
283     parameters.uiProcessSDKVersion = dyld_get_program_sdk_version();
284
285     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
286
287     parameters.httpProxy = [defaults stringForKey:WebKit2HTTPProxyDefaultsKey];
288     parameters.httpsProxy = [defaults stringForKey:WebKit2HTTPSProxyDefaultsKey];
289     parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
290
291     parameters.shouldEnableNetworkCacheEfficacyLogging = [defaults boolForKey:WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey];
292
293     parameters.sourceApplicationBundleIdentifier = m_configuration->sourceApplicationBundleIdentifier();
294     parameters.sourceApplicationSecondaryIdentifier = m_configuration->sourceApplicationSecondaryIdentifier();
295 #if PLATFORM(IOS)
296     parameters.ctDataConnectionServiceType = m_configuration->ctDataConnectionServiceType();
297 #endif
298
299     parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
300     parameters.loadThrottleLatency = Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. };
301
302 #if PLATFORM(MAC)
303     ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
304     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
305     parameters.uiProcessCookieStorageIdentifier = identifyingDataFromCookieStorage([[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]);
306 #endif
307
308     parameters.storageAccessAPIEnabled = storageAccessAPIEnabled();
309     parameters.suppressesConnectionTerminationOnSystemChange = m_configuration->suppressesConnectionTerminationOnSystemChange();
310
311 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
312     parameters.logCookieInformation = [defaults boolForKey:WebKitLogCookieInformationDefaultsKey];
313 #endif
314
315 #if ENABLE(NETWORK_CAPTURE)
316     parameters.recordReplayMode = [defaults stringForKey:WebKitRecordReplayModeDefaultsKey];
317     parameters.recordReplayCacheLocation = [defaults stringForKey:WebKitRecordReplayCacheLocationDefaultsKey];
318     if (parameters.recordReplayCacheLocation.isEmpty())
319         parameters.recordReplayCacheLocation = parameters.diskCacheDirectory;
320 #endif
321
322 #if ENABLE(PROXIMITY_NETWORKING)
323     parameters.wirelessContextIdentifier = m_configuration->wirelessContextIdentifier();
324 #endif
325 }
326
327 void WebProcessPool::platformInvalidateContext()
328 {
329     unregisterNotificationObservers();
330 }
331
332 #if PLATFORM(IOS)
333 String WebProcessPool::parentBundleDirectory() const
334 {
335     return [[[NSBundle mainBundle] bundlePath] stringByStandardizingPath];
336 }
337
338 String WebProcessPool::networkingCachesDirectory() const
339 {
340     String path = pathForProcessContainer();
341     if (path.isEmpty())
342         path = NSHomeDirectory();
343
344     path = path + "/Library/Caches/com.apple.WebKit.Networking/";
345     path = stringByResolvingSymlinksInPath(path);
346
347     NSError *error = nil;
348     NSString* nsPath = path;
349     if (![[NSFileManager defaultManager] createDirectoryAtPath:nsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
350         NSLog(@"could not create networking caches directory \"%@\", error %@", nsPath, error);
351         return String();
352     }
353
354     return path;
355 }
356
357 String WebProcessPool::webContentCachesDirectory() const
358 {
359     String path = pathForProcessContainer();
360     if (path.isEmpty())
361         path = NSHomeDirectory();
362
363     path = path + "/Library/Caches/com.apple.WebKit.WebContent/";
364     path = stringByResolvingSymlinksInPath(path);
365
366     NSError *error = nil;
367     NSString* nsPath = path;
368     if (![[NSFileManager defaultManager] createDirectoryAtPath:nsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
369         NSLog(@"could not create web content caches directory \"%@\", error %@", nsPath, error);
370         return String();
371     }
372
373     return path;
374 }
375
376 String WebProcessPool::containerTemporaryDirectory() const
377 {
378     String path = NSTemporaryDirectory();
379     return stringByResolvingSymlinksInPath(path);
380 }
381 #endif
382
383 #if PLATFORM(IOS)
384 void WebProcessPool::setJavaScriptConfigurationFileEnabledFromDefaults()
385 {
386     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
387
388     setJavaScriptConfigurationFileEnabled([defaults boolForKey:@"WebKitJavaScriptCoreUseConfigFile"]);
389 }
390 #endif
391
392 bool WebProcessPool::omitPDFSupport()
393 {
394     // Since this is a "secret default" we don't bother registering it.
395     return [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
396 }
397
398 bool WebProcessPool::processSuppressionEnabled() const
399 {
400     return !m_userObservablePageCounter.value() && !m_processSuppressionDisabledForPageCounter.value();
401 }
402
403 void WebProcessPool::registerNotificationObservers()
404 {
405 #if !PLATFORM(IOS)
406     // Listen for enhanced accessibility changes and propagate them to the WebProcess.
407     m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
408         setEnhancedAccessibility([[[note userInfo] objectForKey:@"AXEnhancedUserInterface"] boolValue]);
409     }];
410
411     m_automaticTextReplacementNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticTextReplacementNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
412         TextChecker::didChangeAutomaticTextReplacementEnabled();
413         textCheckerStateChanged();
414     }];
415     
416     m_automaticSpellingCorrectionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
417         TextChecker::didChangeAutomaticSpellingCorrectionEnabled();
418         textCheckerStateChanged();
419     }];
420
421     m_automaticQuoteSubstitutionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticQuoteSubstitutionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
422         TextChecker::didChangeAutomaticQuoteSubstitutionEnabled();
423         textCheckerStateChanged();
424     }];
425
426     m_automaticDashSubstitutionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticDashSubstitutionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
427         TextChecker::didChangeAutomaticDashSubstitutionEnabled();
428         textCheckerStateChanged();
429     }];
430
431     m_accessibilityDisplayOptionsNotificationObserver = [[NSWorkspace.sharedWorkspace notificationCenter] addObserverForName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
432         screenPropertiesStateChanged();
433     }];
434
435 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
436     m_scrollerStyleNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSPreferredScrollerStyleDidChangeNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
437         auto scrollbarStyle = [NSScroller preferredScrollerStyle];
438         sendToAllProcesses(Messages::WebProcess::ScrollerStylePreferenceChanged(scrollbarStyle));
439     }];
440 #endif
441
442 #endif // !PLATFORM(IOS)
443 }
444
445 void WebProcessPool::unregisterNotificationObservers()
446 {
447 #if !PLATFORM(IOS)
448     [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];    
449     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticTextReplacementNotificationObserver.get()];
450     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticSpellingCorrectionNotificationObserver.get()];
451     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticQuoteSubstitutionNotificationObserver.get()];
452     [[NSNotificationCenter defaultCenter] removeObserver:m_automaticDashSubstitutionNotificationObserver.get()];
453     [[NSWorkspace.sharedWorkspace notificationCenter] removeObserver:m_accessibilityDisplayOptionsNotificationObserver.get()];
454 #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING)
455     [[NSNotificationCenter defaultCenter] removeObserver:m_scrollerStyleNotificationObserver.get()];
456 #endif
457 #endif // !PLATFORM(IOS)
458 }
459
460 static CFURLStorageSessionRef privateBrowsingSession()
461 {
462     static CFURLStorageSessionRef session;
463     static dispatch_once_t once;
464     dispatch_once(&once, ^{
465         NSString *identifier = [NSString stringWithFormat:@"%@.PrivateBrowsing", [[NSBundle mainBundle] bundleIdentifier]];
466         session = createPrivateStorageSession((__bridge CFStringRef)identifier);
467     });
468
469     return session;
470 }
471
472 bool WebProcessPool::isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const
473 {
474     RetainPtr<CFURLRef> url = URL(URL(), urlString).createCFURL();
475
476     return _CFNetworkIsKnownHSTSHostWithSession(url.get(), privateBrowsingEnabled ? privateBrowsingSession() : nullptr);
477 }
478
479 void WebProcessPool::resetHSTSHosts()
480 {
481     _CFNetworkResetHSTSHostsWithSession(nullptr);
482     _CFNetworkResetHSTSHostsWithSession(privateBrowsingSession());
483 }
484
485 void WebProcessPool::resetHSTSHostsAddedAfterDate(double startDateIntervalSince1970)
486 {
487     NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:startDateIntervalSince1970];
488     _CFNetworkResetHSTSHostsSinceDate(nullptr, (__bridge CFDateRef)startDate);
489     _CFNetworkResetHSTSHostsSinceDate(privateBrowsingSession(), (__bridge CFDateRef)startDate);
490 }
491
492 // FIXME: Deprecated. Left here until a final decision is made.
493 void WebProcessPool::setCookieStoragePartitioningEnabled(bool enabled)
494 {
495     m_cookieStoragePartitioningEnabled = enabled;
496 }
497
498 void WebProcessPool::setStorageAccessAPIEnabled(bool enabled)
499 {
500     m_storageAccessAPIEnabled = enabled;
501     sendToNetworkingProcess(Messages::NetworkProcess::SetStorageAccessAPIEnabled(enabled));
502 }
503
504 int networkProcessLatencyQOS()
505 {
506     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitNetworkProcessLatencyQOS"];
507     return qos;
508 }
509
510 int networkProcessThroughputQOS()
511 {
512     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitNetworkProcessThroughputQOS"];
513     return qos;
514 }
515
516 int webProcessLatencyQOS()
517 {
518     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitWebProcessLatencyQOS"];
519     return qos;
520 }
521
522 int webProcessThroughputQOS()
523 {
524     static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitWebProcessThroughputQOS"];
525     return qos;
526 }
527
528 } // namespace WebKit