public void BasicConfigTest() { string title = "chromely"; string iconFile = "chromely.ico"; string[] args = null; int hostWidth = 1200; int hostHeight = 900; string cefLogFile = "logs\\chromely.cef_new.log"; string defaultLogFile = "logs\\chromely_new.log"; string startUrl = "www.google.com"; var logSeverity = LogSeverity.Error; var config = ChromelyConfiguration .Create() .WithHostTitle(title) .WithHostIconFile(iconFile) .WithAppArgs(null) .WithHostSize(hostWidth, hostHeight) .WithLogFile(cefLogFile) .WithStartUrl(startUrl) .WithLogSeverity(logSeverity) .UseDefaultLogger(defaultLogFile); Assert.NotNull(config); Assert.Equal(title, config.HostTitle); Assert.Equal(iconFile, config.HostIconFile); Assert.Equal(args, config.AppArgs); Assert.Equal(hostWidth, config.HostWidth); Assert.Equal(hostHeight, config.HostHeight); Assert.Equal(cefLogFile, config.LogFile); Assert.Equal(startUrl, config.StartUrl); }
static int Main(string[] args) { try { HostHelpers.SetupDefaultExceptionHandlers(); string startUrl = "local://app/main.html"; ChromelyConfiguration config = ChromelyConfiguration .Create() .WithAppArgs(args) .WithHostSize(1200, 900) .WithLogFile("logs\\chromely.cef_new.log") .WithStartUrl(startUrl) .WithLogSeverity(LogSeverity.Info) .UseDefaultLogger("logs\\chromely_new.log") .UseDefaultResourceSchemeHandler("local", string.Empty) .UseDefaultHttpSchemeHandler("http", "chromely.com") .WithDebuggingMode(true) // The single process should only be used for debugging purpose. // For production, this should not be needed when the app is published and an cefglue_winapi_netcoredemo.exe // is created. // Alternate approach for multi-process, is to add a subprocess application // .WithCustomSetting(CefSettingKeys.BrowserSubprocessPath, full_path_to_subprocess) .WithCustomSetting(CefSettingKeys.SingleProcess, true); var factory = WinapiHostFactory.Init("GraphIcon.ico"); using (var window = factory.CreateWindow( () => new CefGlueBrowserHost(config), "RPGCore Editor", constructionParams: new FrameWindowConstructionParams())) { // Register external url schems window.RegisterUrlScheme(new UrlScheme("https://github.com/mattkol/Chromely", true)); // Register current/local assembly: window.RegisterServiceAssembly(Assembly.GetExecutingAssembly()); // Register external assemblies directory: string serviceAssembliesFolder = @"C:\ChromelyDlls"; window.RegisterServiceAssemblies(serviceAssembliesFolder); // Scan assemblies for Controller routes window.ScanAssemblies(); window.SetSize(config.HostWidth, config.HostHeight); window.CenterToScreen(); window.Show(); return(new EventLoop().Run(window)); } } catch (Exception exception) { Log.Error(exception); } return(0); }
public static INativeHost GetNativeHost(ChromelyConfiguration config) { switch (config.Platform) { case ChromelyPlatform.MacOSX: if (config.HostType == ChromelyHostType.Gtk3) { return(new MacGtk3Host()); } return(new MacCocoaHost()); case ChromelyPlatform.Linux: return(new LinuxGtk3Host()); case ChromelyPlatform.Windows: if (config.HostType == ChromelyHostType.Gtk3) { return(new WinGtk3Host()); } return(new WinAPIHost()); default: return(new WinAPIHost()); } }
public CefSharpBrowserHost(ChromelyConfiguration hostConfig) { HostConfig = hostConfig; m_browser = null; m_settings = new CefSettings(); ServiceAssemblies = new List <Assembly>(); }
public static void EnsureNativeHostFileExists(ChromelyConfiguration config) { // Required only when MacOS and HostType = OSDefault if (config.Platform != ChromelyPlatform.MacOSX) { return; } if (config.HostType == ChromelyHostType.Gtk3) { return; } var appDirectory = AppDomain.CurrentDomain.BaseDirectory; string fullPathNativeDll = Path.Combine(appDirectory, MacOSNativeDllFile); var timeout = DateTime.Now.Add(TimeSpan.FromSeconds(30)); while (!File.Exists(fullPathNativeDll)) { if (DateTime.Now > timeout) { Log.Error($"File {fullPathNativeDll} does not exist."); return; } Thread.Sleep(TimeSpan.FromSeconds(5)); } }
/// <summary> /// Initializes a new instance of the <see cref="CefSharpBrowserHost"/> class. /// </summary> /// <param name="hostConfig"> /// The host config. /// </param> public CefSharpBrowserHost(ChromelyConfiguration hostConfig) { this.mBrowser = null; this.mSettings = new CefSettings(); this.HostConfig = hostConfig; this.ServiceAssemblies = new List <Assembly>(); }
/// <summary> /// The get config. /// </summary> /// <returns> /// The <see cref="ChromelyConfiguration"/>. /// </returns> private ChromelyConfiguration GetConfig() { var title = "chromely"; var iconFile = "chromely.ico"; var hostWidth = 1200; var hostHeight = 900; var cefLogFile = Path.Combine("logs", "chromely.cef_new.log"); var defaultLogFile = Path.Combine("logs", "chromely_new.log"); var startUrl = "www.google.com"; var logSeverity = LogSeverity.Error; var config = ChromelyConfiguration .Create() .WithHostTitle(title) .WithHostIconFile(iconFile) .WithAppArgs(null) .WithHostSize(hostWidth, hostHeight) .WithLogFile(cefLogFile) .WithStartUrl(startUrl) .WithLogSeverity(logSeverity) .UseDefaultLogger(defaultLogFile); return(config); }
/// <summary> /// Initializes a new instance of the <see cref="CefGlueBrowser"/> class. /// </summary> /// <param name="owner"> /// The owner. /// </param> /// <param name="hostConfig"> /// The host config. /// </param> /// <param name="settings"> /// The settings. /// </param> public CefGlueBrowser(object owner, ChromelyConfiguration hostConfig, CefBrowserSettings settings) { Owner = owner; mHostConfig = hostConfig; mSettings = settings; StartUrl = hostConfig.StartUrl; }
/// <summary> /// The use default websocket handler. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="address"> /// The address. /// </param> /// <param name="port"> /// The port. /// </param> /// <param name="onLoadStartServer"> /// The onLoadStartServer. /// </param> /// <returns> /// The <see cref="ChromelyConfiguration"/>. /// </returns> public static ChromelyConfiguration UseDefaultWebsocketHandler(this ChromelyConfiguration configuration, string address, int port, bool onLoadStartServer) { configuration.WebsocketAddress = address; configuration.WebsocketPort = port; configuration.StartWebSocket = onLoadStartServer; return(configuration); }
/// <summary> /// The get config with default values. /// </summary> /// <returns> /// The <see cref="ChromelyConfiguration"/>. /// </returns> private ChromelyConfiguration GetConfigWithDefaultValues() { var defaultLogFile = Path.Combine("logs", "chromely_new.log"); var config = ChromelyConfiguration.Create() .UseDefaultLogger(defaultLogFile) .UseDefaultResourceSchemeHandler("local", string.Empty) .UseDefaultHttpSchemeHandler("http", "chromely.com") //.UseDefaultJsHandler("boundedObject", true) only available with Chromely.CefSharp.Winapi.ChromelyConfigurationExtension .WithCustomSetting(CefSettingKeys.NoSandbox, true) .WithCustomSetting(CefSettingKeys.SingleProcess, true) .WithCustomSetting(CefSettingKeys.BrowserSubprocessPath, nameof(CefSettingKeys.BrowserSubprocessPath)) .WithCustomSetting(CefSettingKeys.MultiThreadedMessageLoop, true) .WithCustomSetting(CefSettingKeys.ExternalMessagePump, true) .WithCustomSetting(CefSettingKeys.WindowlessRenderingEnabled, true) .WithCustomSetting(CefSettingKeys.CommandLineArgsDisabled, true) .WithCustomSetting(CefSettingKeys.CachePath, nameof(CefSettingKeys.CachePath)) .WithCustomSetting(CefSettingKeys.UserDataPath, nameof(CefSettingKeys.UserDataPath)) .WithCustomSetting(CefSettingKeys.UserAgent, nameof(CefSettingKeys.UserAgent)) .WithCustomSetting(CefSettingKeys.ProductVersion, nameof(CefSettingKeys.ProductVersion)) .WithCustomSetting(CefSettingKeys.Locale, nameof(CefSettingKeys.Locale)) .WithCustomSetting(CefSettingKeys.LogFile, nameof(CefSettingKeys.LogFile)) .WithCustomSetting(CefSettingKeys.LogSeverity, (int)CefLogSeverity.Error) .WithCustomSetting(CefSettingKeys.JavaScriptFlags, nameof(CefSettingKeys.JavaScriptFlags)) .WithCustomSetting(CefSettingKeys.ResourcesDirPath, nameof(CefSettingKeys.ResourcesDirPath)) .WithCustomSetting(CefSettingKeys.LocalesDirPath, nameof(CefSettingKeys.LocalesDirPath)) .WithCustomSetting(CefSettingKeys.PackLoadingDisabled, true) .WithCustomSetting(CefSettingKeys.RemoteDebuggingPort, 1025) .WithCustomSetting(CefSettingKeys.UncaughtExceptionStackSize, 1000) .WithCustomSetting(CefSettingKeys.IgnoreCertificateErrors, true) .WithCustomSetting(CefSettingKeys.EnableNetSecurityExpiration, true) .WithCustomSetting(CefSettingKeys.AcceptLanguageList, nameof(CefSettingKeys.AcceptLanguageList)); return(config); }
public void CreateWindow(ChromelyConfiguration hostConfig) { _hostConfig = hostConfig; NativeMethods.ChromelyParam configParam = InitParam(InitCallback, CreateCallback, MovingCallback, ResizeCallback, QuitCallback); var placement = _hostConfig.HostPlacement; configParam.centerscreen = placement.CenterScreen ? 1 : 0; configParam.frameless = placement.Frameless ? 1 : 0; configParam.fullscreen = placement.State == Core.Host.WindowState.Fullscreen ? 1 : 0; configParam.noresize = placement.NoResize ? 1 : 0; configParam.nominbutton = placement.NoMinMaxBoxes ? 1 : 0; configParam.nomaxbutton = placement.NoMinMaxBoxes ? 1 : 0; configParam.title = _hostConfig.HostTitle; configParam.x = placement.Left; configParam.y = placement.Top; configParam.width = placement.Width; configParam.height = placement.Height; NativeMethods.createwindow(ref configParam); }
/// <summary> /// Initializes a new instance of the <see cref="CefGlueBrowserHost"/> class. /// </summary> /// <param name="hostConfig"> /// The host config. /// </param> public CefGlueBrowserHost(ChromelyConfiguration hostConfig) { this.mBrowser = null; this.HostConfig = hostConfig; IoC.RegisterInstance(typeof(ChromelyConfiguration), typeof(ChromelyConfiguration).FullName, hostConfig); this.ServiceAssemblies = new List <Assembly>(); }
public static void LoadNativeHostFile(ChromelyConfiguration config) { // Required only when MacOS and HostType = OSDefault if (config.Platform != ChromelyPlatform.MacOSX) { return; } if (config.HostType == ChromelyHostType.Gtk3) { return; } var appDirectory = AppDomain.CurrentDomain.BaseDirectory; string fullPathNativeDll = Path.Combine(appDirectory, MacOSNativeDllFile); if (File.Exists(fullPathNativeDll)) { return; } Task.Run(() => { string resourcePath = $"Chromely.Native.MacCocoa.{MacOSNativeDllFile}"; using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath)) { using (var file = new FileStream(fullPathNativeDll, FileMode.Create, FileAccess.Write)) { resource?.CopyTo(file); } } }); }
private static int Main(string[] args) { CiTrace("Application", "Started"); // measure startup time (maybe including CEF download) _startupTimer = new Stopwatch(); _startupTimer.Start(); var core = typeof(ChromelyConfiguration).Assembly; CiTrace("Chromely.Core", core.GetName().Version.ToString()); CiTrace("Platform", ChromelyRuntime.Platform.ToString()); var appDirectory = AppDomain.CurrentDomain.BaseDirectory; CiTrace("AppDirectory", appDirectory); var startUrl = $"file:///{appDirectory}/index.html"; var windowStyle = new WindowCreationStyle(); windowStyle.WindowStyles = WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS; windowStyle.WindowExStyles = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; var config = ChromelyConfiguration .Create() .WithDebuggingMode(true) .WithLoadingCefBinariesIfNotFound(true) .WithSilentCefBinariesLoading(true) .RegisterEventHandler <ConsoleMessageEventArgs>(CefEventKey.ConsoleMessage, OnWebBrowserConsoleMessage) .WithAppArgs(args) .WithHostBounds(1000, 600) .WithHostCustomStyle(windowStyle) //.WithHostFlag(HostFlagKey.CenterScreen, true | false - default true) //.WithHostFlag(HostFlagKey.Frameless, true | false - default false) //.WithHostFlag(HostFlagKey.KioskMode, true | false - default false) .WithHostFlag(HostFlagKey.NoResize, true) // - default false) .WithHostFlag(HostFlagKey.NoMinMaxBoxes, true) // - default false) .WithStartUrl(startUrl); CiTrace("Configuration", "Created"); try { using (_window = ChromelyWindow.Create(config)) { _window.RegisterEventHandler(CefEventKey.FrameLoadEnd, new ChromelyEventHandler <FrameLoadEndEventArgs>(CefEventKey.FrameLoadEnd, OnFrameLoaded)); CiTrace("Window", "Created"); var result = _window.Run(args); CiTrace("RunResult", result.ToString()); } } catch (Exception ex) { Console.WriteLine(ex); throw; } CiTrace("Application", "Done"); return(0); }
/// <summary> /// The run. /// </summary> /// <param name="mainWindow"> /// The main window. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public new int Run(WindowCore mainWindow = null) { if (mainWindow is IChromelyHost chromelyHost) { this.mHostConfig = chromelyHost.HostConfig; } return(base.Run(mainWindow)); }
public static ChromelyConfiguration WithHostCustomStyle(this ChromelyConfiguration configuration, WindowCreationStyle customStyle) { if (configuration != null) { configuration.HostCustomCreationStyle = customStyle; } return(configuration); }
/// <summary> /// Registers Javascript object handler. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="chromelyJsHandler"> /// The chromely js handler. /// </param> /// <returns> /// The <see cref="ChromelyConfiguration"/> object. /// </returns> public static ChromelyConfiguration RegisterJsHandler(this ChromelyConfiguration configuration, ChromelyJsHandler chromelyJsHandler) { if (chromelyJsHandler != null) { IoC.RegisterInstance(typeof(ChromelyJsHandler), chromelyJsHandler.Key, chromelyJsHandler); } return(configuration); }
/// <summary> /// Registers message router handler. /// </summary> /// <param name="configuration"> /// The configuration. /// </param> /// <param name="messageRouterHandler"> /// The chromely message router. /// </param> /// <returns> /// The <see cref="ChromelyConfiguration"/> object. /// </returns> public static ChromelyConfiguration RegisterMessageRouterHandler(this ChromelyConfiguration configuration, ChromelyMessageRouter messageRouterHandler) { if (messageRouterHandler != null) { IoC.RegisterInstance(typeof(ChromelyMessageRouter), messageRouterHandler.Key, messageRouterHandler); } return(configuration); }
// ReSharper disable once UnusedParameter.Local private static void Main(string[] args) { Console.WriteLine("Sample showing stonehenge on Chromely"); // stonehenge backend var options = new StonehengeHostOptions { Title = "Demo" }; var provider = StonehengeResourceLoader .CreateDefaultLoader(new VueResourceProvider()); var host = new KestrelHost(provider, options); if (!host.Start(options.Title, false, "localhost", 8888)) { Console.WriteLine("Failed to start stonehenge server"); } // ensure CEF runtime files are present var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? "."; Directory.SetCurrentDirectory(path); try { CefRuntime.Load(); } catch (Exception ex) { Console.WriteLine("Failed to load runtime: " + ex.Message); Console.WriteLine("Installing CEF runtime from " + CefLoader.CefBuildsDownloadUrl); CefLoader.Load(); } // chromely frontend var startUrl = host.BaseUrl; var config = ChromelyConfiguration .Create() .WithHostMode(WindowState.Normal, true) .WithHostTitle(options.Title) //.WithHostIconFile("chromely.ico") .WithAppArgs(args) .WithHostSize(1000, 600) .WithStartUrl(startUrl); using (var window = new CefGlueBrowserWindow(config)) { var exitCode = window.Run(args); if (exitCode != 0) { Console.WriteLine("Failed to start chromely frontend: code " + exitCode); } } Console.WriteLine("Demo done."); }
public new int Run(WindowCore mainWindow = null) { if ((mainWindow != null) && (mainWindow is IChromelyHost)) { IChromelyHost chromelyHost = (IChromelyHost)mainWindow; m_hostConfig = chromelyHost.HostConfig; } return(base.Run(mainWindow)); }
/// <summary> /// Initializes a new instance of the <see cref="Window"/> class. /// </summary> /// <param name="application"> /// The application. /// </param> /// <param name="hostConfig"> /// The host config. /// </param> public Window(HostBase application, ChromelyConfiguration hostConfig) : base(hostConfig.HostTitle, hostConfig.HostWidth, hostConfig.HostHeight, hostConfig.HostIconFile) { this.mHostConfig = hostConfig; this.mCore = new CefGlueBrowser(this, new CefBrowserSettings(), hostConfig.StartUrl); this.mCore.Created += this.BrowserCreated; this.mApplication = application; this.ShowWindow(); }
public Window(HostBase application, ChromelyConfiguration hostConfig) : base(hostConfig.HostTitle, hostConfig.HostWidth, hostConfig.HostHeight, hostConfig.HostIconFile) { m_hostConfig = hostConfig; m_core = new CefGlueBrowser(this, new CefBrowserSettings(), hostConfig.StartUrl); m_core.Created += new EventHandler(BrowserCreated); m_application = application; ShowWindow(); }
/// <summary> /// Factory method to create main window. /// </summary> /// <param name="config"></param> /// <returns>Interface to the main window</returns> public static IChromelyWindow Create(ChromelyConfiguration config) { var path = AppDomain.CurrentDomain.BaseDirectory; var dllName = Path.Combine(path, $"Chromely.dll"); var assembly = Assembly.LoadFile(dllName); var type = assembly.GetTypes().First(t => t.Name == "CefGlueWindow"); return(Activator.CreateInstance(type, config) as HostBase); }
private static IChromelyWindow CreateFromAssembly(string platform, ChromelyConfiguration config) { var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? "."; var dllName = Path.Combine(path, $"Chromely.CefGlue.{platform}.dll"); var assembly = System.Reflection.Assembly.LoadFile(dllName); var type = assembly.GetTypes().First(t => t.Name == "CefGlueWindow"); return(Activator.CreateInstance(type, new object[] { config }) as HostBase); }
public NativeWindow(ChromelyConfiguration hostConfig) { _hostConfig = hostConfig; Handle = IntPtr.Zero; _nativeGui = NativeGuiFactory.GetNativeGui(hostConfig.Platform); _nativeGui.Created += OnCreated; _nativeGui.Moving += OnMoving; _nativeGui.SizeChanged += OnSizeChanged; _nativeGui.Close += OnClose; }
public NativeWindow(ChromelyConfiguration config) { _nativeHost = NativeHostFactory.GetNativeHost(config); _config = config; Handle = IntPtr.Zero; _nativeHost.Created += OnCreated; _nativeHost.Moving += OnMoving; _nativeHost.SizeChanged += OnSizeChanged; _nativeHost.Close += OnClose; }
/// <summary> /// Factory method to create main window. /// </summary> /// <param name="config"></param> /// <returns>Interface to the main window</returns> public static IChromelyWindow Create(ChromelyConfiguration config) { var platform = config.HostApi.ToString(); var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? "."; var dllName = Path.Combine(path, $"Chromely.CefGlue.{platform}.dll"); var assembly = Assembly.LoadFile(dllName); var type = assembly.GetTypes().First(t => t.Name == "CefGlueWindow"); return(Activator.CreateInstance(type, config) as HostBase); }
/// <summary> /// Initializes a new instance of the <see cref="Window"/> class. /// </summary> /// <param name="application"> /// The application. /// </param> /// <param name="hostConfig"> /// The host config. /// </param> public Window(HostBase application, ChromelyConfiguration hostConfig) : base(hostConfig.HostTitle, hostConfig.HostWidth, hostConfig.HostHeight, hostConfig.HostIconFile) { mHostConfig = hostConfig; mBrowser = new CefGlueBrowser(this, hostConfig, new CefBrowserSettings()); mBrowser.Created += OnBrowserCreated; mApplication = application; // Set event handler mBrowser.SetEventHandlers(); ShowWindow(); }
public static IChromelyWindow Create(ChromelyConfiguration config) { switch (CefRuntime.Platform) { case CefRuntimePlatform.Windows: return(CreateFromAssembly("Winapi", config)); case CefRuntimePlatform.Linux: return(CreateFromAssembly("Gtk", config)); } throw new PlatformNotSupportedException($"Chromely.CefGlue does not support {CefRuntime.Platform}"); }
/// <summary> /// Initializes a new instance of the <see cref="Window"/> class. /// </summary> /// <param name="application"> /// The application. /// </param> /// <param name="hostConfig"> /// The host config. /// </param> public Window(HostBase application, ChromelyConfiguration hostConfig) : base(hostConfig) { _hostConfig = hostConfig; Browser = new CefGlueBrowser(this, hostConfig, new CefBrowserSettings()); Browser.Created += OnBrowserCreated; _application = application; // Set event handler Browser.SetEventHandlers(); ShowWindow(); }