Skip to content

Commit

Permalink
WinForms/Wpf/OffScreen - Create specific CefSettings class for each v…
Browse files Browse the repository at this point in the history
…ersion

 - 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
  • Loading branch information
amaitland committed Aug 2, 2018
1 parent 1d94885 commit 366d3a8
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace CefSharp
/// Initialization settings. Many of these and other settings can also configured
/// using command-line switches.
/// </summary>
public ref class CefSettings
public ref class AbstractCefSettings abstract
{
private:
List<CefExtension^>^ _cefExtensions;
Expand All @@ -23,13 +23,12 @@ namespace CefSharp
internal:
::CefSettings* _cefSettings;
List<CefCustomScheme^>^ _cefCustomSchemes;
bool _focusedNodeChangedEnabled;

public:
/// <summary>
/// Default Constructor
/// </summary>
CefSettings() : _cefSettings(new ::CefSettings())
AbstractCefSettings() : _cefSettings(new ::CefSettings())
{
_cefSettings->multi_threaded_message_loop = true;
_cefSettings->no_sandbox = true;
Expand All @@ -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();
}

/// <summary>
Expand Down Expand Up @@ -367,17 +364,6 @@ namespace CefSharp
void set(uint32 value) { _cefSettings->background_color = value; }
}

/// <summary>
/// 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.
/// </summary>
property bool FocusedNodeChangedEnabled
{
bool get() { return _focusedNodeChangedEnabled; }
void set(bool value) { _focusedNodeChangedEnabled = value; }
}

/// <summary>
/// Registers a custom scheme using the provided settings.
/// </summary>
Expand Down
20 changes: 3 additions & 17 deletions CefSharp.Core/Cef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -128,20 +128,6 @@ namespace CefSharp
}
}

/// <summary>
/// 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 <strong>MUST</strong> 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.
/// </summary>
/// <returns>true if successful; otherwise, false.</returns>
static bool Initialize()
{
auto cefSettings = gcnew CefSettings();
return Initialize(cefSettings);
}

/// <summary>
/// Initializes CefSharp with user-provided settings.
/// It's important to note that Initialize and Shutdown <strong>MUST</strong> be called on your main
Expand All @@ -150,7 +136,7 @@ namespace CefSharp
/// </summary>
/// <param name="cefSettings">CefSharp configuration settings.</param>
/// <returns>true if successful; otherwise, false.</returns>
static bool Initialize(CefSettings^ cefSettings)
static bool Initialize(AbstractCefSettings^ cefSettings)
{
return Initialize(cefSettings, false, nullptr);
}
Expand All @@ -164,7 +150,7 @@ namespace CefSharp
/// <param name="cefSettings">CefSharp configuration settings.</param>
/// <param name="performDependencyCheck">Check that all relevant dependencies avaliable, throws exception if any are missing</param>
/// <returns>true if successful; otherwise, false.</returns>
static bool Initialize(CefSettings^ cefSettings, bool performDependencyCheck, IBrowserProcessHandler^ browserProcessHandler)
static bool Initialize(AbstractCefSettings^ cefSettings, bool performDependencyCheck, IBrowserProcessHandler^ browserProcessHandler)
{
if (IsInitialized)
{
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Core/CefSharp.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
<ClInclude Include="NativeMethodWrapper.h" />
<ClInclude Include="Internals\Serialization\V8Serialization.h" />
<ClInclude Include="ManagedCefBrowserAdapter.h" />
<ClInclude Include="CefSettings.h" />
<ClInclude Include="AbstractCefSettings.h" />
<ClInclude Include="Internals\Serialization\Primitives.h" />
<ClInclude Include="RequestContext.h" />
<ClInclude Include="RequestContextSettings.h" />
Expand Down
6 changes: 3 additions & 3 deletions CefSharp.Core/CefSharp.Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@
<ClInclude Include="ManagedCefBrowserAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CefSettings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Internals\StringVisitor.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -274,6 +271,9 @@
<ClInclude Include="Internals\CefRequestContextHandlerAdapter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="AbstractCefSettings.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Internals\CefSharpBrowserWrapper.h">
Expand Down
8 changes: 4 additions & 4 deletions CefSharp.Core/Internals/CefSharpApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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^> _cefSettings;
gcroot<AbstractCefSettings^> _cefSettings;
gcroot<IBrowserProcessHandler^> _browserProcessHandler;

public:
CefSharpApp(CefSettings^ cefSettings, IBrowserProcessHandler^ browserProcessHandler) :
CefSharpApp(AbstractCefSettings^ cefSettings, IBrowserProcessHandler^ browserProcessHandler) :
_cefSettings(cefSettings),
_browserProcessHandler(browserProcessHandler)
{
Expand Down Expand Up @@ -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));
}
Expand Down
17 changes: 4 additions & 13 deletions CefSharp.Example/CefExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class CefExample
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", "");
Expand All @@ -53,7 +53,6 @@ public static void Init(bool osr, bool multiThreadedMessageLoop, IBrowserProcess
//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.
Expand Down Expand Up @@ -96,21 +95,12 @@ public static void Init(bool osr, bool multiThreadedMessageLoop, IBrowserProcess
//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");

Expand Down Expand Up @@ -183,7 +173,8 @@ public static void Init(bool osr, bool multiThreadedMessageLoop, IBrowserProcess

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;
Expand Down
5 changes: 1 addition & 4 deletions CefSharp.OffScreen.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
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
{
Expand All @@ -26,7 +23,7 @@ public static int Main(string[] args)
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
Expand Down
24 changes: 24 additions & 0 deletions CefSharp.OffScreen/CefSettings.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
1 change: 1 addition & 0 deletions CefSharp.OffScreen/CefSharp.OffScreen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BitmapBuffer.cs" />
<Compile Include="CefSettings.cs" />
<Compile Include="ChromiumWebBrowser.cs" />
<Compile Include="DefaultRenderHandler.cs" />
<Compile Include="IRenderHandler.cs" />
Expand Down
2 changes: 2 additions & 0 deletions CefSharp.Test/CefSharpFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System;
using System.IO;

using CefSharp.OffScreen;

namespace CefSharp.Test
{
public class CefSharpFixture : IDisposable
Expand Down
6 changes: 5 additions & 1 deletion CefSharp.WinForms.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ public static int Main(string[] args)
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);
}
Expand Down
10 changes: 10 additions & 0 deletions CefSharp.WinForms/CefSettings.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
}
1 change: 1 addition & 0 deletions CefSharp.WinForms/CefSharp.WinForms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CefSettings.cs" />
<Compile Include="ChromiumWebBrowserDesigner.cs" />
<Compile Include="Internals\DefaultFocusHandler.cs" />
<Compile Include="Internals\ControlExtensions.cs" />
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.WinForms/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private void InitializeFieldsAndCefIfRequired()
{
if (!initialized)
{
if (!Cef.IsInitialized && !Cef.Initialize())
if (!Cef.IsInitialized && !Cef.Initialize(new CefSettings()))
{
throw new InvalidOperationException("Cef::Initialize() failed");
}
Expand Down
6 changes: 5 additions & 1 deletion CefSharp.Wpf.Example/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ protected override void OnStartup(StartupEventArgs e)
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);
}
Expand Down
24 changes: 24 additions & 0 deletions CefSharp.Wpf/CefSettings.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
1 change: 1 addition & 0 deletions CefSharp.Wpf/CefSharp.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="CefSettings.cs" />
<Compile Include="IWpfKeyboardHandler.cs" />
<Compile Include="Internals\VirtualKeys.cs" />
<Compile Include="Internals\WpfKeyboardHandler.cs" />
Expand Down
7 changes: 7 additions & 0 deletions CefSharp/CefSharpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ static CefSharpSettings()
/// Setting this property to true will allocate new Tasks on TaskScheduler.Default for execution.
/// </summary>
public static bool ConcurrentTaskExecution { get; set; }

/// <summary>
/// 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.
/// </summary>
public static bool FocusedNodeChangedEnabled { get; set; }
}
}

0 comments on commit 366d3a8

Please sign in to comment.