Bug 233719

Summary: [WK2] Make Web Lock API work across multiple WebProcesses
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, annulen, darin, ews-watchlist, ggaren, gyuyoung.kim, hi, japhet, kkinnunen, mkwst, ryuan.choi, sam, sergio, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 233289    
Bug Blocks: 232436    
Attachments:
Description Flags
WIP Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch none

Description Chris Dumez 2021-12-01 13:07:30 PST
Make Web Lock API work across multiple WebProcesses when using modern WebKit.
Comment 1 Chris Dumez 2021-12-01 13:44:40 PST
Created attachment 445610 [details]
WIP Patch
Comment 2 Chris Dumez 2021-12-01 15:16:58 PST
Created attachment 445622 [details]
Patch
Comment 3 Chris Dumez 2021-12-01 15:27:56 PST
Created attachment 445624 [details]
Patch
Comment 4 Chris Dumez 2021-12-01 15:42:41 PST
Created attachment 445627 [details]
Patch
Comment 5 Chris Dumez 2021-12-01 16:11:38 PST
Created attachment 445629 [details]
Patch
Comment 6 Chris Dumez 2021-12-01 16:14:23 PST
Created attachment 445630 [details]
Patch
Comment 7 Chris Dumez 2021-12-01 16:51:29 PST
Created attachment 445634 [details]
Patch
Comment 8 Chris Dumez 2021-12-01 17:32:28 PST
Created attachment 445647 [details]
Patch
Comment 9 Chris Dumez 2021-12-01 21:34:52 PST
Created attachment 445668 [details]
Patch
Comment 10 Chris Dumez 2021-12-01 21:46:51 PST
Created attachment 445670 [details]
Patch
Comment 11 Alex Christensen 2021-12-02 08:18:03 PST
Comment on attachment 445670 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=445670&action=review

Would it be worth adding a test using _relatedWebView to verify what happens when you have two pages in the same process?

> Source/WebCore/Modules/web-locks/WebLockRegistry.h:76
> +    HashMap<ClientOrigin, PerOriginRegistry*> m_perOriginRegistries;

Can this be a weak pointer?

> Source/WebKit/WebProcess/WebCoreSupport/RemoteWebLockRegistry.messages.in:28
> +    DidCompleteLockRequest(WebCore::WebLockIdentifier lockIdentifier, WebCore::ScriptExecutionContextIdentifier clientID, bool success);
> +    DidStealLock(WebCore::WebLockIdentifier lockIdentifier, WebCore::ScriptExecutionContextIdentifier clientID);

It seems like this can be a completion handler on the RequestLock message that just contains whether it was success, failure, or stolen.  That would be nicer than introducing a new messages.in just for replies.
Comment 12 Chris Dumez 2021-12-02 08:34:14 PST
(In reply to Alex Christensen from comment #11)
> Comment on attachment 445670 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=445670&action=review
> 
> Would it be worth adding a test using _relatedWebView to verify what happens
> when you have two pages in the same process?
> 
> > Source/WebCore/Modules/web-locks/WebLockRegistry.h:76
> > +    HashMap<ClientOrigin, PerOriginRegistry*> m_perOriginRegistries;
> 
> Can this be a weak pointer?

It can. It is not strictly needed but it is always better to be safe. I'll make the change.

> 
> > Source/WebKit/WebProcess/WebCoreSupport/RemoteWebLockRegistry.messages.in:28
> > +    DidCompleteLockRequest(WebCore::WebLockIdentifier lockIdentifier, WebCore::ScriptExecutionContextIdentifier clientID, bool success);
> > +    DidStealLock(WebCore::WebLockIdentifier lockIdentifier, WebCore::ScriptExecutionContextIdentifier clientID);
> 
> It seems like this can be a completion handler on the RequestLock message
> that just contains whether it was success, failure, or stolen.  That would
> be nicer than introducing a new messages.in just for replies.

There are several issues with that:
1. It could get called twice: once with success because we got the lock and a second time later on because our lock got stolen.
2. It may not get called at all (request may get aborted before it is processed)

Both are really compatible with CompletionHandler and this is why the API currently uses 2 Functions.
Comment 13 Chris Dumez 2021-12-02 09:29:46 PST
Created attachment 445727 [details]
Patch
Comment 14 Chris Dumez 2021-12-02 10:25:36 PST
Created attachment 445736 [details]
Patch
Comment 15 Chris Dumez 2021-12-02 12:46:58 PST
Created attachment 445763 [details]
Patch
Comment 16 EWS 2021-12-02 14:59:47 PST
Committed r286455 (244797@main): <https://commits.webkit.org/244797@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 445763 [details].
Comment 17 Radar WebKit Bug Importer 2021-12-02 15:00:39 PST
<rdar://problem/85990763>