cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.88k stars 2.92k forks source link

Doc - Update CefSettings.CachePath and RootCachePath xml doc #4925

Closed amaitland closed 1 month ago

amaitland commented 2 months ago

Update documentation as upstream doco and behavior has changed.

https://cef-builds.spotifycdn.com/docs/128.4/structcef__settings__t.html#ad1644a7eb23cad969181db010f007710

amaitland commented 2 months ago

Might also need to update general usage

mitchcapper commented 1 month ago

One specific item I saw was the cache_path must have the root cache_path as the same or direct parent directory (if cache_path is specified).

amaitland commented 1 month ago

One specific item I saw was the cache_path must have the root cache_path as the same or direct parent directory (if cache_path is specified).

Yep, looks like the requirements are quite a bit stricter.

I wonder if we might be able to add some validation just before Cef.Initialzie is called, confirm that if the CachePath was specificed, it is a direct child of the RootCachePath

mitchcapper commented 1 month ago

Yes this can be more subtle that one expects as well. Specifying an invalid cachepath causes it to default back if you are running multiple instances this is going to run into the singleton problem which if you have the handler for you might catch quickly but if not the crash may not be apparent.

I think the easiest decently bulletproof way to do this is something along the lines of:

if (! String.IsNullOrWhitespace(CachePath)){
 var di = DirectoryInfo(CachePath);
if (Path.GetRelativePath(di.FullPath,RootCachePath) != "." && Path.GetRelativePath(di.Parent.FullPath,RootCachePath) != ".")
 throw new ArgumentException("If specifying CachePath it must be equal to the RootCachePath or a direct child directory of it");
}

(That is code from my poor memory so almost certainly won't compile but the gyst:)

Granted GetRelativePath is .net std 2.1 so doesn't help most .net framework users. Pretty sure there is GetFinalPath or getfinaltarget or something as well but i think that is an even newer .net version.

One could pinvoke with GetFinalPathNameByHandle but that might be overkill. Could just force users to not use tricky naming so CachePath.Parent must directly equal rootcachepath or throw an error (as cef probably is using basic logic to determine if it should allow the cachepath without full resolution like the above).

amaitland commented 1 month ago

Have created https://github.com/cefsharp/CefSharp/issues/4949 to track adding some validation 👍