2 * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #import "WebProcessPool.h"
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>
56 #import "ArgumentCodersCF.h"
57 #import "WebMemoryPressureHandlerIOS.h"
59 #import <QuartzCore/CARemoteLayerServer.h>
62 using namespace WebCore;
64 NSString *WebDatabaseDirectoryDefaultsKey = @"WebDatabaseDirectory";
65 NSString *WebServiceWorkerRegistrationDirectoryDefaultsKey = @"WebServiceWorkerRegistrationDirectory";
66 NSString *WebKitLocalCacheDefaultsKey = @"WebKitLocalCache";
67 NSString *WebStorageDirectoryDefaultsKey = @"WebKitLocalStorageDatabasePathPreferenceKey";
68 NSString *WebKitJSCJITEnabledDefaultsKey = @"WebKitJSCJITEnabledDefaultsKey";
69 NSString *WebKitJSCFTLJITEnabledDefaultsKey = @"WebKitJSCFTLJITEnabledDefaultsKey";
70 NSString *WebKitMediaKeysStorageDirectoryDefaultsKey = @"WebKitMediaKeysStorageDirectory";
71 NSString *WebKitMediaCacheDirectoryDefaultsKey = @"WebKitMediaCacheDirectory";
74 static NSString *WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification = @"NSApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification";
77 // FIXME: <rdar://problem/9138817> - After this "backwards compatibility" radar is removed, this code should be removed to only return an empty String.
78 NSString *WebIconDatabaseDirectoryDefaultsKey = @"WebIconDatabaseDirectoryDefaultsKey";
80 static NSString * const WebKit2HTTPProxyDefaultsKey = @"WebKit2HTTPProxy";
81 static NSString * const WebKit2HTTPSProxyDefaultsKey = @"WebKit2HTTPSProxy";
83 static NSString * const WebKitNetworkCacheEnabledDefaultsKey = @"WebKitNetworkCacheEnabled";
84 static NSString * const WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey = @"WebKitNetworkCacheEfficacyLoggingEnabled";
86 static NSString * const WebKitSuppressMemoryPressureHandlerDefaultsKey = @"WebKitSuppressMemoryPressureHandler";
87 static NSString * const WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey = @"WebKitNetworkLoadThrottleLatencyMilliseconds";
89 #if ENABLE(NETWORK_CAPTURE)
90 static NSString * const WebKitRecordReplayModeDefaultsKey = @"WebKitRecordReplayMode";
91 static NSString * const WebKitRecordReplayCacheLocationDefaultsKey = @"WebKitRecordReplayCacheLocation";
96 NSString *SchemeForCustomProtocolRegisteredNotificationName = @"WebKitSchemeForCustomProtocolRegisteredNotification";
97 NSString *SchemeForCustomProtocolUnregisteredNotificationName = @"WebKitSchemeForCustomProtocolUnregisteredNotification";
99 static void registerUserDefaultsIfNeeded()
101 static bool didRegister;
106 NSMutableDictionary *registrationDictionary = [NSMutableDictionary dictionary];
108 [registrationDictionary setObject:@YES forKey:WebKitJSCJITEnabledDefaultsKey];
109 [registrationDictionary setObject:@YES forKey:WebKitJSCFTLJITEnabledDefaultsKey];
111 [registrationDictionary setObject:@YES forKey:WebKitNetworkCacheEnabledDefaultsKey];
112 [registrationDictionary setObject:@NO forKey:WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey];
114 [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDictionary];
117 void WebProcessPool::updateProcessSuppressionState()
119 if (m_networkProcess)
120 m_networkProcess->setProcessSuppressionEnabled(processSuppressionEnabled());
122 #if ENABLE(NETSCAPE_PLUGIN_API)
123 if (!m_processSuppressionDisabledForPageCounter.value())
124 m_pluginProcessManagerProcessSuppressionDisabledToken = nullptr;
125 else if (!m_pluginProcessManagerProcessSuppressionDisabledToken)
126 m_pluginProcessManagerProcessSuppressionDisabledToken = PluginProcessManager::singleton().processSuppressionDisabledToken();
130 NSMutableDictionary *WebProcessPool::ensureBundleParameters()
132 if (!m_bundleParameters)
133 m_bundleParameters = adoptNS([[NSMutableDictionary alloc] init]);
135 return m_bundleParameters.get();
138 void WebProcessPool::platformInitialize()
140 registerUserDefaultsIfNeeded();
141 registerNotificationObservers();
144 IPC::setAllowsDecodingSecKeyRef(true);
145 installMemoryPressureHandler();
148 setLegacyCustomProtocolManagerClient(std::make_unique<LegacyCustomProtocolManagerClient>());
152 String WebProcessPool::cookieStorageDirectory() const
154 String path = pathForProcessContainer();
156 path = NSHomeDirectory();
158 path = path + "/Library/Cookies";
159 path = stringByResolvingSymlinksInPath(path);
164 void WebProcessPool::platformResolvePathsForSandboxExtensions()
166 m_resolvedPaths.uiProcessBundleResourcePath = resolvePathForSandboxExtension([[NSBundle mainBundle] resourcePath]);
169 m_resolvedPaths.cookieStorageDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(cookieStorageDirectory());
170 m_resolvedPaths.containerCachesDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(webContentCachesDirectory());
171 m_resolvedPaths.containerTemporaryDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(containerTemporaryDirectory());
175 void WebProcessPool::platformInitializeWebProcess(WebProcessCreationParameters& parameters)
178 #pragma clang diagnostic push
179 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
180 parameters.accessibilityEnhancedUserInterfaceEnabled = [[NSApp accessibilityAttributeValue:@"AXEnhancedUserInterface"] boolValue];
181 #pragma clang diagnostic pop
183 parameters.accessibilityEnhancedUserInterfaceEnabled = false;
186 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
188 parameters.shouldEnableJIT = [defaults boolForKey:WebKitJSCJITEnabledDefaultsKey];
189 parameters.shouldEnableFTLJIT = [defaults boolForKey:WebKitJSCFTLJITEnabledDefaultsKey];
190 parameters.shouldEnableMemoryPressureReliefLogging = [defaults boolForKey:@"LogMemoryJetsamDetails"];
191 parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
193 #if HAVE(HOSTED_CORE_ANIMATION)
195 parameters.acceleratedCompositingPort = MachSendRight::create([CARemoteLayerServer sharedServer].serverPort);
199 // FIXME: This should really be configurable; we shouldn't just blindly allow read access to the UI process bundle.
200 parameters.uiProcessBundleResourcePath = m_resolvedPaths.uiProcessBundleResourcePath;
201 SandboxExtension::createHandleWithoutResolvingPath(parameters.uiProcessBundleResourcePath, SandboxExtension::Type::ReadOnly, parameters.uiProcessBundleResourcePathExtensionHandle);
203 parameters.uiProcessBundleIdentifier = String([[NSBundle mainBundle] bundleIdentifier]);
206 if (!m_resolvedPaths.cookieStorageDirectory.isEmpty())
207 SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.cookieStorageDirectory, SandboxExtension::Type::ReadWrite, parameters.cookieStorageDirectoryExtensionHandle);
209 if (!m_resolvedPaths.containerCachesDirectory.isEmpty())
210 SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.containerCachesDirectory, SandboxExtension::Type::ReadWrite, parameters.containerCachesDirectoryExtensionHandle);
212 if (!m_resolvedPaths.containerTemporaryDirectory.isEmpty())
213 SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.containerTemporaryDirectory, SandboxExtension::Type::ReadWrite, parameters.containerTemporaryDirectoryExtensionHandle);
216 parameters.fontWhitelist = m_fontWhitelist;
218 if (m_bundleParameters) {
219 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200)
220 auto data = adoptNS([[NSMutableData alloc] init]);
221 auto keyedArchiver = adoptNS([[NSKeyedArchiver alloc] initForWritingWithMutableData:data.get()]);
223 [keyedArchiver setRequiresSecureCoding:YES];
225 auto keyedArchiver = secureArchiver();
229 [keyedArchiver encodeObject:m_bundleParameters.get() forKey:@"parameters"];
230 [keyedArchiver finishEncoding];
231 } @catch (NSException *exception) {
232 LOG_ERROR("Failed to encode bundle parameters: %@", exception);
235 #if (!PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
236 auto data = retainPtr(keyedArchiver.get().encodedData);
239 parameters.bundleParameterData = API::Data::createWithoutCopying((const unsigned char*)[data bytes], [data length], [] (unsigned char*, const void* data) {
240 [(NSData *)data release];
243 parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
246 ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
247 parameters.uiProcessCookieStorageIdentifier = identifyingDataFromCookieStorage([[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]);
249 #if ENABLE(MEDIA_STREAM)
250 // Allow microphone access if either preference is set because WebRTC requires microphone access.
251 bool mediaDevicesEnabled = m_defaultPageGroup->preferences().mediaDevicesEnabled();
252 bool webRTCEnabled = m_defaultPageGroup->preferences().peerConnectionEnabled();
253 if ([defaults objectForKey:@"ExperimentalPeerConnectionEnabled"])
254 webRTCEnabled = [defaults boolForKey:@"ExperimentalPeerConnectionEnabled"];
256 bool isSafari = false;
258 if (WebCore::IOSApplication::isMobileSafari())
261 if (WebCore::MacApplication::isSafari())
265 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
266 parameters.webCoreLoggingChannels = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebCoreLogging"];
267 parameters.webKitLoggingChannels = [[NSUserDefaults standardUserDefaults] stringForKey:@"WebKit2Logging"];
270 // FIXME: Remove this and related parameter when <rdar://problem/29448368> is fixed.
271 if (isSafari && !parameters.shouldCaptureAudioInUIProcess && mediaDevicesEnabled)
272 SandboxExtension::createHandleForGenericExtension("com.apple.webkit.microphone", parameters.audioCaptureExtensionHandle);
276 void WebProcessPool::platformInitializeNetworkProcess(NetworkProcessCreationParameters& parameters)
278 NSURLCache *urlCache = [NSURLCache sharedURLCache];
279 parameters.nsURLCacheMemoryCapacity = [urlCache memoryCapacity];
280 parameters.nsURLCacheDiskCapacity = [urlCache diskCapacity];
282 parameters.parentProcessName = [[NSProcessInfo processInfo] processName];
283 parameters.uiProcessBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
285 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
287 parameters.httpProxy = [defaults stringForKey:WebKit2HTTPProxyDefaultsKey];
288 parameters.httpsProxy = [defaults stringForKey:WebKit2HTTPSProxyDefaultsKey];
289 parameters.networkATSContext = adoptCF(_CFNetworkCopyATSContext());
291 parameters.shouldEnableNetworkCache = isNetworkCacheEnabled();
292 parameters.shouldEnableNetworkCacheEfficacyLogging = [defaults boolForKey:WebKitNetworkCacheEfficacyLoggingEnabledDefaultsKey];
294 parameters.sourceApplicationBundleIdentifier = m_configuration->sourceApplicationBundleIdentifier();
295 parameters.sourceApplicationSecondaryIdentifier = m_configuration->sourceApplicationSecondaryIdentifier();
297 parameters.ctDataConnectionServiceType = m_configuration->ctDataConnectionServiceType();
300 parameters.shouldSuppressMemoryPressureHandler = [defaults boolForKey:WebKitSuppressMemoryPressureHandlerDefaultsKey];
301 parameters.loadThrottleLatency = Seconds { [defaults integerForKey:WebKitNetworkLoadThrottleLatencyMillisecondsDefaultsKey] / 1000. };
304 ASSERT(parameters.uiProcessCookieStorageIdentifier.isEmpty());
305 parameters.uiProcessCookieStorageIdentifier = identifyingDataFromCookieStorage([[NSHTTPCookieStorage sharedHTTPCookieStorage] _cookieStorage]);
308 parameters.cookieStoragePartitioningEnabled = cookieStoragePartitioningEnabled();
309 parameters.storageAccessAPIEnabled = storageAccessAPIEnabled();
311 #if ENABLE(NETWORK_CAPTURE)
312 parameters.recordReplayMode = [defaults stringForKey:WebKitRecordReplayModeDefaultsKey];
313 parameters.recordReplayCacheLocation = [defaults stringForKey:WebKitRecordReplayCacheLocationDefaultsKey];
314 if (parameters.recordReplayCacheLocation.isEmpty())
315 parameters.recordReplayCacheLocation = parameters.diskCacheDirectory;
319 void WebProcessPool::platformInvalidateContext()
321 unregisterNotificationObservers();
325 String WebProcessPool::parentBundleDirectory() const
327 return [[[NSBundle mainBundle] bundlePath] stringByStandardizingPath];
330 String WebProcessPool::networkingCachesDirectory() const
332 String path = pathForProcessContainer();
334 path = NSHomeDirectory();
336 path = path + "/Library/Caches/com.apple.WebKit.Networking/";
337 path = stringByResolvingSymlinksInPath(path);
339 NSError *error = nil;
340 NSString* nsPath = path;
341 if (![[NSFileManager defaultManager] createDirectoryAtPath:nsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
342 NSLog(@"could not create networking caches directory \"%@\", error %@", nsPath, error);
349 String WebProcessPool::webContentCachesDirectory() const
351 String path = pathForProcessContainer();
353 path = NSHomeDirectory();
355 path = path + "/Library/Caches/com.apple.WebKit.WebContent/";
356 path = stringByResolvingSymlinksInPath(path);
358 NSError *error = nil;
359 NSString* nsPath = path;
360 if (![[NSFileManager defaultManager] createDirectoryAtPath:nsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
361 NSLog(@"could not create web content caches directory \"%@\", error %@", nsPath, error);
368 String WebProcessPool::containerTemporaryDirectory() const
370 String path = NSTemporaryDirectory();
371 return stringByResolvingSymlinksInPath(path);
375 String WebProcessPool::legacyPlatformDefaultWebSQLDatabaseDirectory()
377 registerUserDefaultsIfNeeded();
379 NSString *databasesDirectory = [[NSUserDefaults standardUserDefaults] objectForKey:WebDatabaseDirectoryDefaultsKey];
380 if (!databasesDirectory || ![databasesDirectory isKindOfClass:[NSString class]])
381 databasesDirectory = @"~/Library/WebKit/Databases";
382 return stringByResolvingSymlinksInPath([databasesDirectory stringByStandardizingPath]);
385 String WebProcessPool::legacyPlatformDefaultIndexedDBDatabaseDirectory()
387 // Indexed databases exist in a subdirectory of the "database directory path."
388 // Currently, the top level of that directory contains entities related to WebSQL databases.
389 // We should fix this, and move WebSQL into a subdirectory (https://bugs.webkit.org/show_bug.cgi?id=124807)
390 // In the meantime, an entity name prefixed with three underscores will not conflict with any WebSQL entities.
391 return FileSystem::pathByAppendingComponent(legacyPlatformDefaultWebSQLDatabaseDirectory(), "___IndexedDB");
394 String WebProcessPool::legacyPlatformDefaultServiceWorkerRegistrationDirectory()
396 registerUserDefaultsIfNeeded();
398 NSString *directory = [[NSUserDefaults standardUserDefaults] objectForKey:WebServiceWorkerRegistrationDirectoryDefaultsKey];
399 if (!directory || ![directory isKindOfClass:[NSString class]])
400 directory = @"~/Library/WebKit/ServiceWorkers";
401 return stringByResolvingSymlinksInPath([directory stringByStandardizingPath]);
404 String WebProcessPool::legacyPlatformDefaultLocalStorageDirectory()
406 registerUserDefaultsIfNeeded();
408 NSString *localStorageDirectory = [[NSUserDefaults standardUserDefaults] objectForKey:WebStorageDirectoryDefaultsKey];
409 if (!localStorageDirectory || ![localStorageDirectory isKindOfClass:[NSString class]])
410 localStorageDirectory = @"~/Library/WebKit/LocalStorage";
411 return stringByResolvingSymlinksInPath([localStorageDirectory stringByStandardizingPath]);
414 String WebProcessPool::legacyPlatformDefaultMediaCacheDirectory()
416 registerUserDefaultsIfNeeded();
418 NSString *mediaKeysCacheDirectory = [[NSUserDefaults standardUserDefaults] objectForKey:WebKitMediaCacheDirectoryDefaultsKey];
419 if (!mediaKeysCacheDirectory || ![mediaKeysCacheDirectory isKindOfClass:[NSString class]]) {
420 mediaKeysCacheDirectory = NSTemporaryDirectory();
422 if (!WebKit::processHasContainer()) {
423 NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier;
424 if (!bundleIdentifier)
425 bundleIdentifier = [NSProcessInfo processInfo].processName;
426 mediaKeysCacheDirectory = [mediaKeysCacheDirectory stringByAppendingPathComponent:bundleIdentifier];
428 mediaKeysCacheDirectory = [mediaKeysCacheDirectory stringByAppendingPathComponent:@"WebKit/MediaCache"];
430 return stringByResolvingSymlinksInPath([mediaKeysCacheDirectory stringByStandardizingPath]);
433 String WebProcessPool::legacyPlatformDefaultMediaKeysStorageDirectory()
435 registerUserDefaultsIfNeeded();
437 NSString *mediaKeysStorageDirectory = [[NSUserDefaults standardUserDefaults] objectForKey:WebKitMediaKeysStorageDirectoryDefaultsKey];
438 if (!mediaKeysStorageDirectory || ![mediaKeysStorageDirectory isKindOfClass:[NSString class]])
439 mediaKeysStorageDirectory = @"~/Library/WebKit/MediaKeys";
440 return stringByResolvingSymlinksInPath([mediaKeysStorageDirectory stringByStandardizingPath]);
443 String WebProcessPool::legacyPlatformDefaultApplicationCacheDirectory()
445 NSString *appName = [[NSBundle mainBundle] bundleIdentifier];
447 appName = [[NSProcessInfo processInfo] processName];
449 // This quirk used to make these apps share application cache storage, but doesn't accomplish that any more.
450 // Preserving it avoids the need to migrate data when upgrading.
451 if (IOSApplication::isMobileSafari() || IOSApplication::isWebApp())
452 appName = @"com.apple.WebAppCache";
458 NSString *cacheDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"];
460 char cacheDirectory[MAXPATHLEN];
461 size_t cacheDirectoryLen = confstr(_CS_DARWIN_USER_CACHE_DIR, cacheDirectory, MAXPATHLEN);
462 if (!cacheDirectoryLen)
465 NSString *cacheDir = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:cacheDirectory length:cacheDirectoryLen - 1];
467 NSString* cachePath = [cacheDir stringByAppendingPathComponent:appName];
468 return stringByResolvingSymlinksInPath([cachePath stringByStandardizingPath]);
471 String WebProcessPool::legacyPlatformDefaultNetworkCacheDirectory()
473 RetainPtr<NSString> cachePath = adoptNS((NSString *)_CFURLCacheCopyCacheDirectory([[NSURLCache sharedURLCache] _CFURLCache]));
475 cachePath = @"~/Library/Caches/com.apple.WebKit.WebProcess";
477 if (isNetworkCacheEnabled())
478 cachePath = [cachePath stringByAppendingPathComponent:@"WebKitCache"];
480 return stringByResolvingSymlinksInPath([cachePath stringByStandardizingPath]);
483 String WebProcessPool::legacyPlatformDefaultJavaScriptConfigurationDirectory()
486 String path = pathForProcessContainer();
488 path = NSHomeDirectory();
490 path = path + "/Library/WebKit/JavaScriptCoreDebug";
491 path = stringByResolvingSymlinksInPath(path);
495 RetainPtr<NSString> javaScriptConfigPath = @"~/Library/WebKit/JavaScriptCoreDebug";
497 return stringByResolvingSymlinksInPath([javaScriptConfigPath stringByStandardizingPath]);
502 void WebProcessPool::setJavaScriptConfigurationFileEnabledFromDefaults()
504 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
506 setJavaScriptConfigurationFileEnabled([defaults boolForKey:@"WebKitJavaScriptCoreUseConfigFile"]);
510 bool WebProcessPool::isNetworkCacheEnabled()
512 registerUserDefaultsIfNeeded();
514 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
516 bool networkCacheEnabledByDefaults = [defaults boolForKey:WebKitNetworkCacheEnabledDefaultsKey];
518 return networkCacheEnabledByDefaults && linkedOnOrAfter(SDKVersion::FirstWithNetworkCache);
521 bool WebProcessPool::omitPDFSupport()
523 // Since this is a "secret default" we don't bother registering it.
524 return [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitOmitPDFSupport"];
527 bool WebProcessPool::processSuppressionEnabled() const
529 return !m_userObservablePageCounter.value() && !m_processSuppressionDisabledForPageCounter.value();
532 void WebProcessPool::registerNotificationObservers()
535 // Listen for enhanced accessibility changes and propagate them to the WebProcess.
536 m_enhancedAccessibilityObserver = [[NSNotificationCenter defaultCenter] addObserverForName:WebKitApplicationDidChangeAccessibilityEnhancedUserInterfaceNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *note) {
537 setEnhancedAccessibility([[[note userInfo] objectForKey:@"AXEnhancedUserInterface"] boolValue]);
540 m_automaticTextReplacementNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticTextReplacementNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
541 TextChecker::didChangeAutomaticTextReplacementEnabled();
542 textCheckerStateChanged();
545 m_automaticSpellingCorrectionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
546 TextChecker::didChangeAutomaticSpellingCorrectionEnabled();
547 textCheckerStateChanged();
550 m_automaticQuoteSubstitutionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticQuoteSubstitutionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
551 TextChecker::didChangeAutomaticQuoteSubstitutionEnabled();
552 textCheckerStateChanged();
555 m_automaticDashSubstitutionNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:NSSpellCheckerDidChangeAutomaticDashSubstitutionNotification object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification *notification) {
556 TextChecker::didChangeAutomaticDashSubstitutionEnabled();
557 textCheckerStateChanged();
559 #endif // !PLATFORM(IOS)
562 void WebProcessPool::unregisterNotificationObservers()
565 [[NSNotificationCenter defaultCenter] removeObserver:m_enhancedAccessibilityObserver.get()];
566 [[NSNotificationCenter defaultCenter] removeObserver:m_automaticTextReplacementNotificationObserver.get()];
567 [[NSNotificationCenter defaultCenter] removeObserver:m_automaticSpellingCorrectionNotificationObserver.get()];
568 [[NSNotificationCenter defaultCenter] removeObserver:m_automaticQuoteSubstitutionNotificationObserver.get()];
569 [[NSNotificationCenter defaultCenter] removeObserver:m_automaticDashSubstitutionNotificationObserver.get()];
570 #endif // !PLATFORM(IOS)
573 static CFURLStorageSessionRef privateBrowsingSession()
575 static CFURLStorageSessionRef session;
576 static dispatch_once_t once;
577 dispatch_once(&once, ^{
578 NSString *identifier = [NSString stringWithFormat:@"%@.PrivateBrowsing", [[NSBundle mainBundle] bundleIdentifier]];
580 session = createPrivateStorageSession((CFStringRef)identifier);
586 bool WebProcessPool::isURLKnownHSTSHost(const String& urlString, bool privateBrowsingEnabled) const
588 RetainPtr<CFURLRef> url = URL(URL(), urlString).createCFURL();
590 return _CFNetworkIsKnownHSTSHostWithSession(url.get(), privateBrowsingEnabled ? privateBrowsingSession() : nullptr);
593 void WebProcessPool::resetHSTSHosts()
595 _CFNetworkResetHSTSHostsWithSession(nullptr);
596 _CFNetworkResetHSTSHostsWithSession(privateBrowsingSession());
599 void WebProcessPool::resetHSTSHostsAddedAfterDate(double startDateIntervalSince1970)
601 NSDate *startDate = [NSDate dateWithTimeIntervalSince1970:startDateIntervalSince1970];
602 _CFNetworkResetHSTSHostsSinceDate(nullptr, (__bridge CFDateRef)startDate);
603 _CFNetworkResetHSTSHostsSinceDate(privateBrowsingSession(), (__bridge CFDateRef)startDate);
606 void WebProcessPool::setCookieStoragePartitioningEnabled(bool enabled)
608 m_cookieStoragePartitioningEnabled = enabled;
609 sendToNetworkingProcess(Messages::NetworkProcess::SetCookieStoragePartitioningEnabled(enabled));
612 void WebProcessPool::setStorageAccessAPIEnabled(bool enabled)
614 m_storageAccessAPIEnabled = enabled;
615 sendToNetworkingProcess(Messages::NetworkProcess::SetStorageAccessAPIEnabled(enabled));
618 int networkProcessLatencyQOS()
620 static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitNetworkProcessLatencyQOS"];
624 int networkProcessThroughputQOS()
626 static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitNetworkProcessThroughputQOS"];
630 int webProcessLatencyQOS()
632 static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitWebProcessLatencyQOS"];
636 int webProcessThroughputQOS()
638 static const int qos = [[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitWebProcessThroughputQOS"];
642 } // namespace WebKit