Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion server/lib/chromiumflags/chromiumflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ func ReadOptionalFlagFile(path string) ([]string, error) {
// both lists Chromium disables it — disable wins over enable.
//
// Non-feature, non-extension flags from both base and runtime are combined with deduplication
// (first occurrence preserved).
// (first occurrence preserved), except the singleton WebRTC policy, whose last
// occurrence wins as it does in Chromium.
func MergeFlags(baseTokens, runtimeTokens []string) []string {
// Buckets
var (
Expand Down Expand Up @@ -265,9 +266,14 @@ func MergeFlags(baseTokens, runtimeTokens []string) []string {
combined := append(append([]string{}, baseNonExt...), runtimeNonExt...)
combined = append(combined, featureFlags...)
combined = append(combined, extFlags...)
var webRTCPolicy string
seen := make(map[string]struct{}, len(combined))
final := make([]string, 0, len(combined))
for _, tok := range combined {
if name, _, _ := strings.Cut(tok, "="); name == "--webrtc-ip-handling-policy" {
webRTCPolicy = tok
continue
}
if tok == "" {
continue
}
Expand All @@ -277,6 +283,9 @@ func MergeFlags(baseTokens, runtimeTokens []string) []string {
seen[tok] = struct{}{}
final = append(final, tok)
}
if webRTCPolicy != "" {
final = append(final, webRTCPolicy)
}
return final
}

Expand Down
25 changes: 25 additions & 0 deletions server/lib/chromiumflags/chromiumflags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,28 @@ func TestMergeFeatureEntries(t *testing.T) {
})
}
}

func TestWebRTCPolicyLastValueSurvivesRuntimeMerge(t *testing.T) {
const prefix = "--webrtc-ip-handling-policy="
for _, tc := range []struct{ base, previous, want string }{
{"default", "emulated", "default"},
{"disable_non_proxied_udp", "emulated", "disable_non_proxied_udp"},
{"emulated", "default", "emulated"},
{"default", "disable_non_proxied_udp", "emulated"},
} {
t.Run(tc.base+"/"+tc.want, func(t *testing.T) {
// Persist a policy update, then merge that file with the original launch.
overlay := MergeFlags([]string{prefix + tc.base, prefix + tc.previous}, []string{prefix + tc.want})
flags := MergeFlagsWithRuntimeTokens(prefix+tc.base, overlay)
var policies []string
for _, flag := range flags {
if strings.HasPrefix(flag, prefix) {
policies = append(policies, flag)
}
}
if !reflect.DeepEqual(policies, []string{prefix + tc.want}) {
t.Fatalf("merged policies = %#v, want latest %q", policies, tc.want)
}
})
}
}
Loading