Exemple #1
0
        static void InitializeCefRuntime()
        {
            if (cefRuntimeUnableToLoad)
            {
                return;
            }
            if (!IsSupportedByThisPlatform())
            {
                return;
            }

            if (cefRuntimeInitialized)
            {
                throw new InvalidOperationException("The CefRuntime is already initialized. Call ShutdownCefRuntime() before initializing it again.");
            }

            //load native libraries
            {
                if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
                {
                    try
                    {
                        string error = NativeLibraryManager.PreLoadLibrary(Path.Combine("CefGlue", "libcef"), true);
                        if (!string.IsNullOrEmpty(error))
                        {
                            cefRuntimeUnableToLoad      = true;
                            cefRuntimeUnableToLoadError = error;
                        }
                    }
                    catch
                    {
                        cefRuntimeUnableToLoad      = true;
                        cefRuntimeUnableToLoadError = "Crash inside NativeLibraryManager.PreLoadLibrary.";
                    }
                }
            }

            //delete log file
            string realLogFileName = VirtualFileSystem.GetRealPathByVirtual("user:Logs\\WebBrowserControl_CefGlue.log");

            try
            {
                if (File.Exists(realLogFileName))
                {
                    File.Delete(realLogFileName);
                }
            }
            catch { }

            if (!cefRuntimeUnableToLoad)
            {
                try
                {
                    CefRuntime.Load();
                }
                catch (DllNotFoundException ex)
                {
                    Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message);
                    return;
                }
                catch (CefRuntimeException ex)
                {
                    Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message);
                    return;
                }
                catch (Exception ex)
                {
                    Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message);
                    return;
                }

                var mainArgs = new CefMainArgs(null);
                var cefApp   = new SimpleApp();

                var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp, IntPtr.Zero);
                if (exitCode != -1)
                {
                    Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.ExecuteProcess: Exit code: {0}", exitCode);
                    return;
                }

                var cefSettings = new CefSettings
                {
                    SingleProcess = true,
                    WindowlessRenderingEnabled = true,
                    MultiThreadedMessageLoop   = true,
                    LogSeverity           = CefLogSeverity.Verbose,
                    LogFile               = realLogFileName,
                    BrowserSubprocessPath = "",
                    CachePath             = "",
                };

                ///// <summary>
                ///// Set to <c>true</c> to disable configuration of browser process features using
                ///// standard CEF and Chromium command-line arguments. Configuration can still
                ///// be specified using CEF data structures or via the
                ///// CefApp::OnBeforeCommandLineProcessing() method.
                ///// </summary>
                //public bool CommandLineArgsDisabled { get; set; }

                ///// <summary>
                ///// The fully qualified path for the resources directory. If this value is
                ///// empty the cef.pak and/or devtools_resources.pak files must be located in
                ///// the module directory on Windows/Linux or the app bundle Resources directory
                ///// on Mac OS X. Also configurable using the "resources-dir-path" command-line
                ///// switch.
                ///// </summary>
                //public string ResourcesDirPath { get; set; }

                try
                {
                    CefRuntime.Initialize(mainArgs, cefSettings, cefApp, IntPtr.Zero);
                }
                catch (CefRuntimeException ex)
                {
                    Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Initialize: " + ex.Message);
                    return;
                }

                cefRuntimeInitialized = true;

                if (!subscribedToEngineAppDestroy)
                {
                    subscribedToEngineAppDestroy = true;
                    EngineApp.DestroyEvent      += EngineApp_DestroyEvent;
                }
            }
        }
Exemple #2
0
        private static void InitializeCefRuntime()
        {
            if( !IsSupportedByThisPlatform() )
                return;

            if( isCefRuntimeInitialized )
                throw new InvalidOperationException( "The CefRuntime is already initialized. Call ShutdownCefRuntime() before initializing it again." );

            if( PlatformInfo.Platform == PlatformInfo.Platforms.Windows )
                NativeLibraryManager.PreLoadLibrary( Path.Combine( "CefGlue", "libcef" ) );

            //delete log file
            string realLogFileName = VirtualFileSystem.GetRealPathByVirtual( "user:Logs\\WebBrowserControl_CefGlue.log" );
            try
            {
                if( File.Exists( realLogFileName ) )
                    File.Delete( realLogFileName );
            }
            catch { }

            try
            {
                CefRuntime.Load();
            }
            catch( DllNotFoundException ex )
            {
                Log.Error( "WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message );
                return;
            }
            catch( CefRuntimeException ex )
            {
                Log.Error( "WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message );
                return;
            }
            catch( Exception ex )
            {
                Log.Error( "WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message );
                return;
            }

            var mainArgs = new CefMainArgs( null );
            var cefApp = new SimpleApp();

            var exitCode = CefRuntime.ExecuteProcess( mainArgs, cefApp, IntPtr.Zero );
            if( exitCode != -1 )
            {
                Log.Error( "WebBrowserControl: InitializeCefRuntime: CefRuntime.ExecuteProcess: Exit code: {0}", exitCode );
                return;
            }

            var cefSettings = new CefSettings
            {
                SingleProcess = true,
                WindowlessRenderingEnabled = true,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Verbose,
                LogFile = realLogFileName,
                BrowserSubprocessPath = "",
                CachePath = "",
            };

            //!!!!
            ///// <summary>
            ///// Set to <c>true</c> to disable configuration of browser process features using
            ///// standard CEF and Chromium command-line arguments. Configuration can still
            ///// be specified using CEF data structures or via the
            ///// CefApp::OnBeforeCommandLineProcessing() method.
            ///// </summary>
            //public bool CommandLineArgsDisabled { get; set; }

            //!!!!!mac
            ///// <summary>
            ///// The fully qualified path for the resources directory. If this value is
            ///// empty the cef.pak and/or devtools_resources.pak files must be located in
            ///// the module directory on Windows/Linux or the app bundle Resources directory
            ///// on Mac OS X. Also configurable using the "resources-dir-path" command-line
            ///// switch.
            ///// </summary>
            //public string ResourcesDirPath { get; set; }

            try
            {
                CefRuntime.Initialize( mainArgs, cefSettings, cefApp, IntPtr.Zero );
            }
            catch( CefRuntimeException ex )
            {
                Log.Error( "WebBrowserControl: InitializeCefRuntime: CefRuntime.Initialize: " + ex.Message );
                return;
            }

            isCefRuntimeInitialized = true;
        }