2015-06-15 16:33:22 +08:00
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
2014-10-07 09:03:00 +08:00
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
2018-08-12 15:09:27 +08:00
using CefSharp.WinForms ;
2014-10-07 09:03:00 +08:00
using System ;
2017-03-22 13:04:33 +08:00
using System.IO ;
2014-10-07 09:03:00 +08:00
using System.Windows.Forms ;
namespace CefSharp.MinimalExample.WinForms
{
public class Program
{
[STAThread]
2020-02-10 10:20:12 +08:00
public static int Main ( string [ ] args )
2014-10-07 09:03:00 +08:00
{
2021-02-08 14:53:54 +08:00
#if ANYCPU
//Only required for PlatformTarget of AnyCPU
AppDomain . CurrentDomain . AssemblyResolve + = Resolver ;
#endif
2016-09-20 09:58:37 +08:00
//For Windows 7 and above, best to include relevant app.manifest entries as well
Cef . EnableHighDPISupport ( ) ;
2017-03-22 13:04:33 +08:00
var settings = new CefSettings ( )
{
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
CachePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "CefSharp\\Cache" )
} ;
2018-07-13 08:48:52 +08:00
//Example of setting a command line argument
//Enables WebRTC
2020-09-09 15:51:12 +08:00
// - CEF Doesn't currently support permissions on a per browser basis see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access
// - CEF Doesn't currently support displaying a UI for media access permissions
//
//NOTE: WebRTC Device Id's aren't persisted as they are in Chrome see https://bitbucket.org/chromiumembedded/cef/issues/2064/persist-webrtc-deviceids-across-restart
2020-05-23 10:11:28 +08:00
settings . CefCommandLineArgs . Add ( "enable-media-stream" ) ;
2020-09-09 15:51:12 +08:00
//https://peter.sh/experiments/chromium-command-line-switches/#use-fake-ui-for-media-stream
settings . CefCommandLineArgs . Add ( "use-fake-ui-for-media-stream" ) ;
//For screen sharing add (see https://bitbucket.org/chromiumembedded/cef/issues/2582/allow-run-time-handling-of-media-access#comment-58677180)
settings . CefCommandLineArgs . Add ( "enable-usermedia-screen-capturing" ) ;
2015-11-05 07:13:24 +08:00
//Perform dependency check to make sure all relevant resources are in our output directory.
2021-04-07 13:52:14 +08:00
Cef . Initialize ( settings , performDependencyCheck : true , browserProcessHandler : null ) ;
2014-10-07 09:03:00 +08:00
var browser = new BrowserForm ( ) ;
Application . Run ( browser ) ;
2020-02-10 10:20:12 +08:00
return 0 ;
2014-10-07 09:03:00 +08:00
}
2021-02-08 14:53:54 +08:00
// Will attempt to load missing assembly from either x86 or x64 subdir
//when PlatformTarget is AnyCPU
#if ANYCPU
private static System . Reflection . Assembly Resolver ( object sender , ResolveEventArgs args )
{
if ( args . Name . StartsWith ( "CefSharp.Core.Runtime" ) )
{
string assemblyName = args . Name . Split ( new [ ] { ',' } , 2 ) [ 0 ] + ".dll" ;
string archSpecificPath = Path . Combine ( AppDomain . CurrentDomain . SetupInformation . ApplicationBase ,
Environment . Is64BitProcess ? "x64" : "x86" ,
assemblyName ) ;
return File . Exists ( archSpecificPath )
? System . Reflection . Assembly . LoadFile ( archSpecificPath )
: null ;
}
return null ;
}
#endif
2014-10-07 09:03:00 +08:00
}
}