From e43befe9fab73eece5a4e85cf1394c2aa1acf74b Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 21 May 2015 10:57:18 +1000 Subject: [PATCH] Start to extract some duplicate code out into extension methods - saves repeating the same block three times --- CefSharp.OffScreen/ChromiumWebBrowser.cs | 12 +---------- CefSharp.WinForms/ChromiumWebBrowser.cs | 12 +---------- CefSharp.Wpf/ChromiumWebBrowser.cs | 14 ++----------- CefSharp/CefSharp.csproj | 1 + CefSharp/WebBrowserExtensions.cs | 26 ++++++++++++++++++++++++ 5 files changed, 31 insertions(+), 34 deletions(-) create mode 100644 CefSharp/WebBrowserExtensions.cs diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index f459c5d50..fcd992c83 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -109,17 +109,7 @@ namespace CefSharp.OffScreen 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; + this.SetHandlersToNull(); // Don't reference event listeners any longer: LoadError = null; diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 0ff8b32a9..689bd838b 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -102,17 +102,7 @@ namespace CefSharp.WinForms 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; + this.SetHandlersToNull(); Cef.RemoveDisposable(this); diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index ab59312f7..95a545f68 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -174,20 +174,10 @@ namespace CefSharp.Wpf FrameLoadEnd = null; LoadError = null; LoadingStateChanged = null; + Rendering = null; // No longer reference handlers: - ResourceHandlerFactory = null; - DialogHandler = null; - JsDialogHandler = null; - KeyboardHandler = null; - RequestHandler = null; - DownloadHandler = null; - LifeSpanHandler = null; - MenuHandler = null; - FocusHandler = null; - DragHandler = null; - GeolocationHandler = null; - Rendering = null; + this.SetHandlersToNull(); if (isdisposing) { diff --git a/CefSharp/CefSharp.csproj b/CefSharp/CefSharp.csproj index d234fbe9e..4a40c43d7 100644 --- a/CefSharp/CefSharp.csproj +++ b/CefSharp/CefSharp.csproj @@ -165,6 +165,7 @@ + diff --git a/CefSharp/WebBrowserExtensions.cs b/CefSharp/WebBrowserExtensions.cs new file mode 100644 index 000000000..3323113bc --- /dev/null +++ b/CefSharp/WebBrowserExtensions.cs @@ -0,0 +1,26 @@ +// Copyright © 2010-2015 The CefSharp Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +using CefSharp.Internals; + +namespace CefSharp +{ + internal static class WebBrowserExtensions + { + internal static void SetHandlersToNull(this IWebBrowserInternal browser) + { + browser.ResourceHandlerFactory = null; + browser.JsDialogHandler = null; + browser.DialogHandler = null; + browser.DownloadHandler = null; + browser.KeyboardHandler = null; + browser.LifeSpanHandler = null; + browser.MenuHandler = null; + browser.FocusHandler = null; + browser.RequestHandler = null; + browser.DragHandler = null; + browser.GeolocationHandler = null; + } + } +}