Skip to content

Commit

Permalink
Cherry-pick 48ca65b. rdar://123799163
Browse files Browse the repository at this point in the history
Identifier: 272448.765@safari-7618-branch
  • Loading branch information
whsieh authored and MyahCobbs committed Mar 20, 2024
1 parent e285de6 commit 7bc9e14
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,4 @@ static const WKNavigationResponsePolicy _WKNavigationResponsePolicyBecomeDownloa
- (void)_webView:(WKWebView *)webView willGoToBackForwardListItem:(WKBackForwardListItem *)item inPageCache:(BOOL)inPageCache WK_API_AVAILABLE(macos(10.13.4), ios(14.0));
- (void)_webView:(WKWebView *)webView decidePolicyForSOAuthorizationLoadWithCurrentPolicy:(_WKSOAuthorizationLoadPolicy)policy forExtension:(NSString *)extension completionHandler:(void (^)(_WKSOAuthorizationLoadPolicy policy))completionHandler WK_API_AVAILABLE(macos(10.15), ios(13.0));

- (void)_webView:(WKWebView *)webView didExceedMemoryFootprintThresholdWithFootprint:(size_t)footprint WK_API_AVAILABLE(macos(WK_MAC_TBA));

@end
7 changes: 4 additions & 3 deletions Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#import "_WKWebsiteDataStoreDelegate.h"
#import <WebCore/Credential.h>
#import <WebCore/RegistrableDomain.h>
#import <WebCore/ResourceResponse.h>
#import <WebCore/ServiceWorkerClientData.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <wtf/BlockPtr.h>
Expand Down Expand Up @@ -80,7 +81,7 @@
, m_hasNotifyBackgroundFetchChangeSelector([m_delegate.get() respondsToSelector:@selector(notifyBackgroundFetchChange:change:)])
, m_hasWindowProxyPropertyAccessSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:domain:didOpenDomainViaWindowOpen:withProperty:directly:)])
, m_hasDidAllowPrivateTokenUsageByThirdPartyForTestingSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:didAllowPrivateTokenUsageByThirdPartyForTesting:forResourceURL:)])
, m_hasDidExceedMemoryFootprintThresholdSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:domain:didExceedMemoryFootprintThreshold:withPageCount:processLifetime:inForeground:)])
, m_hasDidExceedMemoryFootprintThresholdSelector([m_delegate.get() respondsToSelector:@selector(websiteDataStore:domain:didExceedMemoryFootprintThreshold:withPageCount:processLifetime:inForeground:wasPrivateRelayed:)])
{
}

Expand Down Expand Up @@ -300,12 +301,12 @@ void didAllowPrivateTokenUsageByThirdPartyForTesting(bool wasAllowed, WTF::URL&&
[m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() didAllowPrivateTokenUsageByThirdPartyForTesting:wasAllowed forResourceURL:resourceURL];
}

void didExceedMemoryFootprintThreshold(size_t footprint, const String& domain, unsigned pageCount, Seconds processLifetime, bool inForeground)
void didExceedMemoryFootprintThreshold(size_t footprint, const String& domain, unsigned pageCount, Seconds processLifetime, bool inForeground, WebCore::WasPrivateRelayed wasPrivateRelayed)
{
if (!m_hasDidExceedMemoryFootprintThresholdSelector)
return;

[m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() domain:(NSString *)domain didExceedMemoryFootprintThreshold:footprint withPageCount:pageCount processLifetime:processLifetime.seconds() inForeground:inForeground];
[m_delegate.getAutoreleased() websiteDataStore:m_dataStore.getAutoreleased() domain:(NSString *)domain didExceedMemoryFootprintThreshold:footprint withPageCount:pageCount processLifetime:processLifetime.seconds() inForeground:inForeground wasPrivateRelayed:wasPrivateRelayed == WebCore::WasPrivateRelayed::Yes];
}

WeakObjCPtr<WKWebsiteDataStore> m_dataStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ WK_API_AVAILABLE(macos(10.15), ios(13.0))
- (void)notifyBackgroundFetchChange:(NSString *)backgroundFetchIdentifier change:(WKBackgroundFetchChange)change;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didOpenDomainViaWindowOpen:(NSString *)openedRegistrableDomain withProperty:(WKWindowProxyProperty)property directly:(BOOL)directly;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore didAllowPrivateTokenUsageByThirdPartyForTesting:(BOOL)wasAllowed forResourceURL:(NSURL *)resourceURL;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground;
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground wasPrivateRelayed:(BOOL)wasPrivateRelayed;
@end
7 changes: 6 additions & 1 deletion Source/WebKit/UIProcess/WebProcessProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#include <WebCore/PrewarmInformation.h>
#include <WebCore/PublicSuffix.h>
#include <WebCore/RealtimeMediaSourceCenter.h>
#include <WebCore/ResourceResponse.h>
#include <WebCore/SecurityOriginData.h>
#include <WebCore/SuddenTermination.h>
#include <pal/system/Sound.h>
Expand Down Expand Up @@ -1948,21 +1949,25 @@ void WebProcessProxy::didExceedMemoryFootprintThreshold(size_t footprint)
return;

String domain;
bool wasPrivateRelayed = false;

for (auto& page : this->pages()) {
#if ENABLE(PUBLIC_SUFFIX_LIST)
String pageDomain = topPrivatelyControlledDomain(URL({ }, page->currentURL()).host().toString());
if (domain.isEmpty())
domain = WTFMove(pageDomain);
else if (domain != pageDomain)
domain = "multiple"_s;

wasPrivateRelayed = wasPrivateRelayed || page->pageLoadState().wasPrivateRelayed();
#endif
}

if (domain.isEmpty())
domain = "unknown"_s;

auto activeTime = totalForegroundTime() + totalBackgroundTime() + totalSuspendedTime();
dataStore->client().didExceedMemoryFootprintThreshold(footprint, domain, pageCount(), activeTime, throttler().currentState() == ProcessThrottleState::Foreground);
dataStore->client().didExceedMemoryFootprintThreshold(footprint, domain, pageCount(), activeTime, throttler().currentState() == ProcessThrottleState::Foreground, wasPrivateRelayed ? WebCore::WasPrivateRelayed::Yes : WebCore::WasPrivateRelayed::No);
}

void WebProcessProxy::didExceedCPULimit()
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/UIProcess/WebsiteData/WebsiteDataStoreClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <wtf/Seconds.h>

namespace WebCore {
enum class WasPrivateRelayed : bool;
enum class WindowProxyProperty : uint8_t;
struct NotificationData;
class RegistrableDomain;
Expand Down Expand Up @@ -117,7 +118,7 @@ class WebsiteDataStoreClient {
{
}

virtual void didExceedMemoryFootprintThreshold(size_t footprint, const String& domain, unsigned pageCount, Seconds processLifetime, bool inForeground)
virtual void didExceedMemoryFootprintThreshold(size_t, const String&, unsigned, Seconds, bool, WebCore::WasPrivateRelayed)
{
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ @interface MemoryFootprintDelegate : NSObject<_WKWebsiteDataStoreDelegate> {

@implementation MemoryFootprintDelegate

- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground
- (void)websiteDataStore:(WKWebsiteDataStore *)dataStore domain:(NSString *)registrableDomain didExceedMemoryFootprintThreshold:(size_t)footprint withPageCount:(NSUInteger)pageCount processLifetime:(NSTimeInterval)processLifetime inForeground:(BOOL)inForeground wasPrivateRelayed:(BOOL)wasPrivateRelayed
{
_footprints.append(footprint);

Expand Down

0 comments on commit 7bc9e14

Please sign in to comment.