permission.go RawHistoryFolder
1package entity
2
3// DomainTimestamp represents a Unix timestamp in seconds.
4// This is a domain-owned type to avoid importing time in the domain layer.
5
6// PermissionType represents the type of permission being requested.
7type PermissionType string
8
9const (
10 // PermissionTypeMicrophone represents microphone access permission.
11 PermissionTypeMicrophone PermissionType = "microphone"
12
13 // PermissionTypeCamera represents camera access permission.
14 PermissionTypeCamera PermissionType = "camera"
15
16 // PermissionTypeDisplay represents screen sharing/display capture permission.
17 PermissionTypeDisplay PermissionType = "display"
18
19 // PermissionTypeDeviceInfo represents device enumeration permission.
20 PermissionTypeDeviceInfo PermissionType = "device_info"
21
22 // PermissionTypeClipboard represents clipboard access permission.
23 PermissionTypeClipboard PermissionType = "clipboard"
24
25 // PermissionTypeNotification represents notification permission.
26 PermissionTypeNotification PermissionType = "notification"
27
28 // PermissionTypeGeolocation represents geolocation permission.
29 PermissionTypeGeolocation PermissionType = "geolocation"
30
31 // PermissionTypePointerLock represents pointer lock permission.
32 PermissionTypePointerLock PermissionType = "pointer_lock"
33
34 // PermissionTypeMediaKeySystem represents DRM/media key system permission.
35 PermissionTypeMediaKeySystem PermissionType = "media_key_system"
36
37 // PermissionTypeWebsiteDataAccess represents 3rd party cookie/data access permission.
38 PermissionTypeWebsiteDataAccess PermissionType = "website_data_access"
39)
40
41// PermissionDecision represents the user's decision for a permission.
42type PermissionDecision string
43
44const (
45 // PermissionGranted means the permission was allowed.
46 PermissionGranted PermissionDecision = "granted"
47
48 // PermissionDenied means the permission was denied.
49 PermissionDenied PermissionDecision = "denied"
50
51 // PermissionPrompt means no decision has been made yet (default state).
52 PermissionPrompt PermissionDecision = "prompt"
53)
54
55// PermissionRecord stores a permission decision for a specific origin and type.
56type PermissionRecord struct {
57 Origin string // The origin (domain) this permission applies to
58 Type PermissionType // The type of permission
59 Decision PermissionDecision // The decision: granted, denied, or prompt
60 UpdatedAt int64 // Unix timestamp in seconds when this record was last updated
61}
62
63// IsGranted returns true if the permission is granted.
64func (p *PermissionRecord) IsGranted() bool {
65 return p.Decision == PermissionGranted
66}
67
68// IsDenied returns true if the permission is denied.
69func (p *PermissionRecord) IsDenied() bool {
70 return p.Decision == PermissionDenied
71}
72
73// PermissionSet represents multiple permission decisions for a single request.
74// This is used when handling combined permission requests (e.g., mic + camera).
75type PermissionSet struct {
76 Types []PermissionType
77 Decision PermissionDecision
78}
79
80// CanPersist returns true if this permission type can be persisted.
81// Per W3C spec, display capture permissions cannot be persisted.
82func CanPersist(permType PermissionType) bool {
83 switch permType {
84 case PermissionTypeDisplay:
85 return false // W3C forbids persisting display capture permissions
86 case PermissionTypeDeviceInfo, PermissionTypePointerLock:
87 return false // Auto-allowed, no need to persist
88 default:
89 return true
90 }
91}
92
93// IsAutoAllow returns true if this permission type should be auto-allowed.
94func IsAutoAllow(permType PermissionType) bool {
95 switch permType {
96 case PermissionTypeDisplay:
97 return true // Portal handles the UI
98 case PermissionTypeDeviceInfo:
99 return true // Low risk, just lists devices
100 case PermissionTypePointerLock:
101 return true // Low risk, default WebKit behavior
102 default:
103 return false
104 }
105}
106
107// PermissionTypesToStrings converts permission types to strings for logging.
108func PermissionTypesToStrings(types []PermissionType) []string {
109 result := make([]string, len(types))
110 for i, t := range types {
111 result[i] = string(t)
112 }
113 return result
114}