Skip to content

Commit

Permalink
Register assertion invalidation callbacks
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264760
rdar://118347404

Reviewed by Brent Fulgham.

Add environment identifier and register assertion invalidation callbacks for capabilities.

* Source/WebKit/Platform/spi/Cocoa/ExtensionKitSPI.h:
* Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm:
(WebKit::ProcessAssertion::ProcessAssertion):

Canonical link: https://commits.webkit.org/270889@main
  • Loading branch information
pvollan committed Nov 17, 2023
1 parent eea0af3 commit 295b9ce
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Source/WebKit/Platform/spi/Cocoa/ExtensionKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ typedef void(^_SEServiceInteruptionHandler)();

@interface _SECapabilities : NSObject
+(instancetype)assertionWithDomain:(NSString*)domain name:(NSString*)name;
+(instancetype)assertionWithDomain:(NSString*)domain name:(NSString*)name environmentIdentifier:(NSString*)environmentIdentifier;
+(instancetype)assertionWithDomain:(NSString*)domain name:(NSString*)name environmentIdentifier:(NSString*)environmentIdentifier willInvalidate:(void (^)())willInvalidateBlock didInvalidate:(void (^)())didInvalidateBlock;
@end

NS_REFINED_FOR_SWIFT
Expand Down
23 changes: 20 additions & 3 deletions Source/WebKit/UIProcess/Cocoa/ProcessAssertionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,26 @@ - (void)assertion:(RBSAssertion *)assertion didInvalidateWithError:(NSError *)er
, m_reason(reason)
{
#if USE(EXTENSIONKIT)
if (AuxiliaryProcessProxy::manageProcessesAsExtensions()) {
if (process.extensionProcess()) {
NSString *runningBoardAssertionName = runningBoardNameForAssertionType(m_assertionType);
NSString *runningBoardDomain = runningBoardDomainForAssertionType(m_assertionType);
m_capabilities = [get_SECapabilitiesClass() assertionWithDomain:runningBoardDomain name:runningBoardAssertionName];
#if USE(EXTENSIONKIT_INVALIDATION_CALLBACKS)
auto didInvalidateBlock = [weakThis = ThreadSafeWeakPtr { *this }, runningBoardAssertionName = RetainPtr<NSString>(runningBoardAssertionName)] () {
auto strongThis = weakThis.get();
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion: RBS %{public}@ assertion for process with PID=%d was invalidated", strongThis.get(), runningBoardAssertionName.get(), strongThis ? strongThis->m_pid : 0);
if (strongThis)
strongThis->processAssertionWasInvalidated();
};
auto willInvalidateBlock = [weakThis = ThreadSafeWeakPtr { *this }, runningBoardAssertionName = RetainPtr<NSString>(runningBoardAssertionName)] () {
auto strongThis = weakThis.get();
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() RBS %{public}@ assertion for process with PID=%d will be invalidated", strongThis.get(), runningBoardAssertionName.get(), strongThis ? strongThis->m_pid : 0);
if (strongThis)
strongThis->processAssertionWillBeInvalidated();
};
m_capabilities = [get_SECapabilitiesClass() assertionWithDomain:runningBoardDomain name:runningBoardAssertionName environmentIdentifier: process.environmentIdentifier() willInvalidate: willInvalidateBlock didInvalidate: didInvalidateBlock];
#else
m_capabilities = [get_SECapabilitiesClass() assertionWithDomain:runningBoardDomain name:runningBoardAssertionName environmentIdentifier: process.environmentIdentifier()];
#endif
m_process = process.extensionProcess();
if (m_capabilities)
return;
Expand Down Expand Up @@ -461,7 +477,8 @@ - (void)assertion:(RBSAssertion *)assertion didInvalidateWithError:(NSError *)er
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Successfully granted capability", this);
return;
}
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Failed to grant capability with error %@", this, error);
NSString *runningBoardAssertionName = runningBoardNameForAssertionType(m_assertionType);
RELEASE_LOG(ProcessSuspension, "%p - ProcessAssertion() Failed to grant capability %@ with error %@", this, runningBoardAssertionName, error);
}
#endif
NSError *acquisitionError = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ static void launchWithExtensionKit(ProcessLauncher& processLauncher, ProcessLaun

void ProcessLauncher::platformInvalidate()
{
#if USE(EXTENSIONKIT)
[m_process invalidate];
#endif

terminateXPCConnection();
}

Expand Down

0 comments on commit 295b9ce

Please sign in to comment.