@@ -90,6 +90,7 @@ impl RuntimeAuthority {
9090 plugin : & str ,
9191 command_name : & str ,
9292 window : & str ,
93+ webview : & str ,
9394 origin : & Origin ,
9495 ) -> String {
9596 fn print_references ( resolved : & ResolvedCommand ) -> String {
@@ -147,10 +148,16 @@ impl RuntimeAuthority {
147148 . iter ( )
148149 . find ( |( cmd, _) | origin. matches ( & cmd. context ) )
149150 {
150- if resolved. windows . iter ( ) . any ( |w| w. matches ( window) ) {
151+ if resolved. webviews . iter ( ) . any ( |w| w. matches ( webview) )
152+ || resolved. windows . iter ( ) . any ( |w| w. matches ( window) )
153+ {
151154 "allowed" . to_string ( )
152155 } else {
153- format ! ( "{plugin}.{command_name} not allowed on window {window}, expected one of {}, referenced by {}" , resolved. windows. iter( ) . map( |w| w. as_str( ) ) . collect:: <Vec <_>>( ) . join( ", " ) , print_references( resolved) )
156+ format ! ( "{plugin}.{command_name} not allowed on window {window}, webview {webview}, allowed windows: {}, allowed webviews: {}, referenced by {}" ,
157+ resolved. windows. iter( ) . map( |w| w. as_str( ) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
158+ resolved. webviews. iter( ) . map( |w| w. as_str( ) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
159+ print_references( resolved)
160+ )
154161 }
155162 } else {
156163 let permission_error_detail = if let Some ( manifest) = self . acl . get ( plugin) {
@@ -217,6 +224,7 @@ impl RuntimeAuthority {
217224 & self ,
218225 command : & str ,
219226 window : & str ,
227+ webview : & str ,
220228 origin : & Origin ,
221229 ) -> Option < & ResolvedCommand > {
222230 if self
@@ -231,7 +239,10 @@ impl RuntimeAuthority {
231239 . iter ( )
232240 . find ( |( cmd, _) | cmd. name == command && origin. matches ( & cmd. context ) )
233241 . map ( |( _cmd, resolved) | resolved)
234- . filter ( |resolved| resolved. windows . iter ( ) . any ( |w| w. matches ( window) ) )
242+ . filter ( |resolved| {
243+ resolved. webviews . iter ( ) . any ( |w| w. matches ( webview) )
244+ || resolved. windows . iter ( ) . any ( |w| w. matches ( window) )
245+ } )
235246 }
236247 }
237248}
@@ -467,6 +478,7 @@ mod tests {
467478 context : ExecutionContext :: Local ,
468479 } ;
469480 let window = "main-*" ;
481+ let webview = "other-*" ;
470482
471483 let resolved_cmd = ResolvedCommand {
472484 windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -485,6 +497,41 @@ mod tests {
485497 authority. resolve_access(
486498 & command. name,
487499 & window. replace( '*' , "something" ) ,
500+ webview,
501+ & Origin :: Local
502+ ) ,
503+ Some ( & resolved_cmd)
504+ ) ;
505+ }
506+
507+ #[ test]
508+ fn webview_glob_pattern_matches ( ) {
509+ let command = CommandKey {
510+ name : "my-command" . into ( ) ,
511+ context : ExecutionContext :: Local ,
512+ } ;
513+ let window = "other-*" ;
514+ let webview = "main-*" ;
515+
516+ let resolved_cmd = ResolvedCommand {
517+ windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
518+ webviews : vec ! [ Pattern :: new( webview) . unwrap( ) ] ,
519+ ..Default :: default ( )
520+ } ;
521+ let allowed_commands = [ ( command. clone ( ) , resolved_cmd. clone ( ) ) ]
522+ . into_iter ( )
523+ . collect ( ) ;
524+
525+ let authority = RuntimeAuthority :: new ( Resolved {
526+ allowed_commands,
527+ ..Default :: default ( )
528+ } ) ;
529+
530+ assert_eq ! (
531+ authority. resolve_access(
532+ & command. name,
533+ window,
534+ & webview. replace( '*' , "something" ) ,
488535 & Origin :: Local
489536 ) ,
490537 Some ( & resolved_cmd)
@@ -501,6 +548,7 @@ mod tests {
501548 } ,
502549 } ;
503550 let window = "main" ;
551+ let webview = "main" ;
504552
505553 let resolved_cmd = ResolvedCommand {
506554 windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -520,6 +568,7 @@ mod tests {
520568 authority. resolve_access(
521569 & command. name,
522570 window,
571+ webview,
523572 & Origin :: Remote {
524573 domain: domain. into( )
525574 }
@@ -538,6 +587,7 @@ mod tests {
538587 } ,
539588 } ;
540589 let window = "main" ;
590+ let webview = "main" ;
541591
542592 let resolved_cmd = ResolvedCommand {
543593 windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -557,6 +607,7 @@ mod tests {
557607 authority. resolve_access(
558608 & command. name,
559609 window,
610+ webview,
560611 & Origin :: Remote {
561612 domain: domain. replace( '*' , "studio" )
562613 }
@@ -572,6 +623,7 @@ mod tests {
572623 context : ExecutionContext :: Local ,
573624 } ;
574625 let window = "main" ;
626+ let webview = "main" ;
575627
576628 let resolved_cmd = ResolvedCommand {
577629 windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -591,6 +643,7 @@ mod tests {
591643 . resolve_access(
592644 & command. name,
593645 window,
646+ webview,
594647 & Origin :: Remote {
595648 domain: "tauri.app" . into( )
596649 }
@@ -605,6 +658,7 @@ mod tests {
605658 context : ExecutionContext :: Local ,
606659 } ;
607660 let window = "main" ;
661+ let webview = "main" ;
608662 let windows = vec ! [ Pattern :: new( window) . unwrap( ) ] ;
609663 let allowed_commands = [ (
610664 command. clone ( ) ,
@@ -632,7 +686,7 @@ mod tests {
632686 } ) ;
633687
634688 assert ! ( authority
635- . resolve_access( & command. name, window, & Origin :: Local )
689+ . resolve_access( & command. name, window, webview , & Origin :: Local )
636690 . is_none( ) ) ;
637691 }
638692}
0 commit comments