コード例 #1
0
        public static iServiceProvider CreateHost(CefConfiguration config)
        {
            iServiceProvider app = null;

            if (CefRuntime.Platform == CefRuntimePlatform.Windows)
            {
                app = new Windows.ChromeHost.CefGlueBrowserHost(config);
            }
            else if (CefRuntime.Platform == CefRuntimePlatform.Linux)
            {
                app = new Linux.ChromeHost.CefGlueBrowserHost(config);
            }
            return(app);
        }
コード例 #2
0
        /// <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, CefConfiguration hostConfig)
            : base(new XDisplay(IntPtr.Zero), new Rectangle(0, 0, application.HostConfig.HostWidth, application.HostConfig.HostHeight))
        {
            CefGlueClient.window = this;
            this.Name            = application.HostConfig.HostTitle;

            this.mHostConfig  = hostConfig;
            this.mApplication = application;
            this.PropertyNotifyHandlerEvent += (xevent, window) =>
            {
                var attr = this.GetAttributes();
                if (attr.x + attr.width > 0 && attr.y + attr.height > 0 && this.mBrowserWindowHandle != IntPtr.Zero)
                {
                    ResizeEx(this.mBrowserWindowHandle, new Size(attr.x + attr.width, attr.y + attr.height));
                }
            };

            #region Browser
            this.mCore = new CefGlueBrowser(this, new CefBrowserSettings(), this.mHostConfig.StartUrl);
            var windowInfo = CefWindowInfo.Create();
            switch (CefRuntime.Platform)
            {
            case CefRuntimePlatform.Linux:
                windowInfo.SetAsChild(Handle, new CefRectangle(0, 0, 0, 0));
                break;

            case CefRuntimePlatform.MacOSX:
            default:
                break;
            }
            this.mCore.Create(windowInfo);

            this.mCore.AddressChanged += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.BeforeClose += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.BeforePopup += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.BrowserCreated += (s, args) =>
            {
                this.mBrowserWindowHandle = this.mCore.Browser.GetHost().GetWindowHandle();
            };
            this.mCore.ConsoleMessage += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { Log.Trace(e.Source, e.Line, e.Message); });
            };
            this.mCore.LoadEnd += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.LoadError += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.LoadingStateChange += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.LoadStarted += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.PluginCrashed += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.RenderProcessTerminated += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => {
                    if (this.mCore != null)
                    {
                        Log.Critial("Render Process Terminated: reloading page");
                        if (this.mCore.Browser != null)
                        {
                            this.mCore.Browser.Reload();
                        }
                    }
                });
            };
            this.mCore.StatusMessage += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.PluginCrashed += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            this.mCore.TitleChanged += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => {
                    if (!string.IsNullOrEmpty(e.Title))
                    {
                        Name = e.Title;
                    }
                });
            };
            this.mCore.Tooltip += (s, e) =>
            {
                Gtk.Application.Invoke((_s, _e) => { });
            };
            #endregion

            //if (File.Exists(Path.Combine(application.HostConfig.HostIconFile)))
            //    this.Icon = System.Drawing.Icon.FromHandle((new Bitmap(Path.Combine(application.HostConfig.HostIconFile))).GetHicon());
            //
            //this.BackColor = Color.FromArgb(32, 31, 41);


            this.Show();
        }
コード例 #3
0
        /// <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, CefConfiguration hostConfig)
        {
            CefGlueClient.window = this;
            this.Text            = application.HostConfig.HostTitle;
            this.Size            = new Size(application.HostConfig.HostWidth, application.HostConfig.HostHeight);
            this.StartPosition   = FormStartPosition.CenterScreen;
            if (File.Exists(Path.Combine(application.HostConfig.HostIconFile)))
            {
                this.Icon = Icon.FromHandle((new Bitmap(Path.Combine(application.HostConfig.HostIconFile))).GetHicon());
            }

            this.AutoScaleMode = AutoScaleMode.Dpi;
            this.AutoScroll    = false;
            this.BackColor     = Color.FromArgb(32, 31, 41);

            this.mHostConfig  = hostConfig;
            this.mApplication = application;

            var browserConfig = new CefBrowserConfig
            {
                StartUrl     = application.HostConfig.StartUrl,
                ParentHandle = this.Handle,
                AppArgs      = application.HostConfig.AppArgs,
                CefRectangle =
                    new CefRectangle
                {
                    X      = 0,
                    Y      = 0,
                    Width  = this.ClientSize.Width,
                    Height = this.ClientSize.Height
                }
            };

            this.FormClosing += (s, args) => { this.mApplication.Quit(); };
            this.SizeChanged += (s, args) =>
            {
                if (this.mBrowserWindowHandle != IntPtr.Zero)
                {
                    NativeMethods.SetWindowPos(this.mBrowserWindowHandle, IntPtr.Zero, 0, 0, this.ClientSize.Width, this.ClientSize.Height, Core.Host.WinapiConstants.NoZOrder);
                }
            };

            #region Browser
            this.mCore = new CefGlueBrowser(browserConfig);
            this.mCore.AddressChanged += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.BeforeClose += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.BeforePopup += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.BrowserCreated += (s, args) =>
            {
                this.mBrowserWindowHandle = this.mCore.Browser.GetHost().GetWindowHandle();
            };
            this.mCore.ConsoleMessage += (s, e) =>
            {
                this.InvokeIfRequired(() => { Log.Trace(e.Source, e.Line, e.Message); });
            };
            this.mCore.LoadEnd += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.LoadError += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.LoadingStateChange += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.LoadStarted += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.PluginCrashed += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.RenderProcessTerminated += (s, e) =>
            {
                this.InvokeIfRequired(() => {
                    if (this.mCore != null)
                    {
                        Log.Critial("Render Process Terminated: reloading page");
                        if (this.mCore.Browser != null)
                        {
                            this.mCore.Browser.Reload();
                        }
                    }
                });
            };
            this.mCore.StatusMessage += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.PluginCrashed += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            this.mCore.TitleChanged += (s, e) =>
            {
                this.InvokeIfRequired(() => {
                    if (!string.IsNullOrEmpty(e.Title))
                    {
                        Text = e.Title;
                    }
                });
            };
            this.mCore.Tooltip += (s, e) =>
            {
                this.InvokeIfRequired(() => { });
            };
            #endregion

            this.Show();
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HostBase"/> class.
 /// </summary>
 /// <param name="hostConfig">
 /// The host config.
 /// </param>
 protected HostBase(CefConfiguration hostConfig)
 {
     this.HostConfig        = hostConfig;
     this.ServiceAssemblies = new List <Assembly>();
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueApp"/> class.
 /// </summary>
 /// <param name="hostConfig">
 /// The host config.
 /// </param>
 public CefGlueApp(CefConfiguration hostConfig)
 {
     this.mHostConfig = hostConfig;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueBrowserHost"/> class.
 /// </summary>
 /// <param name="hostConfig">
 /// The host config.
 /// </param>
 public CefGlueBrowserHost(CefConfiguration hostConfig)
     : base(hostConfig)
 {
 }
コード例 #7
0
        public static void Main(string[] args)
        {
            #region FirstChanceException & UnhandledException
            AppDomain.CurrentDomain.FirstChanceException += (s, arg) => {
                Log.Error(arg.Exception);
            };

            AppDomain.CurrentDomain.UnhandledException += (s, arg) => {
                Log.Error("IsTerminating: " + arg.IsTerminating + ", Error: " + (arg.ExceptionObject != null ? arg.ExceptionObject : "") + Environment.NewLine);
            };
            #endregion

            #region Configurations / Browser Host
            try
            {
                #region Configurations
                Configuration configuration = null;
                var path = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

                try
                {
                    if (!Directory.Exists("Extensions")) Directory.CreateDirectory("Extensions");
                    if (!Directory.Exists("Web")) Directory.CreateDirectory("Web");

                    if (File.Exists(Path.Combine(path, "Configurations.xml"))) configuration = Configuration.Load(Path.Combine(path, "Configurations.xml"));
                    else
                    {
                        configuration = new Configuration("Default", 60, true)
                                            .Save(Path.Combine(path, "Configurations.xml"));
                    }

                    if (!Directory.Exists(Path.Combine("Web", configuration.Application))) Directory.CreateDirectory(Path.Combine("Web", configuration.Application));
                    if (!File.Exists(Path.Combine("Web", configuration.Application, "index.htm"))) File.WriteAllText(Path.Combine("Web", configuration.Application, "index.htm"), Configuration.WebStartupFile());

                }
                catch (Exception ex) { Log.Trace(ex.Message, ex.StackTrace, true); }

                var config = CefConfiguration
                            .Create()
                            .WithHostTitle("BLIS")
                            .WithHostIconFile("logo.ico")
                            .WithAppArgs(args)
                            .WithHostSize(1024, 600) //1440x900
                            .WithLogFile("logs\\blis.cef_new.log")
                            .WithStartUrl($"http://{configuration.Application}/index.htm")
                            .WithLogSeverity(LogSeverity.Error)
                            .UseDefaultLogger("logs\\blis_new.log")
                            .UseDefaultResourceSchemeHandler("http", string.Empty)
                            .UseDefaultHttpSchemeHandler("http", "blis.com")
                            .RegisterSchemeHandler("local", string.Empty, new CustomResourceHandler())
                            .WithCustomSetting(CefSettingKeys.CachePath, Path.Combine(path, "Logs", "Cache"))
                            .WithCustomSetting(CefSettingKeys.ResourcesDirPath, Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath))
                            .WithCustomSetting(CefSettingKeys.RemoteDebuggingPort, configuration.RemoteDebuggingPort)
                            .WithCustomSetting(CefSettingKeys.NoSandbox, true);
                #endregion

                #region Browser Host
                var app = CefGlueBrowserHost.CreateHost(config);
                if (app != null)
                {
                    app.RegisterServiceAssemblies(Path.Combine(path, "Extensions"));
                    app.ScanAssemblies();
                    app.Run(args);
                }
                #endregion
            }
            catch (Exception exception) { Log.Error(exception); }
            #endregion
        }