Skip to content

Commit f22b14c

Browse files
authored
RDEV-9063 - Add BackgroundColor and VideoAutoplay to CefSettings (#398)
* Add BackgroundColor to CefSettings Signed-off-by: Russell Camo <jrcc1023@gmail.com> * Add EnableVideoAutoplay property to GlobalSettings Signed-off-by: Russell Camo <jrcc1023@gmail.com> --------- Signed-off-by: Russell Camo <jrcc1023@gmail.com>
1 parent b5424ab commit f22b14c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

WebViewControl/GlobalSettings.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Drawing;
34
using System.IO;
45
using Xilium.CefGlue.Common;
56

67
namespace WebViewControl {
78

89
public class GlobalSettings {
910

11+
private Color backgroundColor = Color.White;
1012
private bool persistCache;
1113
private bool enableErrorLogOnly;
14+
private bool enableVideoAutoplay = false;
1215
private bool osrEnabled = false;
1316
private string userAgent;
1417
private string logFile;
@@ -25,6 +28,14 @@ public void AddCommandLineSwitch(string key, string value) {
2528

2629
public IEnumerable<KeyValuePair<string, string>> CommandLineSwitches => commandLineSwitches;
2730

31+
public Color BackgroundColor {
32+
get => backgroundColor;
33+
set {
34+
EnsureNotLoaded(nameof(BackgroundColor));
35+
backgroundColor = value;
36+
}
37+
}
38+
2839
public string CachePath {
2940
get => cachePath;
3041
set {
@@ -78,6 +89,19 @@ public bool OsrEnabled {
7889
}
7990
}
8091

92+
/// <summary>
93+
/// Set to true to enable video autoplay without requiring user interaction.
94+
/// This allows muted videos with the autoplay attribute to play automatically.
95+
/// Default is false for security and user experience considerations.
96+
/// </summary>
97+
public bool EnableVideoAutoplay {
98+
get => enableVideoAutoplay;
99+
set {
100+
EnsureNotLoaded(nameof(EnableVideoAutoplay));
101+
enableVideoAutoplay = value;
102+
}
103+
}
104+
81105
private void EnsureNotLoaded(string propertyName) {
82106
if (CefRuntimeLoader.IsLoaded) {
83107
throw new InvalidOperationException($"Cannot set {propertyName} after WebView engine has been loaded");

WebViewControl/WebViewLoader.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static void Initialize(GlobalSettings settings) {
3737
CachePath = settings.CachePath, // enable cache for external resources to speedup loading
3838
WindowlessRenderingEnabled = settings.OsrEnabled,
3939
RemoteDebuggingPort = settings.GetRemoteDebuggingPort(),
40-
UserAgent = settings.UserAgent
40+
UserAgent = settings.UserAgent,
41+
BackgroundColor = new CefColor((uint)settings.BackgroundColor.ToArgb())
4142
};
4243

4344
var customSchemes = CustomSchemes.Select(s => new CustomScheme() {
@@ -46,7 +47,11 @@ public static void Initialize(GlobalSettings settings) {
4647
}).ToArray();
4748

4849
settings.AddCommandLineSwitch("enable-experimental-web-platform-features", null);
49-
50+
51+
if (settings.EnableVideoAutoplay) {
52+
settings.AddCommandLineSwitch("autoplay-policy", "no-user-gesture-required");
53+
}
54+
5055
CefRuntimeLoader.Initialize(settings: cefSettings, flags: settings.CommandLineSwitches.ToArray(), customSchemes: customSchemes);
5156

5257
AppDomain.CurrentDomain.ProcessExit += delegate { Cleanup(); };

0 commit comments

Comments
 (0)