fix(cef): extract permission type conversion to satisfy funlen
- commit
- ef83d2ae38abd2d9244e9b3a656e046f820feaff
- author
- brice · · 2026-10-03 06:22 UTC
- committer
- brice · · 2026-10-03 07:50 UTC
- parent
- 664e13e
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +30 -25
M internal/ui/coordinator/content/callbacks.go +29 -22
| @@ -203,28 +203,7 @@ func (c *Coordinator) handlePermissionRequest( | |||
| 203 | 203 | ) bool { | |
| 204 | 204 | log := logging.FromContext(ctx) | |
| 205 | 205 | ||
| 206 | - | // Convert string permission types to entity types | |
| 207 | - | entityTypes := make([]entity.PermissionType, 0, len(permTypes)) | |
| 208 | - | for _, pt := range permTypes { | |
| 209 | - | switch pt { | |
| 210 | - | case "microphone": | |
| 211 | - | entityTypes = append(entityTypes, entity.PermissionTypeMicrophone) | |
| 212 | - | case "camera": | |
| 213 | - | entityTypes = append(entityTypes, entity.PermissionTypeCamera) | |
| 214 | - | case "display": | |
| 215 | - | entityTypes = append(entityTypes, entity.PermissionTypeDisplay) | |
| 216 | - | case "notification": | |
| 217 | - | entityTypes = append(entityTypes, entity.PermissionTypeNotification) | |
| 218 | - | case "geolocation": | |
| 219 | - | entityTypes = append(entityTypes, entity.PermissionTypeGeolocation) | |
| 220 | - | case "device_info": | |
| 221 | - | entityTypes = append(entityTypes, entity.PermissionTypeDeviceInfo) | |
| 222 | - | case "website_data_access": | |
| 223 | - | entityTypes = append(entityTypes, entity.PermissionTypeWebsiteDataAccess) | |
| 224 | - | default: | |
| 225 | - | log.Warn().Str("type", pt).Msg("unknown permission type, skipping") | |
| 226 | - | } | |
| 227 | - | } | |
| 206 | + | entityTypes := permissionTypesFromStrings(ctx, permTypes) | |
| 228 | 207 | ||
| 229 | 208 | if len(entityTypes) == 0 { | |
| 230 | 209 | log.Warn().Str("origin", origin).Msg("permission request with no valid types, denying") | |
| @@ -285,6 +264,34 @@ func (c *Coordinator) handlePermissionRequest( | |||
| 285 | 264 | return true | |
| 286 | 265 | } | |
| 287 | 266 | ||
| 267 | + | // permissionTypesFromStrings converts engine permission type strings to entity | |
| 268 | + | // types, skipping unknown ones. | |
| 269 | + | func permissionTypesFromStrings(ctx context.Context, permTypes []string) []entity.PermissionType { | |
| 270 | + | log := logging.FromContext(ctx) | |
| 271 | + | entityTypes := make([]entity.PermissionType, 0, len(permTypes)) | |
| 272 | + | for _, pt := range permTypes { | |
| 273 | + | switch pt { | |
| 274 | + | case "microphone": | |
| 275 | + | entityTypes = append(entityTypes, entity.PermissionTypeMicrophone) | |
| 276 | + | case "camera": | |
| 277 | + | entityTypes = append(entityTypes, entity.PermissionTypeCamera) | |
| 278 | + | case "display": | |
| 279 | + | entityTypes = append(entityTypes, entity.PermissionTypeDisplay) | |
| 280 | + | case "notification": | |
| 281 | + | entityTypes = append(entityTypes, entity.PermissionTypeNotification) | |
| 282 | + | case "geolocation": | |
| 283 | + | entityTypes = append(entityTypes, entity.PermissionTypeGeolocation) | |
| 284 | + | case "device_info": | |
| 285 | + | entityTypes = append(entityTypes, entity.PermissionTypeDeviceInfo) | |
| 286 | + | case "website_data_access": | |
| 287 | + | entityTypes = append(entityTypes, entity.PermissionTypeWebsiteDataAccess) | |
| 288 | + | default: | |
| 289 | + | log.Warn().Str("type", pt).Msg("unknown permission type, skipping") | |
| 290 | + | } | |
| 291 | + | } | |
| 292 | + | return entityTypes | |
| 293 | + | } | |
| 294 | + | ||
| 288 | 295 | func filterWebRTCPermissionTypes(types []entity.PermissionType) []entity.PermissionType { | |
| 289 | 296 | filtered := make([]entity.PermissionType, 0, len(types)) | |
| 290 | 297 | for _, permType := range types { | |
| @@ -203,28 +203,7 @@ func (c *Coordinator) handlePermissionRequest( | |||||
| 203 | ) bool { | 203 | ) bool { | ||
| 204 | log := logging.FromContext(ctx) | 204 | log := logging.FromContext(ctx) | ||
| 205 | 205 | ||||
| 206 | - | // Convert string permission types to entity types | 206 | + | entityTypes := permissionTypesFromStrings(ctx, permTypes) |
| 207 | - | entityTypes := make([]entity.PermissionType, 0, len(permTypes)) | |||
| 208 | - | for _, pt := range permTypes { | |||
| 209 | - | switch pt { | |||
| 210 | - | case "microphone": | |||
| 211 | - | entityTypes = append(entityTypes, entity.PermissionTypeMicrophone) | |||
| 212 | - | case "camera": | |||
| 213 | - | entityTypes = append(entityTypes, entity.PermissionTypeCamera) | |||
| 214 | - | case "display": | |||
| 215 | - | entityTypes = append(entityTypes, entity.PermissionTypeDisplay) | |||
| 216 | - | case "notification": | |||
| 217 | - | entityTypes = append(entityTypes, entity.PermissionTypeNotification) | |||
| 218 | - | case "geolocation": | |||
| 219 | - | entityTypes = append(entityTypes, entity.PermissionTypeGeolocation) | |||
| 220 | - | case "device_info": | |||
| 221 | - | entityTypes = append(entityTypes, entity.PermissionTypeDeviceInfo) | |||
| 222 | - | case "website_data_access": | |||
| 223 | - | entityTypes = append(entityTypes, entity.PermissionTypeWebsiteDataAccess) | |||
| 224 | - | default: | |||
| 225 | - | log.Warn().Str("type", pt).Msg("unknown permission type, skipping") | |||
| 226 | - | } | |||
| 227 | - | } | |||
| 228 | 207 | ||||
| 229 | if len(entityTypes) == 0 { | 208 | if len(entityTypes) == 0 { | ||
| 230 | log.Warn().Str("origin", origin).Msg("permission request with no valid types, denying") | 209 | log.Warn().Str("origin", origin).Msg("permission request with no valid types, denying") | ||
| @@ -285,6 +264,34 @@ func (c *Coordinator) handlePermissionRequest( | |||||
| 285 | return true | 264 | return true | ||
| 286 | } | 265 | } | ||
| 287 | 266 | ||||
| 267 | + | // permissionTypesFromStrings converts engine permission type strings to entity | |||
| 268 | + | // types, skipping unknown ones. | |||
| 269 | + | func permissionTypesFromStrings(ctx context.Context, permTypes []string) []entity.PermissionType { | |||
| 270 | + | log := logging.FromContext(ctx) | |||
| 271 | + | entityTypes := make([]entity.PermissionType, 0, len(permTypes)) | |||
| 272 | + | for _, pt := range permTypes { | |||
| 273 | + | switch pt { | |||
| 274 | + | case "microphone": | |||
| 275 | + | entityTypes = append(entityTypes, entity.PermissionTypeMicrophone) | |||
| 276 | + | case "camera": | |||
| 277 | + | entityTypes = append(entityTypes, entity.PermissionTypeCamera) | |||
| 278 | + | case "display": | |||
| 279 | + | entityTypes = append(entityTypes, entity.PermissionTypeDisplay) | |||
| 280 | + | case "notification": | |||
| 281 | + | entityTypes = append(entityTypes, entity.PermissionTypeNotification) | |||
| 282 | + | case "geolocation": | |||
| 283 | + | entityTypes = append(entityTypes, entity.PermissionTypeGeolocation) | |||
| 284 | + | case "device_info": | |||
| 285 | + | entityTypes = append(entityTypes, entity.PermissionTypeDeviceInfo) | |||
| 286 | + | case "website_data_access": | |||
| 287 | + | entityTypes = append(entityTypes, entity.PermissionTypeWebsiteDataAccess) | |||
| 288 | + | default: | |||
| 289 | + | log.Warn().Str("type", pt).Msg("unknown permission type, skipping") | |||
| 290 | + | } | |||
| 291 | + | } | |||
| 292 | + | return entityTypes | |||
| 293 | + | } | |||
| 294 | + | ||||
| 288 | func filterWebRTCPermissionTypes(types []entity.PermissionType) []entity.PermissionType { | 295 | func filterWebRTCPermissionTypes(types []entity.PermissionType) []entity.PermissionType { | ||
| 289 | filtered := make([]entity.PermissionType, 0, len(types)) | 296 | filtered := make([]entity.PermissionType, 0, len(types)) | ||
| 290 | for _, permType := range types { | 297 | for _, permType := range types { | ||
M internal/ui/coordinator/content/permission_prompt_test.go +1 -3
| @@ -19,9 +19,7 @@ func TestHandlePermissionRequest_BindsDialogBeforeUseCaseForNonWebRTCRequest(t * | |||
| 19 | 19 | permRepo := portmocks.NewMockPermissionRepository(t) | |
| 20 | 20 | dialog := portmocks.NewMockPermissionDialogPresenter(t) | |
| 21 | 21 | // The use case starts without a dialog presenter, like in production. | |
| 22 | - | uc := usecase.NewHandlePermissionUseCase(permRepo, nil, func(ctx context.Context) *zerolog.Logger { | |
| 23 | - | return zerolog.Ctx(ctx) | |
| 24 | - | }) | |
| 22 | + | uc := usecase.NewHandlePermissionUseCase(permRepo, nil, zerolog.Ctx) | |
| 25 | 23 | ||
| 26 | 24 | permRepo.EXPECT().Get(mock.Anything, "https://maps.example.com", entity.PermissionTypeGeolocation). | |
| 27 | 25 | Return(nil, nil) | |
| @@ -19,9 +19,7 @@ func TestHandlePermissionRequest_BindsDialogBeforeUseCaseForNonWebRTCRequest(t * | |||||
| 19 | permRepo := portmocks.NewMockPermissionRepository(t) | 19 | permRepo := portmocks.NewMockPermissionRepository(t) | ||
| 20 | dialog := portmocks.NewMockPermissionDialogPresenter(t) | 20 | dialog := portmocks.NewMockPermissionDialogPresenter(t) | ||
| 21 | // The use case starts without a dialog presenter, like in production. | 21 | // The use case starts without a dialog presenter, like in production. | ||
| 22 | - | uc := usecase.NewHandlePermissionUseCase(permRepo, nil, func(ctx context.Context) *zerolog.Logger { | 22 | + | uc := usecase.NewHandlePermissionUseCase(permRepo, nil, zerolog.Ctx) |
| 23 | - | return zerolog.Ctx(ctx) | |||
| 24 | - | }) | |||
| 25 | 23 | ||||
| 26 | permRepo.EXPECT().Get(mock.Anything, "https://maps.example.com", entity.PermissionTypeGeolocation). | 24 | permRepo.EXPECT().Get(mock.Anything, "https://maps.example.com", entity.PermissionTypeGeolocation). | ||
| 27 | Return(nil, nil) | 25 | Return(nil, nil) | ||