Bug 226757 - [Cocoa] Upstream GroupActivitiesCoordinator
Summary: [Cocoa] Upstream GroupActivitiesCoordinator
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jer Noble
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-06-07 22:45 PDT by Jer Noble
Modified: 2021-06-22 14:56 PDT (History)
6 users (show)

See Also:


Attachments
Patch (57.86 KB, patch)
2021-06-07 22:54 PDT, Jer Noble
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (57.64 KB, patch)
2021-06-07 23:20 PDT, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (63.94 KB, patch)
2021-06-08 16:14 PDT, Jer Noble
no flags Details | Formatted Diff | Diff
Patch (63.74 KB, patch)
2021-06-09 10:05 PDT, Jer Noble
sam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jer Noble 2021-06-07 22:45:44 PDT
[Cocoa] Upstream GroupActivitiesCoordinator
Comment 1 Radar WebKit Bug Importer 2021-06-07 22:47:32 PDT
<rdar://problem/78984282>
Comment 2 Jer Noble 2021-06-07 22:54:25 PDT
Created attachment 430812 [details]
Patch
Comment 3 Jer Noble 2021-06-07 23:20:45 PDT
Created attachment 430813 [details]
Patch
Comment 4 Sam Weinig 2021-06-08 09:07:12 PDT
Comment on attachment 430813 [details]
Patch

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

> Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSession.mm:27
> +#import  "config.h"
> +#import  "GroupSession.h"

Extra spaces.

> Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSession.mm:35
> +Ref<GroupSession> GroupSession::create(RetainPtr<WKGroupSession>&& session)

These names seem too generic. I think we should make these quite a bit specific to the use case.

> Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSessionNotifier.mm:58
> +static void* WebKitSwiftLibrary()
> +{
> +    static void* dylib = [] {
> +        // Start by searching for the library in DYLD_LIBRARY_PATH:
> +        if (void *result = dlopen("libWebKitSwift.dylib", RTLD_NOW))
> +            return result;
> +
> +        // Then search in the Frameworks/ directory of the currently loaded version of WebKit.framework:
> +        Dl_info info { };
> +        if (dladdr((const void*)&WebKitSwiftLibrary, &info) && strlen(info.dli_fname)) {
> +            auto webkitFrameworkDirectory = WTF::FileSystemImpl::parentPath(info.dli_fname);
> +            auto dylibPath = WTF::FileSystemImpl::pathByAppendingComponent(webkitFrameworkDirectory, "Frameworks/libWebKitSwift.dylib");
> +            if (void* result = dlopen(dylibPath.utf8().data(), RTLD_NOW))
> +                return result;
> +        }
> +
> +        // Finally, search at the installed system path:
> +        if (void *result = dlopen("/System/Library/Frameworks/WebKit.framework/Frameworks/libWebKitSwift.dylib", RTLD_NOW))
> +            return result;
> +
> +        return (void *)nullptr;
> +    }();
> +    return dylib;
> +}

Given this is a generic linking of libWebKitSwift.dylib, and could be used for other things in the future, this should probably go in its own .h/.cpp file.

> Source/WebKit/UIProcess/Cocoa/GroupActivities/WKGroupSession.swift:30
> +import AVFoundation
> +import Combine
> +@_spi(Safari) import GroupActivities
> +import Foundation
> +

We don't allow Swift in the WebKit project. This probably needs to be discussed on webkit-dev to determine if it makes sense to allow this addition.
Comment 5 Sam Weinig 2021-06-08 09:07:50 PDT
Comment on attachment 430813 [details]
Patch

r-ing due to the concerns around use of a new language.
Comment 6 Sam Weinig 2021-06-08 14:56:20 PDT
Comment on attachment 430813 [details]
Patch

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

>> Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSession.mm:35
>> +Ref<GroupSession> GroupSession::create(RetainPtr<WKGroupSession>&& session)
> 
> These names seem too generic. I think we should make these quite a bit specific to the use case.

Jer and I discussed this and think that using the prefix GroupActivity or maybe GroupActivities for these classes will help quite a bit. So this will become GroupActivitySession or GroupActivitiesSession.
Comment 7 Jer Noble 2021-06-08 15:39:24 PDT
(In reply to Sam Weinig from comment #4)
> Comment on attachment 430813 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=430813&action=review
> 
> > Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSession.mm:27
> > +#import  "config.h"
> > +#import  "GroupSession.h"
> 
> Extra spaces.

Deleted.

> > Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSession.mm:35
> > +Ref<GroupSession> GroupSession::create(RetainPtr<WKGroupSession>&& session)
> 
> These names seem too generic. I think we should make these quite a bit
> specific to the use case.

I made all the classes in this area match, with a prefix of GroupActivities, which is the name of the underlying framework.

> > Source/WebKit/UIProcess/Cocoa/GroupActivities/GroupSessionNotifier.mm:58
> > +static void* WebKitSwiftLibrary()
> > +{
> > +    static void* dylib = [] {
> > +        // Start by searching for the library in DYLD_LIBRARY_PATH:
> > +        if (void *result = dlopen("libWebKitSwift.dylib", RTLD_NOW))
> > +            return result;
> > +
> > +        // Then search in the Frameworks/ directory of the currently loaded version of WebKit.framework:
> > +        Dl_info info { };
> > +        if (dladdr((const void*)&WebKitSwiftLibrary, &info) && strlen(info.dli_fname)) {
> > +            auto webkitFrameworkDirectory = WTF::FileSystemImpl::parentPath(info.dli_fname);
> > +            auto dylibPath = WTF::FileSystemImpl::pathByAppendingComponent(webkitFrameworkDirectory, "Frameworks/libWebKitSwift.dylib");
> > +            if (void* result = dlopen(dylibPath.utf8().data(), RTLD_NOW))
> > +                return result;
> > +        }
> > +
> > +        // Finally, search at the installed system path:
> > +        if (void *result = dlopen("/System/Library/Frameworks/WebKit.framework/Frameworks/libWebKitSwift.dylib", RTLD_NOW))
> > +            return result;
> > +
> > +        return (void *)nullptr;
> > +    }();
> > +    return dylib;
> > +}
> 
> Given this is a generic linking of libWebKitSwift.dylib, and could be used
> for other things in the future, this should probably go in its own .h/.cpp
> file.

Moved this into WebKitSwiftSoftLink.h/mm

> > Source/WebKit/UIProcess/Cocoa/GroupActivities/WKGroupSession.swift:30
> > +import AVFoundation
> > +import Combine
> > +@_spi(Safari) import GroupActivities
> > +import Foundation
> > +
> 
> We don't allow Swift in the WebKit project. This probably needs to be
> discussed on webkit-dev to determine if it makes sense to allow this
> addition.

I'll start a thread on webkit-dev with the caveat that this is merely bridging code for a Swift-API.
Comment 8 Jer Noble 2021-06-08 16:14:12 PDT
Created attachment 430906 [details]
Patch
Comment 9 Alex Christensen 2021-06-08 19:00:58 PDT
Comment on attachment 430906 [details]
Patch

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

> Source/WebKit/UIProcess/Cocoa/WebKitSwiftSoftLink.mm:51
> +        if ((library = dlopen("/System/Library/Frameworks/WebKit.framework/Frameworks/libWebKitSwift.dylib", RTLD_NOW)))

Could we not hard-code this path into the binary?  I'm imagining lots of problems with INSTALL_PATH being different in places like our catalyst build.
Comment 10 Jer Noble 2021-06-08 21:26:07 PDT
(In reply to Alex Christensen from comment #9)
> Comment on attachment 430906 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=430906&action=review
> 
> > Source/WebKit/UIProcess/Cocoa/WebKitSwiftSoftLink.mm:51
> > +        if ((library = dlopen("/System/Library/Frameworks/WebKit.framework/Frameworks/libWebKitSwift.dylib", RTLD_NOW)))
> 
> Could we not hard-code this path into the binary?  I'm imagining lots of
> problems with INSTALL_PATH being different in places like our catalyst build.

The Catalyst and Staging paths should be covered by the "look in the Frameworks/ directory of the current-loaded WebKit binary" case above.  But because we have to soft-link this dylib rather than strong- or weak-link, the mechanisms we would usually use for locating dylibs won't work here. I'm open to other ideas however.
Comment 11 Alex Christensen 2021-06-09 09:54:34 PDT
Comment on attachment 430906 [details]
Patch

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

>>> Source/WebKit/UIProcess/Cocoa/WebKitSwiftSoftLink.mm:51
>>> +        if ((library = dlopen("/System/Library/Frameworks/WebKit.framework/Frameworks/libWebKitSwift.dylib", RTLD_NOW)))
>> 
>> Could we not hard-code this path into the binary?  I'm imagining lots of problems with INSTALL_PATH being different in places like our catalyst build.
> 
> The Catalyst and Staging paths should be covered by the "look in the Frameworks/ directory of the current-loaded WebKit binary" case above.  But because we have to soft-link this dylib rather than strong- or weak-link, the mechanisms we would usually use for locating dylibs won't work here. I'm open to other ideas however.

Would it work if we just removed this and only searched in the two previous locations?  I'm just worried about us loading the wrong version in Catalyst builds or in Safari Tech Preview
Comment 12 Jer Noble 2021-06-09 10:04:55 PDT
(In reply to Alex Christensen from comment #11)
> Would it work if we just removed this and only searched in the two previous
> locations?  I'm just worried about us loading the wrong version in Catalyst
> builds or in Safari Tech Preview

I think the fallback could be safely removed; this would mean that certain features would fail to work if the .dylib was missing, but the entire point of this .dylib is to handle that scenario, for things like BaseOS installs. I'll remove it.
Comment 13 Jer Noble 2021-06-09 10:05:30 PDT
Created attachment 430973 [details]
Patch
Comment 14 Sam Weinig 2021-06-09 16:48:01 PDT
Comment on attachment 430973 [details]
Patch

What is the plan for testing this?
Comment 15 Sam Weinig 2021-06-09 16:49:15 PDT
Erg, didn't realize there was still a discussion going on about the soft-linking. Sorry.
Comment 16 Jer Noble 2021-06-09 17:16:59 PDT
(In reply to Sam Weinig from comment #15)
> Erg, didn't realize there was still a discussion going on about the
> soft-linking. Sorry.

No, I took Alex's suggestion and implemented it. The current patch reflects that.

(In reply to Sam Weinig from comment #14)
> Comment on attachment 430973 [details]
> Patch
> 
> What is the plan for testing this?

Manual testing only, as it involves a separate device and a FaceTime connection to be functional. We have mock versions of the coordinator's private objects and layout tests based on those mock objects.
Comment 17 Eric Carlson 2021-06-09 17:41:58 PDT
(In reply to Jer Noble from comment #16)
> 
> (In reply to Sam Weinig from comment #14)
> > Comment on attachment 430973 [details]
> > Patch
> > 
> > What is the plan for testing this?
> 
> Manual testing only, as it involves a separate device and a FaceTime
> connection to be functional. We have mock versions of the coordinator's
> private objects and layout tests based on those mock objects.

And a fairly extensive API test.
Comment 18 Jer Noble 2021-06-22 11:49:55 PDT
Committed r279133: https://trac.webkit.org/r279133
Comment 19 Jer Noble 2021-06-22 14:21:10 PDT
Follow-up build fix: Committed r279147
Comment 20 Jer Noble 2021-06-22 14:56:01 PDT
Yet another follow-up build fix: Committed r279151