Bug 192793 - Add a new SPI for controlling getUserMedia
Summary: Add a new SPI for controlling getUserMedia
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-12-17 18:55 PST by youenn fablet
Modified: 2019-01-16 17:19 PST (History)
5 users (show)

See Also:


Attachments
Patch (43.77 KB, patch)
2018-12-18 11:01 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (48.26 KB, patch)
2018-12-18 11:39 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (51.61 KB, patch)
2018-12-18 13:40 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (51.68 KB, patch)
2018-12-18 17:28 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (54.20 KB, patch)
2018-12-19 14:52 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (48.66 KB, patch)
2018-12-19 16:00 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (52.94 KB, patch)
2018-12-20 14:42 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (53.05 KB, patch)
2018-12-20 15:54 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (53.70 KB, patch)
2019-01-08 13:33 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (53.91 KB, patch)
2019-01-08 16:06 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (55.96 KB, patch)
2019-01-16 13:16 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (55.13 KB, patch)
2019-01-16 14:54 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (55.13 KB, patch)
2019-01-16 16:06 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2018-12-17 18:55:28 PST
Add a new SPI for controlling getUserMedia
Comment 1 youenn fablet 2018-12-18 11:01:25 PST
Created attachment 357581 [details]
Patch
Comment 2 youenn fablet 2018-12-18 11:39:55 PST
Created attachment 357590 [details]
Patch
Comment 3 youenn fablet 2018-12-18 13:40:18 PST
Created attachment 357605 [details]
Patch
Comment 4 youenn fablet 2018-12-18 17:28:34 PST
Created attachment 357639 [details]
Patch
Comment 5 Alex Christensen 2018-12-19 13:02:03 PST
Comment on attachment 357639 [details]
Patch

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

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:862
>      auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request)](BOOL authorized) {

This needs a CompletionHandlerCallChecker

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:996
> +        auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request)](BOOL authorized) {

ditto
Comment 6 Eric Carlson 2018-12-19 13:14:16 PST
Comment on attachment 357639 [details]
Patch

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

> Source/WebKit/ChangeLog:16
> +        Did some refactoring by making the callbacks not returning false.

Nit: s/not returning false/not return bool/
Comment 7 youenn fablet 2018-12-19 14:52:48 PST
Created attachment 357729 [details]
Patch
Comment 8 youenn fablet 2018-12-19 16:00:37 PST
Created attachment 357745 [details]
Patch
Comment 9 youenn fablet 2018-12-20 14:42:34 PST
Created attachment 357873 [details]
Patch
Comment 10 youenn fablet 2018-12-20 15:54:09 PST
Created attachment 357885 [details]
Patch
Comment 11 youenn fablet 2019-01-08 13:33:37 PST
Created attachment 358631 [details]
Patch
Comment 12 Alex Christensen 2019-01-08 14:52:59 PST
Comment on attachment 358631 [details]
Patch

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

> Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h:111
> +- (void)_webView:(WKWebView *)webView requestMediaCaptureAuthorization:(_WKCaptureDevices)devices decisionHandler:(void (^)(BOOL authorized))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
> +- (void)_webView:(WKWebView *)webView isMediaCaptureAuthorized:(void (^)(_WKCaptureDevices authorizedDevices))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));

I don't think it is a good design to have two callbacks that are this similar asking a very similar question.  It requires app developers to know lots of details about the implementation and set up a finite state machine in a certain way.
Comment 13 Alex Christensen 2019-01-08 15:23:10 PST
We discussed this, and I think it would be much more clear if one callback indicated it was for getUserMedia and one callback was for enumerateDevices.
Comment 14 youenn fablet 2019-01-08 15:51:03 PST
Yes, we can improve the name of the second callback to tie it more to enumerateDevices.
Something like canExposeMediaCaptureDeviceInformation for instance.
Comment 15 youenn fablet 2019-01-08 16:06:21 PST
Created attachment 358647 [details]
Patch
Comment 16 youenn fablet 2019-01-08 16:07:16 PST
(In reply to youenn fablet from comment #15)
> Created attachment 358647 [details]
> Patch

I went with the following name: queryExposableMediaCaptureDeviceInformation
Comment 17 Eric Carlson 2019-01-09 23:03:24 PST
(In reply to Alex Christensen from comment #12)
> Comment on attachment 358631 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=358631&action=review
> 
> > Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h:111
> > +- (void)_webView:(WKWebView *)webView requestMediaCaptureAuthorization:(_WKCaptureDevices)devices decisionHandler:(void (^)(BOOL authorized))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
> > +- (void)_webView:(WKWebView *)webView isMediaCaptureAuthorized:(void (^)(_WKCaptureDevices authorizedDevices))decisionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
> 
> I don't think it is a good design to have two callbacks that are this
> similar asking a very similar question.  

I don't agree that the questions are all that similar. One says:

    Ask the user to see if the page can access data from the
    camera/microphone right now

the other says: 

    Has this user given permission to access camera/microphone
    without a prompt at some time in the future?


> It requires app developers to know lots of details about the 
> implementation and set up a finite state machine in a certain way.

I don't understand this, why does the app need a FSM? In the first case the app prompts the user, and in the second case it checks for a stored setting.
Comment 18 Eric Carlson 2019-01-09 23:10:13 PST
(In reply to Alex Christensen from comment #13)
> We discussed this, and I think it would be much more clear if one callback
> indicated it was for getUserMedia and one callback was for enumerateDevices.

One callback is not just for enumerateDevices.


(In reply to youenn fablet from comment #16)
> (In reply to youenn fablet from comment #15)
> > Created attachment 358647 [details]
> > Patch
> 
> I went with the following name: queryExposableMediaCaptureDeviceInformation

I agree that the original name can be improved, but I don't think this name is right either. This callback is not just asking about what should be exposed by enumerateDevices, it is asking if the user has given permission to access camera/microphone without a prompt. We may *also* use this to expose device IDs etc before gUM has been called, but it is not the only use of the information provided by this callback.

How about -[_webView:hasPermissionToCaptureWithoutUserPrompt:]?
Comment 19 youenn fablet 2019-01-10 08:22:54 PST
> I agree that the original name can be improved, but I don't think this name
> is right either. This callback is not just asking about what should be
> exposed by enumerateDevices, it is asking if the user has given permission
> to access camera/microphone without a prompt. We may *also* use this to
> expose device IDs etc before gUM has been called, but it is not the only use
> of the information provided by this callback.
> 
> How about -[_webView:hasPermissionToCaptureWithoutUserPrompt:]?

Currently, we are only using the second callback to control enumerateDevices.
A callback dedicated to enumerateDevices has some benefits:
- This offers the flexibility so that one can implement Chrome, Firefox or Safari enumerateDevices  behavior
- This makes it clear to developers which callback they should implement to allow/disallow getUserMedia. Otherwise, developers might implement "hasPermissionToCaptureWithoutUserPrompt", return yes, and getUserMedia call will still fail.
Comment 20 youenn fablet 2019-01-16 13:16:03 PST
Created attachment 359296 [details]
Patch
Comment 21 Eric Carlson 2019-01-16 14:13:06 PST
Comment on attachment 359296 [details]
Patch

r=me with the completion handler change we discussed in person.
Comment 22 youenn fablet 2019-01-16 14:54:38 PST
Created attachment 359314 [details]
Patch for landing
Comment 23 youenn fablet 2019-01-16 15:21:56 PST
(In reply to Eric Carlson from comment #21)
> Comment on attachment 359296 [details]
> Patch
> 
> r=me with the completion handler change we discussed in person.

Thanks for the review.
Yes, I updated the default implementation accordingly.
Comment 24 WebKit Commit Bot 2019-01-16 15:51:17 PST
Comment on attachment 359314 [details]
Patch for landing

Rejecting attachment 359314 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03', 'validate-changelog', '--check-oops', '--non-interactive', 359314, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

ChangeLog entry in Source/WebKit/ChangeLog contains OOPS!.

Full output: https://webkit-queues.webkit.org/results/10777103
Comment 25 youenn fablet 2019-01-16 16:06:45 PST
Created attachment 359331 [details]
Patch for landing
Comment 26 WebKit Commit Bot 2019-01-16 17:18:11 PST
Comment on attachment 359331 [details]
Patch for landing

Clearing flags on attachment: 359331

Committed r240100: <https://trac.webkit.org/changeset/240100>
Comment 27 WebKit Commit Bot 2019-01-16 17:18:13 PST
All reviewed patches have been landed.  Closing bug.
Comment 28 Radar WebKit Bug Importer 2019-01-16 17:19:47 PST
<rdar://problem/47335825>