Skip to content

Commit

Permalink
Net Core - Support for compiling with .Net Core 3.1
Browse files Browse the repository at this point in the history
- Make Wpf/WinForms/OffScreen projects target AnyCPU
Only the VC++ projects are platform specific now.
- Remove BrowserSubProcess project reference
Not needed as we now have a standalone exe
- Add OffScreen example
- Add WPF Example project
- Fix some compile errors for main solution
- Add BrowserSubProcess executable
- JavascriptObjectRepository remove isAsync param
Rather than throw exception remove the option
- BrowserSubprocess Exclude the WCF specific code from the netCore project
- Add some ifdef/ifndef to exclude the WCF specific implementation
- Move WCF implementation into separate namespace
  • Loading branch information
amaitland committed Jul 23, 2020
1 parent a0d9078 commit e8cf336
Show file tree
Hide file tree
Showing 42 changed files with 420 additions and 181 deletions.
4 changes: 4 additions & 0 deletions CefSharp.BrowserSubprocess.Core/BindObjectAsyncHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ namespace CefSharp
JavascriptRootObjectWrapper^ rootObject;
if (!rootObjectWrappers->TryGetValue(frame->GetIdentifier(), rootObject))
{
#ifdef NETCOREAPP
rootObject = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier());
#else
rootObject = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier(), _browserWrapper->BrowserProcess);
#endif
rootObjectWrappers->TryAdd(frame->GetIdentifier(), rootObject);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Stdafx.h"

#include "SubProcess.h"
#include "WcfEnabledSubProcess.h"

using namespace System;
using namespace CefSharp::Internals;
Expand Down
8 changes: 8 additions & 0 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ namespace CefSharp
JavascriptRootObjectWrapper^ rootObject;
if (!rootObjectWrappers->TryGetValue(frameId, rootObject))
{
#ifdef NETCOREAPP
rootObject = gcnew JavascriptRootObjectWrapper(browserId);
#else
rootObject = gcnew JavascriptRootObjectWrapper(browserId, browserWrapper->BrowserProcess);
#endif
rootObjectWrappers->TryAdd(frameId, rootObject);
}

Expand Down Expand Up @@ -394,7 +398,11 @@ namespace CefSharp
//as without javascript there is no need for a context.
if (rootObjectWrapper == nullptr)
{
#ifdef NETCOREAPP
rootObjectWrapper = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier());
#else
rootObjectWrapper = gcnew JavascriptRootObjectWrapper(browser->GetIdentifier(), browserWrapper->BrowserProcess);
#endif

browserWrapper->JavascriptRootObjectWrappers->TryAdd(frameId, rootObjectWrapper);
}
Expand Down
5 changes: 3 additions & 2 deletions CefSharp.BrowserSubprocess.Core/CefBrowserWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "JavascriptRootObjectWrapper.h"

using namespace CefSharp::Internals::Async;
#ifndef NETCOREAPP
using namespace System::ServiceModel;
#endif
using namespace System::Threading;
using namespace System::Threading::Tasks;

Expand Down Expand Up @@ -65,9 +67,8 @@ namespace CefSharp
#ifndef NETCOREAPP
// This allows us to create the WCF proxies back to our parent process.
property ChannelFactory<IBrowserProcess^>^ ChannelFactory;
#endif

// The WCF proxy to the parent process.
property IBrowserProcess^ BrowserProcess;
#endif
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,24 @@
<ClInclude Include="..\CefSharp.Core\Internals\StringUtils.h" />
<ClInclude Include="BindObjectAsyncHandler.h" />
<ClCompile Include="BrowserSubprocessExecutable.h" />
<ClInclude Include="JavascriptRootObjectWrapper.h" />
<ClInclude Include="SubProcessApp.h" />
<ClInclude Include="Async\JavascriptAsyncMethodCallback.h" />
<ClInclude Include="Async\JavascriptAsyncMethodHandler.h" />
<ClInclude Include="Async\JavascriptAsyncMethodWrapper.h" />
<ClInclude Include="Async\JavascriptAsyncObjectWrapper.h" />
<ClInclude Include="CefAppUnmanagedWrapper.h" />
<ClInclude Include="JavascriptPostMessageHandler.h" />
<ClCompile Include="WcfBrowserSubprocessExecutable.h" />
<ClInclude Include="Wrapper\Frame.h" />
<ClInclude Include="Wrapper\Browser.h" />
<ClInclude Include="Wrapper\V8Context.h" />
<ClInclude Include="RegisterBoundObjectHandler.h" />
<ClInclude Include="RegisterBoundObjectRegistry.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="WcfEnabledSubProcess.h" />
<ClInclude Include="SubProcess.h" />
<ClInclude Include="CefBrowserWrapper.h" />
<ClInclude Include="JavascriptCallbackRegistry.h" />
<ClInclude Include="JavascriptCallbackWrapper.h" />
<ClInclude Include="JavascriptMethodWrapper.h" />
<ClInclude Include="JavascriptMethodHandler.h" />
<ClInclude Include="JavascriptObjectWrapper.h" />
<ClInclude Include="JavascriptPropertyWrapper.h" />
<ClInclude Include="JavascriptPropertyHandler.h" />
<ClInclude Include="JavascriptRootObjectWrapper.h" />
<ClInclude Include="Serialization\JsObjectsSerialization.h" />
<ClInclude Include="Stdafx.h" />
<ClInclude Include="TypeUtils.h" />
Expand All @@ -209,15 +202,10 @@
<ClCompile Include="Async\JavascriptAsyncMethodWrapper.cpp" />
<ClCompile Include="Async\JavascriptAsyncObjectWrapper.cpp" />
<ClCompile Include="CefAppUnmanagedWrapper.cpp" />
<ClCompile Include="JavascriptRootObjectWrapper.cpp" />
<ClCompile Include="Wrapper\Frame.cpp" />
<ClCompile Include="Wrapper\Browser.cpp" />
<ClCompile Include="WcfEnabledSubProcess.cpp" />
<ClCompile Include="JavascriptCallbackRegistry.cpp" />
<ClCompile Include="JavascriptMethodHandler.cpp" />
<ClCompile Include="JavascriptMethodWrapper.cpp" />
<ClCompile Include="JavascriptObjectWrapper.cpp" />
<ClCompile Include="JavascriptPropertyWrapper.cpp" />
<ClCompile Include="JavascriptRootObjectWrapper.cpp" />
<ClCompile Include="Serialization\JsObjectsSerialization.cpp" />
<ClCompile Include="Stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
Expand Down
2 changes: 2 additions & 0 deletions CefSharp.BrowserSubprocess.Core/JavascriptMethodHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "include/cef_v8.h"
#include "JavascriptCallbackRegistry.h"

using namespace CefSharp::Internals::Wcf;

namespace CefSharp
{
private class JavascriptMethodHandler : public CefV8Handler
Expand Down
3 changes: 2 additions & 1 deletion CefSharp.BrowserSubprocess.Core/JavascriptMethodWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "JavascriptMethodHandler.h"

using namespace System::Runtime::Serialization;
using namespace CefSharp::Internals::Wcf;

namespace CefSharp
{
Expand Down Expand Up @@ -44,4 +45,4 @@ namespace CefSharp
void Bind(JavascriptMethod^ javascriptMethod, const CefRefPtr<CefV8Value>& v8Value);
BrowserProcessResponse^ Execute(array<Object^>^ parameters);
};
}
}
4 changes: 3 additions & 1 deletion CefSharp.BrowserSubprocess.Core/JavascriptPropertyWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "include/cef_v8.h"
#include "JavascriptCallbackRegistry.h"

using namespace CefSharp::Internals::Wcf;

namespace CefSharp
{
private ref class JavascriptPropertyWrapper
Expand Down Expand Up @@ -37,4 +39,4 @@ namespace CefSharp

void Bind(JavascriptProperty^ javascriptProperty, const CefRefPtr<CefV8Value>& v8Value, JavascriptCallbackRegistry^ callbackRegistry);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace CefSharp

_wrappedAsyncObjects->Add(wrapperObject);
}
#ifndef NETCOREAPP
else
{
if (_browserProcess == nullptr)
Expand All @@ -41,6 +42,7 @@ namespace CefSharp

_wrappedObjects->Add(wrapperObject);
}
#endif
}
}
}
Expand All @@ -66,4 +68,4 @@ namespace CefSharp
}
return result;
}
}
}
18 changes: 18 additions & 0 deletions CefSharp.BrowserSubprocess.Core/JavascriptRootObjectWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@

#include "include/cef_v8.h"
#include "JavascriptCallbackRegistry.h"
#ifndef NETCOREAPP
#include "JavascriptObjectWrapper.h"
#endif
#include "Async/JavascriptAsyncObjectWrapper.h"

using namespace System::Runtime::Serialization;
using namespace System::Linq;
using namespace System::Collections::Generic;

using namespace CefSharp::Internals::Async;
#ifndef NETCOREAPP
using namespace CefSharp::Internals::Wcf;
#endif

namespace CefSharp
{
Expand All @@ -28,10 +33,14 @@ namespace CefSharp
//Is static so ids are unique to this process https://github.com/cefsharp/CefSharp/issues/2792
static int64 _lastCallback;

#ifndef NETCOREAPP
initonly List<JavascriptObjectWrapper^>^ _wrappedObjects;
#endif
initonly List<JavascriptAsyncObjectWrapper^>^ _wrappedAsyncObjects;
initonly Dictionary<int64, JavascriptAsyncMethodCallback^>^ _methodCallbacks;
#ifndef NETCOREAPP
IBrowserProcess^ _browserProcess;
#endif
// The entire set of possible JavaScript functions to
// call directly into.
JavascriptCallbackRegistry^ _callbackRegistry;
Expand All @@ -45,10 +54,16 @@ namespace CefSharp
}

public:
#ifdef NETCOREAPP
JavascriptRootObjectWrapper(int browserId)
#else
JavascriptRootObjectWrapper(int browserId, IBrowserProcess^ browserProcess)
#endif
{
#ifndef NETCOREAPP
_browserProcess = browserProcess;
_wrappedObjects = gcnew List<JavascriptObjectWrapper^>();
#endif
_wrappedAsyncObjects = gcnew List<JavascriptAsyncObjectWrapper^>();
_callbackRegistry = gcnew JavascriptCallbackRegistry(browserId);
_methodCallbacks = gcnew Dictionary<int64, JavascriptAsyncMethodCallback^>();
Expand All @@ -62,12 +77,15 @@ namespace CefSharp
_callbackRegistry = nullptr;
}

#ifndef NETCOREAPP
for each (JavascriptObjectWrapper^ var in _wrappedObjects)
{
delete var;
}
_wrappedObjects->Clear();

#endif

for each (JavascriptAsyncObjectWrapper^ var in _wrappedAsyncObjects)
{
delete var;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "WcfEnabledSubProcess.h"
#include "BrowserSubprocessExecutable.h"

#ifndef NETCOREAPP
using namespace System;
using namespace CefSharp::Internals;

Expand Down Expand Up @@ -45,4 +44,3 @@ namespace CefSharp
};
}
}
#endif
2 changes: 0 additions & 2 deletions CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Stdafx.h"
#include "WcfEnabledSubProcess.h"

#ifndef NETCOREAPP
using namespace System::ServiceModel;

namespace CefSharp
Expand Down Expand Up @@ -102,4 +101,3 @@ namespace CefSharp
}
}
}
#endif
2 changes: 0 additions & 2 deletions CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

#ifndef NETCOREAPP
#pragma once

#include "Stdafx.h"
Expand Down Expand Up @@ -37,4 +36,3 @@ namespace CefSharp
};
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<!-- Note: We cannot use the recommended style of specifying <Project Sdk=...> because we need
to set BaseIntermediateOutputPath and BaseOutputPath before the SDK props are imported. -->
<PropertyGroup>
<BaseIntermediateOutputPath>obj.netcore\</BaseIntermediateOutputPath>
<BaseOutputPath>bin.netcore\</BaseOutputPath>
</PropertyGroup>

<!-- Implicit top import -->
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>CefSharp.BrowserSubprocess</RootNamespace>
<AssemblyName>CefSharp.BrowserSubprocess</AssemblyName>
<DocumentationFile>$(BaseOutputPath)$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\CefSharp.snk</AssemblyOriginatorKeyFile>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<ApplicationManifest>app.manifest</ApplicationManifest>
<StartupObject>CefSharp.BrowserSubprocess.Program</StartupObject>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>2</WarningLevel>
</PropertyGroup>

<ItemGroup>
<Compile Remove="bin\**" />
<Compile Remove="obj\**" />
<EmbeddedResource Remove="bin\**" />
<EmbeddedResource Remove="obj\**" />
<None Remove="bin\**" />
<None Remove="obj\**" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Program.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CefSharp.BrowserSubprocess.Core\CefSharp.BrowserSubprocess.Core.netcore.vcxproj" />
<ProjectReference Include="..\CefSharp\CefSharp.netcore.csproj" />
</ItemGroup>

<!-- Implicit bottom import -->
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
37 changes: 37 additions & 0 deletions CefSharp.BrowserSubprocess/Program.netcore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © 2020 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 System.Diagnostics;
using CefSharp.RenderProcess;

namespace CefSharp.BrowserSubprocess
{
/// <summary>
/// When implementing your own BrowserSubprocess
/// - For .Net Core use <see cref="BrowserSubprocessExecutable"/> (No WCF Support)
/// - Include an app.manifest with the dpi/compatability sections, this is required (this project contains the relevant).
/// - If you are targeting x86/Win32 then you should set /LargeAddressAware (https://docs.microsoft.com/en-us/cpp/build/reference/largeaddressaware?view=vs-2017)
/// </summary>
public class Program
{
public static int Main(string[] args)
{
Debug.WriteLine("BrowserSubprocess starting up with command line: " + string.Join("\n", args));

SubProcess.EnableHighDPISupport();

//Add your own custom implementation of IRenderProcessHandler here
IRenderProcessHandler handler = null;

//The BrowserSubprocessExecutable provides BrowserSubProcess functionality
//specific to CefSharp there is no WCF support used for the sync JSB feature.
var browserProcessExe = new BrowserSubprocessExecutable();
var result = browserProcessExe.Main(args, handler);

Debug.WriteLine("BrowserSubprocess shutting down.");

return result;
}
}
}
8 changes: 8 additions & 0 deletions CefSharp.BrowserSubprocess/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"CefSharp.BrowserSubprocess.netcore": {
"commandName": "Project",
"nativeDebugging": true
}
}
}
1 change: 1 addition & 0 deletions CefSharp.Core/ManagedCefBrowserAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using namespace System::Diagnostics;
#ifndef NETCOREAPP
using namespace System::ServiceModel;
using namespace CefSharp::Internals::Wcf;
#endif
using namespace System::Threading;
using namespace System::Threading::Tasks;
Expand Down
Loading

0 comments on commit e8cf336

Please sign in to comment.