Пример #1
0
        public FrameworkElement GetElement(DpiAwareWindow parentWindow, bool preferTransparentBackground)
        {
            if (_inner == null || _wrapper == null)
            {
                DisposeHelper.Dispose(ref _inner);
                DisposeHelper.Dispose(ref _wrapper);
                CefSharpHelper.EnsureInitialized();

                _downloadHandler = new DownloadHandler();
                _requestHandler  = new RequestHandler {
                    UserAgent = CefSharpHelper.DefaultUserAgent
                };
                _requestHandler.Inject  += OnRequestHandlerInject;
                _requestHandler.Headers += OnRequestHandlerHeaders;

                _inner = new ChromiumWebBrowser(@"about:blank")
                {
                    BrowserSettings =
                    {
                        FileAccessFromFileUrls      = CefState.Enabled,
                        UniversalAccessFromFileUrls = CefState.Enabled,
                        BackgroundColor             =        0xff000000,

                        // For SRS to work, because IsCSPBypassing somehow doesn’t work!
                        WebSecurity                 = CefState.Disabled,
                    },
                    DisplayHandler  = this,
                    DownloadHandler = _downloadHandler,
                    RequestHandler  = _requestHandler,
                    KeyboardHandler = new KeyboardHandler()
                                      // MenuHandler = new MenuHandler(),
                                      // JsDialogHandler = new JsDialogHandler(),
                };

                _inner.FrameLoadStart      += OnFrameLoadStart;
                _inner.FrameLoadEnd        += OnFrameLoadEnd;
                _inner.LoadingStateChanged += OnLoadingStateChanged;
                _inner.LoadError           += OnLoadError;
                _wrapper = new WindowsFormsHost {
                    Child = _inner
                };
            }

            return(_wrapper);
        }
Пример #2
0
        public FrameworkElement GetElement(DpiAwareWindow parentWindow, bool preferTransparentBackground)
        {
            if (_inner == null)
            {
                CefSharpHelper.EnsureInitialized();
                Initialize(preferTransparentBackground);
                if (_inner == null)
                {
                    throw new Exception(@"Initialization failed");
                }
            }

            _zoomLevel = parentWindow?.ScaleX ?? 1d;
            if (_zoomLevel > 1d)
            {
                _inner.LayoutTransform = new ScaleTransform {
                    ScaleX = 1d / _zoomLevel, ScaleY = 1d / _zoomLevel
                };
                _inner.SetBinding(FrameworkElement.WidthProperty, new Binding {
                    Path               = new PropertyPath(FrameworkElement.ActualWidthProperty),
                    Source             = _wrapper,
                    Converter          = new MultiplyConverter(),
                    ConverterParameter = _zoomLevel
                });
                _inner.SetBinding(FrameworkElement.HeightProperty, new Binding {
                    Path               = new PropertyPath(FrameworkElement.ActualHeightProperty),
                    Source             = _wrapper,
                    Converter          = new MultiplyConverter(),
                    ConverterParameter = _zoomLevel
                });
            }
            else
            {
                _inner.LayoutTransform = Transform.Identity;
                _inner.ClearValue(FrameworkElement.WidthProperty);
                _inner.ClearValue(FrameworkElement.HeightProperty);
            }

            RenderOptions.SetBitmapScalingMode(_inner, _zoomLevel >= 1d ? BitmapScalingMode.NearestNeighbor : BitmapScalingMode.HighQuality);
            return(_wrapper);
        }
Пример #3
0
        public FrameworkElement GetElement(DpiAwareWindow parentWindow, bool preferTransparentBackground)
        {
            if (_inner == null)
            {
                CefSharpHelper.EnsureInitialized();

                _downloadHandler = new DownloadHandler();
                _requestHandler  = new RequestHandler {
                    UserAgent = CefSharpHelper.DefaultUserAgent
                };
                _requestHandler.Inject += OnRequestHandlerInject;

                _inner = new ChromiumWebBrowser {
                    BrowserSettings =
                    {
                        FileAccessFromFileUrls      = CefState.Enabled,
                        UniversalAccessFromFileUrls = CefState.Enabled,
                        BackgroundColor             = preferTransparentBackground ? 0U : 0xffffffff,
                        WindowlessFrameRate         = SettingsHolder.Plugins.Cef60Fps ? 60 : 30,
                        WebGl   = CefState.Disabled,
                        Plugins = CefState.Disabled,

                        // For SRS to work, because IsCSPBypassing somehow doesn’t work!
                        WebSecurity                 = CefState.Disabled,
                    },
                    DisplayHandler  = this,
                    DownloadHandler = _downloadHandler,
                    RequestHandler  = _requestHandler,
                    MenuHandler     = new MenuHandler(),
                    JsDialogHandler = new JsDialogHandler(),
                    KeyboardHandler = new KeyboardHandler(),
                    Background      = new SolidColorBrush(preferTransparentBackground ? Colors.Transparent : Colors.White),
                };

                RenderOptions.SetBitmapScalingMode(_inner, BitmapScalingMode.NearestNeighbor);
                _inner.FrameLoadStart      += OnFrameLoadStart;
                _inner.FrameLoadEnd        += OnFrameLoadEnd;
                _inner.LoadingStateChanged += OnLoadingStateChanged;
                _inner.LoadError           += OnLoadError;
                _wrapper = new Border {
                    Child = _inner
                };
            }

            _zoomLevel = parentWindow?.ScaleX ?? 1d;
            if (_zoomLevel > 1d)
            {
                _inner.LayoutTransform = new ScaleTransform {
                    ScaleX = 1d / _zoomLevel, ScaleY = 1d / _zoomLevel
                };
                _inner.SetBinding(FrameworkElement.WidthProperty, new Binding {
                    Path               = new PropertyPath(FrameworkElement.ActualWidthProperty),
                    Source             = _wrapper,
                    Converter          = new MultiplyConverter(),
                    ConverterParameter = _zoomLevel
                });
                _inner.SetBinding(FrameworkElement.HeightProperty, new Binding {
                    Path               = new PropertyPath(FrameworkElement.ActualHeightProperty),
                    Source             = _wrapper,
                    Converter          = new MultiplyConverter(),
                    ConverterParameter = _zoomLevel
                });
            }
            else
            {
                _inner.LayoutTransform = Transform.Identity;
                _inner.ClearValue(FrameworkElement.WidthProperty);
                _inner.ClearValue(FrameworkElement.HeightProperty);
            }

            RenderOptions.SetBitmapScalingMode(_inner, _zoomLevel >= 1d ? BitmapScalingMode.NearestNeighbor : BitmapScalingMode.HighQuality);
            return(_wrapper);
        }