Ejemplo n.º 1
0
        protected virtual void Dispose(bool isdisposing)
        {
            // No longer reference event listeners:
            ConsoleMessage      = null;
            FrameLoadStart      = null;
            FrameLoadEnd        = null;
            LoadError           = null;
            LoadingStateChanged = null;
            Rendering           = null;

            // No longer reference handlers:
            this.SetHandlersToNull();

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

                PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler);

                // Release internal event listeners:
                Loaded            -= OnLoaded;
                GotKeyboardFocus  -= OnGotKeyboardFocus;
                LostKeyboardFocus -= OnLostKeyboardFocus;

                // Release internal event listeners for Drag Drop events:
                DragEnter -= OnDragEnter;
                DragOver  -= OnDragOver;
                DragLeave -= OnDragLeave;
                Drop      -= OnDrop;

                IsVisibleChanged -= OnIsVisibleChanged;

                if (tooltipTimer != null)
                {
                    tooltipTimer.Tick -= OnTooltipTimerTick;
                }

                if (CleanupElement != null)
                {
                    CleanupElement.Unloaded -= OnCleanupElementUnloaded;
                }

                foreach (var disposable in disposables)
                {
                    disposable.Dispose();
                }
                disposables.Clear();
                UiThreadRunAsync(() => WebBrowser = null);
            }

            Cef.RemoveDisposable(this);

            RemoveSourceHook();

            managedCefBrowserAdapter = null;
        }
Ejemplo n.º 2
0
        private void Dispose(bool disposing)
        {
            ClearHandlers();
            ClearEventListeners();

            Cef.RemoveDisposable(this);

            if (!disposing)
            {
                return;
            }

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

            if (managedCefBrowserAdapter != null)
            {
                if (!managedCefBrowserAdapter.IsDisposed)
                {
                    managedCefBrowserAdapter.Dispose();
                }
                managedCefBrowserAdapter = null;
            }
        }
Ejemplo n.º 3
0
        protected virtual void Dispose(bool isdisposing)
        {
            Loaded   -= OnLoaded;
            Unloaded -= OnUnloaded;

            GotKeyboardFocus  -= OnGotKeyboardFocus;
            LostKeyboardFocus -= OnLostKeyboardFocus;

            IsVisibleChanged -= OnIsVisibleChanged;

            Cef.RemoveDisposable(this);

            RemoveSourceHook();

            foreach (var disposable in disposables)
            {
                disposable.Dispose();
            }
            disposables.Clear();

            UiThreadRunAsync(() => WebBrowser = null);
            managedCefBrowserAdapter          = null;
            ConsoleMessage = null;
            FrameLoadStart = null;
            FrameLoadEnd   = null;
            LoadError      = null;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
        protected virtual void Dispose(bool disposing)
        {
            // Don't reference handlers any longer:
            ResourceHandlerFactory = null;
            JsDialogHandler        = null;
            DialogHandler          = null;
            DownloadHandler        = null;
            KeyboardHandler        = null;
            LifeSpanHandler        = null;
            MenuHandler            = null;
            FocusHandler           = null;
            RequestHandler         = null;
            DragHandler            = null;
            GeolocationHandler     = null;

            // Don't reference event listeners any longer:
            LoadError          = null;
            FrameLoadStart     = null;
            FrameLoadEnd       = null;
            ConsoleMessage     = null;
            BrowserInitialized = null;
            StatusMessage      = null;
            NavStateChanged    = null;
            AddressChanged     = null;
            IsLoadingChanged   = null;

            Cef.RemoveDisposable(this);

            if (disposing)
            {
                IsBrowserInitialized = false;

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

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

                if (managedCefBrowserAdapter != null)
                {
                    if (!managedCefBrowserAdapter.IsDisposed)
                    {
                        managedCefBrowserAdapter.Dispose();
                    }
                    managedCefBrowserAdapter = null;
                }
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources for the <see cref="ChromiumWebBrowser"/>
        /// </summary>
        /// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            // Attempt to move the disposeSignaled state from 0 to 1. If successful, we can be assured that
            // this thread is the first thread to do so, and can safely dispose of the object.
            if (Interlocked.CompareExchange(ref disposeSignaled, 1, 0) != 0)
            {
                return;
            }

            if (disposing)
            {
                CanExecuteJavascriptInMainFrame = false;
                Interlocked.Exchange(ref browserInitialized, 0);

                // Don't reference event listeners any longer:
                AddressChanged      = null;
                BrowserInitialized  = null;
                ConsoleMessage      = null;
                FrameLoadEnd        = null;
                FrameLoadStart      = null;
                LoadError           = null;
                LoadingStateChanged = null;
                Paint                     = null;
                AfterPaint                = 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;
                BrowserCore = 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);
        }
Ejemplo n.º 9
0
        protected override void Dispose(bool disposing)
        {
            Cef.RemoveDisposable(this);

            if (disposing)
            {
                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources for the <see cref="ChromiumWebBrowser"/>
        /// </summary>
        /// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            // Attempt to move the disposeSignaled state from 0 to 1. If successful, we can be assured that
            // this thread is the first thread to do so, and can safely dispose of the object.
            if (Interlocked.CompareExchange(ref disposeSignaled, 1, 0) != 0)
            {
                return;
            }

            if (disposing)
            {
                IsBrowserInitialized = false;

                // Don't reference event listeners any longer:
                AddressChanged      = null;
                BrowserInitialized  = null;
                ConsoleMessage      = null;
                FrameLoadEnd        = null;
                FrameLoadStart      = null;
                LoadError           = null;
                LoadingStateChanged = null;
                Paint                     = null;
                AfterPaint                = 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 (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }

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

            Cef.RemoveDisposable(this);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            // Don't reference event listeners any longer:
            LoadError           = null;
            FrameLoadStart      = null;
            FrameLoadEnd        = null;
            ConsoleMessage      = null;
            BrowserInitialized  = null;
            StatusMessage       = null;
            LoadingStateChanged = null;
            AddressChanged      = null;

            Cef.RemoveDisposable(this);

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

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

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

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

            // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter
            // otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version,
            // we do it here for consistency)
            this.SetHandlersToNull();
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        protected virtual void Dispose(bool disposing)
        {
            // Don't reference handlers any longer:
            this.SetHandlersToNull();

            // Don't reference event listeners any longer:
            LoadError           = null;
            FrameLoadStart      = null;
            FrameLoadEnd        = null;
            ConsoleMessage      = null;
            BrowserInitialized  = null;
            StatusMessage       = null;
            LoadingStateChanged = null;
            AddressChanged      = null;

            Cef.RemoveDisposable(this);

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

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

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

                if (managedCefBrowserAdapter != null)
                {
                    if (!managedCefBrowserAdapter.IsDisposed)
                    {
                        managedCefBrowserAdapter.Dispose();
                    }
                    managedCefBrowserAdapter = null;
                }
            }
        }
        /// <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);
        }
Ejemplo n.º 15
0
        protected virtual void Dispose(bool isdisposing)
        {
            Cef.RemoveDisposable(this);

            foreach (var disposable in disposables)
            {
                disposable.Dispose();
            }
            disposables.Clear();

            RemoveSourceHook();

            DoInUi(() => WebBrowser  = null);
            managedCefBrowserAdapter = null;
            ConsoleMessage           = null;
            FrameLoadStart           = null;
            FrameLoadEnd             = null;
            LoadError = null;
        }
Ejemplo n.º 16
0
        protected override void Dispose(bool disposing)
        {
            FocusHandler    = null;
            ResourceHandler = null;
            BrowserSettings.Dispose();
            BrowserSettings = null;

            Cef.RemoveDisposable(this);

            if (disposing)
            {
                if (managedCefBrowserAdapter != null)
                {
                    managedCefBrowserAdapter.Dispose();
                    managedCefBrowserAdapter = null;
                }
            }
            base.Dispose(disposing);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
0
        public void Dispose()
        {
            Cef.RemoveDisposable(this);

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

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

            GC.SuppressFinalize(this);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources for the <see cref="ChromiumWebBrowser"/>
        /// </summary>
        /// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            // Attempt to move the disposeSignaled state from 0 to 1. If successful, we can be assured that
            // this thread is the first thread to do so, and can safely dispose of the object.
            if (Interlocked.CompareExchange(ref disposeSignaled, 1, 0) != 0)
            {
                return;
            }

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

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

                // Don't reference event listeners any longer:
                AddressChanged      = null;
                BrowserInitialized  = null;
                ConsoleMessage      = null;
                FrameLoadEnd        = null;
                FrameLoadStart      = null;
                LoadError           = null;
                LoadingStateChanged = null;
                Paint         = null;
                StatusMessage = null;
                TitleChanged  = null;

                // Release reference to handlers, make sure this is done after we dispose managedCefBrowserAdapter
                // otherwise the ILifeSpanHandler.DoClose will not be invoked. (More important in the WinForms version,
                // we do it here for consistency)
                this.SetHandlersToNull();
            }

            Cef.RemoveDisposable(this);
        }
Ejemplo n.º 20
0
        protected virtual void Dispose(bool isdisposing)
        {
            PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler);

            BrowserSettings.Dispose();

            BrowserSettings = null;
            ResourceHandler = null;

            Loaded -= OnLoaded;

            GotKeyboardFocus  -= OnGotKeyboardFocus;
            LostKeyboardFocus -= OnLostKeyboardFocus;

            // Drag Drop events
            DragEnter -= OnDragEnter;
            DragOver  -= OnDragOver;
            DragLeave -= OnDragLeave;
            Drop      -= OnDrop;

            IsVisibleChanged -= OnIsVisibleChanged;

            Cef.RemoveDisposable(this);

            foreach (var disposable in disposables)
            {
                disposable.Dispose();
            }
            disposables.Clear();

            UiThreadRunAsync(() => WebBrowser = null);
            managedCefBrowserAdapter          = null;
            ConsoleMessage = null;
            FrameLoadStart = null;
            FrameLoadEnd   = null;
            LoadError      = null;
        }
Ejemplo n.º 21
0
 private void RemoveFromListOfCefBrowsers()
 {
     Cef.RemoveDisposable(this);
 }
Ejemplo n.º 22
0
        protected virtual void Dispose(bool isdisposing)
        {
            //Check if alreadty disposed
            if (Interlocked.Increment(ref disposeCount) == 1)
            {
                // No longer reference event listeners:
                ConsoleMessage      = null;
                FrameLoadStart      = null;
                FrameLoadEnd        = null;
                LoadError           = null;
                LoadingStateChanged = null;
                Rendering           = null;

                // No longer reference handlers:
                this.SetHandlersToNull();

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

                    PresentationSource.RemoveSourceChangedHandler(this, PresentationSourceChangedHandler);

                    // Release internal event listeners:
                    Loaded            -= OnLoaded;
                    SizeChanged       -= OnActualSizeChanged;
                    GotKeyboardFocus  -= OnGotKeyboardFocus;
                    LostKeyboardFocus -= OnLostKeyboardFocus;

                    // Release internal event listeners for Drag Drop events:
                    DragEnter -= OnDragEnter;
                    DragOver  -= OnDragOver;
                    DragLeave -= OnDragLeave;
                    Drop      -= OnDrop;

                    IsVisibleChanged -= OnIsVisibleChanged;

                    if (tooltipTimer != null)
                    {
                        tooltipTimer.Tick -= OnTooltipTimerTick;
                    }

                    if (CleanupElement != null)
                    {
                        CleanupElement.Unloaded -= OnCleanupElementUnloaded;
                    }

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


                    browserInitialized = false;
                    UiThreadRunAsync(() =>
                    {
                        SetCurrentValue(IsBrowserInitializedProperty, false);
                        WebBrowser = null;
                    });
                }

                Cef.RemoveDisposable(this);

                RemoveSourceHook();
            }
        }