Changeset 267698 in webkit
- Timestamp:
- Sep 28, 2020, 7:34:46 AM (6 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 3 edited
-
ChangeLog (modified) (1 diff)
-
UIProcess/Cocoa/UIDelegate.h (modified) (1 diff)
-
UIProcess/Cocoa/UIDelegate.mm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r267691 r267698 1 2020-09-28 Youenn Fablet <youenn@apple.com> 2 3 Make sure our calls to AVCaptureDevice requestAccessForMediaType do processing on the main thread 4 https://bugs.webkit.org/show_bug.cgi?id=216974 5 6 Reviewed by Darin Adler. 7 8 The completion handler to [AVCaptureDeviceClass requestAccessForMediaType:] may sometimes be called in a background thread on iOS. 9 Make sure to hop to the main thread if that is the case. 10 Also make sure to ref/weakref lambda captured variables. 11 12 * UIProcess/Cocoa/UIDelegate.h: 13 * UIProcess/Cocoa/UIDelegate.mm: 14 (WebKit::requestAccessForMediaType): 15 (WebKit::UIDelegate::UIClient::decidePolicyForUserMediaPermissionRequest): 16 1 17 2020-09-27 Lauro Moura <lmoura@igalia.com> 2 18 -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h
r267414 r267698 77 77 #endif 78 78 79 class UIClient : public API::UIClient {79 class UIClient : public API::UIClient, public CanMakeWeakPtr<UIClient> { 80 80 public: 81 81 explicit UIClient(UIDelegate&); -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
r267568 r267698 940 940 [delegate _webView:&webView requestUserMediaAuthorizationForDevices:devices url:requestFrameURL mainFrameURL:mainFrameURL decisionHandler:decisionHandler.get()]; 941 941 } 942 943 static void requestAccessForMediaType(CompletionHandler<void(BOOL authorized)>&& completionHandler, AVMediaType type) 944 { 945 auto decisionHandler = makeBlockPtr([completionHandler = WTFMove(completionHandler)](BOOL authorized) mutable { 946 if (!isMainThread()) { 947 callOnMainThread([completionHandler = WTFMove(completionHandler), authorized]() mutable { 948 completionHandler(authorized); 949 }); 950 return; 951 } 952 completionHandler(authorized); 953 }); 954 [PAL::getAVCaptureDeviceClass() requestAccessForMediaType:type completionHandler:decisionHandler.get()]; 955 } 942 956 #endif 943 957 … … 960 974 961 975 bool usingMockCaptureDevices = page.preferences().mockCaptureDevicesEnabled(); 962 auto requestCameraAuthorization = makeBlockPtr([this, &frame, protectedRequest = makeRef(request), webView = RetainPtr<WKWebView>(m_uiDelegate.m_webView), topLevelOrigin = makeRef(topLevelOrigin), usingMockCaptureDevices]() mutable { 963 976 auto requestCameraAuthorization = [weakThis = makeWeakPtr(this), frame = makeRef(frame), protectedRequest = makeRef(request), webView = RetainPtr<WKWebView>(m_uiDelegate.m_webView), topLevelOrigin = makeRef(topLevelOrigin), usingMockCaptureDevices]() mutable { 977 if (!weakThis) { 978 protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied); 979 return; 980 } 964 981 if (!protectedRequest->requiresVideoCapture()) { 965 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>) m_uiDelegate.m_delegate.get(), *webView.get());982 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)weakThis->m_uiDelegate.m_delegate.get(), *webView.get()); 966 983 return; 967 984 } … … 969 986 switch (cameraAuthorizationStatus) { 970 987 case AVAuthorizationStatusAuthorized: 971 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>) m_uiDelegate.m_delegate.get(), *webView.get());988 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)weakThis->m_uiDelegate.m_delegate.get(), *webView.get()); 972 989 break; 973 990 case AVAuthorizationStatusDenied: … … 976 993 return; 977 994 case AVAuthorizationStatusNotDetermined: 978 auto decisionHandler = makeBlockPtr([this, &frame, protectedRequest = makeRef(protectedRequest.get()), webView = RetainPtr<WKWebView>(m_uiDelegate.m_webView), topLevelOrigin = WTFMove(topLevelOrigin)](BOOL authorized) {979 if (!authorized ) {995 auto completionHandler = [weakThis = WTFMove(weakThis), frame = WTFMove(frame), protectedRequest = WTFMove(protectedRequest), webView = WTFMove(webView), topLevelOrigin = WTFMove(topLevelOrigin)](BOOL authorized) { 996 if (!authorized || !weakThis) { 980 997 protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied); 981 998 return; 982 999 } 983 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)m_uiDelegate.m_delegate.get(), *webView.get()); 984 }); 985 986 [PAL::getAVCaptureDeviceClass() requestAccessForMediaType:AVMediaTypeVideo completionHandler:decisionHandler.get()]; 1000 requestUserMediaAuthorizationForFrame(frame, topLevelOrigin, protectedRequest, (id <WKUIDelegatePrivate>)weakThis->m_uiDelegate.m_delegate.get(), *webView.get()); 1001 }; 1002 requestAccessForMediaType(WTFMove(completionHandler), AVMediaTypeVideo); 987 1003 break; 988 1004 } 989 } );1005 }; 990 1006 991 1007 if (requiresAudioCapture) { … … 1000 1016 return; 1001 1017 case AVAuthorizationStatusNotDetermined: 1002 auto decisionHandler = makeBlockPtr([protectedRequest = makeRef(request), requestCameraAuthorization](BOOL authorized){1018 auto completionHandler = [protectedRequest = makeRef(request), requestCameraAuthorization = WTFMove(requestCameraAuthorization)](BOOL authorized) mutable { 1003 1019 if (!authorized) { 1004 1020 protectedRequest->deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied); … … 1006 1022 } 1007 1023 requestCameraAuthorization(); 1008 }); 1009 1010 [PAL::getAVCaptureDeviceClass() requestAccessForMediaType:AVMediaTypeAudio completionHandler:decisionHandler.get()]; 1024 }; 1025 requestAccessForMediaType(WTFMove(completionHandler), AVMediaTypeVideo); 1011 1026 break; 1012 1027 } 1013 } else 1014 requestCameraAuthorization(); 1028 return; 1029 } 1030 requestCameraAuthorization(); 1015 1031 #endif 1016 1032 }
Note:
See TracChangeset
for help on using the changeset viewer.