From fd9d52ebeb063318aa66a0a646fd474dedfb2f3a Mon Sep 17 00:00:00 2001 From: Alex Maitland Date: Thu, 28 Feb 2019 15:01:57 +1000 Subject: [PATCH] WinForms ChromiumWebBrowser - Change BrowserSettings property to use IBrowserSettings Should resolve issue with WinForms Designer Also make IBrowserSettings inherit from IDisposable. Issue #2667 --- CefSharp.WinForms/ChromiumWebBrowser.cs | 10 +++++++--- CefSharp/IBrowserSettings.cs | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index 3358097e1..bbb0efcee 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -52,7 +52,7 @@ namespace CefSharp.WinForms /// /// Browser initialization settings /// - private BrowserSettings browserSettings; + private IBrowserSettings browserSettings; /// /// The request context (we deliberately use a private variable so we can throw an exception if /// user attempts to set after browser created) @@ -72,7 +72,7 @@ namespace CefSharp.WinForms /// /// The browser settings. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(null)] - public BrowserSettings BrowserSettings + public IBrowserSettings BrowserSettings { get { return browserSettings; } set @@ -82,6 +82,10 @@ namespace CefSharp.WinForms throw new Exception("Browser has already been created. BrowserSettings must be " + "set before the underlying CEF browser is created."); } + if (value != null && value.GetType() != typeof(BrowserSettings)) + { + throw new Exception(string.Format("BrowserSettings can only be of type {0} or null", typeof(BrowserSettings))); + } browserSettings = value; } } @@ -640,7 +644,7 @@ namespace CefSharp.WinForms var windowInfo = new WindowInfo(); windowInfo.SetAsChild(Handle); - managedCefBrowserAdapter.CreateBrowser(windowInfo, browserSettings, (RequestContext)RequestContext, Address); + managedCefBrowserAdapter.CreateBrowser(windowInfo, (BrowserSettings)browserSettings, (RequestContext)RequestContext, Address); if (browserSettings != null) { diff --git a/CefSharp/IBrowserSettings.cs b/CefSharp/IBrowserSettings.cs index ed46f528d..736f332c7 100644 --- a/CefSharp/IBrowserSettings.cs +++ b/CefSharp/IBrowserSettings.cs @@ -2,12 +2,14 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System; + namespace CefSharp { /// /// Interface representing browser initialization settings. /// - public interface IBrowserSettings + public interface IBrowserSettings : IDisposable { /// /// StandardFontFamily