Bug 158940 - WebRTC: Add support for RTCPeerConnection legacy MediaStream-based API
Summary: WebRTC: Add support for RTCPeerConnection legacy MediaStream-based API
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
: 158979 (view as bug list)
Depends on: 158777 158832
Blocks: 143211
  Show dependency treegraph
 
Reported: 2016-06-20 06:42 PDT by Adam Bergkvist
Modified: 2016-06-23 06:52 PDT (History)
1 user (show)

See Also:


Attachments
Proposed patch (24.22 KB, patch)
2016-06-20 12:02 PDT, Adam Bergkvist
no flags Details | Formatted Diff | Diff
Updated patch (24.79 KB, patch)
2016-06-22 23:28 PDT, Adam Bergkvist
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Bergkvist 2016-06-20 06:42:47 PDT
The MediaStream-based API on RTCPeerConnection (addStream, removeStream, getLocalStreams, getRemoteStreams, getStreamById) has been removed from the WebRTC 1.0 specification, but is widely implemented and used. We should be able to support it with JS built-ins and some hooks down in native code.
Comment 1 Adam Bergkvist 2016-06-20 12:02:14 PDT
Created attachment 281658 [details]
Proposed patch
Comment 2 Adam Bergkvist 2016-06-20 12:04:02 PDT
(In reply to comment #1)
> Created attachment 281658 [details]
> Proposed patch

This won't build until the JS constructor is in place (http://webkit.org/b/158832).
Comment 3 youenn fablet 2016-06-20 14:56:22 PDT
Comment on attachment 281658 [details]
Proposed patch

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

> Source/WebCore/Modules/mediastream/RTCPeerConnection.js:57
> +    return this.@localStreams.slice();

Array.slice may be corrupted by user scripts.
The same applies to find findIndex, push, forEach, splice methods.
This should be robustified.

> Source/WebCore/Modules/mediastream/RTCPeerConnection.js:94
> +    stream.getTracks().forEach(track => this.@addTrack(track, stream));

Potentially, we know that this, track and stream are of the right type.
So we could replace if statements by assert statements in the binding generated code.
That said, this might be too early to do so.

> Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:87
> +        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().MediaStreamPrivateName(), JSMediaStream::getConstructor(vm, this), DontDelete | ReadOnly),

It might be good to add a keyword similar to PrivateAlso for exposing DOM constructors safely to JS builtins.
Ideally, we should not need to create the constructor but just pass a getter function that would create it if needed
Comment 4 Adam Bergkvist 2016-06-21 00:37:51 PDT
(In reply to comment #3)
> Comment on attachment 281658 [details]
> Proposed patch

Thanks for reviewing Youenn.

> View in context:
> https://bugs.webkit.org/attachment.cgi?id=281658&action=review
> 
> > Source/WebCore/Modules/mediastream/RTCPeerConnection.js:57
> > +    return this.@localStreams.slice();
> 
> Array.slice may be corrupted by user scripts.
> The same applies to find findIndex, push, forEach, splice methods.
> This should be robustified.

Looking at the array prototype implementation, we seem to have a private name for push, but the rest needs fixing. New bug: [1].

[1] http://webkit.org/b/158978

> > Source/WebCore/Modules/mediastream/RTCPeerConnection.js:94
> > +    stream.getTracks().forEach(track => this.@addTrack(track, stream));
> 
> Potentially, we know that this, track and stream are of the right type.
> So we could replace if statements by assert statements in the binding
> generated code.
> That said, this might be too early to do so.

MediaStream.getTracks is actually part of the public API so we need a safe way to call it. New bug [2].

[2] webkit.org/b/158979

I agree that assertions would be sufficient for [PrivateOnly] bindings. The bug [3] suggests that one might want to use the type checking of a [PrivateOnly] function as part of a public API call, but that might be unlikely now when we have [PrivateAlso]. I wouldn't mind closing [3] as a WONTFIX.

[3] webkit.org/b/158778

> 
> > Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:87
> > +        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().MediaStreamPrivateName(), JSMediaStream::getConstructor(vm, this), DontDelete | ReadOnly),
> 
> It might be good to add a keyword similar to PrivateAlso for exposing DOM
> constructors safely to JS builtins.
> Ideally, we should not need to create the constructor but just pass a getter
> function that would create it if needed

That would be useful indeed.
Comment 5 Adam Bergkvist 2016-06-21 00:39:18 PDT
Clickable links for the previous post

[2] http://webkit.org/b/158979
[3] http://webkit.org/b/158778
Comment 6 Adam Bergkvist 2016-06-21 23:17:36 PDT
*** Bug 158979 has been marked as a duplicate of this bug. ***
Comment 7 Adam Bergkvist 2016-06-22 23:28:46 PDT
Created attachment 281899 [details]
Updated patch
Comment 8 Adam Bergkvist 2016-06-22 23:30:09 PDT
(In reply to comment #4)
> MediaStream.getTracks is actually part of the public API so we need a safe
> way to call it. New bug [2].
> 
> [2] webkit.org/b/158979

This is included in the updated patch (closed bug:158979).
Comment 9 Adam Bergkvist 2016-06-23 06:30:11 PDT
Comment on attachment 281899 [details]
Updated patch

Thank you Eric and Youenn for reviewing
Comment 10 WebKit Commit Bot 2016-06-23 06:52:26 PDT
Comment on attachment 281899 [details]
Updated patch

Clearing flags on attachment: 281899

Committed r202376: <http://trac.webkit.org/changeset/202376>
Comment 11 WebKit Commit Bot 2016-06-23 06:52:29 PDT
All reviewed patches have been landed.  Closing bug.