From d87e7950003330ce32e214af8bf6bf94d3177676 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 2 Aug 2018 10:47:12 +1000 Subject: [PATCH] WinForms/Wpf/OffScreen - Create specific CefSettings class for each version - This is a breaking change as there is no common `CefSharp.CefSettings`, there is no `CefSharp.Wpf.CefSettings`, `CefSharp.WinForms.CefSettings` and `CefSharp.OffScreen.CefSettings` - Cef.Initialize has been removed, the `ChromiumWebBrowser` constructor will call the `Cef.Initialize` with the defaults for your flavour - CefSettings.FocusedNodeChangedEnabled has been moved to CefSharpSettings.FocusedNodeChangedEnabled Resolves #2477 --- .../{CefSettings.h => AbstractCefSettings.h} | 24 ++++--------------- CefSharp.Core/Cef.h | 20 +++------------- CefSharp.Core/CefSharp.Core.vcxproj | 2 +- CefSharp.Core/CefSharp.Core.vcxproj.filters | 6 ++--- CefSharp.Core/Internals/CefSharpApp.h | 8 +++---- CefSharp.Example/CefExample.cs | 17 ++++--------- CefSharp.OffScreen.Example/Program.cs | 5 +--- CefSharp.OffScreen/CefSettings.cs | 24 +++++++++++++++++++ CefSharp.OffScreen/CefSharp.OffScreen.csproj | 1 + CefSharp.Test/CefSharpFixture.cs | 2 ++ CefSharp.WinForms.Example/Program.cs | 6 ++++- CefSharp.WinForms/CefSettings.cs | 10 ++++++++ CefSharp.WinForms/CefSharp.WinForms.csproj | 1 + CefSharp.WinForms/ChromiumWebBrowser.cs | 2 +- CefSharp.Wpf.Example/App.xaml.cs | 6 ++++- CefSharp.Wpf/CefSettings.cs | 24 +++++++++++++++++++ CefSharp.Wpf/CefSharp.Wpf.csproj | 1 + CefSharp/CefSharpSettings.cs | 7 ++++++ 18 files changed, 102 insertions(+), 64 deletions(-) rename CefSharp.Core/{CefSettings.h => AbstractCefSettings.h} (96%) create mode 100644 CefSharp.OffScreen/CefSettings.cs create mode 100644 CefSharp.WinForms/CefSettings.cs create mode 100644 CefSharp.Wpf/CefSettings.cs diff --git a/CefSharp.Core/CefSettings.h b/CefSharp.Core/AbstractCefSettings.h similarity index 96% rename from CefSharp.Core/CefSettings.h rename to CefSharp.Core/AbstractCefSettings.h index 7ade8b8af..0b8e1332f 100644 --- a/CefSharp.Core/CefSettings.h +++ b/CefSharp.Core/AbstractCefSettings.h @@ -14,7 +14,7 @@ namespace CefSharp /// Initialization settings. Many of these and other settings can also configured /// using command-line switches. /// - public ref class CefSettings + public ref class AbstractCefSettings abstract { private: List^ _cefExtensions; @@ -23,13 +23,12 @@ namespace CefSharp internal: ::CefSettings* _cefSettings; List^ _cefCustomSchemes; - bool _focusedNodeChangedEnabled; public: /// /// Default Constructor /// - CefSettings() : _cefSettings(new ::CefSettings()) + AbstractCefSettings() : _cefSettings(new ::CefSettings()) { _cefSettings->multi_threaded_message_loop = true; _cefSettings->no_sandbox = true; @@ -40,18 +39,16 @@ namespace CefSharp //Automatically discovered and load a system-wide installation of Pepper Flash. _cefCommandLineArgs->Add("enable-system-flash", "1"); - - _focusedNodeChangedEnabled = false; } - !CefSettings() + !AbstractCefSettings() { delete _cefSettings; } - ~CefSettings() + ~AbstractCefSettings() { - this->!CefSettings(); + this->!AbstractCefSettings(); } /// @@ -367,17 +364,6 @@ namespace CefSharp void set(uint32 value) { _cefSettings->background_color = value; } } - /// - /// If true a message will be sent from the render subprocess to the - /// browser when a DOM node (or no node) gets focus. The default is - /// false. - /// - property bool FocusedNodeChangedEnabled - { - bool get() { return _focusedNodeChangedEnabled; } - void set(bool value) { _focusedNodeChangedEnabled = value; } - } - /// /// Registers a custom scheme using the provided settings. /// diff --git a/CefSharp.Core/Cef.h b/CefSharp.Core/Cef.h index 9f9286374..0ebc67fc0 100644 --- a/CefSharp.Core/Cef.h +++ b/CefSharp.Core/Cef.h @@ -19,7 +19,7 @@ #include "Internals/CefTaskScheduler.h" #include "Internals/CefRegisterCdmCallbackAdapter.h" #include "CookieManager.h" -#include "CefSettings.h" +#include "AbstractCefSettings.h" #include "RequestContext.h" #include "SchemeHandlerFactoryWrapper.h" @@ -128,20 +128,6 @@ namespace CefSharp } } - /// - /// Initializes CefSharp with the default settings. - /// This function can only be called once, subsiquent calls will result in an Exception. - /// It's important to note that Initialize and Shutdown MUST be called on your main - /// applicaiton thread (Typically the UI thead). If you call them on different - /// threads, your application will hang. See the documentation for Cef.Shutdown() for more details. - /// - /// true if successful; otherwise, false. - static bool Initialize() - { - auto cefSettings = gcnew CefSettings(); - return Initialize(cefSettings); - } - /// /// Initializes CefSharp with user-provided settings. /// It's important to note that Initialize and Shutdown MUST be called on your main @@ -150,7 +136,7 @@ namespace CefSharp /// /// CefSharp configuration settings. /// true if successful; otherwise, false. - static bool Initialize(CefSettings^ cefSettings) + static bool Initialize(AbstractCefSettings^ cefSettings) { return Initialize(cefSettings, false, nullptr); } @@ -164,7 +150,7 @@ namespace CefSharp /// CefSharp configuration settings. /// Check that all relevant dependencies avaliable, throws exception if any are missing /// true if successful; otherwise, false. - static bool Initialize(CefSettings^ cefSettings, bool performDependencyCheck, IBrowserProcessHandler^ browserProcessHandler) + static bool Initialize(AbstractCefSettings^ cefSettings, bool performDependencyCheck, IBrowserProcessHandler^ browserProcessHandler) { if (IsInitialized) { diff --git a/CefSharp.Core/CefSharp.Core.vcxproj b/CefSharp.Core/CefSharp.Core.vcxproj index 5a2c318d5..612241356 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj +++ b/CefSharp.Core/CefSharp.Core.vcxproj @@ -304,7 +304,7 @@ - + diff --git a/CefSharp.Core/CefSharp.Core.vcxproj.filters b/CefSharp.Core/CefSharp.Core.vcxproj.filters index e9724dca4..d009c23fa 100644 --- a/CefSharp.Core/CefSharp.Core.vcxproj.filters +++ b/CefSharp.Core/CefSharp.Core.vcxproj.filters @@ -112,9 +112,6 @@ Header Files - - Header Files - Header Files @@ -274,6 +271,9 @@ Header Files + + Header Files + diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h index eb470e0d6..7a78ca9be 100644 --- a/CefSharp.Core/Internals/CefSharpApp.h +++ b/CefSharp.Core/Internals/CefSharpApp.h @@ -7,18 +7,18 @@ #include "Stdafx.h" #include "include/cef_app.h" -#include "CefSettings.h" +#include "AbstractCefSettings.h" namespace CefSharp { private class CefSharpApp : public CefApp, public CefBrowserProcessHandler { - gcroot _cefSettings; + gcroot _cefSettings; gcroot _browserProcessHandler; public: - CefSharpApp(CefSettings^ cefSettings, IBrowserProcessHandler^ browserProcessHandler) : + CefSharpApp(AbstractCefSettings^ cefSettings, IBrowserProcessHandler^ browserProcessHandler) : _cefSettings(cefSettings), _browserProcessHandler(browserProcessHandler) { @@ -89,7 +89,7 @@ namespace CefSharp commandLine->AppendArgument(StringUtils::ToNative(CefSharpArguments::CustomSchemeArgument + argument)); } - if (_cefSettings->FocusedNodeChangedEnabled) + if (CefSharpSettings::FocusedNodeChangedEnabled) { commandLine->AppendArgument(StringUtils::ToNative(CefSharpArguments::FocusedNodeChangedEnabledArgument)); } diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index 130f49caf..bbf0c0936 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -38,7 +38,7 @@ namespace CefSharp.Example private static readonly bool DebuggingSubProcess = Debugger.IsAttached; private static string PluginInformation = ""; - public static void Init(bool osr, bool multiThreadedMessageLoop, IBrowserProcessHandler browserProcessHandler) + public static void Init(AbstractCefSettings settings, IBrowserProcessHandler browserProcessHandler) { // Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys // Environment.SetEnvironmentVariable("GOOGLE_API_KEY", ""); @@ -53,7 +53,6 @@ namespace CefSharp.Example //http://peter.sh/experiments/chromium-command-line-switches/ //NOTE: Not all relevant in relation to `CefSharp`, use for reference purposes only. - var settings = new CefSettings(); settings.RemoteDebuggingPort = 8088; //The location where cache data will be stored on disk. If empty an in-memory cache will be used for some features and a temporary disk cache for others. //HTML5 databases such as localStorage will only persist across sessions if a cache path is specified. @@ -96,21 +95,12 @@ namespace CefSharp.Example //Possibly useful when experiencing blury fonts. //settings.CefCommandLineArgs.Add("disable-direct-write", "1"); - settings.MultiThreadedMessageLoop = multiThreadedMessageLoop; - settings.ExternalMessagePump = !multiThreadedMessageLoop; - //Enables Uncaught exception handler settings.UncaughtExceptionStackSize = 10; // Off Screen rendering (WPF/Offscreen) - if(osr) + if(settings.WindowlessRenderingEnabled) { - settings.WindowlessRenderingEnabled = true; - - //https://github.com/cefsharp/CefSharp/issues/2408 - settings.CefCommandLineArgs.Add("disable-features", "AsyncWheelEvents,SurfaceSynchronization,TouchpadAndWheelScrollLatching"); - settings.CefCommandLineArgs.Add("disable-blink-features", "RootLayerScrolling"); - //Disable Direct Composition to test https://github.com/cefsharp/CefSharp/issues/1634 //settings.CefCommandLineArgs.Add("disable-direct-composition", "1"); @@ -183,7 +173,8 @@ namespace CefSharp.Example settings.RegisterExtension(new CefExtension("cefsharp/example", Resources.extension)); - settings.FocusedNodeChangedEnabled = true; + //This must be set before Cef.Initialized is called + CefSharpSettings.FocusedNodeChangedEnabled = true; //Experimental option where bound async methods are queued on TaskScheduler.Default. //CefSharpSettings.ConcurrentTaskExecution = true; diff --git a/CefSharp.OffScreen.Example/Program.cs b/CefSharp.OffScreen.Example/Program.cs index 356767f34..0962e03e2 100644 --- a/CefSharp.OffScreen.Example/Program.cs +++ b/CefSharp.OffScreen.Example/Program.cs @@ -6,12 +6,9 @@ using System; using System.Diagnostics; using System.Drawing; using System.IO; -using System.Linq; using System.Threading.Tasks; -using CefSharp; using CefSharp.Example; using CefSharp.Example.Handlers; -using CefSharp.Internals; namespace CefSharp.OffScreen.Example { @@ -26,7 +23,7 @@ namespace CefSharp.OffScreen.Example Console.WriteLine(); // You need to replace this with your own call to Cef.Initialize(); - CefExample.Init(true, multiThreadedMessageLoop:true, browserProcessHandler: new BrowserProcessHandler()); + CefExample.Init(new CefSettings(), browserProcessHandler: new BrowserProcessHandler()); MainAsync("cachePath1", 1.0); //Demo showing Zoom Level of 3.0 diff --git a/CefSharp.OffScreen/CefSettings.cs b/CefSharp.OffScreen/CefSettings.cs new file mode 100644 index 000000000..5a276481a --- /dev/null +++ b/CefSharp.OffScreen/CefSettings.cs @@ -0,0 +1,24 @@ +// Copyright © 2010-2017 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. + +namespace CefSharp.OffScreen +{ + public class CefSettings : AbstractCefSettings + { + //TODO: This is duplicated with the WPF version + public CefSettings() : base() + { + WindowlessRenderingEnabled = true; + + if(Cef.CefVersion.StartsWith("r3.3497")) + { + throw new System.Exception("Issue #2408 should have been resolved, remove the below code"); + } + + //https://github.com/cefsharp/CefSharp/issues/2408 + CefCommandLineArgs.Add("disable-features", "AsyncWheelEvents,SurfaceSynchronization,TouchpadAndWheelScrollLatching"); + CefCommandLineArgs.Add("disable-blink-features", "RootLayerScrolling"); + } + } +} diff --git a/CefSharp.OffScreen/CefSharp.OffScreen.csproj b/CefSharp.OffScreen/CefSharp.OffScreen.csproj index cd012e699..5fa8b02f8 100644 --- a/CefSharp.OffScreen/CefSharp.OffScreen.csproj +++ b/CefSharp.OffScreen/CefSharp.OffScreen.csproj @@ -73,6 +73,7 @@ + diff --git a/CefSharp.Test/CefSharpFixture.cs b/CefSharp.Test/CefSharpFixture.cs index 0620efc7a..5d5c025fe 100644 --- a/CefSharp.Test/CefSharpFixture.cs +++ b/CefSharp.Test/CefSharpFixture.cs @@ -5,6 +5,8 @@ using System; using System.IO; +using CefSharp.OffScreen; + namespace CefSharp.Test { public class CefSharpFixture : IDisposable diff --git a/CefSharp.WinForms.Example/Program.cs b/CefSharp.WinForms.Example/Program.cs index c89d2044e..23cff9d10 100644 --- a/CefSharp.WinForms.Example/Program.cs +++ b/CefSharp.WinForms.Example/Program.cs @@ -79,7 +79,11 @@ namespace CefSharp.WinForms.Example browserProcessHandler = new WinFormsBrowserProcessHandler(scheduler); } - CefExample.Init(osr: false, multiThreadedMessageLoop: multiThreadedMessageLoop, browserProcessHandler: browserProcessHandler); + var settings = new CefSettings(); + settings.MultiThreadedMessageLoop = multiThreadedMessageLoop; + settings.ExternalMessagePump = !multiThreadedMessageLoop; + + CefExample.Init(settings, browserProcessHandler: browserProcessHandler); Application.Run(browser); } diff --git a/CefSharp.WinForms/CefSettings.cs b/CefSharp.WinForms/CefSettings.cs new file mode 100644 index 000000000..bceb7e280 --- /dev/null +++ b/CefSharp.WinForms/CefSettings.cs @@ -0,0 +1,10 @@ +// Copyright © 2010-2017 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. + +namespace CefSharp.WinForms +{ + public class CefSettings : AbstractCefSettings + { + } +} diff --git a/CefSharp.WinForms/CefSharp.WinForms.csproj b/CefSharp.WinForms/CefSharp.WinForms.csproj index 401a058e2..f4a381cb5 100644 --- a/CefSharp.WinForms/CefSharp.WinForms.csproj +++ b/CefSharp.WinForms/CefSharp.WinForms.csproj @@ -65,6 +65,7 @@ + diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index e5c7b6439..cfa246456 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -380,7 +380,7 @@ namespace CefSharp.WinForms { if (!initialized) { - if (!Cef.IsInitialized && !Cef.Initialize()) + if (!Cef.IsInitialized && !Cef.Initialize(new CefSettings())) { throw new InvalidOperationException("Cef::Initialize() failed"); } diff --git a/CefSharp.Wpf.Example/App.xaml.cs b/CefSharp.Wpf.Example/App.xaml.cs index 08e4a0037..01d41c81e 100644 --- a/CefSharp.Wpf.Example/App.xaml.cs +++ b/CefSharp.Wpf.Example/App.xaml.cs @@ -35,7 +35,11 @@ namespace CefSharp.Wpf.Example browserProcessHandler = new WpfBrowserProcessHandler(Dispatcher); } - CefExample.Init(osr: true, multiThreadedMessageLoop: multiThreadedMessageLoop, browserProcessHandler: browserProcessHandler); + var settings = new CefSettings(); + settings.MultiThreadedMessageLoop = multiThreadedMessageLoop; + settings.ExternalMessagePump = !multiThreadedMessageLoop; + + CefExample.Init(settings, browserProcessHandler: browserProcessHandler); base.OnStartup(e); } diff --git a/CefSharp.Wpf/CefSettings.cs b/CefSharp.Wpf/CefSettings.cs new file mode 100644 index 000000000..7e24b2c54 --- /dev/null +++ b/CefSharp.Wpf/CefSettings.cs @@ -0,0 +1,24 @@ +// Copyright © 2010-2017 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. + +namespace CefSharp.Wpf +{ + public class CefSettings : AbstractCefSettings + { + //TODO: This is duplicated with the Offscreen version + public CefSettings() : base() + { + WindowlessRenderingEnabled = true; + + if (Cef.CefVersion.StartsWith("r3.3497")) + { + throw new System.Exception("Issue #2408 should have been resolved, remove the below code"); + } + + //https://github.com/cefsharp/CefSharp/issues/2408 + CefCommandLineArgs.Add("disable-features", "AsyncWheelEvents,SurfaceSynchronization,TouchpadAndWheelScrollLatching"); + CefCommandLineArgs.Add("disable-blink-features", "RootLayerScrolling"); + } + } +} diff --git a/CefSharp.Wpf/CefSharp.Wpf.csproj b/CefSharp.Wpf/CefSharp.Wpf.csproj index f4d0b46a8..e93742e94 100644 --- a/CefSharp.Wpf/CefSharp.Wpf.csproj +++ b/CefSharp.Wpf/CefSharp.Wpf.csproj @@ -78,6 +78,7 @@ + diff --git a/CefSharp/CefSharpSettings.cs b/CefSharp/CefSharpSettings.cs index bf1aa710c..8b94d9cd9 100644 --- a/CefSharp/CefSharpSettings.cs +++ b/CefSharp/CefSharpSettings.cs @@ -94,5 +94,12 @@ namespace CefSharp /// Setting this property to true will allocate new Tasks on TaskScheduler.Default for execution. /// public static bool ConcurrentTaskExecution { get; set; } + + /// + /// If true a message will be sent from the render subprocess to the + /// browser when a DOM node (or no node) gets focus. The default is + /// false. + /// + public static bool FocusedNodeChangedEnabled { get; set; } } }