Exemplo n.º 1
0
        /// <summary>
        /// Create the underlying browser. The instance address, browser settings and request context will be used.
        /// </summary>
        /// <param name="windowInfo">Window information used when creating the browser</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(IWindowInfo windowInfo = null, 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(frameworkCreated: true);
            }

            if (windowInfo == null)
            {
                windowInfo = new WindowInfo();
                windowInfo.SetAsWindowless(IntPtr.Zero);
            }

            managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings, (RequestContext)RequestContext, Address);

            //Dispose of BrowserSettings if we created it, if user created then they're responsible
            if (browserSettings.FrameworkCreated)
            {
                browserSettings.Dispose();
            }
            browserSettings = null;
        }
Exemplo n.º 2
0
        private void CreateBrowser()
        {
            browserCreated = true;

            if (((IWebBrowserInternal)this).HasParent == false)
            {
                //If we are Recreating our handle we will have re-parented our
                //browser to parkingControl. We'll assign the browser to our newly
                //created handle now.
                if ((RecreatingHandle || ParkControlOnHandleDestroyed) && IsBrowserInitialized && browser != null)
                {
                    var host = this.GetBrowserHost();
                    var hwnd = host.GetWindowHandle();

                    NativeMethodWrapper.SetWindowParent(hwnd, Handle);

                    parkingControl.Dispose();
                    parkingControl = null;
                }
                else
                {
                    var windowInfo = CreateBrowserWindowInfo(Handle);

                    initialAddressLoaded = !string.IsNullOrEmpty(Address);

                    managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings as BrowserSettings, requestContext as RequestContext, Address);
                }
            }
        }
Exemplo n.º 3
0
        private void CreateBrowser()
        {
            browserCreated = true;

            if (((IWebBrowserInternal)this).HasParent == false)
            {
                //If we are Recreating our handle we will have re-parented our
                //browser to parkingControl. We'll assign the browser to our newly
                //created handle now.
                if ((RecreatingHandle || ParkControlOnHandleDestroyed) && IsBrowserInitialized && browser != null)
                {
                    var host = this.GetBrowserHost();
                    var hwnd = host.GetWindowHandle();

                    NativeMethodWrapper.SetWindowParent(hwnd, Handle);

                    parkingControl.Dispose();
                    parkingControl = null;
                }
                else
                {
                    var windowInfo = CreateBrowserWindowInfo(Handle);

                    //We actually check if WS_EX_NOACTIVATE was set for instances
                    //the user has override CreateBrowserWindowInfo and not called base.CreateBrowserWindowInfo
                    removeExNoActivateStyle = (windowInfo.ExStyle & WS_EX_NOACTIVATE) == WS_EX_NOACTIVATE;

                    initialAddressLoaded = !string.IsNullOrEmpty(Address);

                    managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings as BrowserSettings, requestContext as RequestContext, Address);
                }
            }
        }
Exemplo n.º 4
0
 private void CreateBrowser()
 {
     if (((IWebBrowserInternal)this).HasParent == false)
     {
         managedCefBrowserAdapter.CreateBrowser(BrowserSettings, RequestContext, Handle, Address);
     }
 }
Exemplo n.º 5
0
        internal void CreateBrowser(IntPtr parent)
        {
            if (((IWebBrowserInternal)this).HasParent == false)
            {
                if (IsBrowserInitialized == false || _browser == null)
                {
                    _requestContext = Cef.GetGlobalRequestContext();

                    var windowInfo = CreateBrowserWindowInfo(parent);

                    //We actually check if WS_EX_NOACTIVATE was set for instances
                    //the user has override CreateBrowserWindowInfo and not called base.CreateBrowserWindowInfo
                    _removeExNoActivateStyle = ((WS_EX)windowInfo.ExStyle & WS_EX.NOACTIVATE) == WS_EX.NOACTIVATE;

                    _initialAddressLoaded = !string.IsNullOrEmpty(_config?.StartUrl);
                    Address = _config?.StartUrl;

                    _browserSettings.DefaultEncoding             = "UTF-8";
                    _browserSettings.FileAccessFromFileUrls      = CefState.Enabled;
                    _browserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
                    _browserSettings.WebSecurity = CefState.Disabled;

                    _managedCefBrowserAdapter.CreateBrowser(windowInfo, _browserSettings as BrowserSettings, _requestContext as RequestContext, Address);
                }
                else
                {
                    // If the browser already exists we'll reparent it to the new Handle
                    var browserHandle = _browser.GetHost().GetWindowHandle();
                    NativeMethodWrapper.SetWindowParent(browserHandle, parent);
                }

                Logger.Instance.Log.LogInformation("Cef browser successfully created.");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create the underlying browser. The instance address, browser settings and request context will be used.
        /// </summary>
        /// <param name="windowInfo">Window information used when creating the browser</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(IWindowInfo windowInfo = null, 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();
            }
            else if (browserSettings.IsDisposed)
            {
                throw new ObjectDisposedException("browserSettings", "The BrowserSettings reference you have passed has already been disposed. You cannot reuse the BrowserSettings class");
            }

            if (windowInfo == null)
            {
                windowInfo = new WindowInfo();
                windowInfo.SetAsWindowless(IntPtr.Zero);
            }

            //Dispose of browser settings after we've created the browser
            using (browserSettings)
            {
                managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings, (RequestContext)RequestContext, Address);
            }
        }
Exemplo n.º 7
0
        private void CreateBrowser()
        {
            browserCreated = true;

            if (((IWebBrowserInternal)this).HasParent == false)
            {
                if (IsBrowserInitialized == false || browser == null)
                {
                    var windowInfo = new WindowInfo();
                    windowInfo.SetAsChild(Handle);

                    managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings, (RequestContext)RequestContext, Address);

                    if (browserSettings != null)
                    {
                        browserSettings.Dispose();
                        browserSettings = null;
                    }
                }
                else
                {
                    //If the browser already exists we'll reparent it to the new Handle
                    var browserHandle = browser.GetHost().GetWindowHandle();
                    NativeMethodWrapper.SetWindowParent(browserHandle, Handle);
                }
            }
        }
Exemplo n.º 8
0
        protected override void OnHandleCreated(EventArgs e)
        {
            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this);
            managedCefBrowserAdapter.CreateBrowser(BrowserSettings ?? new BrowserSettings(), Handle, Address);

            base.OnHandleCreated(e);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.HandleCreated" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnHandleCreated(EventArgs e)
        {
            if (((IWebBrowserInternal)this).HasParent == false)
            {
                managedCefBrowserAdapter.CreateBrowser(BrowserSettings, RequestContext, Handle, Address);
            }

            base.OnHandleCreated(e);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChromiumWebBrowser"/> class.
        /// </summary>
        /// <param name="address">The address.</param>
        public ChromiumWebBrowser(IntPtr parent, string address)
        {
            Address = address;

            InitializeFieldsAndCefIfRequired();

            if (((IWebBrowserInternal)this).HasParent == false)
            {
                managedCefBrowserAdapter.CreateBrowser(BrowserSettings, RequestContext, parent, Address);
            }
        }
Exemplo n.º 11
0
        private void CreateBrowser()
        {
            browserCreated = true;

            if (((IWebBrowserInternal)this).HasParent == false)
            {
                if (IsBrowserInitialized == false || browser == null)
                {
                    //TODO: Revert temp workaround for default url not loading
                    managedCefBrowserAdapter.CreateBrowser(BrowserSettings, (RequestContext)RequestContext, Handle, null);
                }
                else
                {
                    //If the browser already exists we'll reparent it to the new Handle
                    var browserHandle = browser.GetHost().GetWindowHandle();
                    NativeMethodWrapper.SetWindowParent(browserHandle, Handle);
                }
            }
        }
Exemplo n.º 12
0
        private void CreateBrowser()
        {
            browserCreated = true;

            if (((IWebBrowserInternal)this).HasParent == false)
            {
                if (IsBrowserInitialized == false || browser == null)
                {
                    var windowInfo = CreateBrowserWindowInfo(Handle);

                    initialAddressLoaded = !string.IsNullOrEmpty(Address);

                    managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings as BrowserSettings, requestContext as RequestContext, Address);

                    browserSettings = null;
                }
                else
                {
                    //If the browser already exists we'll reparent it to the new Handle
                    var browserHandle = browser.GetHost().GetWindowHandle();
                    NativeMethodWrapper.SetWindowParent(browserHandle, Handle);
                }
            }
        }
Exemplo n.º 13
0
 protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this);
     managedCefBrowserAdapter.CreateBrowser(BrowserSettings ?? new BrowserSettings(), Handle, Address);
 }