Esempio n. 1
0
        protected override void OnCreate(ref CreateWindowPacket packet)
        {
            //For Windows 7 and above, best to include relevant app.manifest entries as well
            CefSharpGlobal.Cef.EnableHighDPISupport();

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

            m_settings = new CefSharpGlobal.CefSettings
            {
                LocalesDirPath           = localesDirPath,
                Locale                   = HostConfig.Locale,
                MultiThreadedMessageLoop = true,
                CachePath                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
                LogSeverity              = (CefSharpGlobal.LogSeverity)HostConfig.LogSeverity,
                LogFile                  = HostConfig.LogFile
            };

            // Update configuration settings
            m_settings.Update(HostConfig.CustomSettings);
            m_settings.UpdateCommandLineArgs(HostConfig.CommandLineArgs);

            RegisterSchemeHandlers();

            //Perform dependency check to make sure all relevant resources are in our output directory.
            CefSharpGlobal.Cef.Initialize(m_settings, performDependencyCheck: HostConfig.PerformDependencyCheck, browserProcessHandler: null);

            m_browser = new ChromiumWebBrowser(Handle, HostConfig.StartUrl);
            m_browser.IsBrowserInitializedChanged += IsBrowserInitializedChanged;
            m_browser.MenuHandler = new CefSharpContextMenuHandler();

            m_browser.RequestHandler = new CefSharpRequestHandler();
            RegisterJsHandlers();

            base.OnCreate(ref packet);

            Log.Info("Cef browser successfully created.");
        }
        public void SettingsUpdateTest()
        {
            var hostConfig = this.GetConfigWithDefaultValues();
            var settings   = new CefSharpGlobal.CefSettings
            {
                Locale = hostConfig.Locale,
                MultiThreadedMessageLoop = false,
                LogSeverity = (CefSharpGlobal.LogSeverity)hostConfig.LogSeverity,
                LogFile     = hostConfig.LogFile
            };

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

            Assert.True(settings.MultiThreadedMessageLoop);
            Assert.True(settings.ExternalMessagePump);
            Assert.True(settings.WindowlessRenderingEnabled);
            Assert.True(settings.CommandLineArgsDisabled);
            Assert.True(settings.PackLoadingDisabled);
            Assert.True(settings.IgnoreCertificateErrors);
            Assert.True(settings.FocusedNodeChangedEnabled);

            Assert.Equal(nameof(CefSettingKeys.BrowserSubprocessPath), settings.BrowserSubprocessPath);
            Assert.Equal(nameof(CefSettingKeys.CachePath), settings.CachePath);
            Assert.Equal(nameof(CefSettingKeys.UserDataPath), settings.UserDataPath);
            Assert.Equal(nameof(CefSettingKeys.UserAgent), settings.UserAgent);
            Assert.Equal(nameof(CefSettingKeys.ProductVersion), settings.ProductVersion);
            Assert.Equal(nameof(CefSettingKeys.Locale), settings.Locale);
            Assert.Equal(nameof(CefSettingKeys.LogFile), settings.LogFile);
            Assert.Equal(CefSharpGlobal.LogSeverity.Error, (CefSharpGlobal.LogSeverity)settings.LogSeverity);
            Assert.Equal(nameof(CefSettingKeys.JavaScriptFlags), settings.JavascriptFlags);
            Assert.Equal(nameof(CefSettingKeys.ResourcesDirPath), settings.ResourcesDirPath);
            Assert.Equal(nameof(CefSettingKeys.LocalesDirPath), settings.LocalesDirPath);
            Assert.Equal(nameof(CefSettingKeys.AcceptLanguageList), settings.AcceptLanguageList);

            Assert.Equal(1025, settings.RemoteDebuggingPort);
            Assert.Equal(1000, settings.UncaughtExceptionStackSize);
        }