1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
|
/*
* Copyright (C) 2010-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "APIDictionary.h"
#include "APIObject.h"
#include "APIProcessPoolConfiguration.h"
#include "GPUProcessProxy.h"
#include "HiddenPageThrottlingAutoIncreasesCounter.h"
#include "MessageReceiver.h"
#include "MessageReceiverMap.h"
#include "NetworkProcessProxy.h"
#include "ProcessThrottler.h"
#include "VisitedLinkStore.h"
#include "WebContextClient.h"
#include "WebContextConnectionClient.h"
#include "WebPreferencesStore.h"
#include "WebProcessProxy.h"
#include "WebsiteDataStore.h"
#include <WebCore/CrossSiteNavigationDataTransfer.h>
#include <WebCore/ProcessIdentifier.h>
#include <WebCore/SecurityOriginHash.h>
#include <WebCore/SharedStringHash.h>
#include <pal/SessionID.h>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/MemoryPressureHandler.h>
#include <wtf/OptionSet.h>
#include <wtf/RefCounter.h>
#include <wtf/RefPtr.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
#if PLATFORM(COCOA)
OBJC_CLASS NSMutableDictionary;
OBJC_CLASS NSObject;
OBJC_CLASS NSSet;
OBJC_CLASS NSString;
OBJC_CLASS WKPreferenceObserver;
OBJC_CLASS WKProcessPoolWeakObserver;
#if PLATFORM(MAC)
OBJC_CLASS WKWebInspectorPreferenceObserver;
#endif
#endif
#if PLATFORM(MAC)
#include "DisplayLink.h"
#include <WebCore/PowerObserverMac.h>
#include <pal/system/SystemSleepListener.h>
#endif
#if ENABLE(IPC_TESTING_API)
#include "IPCTester.h"
#endif
namespace API {
class AutomationClient;
class DownloadClient;
class HTTPCookieStore;
class InjectedBundleClient;
class LegacyContextHistoryClient;
class LegacyDownloadClient;
class Navigation;
class PageConfiguration;
}
namespace WebCore {
class RegistrableDomain;
enum class EventMakesGamepadsVisible : bool;
enum class GamepadHapticEffectType : uint8_t;
struct GamepadEffectParameters;
struct MockMediaDevice;
#if PLATFORM(COCOA)
class PowerSourceNotifier;
#endif
}
namespace WebKit {
class LockdownModeObserver;
class HighPerformanceGraphicsUsageSampler;
class UIGamepad;
class PerActivityStateCPUUsageSampler;
class SuspendedPageProxy;
class WebAutomationSession;
class WebBackForwardCache;
class WebContextSupplement;
class WebPageGroup;
class WebPageProxy;
class WebProcessCache;
struct GPUProcessConnectionParameters;
struct GPUProcessCreationParameters;
struct NetworkProcessCreationParameters;
struct WebProcessCreationParameters;
struct WebProcessDataStoreParameters;
#if PLATFORM(COCOA)
int networkProcessLatencyQOS();
int networkProcessThroughputQOS();
int webProcessLatencyQOS();
int webProcessThroughputQOS();
#endif
void addLockdownModeObserver(LockdownModeObserver&);
void removeLockdownModeObserver(LockdownModeObserver&);
bool lockdownModeEnabledBySystem();
void setLockdownModeEnabledGloballyForTesting(std::optional<bool>);
enum class CallDownloadDidStart : bool;
enum class ProcessSwapRequestedByClient : bool;
class WebProcessPool final
: public API::ObjectImpl<API::Object::Type::ProcessPool>
, public IPC::MessageReceiver
#if PLATFORM(MAC)
, private PAL::SystemSleepListener::Client
#endif
{
public:
static Ref<WebProcessPool> create(API::ProcessPoolConfiguration&);
explicit WebProcessPool(API::ProcessPoolConfiguration&);
virtual ~WebProcessPool();
API::ProcessPoolConfiguration& configuration() { return m_configuration.get(); }
static Vector<Ref<WebProcessPool>> allProcessPools();
template <typename T>
T* supplement()
{
return static_cast<T*>(m_supplements.get(T::supplementName()));
}
template <typename T>
void addSupplement()
{
m_supplements.add(T::supplementName(), T::create(this));
}
void addMessageReceiver(IPC::ReceiverName, IPC::MessageReceiver&);
void addMessageReceiver(IPC::ReceiverName, uint64_t destinationID, IPC::MessageReceiver&);
void removeMessageReceiver(IPC::ReceiverName);
void removeMessageReceiver(IPC::ReceiverName, uint64_t destinationID);
WebBackForwardCache& backForwardCache() { return m_backForwardCache.get(); }
void addMessageReceiver(IPC::ReceiverName messageReceiverName, const ObjectIdentifierGenericBase& destinationID, IPC::MessageReceiver& receiver)
{
addMessageReceiver(messageReceiverName, destinationID.toUInt64(), receiver);
}
void removeMessageReceiver(IPC::ReceiverName messageReceiverName, const ObjectIdentifierGenericBase& destinationID)
{
removeMessageReceiver(messageReceiverName, destinationID.toUInt64());
}
bool dispatchMessage(IPC::Connection&, IPC::Decoder&);
bool dispatchSyncMessage(IPC::Connection&, IPC::Decoder&, UniqueRef<IPC::Encoder>&);
void initializeClient(const WKContextClientBase*);
void setInjectedBundleClient(std::unique_ptr<API::InjectedBundleClient>&&);
void initializeConnectionClient(const WKContextConnectionClientBase*);
void setHistoryClient(std::unique_ptr<API::LegacyContextHistoryClient>&&);
void setLegacyDownloadClient(RefPtr<API::DownloadClient>&&);
void setAutomationClient(std::unique_ptr<API::AutomationClient>&&);
const Vector<Ref<WebProcessProxy>>& processes() const { return m_processes; }
// WebProcessProxy object which does not have a running process which is used for convenience, to avoid
// null checks in WebPageProxy.
WebProcessProxy* dummyProcessProxy(PAL::SessionID sessionID) const { return m_dummyProcessProxies.get(sessionID).get(); }
void forEachProcessForSession(PAL::SessionID, const Function<void(WebProcessProxy&)>&);
template<typename T> void sendToAllProcesses(const T& message);
template<typename T> void sendToAllProcessesForSession(const T& message, PAL::SessionID);
template<typename T> static void sendToAllRemoteWorkerProcesses(const T& message);
void processDidFinishLaunching(WebProcessProxy&);
WebProcessCache& webProcessCache() { return m_webProcessCache.get(); }
// Disconnect the process from the context.
void disconnectProcess(WebProcessProxy&);
Ref<WebPageProxy> createWebPage(PageClient&, Ref<API::PageConfiguration>&&);
void pageBeginUsingWebsiteDataStore(WebPageProxyIdentifier, WebsiteDataStore&);
void pageEndUsingWebsiteDataStore(WebPageProxyIdentifier, WebsiteDataStore&);
bool hasPagesUsingWebsiteDataStore(WebsiteDataStore&) const;
const String& injectedBundlePath() const { return m_configuration->injectedBundlePath(); }
Ref<DownloadProxy> download(WebsiteDataStore&, WebPageProxy* initiatingPage, const WebCore::ResourceRequest&, const String& suggestedFilename = { });
Ref<DownloadProxy> resumeDownload(WebsiteDataStore&, WebPageProxy* initiatingPage, const API::Data& resumeData, const String& path, CallDownloadDidStart);
void setInjectedBundleInitializationUserData(RefPtr<API::Object>&& userData) { m_injectedBundleInitializationUserData = WTFMove(userData); }
void postMessageToInjectedBundle(const String&, API::Object*);
void populateVisitedLinks();
#if PLATFORM(IOS_FAMILY)
void applicationIsAboutToSuspend();
static void notifyProcessPoolsApplicationIsAboutToSuspend();
void setProcessesShouldSuspend(bool);
#endif
void handleMemoryPressureWarning(Critical);
#if PLATFORM(COCOA)
void screenPropertiesChanged();
#endif
#if PLATFORM(MAC)
void displayPropertiesChanged(const WebCore::ScreenProperties&, WebCore::PlatformDisplayID, CGDisplayChangeSummaryFlags);
#endif
#if HAVE(CVDISPLAYLINK)
DisplayLinkCollection& displayLinks() { return m_displayLinks; }
#endif
void addSupportedPlugin(String&& matchingDomain, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions);
void clearSupportedPlugins();
ProcessID prewarmedProcessID();
void activePagesOriginsInWebProcessForTesting(ProcessID, CompletionHandler<void(Vector<String>&&)>&&);
WebPageGroup& defaultPageGroup() { return m_defaultPageGroup.get(); }
void setAlwaysUsesComplexTextCodePath(bool);
void setDisableFontSubpixelAntialiasingForTesting(bool);
void registerURLSchemeAsEmptyDocument(const String&);
void registerURLSchemeAsSecure(const String&);
void registerURLSchemeAsBypassingContentSecurityPolicy(const String&);
void setDomainRelaxationForbiddenForURLScheme(const String&);
void registerURLSchemeAsLocal(const String&);
void registerURLSchemeAsNoAccess(const String&);
void registerURLSchemeAsDisplayIsolated(const String&);
void registerURLSchemeAsCORSEnabled(const String&);
void registerURLSchemeAsCachePartitioned(const String&);
void registerURLSchemeAsCanDisplayOnlyIfCanRequest(const String&);
VisitedLinkStore& visitedLinkStore() { return m_visitedLinkStore.get(); }
void setCacheModel(CacheModel);
void setCacheModelSynchronouslyForTesting(CacheModel);
void setDefaultRequestTimeoutInterval(double);
void startMemorySampler(const double interval);
void stopMemorySampler();
#if USE(SOUP)
static void setNetworkProcessMemoryPressureHandlerConfiguration(const std::optional<MemoryPressureHandler::Configuration>& configuration) { s_networkProcessMemoryPressureHandlerConfiguration = configuration; }
#endif
void setEnhancedAccessibility(bool);
// Downloads.
Ref<DownloadProxy> createDownloadProxy(WebsiteDataStore&, const WebCore::ResourceRequest&, WebPageProxy* originatingPage, const FrameInfoData&);
API::LegacyContextHistoryClient& historyClient() { return *m_historyClient; }
WebContextClient& client() { return m_client; }
struct Statistics {
unsigned wkViewCount;
unsigned wkPageCount;
unsigned wkFrameCount;
};
static Statistics& statistics();
void terminateAllWebContentProcesses();
void sendNetworkProcessPrepareToSuspendForTesting(CompletionHandler<void()>&&);
void sendNetworkProcessWillSuspendImminentlyForTesting();
void sendNetworkProcessDidResume();
void terminateServiceWorkers();
void setShouldMakeNextWebProcessLaunchFailForTesting(bool value) { m_shouldMakeNextWebProcessLaunchFailForTesting = value; }
bool shouldMakeNextWebProcessLaunchFailForTesting() const { return m_shouldMakeNextWebProcessLaunchFailForTesting; }
void reportWebContentCPUTime(Seconds cpuTime, uint64_t activityState);
Ref<WebProcessProxy> processForRegistrableDomain(WebsiteDataStore&, const WebCore::RegistrableDomain&, WebProcessProxy::LockdownMode); // Will return an existing one if limit is met or due to caching.
void prewarmProcess();
bool shouldTerminate(WebProcessProxy&);
void disableProcessTermination();
void enableProcessTermination();
void updateAutomationCapabilities() const;
void setAutomationSession(RefPtr<WebAutomationSession>&&);
WebAutomationSession* automationSession() const { return m_automationSession.get(); }
// Defaults to false.
void setHTTPPipeliningEnabled(bool);
bool httpPipeliningEnabled() const;
bool javaScriptConfigurationFileEnabled() { return m_javaScriptConfigurationFileEnabled; }
void setJavaScriptConfigurationFileEnabled(bool flag);
#if PLATFORM(IOS_FAMILY)
void setJavaScriptConfigurationFileEnabledFromDefaults();
#endif
void garbageCollectJavaScriptObjects();
void setJavaScriptGarbageCollectorTimerEnabled(bool flag);
enum class GamepadType {
All,
HID,
GameControllerFramework,
};
size_t numberOfConnectedGamepadsForTesting(GamepadType);
void setUsesOnlyHIDGamepadProviderForTesting(bool);
#if PLATFORM(COCOA)
static bool omitPDFSupport();
#endif
void fullKeyboardAccessModeChanged(bool fullKeyboardAccessEnabled);
#if OS(LINUX)
void sendMemoryPressureEvent(bool isCritical);
#endif
void textCheckerStateChanged();
#if ENABLE(GPU_PROCESS)
void gpuProcessDidFinishLaunching(ProcessID);
void gpuProcessExited(ProcessID, ProcessTerminationReason);
void createGPUProcessConnection(WebProcessProxy&, IPC::Connection::Handle&&, WebKit::GPUProcessConnectionParameters&&);
GPUProcessProxy& ensureGPUProcess();
GPUProcessProxy* gpuProcess() const { return m_gpuProcess.get(); }
#endif
// Network Process Management
void networkProcessDidTerminate(NetworkProcessProxy&, ProcessTerminationReason);
bool isServiceWorkerPageID(WebPageProxyIdentifier) const;
#if ENABLE(SERVICE_WORKER)
size_t serviceWorkerProxiesCount() const;
bool hasServiceWorkerForegroundActivityForTesting() const;
bool hasServiceWorkerBackgroundActivityForTesting() const;
#endif
void serviceWorkerProcessCrashed(WebProcessProxy&, ProcessTerminationReason);
void updateRemoteWorkerUserAgent(const String& userAgent);
UserContentControllerIdentifier userContentControllerIdentifierForRemoteWorkers();
static void establishRemoteWorkerContextConnectionToNetworkProcess(RemoteWorkerType, WebCore::RegistrableDomain&&, std::optional<WebCore::ProcessIdentifier> requestingProcessIdentifier, std::optional<WebCore::ScriptExecutionContextIdentifier> serviceWorkerPageIdentifier, PAL::SessionID, CompletionHandler<void(WebCore::ProcessIdentifier)>&&);
#if PLATFORM(COCOA)
bool processSuppressionEnabled() const;
#endif
void windowServerConnectionStateChanged();
static void setInvalidMessageCallback(void (*)(WKStringRef));
static void didReceiveInvalidMessage(IPC::MessageName);
bool isURLKnownHSTSHost(const String& urlString) const;
static void registerGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
static void unregisterGlobalURLSchemeAsHavingCustomProtocolHandlers(const String&);
void notifyMediaStreamingActivity(bool);
#if PLATFORM(COCOA)
void updateProcessSuppressionState();
NSMutableDictionary *ensureBundleParameters();
NSMutableDictionary *bundleParameters() { return m_bundleParameters.get(); }
#else
void updateProcessSuppressionState() const { }
#endif
void updateHiddenPageThrottlingAutoIncreaseLimit();
void setMemoryCacheDisabled(bool);
void setFontAllowList(API::Array*);
UserObservablePageCounter::Token userObservablePageCount()
{
return m_userObservablePageCounter.count();
}
ProcessSuppressionDisabledToken processSuppressionDisabledForPageCount()
{
return m_processSuppressionDisabledForPageCounter.count();
}
HiddenPageThrottlingAutoIncreasesCounter::Token hiddenPageThrottlingAutoIncreasesCount()
{
return m_hiddenPageThrottlingAutoIncreasesCounter.count();
}
bool alwaysRunsAtBackgroundPriority() const { return m_alwaysRunsAtBackgroundPriority; }
bool shouldTakeUIBackgroundAssertion() const { return m_shouldTakeUIBackgroundAssertion; }
static bool anyProcessPoolNeedsUIBackgroundAssertion();
#if ENABLE(GAMEPAD)
void gamepadConnected(const UIGamepad&, WebCore::EventMakesGamepadsVisible);
void gamepadDisconnected(const UIGamepad&);
#endif
#if PLATFORM(COCOA)
bool cookieStoragePartitioningEnabled() const { return m_cookieStoragePartitioningEnabled; }
void setCookieStoragePartitioningEnabled(bool);
void clearPermanentCredentialsForProtectionSpace(WebCore::ProtectionSpace&&);
void lockdownModeStateChanged();
#endif
#if ENABLE(WEBCONTENT_CRASH_TESTING)
static bool shouldCrashWhenCreatingWebProcess() { return s_shouldCrashWhenCreatingWebProcess; }
#endif
ForegroundWebProcessToken foregroundWebProcessToken() const { return ForegroundWebProcessToken(m_foregroundWebProcessCounter.count()); }
BackgroundWebProcessToken backgroundWebProcessToken() const { return BackgroundWebProcessToken(m_backgroundWebProcessCounter.count()); }
bool hasForegroundWebProcesses() const { return m_foregroundWebProcessCounter.value(); }
bool hasBackgroundWebProcesses() const { return m_backgroundWebProcessCounter.value(); }
enum class DidCreateNewProcess : bool { No, Yes };
void processForNavigation(WebPageProxy&, WebFrameProxy&, const API::Navigation&, Ref<WebProcessProxy>&& sourceProcess, const URL& sourceURL, ProcessSwapRequestedByClient, WebProcessProxy::LockdownMode, const FrameInfoData&, Ref<WebsiteDataStore>&&, CompletionHandler<void(Ref<WebProcessProxy>&&, SuspendedPageProxy*, ASCIILiteral, DidCreateNewProcess)>&&);
void didReachGoodTimeToPrewarm();
bool hasPrewarmedProcess() const { return m_prewarmedProcess.get(); }
void didCollectPrewarmInformation(const WebCore::RegistrableDomain&, const WebCore::PrewarmInformation&);
void addMockMediaDevice(const WebCore::MockMediaDevice&);
void clearMockMediaDevices();
void removeMockMediaDevice(const String&);
void setMockMediaDeviceIsEphemeral(const String&, bool);
void resetMockMediaDevices();
void sendDisplayConfigurationChangedMessageForTesting();
void clearCurrentModifierStateForTesting();
#if ENABLE(TRACKING_PREVENTION)
void setDomainsWithUserInteraction(HashSet<WebCore::RegistrableDomain>&&);
void setDomainsWithCrossPageStorageAccess(HashMap<TopFrameDomain, SubResourceDomain>&&, CompletionHandler<void()>&&);
void seedResourceLoadStatisticsForTesting(const WebCore::RegistrableDomain& firstPartyDomain, const WebCore::RegistrableDomain& thirdPartyDomain, bool shouldScheduleNotification, CompletionHandler<void()>&&);
void sendResourceLoadStatisticsDataImmediately(CompletionHandler<void()>&&);
#endif
#if PLATFORM(GTK) || PLATFORM(WPE)
void setSandboxEnabled(bool enabled) { m_sandboxEnabled = enabled; };
void addSandboxPath(const CString& path, SandboxPermission permission) { m_extraSandboxPaths.add(path, permission); };
const HashMap<CString, SandboxPermission>& sandboxPaths() const { return m_extraSandboxPaths; };
bool sandboxEnabled() const { return m_sandboxEnabled; };
void setUserMessageHandler(Function<void(UserMessage&&, CompletionHandler<void(UserMessage&&)>&&)>&& handler) { m_userMessageHandler = WTFMove(handler); }
const Function<void(UserMessage&&, CompletionHandler<void(UserMessage&&)>&&)>& userMessageHandler() const { return m_userMessageHandler; }
#endif
WebProcessWithAudibleMediaToken webProcessWithAudibleMediaToken() const;
WebProcessWithMediaStreamingToken webProcessWithMediaStreamingToken() const;
static bool globalDelaysWebProcessLaunchDefaultValue();
bool delaysWebProcessLaunchDefaultValue() const { return m_delaysWebProcessLaunchDefaultValue; }
void setDelaysWebProcessLaunchDefaultValue(bool delaysWebProcessLaunchDefaultValue) { m_delaysWebProcessLaunchDefaultValue = delaysWebProcessLaunchDefaultValue; }
void setJavaScriptConfigurationDirectory(String&& directory) { m_javaScriptConfigurationDirectory = directory; }
const String& javaScriptConfigurationDirectory() const { return m_javaScriptConfigurationDirectory; }
void setOverrideLanguages(Vector<String>&&);
WebProcessDataStoreParameters webProcessDataStoreParameters(WebProcessProxy&, WebsiteDataStore&);
static void setUseSeparateServiceWorkerProcess(bool);
static bool useSeparateServiceWorkerProcess() { return s_useSeparateServiceWorkerProcess; }
void addRemoteWorkerProcess(WebProcessProxy&);
void removeRemoteWorkerProcess(WebProcessProxy&);
#if ENABLE(CFPREFS_DIRECT_MODE)
void notifyPreferencesChanged(const String& domain, const String& key, const std::optional<String>& encodedValue);
#endif
#if PLATFORM(PLAYSTATION)
const String& webProcessPath() const { return m_resolvedPaths.webProcessPath; }
const String& networkProcessPath() const { return m_resolvedPaths.networkProcessPath; }
int32_t userId() const { return m_userId; }
#endif
static void platformInitializeNetworkProcess(NetworkProcessCreationParameters&);
static Vector<String> urlSchemesWithCustomProtocolHandlers();
Ref<WebProcessProxy> createNewWebProcess(WebsiteDataStore*, WebProcessProxy::LockdownMode, WebProcessProxy::IsPrewarmed = WebProcessProxy::IsPrewarmed::No, WebCore::CrossOriginMode = WebCore::CrossOriginMode::Shared);
bool hasAudibleMediaActivity() const { return !!m_audibleMediaActivity; }
#if PLATFORM(IOS_FAMILY)
bool processesShouldSuspend() const { return m_processesShouldSuspend; }
#endif
#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
void hardwareConsoleStateChanged();
#endif
bool operator==(const WebProcessPool& other) const { return (this == &other); }
private:
void platformInitialize();
void platformInitializeWebProcess(const WebProcessProxy&, WebProcessCreationParameters&);
void platformInvalidateContext();
std::tuple<Ref<WebProcessProxy>, SuspendedPageProxy*, ASCIILiteral> processForNavigationInternal(WebPageProxy&, const API::Navigation&, Ref<WebProcessProxy>&& sourceProcess, const URL& sourceURL, ProcessSwapRequestedByClient, WebProcessProxy::LockdownMode, const FrameInfoData&, Ref<WebsiteDataStore>&&);
RefPtr<WebProcessProxy> tryTakePrewarmedProcess(WebsiteDataStore&, WebProcessProxy::LockdownMode);
void initializeNewWebProcess(WebProcessProxy&, WebsiteDataStore*, WebProcessProxy::IsPrewarmed = WebProcessProxy::IsPrewarmed::No);
void handleMessage(IPC::Connection&, const String& messageName, const UserData& messageBody);
void handleSynchronousMessage(IPC::Connection&, const String& messageName, const UserData& messageBody, CompletionHandler<void(UserData&&)>&&);
#if ENABLE(GAMEPAD)
void startedUsingGamepads(IPC::Connection&);
void stoppedUsingGamepads(IPC::Connection&, CompletionHandler<void()>&&);
void playGamepadEffect(unsigned gamepadIndex, const String& gamepadID, WebCore::GamepadHapticEffectType, const WebCore::GamepadEffectParameters&, CompletionHandler<void(bool)>&&);
void stopGamepadEffects(unsigned gamepadIndex, const String& gamepadID, CompletionHandler<void()>&&);
void processStoppedUsingGamepads(WebProcessProxy&);
#endif
void updateProcessAssertions();
void updateAudibleMediaAssertions();
void updateMediaStreamingActivity();
// IPC::MessageReceiver.
// Implemented in generated WebProcessPoolMessageReceiver.cpp
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
bool didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, UniqueRef<IPC::Encoder>&) override;
bool usesSingleWebProcess() const { return m_configuration->usesSingleWebProcess(); }
#if PLATFORM(COCOA)
void addCFNotificationObserver(CFNotificationCallback, CFStringRef name, CFNotificationCenterRef = CFNotificationCenterGetDarwinNotifyCenter());
void removeCFNotificationObserver(CFStringRef name, CFNotificationCenterRef = CFNotificationCenterGetDarwinNotifyCenter());
void registerNotificationObservers();
void unregisterNotificationObservers();
#if ENABLE(WEBCONTENT_CRASH_TESTING)
static void initializeShouldCrashWhenCreatingWebProcess();
#endif
#endif
void setApplicationIsActive(bool);
void resolvePathsForSandboxExtensions();
void platformResolvePathsForSandboxExtensions();
void addProcessToOriginCacheSet(WebProcessProxy&, const URL&);
void removeProcessFromOriginCacheSet(WebProcessProxy&);
void tryPrewarmWithDomainInformation(WebProcessProxy&, const WebCore::RegistrableDomain&);
void updateBackForwardCacheCapacity();
#if PLATFORM(IOS_FAMILY) && !PLATFORM(MACCATALYST)
static float displayBrightness();
static void backlightLevelDidChangeCallback(CFNotificationCenterRef, void* observer, CFStringRef name, const void* postingObject, CFDictionaryRef userInfo);
#if ENABLE(REMOTE_INSPECTOR)
static void remoteWebInspectorEnabledCallback(CFNotificationCenterRef, void* observer, CFStringRef name, const void* postingObject, CFDictionaryRef userInfo);
#endif
#endif
#if PLATFORM(COCOA)
static void lockdownModeConfigurationUpdateCallback(CFNotificationCenterRef, void* observer, CFStringRef name, const void* postingObject, CFDictionaryRef userInfo);
#endif
#if PLATFORM(COCOA)
static void accessibilityPreferencesChangedCallback(CFNotificationCenterRef, void* observer, CFStringRef name, const void* postingObject, CFDictionaryRef userInfo);
#endif
#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
static void mediaAccessibilityPreferencesChangedCallback(CFNotificationCenterRef, void* observer, CFStringRef name, const void* postingObject, CFDictionaryRef userInfo);
#endif
#if PLATFORM(MAC)
static void colorPreferencesDidChangeCallback(CFNotificationCenterRef, void* observer, CFStringRef name, const void* postingObject, CFDictionaryRef userInfo);
#endif
#if HAVE(POWERLOG_TASK_MODE_QUERY) && ENABLE(GPU_PROCESS)
static void powerLogTaskModeStartedCallback(CFNotificationCenterRef, void* observer, CFStringRef, const void*, CFDictionaryRef);
#endif
#if ENABLE(CFPREFS_DIRECT_MODE)
void startObservingPreferenceChanges();
#endif
static void registerDisplayConfigurationCallback();
static void registerHighDynamicRangeChangeCallback();
#if PLATFORM(MAC)
// PAL::SystemSleepListener
void systemWillSleep() final;
void systemDidWake() final;
#endif
#if HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK)
void setMediaAccessibilityPreferences(WebProcessProxy&);
#endif
void clearAudibleActivity();
Ref<API::ProcessPoolConfiguration> m_configuration;
IPC::MessageReceiverMap m_messageReceiverMap;
Vector<Ref<WebProcessProxy>> m_processes;
WeakPtr<WebProcessProxy> m_prewarmedProcess;
HashMap<PAL::SessionID, WeakPtr<WebProcessProxy>> m_dummyProcessProxies; // Lightweight WebProcessProxy objects without backing process.
static WeakHashSet<WebProcessProxy>& remoteWorkerProcesses();
std::optional<WebPreferencesStore> m_remoteWorkerPreferences;
RefPtr<WebUserContentControllerProxy> m_userContentControllerForRemoteWorkers;
String m_remoteWorkerUserAgent;
#if ENABLE(GPU_PROCESS)
RefPtr<GPUProcessProxy> m_gpuProcess;
#endif
Ref<WebPageGroup> m_defaultPageGroup;
RefPtr<API::Object> m_injectedBundleInitializationUserData;
std::unique_ptr<API::InjectedBundleClient> m_injectedBundleClient;
WebContextClient m_client;
WebContextConnectionClient m_connectionClient;
std::unique_ptr<API::AutomationClient> m_automationClient;
RefPtr<API::DownloadClient> m_legacyDownloadClient;
std::unique_ptr<API::LegacyContextHistoryClient> m_historyClient;
RefPtr<WebAutomationSession> m_automationSession;
Ref<VisitedLinkStore> m_visitedLinkStore;
bool m_visitedLinksPopulated { false };
HashSet<String> m_schemesToRegisterAsEmptyDocument;
HashSet<String> m_schemesToSetDomainRelaxationForbiddenFor;
HashSet<String> m_schemesToRegisterAsDisplayIsolated;
HashSet<String> m_schemesToRegisterAsCORSEnabled;
HashSet<String> m_schemesToRegisterAsAlwaysRevalidated;
HashSet<String> m_schemesToRegisterAsCachePartitioned;
HashSet<String> m_schemesToRegisterAsCanDisplayOnlyIfCanRequest;
bool m_alwaysUsesComplexTextCodePath { false };
bool m_disableFontSubpixelAntialiasingForTesting { false };
Vector<String> m_fontAllowList;
// Messages that were posted before any pages were created.
// The client should use initialization messages instead, so that a restarted process would get the same state.
Vector<std::pair<String, RefPtr<API::Object>>> m_messagesToInjectedBundlePostedToEmptyContext;
bool m_memorySamplerEnabled { false };
double m_memorySamplerInterval { 1400.0 };
typedef HashMap<const char*, RefPtr<WebContextSupplement>, PtrHash<const char*>> WebContextSupplementMap;
WebContextSupplementMap m_supplements;
#if USE(SOUP)
static std::optional<MemoryPressureHandler::Configuration> s_networkProcessMemoryPressureHandlerConfiguration;
#endif
#if PLATFORM(MAC)
RetainPtr<NSObject> m_enhancedAccessibilityObserver;
RetainPtr<NSObject> m_automaticTextReplacementNotificationObserver;
RetainPtr<NSObject> m_automaticSpellingCorrectionNotificationObserver;
RetainPtr<NSObject> m_automaticQuoteSubstitutionNotificationObserver;
RetainPtr<NSObject> m_automaticDashSubstitutionNotificationObserver;
RetainPtr<NSObject> m_accessibilityDisplayOptionsNotificationObserver;
RetainPtr<NSObject> m_scrollerStyleNotificationObserver;
RetainPtr<NSObject> m_deactivationObserver;
RetainPtr<WKWebInspectorPreferenceObserver> m_webInspectorPreferenceObserver;
std::unique_ptr<HighPerformanceGraphicsUsageSampler> m_highPerformanceGraphicsUsageSampler;
std::unique_ptr<PerActivityStateCPUUsageSampler> m_perActivityStateCPUUsageSampler;
#endif
#if PLATFORM(COCOA)
std::unique_ptr<WebCore::PowerSourceNotifier> m_powerSourceNotifier;
RetainPtr<NSObject> m_activationObserver;
RetainPtr<NSObject> m_accessibilityEnabledObserver;
RetainPtr<NSObject> m_applicationLaunchObserver;
RetainPtr<WKProcessPoolWeakObserver> m_weakObserver;
#endif
bool m_processTerminationEnabled { true };
bool m_memoryCacheDisabled { false };
bool m_javaScriptConfigurationFileEnabled { false };
String m_javaScriptConfigurationDirectory;
bool m_alwaysRunsAtBackgroundPriority;
bool m_shouldTakeUIBackgroundAssertion;
bool m_shouldMakeNextWebProcessLaunchFailForTesting { false };
bool m_tccPreferenceEnabled { false };
UserObservablePageCounter m_userObservablePageCounter;
ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;
HiddenPageThrottlingAutoIncreasesCounter m_hiddenPageThrottlingAutoIncreasesCounter;
RunLoop::Timer m_hiddenPageThrottlingTimer;
#if ENABLE(GPU_PROCESS)
RunLoop::Timer m_resetGPUProcessCrashCountTimer;
unsigned m_recentGPUProcessCrashCount { 0 };
#endif
#if PLATFORM(COCOA)
RetainPtr<NSMutableDictionary> m_bundleParameters;
#endif
#if ENABLE(CONTENT_EXTENSIONS)
HashMap<String, String> m_encodedContentExtensions;
#endif
#if ENABLE(GAMEPAD)
WeakHashSet<WebProcessProxy> m_processesUsingGamepads;
#endif
#if PLATFORM(COCOA)
bool m_cookieStoragePartitioningEnabled { false };
#endif
#if ENABLE(WEBCONTENT_CRASH_TESTING)
static bool s_shouldCrashWhenCreatingWebProcess;
#endif
struct Paths {
String injectedBundlePath;
String uiProcessBundleResourcePath;
#if PLATFORM(PLAYSTATION)
String webProcessPath;
String networkProcessPath;
#endif
Vector<String> additionalWebProcessSandboxExtensionPaths;
};
Paths m_resolvedPaths;
HashMap<PAL::SessionID, HashSet<WebPageProxyIdentifier>> m_sessionToPageIDsMap;
ForegroundWebProcessCounter m_foregroundWebProcessCounter;
BackgroundWebProcessCounter m_backgroundWebProcessCounter;
UniqueRef<WebBackForwardCache> m_backForwardCache;
UniqueRef<WebProcessCache> m_webProcessCache;
HashMap<WebCore::RegistrableDomain, RefPtr<WebProcessProxy>> m_swappedProcessesPerRegistrableDomain;
HashMap<WebCore::RegistrableDomain, std::unique_ptr<WebCore::PrewarmInformation>> m_prewarmInformationPerRegistrableDomain;
#if HAVE(CVDISPLAYLINK)
DisplayLinkCollection m_displayLinks;
#endif
#if PLATFORM(GTK) || PLATFORM(WPE)
bool m_sandboxEnabled { false };
HashMap<CString, SandboxPermission> m_extraSandboxPaths;
Function<void(UserMessage&&, CompletionHandler<void(UserMessage&&)>&&)> m_userMessageHandler;
#endif
WebProcessWithAudibleMediaCounter m_webProcessWithAudibleMediaCounter;
struct AudibleMediaActivity {
Ref<ProcessAssertion> uiProcessMediaPlaybackAssertion;
#if ENABLE(GPU_PROCESS)
RefPtr<ProcessAssertion> gpuProcessMediaPlaybackAssertion;
#endif
};
std::optional<AudibleMediaActivity> m_audibleMediaActivity;
RunLoop::Timer m_audibleActivityTimer;
WebProcessWithMediaStreamingCounter m_webProcessWithMediaStreamingCounter;
bool m_mediaStreamingActivity { false };
#if PLATFORM(PLAYSTATION)
int32_t m_userId { -1 };
#endif
bool m_delaysWebProcessLaunchDefaultValue { globalDelaysWebProcessLaunchDefaultValue() };
static bool s_useSeparateServiceWorkerProcess;
static bool s_didGlobalStaticInitialization;
#if ENABLE(TRACKING_PREVENTION)
HashSet<WebCore::RegistrableDomain> m_domainsWithUserInteraction;
HashMap<TopFrameDomain, SubResourceDomain> m_domainsWithCrossPageStorageAccessQuirk;
#endif
#if PLATFORM(MAC)
std::unique_ptr<WebCore::PowerObserver> m_powerObserver;
std::unique_ptr<PAL::SystemSleepListener> m_systemSleepListener;
Vector<int> m_openDirectoryNotifyTokens;
#endif
#if ENABLE(IPC_TESTING_API)
IPCTester m_ipcTester;
#endif
#if PLATFORM(IOS_FAMILY)
bool m_processesShouldSuspend { false };
#endif
};
template<typename T>
void WebProcessPool::sendToAllProcesses(const T& message)
{
for (auto& process : m_processes) {
if (process->canSendMessage())
process->send(T(message), 0);
}
}
template<typename T>
void WebProcessPool::sendToAllProcessesForSession(const T& message, PAL::SessionID sessionID)
{
forEachProcessForSession(sessionID, [&](auto& process) {
process.send(T(message), 0);
});
}
template<typename T>
void WebProcessPool::sendToAllRemoteWorkerProcesses(const T& message)
{
for (auto& process : remoteWorkerProcesses()) {
if (process.canSendMessage())
process.send(T(message), 0);
}
}
} // namespace WebKit
|