Пример #1
0
        /// <summary>
        /// Create a new texture renderer.
        /// </summary>
        /// <param name="logger">The logger to log to.</param>
        /// <param name="frameRate">
        /// The maximum rate in frames per second (fps) that CefRenderHandler::OnPaint will
        /// be called for a windowless browser. The actual fps may be lower if the browser
        /// cannot generate frames at the requested rate. The minimum value is 1 and the
        /// maximum value is 60 (default 30).
        /// </param>
        public HTMLTextureRenderer(ILogger logger, int frameRate)
        {
            Logger    = logger;
            FrameRate = VMath.Clamp(frameRate, MIN_FRAME_RATE, MAX_FRAME_RATE);

            FLoaded = false;

            var settings = new CefBrowserSettings();

            settings.FileAccessFromFileUrls = CefState.Enabled;
            settings.Plugins     = CefState.Enabled;
            settings.RemoteFonts = CefState.Enabled;
            settings.UniversalAccessFromFileUrls = CefState.Enabled;
            settings.WebGL               = CefState.Enabled;
            settings.WebSecurity         = CefState.Disabled;
            settings.WindowlessFrameRate = frameRate;

            var windowInfo = CefWindowInfo.Create();

            windowInfo.SetAsWindowless(IntPtr.Zero, true);

            FWebClient = new WebClient(this);
            // See http://magpcss.org/ceforum/viewtopic.php?f=6&t=5901
            // We need to maintain different request contexts in order to have different zoom levels
            // See https://bitbucket.org/chromiumembedded/cef/issues/1314
            var rcSettings = new CefRequestContextSettings()
            {
                IgnoreCertificateErrors = true
            };

            FRequestContext = CefRequestContext.CreateContext(rcSettings, new WebClient.RequestContextHandler());
            CefBrowserHost.CreateBrowser(windowInfo, FWebClient, settings, FRequestContext);
            // Block until browser is created
            FBrowserAttachedEvent.WaitOne();
        }
Пример #2
0
        private void CreateBrowser()
        {
            var windowInfo = CefWindowInfo.Create();

            windowInfo.SetTransparentPainting(true);

            windowInfo.SetAsOffScreen(IntPtr.Zero);
            windowInfo.Width  = this.Width;
            windowInfo.Height = this.Height;

            var browserSettings = new CefBrowserSettings
            {
                AcceleratedCompositing = CefState.Disabled,
                FileAccessFromFileUrls = CefState.Enabled,
                Java = CefState.Disabled,
                JavaScriptAccessClipboard = CefState.Disabled,
                JavaScriptCloseWindows    = CefState.Disabled,
                WebGL = CefState.Disabled,
            };

            CefBrowserHost.CreateBrowser(
                client: this,
                windowInfo: windowInfo,
                settings: browserSettings,
                requestContext: CefRequestContext.CreateContext(new RequestContextHandler(this.CookieDirectory)));
        }
Пример #3
0
        protected override void OnHandleCreated(EventArgs e)
        {
            if (DesignMode)
            {
                if (!_handleCreated)
                {
                    Paint += PaintInDesignMode;
                }
            }
            else
            {
                var windowInfo = CefWindowInfo.Create();
                windowInfo.SetAsChild(Handle, new CefRectangle {
                    X = 0, Y = 0, Width = Width, Height = Height
                });

                var client   = CreateWebClient();
                var settings = BrowserSettings;
                if (settings == null)
                {
                    settings = new CefBrowserSettings();
                    settings.AcceptLanguageList          = "zh-CN";          //设置默认为;
                    settings.FileAccessFromFileUrls      = CefState.Enabled; // CefCommandLine.Create("allow-access-from.file");
                    settings.UniversalAccessFromFileUrls = CefState.Enabled;
                    settings.ApplicationCache            = CefState.Enabled;
                    settings.JavaScript = CefState.Enabled;
                    settings.JavaScriptAccessClipboard = CefState.Enabled;
                    settings.JavaScriptDomPaste        = CefState.Enabled;
                    settings.LocalStorage               = CefState.Enabled;
                    settings.WebGL                      = CefState.Disabled;
                    settings.Databases                  = CefState.Enabled;
                    settings.ImageLoading               = CefState.Enabled;
                    settings.WebSecurity                = CefState.Enabled;
                    settings.JavaScriptCloseWindows     = CefState.Enabled;
                    settings.DefaultEncoding            = "UTF8";
                    settings.ImageLoading               = CefState.Enabled;
                    settings.ImageShrinkStandaloneToFit = CefState.Enabled;
                }


                //判断隔离独立页面的Cookie
                if (multiUsersMode)
                {
                    tabIndexNumber++;
                    CefRequestContextSettings contextSettings = new CefRequestContextSettings();
                    contextSettings.PersistSessionCookies   = false;
                    contextSettings.PersistUserPreferences  = true;
                    contextSettings.AcceptLanguageList      = "zh-CN";
                    contextSettings.IgnoreCertificateErrors = true;
                    CefWebRequestContextHandler requestContextHandler = new CefWebRequestContextHandler();
                    CefRequestContext           requestContext        = CefRequestContext.CreateContext(contextSettings, requestContextHandler);
                    CefBrowserHost.CreateBrowser(windowInfo, client, settings, StartUrl, null, requestContext); //隔离Cookie
                    contextSettings = null;
                    requestContext  = null;

                    GC.Collect();
                }
                else
                {
                    //CefRequestContextSettings contextSettings = new CefRequestContextSettings();
                    //contextSettings.PersistSessionCookies = true;
                    //contextSettings.PersistUserPreferences = true;
                    //contextSettings.CachePath = GetAppDir("Cache");
                    //contextSettings.AcceptLanguageList = "zh-CN";
                    //// contextSettings.EnableNetSecurityExpiration = false;
                    //contextSettings.IgnoreCertificateErrors = true;
                    //CefWebRequestContextHandler requestContextHandler = new CefWebRequestContextHandler();

                    //CefRequestContext requestContext = CefRequestContext.CreateContext(contextSettings, requestContextHandler);
                    //CefBrowserHost.CreateBrowser(windowInfo, client, settings, StartUrl, null, requestContext);
                    //contextSettings = null;
                    //requestContext = null;

                    //GC.Collect();
                    CefBrowserHost.CreateBrowser(windowInfo, client, settings, StartUrl);
                }
                windowInfo = null;
                client     = null;
                settings   = null;
                GC.Collect();
            }

            _handleCreated = true;
            base.OnHandleCreated(e);
        }