@@ -90,6 +90,7 @@ impl RuntimeAuthority {
90
90
plugin : & str ,
91
91
command_name : & str ,
92
92
window : & str ,
93
+ webview : & str ,
93
94
origin : & Origin ,
94
95
) -> String {
95
96
fn print_references ( resolved : & ResolvedCommand ) -> String {
@@ -147,10 +148,16 @@ impl RuntimeAuthority {
147
148
. iter ( )
148
149
. find ( |( cmd, _) | origin. matches ( & cmd. context ) )
149
150
{
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
+ {
151
154
"allowed" . to_string ( )
152
155
} 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
+ )
154
161
}
155
162
} else {
156
163
let permission_error_detail = if let Some ( manifest) = self . acl . get ( plugin) {
@@ -217,6 +224,7 @@ impl RuntimeAuthority {
217
224
& self ,
218
225
command : & str ,
219
226
window : & str ,
227
+ webview : & str ,
220
228
origin : & Origin ,
221
229
) -> Option < & ResolvedCommand > {
222
230
if self
@@ -231,7 +239,10 @@ impl RuntimeAuthority {
231
239
. iter ( )
232
240
. find ( |( cmd, _) | cmd. name == command && origin. matches ( & cmd. context ) )
233
241
. 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
+ } )
235
246
}
236
247
}
237
248
}
@@ -467,6 +478,7 @@ mod tests {
467
478
context : ExecutionContext :: Local ,
468
479
} ;
469
480
let window = "main-*" ;
481
+ let webview = "other-*" ;
470
482
471
483
let resolved_cmd = ResolvedCommand {
472
484
windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -485,6 +497,41 @@ mod tests {
485
497
authority. resolve_access(
486
498
& command. name,
487
499
& 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" ) ,
488
535
& Origin :: Local
489
536
) ,
490
537
Some ( & resolved_cmd)
@@ -501,6 +548,7 @@ mod tests {
501
548
} ,
502
549
} ;
503
550
let window = "main" ;
551
+ let webview = "main" ;
504
552
505
553
let resolved_cmd = ResolvedCommand {
506
554
windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -520,6 +568,7 @@ mod tests {
520
568
authority. resolve_access(
521
569
& command. name,
522
570
window,
571
+ webview,
523
572
& Origin :: Remote {
524
573
domain: domain. into( )
525
574
}
@@ -538,6 +587,7 @@ mod tests {
538
587
} ,
539
588
} ;
540
589
let window = "main" ;
590
+ let webview = "main" ;
541
591
542
592
let resolved_cmd = ResolvedCommand {
543
593
windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -557,6 +607,7 @@ mod tests {
557
607
authority. resolve_access(
558
608
& command. name,
559
609
window,
610
+ webview,
560
611
& Origin :: Remote {
561
612
domain: domain. replace( '*' , "studio" )
562
613
}
@@ -572,6 +623,7 @@ mod tests {
572
623
context : ExecutionContext :: Local ,
573
624
} ;
574
625
let window = "main" ;
626
+ let webview = "main" ;
575
627
576
628
let resolved_cmd = ResolvedCommand {
577
629
windows : vec ! [ Pattern :: new( window) . unwrap( ) ] ,
@@ -591,6 +643,7 @@ mod tests {
591
643
. resolve_access(
592
644
& command. name,
593
645
window,
646
+ webview,
594
647
& Origin :: Remote {
595
648
domain: "tauri.app" . into( )
596
649
}
@@ -605,6 +658,7 @@ mod tests {
605
658
context : ExecutionContext :: Local ,
606
659
} ;
607
660
let window = "main" ;
661
+ let webview = "main" ;
608
662
let windows = vec ! [ Pattern :: new( window) . unwrap( ) ] ;
609
663
let allowed_commands = [ (
610
664
command. clone ( ) ,
@@ -632,7 +686,7 @@ mod tests {
632
686
} ) ;
633
687
634
688
assert ! ( authority
635
- . resolve_access( & command. name, window, & Origin :: Local )
689
+ . resolve_access( & command. name, window, webview , & Origin :: Local )
636
690
. is_none( ) ) ;
637
691
}
638
692
}
0 commit comments