Example #1
0
        /// <summary>
        /// Create the underlying browser. The instance address, browser settings and request context will be used.
        /// </summary>
        /// <param name="windowHandle">Window handle if any, IntPtr.Zero is the default</param>
        /// <exception cref="System.Exception">An instance of the underlying offscreen browser has already been created, this method can only be called once.</exception>

        public void CreateBrowser(IntPtr windowHandle)
        {
            if (browserCreated)
            {
                throw new Exception("An instance of the underlying offscreen browser has already been created, this method can only be called once.");
            }

            browserCreated = true;

            managedCefBrowserAdapter.CreateOffscreenBrowser(windowHandle, BrowserSettings, (RequestContext)RequestContext, Address);
        }
Example #2
0
        /// <summary>
        /// Create a new OffScreen Chromium Browser
        /// </summary>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        public ChromiumWebBrowser(string address, BrowserSettings browserSettings = null)
        {
            if (!Cef.IsInitialized && !Cef.Initialize())
            {
                throw new InvalidOperationException("Cef::Initialize() failed");
            }

            ResourceHandler = new DefaultResourceHandler();

            Cef.AddDisposable(this);
            Address = address;

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
            managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, browserSettings ?? new BrowserSettings(), address);
        }
Example #3
0
        private void CreateOffscreenBrowserWhenActualSizeChanged()
        {
            if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            var webBrowserInternal = this as IWebBrowserInternal;

            if (!webBrowserInternal.HasParent)
            {
                managedCefBrowserAdapter.CreateOffscreenBrowser(source == null ? IntPtr.Zero : source.Handle, BrowserSettings, RequestContext, Address);
            }
            browserCreated = true;
        }
Example #4
0
        /// <summary>
        /// Create a new OffScreen Chromium Browser
        /// </summary>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        public ChromiumWebBrowser(string address, BrowserSettings browserSettings = null)
        {
            if (!Cef.IsInitialized && !Cef.Initialize())
            {
                throw new InvalidOperationException("Cef::Initialize() failed");
            }

            ResourceHandler = new DefaultResourceHandler();

            Cef.AddDisposable(this);
            Address = address;

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
            managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, browserSettings ?? new BrowserSettings(), address);
        }
Example #5
0
        /// <summary>
        /// Create the underlying Browser instance, can be overriden to defer control creation
        /// The browser will only be created when size > Size(0,0). If you specify a posative
        /// size then the browser will be created, if the ActualWidth and ActualHeight
        /// properties are in relatity still 0 then you'll likely end up with a browser that
        /// won't render.
        /// </summary>
        /// <param name="size">size of the current control, must be greater than Size(0, 0)</param>
        /// <returns>bool to indicate if browser was created. If the browser has already been created then this will return false.</returns>
        protected virtual bool CreateOffscreenBrowser(Size size)
        {
            if (browserCreated || System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) || size.IsEmpty || size.Equals(new Size(0, 0)))
            {
                return(false);
            }

            var webBrowserInternal = this as IWebBrowserInternal;

            if (!webBrowserInternal.HasParent)
            {
                managedCefBrowserAdapter.CreateOffscreenBrowser(source == null ? IntPtr.Zero : source.Handle, BrowserSettings, RequestContext, Address);
            }
            browserCreated = true;

            return(true);
        }
Example #6
0
        /// <summary>
        /// Create a new OffScreen Chromium Browser
        /// </summary>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        /// <param name="requestcontext">See <see cref="RequestContext"/> for more details. Defaults to null</param>
        public ChromiumWebBrowser(string address = "", BrowserSettings browserSettings = null, RequestContext requestcontext = null)
        {
            if (!Cef.IsInitialized && !Cef.Initialize())
            {
                throw new InvalidOperationException("Cef::Initialize() failed");
            }

            BitmapFactory = new BitmapFactory(BitmapLock);

            ResourceHandlerFactory = new DefaultResourceHandlerFactory();
            BrowserSettings = browserSettings ?? new BrowserSettings();
            RequestContext = requestcontext;

            Cef.AddDisposable(this);
            Address = address;

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
            managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, BrowserSettings, RequestContext, address);
        }
        /// <summary>
        /// Create a new OffScreen Chromium Browser.
        /// </summary>
        /// <param name="height">Height of browser</param>
        /// <param name="address">Initial address (url) to load</param>
        /// <param name="browserSettings">The browser settings to use. If null, the default settings are used.</param>
        /// <param name="requestcontext">See <see cref="RequestContext"/> for more details. Defaults to null</param>
        /// <param name="width">Width of browser</param>
        public ChromiumWebBrowserController(int width = 1366, int height = 768, string address = "",
                                            RequestContext requestcontext = null, BrowserSettings browserSettings = null)
        {
            if (!Cef.IsInitialized && !Cef.Initialize())
            {
                throw new InvalidOperationException("Cef::Initialize() failed");
            }

            size = new Size(width, height);
            ResourceHandlerFactory = new DefaultResourceHandlerFactory();
            BrowserSettings        = browserSettings ?? new BrowserSettings();
            RequestContext         = requestcontext;

            Cef.AddDisposable(this);
            Address = address;

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);
            managedCefBrowserAdapter.CreateOffscreenBrowser(IntPtr.Zero, BrowserSettings, RequestContext, address);
        }
Example #8
0
        public ChromiumWebBrowser()
        {
            Cef.AddDisposable(this);
            Focusable        = true;
            FocusVisualStyle = null;
            IsTabStop        = true;

            Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));

            Loaded   += OnLoaded;
            Unloaded += OnUnloaded;

            GotKeyboardFocus  += OnGotKeyboardFocus;
            LostKeyboardFocus += OnLostKeyboardFocus;

            IsVisibleChanged += OnIsVisibleChanged;

            ToolTip            = toolTip = new ToolTip();
            toolTip.StaysOpen  = true;
            toolTip.Visibility = Visibility.Collapsed;
            toolTip.Closed    += OnTooltipClosed;


            BackCommand       = new DelegateCommand(Back, () => CanGoBack);
            ForwardCommand    = new DelegateCommand(Forward, () => CanGoForward);
            ReloadCommand     = new DelegateCommand(Reload, () => CanReload);
            PrintCommand      = new DelegateCommand(Print);
            ZoomInCommand     = new DelegateCommand(ZoomIn);
            ZoomOutCommand    = new DelegateCommand(ZoomOut);
            ZoomResetCommand  = new DelegateCommand(ZoomReset);
            ViewSourceCommand = new DelegateCommand(ViewSource);
            CleanupCommand    = new DelegateCommand(Dispose);
            StopCommand       = new DelegateCommand(Stop);

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this);
            managedCefBrowserAdapter.CreateOffscreenBrowser(BrowserSettings ?? new BrowserSettings());

            disposables.Add(managedCefBrowserAdapter);

            disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged));
            disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged));
        }
Example #9
0
        /// <summary>
        /// Create the underlying browser. The instance address, browser settings and request context will be used.
        /// </summary>
        /// <param name="windowHandle">Window handle if any, IntPtr.Zero is the default</param>
        /// <param name="browserSettings">Browser initialization settings</param>
        /// <exception cref="System.Exception">An instance of the underlying offscreen browser has already been created, this method can only be called once.</exception>
        public void CreateBrowser(IntPtr windowHandle, BrowserSettings browserSettings = null)
        {
            if (browserCreated)
            {
                throw new Exception("An instance of the underlying offscreen browser has already been created, this method can only be called once.");
            }

            browserCreated = true;

            if (browserSettings == null)
            {
                browserSettings = new BrowserSettings();
            }

            //Dispose of browser settings after we've created the browser
            using (browserSettings)
            {
                managedCefBrowserAdapter.CreateOffscreenBrowser(windowHandle, browserSettings, (RequestContext)RequestContext, Address);
            }
        }
        public ChromiumWebBrowser()
        {
            Cef.AddDisposable(this);
            Focusable = true;
            FocusVisualStyle = null;
            IsTabStop = true;

            Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));

            Loaded += OnLoaded;
            Unloaded += OnUnloaded;

            GotKeyboardFocus += OnGotKeyboardFocus;
            LostKeyboardFocus += OnLostKeyboardFocus;

            IsVisibleChanged += OnIsVisibleChanged;

            ToolTip = toolTip = new ToolTip();
            toolTip.StaysOpen = true;
            toolTip.Visibility = Visibility.Collapsed;
            toolTip.Closed += OnTooltipClosed;

            BackCommand = new DelegateCommand(Back, () => CanGoBack);
            ForwardCommand = new DelegateCommand(Forward, () => CanGoForward);
            ReloadCommand = new DelegateCommand(Reload, () => CanReload);
            PrintCommand = new DelegateCommand(Print);
            ZoomInCommand = new DelegateCommand(ZoomIn);
            ZoomOutCommand = new DelegateCommand(ZoomOut);
            ZoomResetCommand = new DelegateCommand(ZoomReset);
            ViewSourceCommand = new DelegateCommand(ViewSource);
            CleanupCommand = new DelegateCommand(Dispose);
            StopCommand = new DelegateCommand(Stop);

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this);
            managedCefBrowserAdapter.CreateOffscreenBrowser(BrowserSettings ?? new BrowserSettings());

            disposables.Add(managedCefBrowserAdapter);

            disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged));
            disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged));
        }
Example #11
0
        public WebView()
        {
            Focusable = true;
            FocusVisualStyle = null;
            IsTabStop = true;

            Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));

            Loaded += OnLoaded;
            Unloaded += OnUnloaded;

            this.IsVisibleChanged += OnIsVisibleChanged;

            ToolTip = toolTip = new ToolTip();
            toolTip.StaysOpen = true;
            toolTip.Visibility = Visibility.Collapsed;
            toolTip.Closed += OnTooltipClosed;

            BackCommand = new DelegateCommand(Back, CanGoBack);
            ForwardCommand = new DelegateCommand(Forward, CanGoForward);
            ReloadCommand = new DelegateCommand(Reload, CanReload);

            browserCore = new BrowserCore("about:blank");
            browserCore.PropertyChanged += OnBrowserCorePropertyChanged;
            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this);
            managedCefBrowserAdapter.CreateOffscreenBrowser(BrowserSettings ?? new BrowserSettings());

            disposables.Add(managedCefBrowserAdapter);

            disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged));
            disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged));
        }