@@ -16,11 +16,11 @@ pub use jni::{
1616pub use ndk;
1717
1818use super :: {
19- ASSET_LOADER_DOMAIN , EVAL_CALLBACKS , IPC , ON_LOAD_HANDLER , REQUEST_HANDLER , TITLE_CHANGE_HANDLER ,
20- URL_LOADING_OVERRIDE , WITH_ASSET_LOADER ,
19+ ASSET_LOADER_DOMAIN , EVAL_CALLBACKS , IPC , ON_LOAD_HANDLER , PERMISSION_HANDLER , REQUEST_HANDLER ,
20+ TITLE_CHANGE_HANDLER , URL_LOADING_OVERRIDE , WITH_ASSET_LOADER ,
2121} ;
2222
23- use crate :: PageLoadEvent ;
23+ use crate :: { PageLoadEvent , PermissionKind , PermissionResponse } ;
2424
2525#[ macro_export]
2626macro_rules! android_binding {
@@ -97,6 +97,14 @@ macro_rules! android_binding {
9797 handleReceivedTitle,
9898 [ JObject , JString ] ,
9999 ) ;
100+ android_fn!(
101+ $domain,
102+ $package,
103+ RustWebChromeClient ,
104+ onPermissionRequestNative,
105+ [ jni:: objects:: JObjectArray ] ,
106+ jint
107+ ) ;
100108 } } ;
101109}
102110
@@ -413,3 +421,51 @@ pub unsafe fn onPageLoaded(mut env: JNIEnv, _: JClass, url: JString) {
413421 }
414422 }
415423}
424+
425+ pub unsafe fn onPermissionRequestNative (
426+ mut env : JNIEnv ,
427+ _: JClass ,
428+ resources : jni:: objects:: JObjectArray ,
429+ ) -> jint {
430+ let mut allowed = false ;
431+ let mut denied = false ;
432+ let mut prompt = false ;
433+
434+ if let Ok ( size) = env. get_array_length ( & resources) {
435+ for i in 0 ..size {
436+ if let Ok ( resource) = env. get_object_array_element ( & resources, i) {
437+ if let Ok ( resource_str) = env. get_string ( & resource. into ( ) ) {
438+ let resource_str = resource_str. to_string_lossy ( ) ;
439+
440+ let kind = match resource_str. as_ref ( ) {
441+ "android.webkit.resource.AUDIO_CAPTURE" => PermissionKind :: Microphone ,
442+ "android.webkit.resource.VIDEO_CAPTURE" => PermissionKind :: Camera ,
443+ "android.webkit.resource.PROTECTED_MEDIA_ID" => PermissionKind :: MediaKeySystemAccess ,
444+ "android.webkit.resource.MIDI_SYSEX" => PermissionKind :: Midi ,
445+ _ => PermissionKind :: Other ,
446+ } ;
447+
448+ if let Some ( handler) = & * PERMISSION_HANDLER . lock ( ) . unwrap ( ) {
449+ match ( handler. handler ) ( kind) {
450+ PermissionResponse :: Allow => allowed = true ,
451+ PermissionResponse :: Deny => denied = true ,
452+ PermissionResponse :: Prompt => prompt = true ,
453+ PermissionResponse :: Default => { }
454+ }
455+ }
456+ }
457+ }
458+ }
459+ }
460+
461+ // Consolidated decision logic
462+ if denied {
463+ 1 // Deny
464+ } else if allowed {
465+ 0 // Allow
466+ } else if prompt {
467+ 3 // Prompt
468+ } else {
469+ 2 // Default
470+ }
471+ }
0 commit comments