Bug 217104 - Prevent media capture unless the application has correct data for system permission prompt
Summary: Prevent media capture unless the application has correct data for system perm...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Eric Carlson
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-09-29 13:43 PDT by Eric Carlson
Modified: 2020-10-01 11:28 PDT (History)
8 users (show)

See Also:


Attachments
Patch (19.99 KB, patch)
2020-09-29 14:19 PDT, Eric Carlson
no flags Details | Formatted Diff | Diff
Patch for landing (19.69 KB, patch)
2020-09-29 17:31 PDT, Eric Carlson
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Carlson 2020-09-29 13:43:33 PDT
The system will terminate an app that doesn't have the appropriate key(s) in its Info.plist when it tries to use a capture device, so don't allow that to happen.
Comment 1 Radar WebKit Bug Importer 2020-09-29 13:43:43 PDT
<rdar://problem/69761929>
Comment 2 Eric Carlson 2020-09-29 14:19:45 PDT
Created attachment 410050 [details]
Patch
Comment 3 Darin Adler 2020-09-29 16:13:11 PDT
Comment on attachment 410050 [details]
Patch

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

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:988
> +    AVAuthorizationStatus microphoneAuthorizationStatus = usingMockCaptureDevices || !requiresAudioCapture ? AVAuthorizationStatusAuthorized : [PAL::getAVCaptureDeviceClass() authorizationStatusForMediaType:AVMediaTypeAudio];

auto

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:994
> +    AVAuthorizationStatus cameraAuthorizationStatus = usingMockCaptureDevices || !requiresVideoCapture ? AVAuthorizationStatusAuthorized : [PAL::getAVCaptureDeviceClass() authorizationStatusForMediaType:AVMediaTypeVideo];

auto

> Source/WebKit/UIProcess/Cocoa/UserMediaPermissionRequestManagerProxy.mm:41
> +    static std::once_flag onceFlag;
> +    static bool validUsageString;
> +    std::call_once(onceFlag, [] {
> +        NSString *usageString = NSBundle.mainBundle.infoDictionary[@"NSMicrophoneUsageDescription"];
> +        validUsageString = usageString.length;
> +    });
> +
> +    return validUsageString;

Does this need to be thread-safe? If not, it can be a two-liner:

    static bool isPermiitted = NSBundle.mainBundle.infoDictionary[@"NSMicrophoneUsageDescription"].length;
    return isPermitted;

> Source/WebKit/UIProcess/Cocoa/UserMediaPermissionRequestManagerProxy.mm:57
> +    static std::once_flag onceFlag;
> +    static bool validUsageString;
> +    std::call_once(onceFlag, [] {
> +        NSString *usageString = NSBundle.mainBundle.infoDictionary[@"NSCameraUsageDescription"];
> +        validUsageString = usageString.length;
> +    });
> +
> +    return validUsageString;

Ditto.
Comment 4 Eric Carlson 2020-09-29 17:21:13 PDT
Comment on attachment 410050 [details]
Patch

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

Thanks for the review!

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:988
>> +    AVAuthorizationStatus microphoneAuthorizationStatus = usingMockCaptureDevices || !requiresAudioCapture ? AVAuthorizationStatusAuthorized : [PAL::getAVCaptureDeviceClass() authorizationStatusForMediaType:AVMediaTypeAudio];
> 
> auto

Why do I have so much trouble remembering to use `auto`?

Fixed.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:994
>> +    AVAuthorizationStatus cameraAuthorizationStatus = usingMockCaptureDevices || !requiresVideoCapture ? AVAuthorizationStatusAuthorized : [PAL::getAVCaptureDeviceClass() authorizationStatusForMediaType:AVMediaTypeVideo];
> 
> auto

Fixed.

>> Source/WebKit/UIProcess/Cocoa/UserMediaPermissionRequestManagerProxy.mm:41
>> +    return validUsageString;
> 
> Does this need to be thread-safe? If not, it can be a two-liner:
> 
>     static bool isPermiitted = NSBundle.mainBundle.infoDictionary[@"NSMicrophoneUsageDescription"].length;
>     return isPermitted;

Good idea, changed.

>> Source/WebKit/UIProcess/Cocoa/UserMediaPermissionRequestManagerProxy.mm:57
>> +    return validUsageString;
> 
> Ditto.

Ditto.
Comment 5 Eric Carlson 2020-09-29 17:31:16 PDT
Created attachment 410072 [details]
Patch for landing
Comment 6 EWS 2020-10-01 11:28:22 PDT
Committed r267844: <https://trac.webkit.org/changeset/267844>

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