Bug 216974

Summary: Make sure our calls to AVCaptureDevice requestAccessForMediaType do processing on the main thread
Product: WebKit Reporter: youenn fablet <youennf>
Component: WebRTCAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, eric.carlson, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
ews-feeder: commit-queue-
Patch
none
Patch for landing none

Description youenn fablet 2020-09-25 06:54:15 PDT
Make sure our calls to AVCaptureDevice requestAccessForMediaType do processing on the main thread
Comment 1 youenn fablet 2020-09-25 07:31:10 PDT
Created attachment 409691 [details]
Patch
Comment 2 youenn fablet 2020-09-25 07:43:06 PDT
Created attachment 409692 [details]
Patch
Comment 3 youenn fablet 2020-09-25 07:49:50 PDT
Created attachment 409693 [details]
Patch
Comment 4 youenn fablet 2020-09-25 08:03:58 PDT
Created attachment 409694 [details]
Patch
Comment 5 Radar WebKit Bug Importer 2020-09-25 08:17:34 PDT
<rdar://problem/69572304>
Comment 6 Darin Adler 2020-09-26 16:07:27 PDT
Comment on attachment 409694 [details]
Patch

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

> Source/WebKit/ChangeLog:8
> +        The completion handler to [AVCaptureDeviceClass requestAccessForMediaType:] may sometimes be called in a background thread on iOS.

Can we make a test for this that will fail on iOS?

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:995
> +            auto completionHandler = [this, weakThis = WTFMove(weakThis), frame = WTFMove(frame), protectedRequest = WTFMove(protectedRequest), webView = WTFMove(webView), topLevelOrigin = WTFMove(topLevelOrigin)](BOOL authorized) {

I think it’s a bad pattern when we pass a pointer twice, once that we use and other for lifetime checking. In case like this, can we *not* capture this, please? Minimizes the chance we use it wrong. I feel the same way about capturing both "this" and "protectedThis".
Comment 7 youenn fablet 2020-09-28 02:20:41 PDT
(In reply to Darin Adler from comment #6)
> Comment on attachment 409694 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=409694&action=review
> 
> > Source/WebKit/ChangeLog:8
> > +        The completion handler to [AVCaptureDeviceClass requestAccessForMediaType:] may sometimes be called in a background thread on iOS.
> 
> Can we make a test for this that will fail on iOS?

We are only calling this code path in case the authorisation is undetermined, which will most probably trigger a prompt.
We usually avoid doing so as we cannot handle prompts easily.
That said, it seems we could investigate using some additional tools.
I filed rdar://problem/69687122.
> 
> > Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:995
> > +            auto completionHandler = [this, weakThis = WTFMove(weakThis), frame = WTFMove(frame), protectedRequest = WTFMove(protectedRequest), webView = WTFMove(webView), topLevelOrigin = WTFMove(topLevelOrigin)](BOOL authorized) {
> 
> I think it’s a bad pattern when we pass a pointer twice, once that we use
> and other for lifetime checking. In case like this, can we *not* capture
> this, please? Minimizes the chance we use it wrong. I feel the same way
> about capturing both "this" and "protectedThis".

Will change it. I agree for weakThis, since 'this' is unsafer than using weakThis.

Not sure about protectedThis though.
This is no different from using 'this' in a method where this is a protectedThis before.
Comment 8 youenn fablet 2020-09-28 02:27:26 PDT
> > > Source/WebKit/ChangeLog:8
> > > +        The completion handler to [AVCaptureDeviceClass requestAccessForMediaType:] may sometimes be called in a background thread on iOS.
> > 
> > Can we make a test for this that will fail on iOS?
> 
> We are only calling this code path in case the authorisation is
> undetermined, which will most probably trigger a prompt.
> We usually avoid doing so as we cannot handle prompts easily.
> That said, it seems we could investigate using some additional tools.
> I filed rdar://problem/69687122.

Or we could add some testing API to force explicit request.
Comment 9 youenn fablet 2020-09-28 02:28:30 PDT
Created attachment 409875 [details]
Patch for landing
Comment 10 EWS 2020-09-28 07:34:51 PDT
Committed r267698: <https://trac.webkit.org/changeset/267698>

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