Ejemplo n.º 1
0
        protected override void OnCreate(ref CreateWindowPacket packet)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            var mainArgs = new CefMainArgs(HostConfig.AppArgs);
            var app      = new CefWebApp(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                   = HostConfig.Locale,
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity              = (CefLogSeverity)HostConfig.LogSeverity,
                LogFile                  = HostConfig.LogFile,
                ResourcesDirPath         = Path.GetDirectoryName(new Uri(Assembly.GetEntryAssembly().CodeBase).LocalPath),
                NoSandbox                = true
            };

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

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

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            CefBrowserConfig browserConfig = new CefBrowserConfig();

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

            m_browser = new CefWebBrowser(browserConfig);

            base.OnCreate(ref packet);

            Log.Info("Cef browser successfully created.");
        }
Ejemplo n.º 2
0
        private int RunInternal(string[] args)
        {
            CefRuntime.Load();

            var settings = new CefSettings();

            settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            settings.SingleProcess            = false;
            settings.LogSeverity         = CefLogSeverity.Verbose;
            settings.LogFile             = HostConfig.CefLogFile;
            settings.ResourcesDirPath    = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;

            var argv = args;

            if (CefRuntime.Platform != CefRuntimePlatform.Windows)
            {
                argv = new string[args.Length + 1];
                Array.Copy(args, 0, argv, 1, args.Length);
                argv[0] = "-";
            }

            var mainArgs = new CefMainArgs(argv);
            var app      = new CefWebApp();

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

            Log.Info((string.Format("CefRuntime.ExecuteProcess() returns {0}", exitCode)));

            if (exitCode != -1)
            {
                // An error has occured.
                return(exitCode);
            }

            // guard if something wrong
            foreach (var arg in args)
            {
                if (arg.StartsWith("--type="))
                {
                    return(-2);
                }
            }

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

            RegisterSchemeHandlers();
            RegisterMessageRouters();

            PlatformInitialize();

            m_mainView = CreateMainView();

            PlatformRunMessageLoop();

            m_mainView.Dispose();
            m_mainView = null;

            CefRuntime.Shutdown();

            PlatformShutdown();
            return(0);
        }