/// <summary>
        /// The on create.
        /// </summary>
        /// <param name="packet">
        /// The packet.
        /// </param>
        /// <exception cref="Exception">
        /// Rethrown exception on Cef load failure.
        /// </exception>
        protected override void OnCreate(ref CreateWindowPacket packet)
        {
            // Will throw exception if Cef load fails.
            CefRuntime.Load();

            var mainArgs = new CefMainArgs(this.HostConfig.AppArgs);
            var app      = new CefGlueApp(this.HostConfig);

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode != -1)
            {
                return;
            }

            var codeBase       = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder    = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var localesDirPath = Path.Combine(localFolder, "locales");

            var settings = new CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = this.HostConfig.Locale,
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity              = (CefLogSeverity)this.HostConfig.LogSeverity,
                LogFile                  = this.HostConfig.LogFile,
                ResourcesDirPath         = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath),
                NoSandbox                = true
            };

            // Update configuration settings
            settings.Update(this.HostConfig.CustomSettings);

            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            this.RegisterSchemeHandlers();
            this.RegisterMessageRouters();

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

            this.mBrowser = new CefGlueBrowser(browserConfig);

            base.OnCreate(ref packet);

            Log.Info("Cef browser successfully created.");
        }
示例#2
0
 /// <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>();
 }
示例#3
0
 /// <summary>
 /// The dispose.
 /// </summary>
 public void Dispose()
 {
     if (mBrowser != null)
     {
         mBrowser.Dispose();
         mBrowser             = null;
         mBrowserWindowHandle = IntPtr.Zero;
     }
 }
示例#4
0
 /// <summary>
 /// The dispose.
 /// </summary>
 public void Dispose()
 {
     if (Browser != null)
     {
         Browser.Dispose();
         Browser = null;
         _browserWindowHandle = IntPtr.Zero;
     }
 }
示例#5
0
        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();
        }
示例#6
0
文件: Window.cs 项目: ztxyzu/Chromely
        /// <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();
        }
示例#7
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, ChromelyConfiguration hostConfig)
            : base(hostConfig)
        {
            _hostConfig      = hostConfig;
            Browser          = new CefGlueBrowser(this, hostConfig, new CefBrowserSettings());
            Browser.Created += OnBrowserCreated;
            _application     = application;

            // Set event handler
            Browser.SetEventHandlers();

            ShowWindow();
        }
示例#8
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, 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();
        }
示例#9
0
        public Window(IChromelyNativeHost nativeHost, IChromelyContainer container, IChromelyConfiguration config, IChromelyCommandTaskRunner commandTaskRunner, CefMessageRouterBrowserSide browserMessageRouter)
            : base(nativeHost, config)
        {
            _container            = container;
            _config               = config;
            _commandTaskRunner    = commandTaskRunner;
            _browserMessageRouter = browserMessageRouter;
            Browser               = new CefGlueBrowser(this, _container, config, _commandTaskRunner, _browserMessageRouter, new CefBrowserSettings());
            Browser.Created      += OnBrowserCreated;

            // Set event handler
            Browser.SetEventHandlers(_container);

            ShowWindow();
        }
示例#10
0
 public void Dispose()
 {
     try
     {
         if (Browser != null)
         {
             Browser.Dispose();
             Browser = null;
             _browserWindowHandle = IntPtr.Zero;
         }
     }
     catch (Exception exception)
     {
         Logger.Instance.Log.Error(exception);
     }
 }
示例#11
0
        public void Dispose()
        {
            try
            {
                if (Browser != null)
                {
                    Browser?.InvokeAsyncIfPossible(() => Browser?.OnBeforeClose(new BeforeCloseEventArgs()));

                    Browser?.Dispose();
                    Browser = null;
                    _browserWindowHandle = IntPtr.Zero;
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.Log.Error(exception);
            }
        }
示例#12
0
        public void Dispose()
        {
            try
            {
                if (Browser != null)
                {
                    // A hack - until fix is found for why OnBeforeClose is not called in CefGlueLifeHandler.cs
                    Browser?.OnBeforeClose();

                    Browser?.Dispose();
                    Browser = null;
                    _browserWindowHandle = IntPtr.Zero;
                }
            }
            catch (Exception exception)
            {
                Logger.Instance.Log.Error(exception);
            }
        }
示例#13
0
        public Window(IChromelyNativeHost nativeHost, IChromelyContainer container, IChromelyConfiguration config, IChromelyCommandTaskRunner commandTaskRunner, CefMessageRouterBrowserSide browserMessageRouter)
            : base(nativeHost, config)
        {
            _container            = container;
            _config               = config;
            _commandTaskRunner    = commandTaskRunner;
            _browserMessageRouter = browserMessageRouter;
            Browser               = new CefGlueBrowser(this, _container, config, _commandTaskRunner, _browserMessageRouter, new CefBrowserSettings());

            // Set event handler
            Browser.SetEventHandlers(_container);

            Browser.Created += OnBrowserCreated;

            // 'Created' event sometimes tries to attach interceptors too early, while all windows is not created yet,
            // so it's better to use 'FrameLoadStart'.
            Browser.FrameLoadStart += OnFrameLoadStart;

            ShowWindow();
        }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueLoadHandler"/> class.
 /// </summary>
 public CefGlueLoadHandler()
 {
     _browser = CefGlueBrowser.BrowserCore;
 }
示例#15
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();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueRequestHandler"/> class.
 /// </summary>
 public CefGlueRequestHandler(IChromelyConfiguration config, IChromelyCommandTaskRunner commandTaskRunner, CefGlueBrowser browser)
 {
     _config            = config;
     _commandTaskRunner = commandTaskRunner;
     _browser           = browser;
 }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueRequestHandler"/> class.
 /// </summary>
 public CefGlueRequestHandler()
 {
     this.mBrowser = CefGlueBrowser.BrowserCore;
 }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueDisplayHandler"/> class.
 /// </summary>
 public CefGlueDisplayHandler()
 {
     _browser = CefGlueBrowser.BrowserCore;
 }
示例#19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueLifeSpanHandler"/> class.
 /// </summary>
 public CefGlueLifeSpanHandler()
 {
     this.mBrowser = CefGlueBrowser.BrowserCore;
 }
示例#20
0
 /// <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;
     this.ServiceAssemblies = new List <Assembly>();
 }
示例#21
0
 /// <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;
 }
示例#22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueLoadHandler"/> class.
 /// </summary>
 public CefGlueLoadHandler()
 {
     this.mBrowser = CefGlueBrowser.BrowserCore;
 }
示例#23
0
 public CefGlueBrowserHost(ChromelyConfiguration hostConfig)
 {
     HostConfig        = hostConfig;
     m_browser         = null;
     ServiceAssemblies = new List <Assembly>();
 }
示例#24
0
 public CefGlueLifeSpanHandler()
 {
     m_browser = CefGlueBrowser.BrowserCore;
 }
示例#25
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();
        }
示例#26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueDisplayHandler"/> class.
 /// </summary>
 public CefGlueDisplayHandler()
 {
     this.mBrowser = CefGlueBrowser.BrowserCore;
 }
示例#27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueRequestHandler"/> class.
 /// </summary>
 public CefGlueRequestHandler()
 {
     _browser = CefGlueBrowser.BrowserCore;
 }
示例#28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefGlueLoadHandler"/> class.
 /// </summary>
 public CefGlueLoadHandler(IChromelyConfiguration config, CefGlueBrowser browser)
 {
     _config  = config;
     _browser = browser;
 }