Esempio 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, IBrowserSettings 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 = Core.ObjectFactory.CreateBrowserSettings(autoDispose: true);
            }

            if (windowInfo == null)
            {
                windowInfo = Core.ObjectFactory.CreateWindowInfo();
                windowInfo.SetAsWindowless(IntPtr.Zero);
            }

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

            //Dispose of BrowserSettings if we created it, if user created then they're responsible
            if (browserSettings.AutoDispose)
            {
                browserSettings.Dispose();
            }
            browserSettings = null;
        }
Esempio 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);

                    //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, requestContext, Address);
                }
            }
        }
Esempio n. 3
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, _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.");
            }
        }
Esempio n. 4
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, IBrowserSettings 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 = Core.ObjectFactory.CreateBrowserSettings(autoDispose: true);
            }

            if (windowInfo == null)
            {
                windowInfo = Core.ObjectFactory.CreateWindowInfo();
                windowInfo.SetAsWindowless(IntPtr.Zero);
            }

            //TODO: We need some sort of timeout and
            //if we use the same approach for WPF/WinForms then
            //we need to move the common code into the partial class
            GlobalContextInitialized.ExecuteOrEnqueue((success) =>
            {
                if (!success)
                {
                    return;
                }

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

                //Dispose of BrowserSettings if we created it, if user created then they're responsible
                if (browserSettings.AutoDispose)
                {
                    browserSettings.Dispose();
                }
                browserSettings = null;
            });
        }