Bug 228649

Summary: Attribute nw connections to the page bundle identifier
Product: WebKit Reporter: youenn fablet <youennf>
Component: WebRTCAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, eric.carlson, ews-watchlist, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch for landing
none
Patch for landing
ews-feeder: commit-queue-
Patch for landing ews-feeder: commit-queue-

Description youenn fablet 2021-07-30 10:23:07 PDT
Attribute nw connections to the page bundle identifier
Comment 1 youenn fablet 2021-07-30 10:31:32 PDT
Created attachment 434645 [details]
Patch
Comment 2 youenn fablet 2021-08-02 00:47:51 PDT
Created attachment 434743 [details]
Patch
Comment 3 Radar WebKit Bug Importer 2021-08-02 09:43:09 PDT
<rdar://problem/81415612>
Comment 4 Eric Carlson 2021-08-02 09:44:19 PDT
Comment on attachment 434743 [details]
Patch

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

> Source/WebKit/NetworkProcess/NetworkSession.cpp:411
> +    return m_attributedBundleIdentifierFromPageIdentifiers.get(identifier);

It is worth ASSERTing that the identifier is in the map?

> Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp:159
> +        if (auto socket = NetworkRTCUDPSocketCocoa::createUDPSocket(identifier, *this, address.value, minPort, maxPort, m_ipcConnection.copyRef(), String(attributedBundleIdentifierFromPageIdentifier(pageIdentifier)), isFirstParty, isRelayDisabled,   WTFMove(domain))) {

Nit: extra space before `WTFMove`

Is this called often enough that it would be worth keeping a pageIdentifier -> attributedBundleIdentifier map in the provider instead of doing the synchronous cross-thread hop every time?

> Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp:202
> +        if (auto socket = NetworkRTCTCPSocketCocoa::createClientTCPSocket(identifier, *this, remoteAddress.value, options, attributedBundleIdentifierFromPageIdentifier(pageIdentifier), isRelayDisabled, m_ipcConnection.copyRef())) {

Ditto.
Comment 5 Alex Christensen 2021-08-02 10:50:34 PDT
Comment on attachment 434743 [details]
Patch

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

> Source/WebKit/ChangeLog:9
> +        Use page identifier to get the bundle identifier.

attributed bundle identifier, not the bundle identifier.  The former is set via SPI in contexts such as SFSafariViewController when the view is made on behalf of another application, the latter is set for the executable.

>> Source/WebKit/NetworkProcess/NetworkSession.cpp:411
>> +    return m_attributedBundleIdentifierFromPageIdentifiers.get(identifier);
> 
> It is worth ASSERTing that the identifier is in the map?

no,  it is likely not in the map.

> Source/WebKit/NetworkProcess/NetworkSession.h:180
> +    String attributedBundleIdentifierFromPageIdentifier(WebPageProxyIdentifier) const;

This could return a const String&

> Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp:149
> +        return value;

I feel like there should be an isolatedCopy somewhere in here.
Comment 6 youenn fablet 2021-08-02 11:04:57 PDT
Created attachment 434771 [details]
Patch for landing
Comment 7 youenn fablet 2021-08-02 11:11:25 PDT
> > Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp:159
> > +        if (auto socket = NetworkRTCUDPSocketCocoa::createUDPSocket(identifier, *this, address.value, minPort, maxPort, m_ipcConnection.copyRef(), String(attributedBundleIdentifierFromPageIdentifier(pageIdentifier)), isFirstParty, isRelayDisabled,   WTFMove(domain))) {
> 
> Nit: extra space before `WTFMove`

OK

> Is this called often enough that it would be worth keeping a pageIdentifier
> -> attributedBundleIdentifier map in the provider instead of doing the
> synchronous cross-thread hop every time?

Yep, this is in the patch.

> > Source/WebKit/ChangeLog:9
> > +        Use page identifier to get the bundle identifier.
> 
> attributed bundle identifier, not the bundle identifier.  The former is set
> via SPI in contexts such as SFSafariViewController when the view is made on
> behalf of another application, the latter is set for the executable.

OK


> > Source/WebKit/NetworkProcess/NetworkSession.h:180
> > +    String attributedBundleIdentifierFromPageIdentifier(WebPageProxyIdentifier) const;
> 
> This could return a const String&

OK

> > Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.cpp:149
> > +        return value;
> 
> I feel like there should be an isolatedCopy somewhere in here.

There is one when adding the NetworkSession string to the NetworkRTCProvider map (line 147). I do not think we need an isolated copy every time we return the string:
- The map is only accessed in the background thread.
- The sockets keep a ref of the strings but the sockets are deleted in the background thread.
Comment 8 youenn fablet 2021-08-02 11:11:55 PDT
> - The map is only accessed in the background thread.

I'll clear the map in the background thread when closing even though this is not strictly needed.
Comment 9 youenn fablet 2021-08-02 11:21:05 PDT
Created attachment 434776 [details]
Patch for landing
Comment 10 youenn fablet 2021-08-02 11:33:05 PDT
Created attachment 434778 [details]
Patch for landing
Comment 11 EWS 2021-08-02 14:09:59 PDT
Committed r280556 (240180@main): <https://commits.webkit.org/240180@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 434778 [details].