| 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 | #include "config.h" |
| 27 | #include "WebProcessPool.h" |
| 28 | |
| 29 | #include "APIArray.h" |
| 30 | #include "APIAutomationClient.h" |
| 31 | #include "APICustomProtocolManagerClient.h" |
| 32 | #include "APIDownloadClient.h" |
| 33 | #include "APIHTTPCookieStore.h" |
| 34 | #include "APIInjectedBundleClient.h" |
| 35 | #include "APILegacyContextHistoryClient.h" |
| 36 | #include "APINavigation.h" |
| 37 | #include "APIPageConfiguration.h" |
| 38 | #include "APIProcessPoolConfiguration.h" |
| 39 | #include "AuxiliaryProcessMessages.h" |
| 40 | #include "DownloadProxy.h" |
| 41 | #include "DownloadProxyMessages.h" |
| 42 | #include "GamepadData.h" |
| 43 | #include "HighPerformanceGraphicsUsageSampler.h" |
| 44 | #include "LogInitialization.h" |
| 45 | #include "Logging.h" |
| 46 | #include "NetworkProcessCreationParameters.h" |
| 47 | #include "NetworkProcessMessages.h" |
| 48 | #include "NetworkProcessProxy.h" |
| 49 | #include "PerActivityStateCPUUsageSampler.h" |
| 50 | #include "PluginProcessManager.h" |
| 51 | #include "SandboxExtension.h" |
| 52 | #include "ServiceWorkerProcessProxy.h" |
| 53 | #include "StatisticsData.h" |
| 54 | #include "TextChecker.h" |
| 55 | #include "UIGamepad.h" |
| 56 | #include "UIGamepadProvider.h" |
| 57 | #include "WKContextPrivate.h" |
| 58 | #include "WebAutomationSession.h" |
| 59 | #include "WebBackForwardList.h" |
| 60 | #include "WebBackForwardListItem.h" |
| 61 | #include "WebCertificateInfo.h" |
| 62 | #include "WebContextSupplement.h" |
| 63 | #include "WebCookieManagerProxy.h" |
| 64 | #include "WebCoreArgumentCoders.h" |
| 65 | #include "WebGeolocationManagerProxy.h" |
| 66 | #include "WebInspectorUtilities.h" |
| 67 | #include "WebKit2Initialize.h" |
| 68 | #include "WebMemorySampler.h" |
| 69 | #include "WebNotificationManagerProxy.h" |
| 70 | #include "WebPageGroup.h" |
| 71 | #include "WebPreferences.h" |
| 72 | #include "WebPreferencesKeys.h" |
| 73 | #include "WebProcessCache.h" |
| 74 | #include "WebProcessCreationParameters.h" |
| 75 | #include "WebProcessDataStoreParameters.h" |
| 76 | #include "WebProcessMessages.h" |
| 77 | #include "WebProcessPoolMessages.h" |
| 78 | #include "WebProcessProxy.h" |
| 79 | #include "WebsiteDataStore.h" |
| 80 | #include "WebsiteDataStoreParameters.h" |
| 81 | #include <JavaScriptCore/JSCInlines.h> |
| 82 | #include <WebCore/ApplicationCacheStorage.h> |
| 83 | #include <WebCore/LogInitialization.h> |
| 84 | #include <WebCore/MockRealtimeMediaSourceCenter.h> |
| 85 | #include <WebCore/NetworkStorageSession.h> |
| 86 | #include <WebCore/PlatformScreen.h> |
| 87 | #include <WebCore/ProcessIdentifier.h> |
| 88 | #include <WebCore/ProcessWarming.h> |
| 89 | #include <WebCore/ResourceRequest.h> |
| 90 | #include <WebCore/RuntimeApplicationChecks.h> |
| 91 | #include <WebCore/RuntimeEnabledFeatures.h> |
| 92 | #include <pal/SessionID.h> |
| 93 | #include <wtf/Language.h> |
| 94 | #include <wtf/MainThread.h> |
| 95 | #include <wtf/NeverDestroyed.h> |
| 96 | #include <wtf/ProcessPrivilege.h> |
| 97 | #include <wtf/RunLoop.h> |
| 98 | #include <wtf/Scope.h> |
| 99 | #include <wtf/URLParser.h> |
| 100 | #include <wtf/WallTime.h> |
| 101 | #include <wtf/text/StringBuilder.h> |
| 102 | #include <wtf/text/StringConcatenateNumbers.h> |
| 103 | |
| 104 | #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) |
| 105 | #include "LegacyCustomProtocolManagerMessages.h" |
| 106 | #endif |
| 107 | |
| 108 | #if ENABLE(SERVICE_CONTROLS) |
| 109 | #include "ServicesController.h" |
| 110 | #endif |
| 111 | |
| 112 | #if ENABLE(REMOTE_INSPECTOR) |
| 113 | #include <JavaScriptCore/RemoteInspector.h> |
| 114 | #endif |
| 115 | |
| 116 | #if OS(LINUX) |
| 117 | #include "MemoryPressureMonitor.h" |
| 118 | #endif |
| 119 | |
| 120 | #if PLATFORM(WAYLAND) |
| 121 | #include "WaylandCompositor.h" |
| 122 | #include <WebCore/PlatformDisplay.h> |
| 123 | #endif |
| 124 | |
| 125 | #if PLATFORM(COCOA) |
| 126 | #include "VersionChecks.h" |
| 127 | #endif |
| 128 | |
| 129 | #ifndef NDEBUG |
| 130 | #include <wtf/RefCountedLeakCounter.h> |
| 131 | #endif |
| 132 | |
| 133 | namespace WebKit { |
| 134 | using namespace WebCore; |
| 135 | |
| 136 | DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, processPoolCounter, ("WebProcessPool" )); |
| 137 | |
| 138 | const Seconds serviceWorkerTerminationDelay { 5_s }; |
| 139 | |
| 140 | static uint64_t generateListenerIdentifier() |
| 141 | { |
| 142 | static uint64_t nextIdentifier = 1; |
| 143 | return nextIdentifier++; |
| 144 | } |
| 145 | |
| 146 | static HashMap<uint64_t, Function<void(WebProcessPool&)>>& processPoolCreationListenerFunctionMap() |
| 147 | { |
| 148 | static NeverDestroyed<HashMap<uint64_t, Function<void(WebProcessPool&)>>> map; |
| 149 | return map; |
| 150 | } |
| 151 | |
| 152 | uint64_t WebProcessPool::registerProcessPoolCreationListener(Function<void(WebProcessPool&)>&& function) |
| 153 | { |
| 154 | ASSERT(function); |
| 155 | |
| 156 | auto identifier = generateListenerIdentifier(); |
| 157 | processPoolCreationListenerFunctionMap().set(identifier, WTFMove(function)); |
| 158 | return identifier; |
| 159 | } |
| 160 | |
| 161 | void WebProcessPool::unregisterProcessPoolCreationListener(uint64_t identifier) |
| 162 | { |
| 163 | processPoolCreationListenerFunctionMap().remove(identifier); |
| 164 | } |
| 165 | |
| 166 | Ref<WebProcessPool> WebProcessPool::create(API::ProcessPoolConfiguration& configuration) |
| 167 | { |
| 168 | InitializeWebKit2(); |
| 169 | return adoptRef(*new WebProcessPool(configuration)); |
| 170 | } |
| 171 | |
| 172 | void WebProcessPool::notifyThisWebProcessPoolWasCreated() |
| 173 | { |
| 174 | auto& listenerMap = processPoolCreationListenerFunctionMap(); |
| 175 | |
| 176 | Vector<uint64_t> identifiers; |
| 177 | identifiers.reserveInitialCapacity(listenerMap.size()); |
| 178 | for (auto identifier : listenerMap.keys()) |
| 179 | identifiers.uncheckedAppend(identifier); |
| 180 | |
| 181 | for (auto identifier : identifiers) { |
| 182 | auto iterator = listenerMap.find(identifier); |
| 183 | if (iterator == listenerMap.end()) |
| 184 | continue; |
| 185 | |
| 186 | // To make sure the Function object stays alive until after the function call has been made, |
| 187 | // we temporarily move it out of the map. |
| 188 | // This protects it from the Function calling unregisterProcessPoolCreationListener thereby |
| 189 | // removing itself from the map of listeners. |
| 190 | // If the identifier still exists in the map later, we move it back in. |
| 191 | Function<void(WebProcessPool&)> function = WTFMove(iterator->value); |
| 192 | function(*this); |
| 193 | |
| 194 | iterator = listenerMap.find(identifier); |
| 195 | if (iterator != listenerMap.end()) { |
| 196 | ASSERT(!iterator->value); |
| 197 | iterator->value = WTFMove(function); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | static Vector<WebProcessPool*>& processPools() |
| 203 | { |
| 204 | static NeverDestroyed<Vector<WebProcessPool*>> processPools; |
| 205 | return processPools; |
| 206 | } |
| 207 | |
| 208 | const Vector<WebProcessPool*>& WebProcessPool::allProcessPools() |
| 209 | { |
| 210 | return processPools(); |
| 211 | } |
| 212 | |
| 213 | static Ref<WebsiteDataStoreConfiguration> legacyWebsiteDataStoreConfiguration(API::ProcessPoolConfiguration& processPoolConfiguration) |
| 214 | { |
| 215 | auto configuration = WebsiteDataStoreConfiguration::create(); |
| 216 | |
| 217 | configuration->setCacheStorageDirectory(String(API::WebsiteDataStore::defaultCacheStorageDirectory())); |
| 218 | configuration->setServiceWorkerRegistrationDirectory(String(API::WebsiteDataStore::defaultServiceWorkerRegistrationDirectory())); |
| 219 | configuration->setLocalStorageDirectory(String(processPoolConfiguration.localStorageDirectory())); |
| 220 | configuration->setWebSQLDatabaseDirectory(String(processPoolConfiguration.webSQLDatabaseDirectory())); |
| 221 | configuration->setApplicationCacheDirectory(String(processPoolConfiguration.applicationCacheDirectory())); |
| 222 | configuration->setApplicationCacheFlatFileSubdirectoryName(String(processPoolConfiguration.applicationCacheFlatFileSubdirectoryName())); |
| 223 | configuration->setMediaCacheDirectory(String(processPoolConfiguration.mediaCacheDirectory())); |
| 224 | configuration->setMediaKeysStorageDirectory(String(processPoolConfiguration.mediaKeysStorageDirectory())); |
| 225 | configuration->setIndexedDBDatabaseDirectory(String(processPoolConfiguration.indexedDBDatabaseDirectory())); |
| 226 | configuration->setResourceLoadStatisticsDirectory(String(processPoolConfiguration.resourceLoadStatisticsDirectory())); |
| 227 | configuration->setNetworkCacheDirectory(String(processPoolConfiguration.diskCacheDirectory())); |
| 228 | configuration->setJavaScriptConfigurationDirectory(String(processPoolConfiguration.javaScriptConfigurationDirectory())); |
| 229 | |
| 230 | return configuration; |
| 231 | } |
| 232 | |
| 233 | static HashSet<String, ASCIICaseInsensitiveHash>& globalURLSchemesWithCustomProtocolHandlers() |
| 234 | { |
| 235 | static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> set; |
| 236 | return set; |
| 237 | } |
| 238 | |
| 239 | WebProcessPool::WebProcessPool(API::ProcessPoolConfiguration& configuration) |
| 240 | : m_configuration(configuration.copy()) |
| 241 | , m_defaultPageGroup(WebPageGroup::create()) |
| 242 | , m_injectedBundleClient(std::make_unique<API::InjectedBundleClient>()) |
| 243 | , m_automationClient(std::make_unique<API::AutomationClient>()) |
| 244 | , m_downloadClient(std::make_unique<API::DownloadClient>()) |
| 245 | , m_historyClient(std::make_unique<API::LegacyContextHistoryClient>()) |
| 246 | , m_customProtocolManagerClient(std::make_unique<API::CustomProtocolManagerClient>()) |
| 247 | , m_visitedLinkStore(VisitedLinkStore::create()) |
| 248 | #if PLATFORM(MAC) |
| 249 | , m_highPerformanceGraphicsUsageSampler(std::make_unique<HighPerformanceGraphicsUsageSampler>(*this)) |
| 250 | , m_perActivityStateCPUUsageSampler(std::make_unique<PerActivityStateCPUUsageSampler>(*this)) |
| 251 | #endif |
| 252 | , m_alwaysRunsAtBackgroundPriority(m_configuration->alwaysRunsAtBackgroundPriority()) |
| 253 | , m_shouldTakeUIBackgroundAssertion(m_configuration->shouldTakeUIBackgroundAssertion()) |
| 254 | , m_userObservablePageCounter([this](RefCounterEvent) { updateProcessSuppressionState(); }) |
| 255 | , m_processSuppressionDisabledForPageCounter([this](RefCounterEvent) { updateProcessSuppressionState(); }) |
| 256 | , m_hiddenPageThrottlingAutoIncreasesCounter([this](RefCounterEvent) { m_hiddenPageThrottlingTimer.startOneShot(0_s); }) |
| 257 | , m_hiddenPageThrottlingTimer(RunLoop::main(), this, &WebProcessPool::updateHiddenPageThrottlingAutoIncreaseLimit) |
| 258 | , m_serviceWorkerProcessesTerminationTimer(RunLoop::main(), this, &WebProcessPool::terminateServiceWorkerProcesses) |
| 259 | #if PLATFORM(IOS_FAMILY) |
| 260 | , m_foregroundWebProcessCounter([this](RefCounterEvent) { updateProcessAssertions(); }) |
| 261 | , m_backgroundWebProcessCounter([this](RefCounterEvent) { updateProcessAssertions(); }) |
| 262 | #endif |
| 263 | , m_webProcessCache(makeUniqueRef<WebProcessCache>(*this)) |
| 264 | { |
| 265 | static std::once_flag onceFlag; |
| 266 | std::call_once(onceFlag, [] { |
| 267 | WTF::setProcessPrivileges(allPrivileges()); |
| 268 | WebCore::NetworkStorageSession::permitProcessToUseCookieAPI(true); |
| 269 | Process::setIdentifier(WebCore::ProcessIdentifier::generate()); |
| 270 | }); |
| 271 | |
| 272 | if (m_configuration->shouldHaveLegacyDataStore()) |
| 273 | m_websiteDataStore = API::WebsiteDataStore::createLegacy(legacyWebsiteDataStoreConfiguration(m_configuration)); |
| 274 | |
| 275 | if (!m_websiteDataStore && API::WebsiteDataStore::defaultDataStoreExists()) |
| 276 | m_websiteDataStore = API::WebsiteDataStore::defaultDataStore(); |
| 277 | |
| 278 | for (auto& scheme : m_configuration->alwaysRevalidatedURLSchemes()) |
| 279 | m_schemesToRegisterAsAlwaysRevalidated.add(scheme); |
| 280 | |
| 281 | for (const auto& urlScheme : m_configuration->cachePartitionedURLSchemes()) |
| 282 | m_schemesToRegisterAsCachePartitioned.add(urlScheme); |
| 283 | |
| 284 | platformInitialize(); |
| 285 | |
| 286 | #if OS(LINUX) |
| 287 | MemoryPressureMonitor::singleton().start(); |
| 288 | #endif |
| 289 | |
| 290 | addMessageReceiver(Messages::WebProcessPool::messageReceiverName(), *this); |
| 291 | |
| 292 | // NOTE: These sub-objects must be initialized after m_messageReceiverMap.. |
| 293 | addSupplement<WebCookieManagerProxy>(); |
| 294 | addSupplement<WebGeolocationManagerProxy>(); |
| 295 | addSupplement<WebNotificationManagerProxy>(); |
| 296 | #if ENABLE(MEDIA_SESSION) |
| 297 | addSupplement<WebMediaSessionFocusManager>(); |
| 298 | #endif |
| 299 | |
| 300 | processPools().append(this); |
| 301 | |
| 302 | addLanguageChangeObserver(this, languageChanged); |
| 303 | |
| 304 | resolvePathsForSandboxExtensions(); |
| 305 | |
| 306 | #if !LOG_DISABLED || !RELEASE_LOG_DISABLED |
| 307 | WebCore::initializeLogChannelsIfNecessary(); |
| 308 | WebKit::initializeLogChannelsIfNecessary(); |
| 309 | #endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED |
| 310 | |
| 311 | #ifndef NDEBUG |
| 312 | processPoolCounter.increment(); |
| 313 | #endif |
| 314 | |
| 315 | notifyThisWebProcessPoolWasCreated(); |
| 316 | |
| 317 | updateMaxSuspendedPageCount(); |
| 318 | } |
| 319 | |
| 320 | WebProcessPool::~WebProcessPool() |
| 321 | { |
| 322 | m_webProcessCache->clear(); |
| 323 | |
| 324 | bool removed = processPools().removeFirst(this); |
| 325 | ASSERT_UNUSED(removed, removed); |
| 326 | |
| 327 | removeLanguageChangeObserver(this); |
| 328 | |
| 329 | m_messageReceiverMap.invalidate(); |
| 330 | |
| 331 | for (auto& supplement : m_supplements.values()) { |
| 332 | supplement->processPoolDestroyed(); |
| 333 | supplement->clearProcessPool(); |
| 334 | } |
| 335 | |
| 336 | invalidateCallbackMap(m_dictionaryCallbacks, CallbackBase::Error::OwnerWasInvalidated); |
| 337 | |
| 338 | platformInvalidateContext(); |
| 339 | |
| 340 | #ifndef NDEBUG |
| 341 | processPoolCounter.decrement(); |
| 342 | #endif |
| 343 | |
| 344 | if (m_networkProcess) |
| 345 | m_networkProcess->shutDownProcess(); |
| 346 | |
| 347 | #if ENABLE(GAMEPAD) |
| 348 | if (!m_processesUsingGamepads.isEmpty()) |
| 349 | UIGamepadProvider::singleton().processPoolStoppedUsingGamepads(*this); |
| 350 | #endif |
| 351 | |
| 352 | // Only remaining processes should be pre-warmed ones as other keep the process pool alive. |
| 353 | while (!m_processes.isEmpty()) { |
| 354 | auto& process = m_processes.first(); |
| 355 | |
| 356 | ASSERT(process->isPrewarmed()); |
| 357 | // We need to be the only one holding a reference to the pre-warmed process so that it gets destroyed. |
| 358 | // WebProcessProxies currently always expect to have a WebProcessPool. |
| 359 | ASSERT(process->hasOneRef()); |
| 360 | |
| 361 | process->shutDown(); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | void WebProcessPool::initializeClient(const WKContextClientBase* client) |
| 366 | { |
| 367 | m_client.initialize(client); |
| 368 | } |
| 369 | |
| 370 | void WebProcessPool::setInjectedBundleClient(std::unique_ptr<API::InjectedBundleClient>&& client) |
| 371 | { |
| 372 | if (!client) |
| 373 | m_injectedBundleClient = std::make_unique<API::InjectedBundleClient>(); |
| 374 | else |
| 375 | m_injectedBundleClient = WTFMove(client); |
| 376 | } |
| 377 | |
| 378 | void WebProcessPool::initializeConnectionClient(const WKContextConnectionClientBase* client) |
| 379 | { |
| 380 | m_connectionClient.initialize(client); |
| 381 | } |
| 382 | |
| 383 | void WebProcessPool::setHistoryClient(std::unique_ptr<API::LegacyContextHistoryClient>&& historyClient) |
| 384 | { |
| 385 | if (!historyClient) |
| 386 | m_historyClient = std::make_unique<API::LegacyContextHistoryClient>(); |
| 387 | else |
| 388 | m_historyClient = WTFMove(historyClient); |
| 389 | } |
| 390 | |
| 391 | void WebProcessPool::setDownloadClient(std::unique_ptr<API::DownloadClient>&& downloadClient) |
| 392 | { |
| 393 | if (!downloadClient) |
| 394 | m_downloadClient = std::make_unique<API::DownloadClient>(); |
| 395 | else |
| 396 | m_downloadClient = WTFMove(downloadClient); |
| 397 | } |
| 398 | |
| 399 | void WebProcessPool::setAutomationClient(std::unique_ptr<API::AutomationClient>&& automationClient) |
| 400 | { |
| 401 | if (!automationClient) |
| 402 | m_automationClient = std::make_unique<API::AutomationClient>(); |
| 403 | else |
| 404 | m_automationClient = WTFMove(automationClient); |
| 405 | } |
| 406 | |
| 407 | void WebProcessPool::setLegacyCustomProtocolManagerClient(std::unique_ptr<API::CustomProtocolManagerClient>&& customProtocolManagerClient) |
| 408 | { |
| 409 | #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) |
| 410 | if (!customProtocolManagerClient) |
| 411 | m_customProtocolManagerClient = std::make_unique<API::CustomProtocolManagerClient>(); |
| 412 | else |
| 413 | m_customProtocolManagerClient = WTFMove(customProtocolManagerClient); |
| 414 | #endif |
| 415 | } |
| 416 | |
| 417 | void WebProcessPool::setCustomWebContentServiceBundleIdentifier(const String& customWebContentServiceBundleIdentifier) |
| 418 | { |
| 419 | // Guard against API misuse. |
| 420 | if (!customWebContentServiceBundleIdentifier.isAllASCII()) |
| 421 | CRASH(); |
| 422 | |
| 423 | m_configuration->setCustomWebContentServiceBundleIdentifier(customWebContentServiceBundleIdentifier); |
| 424 | } |
| 425 | |
| 426 | IPC::Connection* WebProcessPool::networkingProcessConnection() |
| 427 | { |
| 428 | return m_networkProcess->connection(); |
| 429 | } |
| 430 | |
| 431 | void WebProcessPool::languageChanged(void* context) |
| 432 | { |
| 433 | static_cast<WebProcessPool*>(context)->languageChanged(); |
| 434 | } |
| 435 | |
| 436 | void WebProcessPool::languageChanged() |
| 437 | { |
| 438 | sendToAllProcesses(Messages::WebProcess::UserPreferredLanguagesChanged(userPreferredLanguages())); |
| 439 | #if USE(SOUP) |
| 440 | if (m_networkProcess) |
| 441 | m_networkProcess->send(Messages::NetworkProcess::UserPreferredLanguagesChanged(userPreferredLanguages()), 0); |
| 442 | #endif |
| 443 | } |
| 444 | |
| 445 | void WebProcessPool::fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled) |
| 446 | { |
| 447 | sendToAllProcesses(Messages::WebProcess::FullKeyboardAccessModeChanged(fullKeyboardAccessEnabled)); |
| 448 | } |
| 449 | |
| 450 | #if OS(LINUX) |
| 451 | void WebProcessPool::sendMemoryPressureEvent(bool isCritical) |
| 452 | { |
| 453 | sendToAllProcesses(Messages::AuxiliaryProcess::DidReceiveMemoryPressureEvent(isCritical)); |
| 454 | sendToNetworkingProcess(Messages::AuxiliaryProcess::DidReceiveMemoryPressureEvent(isCritical)); |
| 455 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 456 | PluginProcessManager::singleton().sendMemoryPressureEvent(isCritical); |
| 457 | #endif |
| 458 | } |
| 459 | #endif |
| 460 | |
| 461 | void WebProcessPool::textCheckerStateChanged() |
| 462 | { |
| 463 | sendToAllProcesses(Messages::WebProcess::SetTextCheckerState(TextChecker::state())); |
| 464 | } |
| 465 | |
| 466 | void WebProcessPool::setApplicationIsActive(bool isActive) |
| 467 | { |
| 468 | m_webProcessCache->setApplicationIsActive(isActive); |
| 469 | } |
| 470 | |
| 471 | void WebProcessPool::screenPropertiesStateChanged() |
| 472 | { |
| 473 | #if PLATFORM(MAC) |
| 474 | auto screenProperties = WebCore::collectScreenProperties(); |
| 475 | sendToAllProcesses(Messages::WebProcess::SetScreenProperties(screenProperties)); |
| 476 | #endif |
| 477 | } |
| 478 | |
| 479 | NetworkProcessProxy& WebProcessPool::ensureNetworkProcess(WebsiteDataStore* withWebsiteDataStore) |
| 480 | { |
| 481 | if (m_networkProcess) { |
| 482 | if (withWebsiteDataStore) { |
| 483 | m_networkProcess->addSession(makeRef(*withWebsiteDataStore)); |
| 484 | withWebsiteDataStore->clearPendingCookies(); |
| 485 | } |
| 486 | return *m_networkProcess; |
| 487 | } |
| 488 | |
| 489 | m_networkProcess = std::make_unique<NetworkProcessProxy>(*this); |
| 490 | |
| 491 | NetworkProcessCreationParameters parameters; |
| 492 | |
| 493 | if (m_websiteDataStore) { |
| 494 | parameters.defaultDataStoreParameters.pendingCookies = copyToVector(m_websiteDataStore->websiteDataStore().pendingCookies()); |
| 495 | m_websiteDataStore->websiteDataStore().clearPendingCookies(); |
| 496 | #if PLATFORM(COCOA) |
| 497 | parameters.defaultDataStoreParameters.networkSessionParameters.sourceApplicationBundleIdentifier = m_websiteDataStore->websiteDataStore().sourceApplicationBundleIdentifier(); |
| 498 | parameters.defaultDataStoreParameters.networkSessionParameters.sourceApplicationSecondaryIdentifier = m_websiteDataStore->websiteDataStore().sourceApplicationSecondaryIdentifier(); |
| 499 | parameters.defaultDataStoreParameters.networkSessionParameters.allowsTLSFallback = m_websiteDataStore->websiteDataStore().allowsTLSFallback() ? AllowsTLSFallback::Yes : AllowsTLSFallback::No; |
| 500 | #endif |
| 501 | m_websiteDataStore->websiteDataStore().networkingHasBegun(); |
| 502 | } |
| 503 | |
| 504 | parameters.cacheModel = cacheModel(); |
| 505 | parameters.canHandleHTTPSServerTrustEvaluation = m_canHandleHTTPSServerTrustEvaluation; |
| 506 | |
| 507 | for (auto& scheme : globalURLSchemesWithCustomProtocolHandlers()) |
| 508 | parameters.urlSchemesRegisteredForCustomProtocols.append(scheme); |
| 509 | |
| 510 | for (auto& scheme : m_urlSchemesRegisteredForCustomProtocols) |
| 511 | parameters.urlSchemesRegisteredForCustomProtocols.append(scheme); |
| 512 | |
| 513 | parameters.diskCacheDirectory = m_configuration->diskCacheDirectory(); |
| 514 | if (!parameters.diskCacheDirectory.isEmpty()) |
| 515 | SandboxExtension::createHandleForReadWriteDirectory(parameters.diskCacheDirectory, parameters.diskCacheDirectoryExtensionHandle); |
| 516 | #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION) |
| 517 | parameters.shouldEnableNetworkCacheSpeculativeRevalidation = m_configuration->diskCacheSpeculativeValidationEnabled(); |
| 518 | #endif |
| 519 | |
| 520 | #if PLATFORM(IOS_FAMILY) |
| 521 | String cookieStorageDirectory = this->cookieStorageDirectory(); |
| 522 | if (!cookieStorageDirectory.isEmpty()) |
| 523 | SandboxExtension::createHandleForReadWriteDirectory(cookieStorageDirectory, parameters.cookieStorageDirectoryExtensionHandle); |
| 524 | |
| 525 | String containerCachesDirectory = this->networkingCachesDirectory(); |
| 526 | if (!containerCachesDirectory.isEmpty()) |
| 527 | SandboxExtension::createHandleForReadWriteDirectory(containerCachesDirectory, parameters.containerCachesDirectoryExtensionHandle); |
| 528 | |
| 529 | String parentBundleDirectory = this->parentBundleDirectory(); |
| 530 | if (!parentBundleDirectory.isEmpty()) |
| 531 | SandboxExtension::createHandle(parentBundleDirectory, SandboxExtension::Type::ReadOnly, parameters.parentBundleDirectoryExtensionHandle); |
| 532 | |
| 533 | #if ENABLE(INDEXED_DATABASE) |
| 534 | SandboxExtension::createHandleForTemporaryFile(emptyString(), SandboxExtension::Type::ReadWrite, parameters.defaultDataStoreParameters.indexedDatabaseTempBlobDirectoryExtensionHandle); |
| 535 | #endif |
| 536 | #endif |
| 537 | |
| 538 | parameters.hstsStorageDirectory = m_configuration->hstsStorageDirectory(); |
| 539 | if (!parameters.hstsStorageDirectory.isNull()) |
| 540 | SandboxExtension::createHandleForReadWriteDirectory(parameters.hstsStorageDirectory, parameters.hstsStorageDirectoryExtensionHandle); |
| 541 | |
| 542 | parameters.shouldUseTestingNetworkSession = m_shouldUseTestingNetworkSession; |
| 543 | |
| 544 | parameters.urlSchemesRegisteredAsSecure = copyToVector(m_schemesToRegisterAsSecure); |
| 545 | parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy = copyToVector(m_schemesToRegisterAsBypassingContentSecurityPolicy); |
| 546 | parameters.urlSchemesRegisteredAsLocal = copyToVector(m_schemesToRegisterAsLocal); |
| 547 | parameters.urlSchemesRegisteredAsNoAccess = copyToVector(m_schemesToRegisterAsNoAccess); |
| 548 | parameters.urlSchemesRegisteredAsDisplayIsolated = copyToVector(m_schemesToRegisterAsDisplayIsolated); |
| 549 | parameters.urlSchemesRegisteredAsCORSEnabled = copyToVector(m_schemesToRegisterAsCORSEnabled); |
| 550 | parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest = copyToVector(m_schemesToRegisterAsCanDisplayOnlyIfCanRequest); |
| 551 | |
| 552 | #if ENABLE(INDEXED_DATABASE) |
| 553 | // ********* |
| 554 | // IMPORTANT: Do not change the directory structure for indexed databases on disk without first consulting a reviewer from Apple (<rdar://problem/17454712>) |
| 555 | // ********* |
| 556 | parameters.defaultDataStoreParameters.indexedDatabaseDirectory = m_configuration->indexedDBDatabaseDirectory(); |
| 557 | if (parameters.defaultDataStoreParameters.indexedDatabaseDirectory.isEmpty()) |
| 558 | parameters.defaultDataStoreParameters.indexedDatabaseDirectory = API::WebsiteDataStore::defaultDataStore()->websiteDataStore().parameters().indexedDatabaseDirectory; |
| 559 | |
| 560 | SandboxExtension::createHandleForReadWriteDirectory(parameters.defaultDataStoreParameters.indexedDatabaseDirectory, parameters.defaultDataStoreParameters.indexedDatabaseDirectoryExtensionHandle); |
| 561 | m_networkProcess->createSymLinkForFileUpgrade(parameters.defaultDataStoreParameters.indexedDatabaseDirectory); |
| 562 | #endif |
| 563 | |
| 564 | #if ENABLE(SERVICE_WORKER) |
| 565 | if (m_websiteDataStore) |
| 566 | parameters.serviceWorkerRegistrationDirectory = m_websiteDataStore->websiteDataStore().resolvedServiceWorkerRegistrationDirectory(); |
| 567 | if (!parameters.serviceWorkerRegistrationDirectory) |
| 568 | parameters.serviceWorkerRegistrationDirectory = API::WebsiteDataStore::defaultServiceWorkerRegistrationDirectory(); |
| 569 | SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle); |
| 570 | |
| 571 | if (!m_schemesServiceWorkersCanHandle.isEmpty()) |
| 572 | parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle); |
| 573 | |
| 574 | parameters.shouldDisableServiceWorkerProcessTerminationDelay = m_shouldDisableServiceWorkerProcessTerminationDelay; |
| 575 | #endif |
| 576 | |
| 577 | if (m_websiteDataStore) |
| 578 | parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsDirectory = m_websiteDataStore->websiteDataStore().resolvedResourceLoadStatisticsDirectory(); |
| 579 | if (parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsDirectory.isEmpty()) |
| 580 | parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsDirectory = API::WebsiteDataStore::defaultResourceLoadStatisticsDirectory(); |
| 581 | |
| 582 | SandboxExtension::createHandleForReadWriteDirectory(parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsDirectory, parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsDirectoryExtensionHandle); |
| 583 | |
| 584 | bool enableResourceLoadStatistics = false; |
| 585 | bool shouldIncludeLocalhost = true; |
| 586 | bool enableResourceLoadStatisticsDebugMode = false; |
| 587 | WebCore::RegistrableDomain manualPrevalentResource { }; |
| 588 | if (withWebsiteDataStore) { |
| 589 | enableResourceLoadStatistics = withWebsiteDataStore->resourceLoadStatisticsEnabled(); |
| 590 | if (enableResourceLoadStatistics) { |
| 591 | auto networkSessionParameters = withWebsiteDataStore->parameters().networkSessionParameters; |
| 592 | shouldIncludeLocalhost = networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics; |
| 593 | enableResourceLoadStatisticsDebugMode = networkSessionParameters.enableResourceLoadStatisticsDebugMode; |
| 594 | manualPrevalentResource = networkSessionParameters.resourceLoadStatisticsManualPrevalentResource; |
| 595 | } |
| 596 | |
| 597 | parameters.defaultDataStoreParameters.perOriginStorageQuota = withWebsiteDataStore->perOriginStorageQuota(); |
| 598 | parameters.defaultDataStoreParameters.perThirdPartyOriginStorageQuota = withWebsiteDataStore->perThirdPartyOriginStorageQuota(); |
| 599 | } else if (m_websiteDataStore) { |
| 600 | enableResourceLoadStatistics = m_websiteDataStore->resourceLoadStatisticsEnabled(); |
| 601 | if (enableResourceLoadStatistics) { |
| 602 | auto networkSessionParameters = m_websiteDataStore->websiteDataStore().parameters().networkSessionParameters; |
| 603 | shouldIncludeLocalhost = networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics; |
| 604 | enableResourceLoadStatisticsDebugMode = networkSessionParameters.enableResourceLoadStatisticsDebugMode; |
| 605 | manualPrevalentResource = networkSessionParameters.resourceLoadStatisticsManualPrevalentResource; |
| 606 | } |
| 607 | |
| 608 | parameters.defaultDataStoreParameters.perOriginStorageQuota = m_websiteDataStore->websiteDataStore().perOriginStorageQuota(); |
| 609 | parameters.defaultDataStoreParameters.perThirdPartyOriginStorageQuota = m_websiteDataStore->websiteDataStore().perThirdPartyOriginStorageQuota(); |
| 610 | } |
| 611 | |
| 612 | parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatistics = enableResourceLoadStatistics; |
| 613 | parameters.defaultDataStoreParameters.networkSessionParameters.shouldIncludeLocalhostInResourceLoadStatistics = shouldIncludeLocalhost; |
| 614 | parameters.defaultDataStoreParameters.networkSessionParameters.enableResourceLoadStatisticsDebugMode = enableResourceLoadStatisticsDebugMode; |
| 615 | parameters.defaultDataStoreParameters.networkSessionParameters.resourceLoadStatisticsManualPrevalentResource = manualPrevalentResource; |
| 616 | |
| 617 | // Add any platform specific parameters |
| 618 | platformInitializeNetworkProcess(parameters); |
| 619 | |
| 620 | // Initialize the network process. |
| 621 | m_networkProcess->send(Messages::NetworkProcess::InitializeNetworkProcess(parameters), 0); |
| 622 | |
| 623 | if (WebPreferences::anyPagesAreUsingPrivateBrowsing()) |
| 624 | m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters()), 0); |
| 625 | |
| 626 | #if PLATFORM(COCOA) |
| 627 | m_networkProcess->send(Messages::NetworkProcess::SetQOS(networkProcessLatencyQOS(), networkProcessThroughputQOS()), 0); |
| 628 | #endif |
| 629 | |
| 630 | if (m_didNetworkProcessCrash) { |
| 631 | m_didNetworkProcessCrash = false; |
| 632 | reinstateNetworkProcessAssertionState(*m_networkProcess); |
| 633 | } |
| 634 | |
| 635 | if (withWebsiteDataStore) { |
| 636 | m_networkProcess->addSession(makeRef(*withWebsiteDataStore)); |
| 637 | withWebsiteDataStore->clearPendingCookies(); |
| 638 | } |
| 639 | |
| 640 | // Make sure the network process knows about all the sessions that have been registered before it started. |
| 641 | for (auto& sessionID : m_sessionToPageIDsMap.keys()) { |
| 642 | if (auto* websiteDataStore = WebsiteDataStore::existingNonDefaultDataStoreForSessionID(sessionID)) |
| 643 | m_networkProcess->addSession(*websiteDataStore); |
| 644 | } |
| 645 | |
| 646 | return *m_networkProcess; |
| 647 | } |
| 648 | |
| 649 | void WebProcessPool::networkProcessCrashed(NetworkProcessProxy& networkProcessProxy, Vector<std::pair<RefPtr<WebProcessProxy>, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>>&& pendingReplies) |
| 650 | { |
| 651 | ASSERT(m_networkProcess); |
| 652 | ASSERT(&networkProcessProxy == m_networkProcess.get()); |
| 653 | m_didNetworkProcessCrash = true; |
| 654 | |
| 655 | for (auto& supplement : m_supplements.values()) |
| 656 | supplement->processDidClose(&networkProcessProxy); |
| 657 | |
| 658 | m_client.networkProcessDidCrash(this); |
| 659 | |
| 660 | if (m_automationSession) |
| 661 | m_automationSession->terminate(); |
| 662 | |
| 663 | // Leave the process proxy around during client call, so that the client could query the process identifier. |
| 664 | m_networkProcess = nullptr; |
| 665 | |
| 666 | // Attempt to re-launch. |
| 667 | if (pendingReplies.isEmpty()) |
| 668 | return; |
| 669 | auto& newNetworkProcess = ensureNetworkProcess(); |
| 670 | for (auto& reply : pendingReplies) |
| 671 | newNetworkProcess.getNetworkProcessConnection(*reply.first, WTFMove(reply.second)); |
| 672 | } |
| 673 | |
| 674 | void WebProcessPool::getNetworkProcessConnection(WebProcessProxy& webProcessProxy, Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply&& reply) |
| 675 | { |
| 676 | ensureNetworkProcess(); |
| 677 | ASSERT(m_networkProcess); |
| 678 | |
| 679 | m_networkProcess->getNetworkProcessConnection(webProcessProxy, WTFMove(reply)); |
| 680 | } |
| 681 | |
| 682 | #if ENABLE(SERVICE_WORKER) |
| 683 | void WebProcessPool::establishWorkerContextConnectionToNetworkProcess(NetworkProcessProxy& proxy, RegistrableDomain&& registrableDomain, Optional<PAL::SessionID> sessionID) |
| 684 | { |
| 685 | ASSERT_UNUSED(proxy, &proxy == m_networkProcess.get()); |
| 686 | |
| 687 | if (m_serviceWorkerProcesses.contains(registrableDomain)) |
| 688 | return; |
| 689 | |
| 690 | m_mayHaveRegisteredServiceWorkers.clear(); |
| 691 | |
| 692 | WebsiteDataStore* websiteDataStore = nullptr; |
| 693 | if (sessionID) |
| 694 | websiteDataStore = WebsiteDataStore::existingNonDefaultDataStoreForSessionID(*sessionID); |
| 695 | |
| 696 | if (!websiteDataStore) { |
| 697 | if (!m_websiteDataStore) |
| 698 | m_websiteDataStore = API::WebsiteDataStore::defaultDataStore().ptr(); |
| 699 | websiteDataStore = &m_websiteDataStore->websiteDataStore(); |
| 700 | } |
| 701 | |
| 702 | if (m_serviceWorkerProcesses.isEmpty()) |
| 703 | sendToAllProcesses(Messages::WebProcess::RegisterServiceWorkerClients { }); |
| 704 | |
| 705 | auto serviceWorkerProcessProxy = ServiceWorkerProcessProxy::create(*this, registrableDomain, *websiteDataStore); |
| 706 | m_serviceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcessProxy.ptr()); |
| 707 | |
| 708 | updateProcessAssertions(); |
| 709 | initializeNewWebProcess(serviceWorkerProcessProxy, websiteDataStore); |
| 710 | |
| 711 | auto* serviceWorkerProcessProxyPtr = serviceWorkerProcessProxy.ptr(); |
| 712 | m_processes.append(WTFMove(serviceWorkerProcessProxy)); |
| 713 | |
| 714 | serviceWorkerProcessProxyPtr->start(m_serviceWorkerPreferences ? m_serviceWorkerPreferences.value() : m_defaultPageGroup->preferences().store(), sessionID); |
| 715 | if (!m_serviceWorkerUserAgent.isNull()) |
| 716 | serviceWorkerProcessProxyPtr->setUserAgent(m_serviceWorkerUserAgent); |
| 717 | } |
| 718 | #endif |
| 719 | |
| 720 | void WebProcessPool::disableServiceWorkerProcessTerminationDelay() |
| 721 | { |
| 722 | #if ENABLE(SERVICE_WORKER) |
| 723 | if (m_shouldDisableServiceWorkerProcessTerminationDelay) |
| 724 | return; |
| 725 | |
| 726 | m_shouldDisableServiceWorkerProcessTerminationDelay = true; |
| 727 | if (m_networkProcess) |
| 728 | m_networkProcess->send(Messages::NetworkProcess::DisableServiceWorkerProcessTerminationDelay(), 0); |
| 729 | #endif |
| 730 | } |
| 731 | |
| 732 | void WebProcessPool::willStartUsingPrivateBrowsing() |
| 733 | { |
| 734 | for (auto* processPool : allProcessPools()) |
| 735 | processPool->setAnyPageGroupMightHavePrivateBrowsingEnabled(true); |
| 736 | } |
| 737 | |
| 738 | void WebProcessPool::willStopUsingPrivateBrowsing() |
| 739 | { |
| 740 | for (auto* processPool : allProcessPools()) |
| 741 | processPool->setAnyPageGroupMightHavePrivateBrowsingEnabled(false); |
| 742 | } |
| 743 | |
| 744 | void WebProcessPool::windowServerConnectionStateChanged() |
| 745 | { |
| 746 | size_t processCount = m_processes.size(); |
| 747 | for (size_t i = 0; i < processCount; ++i) |
| 748 | m_processes[i]->windowServerConnectionStateChanged(); |
| 749 | } |
| 750 | |
| 751 | void WebProcessPool::setAnyPageGroupMightHavePrivateBrowsingEnabled(bool privateBrowsingEnabled) |
| 752 | { |
| 753 | if (privateBrowsingEnabled) { |
| 754 | ensureNetworkProcess().send(Messages::NetworkProcess::AddWebsiteDataStore(WebsiteDataStoreParameters::legacyPrivateSessionParameters()), 0); |
| 755 | } else { |
| 756 | if (auto* networkProcess = this->networkProcess()) |
| 757 | networkProcess->removeSession(PAL::SessionID::legacyPrivateSessionID()); |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | void (*s_invalidMessageCallback)(WKStringRef messageName); |
| 762 | |
| 763 | void WebProcessPool::setInvalidMessageCallback(void (*invalidMessageCallback)(WKStringRef messageName)) |
| 764 | { |
| 765 | s_invalidMessageCallback = invalidMessageCallback; |
| 766 | } |
| 767 | |
| 768 | void WebProcessPool::didReceiveInvalidMessage(const IPC::StringReference& messageReceiverName, const IPC::StringReference& messageName) |
| 769 | { |
| 770 | if (!s_invalidMessageCallback) |
| 771 | return; |
| 772 | |
| 773 | StringBuilder messageNameStringBuilder; |
| 774 | messageNameStringBuilder.append(messageReceiverName.data(), messageReceiverName.size()); |
| 775 | messageNameStringBuilder.append('.'); |
| 776 | messageNameStringBuilder.append(messageName.data(), messageName.size()); |
| 777 | |
| 778 | s_invalidMessageCallback(toAPI(API::String::create(messageNameStringBuilder.toString()).ptr())); |
| 779 | } |
| 780 | |
| 781 | void WebProcessPool::processDidCachePage(WebProcessProxy* process) |
| 782 | { |
| 783 | if (m_processWithPageCache && m_processWithPageCache != process) |
| 784 | m_processWithPageCache->releasePageCache(); |
| 785 | m_processWithPageCache = process; |
| 786 | } |
| 787 | |
| 788 | void WebProcessPool::resolvePathsForSandboxExtensions() |
| 789 | { |
| 790 | m_resolvedPaths.injectedBundlePath = resolvePathForSandboxExtension(injectedBundlePath()); |
| 791 | m_resolvedPaths.applicationCacheDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->applicationCacheDirectory()); |
| 792 | m_resolvedPaths.webSQLDatabaseDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->webSQLDatabaseDirectory()); |
| 793 | m_resolvedPaths.mediaCacheDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->mediaCacheDirectory()); |
| 794 | m_resolvedPaths.mediaKeyStorageDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->mediaKeysStorageDirectory()); |
| 795 | m_resolvedPaths.indexedDatabaseDirectory = resolveAndCreateReadWriteDirectoryForSandboxExtension(m_configuration->indexedDBDatabaseDirectory()); |
| 796 | |
| 797 | m_resolvedPaths.additionalWebProcessSandboxExtensionPaths.reserveCapacity(m_configuration->additionalReadAccessAllowedPaths().size()); |
| 798 | for (const auto& path : m_configuration->additionalReadAccessAllowedPaths()) |
| 799 | m_resolvedPaths.additionalWebProcessSandboxExtensionPaths.uncheckedAppend(resolvePathForSandboxExtension(path.data())); |
| 800 | |
| 801 | platformResolvePathsForSandboxExtensions(); |
| 802 | } |
| 803 | |
| 804 | WebProcessProxy& WebProcessPool::createNewWebProcess(WebsiteDataStore* websiteDataStore, WebProcessProxy::IsPrewarmed isPrewarmed) |
| 805 | { |
| 806 | auto processProxy = WebProcessProxy::create(*this, websiteDataStore, isPrewarmed); |
| 807 | auto& process = processProxy.get(); |
| 808 | initializeNewWebProcess(process, websiteDataStore, isPrewarmed); |
| 809 | m_processes.append(WTFMove(processProxy)); |
| 810 | |
| 811 | if (m_serviceWorkerProcessesTerminationTimer.isActive()) |
| 812 | m_serviceWorkerProcessesTerminationTimer.stop(); |
| 813 | |
| 814 | return process; |
| 815 | } |
| 816 | |
| 817 | RefPtr<WebProcessProxy> WebProcessPool::tryTakePrewarmedProcess(WebsiteDataStore& websiteDataStore) |
| 818 | { |
| 819 | if (!m_prewarmedProcess) |
| 820 | return nullptr; |
| 821 | |
| 822 | ASSERT(m_prewarmedProcess->isPrewarmed()); |
| 823 | m_prewarmedProcess->markIsNoLongerInPrewarmedPool(); |
| 824 | |
| 825 | m_prewarmedProcess->setWebsiteDataStore(websiteDataStore); |
| 826 | sendWebProcessDataStoreParameters(*m_prewarmedProcess, websiteDataStore); |
| 827 | |
| 828 | return std::exchange(m_prewarmedProcess, nullptr); |
| 829 | } |
| 830 | |
| 831 | #if PLATFORM(MAC) |
| 832 | static void displayReconfigurationCallBack(CGDirectDisplayID display, CGDisplayChangeSummaryFlags flags, void *userInfo) |
| 833 | { |
| 834 | auto screenProperties = WebCore::collectScreenProperties(); |
| 835 | for (auto& processPool : WebProcessPool::allProcessPools()) { |
| 836 | processPool->sendToAllProcesses(Messages::WebProcess::SetScreenProperties(screenProperties)); |
| 837 | #if ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) |
| 838 | processPool->sendToAllProcesses(Messages::WebProcess::DisplayConfigurationChanged(display, flags)); |
| 839 | #endif |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | static void registerDisplayConfigurationCallback() |
| 844 | { |
| 845 | static std::once_flag onceFlag; |
| 846 | std::call_once( |
| 847 | onceFlag, |
| 848 | [] { |
| 849 | CGDisplayRegisterReconfigurationCallback(displayReconfigurationCallBack, nullptr); |
| 850 | }); |
| 851 | } |
| 852 | #endif |
| 853 | |
| 854 | void WebProcessPool::sendWebProcessDataStoreParameters(WebProcessProxy& process, WebsiteDataStore& websiteDataStore) |
| 855 | { |
| 856 | WebProcessDataStoreParameters parameters; |
| 857 | |
| 858 | websiteDataStore.resolveDirectoriesIfNecessary(); |
| 859 | |
| 860 | parameters.applicationCacheDirectory = websiteDataStore.resolvedApplicationCacheDirectory(); |
| 861 | if (parameters.applicationCacheDirectory.isEmpty()) |
| 862 | parameters.applicationCacheDirectory = m_resolvedPaths.applicationCacheDirectory; |
| 863 | if (!parameters.applicationCacheDirectory.isEmpty()) |
| 864 | SandboxExtension::createHandleWithoutResolvingPath(parameters.applicationCacheDirectory, SandboxExtension::Type::ReadWrite, parameters.applicationCacheDirectoryExtensionHandle); |
| 865 | parameters.applicationCacheFlatFileSubdirectoryName = m_configuration->applicationCacheFlatFileSubdirectoryName(); |
| 866 | |
| 867 | parameters.webSQLDatabaseDirectory = websiteDataStore.resolvedDatabaseDirectory(); |
| 868 | if (parameters.webSQLDatabaseDirectory.isEmpty()) |
| 869 | parameters.webSQLDatabaseDirectory = m_resolvedPaths.webSQLDatabaseDirectory; |
| 870 | if (!parameters.webSQLDatabaseDirectory.isEmpty()) |
| 871 | SandboxExtension::createHandleWithoutResolvingPath(parameters.webSQLDatabaseDirectory, SandboxExtension::Type::ReadWrite, parameters.webSQLDatabaseDirectoryExtensionHandle); |
| 872 | |
| 873 | parameters.mediaCacheDirectory = websiteDataStore.resolvedMediaCacheDirectory(); |
| 874 | if (parameters.mediaCacheDirectory.isEmpty()) |
| 875 | parameters.mediaCacheDirectory = m_resolvedPaths.mediaCacheDirectory; |
| 876 | if (!parameters.mediaCacheDirectory.isEmpty()) |
| 877 | SandboxExtension::createHandleWithoutResolvingPath(parameters.mediaCacheDirectory, SandboxExtension::Type::ReadWrite, parameters.mediaCacheDirectoryExtensionHandle); |
| 878 | |
| 879 | parameters.mediaKeyStorageDirectory = websiteDataStore.resolvedMediaKeysDirectory(); |
| 880 | if (parameters.mediaKeyStorageDirectory.isEmpty()) |
| 881 | parameters.mediaKeyStorageDirectory = m_resolvedPaths.mediaKeyStorageDirectory; |
| 882 | if (!parameters.mediaKeyStorageDirectory.isEmpty()) |
| 883 | SandboxExtension::createHandleWithoutResolvingPath(parameters.mediaKeyStorageDirectory, SandboxExtension::Type::ReadWrite, parameters.mediaKeyStorageDirectoryExtensionHandle); |
| 884 | |
| 885 | if (javaScriptConfigurationFileEnabled()) { |
| 886 | parameters.javaScriptConfigurationDirectory = websiteDataStore.resolvedJavaScriptConfigurationDirectory(); |
| 887 | if (!parameters.javaScriptConfigurationDirectory.isEmpty()) |
| 888 | SandboxExtension::createHandleWithoutResolvingPath(parameters.javaScriptConfigurationDirectory, SandboxExtension::Type::ReadWrite, parameters.javaScriptConfigurationDirectoryExtensionHandle); |
| 889 | } |
| 890 | |
| 891 | parameters.resourceLoadStatisticsEnabled = websiteDataStore.resourceLoadStatisticsEnabled(); |
| 892 | |
| 893 | process.send(Messages::WebProcess::SetWebsiteDataStoreParameters(parameters), 0); |
| 894 | } |
| 895 | |
| 896 | void WebProcessPool::initializeNewWebProcess(WebProcessProxy& process, WebsiteDataStore* websiteDataStore, WebProcessProxy::IsPrewarmed isPrewarmed) |
| 897 | { |
| 898 | auto initializationActivityToken = process.throttler().backgroundActivityToken(); |
| 899 | auto scopeExit = makeScopeExit([&process, initializationActivityToken] { |
| 900 | // Round-trip to the Web Content process before releasing the |
| 901 | // initialization activity token, so that we're sure that all |
| 902 | // messages sent from this function have been handled. |
| 903 | process.isResponsive([initializationActivityToken] (bool) { }); |
| 904 | }); |
| 905 | |
| 906 | ensureNetworkProcess(); |
| 907 | |
| 908 | WebProcessCreationParameters parameters; |
| 909 | |
| 910 | parameters.injectedBundlePath = m_resolvedPaths.injectedBundlePath; |
| 911 | if (!parameters.injectedBundlePath.isEmpty()) |
| 912 | SandboxExtension::createHandleWithoutResolvingPath(parameters.injectedBundlePath, SandboxExtension::Type::ReadOnly, parameters.injectedBundlePathExtensionHandle); |
| 913 | |
| 914 | parameters.additionalSandboxExtensionHandles.allocate(m_resolvedPaths.additionalWebProcessSandboxExtensionPaths.size()); |
| 915 | for (size_t i = 0, size = m_resolvedPaths.additionalWebProcessSandboxExtensionPaths.size(); i < size; ++i) |
| 916 | SandboxExtension::createHandleWithoutResolvingPath(m_resolvedPaths.additionalWebProcessSandboxExtensionPaths[i], SandboxExtension::Type::ReadOnly, parameters.additionalSandboxExtensionHandles[i]); |
| 917 | |
| 918 | #if PLATFORM(IOS_FAMILY) |
| 919 | setJavaScriptConfigurationFileEnabledFromDefaults(); |
| 920 | #endif |
| 921 | |
| 922 | parameters.cacheModel = cacheModel(); |
| 923 | parameters.languages = configuration().overrideLanguages().isEmpty() ? userPreferredLanguages() : configuration().overrideLanguages(); |
| 924 | |
| 925 | parameters.urlSchemesRegisteredAsEmptyDocument = copyToVector(m_schemesToRegisterAsEmptyDocument); |
| 926 | parameters.urlSchemesRegisteredAsSecure = copyToVector(m_schemesToRegisterAsSecure); |
| 927 | parameters.urlSchemesRegisteredAsBypassingContentSecurityPolicy = copyToVector(m_schemesToRegisterAsBypassingContentSecurityPolicy); |
| 928 | parameters.urlSchemesForWhichDomainRelaxationIsForbidden = copyToVector(m_schemesToSetDomainRelaxationForbiddenFor); |
| 929 | parameters.urlSchemesRegisteredAsLocal = copyToVector(m_schemesToRegisterAsLocal); |
| 930 | parameters.urlSchemesRegisteredAsNoAccess = copyToVector(m_schemesToRegisterAsNoAccess); |
| 931 | parameters.urlSchemesRegisteredAsDisplayIsolated = copyToVector(m_schemesToRegisterAsDisplayIsolated); |
| 932 | parameters.urlSchemesRegisteredAsCORSEnabled = copyToVector(m_schemesToRegisterAsCORSEnabled); |
| 933 | parameters.urlSchemesRegisteredAsAlwaysRevalidated = copyToVector(m_schemesToRegisterAsAlwaysRevalidated); |
| 934 | parameters.urlSchemesRegisteredAsCachePartitioned = copyToVector(m_schemesToRegisterAsCachePartitioned); |
| 935 | parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle); |
| 936 | parameters.urlSchemesRegisteredAsCanDisplayOnlyIfCanRequest = copyToVector(m_schemesToRegisterAsCanDisplayOnlyIfCanRequest); |
| 937 | |
| 938 | parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath; |
| 939 | parameters.shouldUseFontSmoothing = m_shouldUseFontSmoothing; |
| 940 | |
| 941 | parameters.terminationTimeout = 0_s; |
| 942 | |
| 943 | parameters.textCheckerState = TextChecker::state(); |
| 944 | |
| 945 | parameters.fullKeyboardAccessEnabled = WebProcessProxy::fullKeyboardAccessEnabled(); |
| 946 | |
| 947 | parameters.defaultRequestTimeoutInterval = API::URLRequest::defaultTimeoutInterval(); |
| 948 | |
| 949 | #if ENABLE(NOTIFICATIONS) |
| 950 | // FIXME: There should be a generic way for supplements to add to the intialization parameters. |
| 951 | parameters.notificationPermissions = supplement<WebNotificationManagerProxy>()->notificationPermissions(); |
| 952 | #endif |
| 953 | |
| 954 | parameters.plugInAutoStartOriginHashes = m_plugInAutoStartProvider.autoStartOriginHashesCopy(); |
| 955 | parameters.plugInAutoStartOrigins = copyToVector(m_plugInAutoStartProvider.autoStartOrigins()); |
| 956 | |
| 957 | parameters.memoryCacheDisabled = m_memoryCacheDisabled; |
| 958 | parameters.attrStyleEnabled = m_configuration->attrStyleEnabled(); |
| 959 | |
| 960 | #if ENABLE(SERVICE_CONTROLS) |
| 961 | auto& serviceController = ServicesController::singleton(); |
| 962 | parameters.hasImageServices = serviceController.hasImageServices(); |
| 963 | parameters.hasSelectionServices = serviceController.hasSelectionServices(); |
| 964 | parameters.hasRichContentServices = serviceController.hasRichContentServices(); |
| 965 | serviceController.refreshExistingServices(); |
| 966 | #endif |
| 967 | |
| 968 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 969 | parameters.pluginLoadClientPolicies = m_pluginLoadClientPolicies; |
| 970 | #endif |
| 971 | |
| 972 | #if OS(LINUX) |
| 973 | parameters.shouldEnableMemoryPressureReliefLogging = true; |
| 974 | #endif |
| 975 | |
| 976 | #if PLATFORM(WAYLAND) && USE(EGL) |
| 977 | if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland) |
| 978 | parameters.waylandCompositorDisplayName = WaylandCompositor::singleton().displayName(); |
| 979 | #endif |
| 980 | |
| 981 | #if ENABLE(MEDIA_STREAM) |
| 982 | parameters.shouldCaptureAudioInUIProcess = m_configuration->shouldCaptureAudioInUIProcess(); |
| 983 | parameters.shouldCaptureVideoInUIProcess = m_configuration->shouldCaptureVideoInUIProcess(); |
| 984 | parameters.shouldCaptureDisplayInUIProcess = m_configuration->shouldCaptureDisplayInUIProcess(); |
| 985 | #endif |
| 986 | |
| 987 | parameters.presentingApplicationPID = m_configuration->presentingApplicationPID(); |
| 988 | |
| 989 | #if PLATFORM(COCOA) |
| 990 | parameters.mediaMIMETypes = process.mediaMIMETypes(); |
| 991 | #endif |
| 992 | |
| 993 | #if PLATFORM(WPE) |
| 994 | parameters.isServiceWorkerProcess = process.isServiceWorkerProcess(); |
| 995 | #endif |
| 996 | |
| 997 | // Add any platform specific parameters |
| 998 | platformInitializeWebProcess(parameters); |
| 999 | |
| 1000 | RefPtr<API::Object> injectedBundleInitializationUserData = m_injectedBundleClient->getInjectedBundleInitializationUserData(*this); |
| 1001 | if (!injectedBundleInitializationUserData) |
| 1002 | injectedBundleInitializationUserData = m_injectedBundleInitializationUserData; |
| 1003 | parameters.initializationUserData = UserData(process.transformObjectsToHandles(injectedBundleInitializationUserData.get())); |
| 1004 | |
| 1005 | process.send(Messages::WebProcess::InitializeWebProcess(parameters), 0); |
| 1006 | |
| 1007 | #if PLATFORM(COCOA) |
| 1008 | process.send(Messages::WebProcess::SetQOS(webProcessLatencyQOS(), webProcessThroughputQOS()), 0); |
| 1009 | #endif |
| 1010 | |
| 1011 | if (websiteDataStore) |
| 1012 | sendWebProcessDataStoreParameters(process, *websiteDataStore); |
| 1013 | |
| 1014 | if (m_automationSession) |
| 1015 | process.send(Messages::WebProcess::EnsureAutomationSessionProxy(m_automationSession->sessionIdentifier()), 0); |
| 1016 | |
| 1017 | ASSERT(m_messagesToInjectedBundlePostedToEmptyContext.isEmpty()); |
| 1018 | |
| 1019 | if (isPrewarmed == WebProcessProxy::IsPrewarmed::Yes) { |
| 1020 | ASSERT(!m_prewarmedProcess); |
| 1021 | m_prewarmedProcess = &process; |
| 1022 | process.send(Messages::WebProcess::PrewarmGlobally(), 0); |
| 1023 | } |
| 1024 | |
| 1025 | #if PLATFORM(IOS) |
| 1026 | process.send(Messages::WebProcess::BacklightLevelDidChange(displayBrightness()), 0); |
| 1027 | #endif |
| 1028 | |
| 1029 | #if ENABLE(REMOTE_INSPECTOR) |
| 1030 | // Initialize remote inspector connection now that we have a sub-process that is hosting one of our web views. |
| 1031 | Inspector::RemoteInspector::singleton(); |
| 1032 | #endif |
| 1033 | |
| 1034 | #if PLATFORM(MAC) |
| 1035 | registerDisplayConfigurationCallback(); |
| 1036 | #endif |
| 1037 | } |
| 1038 | |
| 1039 | void WebProcessPool::prewarmProcess() |
| 1040 | { |
| 1041 | if (m_prewarmedProcess) |
| 1042 | return; |
| 1043 | |
| 1044 | RELEASE_LOG(PerformanceLogging, "Prewarming a WebProcess for performance" ); |
| 1045 | createNewWebProcess(nullptr, WebProcessProxy::IsPrewarmed::Yes); |
| 1046 | } |
| 1047 | |
| 1048 | void WebProcessPool::enableProcessTermination() |
| 1049 | { |
| 1050 | m_processTerminationEnabled = true; |
| 1051 | Vector<RefPtr<WebProcessProxy>> processes = m_processes; |
| 1052 | for (size_t i = 0; i < processes.size(); ++i) { |
| 1053 | if (shouldTerminate(processes[i].get())) |
| 1054 | processes[i]->terminate(); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | bool WebProcessPool::shouldTerminate(WebProcessProxy* process) |
| 1059 | { |
| 1060 | ASSERT(m_processes.contains(process)); |
| 1061 | |
| 1062 | if (!m_processTerminationEnabled || m_configuration->alwaysKeepAndReuseSwappedProcesses()) |
| 1063 | return false; |
| 1064 | |
| 1065 | return true; |
| 1066 | } |
| 1067 | |
| 1068 | void WebProcessPool::processDidFinishLaunching(WebProcessProxy* process) |
| 1069 | { |
| 1070 | ASSERT(m_processes.contains(process)); |
| 1071 | |
| 1072 | if (!m_visitedLinksPopulated) { |
| 1073 | populateVisitedLinks(); |
| 1074 | m_visitedLinksPopulated = true; |
| 1075 | } |
| 1076 | |
| 1077 | // Sometimes the memorySampler gets initialized after process initialization has happened but before the process has finished launching |
| 1078 | // so check if it needs to be started here |
| 1079 | if (m_memorySamplerEnabled) { |
| 1080 | SandboxExtension::Handle sampleLogSandboxHandle; |
| 1081 | WallTime now = WallTime::now(); |
| 1082 | String sampleLogFilePath = makeString("WebProcess" , static_cast<unsigned long long>(now.secondsSinceEpoch().seconds()), "pid" , process->processIdentifier()); |
| 1083 | sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::Type::ReadWrite, sampleLogSandboxHandle); |
| 1084 | |
| 1085 | process->send(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, m_memorySamplerInterval), 0); |
| 1086 | } |
| 1087 | |
| 1088 | if (m_configuration->fullySynchronousModeIsAllowedForTesting()) |
| 1089 | process->connection()->allowFullySynchronousModeForTesting(); |
| 1090 | |
| 1091 | if (m_configuration->ignoreSynchronousMessagingTimeoutsForTesting()) |
| 1092 | process->connection()->ignoreTimeoutsForTesting(); |
| 1093 | |
| 1094 | m_connectionClient.didCreateConnection(this, process->webConnection()); |
| 1095 | |
| 1096 | if (m_websiteDataStore) |
| 1097 | m_websiteDataStore->websiteDataStore().didCreateNetworkProcess(); |
| 1098 | } |
| 1099 | |
| 1100 | void WebProcessPool::disconnectProcess(WebProcessProxy* process) |
| 1101 | { |
| 1102 | ASSERT(m_processes.contains(process)); |
| 1103 | ASSERT(!m_processesPlayingAudibleMedia.contains(process->coreProcessIdentifier())); |
| 1104 | |
| 1105 | if (m_prewarmedProcess == process) { |
| 1106 | ASSERT(m_prewarmedProcess->isPrewarmed()); |
| 1107 | m_prewarmedProcess = nullptr; |
| 1108 | } |
| 1109 | |
| 1110 | if (m_dummyProcessProxy == process) |
| 1111 | m_dummyProcessProxy = nullptr; |
| 1112 | |
| 1113 | // FIXME (Multi-WebProcess): <rdar://problem/12239765> Some of the invalidation calls of the other supplements are still necessary in multi-process mode, but they should only affect data structures pertaining to the process being disconnected. |
| 1114 | // Clearing everything causes assertion failures, so it's less trouble to skip that for now. |
| 1115 | RefPtr<WebProcessProxy> protect(process); |
| 1116 | if (m_processWithPageCache == process) |
| 1117 | m_processWithPageCache = nullptr; |
| 1118 | |
| 1119 | m_suspendedPages.removeAllMatching([process](auto& suspendedPage) { |
| 1120 | return &suspendedPage->process() == process; |
| 1121 | }); |
| 1122 | |
| 1123 | #if ENABLE(SERVICE_WORKER) |
| 1124 | if (is<ServiceWorkerProcessProxy>(*process)) { |
| 1125 | auto* removedProcess = m_serviceWorkerProcesses.take(downcast<ServiceWorkerProcessProxy>(*process).registrableDomain()); |
| 1126 | ASSERT_UNUSED(removedProcess, removedProcess == process); |
| 1127 | updateProcessAssertions(); |
| 1128 | } |
| 1129 | #endif |
| 1130 | |
| 1131 | static_cast<WebContextSupplement*>(supplement<WebGeolocationManagerProxy>())->processDidClose(process); |
| 1132 | |
| 1133 | m_processes.removeFirst(process); |
| 1134 | |
| 1135 | #if ENABLE(GAMEPAD) |
| 1136 | if (m_processesUsingGamepads.contains(process)) |
| 1137 | processStoppedUsingGamepads(*process); |
| 1138 | #endif |
| 1139 | |
| 1140 | removeProcessFromOriginCacheSet(*process); |
| 1141 | |
| 1142 | #if ENABLE(SERVICE_WORKER) |
| 1143 | // FIXME: We should do better than this. For now, we just destroy the ServiceWorker process |
| 1144 | // whenever there is no regular WebContent process remaining. |
| 1145 | if (m_processes.size() == m_serviceWorkerProcesses.size()) { |
| 1146 | if (!m_serviceWorkerProcessesTerminationTimer.isActive()) |
| 1147 | m_serviceWorkerProcessesTerminationTimer.startOneShot(serviceWorkerTerminationDelay); |
| 1148 | } |
| 1149 | #endif |
| 1150 | } |
| 1151 | |
| 1152 | WebProcessProxy& WebProcessPool::processForRegistrableDomain(WebsiteDataStore& websiteDataStore, WebPageProxy* page, const RegistrableDomain& registrableDomain) |
| 1153 | { |
| 1154 | if (!registrableDomain.isEmpty()) { |
| 1155 | if (auto process = webProcessCache().takeProcess(registrableDomain, websiteDataStore)) |
| 1156 | return *process; |
| 1157 | |
| 1158 | // Check if we have a suspended page for the given registrable domain and use its process if we do, for performance reasons. |
| 1159 | if (auto process = page ? findReusableSuspendedPageProcess(registrableDomain, *page, websiteDataStore) : nullptr) { |
| 1160 | RELEASE_LOG(ProcessSwapping, "Using WebProcess %i from a SuspendedPage" , process->processIdentifier()); |
| 1161 | return *process; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | if (auto process = tryTakePrewarmedProcess(websiteDataStore)) { |
| 1166 | RELEASE_LOG(ProcessSwapping, "Using prewarmed process %i" , process->processIdentifier()); |
| 1167 | if (!registrableDomain.isEmpty()) |
| 1168 | tryPrewarmWithDomainInformation(*process, registrableDomain); |
| 1169 | return *process; |
| 1170 | } |
| 1171 | |
| 1172 | if (!usesSingleWebProcess()) |
| 1173 | return createNewWebProcess(&websiteDataStore); |
| 1174 | |
| 1175 | #if PLATFORM(COCOA) |
| 1176 | bool mustMatchDataStore = API::WebsiteDataStore::defaultDataStoreExists() && &websiteDataStore != &API::WebsiteDataStore::defaultDataStore()->websiteDataStore(); |
| 1177 | #else |
| 1178 | bool mustMatchDataStore = false; |
| 1179 | #endif |
| 1180 | |
| 1181 | for (auto& process : m_processes) { |
| 1182 | if (process == m_prewarmedProcess || process == m_dummyProcessProxy) |
| 1183 | continue; |
| 1184 | #if ENABLE(SERVICE_WORKER) |
| 1185 | if (is<ServiceWorkerProcessProxy>(*process)) |
| 1186 | continue; |
| 1187 | #endif |
| 1188 | if (mustMatchDataStore && &process->websiteDataStore() != &websiteDataStore) |
| 1189 | continue; |
| 1190 | return *process; |
| 1191 | } |
| 1192 | return createNewWebProcess(&websiteDataStore); |
| 1193 | } |
| 1194 | |
| 1195 | Ref<WebPageProxy> WebProcessPool::createWebPage(PageClient& pageClient, Ref<API::PageConfiguration>&& pageConfiguration) |
| 1196 | { |
| 1197 | if (!pageConfiguration->pageGroup()) |
| 1198 | pageConfiguration->setPageGroup(m_defaultPageGroup.ptr()); |
| 1199 | if (!pageConfiguration->preferences()) |
| 1200 | pageConfiguration->setPreferences(&pageConfiguration->pageGroup()->preferences()); |
| 1201 | if (!pageConfiguration->userContentController()) |
| 1202 | pageConfiguration->setUserContentController(&pageConfiguration->pageGroup()->userContentController()); |
| 1203 | if (!pageConfiguration->visitedLinkStore()) |
| 1204 | pageConfiguration->setVisitedLinkStore(m_visitedLinkStore.ptr()); |
| 1205 | |
| 1206 | if (!pageConfiguration->websiteDataStore()) { |
| 1207 | // We try to avoid creating the default data store as long as possible. |
| 1208 | // But if there is an attempt to create a web page without any specified data store, then we have to create it. |
| 1209 | if (!m_websiteDataStore) |
| 1210 | m_websiteDataStore = API::WebsiteDataStore::defaultDataStore().ptr(); |
| 1211 | |
| 1212 | ASSERT(!pageConfiguration->sessionID().isValid()); |
| 1213 | pageConfiguration->setWebsiteDataStore(m_websiteDataStore.get()); |
| 1214 | pageConfiguration->setSessionID(pageConfiguration->preferences()->privateBrowsingEnabled() ? PAL::SessionID::legacyPrivateSessionID() : m_websiteDataStore->websiteDataStore().sessionID()); |
| 1215 | } |
| 1216 | |
| 1217 | RefPtr<WebProcessProxy> process; |
| 1218 | auto* relatedPage = pageConfiguration->relatedPage(); |
| 1219 | if (relatedPage && !relatedPage->isClosed()) { |
| 1220 | // Sharing processes, e.g. when creating the page via window.open(). |
| 1221 | process = &pageConfiguration->relatedPage()->ensureRunningProcess(); |
| 1222 | // We do not support several WebsiteDataStores sharing a single process. |
| 1223 | ASSERT(process.get() == m_dummyProcessProxy || &pageConfiguration->websiteDataStore()->websiteDataStore() == &process->websiteDataStore()); |
| 1224 | ASSERT(&pageConfiguration->relatedPage()->websiteDataStore() == &pageConfiguration->websiteDataStore()->websiteDataStore()); |
| 1225 | } else if (!m_isDelayedWebProcessLaunchDisabled) { |
| 1226 | // In the common case, we delay process launch until something is actually loaded in the page. |
| 1227 | if (!m_dummyProcessProxy) { |
| 1228 | auto dummyProcessProxy = WebProcessProxy::create(*this, nullptr, WebProcessProxy::IsPrewarmed::No, WebProcessProxy::ShouldLaunchProcess::No); |
| 1229 | m_dummyProcessProxy = dummyProcessProxy.ptr(); |
| 1230 | m_processes.append(WTFMove(dummyProcessProxy)); |
| 1231 | } |
| 1232 | process = m_dummyProcessProxy; |
| 1233 | } else |
| 1234 | process = &processForRegistrableDomain(pageConfiguration->websiteDataStore()->websiteDataStore(), nullptr, { }); |
| 1235 | |
| 1236 | ASSERT(process); |
| 1237 | |
| 1238 | auto page = process->createWebPage(pageClient, WTFMove(pageConfiguration)); |
| 1239 | |
| 1240 | #if ENABLE(SERVICE_WORKER) |
| 1241 | ASSERT(!is<ServiceWorkerProcessProxy>(*process)); |
| 1242 | |
| 1243 | if (!m_serviceWorkerPreferences) { |
| 1244 | m_serviceWorkerPreferences = page->preferencesStore(); |
| 1245 | for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) |
| 1246 | serviceWorkerProcess->updatePreferencesStore(*m_serviceWorkerPreferences); |
| 1247 | } |
| 1248 | #endif |
| 1249 | |
| 1250 | bool enableProcessSwapOnCrossSiteNavigation = page->preferences().processSwapOnCrossSiteNavigationEnabled(); |
| 1251 | #if PLATFORM(IOS_FAMILY) |
| 1252 | if (WebCore::IOSApplication::isFirefox() && !linkedOnOrAfter(WebKit::SDKVersion::FirstWithProcessSwapOnCrossSiteNavigation)) |
| 1253 | enableProcessSwapOnCrossSiteNavigation = false; |
| 1254 | #endif |
| 1255 | |
| 1256 | bool wasProcessSwappingOnNavigationEnabled = m_configuration->processSwapsOnNavigation(); |
| 1257 | m_configuration->setProcessSwapsOnNavigationFromExperimentalFeatures(enableProcessSwapOnCrossSiteNavigation); |
| 1258 | if (wasProcessSwappingOnNavigationEnabled != m_configuration->processSwapsOnNavigation()) |
| 1259 | m_webProcessCache->updateCapacity(*this); |
| 1260 | |
| 1261 | m_configuration->setShouldCaptureAudioInUIProcess(page->preferences().captureAudioInUIProcessEnabled()); |
| 1262 | m_configuration->setShouldCaptureVideoInUIProcess(page->preferences().captureVideoInUIProcessEnabled()); |
| 1263 | |
| 1264 | return page; |
| 1265 | } |
| 1266 | |
| 1267 | #if ENABLE(SERVICE_WORKER) |
| 1268 | void WebProcessPool::updateServiceWorkerUserAgent(const String& userAgent) |
| 1269 | { |
| 1270 | if (m_serviceWorkerUserAgent == userAgent) |
| 1271 | return; |
| 1272 | m_serviceWorkerUserAgent = userAgent; |
| 1273 | for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) |
| 1274 | serviceWorkerProcess->setUserAgent(m_serviceWorkerUserAgent); |
| 1275 | } |
| 1276 | |
| 1277 | bool WebProcessPool::mayHaveRegisteredServiceWorkers(const WebsiteDataStore& store) |
| 1278 | { |
| 1279 | if (!m_serviceWorkerProcesses.isEmpty()) |
| 1280 | return true; |
| 1281 | |
| 1282 | String serviceWorkerRegistrationDirectory = store.resolvedServiceWorkerRegistrationDirectory(); |
| 1283 | if (serviceWorkerRegistrationDirectory.isEmpty()) |
| 1284 | serviceWorkerRegistrationDirectory = API::WebsiteDataStore::defaultDataStoreConfiguration()->serviceWorkerRegistrationDirectory(); |
| 1285 | |
| 1286 | return m_mayHaveRegisteredServiceWorkers.ensure(serviceWorkerRegistrationDirectory, [&] { |
| 1287 | // FIXME: Make this computation on a background thread. |
| 1288 | return ServiceWorkerProcessProxy::hasRegisteredServiceWorkers(serviceWorkerRegistrationDirectory); |
| 1289 | }).iterator->value; |
| 1290 | } |
| 1291 | #endif |
| 1292 | |
| 1293 | void WebProcessPool::pageBeginUsingWebsiteDataStore(uint64_t pageID, WebsiteDataStore& dataStore) |
| 1294 | { |
| 1295 | auto result = m_sessionToPageIDsMap.add(dataStore.sessionID(), HashSet<uint64_t>()).iterator->value.add(pageID); |
| 1296 | ASSERT_UNUSED(result, result.isNewEntry); |
| 1297 | |
| 1298 | auto sessionID = dataStore.sessionID(); |
| 1299 | if (sessionID.isEphemeral()) { |
| 1300 | ASSERT(dataStore.parameters().networkSessionParameters.sessionID == sessionID); |
| 1301 | if (m_networkProcess) { |
| 1302 | m_networkProcess->addSession(makeRef(dataStore)); |
| 1303 | dataStore.clearPendingCookies(); |
| 1304 | } |
| 1305 | } else if (sessionID != PAL::SessionID::defaultSessionID()) { |
| 1306 | if (m_networkProcess) { |
| 1307 | m_networkProcess->addSession(makeRef(dataStore)); |
| 1308 | dataStore.clearPendingCookies(); |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | |
| 1313 | void WebProcessPool::pageEndUsingWebsiteDataStore(uint64_t pageID, WebsiteDataStore& dataStore) |
| 1314 | { |
| 1315 | auto sessionID = dataStore.sessionID(); |
| 1316 | auto iterator = m_sessionToPageIDsMap.find(sessionID); |
| 1317 | ASSERT(iterator != m_sessionToPageIDsMap.end()); |
| 1318 | |
| 1319 | auto takenPageID = iterator->value.take(pageID); |
| 1320 | ASSERT_UNUSED(takenPageID, takenPageID == pageID); |
| 1321 | |
| 1322 | if (iterator->value.isEmpty()) { |
| 1323 | m_sessionToPageIDsMap.remove(iterator); |
| 1324 | |
| 1325 | if (sessionID == PAL::SessionID::defaultSessionID()) |
| 1326 | return; |
| 1327 | |
| 1328 | // The last user of this non-default PAL::SessionID is gone, so clean it up in the child processes. |
| 1329 | if (networkProcess()) |
| 1330 | networkProcess()->removeSession(sessionID); |
| 1331 | |
| 1332 | m_webProcessCache->clearAllProcessesForSession(sessionID); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | bool WebProcessPool::hasPagesUsingWebsiteDataStore(WebsiteDataStore& dataStore) const |
| 1337 | { |
| 1338 | return m_sessionToPageIDsMap.contains(dataStore.sessionID()); |
| 1339 | } |
| 1340 | |
| 1341 | DownloadProxy& WebProcessPool::download(WebPageProxy* initiatingPage, const ResourceRequest& request, const String& suggestedFilename) |
| 1342 | { |
| 1343 | auto& downloadProxy = createDownloadProxy(request, initiatingPage); |
| 1344 | PAL::SessionID sessionID = initiatingPage ? initiatingPage->sessionID() : PAL::SessionID::defaultSessionID(); |
| 1345 | |
| 1346 | if (initiatingPage) |
| 1347 | initiatingPage->handleDownloadRequest(downloadProxy); |
| 1348 | |
| 1349 | if (networkProcess()) { |
| 1350 | ResourceRequest updatedRequest(request); |
| 1351 | // Request's firstPartyForCookies will be used as Original URL of the download request. |
| 1352 | // We set the value to top level document's URL. |
| 1353 | if (initiatingPage) { |
| 1354 | URL initiatingPageURL = URL { URL { }, initiatingPage->pageLoadState().url() }; |
| 1355 | updatedRequest.setFirstPartyForCookies(initiatingPageURL); |
| 1356 | updatedRequest.setIsSameSite(areRegistrableDomainsEqual(initiatingPageURL, request.url())); |
| 1357 | if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent)) |
| 1358 | updatedRequest.setHTTPUserAgent(initiatingPage->userAgent()); |
| 1359 | } else { |
| 1360 | updatedRequest.setFirstPartyForCookies(URL()); |
| 1361 | updatedRequest.setIsSameSite(false); |
| 1362 | if (!updatedRequest.hasHTTPHeaderField(HTTPHeaderName::UserAgent)) |
| 1363 | updatedRequest.setHTTPUserAgent(WebPageProxy::standardUserAgent()); |
| 1364 | } |
| 1365 | updatedRequest.setIsTopSite(false); |
| 1366 | networkProcess()->send(Messages::NetworkProcess::DownloadRequest(sessionID, downloadProxy.downloadID(), updatedRequest, suggestedFilename), 0); |
| 1367 | return downloadProxy; |
| 1368 | } |
| 1369 | |
| 1370 | return downloadProxy; |
| 1371 | } |
| 1372 | |
| 1373 | DownloadProxy& WebProcessPool::resumeDownload(WebPageProxy* initiatingPage, const API::Data* resumeData, const String& path) |
| 1374 | { |
| 1375 | auto& downloadProxy = createDownloadProxy(ResourceRequest(), initiatingPage); |
| 1376 | PAL::SessionID sessionID = initiatingPage ? initiatingPage->sessionID() : PAL::SessionID::defaultSessionID(); |
| 1377 | |
| 1378 | SandboxExtension::Handle sandboxExtensionHandle; |
| 1379 | if (!path.isEmpty()) |
| 1380 | SandboxExtension::createHandle(path, SandboxExtension::Type::ReadWrite, sandboxExtensionHandle); |
| 1381 | |
| 1382 | if (networkProcess()) { |
| 1383 | networkProcess()->send(Messages::NetworkProcess::ResumeDownload(sessionID, downloadProxy.downloadID(), resumeData->dataReference(), path, sandboxExtensionHandle), 0); |
| 1384 | return downloadProxy; |
| 1385 | } |
| 1386 | |
| 1387 | return downloadProxy; |
| 1388 | } |
| 1389 | |
| 1390 | void WebProcessPool::postMessageToInjectedBundle(const String& messageName, API::Object* messageBody) |
| 1391 | { |
| 1392 | for (auto& process : m_processes) { |
| 1393 | // FIXME: Return early if the message body contains any references to WKPageRefs/WKFrameRefs etc. since they're local to a process. |
| 1394 | process->send(Messages::WebProcess::HandleInjectedBundleMessage(messageName, UserData(process->transformObjectsToHandles(messageBody).get())), 0); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | void WebProcessPool::didReachGoodTimeToPrewarm() |
| 1399 | { |
| 1400 | if (!configuration().isAutomaticProcessWarmingEnabled() || !configuration().processSwapsOnNavigation() || usesSingleWebProcess()) |
| 1401 | return; |
| 1402 | |
| 1403 | if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) { |
| 1404 | if (!m_prewarmedProcess) |
| 1405 | RELEASE_LOG(PerformanceLogging, "Not automatically prewarming a WebProcess due to memory pressure" ); |
| 1406 | return; |
| 1407 | } |
| 1408 | |
| 1409 | prewarmProcess(); |
| 1410 | } |
| 1411 | |
| 1412 | void WebProcessPool::populateVisitedLinks() |
| 1413 | { |
| 1414 | m_historyClient->populateVisitedLinks(*this); |
| 1415 | } |
| 1416 | |
| 1417 | WebProcessPool::Statistics& WebProcessPool::statistics() |
| 1418 | { |
| 1419 | static Statistics statistics = Statistics(); |
| 1420 | |
| 1421 | return statistics; |
| 1422 | } |
| 1423 | |
| 1424 | void WebProcessPool::handleMemoryPressureWarning(Critical) |
| 1425 | { |
| 1426 | RELEASE_LOG(PerformanceLogging, "%p - WebProcessPool::handleMemoryPressureWarning" , this); |
| 1427 | |
| 1428 | |
| 1429 | clearSuspendedPages(AllowProcessCaching::No); |
| 1430 | m_webProcessCache->clear(); |
| 1431 | |
| 1432 | if (m_prewarmedProcess) |
| 1433 | m_prewarmedProcess->shutDown(); |
| 1434 | ASSERT(!m_prewarmedProcess); |
| 1435 | } |
| 1436 | |
| 1437 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 1438 | void WebProcessPool::setAdditionalPluginsDirectory(const String& directory) |
| 1439 | { |
| 1440 | Vector<String> directories; |
| 1441 | directories.append(directory); |
| 1442 | |
| 1443 | m_pluginInfoStore.setAdditionalPluginsDirectories(directories); |
| 1444 | } |
| 1445 | |
| 1446 | void WebProcessPool::refreshPlugins() |
| 1447 | { |
| 1448 | m_pluginInfoStore.refresh(); |
| 1449 | sendToAllProcesses(Messages::WebProcess::RefreshPlugins()); |
| 1450 | } |
| 1451 | |
| 1452 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
| 1453 | |
| 1454 | ProcessID WebProcessPool::networkProcessIdentifier() |
| 1455 | { |
| 1456 | return m_networkProcess ? m_networkProcess->processIdentifier() : 0; |
| 1457 | } |
| 1458 | |
| 1459 | ProcessID WebProcessPool::prewarmedProcessIdentifier() |
| 1460 | { |
| 1461 | return m_prewarmedProcess ? m_prewarmedProcess->processIdentifier() : 0; |
| 1462 | } |
| 1463 | |
| 1464 | void WebProcessPool::activePagesOriginsInWebProcessForTesting(ProcessID pid, CompletionHandler<void(Vector<String>&&)>&& completionHandler) |
| 1465 | { |
| 1466 | for (auto& process : m_processes) { |
| 1467 | if (process->processIdentifier() == pid) |
| 1468 | return process->activePagesDomainsForTesting(WTFMove(completionHandler)); |
| 1469 | } |
| 1470 | completionHandler({ }); |
| 1471 | } |
| 1472 | |
| 1473 | void WebProcessPool::setAlwaysUsesComplexTextCodePath(bool alwaysUseComplexText) |
| 1474 | { |
| 1475 | m_alwaysUsesComplexTextCodePath = alwaysUseComplexText; |
| 1476 | sendToAllProcesses(Messages::WebProcess::SetAlwaysUsesComplexTextCodePath(alwaysUseComplexText)); |
| 1477 | } |
| 1478 | |
| 1479 | void WebProcessPool::setShouldUseFontSmoothing(bool useFontSmoothing) |
| 1480 | { |
| 1481 | m_shouldUseFontSmoothing = useFontSmoothing; |
| 1482 | sendToAllProcesses(Messages::WebProcess::SetShouldUseFontSmoothing(useFontSmoothing)); |
| 1483 | } |
| 1484 | |
| 1485 | void WebProcessPool::setResourceLoadStatisticsEnabled(bool enabled) |
| 1486 | { |
| 1487 | sendToAllProcesses(Messages::WebProcess::SetResourceLoadStatisticsEnabled(enabled)); |
| 1488 | } |
| 1489 | |
| 1490 | void WebProcessPool::clearResourceLoadStatistics() |
| 1491 | { |
| 1492 | sendToAllProcesses(Messages::WebProcess::ClearResourceLoadStatistics()); |
| 1493 | } |
| 1494 | |
| 1495 | void WebProcessPool::registerURLSchemeAsEmptyDocument(const String& urlScheme) |
| 1496 | { |
| 1497 | m_schemesToRegisterAsEmptyDocument.add(urlScheme); |
| 1498 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsEmptyDocument(urlScheme)); |
| 1499 | } |
| 1500 | |
| 1501 | void WebProcessPool::registerURLSchemeAsSecure(const String& urlScheme) |
| 1502 | { |
| 1503 | m_schemesToRegisterAsSecure.add(urlScheme); |
| 1504 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsSecure(urlScheme)); |
| 1505 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsSecure(urlScheme)); |
| 1506 | } |
| 1507 | |
| 1508 | void WebProcessPool::registerURLSchemeAsBypassingContentSecurityPolicy(const String& urlScheme) |
| 1509 | { |
| 1510 | m_schemesToRegisterAsBypassingContentSecurityPolicy.add(urlScheme); |
| 1511 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsBypassingContentSecurityPolicy(urlScheme)); |
| 1512 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsBypassingContentSecurityPolicy(urlScheme)); |
| 1513 | } |
| 1514 | |
| 1515 | void WebProcessPool::setDomainRelaxationForbiddenForURLScheme(const String& urlScheme) |
| 1516 | { |
| 1517 | m_schemesToSetDomainRelaxationForbiddenFor.add(urlScheme); |
| 1518 | sendToAllProcesses(Messages::WebProcess::SetDomainRelaxationForbiddenForURLScheme(urlScheme)); |
| 1519 | } |
| 1520 | |
| 1521 | void WebProcessPool::setCanHandleHTTPSServerTrustEvaluation(bool value) |
| 1522 | { |
| 1523 | m_canHandleHTTPSServerTrustEvaluation = value; |
| 1524 | if (m_networkProcess) { |
| 1525 | m_networkProcess->send(Messages::NetworkProcess::SetCanHandleHTTPSServerTrustEvaluation(value), 0); |
| 1526 | return; |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | void WebProcessPool::preconnectToServer(const URL& url) |
| 1531 | { |
| 1532 | if (!url.isValid() || !url.protocolIsInHTTPFamily()) |
| 1533 | return; |
| 1534 | |
| 1535 | ensureNetworkProcess().send(Messages::NetworkProcess::PreconnectTo(url, StoredCredentialsPolicy::Use), 0); |
| 1536 | } |
| 1537 | |
| 1538 | void WebProcessPool::registerURLSchemeAsLocal(const String& urlScheme) |
| 1539 | { |
| 1540 | m_schemesToRegisterAsLocal.add(urlScheme); |
| 1541 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsLocal(urlScheme)); |
| 1542 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsLocal(urlScheme)); |
| 1543 | } |
| 1544 | |
| 1545 | void WebProcessPool::registerURLSchemeAsNoAccess(const String& urlScheme) |
| 1546 | { |
| 1547 | m_schemesToRegisterAsNoAccess.add(urlScheme); |
| 1548 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsNoAccess(urlScheme)); |
| 1549 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsNoAccess(urlScheme)); |
| 1550 | } |
| 1551 | |
| 1552 | void WebProcessPool::registerURLSchemeAsDisplayIsolated(const String& urlScheme) |
| 1553 | { |
| 1554 | m_schemesToRegisterAsDisplayIsolated.add(urlScheme); |
| 1555 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsDisplayIsolated(urlScheme)); |
| 1556 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsDisplayIsolated(urlScheme)); |
| 1557 | } |
| 1558 | |
| 1559 | void WebProcessPool::registerURLSchemeAsCORSEnabled(const String& urlScheme) |
| 1560 | { |
| 1561 | m_schemesToRegisterAsCORSEnabled.add(urlScheme); |
| 1562 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCORSEnabled(urlScheme)); |
| 1563 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsCORSEnabled(urlScheme)); |
| 1564 | } |
| 1565 | |
| 1566 | void WebProcessPool::registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme) |
| 1567 | { |
| 1568 | if (!urlScheme) |
| 1569 | return; |
| 1570 | |
| 1571 | globalURLSchemesWithCustomProtocolHandlers().add(urlScheme); |
| 1572 | for (auto* processPool : allProcessPools()) |
| 1573 | processPool->registerSchemeForCustomProtocol(urlScheme); |
| 1574 | } |
| 1575 | |
| 1576 | void WebProcessPool::unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String& urlScheme) |
| 1577 | { |
| 1578 | if (!urlScheme) |
| 1579 | return; |
| 1580 | |
| 1581 | globalURLSchemesWithCustomProtocolHandlers().remove(urlScheme); |
| 1582 | for (auto* processPool : allProcessPools()) |
| 1583 | processPool->unregisterSchemeForCustomProtocol(urlScheme); |
| 1584 | } |
| 1585 | |
| 1586 | void WebProcessPool::registerURLSchemeAsCachePartitioned(const String& urlScheme) |
| 1587 | { |
| 1588 | m_schemesToRegisterAsCachePartitioned.add(urlScheme); |
| 1589 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCachePartitioned(urlScheme)); |
| 1590 | } |
| 1591 | |
| 1592 | void WebProcessPool::registerURLSchemeServiceWorkersCanHandle(const String& urlScheme) |
| 1593 | { |
| 1594 | m_schemesServiceWorkersCanHandle.add(urlScheme); |
| 1595 | sendToAllProcesses(Messages::AuxiliaryProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme)); |
| 1596 | if (m_networkProcess) |
| 1597 | m_networkProcess->send(Messages::AuxiliaryProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme), 0); |
| 1598 | } |
| 1599 | |
| 1600 | void WebProcessPool::registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String& urlScheme) |
| 1601 | { |
| 1602 | m_schemesToRegisterAsCanDisplayOnlyIfCanRequest.add(urlScheme); |
| 1603 | sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCanDisplayOnlyIfCanRequest(urlScheme)); |
| 1604 | sendToNetworkingProcess(Messages::NetworkProcess::RegisterURLSchemeAsCanDisplayOnlyIfCanRequest(urlScheme)); |
| 1605 | } |
| 1606 | |
| 1607 | void WebProcessPool::updateMaxSuspendedPageCount() |
| 1608 | { |
| 1609 | unsigned dummy = 0; |
| 1610 | Seconds dummyInterval; |
| 1611 | unsigned pageCacheSize = 0; |
| 1612 | calculateMemoryCacheSizes(m_configuration->cacheModel(), dummy, dummy, dummy, dummyInterval, pageCacheSize); |
| 1613 | |
| 1614 | m_maxSuspendedPageCount = pageCacheSize; |
| 1615 | |
| 1616 | while (m_suspendedPages.size() > m_maxSuspendedPageCount) |
| 1617 | m_suspendedPages.removeFirst(); |
| 1618 | } |
| 1619 | |
| 1620 | void WebProcessPool::setCacheModel(CacheModel cacheModel) |
| 1621 | { |
| 1622 | m_configuration->setCacheModel(cacheModel); |
| 1623 | updateMaxSuspendedPageCount(); |
| 1624 | |
| 1625 | sendToAllProcesses(Messages::WebProcess::SetCacheModel(cacheModel)); |
| 1626 | |
| 1627 | if (m_networkProcess) |
| 1628 | m_networkProcess->send(Messages::NetworkProcess::SetCacheModel(cacheModel), 0); |
| 1629 | } |
| 1630 | |
| 1631 | void WebProcessPool::setDefaultRequestTimeoutInterval(double timeoutInterval) |
| 1632 | { |
| 1633 | sendToAllProcesses(Messages::WebProcess::SetDefaultRequestTimeoutInterval(timeoutInterval)); |
| 1634 | } |
| 1635 | |
| 1636 | DownloadProxy& WebProcessPool::createDownloadProxy(const ResourceRequest& request, WebPageProxy* originatingPage) |
| 1637 | { |
| 1638 | auto& downloadProxy = ensureNetworkProcess().createDownloadProxy(request); |
| 1639 | downloadProxy.setOriginatingPage(originatingPage); |
| 1640 | return downloadProxy; |
| 1641 | } |
| 1642 | |
| 1643 | void WebProcessPool::synthesizeAppIsBackground(bool background) |
| 1644 | { |
| 1645 | ensureNetworkProcess().synthesizeAppIsBackground(background); |
| 1646 | } |
| 1647 | |
| 1648 | void WebProcessPool::addMessageReceiver(IPC::StringReference messageReceiverName, IPC::MessageReceiver& messageReceiver) |
| 1649 | { |
| 1650 | m_messageReceiverMap.addMessageReceiver(messageReceiverName, messageReceiver); |
| 1651 | } |
| 1652 | |
| 1653 | void WebProcessPool::addMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID, IPC::MessageReceiver& messageReceiver) |
| 1654 | { |
| 1655 | m_messageReceiverMap.addMessageReceiver(messageReceiverName, destinationID, messageReceiver); |
| 1656 | } |
| 1657 | |
| 1658 | void WebProcessPool::removeMessageReceiver(IPC::StringReference messageReceiverName) |
| 1659 | { |
| 1660 | m_messageReceiverMap.removeMessageReceiver(messageReceiverName); |
| 1661 | } |
| 1662 | |
| 1663 | void WebProcessPool::removeMessageReceiver(IPC::StringReference messageReceiverName, uint64_t destinationID) |
| 1664 | { |
| 1665 | m_messageReceiverMap.removeMessageReceiver(messageReceiverName, destinationID); |
| 1666 | } |
| 1667 | |
| 1668 | bool WebProcessPool::dispatchMessage(IPC::Connection& connection, IPC::Decoder& decoder) |
| 1669 | { |
| 1670 | return m_messageReceiverMap.dispatchMessage(connection, decoder); |
| 1671 | } |
| 1672 | |
| 1673 | bool WebProcessPool::dispatchSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder) |
| 1674 | { |
| 1675 | return m_messageReceiverMap.dispatchSyncMessage(connection, decoder, replyEncoder); |
| 1676 | } |
| 1677 | |
| 1678 | void WebProcessPool::setEnhancedAccessibility(bool flag) |
| 1679 | { |
| 1680 | sendToAllProcesses(Messages::WebProcess::SetEnhancedAccessibility(flag)); |
| 1681 | } |
| 1682 | |
| 1683 | void WebProcessPool::startMemorySampler(const double interval) |
| 1684 | { |
| 1685 | // For new WebProcesses we will also want to start the Memory Sampler |
| 1686 | m_memorySamplerEnabled = true; |
| 1687 | m_memorySamplerInterval = interval; |
| 1688 | |
| 1689 | // For UIProcess |
| 1690 | #if ENABLE(MEMORY_SAMPLER) |
| 1691 | WebMemorySampler::singleton()->start(interval); |
| 1692 | #endif |
| 1693 | |
| 1694 | // For WebProcess |
| 1695 | SandboxExtension::Handle sampleLogSandboxHandle; |
| 1696 | WallTime now = WallTime::now(); |
| 1697 | String sampleLogFilePath = makeString("WebProcess" , static_cast<unsigned long long>(now.secondsSinceEpoch().seconds())); |
| 1698 | sampleLogFilePath = SandboxExtension::createHandleForTemporaryFile(sampleLogFilePath, SandboxExtension::Type::ReadWrite, sampleLogSandboxHandle); |
| 1699 | |
| 1700 | sendToAllProcesses(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, interval)); |
| 1701 | } |
| 1702 | |
| 1703 | void WebProcessPool::stopMemorySampler() |
| 1704 | { |
| 1705 | // For WebProcess |
| 1706 | m_memorySamplerEnabled = false; |
| 1707 | |
| 1708 | // For UIProcess |
| 1709 | #if ENABLE(MEMORY_SAMPLER) |
| 1710 | WebMemorySampler::singleton()->stop(); |
| 1711 | #endif |
| 1712 | |
| 1713 | sendToAllProcesses(Messages::WebProcess::StopMemorySampler()); |
| 1714 | } |
| 1715 | |
| 1716 | void WebProcessPool::useTestingNetworkSession() |
| 1717 | { |
| 1718 | ASSERT(m_processes.isEmpty()); |
| 1719 | ASSERT(!m_networkProcess); |
| 1720 | |
| 1721 | if (m_networkProcess) |
| 1722 | return; |
| 1723 | |
| 1724 | if (!m_processes.isEmpty()) |
| 1725 | return; |
| 1726 | |
| 1727 | m_shouldUseTestingNetworkSession = true; |
| 1728 | } |
| 1729 | |
| 1730 | template<typename T, typename U> |
| 1731 | void WebProcessPool::sendSyncToNetworkingProcess(T&& message, U&& reply) |
| 1732 | { |
| 1733 | if (m_networkProcess && m_networkProcess->canSendMessage()) |
| 1734 | m_networkProcess->sendSync(std::forward<T>(message), std::forward<U>(reply), 0); |
| 1735 | } |
| 1736 | |
| 1737 | void WebProcessPool::setAllowsAnySSLCertificateForWebSocket(bool allows) |
| 1738 | { |
| 1739 | sendSyncToNetworkingProcess(Messages::NetworkProcess::SetAllowsAnySSLCertificateForWebSocket(allows), Messages::NetworkProcess::SetAllowsAnySSLCertificateForWebSocket::Reply()); |
| 1740 | } |
| 1741 | |
| 1742 | void WebProcessPool::clearCachedCredentials() |
| 1743 | { |
| 1744 | if (m_networkProcess) |
| 1745 | m_networkProcess->send(Messages::NetworkProcess::ClearCachedCredentials(), 0); |
| 1746 | } |
| 1747 | |
| 1748 | void WebProcessPool::terminateNetworkProcess() |
| 1749 | { |
| 1750 | if (!m_networkProcess) |
| 1751 | return; |
| 1752 | |
| 1753 | m_networkProcess->terminate(); |
| 1754 | m_networkProcess = nullptr; |
| 1755 | m_didNetworkProcessCrash = true; |
| 1756 | } |
| 1757 | |
| 1758 | void WebProcessPool::sendNetworkProcessWillSuspendImminently() |
| 1759 | { |
| 1760 | if (m_networkProcess) |
| 1761 | m_networkProcess->sendProcessWillSuspendImminently(); |
| 1762 | } |
| 1763 | |
| 1764 | void WebProcessPool::sendNetworkProcessDidResume() |
| 1765 | { |
| 1766 | if (m_networkProcess) |
| 1767 | m_networkProcess->sendProcessDidResume(); |
| 1768 | } |
| 1769 | |
| 1770 | void WebProcessPool::terminateServiceWorkerProcesses() |
| 1771 | { |
| 1772 | #if ENABLE(SERVICE_WORKER) |
| 1773 | auto protectedThis = makeRef(*this); |
| 1774 | while (!m_serviceWorkerProcesses.isEmpty()) |
| 1775 | m_serviceWorkerProcesses.begin()->value->requestTermination(ProcessTerminationReason::RequestedByClient); |
| 1776 | #endif |
| 1777 | } |
| 1778 | |
| 1779 | void WebProcessPool::syncNetworkProcessCookies() |
| 1780 | { |
| 1781 | ensureNetworkProcess().syncAllCookies(); |
| 1782 | } |
| 1783 | |
| 1784 | void WebProcessPool::setIDBPerOriginQuota(uint64_t quota) |
| 1785 | { |
| 1786 | #if ENABLE(INDEXED_DATABASE) |
| 1787 | ensureNetworkProcess().send(Messages::NetworkProcess::SetIDBPerOriginQuota(quota), 0); |
| 1788 | #endif |
| 1789 | } |
| 1790 | |
| 1791 | void WebProcessPool::allowSpecificHTTPSCertificateForHost(const WebCertificateInfo* certificate, const String& host) |
| 1792 | { |
| 1793 | ensureNetworkProcess(); |
| 1794 | m_networkProcess->send(Messages::NetworkProcess::AllowSpecificHTTPSCertificateForHost(certificate->certificateInfo(), host), 0); |
| 1795 | } |
| 1796 | |
| 1797 | void WebProcessPool::updateAutomationCapabilities() const |
| 1798 | { |
| 1799 | #if ENABLE(REMOTE_INSPECTOR) |
| 1800 | Inspector::RemoteInspector::singleton().clientCapabilitiesDidChange(); |
| 1801 | #endif |
| 1802 | } |
| 1803 | |
| 1804 | void WebProcessPool::setAutomationSession(RefPtr<WebAutomationSession>&& automationSession) |
| 1805 | { |
| 1806 | if (m_automationSession) |
| 1807 | m_automationSession->setProcessPool(nullptr); |
| 1808 | |
| 1809 | m_automationSession = WTFMove(automationSession); |
| 1810 | |
| 1811 | #if ENABLE(REMOTE_INSPECTOR) |
| 1812 | if (m_automationSession) { |
| 1813 | m_automationSession->init(); |
| 1814 | m_automationSession->setProcessPool(this); |
| 1815 | |
| 1816 | sendToAllProcesses(Messages::WebProcess::EnsureAutomationSessionProxy(m_automationSession->sessionIdentifier())); |
| 1817 | } else |
| 1818 | sendToAllProcesses(Messages::WebProcess::DestroyAutomationSessionProxy()); |
| 1819 | #endif |
| 1820 | } |
| 1821 | |
| 1822 | void WebProcessPool::setHTTPPipeliningEnabled(bool enabled) |
| 1823 | { |
| 1824 | #if PLATFORM(COCOA) |
| 1825 | ResourceRequest::setHTTPPipeliningEnabled(enabled); |
| 1826 | #else |
| 1827 | UNUSED_PARAM(enabled); |
| 1828 | #endif |
| 1829 | } |
| 1830 | |
| 1831 | bool WebProcessPool::httpPipeliningEnabled() const |
| 1832 | { |
| 1833 | #if PLATFORM(COCOA) |
| 1834 | return ResourceRequest::httpPipeliningEnabled(); |
| 1835 | #else |
| 1836 | return false; |
| 1837 | #endif |
| 1838 | } |
| 1839 | |
| 1840 | void WebProcessPool::getStatistics(uint32_t statisticsMask, Function<void (API::Dictionary*, CallbackBase::Error)>&& callbackFunction) |
| 1841 | { |
| 1842 | if (!statisticsMask) { |
| 1843 | callbackFunction(nullptr, CallbackBase::Error::Unknown); |
| 1844 | return; |
| 1845 | } |
| 1846 | |
| 1847 | auto request = StatisticsRequest::create(DictionaryCallback::create(WTFMove(callbackFunction))); |
| 1848 | |
| 1849 | if (statisticsMask & StatisticsRequestTypeWebContent) |
| 1850 | requestWebContentStatistics(request.get()); |
| 1851 | |
| 1852 | if (statisticsMask & StatisticsRequestTypeNetworking) |
| 1853 | requestNetworkingStatistics(request.get()); |
| 1854 | } |
| 1855 | |
| 1856 | void WebProcessPool::requestWebContentStatistics(StatisticsRequest& request) |
| 1857 | { |
| 1858 | // FIXME (Multi-WebProcess) <rdar://problem/13200059>: Make getting statistics from multiple WebProcesses work. |
| 1859 | } |
| 1860 | |
| 1861 | void WebProcessPool::requestNetworkingStatistics(StatisticsRequest& request) |
| 1862 | { |
| 1863 | if (!m_networkProcess) { |
| 1864 | LOG_ERROR("Attempt to get NetworkProcess statistics but the NetworkProcess is unavailable" ); |
| 1865 | return; |
| 1866 | } |
| 1867 | |
| 1868 | uint64_t requestID = request.addOutstandingRequest(); |
| 1869 | m_statisticsRequests.set(requestID, &request); |
| 1870 | m_networkProcess->send(Messages::NetworkProcess::GetNetworkProcessStatistics(requestID), 0); |
| 1871 | } |
| 1872 | |
| 1873 | static WebProcessProxy* webProcessProxyFromConnection(IPC::Connection& connection, const Vector<RefPtr<WebProcessProxy>>& processes) |
| 1874 | { |
| 1875 | for (auto& process : processes) { |
| 1876 | if (process->hasConnection(connection)) |
| 1877 | return process.get(); |
| 1878 | } |
| 1879 | |
| 1880 | ASSERT_NOT_REACHED(); |
| 1881 | return nullptr; |
| 1882 | } |
| 1883 | |
| 1884 | void WebProcessPool::handleMessage(IPC::Connection& connection, const String& messageName, const WebKit::UserData& messageBody) |
| 1885 | { |
| 1886 | auto* webProcessProxy = webProcessProxyFromConnection(connection, m_processes); |
| 1887 | if (!webProcessProxy) |
| 1888 | return; |
| 1889 | m_injectedBundleClient->didReceiveMessageFromInjectedBundle(*this, messageName, webProcessProxy->transformHandlesToObjects(messageBody.object()).get()); |
| 1890 | } |
| 1891 | |
| 1892 | void WebProcessPool::handleSynchronousMessage(IPC::Connection& connection, const String& messageName, const UserData& messageBody, CompletionHandler<void(UserData&&)>&& completionHandler) |
| 1893 | { |
| 1894 | auto* webProcessProxy = webProcessProxyFromConnection(connection, m_processes); |
| 1895 | if (!webProcessProxy) |
| 1896 | return completionHandler({ }); |
| 1897 | |
| 1898 | RefPtr<API::Object> returnData; |
| 1899 | m_injectedBundleClient->didReceiveSynchronousMessageFromInjectedBundle(*this, messageName, webProcessProxy->transformHandlesToObjects(messageBody.object()).get(), returnData); |
| 1900 | completionHandler(UserData(webProcessProxy->transformObjectsToHandles(returnData.get()))); |
| 1901 | } |
| 1902 | |
| 1903 | void WebProcessPool::didGetStatistics(const StatisticsData& statisticsData, uint64_t requestID) |
| 1904 | { |
| 1905 | RefPtr<StatisticsRequest> request = m_statisticsRequests.take(requestID); |
| 1906 | if (!request) { |
| 1907 | LOG_ERROR("Cannot report networking statistics." ); |
| 1908 | return; |
| 1909 | } |
| 1910 | |
| 1911 | request->completedRequest(requestID, statisticsData); |
| 1912 | } |
| 1913 | |
| 1914 | #if ENABLE(GAMEPAD) |
| 1915 | |
| 1916 | void WebProcessPool::startedUsingGamepads(IPC::Connection& connection) |
| 1917 | { |
| 1918 | auto* proxy = webProcessProxyFromConnection(connection, m_processes); |
| 1919 | if (!proxy) |
| 1920 | return; |
| 1921 | |
| 1922 | bool wereAnyProcessesUsingGamepads = !m_processesUsingGamepads.isEmpty(); |
| 1923 | |
| 1924 | ASSERT(!m_processesUsingGamepads.contains(proxy)); |
| 1925 | m_processesUsingGamepads.add(proxy); |
| 1926 | |
| 1927 | if (!wereAnyProcessesUsingGamepads) |
| 1928 | UIGamepadProvider::singleton().processPoolStartedUsingGamepads(*this); |
| 1929 | |
| 1930 | proxy->send(Messages::WebProcess::SetInitialGamepads(UIGamepadProvider::singleton().snapshotGamepads()), 0); |
| 1931 | } |
| 1932 | |
| 1933 | void WebProcessPool::stoppedUsingGamepads(IPC::Connection& connection) |
| 1934 | { |
| 1935 | auto* proxy = webProcessProxyFromConnection(connection, m_processes); |
| 1936 | if (!proxy) |
| 1937 | return; |
| 1938 | |
| 1939 | ASSERT(m_processesUsingGamepads.contains(proxy)); |
| 1940 | processStoppedUsingGamepads(*proxy); |
| 1941 | } |
| 1942 | |
| 1943 | void WebProcessPool::processStoppedUsingGamepads(WebProcessProxy& process) |
| 1944 | { |
| 1945 | bool wereAnyProcessesUsingGamepads = !m_processesUsingGamepads.isEmpty(); |
| 1946 | |
| 1947 | ASSERT(m_processesUsingGamepads.contains(&process)); |
| 1948 | m_processesUsingGamepads.remove(&process); |
| 1949 | |
| 1950 | if (wereAnyProcessesUsingGamepads && m_processesUsingGamepads.isEmpty()) |
| 1951 | UIGamepadProvider::singleton().processPoolStoppedUsingGamepads(*this); |
| 1952 | } |
| 1953 | |
| 1954 | void WebProcessPool::gamepadConnected(const UIGamepad& gamepad) |
| 1955 | { |
| 1956 | for (auto& process : m_processesUsingGamepads) |
| 1957 | process->send(Messages::WebProcess::GamepadConnected(gamepad.fullGamepadData()), 0); |
| 1958 | } |
| 1959 | |
| 1960 | void WebProcessPool::gamepadDisconnected(const UIGamepad& gamepad) |
| 1961 | { |
| 1962 | for (auto& process : m_processesUsingGamepads) |
| 1963 | process->send(Messages::WebProcess::GamepadDisconnected(gamepad.index()), 0); |
| 1964 | } |
| 1965 | |
| 1966 | void WebProcessPool::setInitialConnectedGamepads(const Vector<std::unique_ptr<UIGamepad>>& gamepads) |
| 1967 | { |
| 1968 | Vector<GamepadData> gamepadDatas; |
| 1969 | gamepadDatas.grow(gamepads.size()); |
| 1970 | for (size_t i = 0; i < gamepads.size(); ++i) { |
| 1971 | if (!gamepads[i]) |
| 1972 | continue; |
| 1973 | gamepadDatas[i] = gamepads[i]->fullGamepadData(); |
| 1974 | } |
| 1975 | |
| 1976 | for (auto& process : m_processesUsingGamepads) |
| 1977 | process->send(Messages::WebProcess::SetInitialGamepads(gamepadDatas), 0); |
| 1978 | } |
| 1979 | |
| 1980 | #endif // ENABLE(GAMEPAD) |
| 1981 | |
| 1982 | void WebProcessPool::setJavaScriptConfigurationFileEnabled(bool flag) |
| 1983 | { |
| 1984 | m_javaScriptConfigurationFileEnabled = flag; |
| 1985 | } |
| 1986 | |
| 1987 | void WebProcessPool::garbageCollectJavaScriptObjects() |
| 1988 | { |
| 1989 | sendToAllProcesses(Messages::WebProcess::GarbageCollectJavaScriptObjects()); |
| 1990 | } |
| 1991 | |
| 1992 | void WebProcessPool::setJavaScriptGarbageCollectorTimerEnabled(bool flag) |
| 1993 | { |
| 1994 | sendToAllProcesses(Messages::WebProcess::SetJavaScriptGarbageCollectorTimerEnabled(flag)); |
| 1995 | } |
| 1996 | |
| 1997 | void WebProcessPool::addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash, PAL::SessionID sessionID) |
| 1998 | { |
| 1999 | m_plugInAutoStartProvider.addAutoStartOriginHash(pageOrigin, plugInOriginHash, sessionID); |
| 2000 | } |
| 2001 | |
| 2002 | void WebProcessPool::plugInDidReceiveUserInteraction(unsigned plugInOriginHash, PAL::SessionID sessionID) |
| 2003 | { |
| 2004 | m_plugInAutoStartProvider.didReceiveUserInteraction(plugInOriginHash, sessionID); |
| 2005 | } |
| 2006 | |
| 2007 | Ref<API::Dictionary> WebProcessPool::plugInAutoStartOriginHashes() const |
| 2008 | { |
| 2009 | return m_plugInAutoStartProvider.autoStartOriginsTableCopy(); |
| 2010 | } |
| 2011 | |
| 2012 | void WebProcessPool::setPlugInAutoStartOriginHashes(API::Dictionary& dictionary) |
| 2013 | { |
| 2014 | m_plugInAutoStartProvider.setAutoStartOriginsTable(dictionary); |
| 2015 | } |
| 2016 | |
| 2017 | void WebProcessPool::setPlugInAutoStartOrigins(API::Array& array) |
| 2018 | { |
| 2019 | m_plugInAutoStartProvider.setAutoStartOriginsArray(array); |
| 2020 | } |
| 2021 | |
| 2022 | void WebProcessPool::setPlugInAutoStartOriginsFilteringOutEntriesAddedAfterTime(API::Dictionary& dictionary, WallTime time) |
| 2023 | { |
| 2024 | m_plugInAutoStartProvider.setAutoStartOriginsFilteringOutEntriesAddedAfterTime(dictionary, time); |
| 2025 | } |
| 2026 | |
| 2027 | void WebProcessPool::registerSchemeForCustomProtocol(const String& scheme) |
| 2028 | { |
| 2029 | #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) |
| 2030 | if (!globalURLSchemesWithCustomProtocolHandlers().contains(scheme)) |
| 2031 | m_urlSchemesRegisteredForCustomProtocols.add(scheme); |
| 2032 | sendToNetworkingProcess(Messages::LegacyCustomProtocolManager::RegisterScheme(scheme)); |
| 2033 | #endif |
| 2034 | } |
| 2035 | |
| 2036 | void WebProcessPool::unregisterSchemeForCustomProtocol(const String& scheme) |
| 2037 | { |
| 2038 | #if ENABLE(LEGACY_CUSTOM_PROTOCOL_MANAGER) |
| 2039 | m_urlSchemesRegisteredForCustomProtocols.remove(scheme); |
| 2040 | sendToNetworkingProcess(Messages::LegacyCustomProtocolManager::UnregisterScheme(scheme)); |
| 2041 | #endif |
| 2042 | } |
| 2043 | |
| 2044 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 2045 | void WebProcessPool::setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy policy, const String& host, const String& bundleIdentifier, const String& versionString) |
| 2046 | { |
| 2047 | auto& policiesForHost = m_pluginLoadClientPolicies.ensure(host, [] { return HashMap<String, HashMap<String, uint8_t>>(); }).iterator->value; |
| 2048 | auto& versionsToPolicies = policiesForHost.ensure(bundleIdentifier, [] { return HashMap<String, uint8_t>(); }).iterator->value; |
| 2049 | versionsToPolicies.set(versionString, policy); |
| 2050 | |
| 2051 | sendToAllProcesses(Messages::WebProcess::SetPluginLoadClientPolicy(policy, host, bundleIdentifier, versionString)); |
| 2052 | } |
| 2053 | |
| 2054 | void WebProcessPool::resetPluginLoadClientPolicies(HashMap<String, HashMap<String, HashMap<String, uint8_t>>>&& pluginLoadClientPolicies) |
| 2055 | { |
| 2056 | m_pluginLoadClientPolicies = WTFMove(pluginLoadClientPolicies); |
| 2057 | sendToAllProcesses(Messages::WebProcess::ResetPluginLoadClientPolicies(m_pluginLoadClientPolicies)); |
| 2058 | } |
| 2059 | |
| 2060 | void WebProcessPool::clearPluginClientPolicies() |
| 2061 | { |
| 2062 | m_pluginLoadClientPolicies.clear(); |
| 2063 | sendToAllProcesses(Messages::WebProcess::ClearPluginClientPolicies()); |
| 2064 | } |
| 2065 | #endif |
| 2066 | |
| 2067 | void WebProcessPool::addSupportedPlugin(String&& matchingDomain, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions) |
| 2068 | { |
| 2069 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 2070 | m_pluginInfoStore.addSupportedPlugin(WTFMove(matchingDomain), WTFMove(name), WTFMove(mimeTypes), WTFMove(extensions)); |
| 2071 | #else |
| 2072 | UNUSED_PARAM(matchingDomain); |
| 2073 | UNUSED_PARAM(name); |
| 2074 | UNUSED_PARAM(mimeTypes); |
| 2075 | UNUSED_PARAM(extensions); |
| 2076 | #endif |
| 2077 | } |
| 2078 | |
| 2079 | void WebProcessPool::clearSupportedPlugins() |
| 2080 | { |
| 2081 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 2082 | m_pluginInfoStore.clearSupportedPlugins(); |
| 2083 | #endif |
| 2084 | } |
| 2085 | |
| 2086 | void WebProcessPool::setMemoryCacheDisabled(bool disabled) |
| 2087 | { |
| 2088 | m_memoryCacheDisabled = disabled; |
| 2089 | sendToAllProcesses(Messages::WebProcess::SetMemoryCacheDisabled(disabled)); |
| 2090 | } |
| 2091 | |
| 2092 | void WebProcessPool::setFontWhitelist(API::Array* array) |
| 2093 | { |
| 2094 | m_fontWhitelist.clear(); |
| 2095 | if (array) { |
| 2096 | for (size_t i = 0; i < array->size(); ++i) { |
| 2097 | if (API::String* font = array->at<API::String>(i)) |
| 2098 | m_fontWhitelist.append(font->string()); |
| 2099 | } |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | void WebProcessPool::updateHiddenPageThrottlingAutoIncreaseLimit() |
| 2104 | { |
| 2105 | // We're estimating an upper bound for a set of background timer fires for a page to be 200ms |
| 2106 | // (including all timer fires, all paging-in, and any resulting GC). To ensure this does not |
| 2107 | // result in more than 1% CPU load allow for one timer fire per 100x this duration. |
| 2108 | static int maximumTimerThrottlePerPageInMS = 200 * 100; |
| 2109 | |
| 2110 | int limitInMilliseconds = maximumTimerThrottlePerPageInMS * m_hiddenPageThrottlingAutoIncreasesCounter.value(); |
| 2111 | sendToAllProcesses(Messages::WebProcess::SetHiddenPageDOMTimerThrottlingIncreaseLimit(limitInMilliseconds)); |
| 2112 | } |
| 2113 | |
| 2114 | void WebProcessPool::reportWebContentCPUTime(Seconds cpuTime, uint64_t activityState) |
| 2115 | { |
| 2116 | #if PLATFORM(MAC) |
| 2117 | if (m_perActivityStateCPUUsageSampler) |
| 2118 | m_perActivityStateCPUUsageSampler->reportWebContentCPUTime(cpuTime, static_cast<WebCore::ActivityStateForCPUSampling>(activityState)); |
| 2119 | #else |
| 2120 | UNUSED_PARAM(cpuTime); |
| 2121 | UNUSED_PARAM(activityState); |
| 2122 | #endif |
| 2123 | } |
| 2124 | |
| 2125 | void WebProcessPool::updateProcessAssertions() |
| 2126 | { |
| 2127 | #if PLATFORM(IOS_FAMILY) |
| 2128 | #if ENABLE(SERVICE_WORKER) |
| 2129 | auto updateServiceWorkerProcessAssertion = [&] { |
| 2130 | if (!m_serviceWorkerProcesses.isEmpty() && m_foregroundWebProcessCounter.value()) { |
| 2131 | // FIXME: We can do better than this once we have process per origin. |
| 2132 | for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) { |
| 2133 | auto& registrableDomain = serviceWorkerProcess->registrableDomain(); |
| 2134 | if (!m_foregroundTokensForServiceWorkerProcesses.contains(registrableDomain)) |
| 2135 | m_foregroundTokensForServiceWorkerProcesses.add(registrableDomain, serviceWorkerProcess->throttler().foregroundActivityToken()); |
| 2136 | } |
| 2137 | m_backgroundTokensForServiceWorkerProcesses.clear(); |
| 2138 | return; |
| 2139 | } |
| 2140 | if (!m_serviceWorkerProcesses.isEmpty() && m_backgroundWebProcessCounter.value()) { |
| 2141 | // FIXME: We can do better than this once we have process per origin. |
| 2142 | for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) { |
| 2143 | auto& registrableDomain = serviceWorkerProcess->registrableDomain(); |
| 2144 | if (!m_backgroundTokensForServiceWorkerProcesses.contains(registrableDomain)) |
| 2145 | m_backgroundTokensForServiceWorkerProcesses.add(registrableDomain, serviceWorkerProcess->throttler().backgroundActivityToken()); |
| 2146 | } |
| 2147 | m_foregroundTokensForServiceWorkerProcesses.clear(); |
| 2148 | return; |
| 2149 | } |
| 2150 | m_foregroundTokensForServiceWorkerProcesses.clear(); |
| 2151 | m_backgroundTokensForServiceWorkerProcesses.clear(); |
| 2152 | }; |
| 2153 | updateServiceWorkerProcessAssertion(); |
| 2154 | #endif |
| 2155 | |
| 2156 | auto updateNetworkProcessAssertion = [&] { |
| 2157 | auto& networkProcess = ensureNetworkProcess(); |
| 2158 | |
| 2159 | if (m_foregroundWebProcessCounter.value()) { |
| 2160 | if (!m_foregroundTokenForNetworkProcess) { |
| 2161 | m_foregroundTokenForNetworkProcess = networkProcess.throttler().foregroundActivityToken(); |
| 2162 | networkProcess.sendProcessDidTransitionToForeground(); |
| 2163 | } |
| 2164 | m_backgroundTokenForNetworkProcess = nullptr; |
| 2165 | return; |
| 2166 | } |
| 2167 | if (m_backgroundWebProcessCounter.value()) { |
| 2168 | if (!m_backgroundTokenForNetworkProcess) { |
| 2169 | m_backgroundTokenForNetworkProcess = networkProcess.throttler().backgroundActivityToken(); |
| 2170 | networkProcess.sendProcessDidTransitionToBackground(); |
| 2171 | } |
| 2172 | m_foregroundTokenForNetworkProcess = nullptr; |
| 2173 | return; |
| 2174 | } |
| 2175 | m_foregroundTokenForNetworkProcess = nullptr; |
| 2176 | m_backgroundTokenForNetworkProcess = nullptr; |
| 2177 | }; |
| 2178 | updateNetworkProcessAssertion(); |
| 2179 | #endif |
| 2180 | } |
| 2181 | |
| 2182 | #if ENABLE(SERVICE_WORKER) |
| 2183 | void WebProcessPool::postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destination, MessageWithMessagePorts&& message, ServiceWorkerIdentifier source, const String& sourceOrigin) |
| 2184 | { |
| 2185 | sendToNetworkingProcessRelaunchingIfNecessary(Messages::NetworkProcess::PostMessageToServiceWorkerClient(destination, WTFMove(message), source, sourceOrigin)); |
| 2186 | } |
| 2187 | |
| 2188 | void WebProcessPool::postMessageToServiceWorker(ServiceWorkerIdentifier destination, MessageWithMessagePorts&& message, const ServiceWorkerOrClientIdentifier& source, SWServerConnectionIdentifier connectionIdentifier) |
| 2189 | { |
| 2190 | sendToNetworkingProcessRelaunchingIfNecessary(Messages::NetworkProcess::PostMessageToServiceWorker(destination, WTFMove(message), source, connectionIdentifier)); |
| 2191 | } |
| 2192 | #endif |
| 2193 | |
| 2194 | void WebProcessPool::reinstateNetworkProcessAssertionState(NetworkProcessProxy& newNetworkProcessProxy) |
| 2195 | { |
| 2196 | #if PLATFORM(IOS_FAMILY) |
| 2197 | // The network process crashed; take new tokens for the new network process. |
| 2198 | if (m_backgroundTokenForNetworkProcess) |
| 2199 | m_backgroundTokenForNetworkProcess = newNetworkProcessProxy.throttler().backgroundActivityToken(); |
| 2200 | else if (m_foregroundTokenForNetworkProcess) |
| 2201 | m_foregroundTokenForNetworkProcess = newNetworkProcessProxy.throttler().foregroundActivityToken(); |
| 2202 | #else |
| 2203 | UNUSED_PARAM(newNetworkProcessProxy); |
| 2204 | #endif |
| 2205 | } |
| 2206 | |
| 2207 | #if ENABLE(SERVICE_WORKER) |
| 2208 | ServiceWorkerProcessProxy* WebProcessPool::serviceWorkerProcessProxyFromPageID(uint64_t pageID) const |
| 2209 | { |
| 2210 | // FIXME: This is inefficient. |
| 2211 | for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) { |
| 2212 | if (serviceWorkerProcess->pageID() == pageID) |
| 2213 | return serviceWorkerProcess; |
| 2214 | } |
| 2215 | return nullptr; |
| 2216 | } |
| 2217 | #endif |
| 2218 | |
| 2219 | void WebProcessPool::addProcessToOriginCacheSet(WebProcessProxy& process, const URL& url) |
| 2220 | { |
| 2221 | auto registrableDomain = WebCore::RegistrableDomain { url }; |
| 2222 | auto result = m_swappedProcessesPerRegistrableDomain.add(registrableDomain, &process); |
| 2223 | if (!result.isNewEntry) |
| 2224 | result.iterator->value = &process; |
| 2225 | |
| 2226 | LOG(ProcessSwapping, "(ProcessSwapping) Registrable domain %s just saved a cached process with pid %i" , registrableDomain.string().utf8().data(), process.processIdentifier()); |
| 2227 | if (!result.isNewEntry) |
| 2228 | LOG(ProcessSwapping, "(ProcessSwapping) Note: It already had one saved" ); |
| 2229 | } |
| 2230 | |
| 2231 | void WebProcessPool::removeProcessFromOriginCacheSet(WebProcessProxy& process) |
| 2232 | { |
| 2233 | LOG(ProcessSwapping, "(ProcessSwapping) Removing process with pid %i from the origin cache set" , process.processIdentifier()); |
| 2234 | |
| 2235 | // FIXME: This can be very inefficient as the number of remembered origins and processes grows |
| 2236 | Vector<WebCore::RegistrableDomain> registrableDomainsToRemove; |
| 2237 | for (auto entry : m_swappedProcessesPerRegistrableDomain) { |
| 2238 | if (entry.value == &process) |
| 2239 | registrableDomainsToRemove.append(entry.key); |
| 2240 | } |
| 2241 | |
| 2242 | for (auto& registrableDomain : registrableDomainsToRemove) |
| 2243 | m_swappedProcessesPerRegistrableDomain.remove(registrableDomain); |
| 2244 | } |
| 2245 | |
| 2246 | void WebProcessPool::processForNavigation(WebPageProxy& page, const API::Navigation& navigation, Ref<WebProcessProxy>&& sourceProcess, const URL& sourceURL, ProcessSwapRequestedByClient processSwapRequestedByClient, Ref<WebsiteDataStore>&& dataStore, CompletionHandler<void(Ref<WebProcessProxy>&&, SuspendedPageProxy*, const String&)>&& completionHandler) |
| 2247 | { |
| 2248 | processForNavigationInternal(page, navigation, sourceProcess.copyRef(), sourceURL, processSwapRequestedByClient, WTFMove(dataStore), [this, page = makeRefPtr(page), navigation = makeRef(navigation), sourceProcess = sourceProcess.copyRef(), sourceURL, processSwapRequestedByClient, completionHandler = WTFMove(completionHandler)](Ref<WebProcessProxy>&& process, SuspendedPageProxy* suspendedPage, const String& reason) mutable { |
| 2249 | // We are process-swapping so automatic process prewarming would be beneficial if the client has not explicitly enabled / disabled it. |
| 2250 | bool doingAnAutomaticProcessSwap = processSwapRequestedByClient == ProcessSwapRequestedByClient::No && process.ptr() != sourceProcess.ptr(); |
| 2251 | if (doingAnAutomaticProcessSwap && !configuration().wasAutomaticProcessWarmingSetByClient() && !configuration().clientWouldBenefitFromAutomaticProcessPrewarming()) { |
| 2252 | RELEASE_LOG(PerformanceLogging, "Automatically turning on process prewarming because the client would benefit from it" ); |
| 2253 | configuration().setClientWouldBenefitFromAutomaticProcessPrewarming(true); |
| 2254 | } |
| 2255 | |
| 2256 | if (m_configuration->alwaysKeepAndReuseSwappedProcesses() && process.ptr() != sourceProcess.ptr()) { |
| 2257 | static std::once_flag onceFlag; |
| 2258 | std::call_once(onceFlag, [] { |
| 2259 | WTFLogAlways("WARNING: The option to always keep swapped web processes alive is active. This is meant for debugging and testing only." ); |
| 2260 | }); |
| 2261 | |
| 2262 | addProcessToOriginCacheSet(sourceProcess, sourceURL); |
| 2263 | |
| 2264 | LOG(ProcessSwapping, "(ProcessSwapping) Navigating from %s to %s, keeping around old process. Now holding on to old processes for %u origins." , sourceURL.string().utf8().data(), navigation->currentRequest().url().string().utf8().data(), m_swappedProcessesPerRegistrableDomain.size()); |
| 2265 | } |
| 2266 | |
| 2267 | completionHandler(WTFMove(process), suspendedPage, reason); |
| 2268 | }); |
| 2269 | } |
| 2270 | |
| 2271 | void WebProcessPool::processForNavigationInternal(WebPageProxy& page, const API::Navigation& navigation, Ref<WebProcessProxy>&& sourceProcess, const URL& pageSourceURL, ProcessSwapRequestedByClient processSwapRequestedByClient, Ref<WebsiteDataStore>&& dataStore, CompletionHandler<void(Ref<WebProcessProxy>&&, SuspendedPageProxy*, const String&)>&& completionHandler) |
| 2272 | { |
| 2273 | auto& targetURL = navigation.currentRequest().url(); |
| 2274 | auto targetRegistrableDomain = WebCore::RegistrableDomain { targetURL }; |
| 2275 | |
| 2276 | auto createNewProcess = [this, protectedThis = makeRef(*this), page = makeRef(page), targetRegistrableDomain, dataStore = dataStore.copyRef()] () -> Ref<WebProcessProxy> { |
| 2277 | return processForRegistrableDomain(dataStore, page.ptr(), targetRegistrableDomain); |
| 2278 | }; |
| 2279 | |
| 2280 | if (usesSingleWebProcess()) |
| 2281 | return completionHandler(WTFMove(sourceProcess), nullptr, "Single WebProcess mode is enabled"_s ); |
| 2282 | |
| 2283 | if (processSwapRequestedByClient == ProcessSwapRequestedByClient::Yes) |
| 2284 | return completionHandler(createNewProcess(), nullptr, "Process swap was requested by the client"_s ); |
| 2285 | |
| 2286 | if (!m_configuration->processSwapsOnNavigation()) |
| 2287 | return completionHandler(WTFMove(sourceProcess), nullptr, "Feature is disabled"_s ); |
| 2288 | |
| 2289 | if (m_automationSession) |
| 2290 | return completionHandler(WTFMove(sourceProcess), nullptr, "An automation session is active"_s ); |
| 2291 | |
| 2292 | if (!sourceProcess->hasCommittedAnyProvisionalLoads()) { |
| 2293 | tryPrewarmWithDomainInformation(sourceProcess, targetRegistrableDomain); |
| 2294 | return completionHandler(WTFMove(sourceProcess), nullptr, "Process has not yet committed any provisional loads"_s ); |
| 2295 | } |
| 2296 | |
| 2297 | // FIXME: We should support process swap when a window has been opened via window.open() without 'noopener'. |
| 2298 | // The issue is that the opener has a handle to the WindowProxy. |
| 2299 | if (navigation.openedByDOMWithOpener() && !m_configuration->processSwapsOnWindowOpenWithOpener()) |
| 2300 | return completionHandler(WTFMove(sourceProcess), nullptr, "Browsing context been opened by DOM without 'noopener'"_s ); |
| 2301 | |
| 2302 | // FIXME: We should support process swap when a window has opened other windows via window.open. |
| 2303 | if (navigation.hasOpenedFrames()) |
| 2304 | return completionHandler(WTFMove(sourceProcess), nullptr, "Browsing context has opened other windows"_s ); |
| 2305 | |
| 2306 | if (auto* targetItem = navigation.targetItem()) { |
| 2307 | if (auto* suspendedPage = targetItem->suspendedPage()) { |
| 2308 | return suspendedPage->waitUntilReadyToUnsuspend([createNewProcess = WTFMove(createNewProcess), completionHandler = WTFMove(completionHandler)](SuspendedPageProxy* suspendedPage) mutable { |
| 2309 | if (!suspendedPage) |
| 2310 | return completionHandler(createNewProcess(), nullptr, "Using new process because target back/forward item's suspended page is not reusable"_s ); |
| 2311 | Ref<WebProcessProxy> process = suspendedPage->process(); |
| 2312 | completionHandler(WTFMove(process), suspendedPage, "Using target back/forward item's process and suspended page"_s ); |
| 2313 | }); |
| 2314 | } |
| 2315 | |
| 2316 | if (RefPtr<WebProcessProxy> process = WebProcessProxy::processForIdentifier(targetItem->lastProcessIdentifier())) { |
| 2317 | if (process->state() != WebProcessProxy::State::Terminated) { |
| 2318 | // FIXME: Architecturally we do not currently support multiple WebPage's with the same ID in a given WebProcess. |
| 2319 | // In the case where this WebProcess has a SuspendedPageProxy for this WebPage, we can throw it away to support |
| 2320 | // WebProcess re-use. |
| 2321 | removeAllSuspendedPagesForPage(page, process.get()); |
| 2322 | |
| 2323 | // Make sure we remove the process from the cache if it is in there since we're about to use it. |
| 2324 | if (process->isInProcessCache()) { |
| 2325 | webProcessCache().removeProcess(*process, WebProcessCache::ShouldShutDownProcess::No); |
| 2326 | ASSERT(!process->isInProcessCache()); |
| 2327 | } |
| 2328 | |
| 2329 | return completionHandler(process.releaseNonNull(), nullptr, "Using target back/forward item's process"_s ); |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | if (navigation.treatAsSameOriginNavigation()) |
| 2335 | return completionHandler(WTFMove(sourceProcess), nullptr, "The treatAsSameOriginNavigation flag is set"_s ); |
| 2336 | |
| 2337 | URL sourceURL; |
| 2338 | if (page.isPageOpenedByDOMShowingInitialEmptyDocument() && !navigation.requesterOrigin().isEmpty()) |
| 2339 | sourceURL = URL { URL(), navigation.requesterOrigin().toString() }; |
| 2340 | else |
| 2341 | sourceURL = pageSourceURL; |
| 2342 | |
| 2343 | if (sourceURL.isEmpty() && page.configuration().relatedPage()) { |
| 2344 | sourceURL = URL { { }, page.configuration().relatedPage()->pageLoadState().url() }; |
| 2345 | RELEASE_LOG(ProcessSwapping, "Using related page %p's URL as source URL for process swap decision" , page.configuration().relatedPage()); |
| 2346 | } |
| 2347 | |
| 2348 | if (!sourceURL.isValid() || !targetURL.isValid() || sourceURL.isEmpty() || sourceURL.protocolIsAbout() || targetRegistrableDomain.matches(sourceURL)) |
| 2349 | return completionHandler(WTFMove(sourceProcess), nullptr, "Navigation is same-site"_s ); |
| 2350 | |
| 2351 | String reason = "Navigation is cross-site"_s ; |
| 2352 | |
| 2353 | if (m_configuration->alwaysKeepAndReuseSwappedProcesses()) { |
| 2354 | LOG(ProcessSwapping, "(ProcessSwapping) Considering re-use of a previously cached process for domain %s" , targetRegistrableDomain.string().utf8().data()); |
| 2355 | |
| 2356 | if (auto* process = m_swappedProcessesPerRegistrableDomain.get(targetRegistrableDomain)) { |
| 2357 | if (&process->websiteDataStore() == dataStore.ptr()) { |
| 2358 | LOG(ProcessSwapping, "(ProcessSwapping) Reusing a previously cached process with pid %i to continue navigation to URL %s" , process->processIdentifier(), targetURL.string().utf8().data()); |
| 2359 | |
| 2360 | // FIXME: Architecturally we do not currently support multiple WebPage's with the same ID in a given WebProcess. |
| 2361 | // In the case where this WebProcess has a SuspendedPageProxy for this WebPage, we can throw it away to support |
| 2362 | // WebProcess re-use. |
| 2363 | // In the future it would be great to refactor-out this limitation (https://bugs.webkit.org/show_bug.cgi?id=191166). |
| 2364 | removeAllSuspendedPagesForPage(page, process); |
| 2365 | |
| 2366 | return completionHandler(makeRef(*process), nullptr, reason); |
| 2367 | } |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | return completionHandler(createNewProcess(), nullptr, reason); |
| 2372 | } |
| 2373 | |
| 2374 | RefPtr<WebProcessProxy> WebProcessPool::findReusableSuspendedPageProcess(const WebCore::RegistrableDomain& registrableDomain, WebPageProxy& page, WebsiteDataStore& dataStore) |
| 2375 | { |
| 2376 | auto it = m_suspendedPages.findIf([&](auto& suspendedPage) { |
| 2377 | return suspendedPage->process().registrableDomain() == registrableDomain && &suspendedPage->process().websiteDataStore() == &dataStore; |
| 2378 | }); |
| 2379 | if (it == m_suspendedPages.end()) |
| 2380 | return nullptr; |
| 2381 | |
| 2382 | Ref<WebProcessProxy> process = (*it)->process(); |
| 2383 | |
| 2384 | // FIXME: If the SuspendedPage is for this page, then we need to destroy the suspended page as we do not support having |
| 2385 | // multiple WebPages with the same ID in a given WebProcess currently (https://bugs.webkit.org/show_bug.cgi?id=191166). |
| 2386 | if (&(*it)->page() == &page) |
| 2387 | m_suspendedPages.remove(it); |
| 2388 | |
| 2389 | |
| 2390 | return process; |
| 2391 | } |
| 2392 | |
| 2393 | void WebProcessPool::addSuspendedPage(std::unique_ptr<SuspendedPageProxy>&& suspendedPage) |
| 2394 | { |
| 2395 | if (!m_maxSuspendedPageCount) |
| 2396 | return; |
| 2397 | |
| 2398 | if (m_suspendedPages.size() >= m_maxSuspendedPageCount) |
| 2399 | m_suspendedPages.removeFirst(); |
| 2400 | |
| 2401 | m_suspendedPages.append(WTFMove(suspendedPage)); |
| 2402 | } |
| 2403 | |
| 2404 | void WebProcessPool::removeAllSuspendedPagesForPage(WebPageProxy& page, WebProcessProxy* process) |
| 2405 | { |
| 2406 | m_suspendedPages.removeAllMatching([&page, process](auto& suspendedPage) { |
| 2407 | return &suspendedPage->page() == &page && (!process || &suspendedPage->process() == process); |
| 2408 | }); |
| 2409 | } |
| 2410 | |
| 2411 | std::unique_ptr<SuspendedPageProxy> WebProcessPool::takeSuspendedPage(SuspendedPageProxy& suspendedPage) |
| 2412 | { |
| 2413 | return m_suspendedPages.takeFirst([&suspendedPage](auto& item) { |
| 2414 | return item.get() == &suspendedPage; |
| 2415 | }); |
| 2416 | } |
| 2417 | |
| 2418 | void WebProcessPool::removeSuspendedPage(SuspendedPageProxy& suspendedPage) |
| 2419 | { |
| 2420 | auto it = m_suspendedPages.findIf([&suspendedPage](auto& item) { |
| 2421 | return item.get() == &suspendedPage; |
| 2422 | }); |
| 2423 | if (it != m_suspendedPages.end()) |
| 2424 | m_suspendedPages.remove(it); |
| 2425 | } |
| 2426 | |
| 2427 | bool WebProcessPool::hasSuspendedPageFor(WebProcessProxy& process, WebPageProxy& page) const |
| 2428 | { |
| 2429 | return m_suspendedPages.findIf([&process, &page](auto& suspendedPage) { |
| 2430 | return &suspendedPage->process() == &process && &suspendedPage->page() == &page; |
| 2431 | }) != m_suspendedPages.end(); |
| 2432 | } |
| 2433 | |
| 2434 | void WebProcessPool::clearSuspendedPages(AllowProcessCaching allowProcessCaching) |
| 2435 | { |
| 2436 | HashSet<RefPtr<WebProcessProxy>> processes; |
| 2437 | for (auto& suspendedPage : m_suspendedPages) |
| 2438 | processes.add(&suspendedPage->process()); |
| 2439 | |
| 2440 | m_suspendedPages.clear(); |
| 2441 | |
| 2442 | for (auto& process : processes) |
| 2443 | process->maybeShutDown(allowProcessCaching); |
| 2444 | } |
| 2445 | |
| 2446 | void WebProcessPool::addMockMediaDevice(const MockMediaDevice& device) |
| 2447 | { |
| 2448 | #if ENABLE(MEDIA_STREAM) |
| 2449 | MockRealtimeMediaSourceCenter::addDevice(device); |
| 2450 | sendToAllProcesses(Messages::WebProcess::AddMockMediaDevice { device }); |
| 2451 | #endif |
| 2452 | } |
| 2453 | |
| 2454 | void WebProcessPool::clearMockMediaDevices() |
| 2455 | { |
| 2456 | #if ENABLE(MEDIA_STREAM) |
| 2457 | MockRealtimeMediaSourceCenter::setDevices({ }); |
| 2458 | sendToAllProcesses(Messages::WebProcess::ClearMockMediaDevices { }); |
| 2459 | #endif |
| 2460 | } |
| 2461 | |
| 2462 | void WebProcessPool::removeMockMediaDevice(const String& persistentId) |
| 2463 | { |
| 2464 | #if ENABLE(MEDIA_STREAM) |
| 2465 | MockRealtimeMediaSourceCenter::removeDevice(persistentId); |
| 2466 | sendToAllProcesses(Messages::WebProcess::RemoveMockMediaDevice { persistentId }); |
| 2467 | #endif |
| 2468 | } |
| 2469 | |
| 2470 | void WebProcessPool::resetMockMediaDevices() |
| 2471 | { |
| 2472 | #if ENABLE(MEDIA_STREAM) |
| 2473 | MockRealtimeMediaSourceCenter::resetDevices(); |
| 2474 | sendToAllProcesses(Messages::WebProcess::ResetMockMediaDevices { }); |
| 2475 | #endif |
| 2476 | } |
| 2477 | |
| 2478 | void WebProcessPool::sendDisplayConfigurationChangedMessageForTesting() |
| 2479 | { |
| 2480 | #if PLATFORM(MAC) && ENABLE(WEBPROCESS_WINDOWSERVER_BLOCKING) |
| 2481 | auto display = CGSMainDisplayID(); |
| 2482 | |
| 2483 | for (auto& processPool : WebProcessPool::allProcessPools()) { |
| 2484 | processPool->sendToAllProcesses(Messages::WebProcess::DisplayConfigurationChanged(display, kCGDisplayBeginConfigurationFlag)); |
| 2485 | processPool->sendToAllProcesses(Messages::WebProcess::DisplayConfigurationChanged(display, kCGDisplaySetModeFlag | kCGDisplayDesktopShapeChangedFlag)); |
| 2486 | } |
| 2487 | #endif |
| 2488 | } |
| 2489 | |
| 2490 | void WebProcessPool::didCollectPrewarmInformation(const WebCore::RegistrableDomain& registrableDomain, const WebCore::PrewarmInformation& prewarmInformation) |
| 2491 | { |
| 2492 | static const size_t maximumSizeToPreventUnlimitedGrowth = 100; |
| 2493 | if (m_prewarmInformationPerRegistrableDomain.size() == maximumSizeToPreventUnlimitedGrowth) |
| 2494 | m_prewarmInformationPerRegistrableDomain.remove(m_prewarmInformationPerRegistrableDomain.random()); |
| 2495 | |
| 2496 | auto& value = m_prewarmInformationPerRegistrableDomain.ensure(registrableDomain, [] { |
| 2497 | return std::make_unique<WebCore::PrewarmInformation>(); |
| 2498 | }).iterator->value; |
| 2499 | |
| 2500 | *value = prewarmInformation; |
| 2501 | } |
| 2502 | |
| 2503 | void WebProcessPool::tryPrewarmWithDomainInformation(WebProcessProxy& process, const RegistrableDomain& registrableDomain) |
| 2504 | { |
| 2505 | auto* prewarmInformation = m_prewarmInformationPerRegistrableDomain.get(registrableDomain); |
| 2506 | if (!prewarmInformation) |
| 2507 | return; |
| 2508 | process.send(Messages::WebProcess::PrewarmWithDomainInformation(*prewarmInformation), 0); |
| 2509 | } |
| 2510 | |
| 2511 | void WebProcessPool::clearCurrentModifierStateForTesting() |
| 2512 | { |
| 2513 | sendToAllProcesses(Messages::WebProcess::ClearCurrentModifierStateForTesting()); |
| 2514 | } |
| 2515 | |
| 2516 | void WebProcessPool::committedCrossSiteLoadWithLinkDecoration(PAL::SessionID sessionID, const RegistrableDomain& fromDomain, const RegistrableDomain& toDomain, uint64_t pageID) |
| 2517 | { |
| 2518 | #if ENABLE(RESOURCE_LOAD_STATISTICS) |
| 2519 | if (!m_networkProcess) |
| 2520 | return; |
| 2521 | |
| 2522 | m_networkProcess->committedCrossSiteLoadWithLinkDecoration(sessionID, fromDomain, toDomain, pageID, [] { }); |
| 2523 | #else |
| 2524 | UNUSED_PARAM(sessionID); |
| 2525 | UNUSED_PARAM(fromDomain); |
| 2526 | UNUSED_PARAM(toDomain); |
| 2527 | UNUSED_PARAM(pageID); |
| 2528 | #endif |
| 2529 | } |
| 2530 | |
| 2531 | void WebProcessPool::setWebProcessHasUploads(ProcessIdentifier processID) |
| 2532 | { |
| 2533 | auto* process = WebProcessProxy::processForIdentifier(processID); |
| 2534 | ASSERT(process); |
| 2535 | |
| 2536 | RELEASE_LOG(ProcessSuspension, "Web process pid %u now has uploads in progress" , (unsigned)process->processIdentifier()); |
| 2537 | |
| 2538 | if (m_processesWithUploads.isEmpty()) { |
| 2539 | RELEASE_LOG(ProcessSuspension, "The number of uploads in progress is now one. Taking Networking and UI process assertions." ); |
| 2540 | |
| 2541 | ASSERT(m_networkProcess); |
| 2542 | m_networkProcess->takeUploadAssertion(); |
| 2543 | |
| 2544 | ASSERT(!m_uiProcessUploadAssertion); |
| 2545 | m_uiProcessUploadAssertion = std::make_unique<ProcessAssertion>(getCurrentProcessID(), "WebKit uploads"_s , AssertionState::UnboundedNetworking); |
| 2546 | } |
| 2547 | |
| 2548 | auto result = m_processesWithUploads.add(processID, nullptr); |
| 2549 | ASSERT(result.isNewEntry); |
| 2550 | result.iterator->value = std::make_unique<ProcessAssertion>(process->processIdentifier(), "WebKit uploads"_s , AssertionState::UnboundedNetworking); |
| 2551 | } |
| 2552 | |
| 2553 | void WebProcessPool::clearWebProcessHasUploads(ProcessIdentifier processID) |
| 2554 | { |
| 2555 | auto result = m_processesWithUploads.take(processID); |
| 2556 | ASSERT_UNUSED(result, result); |
| 2557 | |
| 2558 | auto* process = WebProcessProxy::processForIdentifier(processID); |
| 2559 | ASSERT_UNUSED(process, process); |
| 2560 | RELEASE_LOG(ProcessSuspension, "Web process pid %u no longer has uploads in progress" , (unsigned)process->processIdentifier()); |
| 2561 | |
| 2562 | if (m_processesWithUploads.isEmpty()) { |
| 2563 | RELEASE_LOG(ProcessSuspension, "The number of uploads in progress is now zero. Releasing Networking and UI process assertions." ); |
| 2564 | |
| 2565 | if (m_networkProcess) |
| 2566 | m_networkProcess->clearUploadAssertion(); |
| 2567 | |
| 2568 | ASSERT(m_uiProcessUploadAssertion); |
| 2569 | m_uiProcessUploadAssertion = nullptr; |
| 2570 | } |
| 2571 | |
| 2572 | } |
| 2573 | |
| 2574 | void WebProcessPool::setWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier processID) |
| 2575 | { |
| 2576 | auto* process = WebProcessProxy::processForIdentifier(processID); |
| 2577 | ASSERT(process); |
| 2578 | |
| 2579 | RELEASE_LOG(ProcessSuspension, "Web process pid %u is now playing audible media" , (unsigned)process->processIdentifier()); |
| 2580 | |
| 2581 | if (m_processesPlayingAudibleMedia.isEmpty()) { |
| 2582 | RELEASE_LOG(ProcessSuspension, "The number of processes playing audible media is now one. Taking UI process assertion." ); |
| 2583 | |
| 2584 | ASSERT(!m_uiProcessMediaPlaybackAssertion); |
| 2585 | m_uiProcessMediaPlaybackAssertion = std::make_unique<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s , AssertionState::Foreground, AssertionReason::MediaPlayback); |
| 2586 | } |
| 2587 | |
| 2588 | auto result = m_processesPlayingAudibleMedia.add(processID, nullptr); |
| 2589 | ASSERT(result.isNewEntry); |
| 2590 | result.iterator->value = std::make_unique<ProcessAssertion>(process->processIdentifier(), "WebKit Media Playback"_s , AssertionState::Foreground, AssertionReason::MediaPlayback); |
| 2591 | } |
| 2592 | |
| 2593 | void WebProcessPool::clearWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier processID) |
| 2594 | { |
| 2595 | auto result = m_processesPlayingAudibleMedia.take(processID); |
| 2596 | ASSERT_UNUSED(result, result); |
| 2597 | |
| 2598 | auto* process = WebProcessProxy::processForIdentifier(processID); |
| 2599 | ASSERT(process); |
| 2600 | RELEASE_LOG(ProcessSuspension, "Web process pid %u is no longer playing audible media" , (unsigned)process->processIdentifier()); |
| 2601 | |
| 2602 | if (m_processesPlayingAudibleMedia.isEmpty()) { |
| 2603 | RELEASE_LOG(ProcessSuspension, "The number of processes playing audible media now zero. Releasing UI process assertion." ); |
| 2604 | |
| 2605 | ASSERT(m_uiProcessMediaPlaybackAssertion); |
| 2606 | m_uiProcessMediaPlaybackAssertion = nullptr; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | } // namespace WebKit |
| 2611 | |