Пример #1
0
        /// <inheritdoc/>
        protected override void OnAfterCreated(IWebBrowser chromiumWebBrowser, IBrowser browser)
        {
            if (browser.IsPopup)
            {
                var windowHandle = browser.GetHost().GetWindowHandle();

                //WinForms will kindly lookup the child control from it's handle
                //If no parentControl then likely it's a native popup created by CEF
                //(Devtools by default will open as a popup, at this point the Url hasn't been set, so
                // we're going with this assumption as it fits the use case currently)
                var control = Control.FromChildHandle(windowHandle) as ChromiumHostControl;

                //If control is null then we'll treat as a native popup (do nothing)
                //If control is disposed there's nothing for us to do either.
                if (control != null && !control.IsDisposed)
                {
                    control.BrowserHwnd = windowHandle;

                    control.InvokeOnUiThreadIfRequired(() =>
                    {
                        var interceptor     = new ParentFormMessageInterceptor(control);
                        interceptor.Moving += (sender, args) =>
                        {
                            if (!browser.IsDisposed)
                            {
                                browser?.GetHost()?.NotifyMoveOrResizeStarted();
                            }
                        };

                        popupParentFormMessageInterceptors.Add(browser.Identifier, interceptor);
                    });
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Called after browser created.
        /// </summary>
        /// <param name="browser">The browser.</param>
        void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
        {
            this.browser         = browser;
            IsBrowserInitialized = true;

            // By the time this callback gets called, this control
            // is most likely hooked into a browser Form of some sort.
            // (Which is what ParentFormMessageInterceptor relies on.)
            // Ensure the ParentFormMessageInterceptor construction occurs on the WinForms UI thread:
            if (UseParentFormMessageInterceptor)
            {
                this.InvokeOnUiThreadIfRequired(() =>
                {
                    parentFormMessageInterceptor = new ParentFormMessageInterceptor(this);
                });
            }

            ResizeBrowser();

            //If Load was called after the call to CreateBrowser we'll call Load
            //on the MainFrame
            if (!initialAddressLoaded && !string.IsNullOrEmpty(Address))
            {
                browser.MainFrame.LoadUrl(Address);
            }

            IsBrowserInitializedChanged?.Invoke(this, EventArgs.Empty);
        }
Пример #3
0
        /// <summary>
        /// Called after browser created.
        /// </summary>
        /// <param name="browser">The browser.</param>
        void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
        {
            this.browser         = browser;
            IsBrowserInitialized = true;

            //TODO: Revert temp workaround for default url not loading
            if (!string.IsNullOrEmpty(Address))
            {
                browser.MainFrame.LoadUrl(Address);
            }

            // By the time this callback gets called, this control
            // is most likely hooked into a browser Form of some sort.
            // (Which is what ParentFormMessageInterceptor relies on.)
            // Ensure the ParentFormMessageInterceptor construction occurs on the WinForms UI thread:
            if (UseParentFormMessageInterceptor)
            {
                this.InvokeOnUiThreadIfRequired(() =>
                {
                    parentFormMessageInterceptor = new ParentFormMessageInterceptor(this);
                });
            }

            ResizeBrowser();

            var handler = IsBrowserInitializedChanged;

            if (handler != null)
            {
                handler(this, new IsBrowserInitializedChangedEventArgs(IsBrowserInitialized));
            }
        }
Пример #4
0
        private void InternalDispose(bool disposing)
        {
            if (disposing)
            {
                Interlocked.Exchange(ref browserInitialized, 0);
                CanExecuteJavascriptInMainFrame = false;

                // Don't maintain a reference to event listeners anylonger:
                AddressChanged = null;
                ConsoleMessage = null;
                FrameLoadEnd   = null;
                FrameLoadStart = null;
                IsBrowserInitializedChanged = null;
                LoadError                 = null;
                LoadingStateChanged       = null;
                StatusMessage             = null;
                TitleChanged              = null;
                JavascriptMessageReceived = null;

                // Release reference to handlers, except LifeSpanHandler which is done after Disposing
                // ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
                // We also leave FocusHandler and override with a NoFocusHandler implementation as
                // it so we can block taking Focus (we're dispoing afterall). Issue #3715
                FreeHandlersExceptLifeSpanAndFocus();

                FocusHandler = new NoFocusHandler();

                browser = null;

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

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

                browserSettings = null;

                parkingControl?.Dispose();
                parkingControl = null;

                // LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
                // is called.
                LifeSpanHandler = null;
            }

            Cef.RemoveDisposable(this);
        }
Пример #5
0
        private void InternalDispose(bool disposing)
        {
            if (disposing)
            {
                CanExecuteJavascriptInMainFrame = false;
                IsBrowserInitialized            = false;

                // Don't maintain a reference to event listeners anylonger:
                AddressChanged = null;
                ConsoleMessage = null;
                FrameLoadEnd   = null;
                FrameLoadStart = null;
                IsBrowserInitializedChanged = null;
                LoadError                 = null;
                LoadingStateChanged       = null;
                StatusMessage             = null;
                TitleChanged              = null;
                JavascriptMessageReceived = null;

                // Release reference to handlers, except LifeSpanHandler which is done after Disposing
                // ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
                this.SetHandlersToNullExceptLifeSpan();

                browser = null;

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

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

                browserSettings = null;

                parkingControl?.Dispose();
                parkingControl = null;

                // LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
                // is called.
                LifeSpanHandler = null;
            }

            Cef.RemoveDisposable(this);
        }
Пример #6
0
        protected override void Dispose(bool disposing)
        {
            // Don't utilize any of the handlers anymore:
            DialogHandler          = null;
            JsDialogHandler        = null;
            KeyboardHandler        = null;
            RequestHandler         = null;
            DownloadHandler        = null;
            LifeSpanHandler        = null;
            MenuHandler            = null;
            DragHandler            = null;
            GeolocationHandler     = null;
            FocusHandler           = null;
            ResourceHandlerFactory = null;

            Cef.RemoveDisposable(this);

            if (disposing)
            {
                IsBrowserInitialized = false;

                if (BrowserSettings != null)
                {
                    BrowserSettings.Dispose();
                    BrowserSettings = null;
                }

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

                // Don't maintain a reference to event listeners anylonger:
                LoadError                   = null;
                FrameLoadStart              = null;
                FrameLoadEnd                = null;
                NavStateChanged             = null;
                ConsoleMessage              = null;
                StatusMessage               = null;
                AddressChanged              = null;
                TitleChanged                = null;
                IsBrowserInitializedChanged = null;
                IsLoadingChanged            = null;
            }
            base.Dispose(disposing);
        }
Пример #7
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            Cef.RemoveDisposable(this);

            if (disposing)
            {
                browser = null;
                IsBrowserInitialized = false;

                if (BrowserSettings != null)
                {
                    BrowserSettings.Dispose();
                    BrowserSettings = null;
                }

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

                // Don't maintain a reference to event listeners anylonger:
                LoadError                   = null;
                FrameLoadStart              = null;
                FrameLoadEnd                = null;
                LoadingStateChanged         = null;
                ConsoleMessage              = null;
                StatusMessage               = null;
                AddressChanged              = null;
                TitleChanged                = null;
                IsBrowserInitializedChanged = null;
            }

            // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter
            // otherwise the ILifeSpanHandler.DoClose will not be invoked.
            this.SetHandlersToNull();

            base.Dispose(disposing);
        }
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            // Don't utilize any of the handlers anymore:
            this.SetHandlersToNull();

            Cef.RemoveDisposable(this);

            if (disposing)
            {
                browser = null;
                IsBrowserInitialized = false;

                if (BrowserSettings != null)
                {
                    BrowserSettings.Dispose();
                    BrowserSettings = null;
                }

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

                // Don't maintain a reference to event listeners anylonger:
                LoadError                   = null;
                FrameLoadStart              = null;
                FrameLoadEnd                = null;
                LoadingStateChanged         = null;
                ConsoleMessage              = null;
                StatusMessage               = null;
                AddressChanged              = null;
                TitleChanged                = null;
                IsBrowserInitializedChanged = null;
            }
            base.Dispose(disposing);
        }
Пример #9
0
        private void InternalDispose(bool disposing)
        {
            if (disposing)
            {
                IsBrowserInitialized = false;

                // Don't maintain a reference to event listeners anylonger:
                AddressChanged = null;
                ConsoleMessage = null;
                FrameLoadEnd   = null;
                FrameLoadStart = null;
                IsBrowserInitializedChanged = null;
                LoadError           = null;
                LoadingStateChanged = null;
                StatusMessage       = null;
                TitleChanged        = null;

                // Release reference to handlers, except LifeSpanHandler which is done after Disposing
                // ManagedCefBrowserAdapter otherwise the ILifeSpanHandler.DoClose will not be invoked.
                this.SetHandlersToNullExceptLifeSpan();

                browser = null;

                if (parentFormMessageInterceptor != null)
                {
                    parentFormMessageInterceptor.Dispose();
                    parentFormMessageInterceptor = null;
                }

                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

                // LifeSpanHandler is set to null after managedCefBrowserAdapter.Dispose so ILifeSpanHandler.DoClose
                // is called.
                LifeSpanHandler = null;
            }

            Cef.RemoveDisposable(this);
        }
Пример #10
0
        /// <summary>
        /// Called after browser created.
        /// </summary>
        /// <param name="browser">The browser.</param>
        void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
        {
            this.browser         = browser;
            IsBrowserInitialized = true;

            // By the time this callback gets called, this control
            // is most likely hooked into a browser Form of some sort.
            // (Which is what ParentFormMessageInterceptor relies on.)
            // Ensure the ParentFormMessageInterceptor construction occurs on the WinForms UI thread:
            if (UseParentFormMessageInterceptor)
            {
                this.InvokeOnUiThreadIfRequired(() =>
                {
                    parentFormMessageInterceptor = new ParentFormMessageInterceptor(this);
                });
            }

            ResizeBrowser();

            IsBrowserInitializedChanged?.Invoke(this, new IsBrowserInitializedChangedEventArgs(IsBrowserInitialized));
        }
Пример #11
0
        /// <summary>
        /// Called after browser created.
        /// </summary>
        /// <param name="browser">The browser.</param>
        partial void OnAfterBrowserCreated(IBrowser browser)
        {
            BrowserCore = browser;
            BrowserHwnd = browser.GetHost().GetWindowHandle();

            // By the time this callback gets called, this control
            // is most likely hooked into a browser Form of some sort.
            // (Which is what ParentFormMessageInterceptor relies on.)
            // Ensure the ParentFormMessageInterceptor construction occurs on the WinForms UI thread:
            if (UseParentFormMessageInterceptor)
            {
                this.InvokeOnUiThreadIfRequired(() =>
                {
                    parentFormMessageInterceptor         = new ParentFormMessageInterceptor(this);
                    parentFormMessageInterceptor.Moving += (sender, args) =>
                    {
                        if (IsBrowserInitialized && !IsDisposed)
                        {
                            browser?.GetHost()?.NotifyMoveOrResizeStarted();
                        }
                    };
                });
            }

            ResizeBrowser(Width, Height);

            //If Load was called after the call to CreateBrowser we'll call Load
            //on the MainFrame
            if (!initialAddressLoaded && !string.IsNullOrEmpty(Address))
            {
                browser.MainFrame.LoadUrl(Address);
            }

            if (initialFocus)
            {
                browser.GetHost()?.SetFocus(true);
            }

            RaiseIsBrowserInitializedChangedEvent();
        }
Пример #12
0
        private void FreeUnmanagedResources()
        {
            browser = null;

            if (parentFormMessageInterceptor != null)
            {
                parentFormMessageInterceptor.Dispose();
                parentFormMessageInterceptor = null;
            }

            if (BrowserSettings != null)
            {
                BrowserSettings.Dispose();
                BrowserSettings = null;
            }

            if (managedCefBrowserAdapter != null)
            {
                managedCefBrowserAdapter.Dispose();
                managedCefBrowserAdapter = null;
            }
        }
Пример #13
0
        void IWebBrowserInternal.OnInitialized()
        {
            IsBrowserInitialized = true;

            // By the time this callback gets called, this control
            // is most likely hooked into a browser Form of some sort.
            // (Which is what ParentFormMessageInterceptor relies on.)
            // Ensure the ParentFormMessageInterceptor construction occurs on the WinForms UI thread:
            this.InvokeOnUiThreadIfRequired(() =>
            {
                parentFormMessageInterceptor = new ParentFormMessageInterceptor(this);
            });

            ResizeBrowser();

            var handler = IsBrowserInitializedChanged;

            if (handler != null)
            {
                handler(this, new IsBrowserInitializedChangedEventArgs(IsBrowserInitialized));
            }
        }