-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mac): expose getDisplayMedia() permission decision handler #1196
Open
pewsheen
wants to merge
9
commits into
dev
Choose a base branch
from
fix/media-perm-request-14-0
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−15
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
90a5447
fix(mac): unsuppressing media permission request only for macOS 14.0
pewsheen d1c82e5
wip
FabianLars b43d31a
wip: possible fix
pewsheen dc445ef
poc: expose display capture decision handler
pewsheen 6ac68fb
move to a module
pewsheen 092a152
organize example
pewsheen 519f55b
Merge branch 'dev' into fix/media-perm-request-14-0
pewsheen be78086
add decision handler setter
pewsheen 34bb3cf
fix simple example
pewsheen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wry": patch | ||
--- | ||
|
||
On macOS 14.0, unsuppressing the media permission request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
use crate::operating_system_version; | ||
use cocoa::base::id; | ||
use objc::{ | ||
declare::ClassDecl, | ||
runtime::{Object, Sel}, | ||
}; | ||
use std::ffi::c_void; | ||
|
||
#[repr(isize)] | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub enum WKMediaCaptureType { | ||
Camera = 0, | ||
Microphone, | ||
CameraAndMicrophone, | ||
} | ||
|
||
impl From<isize> for WKMediaCaptureType { | ||
fn from(value: isize) -> Self { | ||
match value { | ||
0 => WKMediaCaptureType::Camera, | ||
1 => WKMediaCaptureType::Microphone, | ||
2 => WKMediaCaptureType::CameraAndMicrophone, | ||
_ => panic!("Invalid WKMediaCaptureType value"), | ||
} | ||
} | ||
} | ||
|
||
#[repr(isize)] | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub enum WKDisplayCapturePermissionDecision { | ||
Deny = 0, | ||
ScreenPrompt, | ||
WindowPrompt, | ||
} | ||
|
||
impl From<isize> for WKDisplayCapturePermissionDecision { | ||
fn from(value: isize) -> Self { | ||
match value { | ||
0 => WKDisplayCapturePermissionDecision::Deny, | ||
1 => WKDisplayCapturePermissionDecision::ScreenPrompt, | ||
2 => WKDisplayCapturePermissionDecision::WindowPrompt, | ||
_ => panic!("Invalid WKDisplayCapturePermissionDecision value"), | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn declare_decision_handler(ctl: &mut ClassDecl) { | ||
#[cfg(target_os = "macos")] | ||
if operating_system_version().0 >= 13 { | ||
unsafe { | ||
ctl.add_ivar::<*mut c_void>("display_capture_decision_handler"); | ||
ctl.add_method(sel!(_webView:requestDisplayCapturePermissionForOrigin:initiatedByFrame:withSystemAudio:decisionHandler:), | ||
request_display_capture_permission as extern "C" fn(&Object, Sel, id, id, id, isize, id),); | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn set_decision_handler( | ||
webview: id, | ||
handler: Option<Box<dyn Fn(WKMediaCaptureType) -> WKDisplayCapturePermissionDecision + 'static>>, | ||
) { | ||
#[cfg(target_os = "macos")] | ||
if operating_system_version().0 >= 13 { | ||
unsafe { | ||
if let Some(handler) = handler { | ||
drop_decision_hanlder(webview); | ||
|
||
let ui_delegate: id = msg_send![webview, UIDelegate]; | ||
let handler = Box::into_raw(Box::new(handler)); | ||
(*ui_delegate).set_ivar( | ||
"display_capture_decision_handler", | ||
handler as *mut _ as *mut c_void, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn drop_decision_hanlder(webview: *mut Object) { | ||
unsafe { | ||
let ui_delegate: id = msg_send![webview, UIDelegate]; | ||
let function = (*ui_delegate).get_ivar::<*mut c_void>("display_capture_decision_handler"); | ||
if !function.is_null() { | ||
let function = *function | ||
as *mut Box<dyn for<'s> Fn(WKMediaCaptureType) -> WKDisplayCapturePermissionDecision>; | ||
drop(Box::from_raw(function)); | ||
} | ||
} | ||
} | ||
|
||
extern "C" fn request_display_capture_permission( | ||
this: &Object, | ||
_: Sel, | ||
_webview: id, | ||
_origin: id, | ||
_frame: id, | ||
capture_type: isize, | ||
decision_handler: id, | ||
) { | ||
unsafe { | ||
let decision_handler = | ||
decision_handler as *mut block::Block<(WKDisplayCapturePermissionDecision,), c_void>; | ||
|
||
let function = this.get_ivar::<*mut c_void>("display_capture_decision_handler"); | ||
if !function.is_null() { | ||
let function = *function | ||
as *mut Box<dyn for<'s> Fn(WKMediaCaptureType) -> WKDisplayCapturePermissionDecision>; | ||
|
||
let decision = (*function)(WKMediaCaptureType::from(capture_type)); | ||
(*decision_handler).call((decision,)); | ||
} else { | ||
(*decision_handler).call((WKDisplayCapturePermissionDecision::Deny,)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the usages of this function have the same typo)