Taking a slightly different turn here; wrapping the C API (which I had as an idea to avoid having to do a bunch of needless wrappers) seemed too awkward because of the refcounting et al... We have to go with the C++ route after all, but we will still keep the subprocess in C# since it's clearly nicer.

This commit is contained in:
Per Lundberg
2013-10-30 22:28:14 +02:00
parent 394287cf08
commit 64d375d556
8 changed files with 114 additions and 41 deletions
+2 -1
View File
@@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using CefSharp.Wrappers;
namespace CefSharp.BrowserSubprocess
{
@@ -14,7 +15,7 @@ namespace CefSharp.BrowserSubprocess
{
var hInstance = Process.GetCurrentProcess().Handle;
LogCommandLine(args);
MessageBox.Show("Please attach debugger now");
//MessageBox.Show("Please attach debugger now");
return ExecuteCefRenderProcess(hInstance);
}
@@ -1,6 +1,8 @@
namespace CefSharp.BrowserSubprocess
using CefSharp.Wrappers;
namespace CefSharp.BrowserSubprocess
{
internal class SubprocessCefApp : WrappedCefApp
internal class SubprocessCefApp : CefAppWrapper
{
}
}
+3 -1
View File
@@ -214,7 +214,6 @@
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" />
<ClCompile Include="BrowserCore.cpp" />
<ClCompile Include="CefWrappers\GlobalMethods.cpp" />
<ClCompile Include="Internals\ClientAdapter.cpp" />
<ClCompile Include="Internals\CookieVisitor.cpp" />
<ClCompile Include="Internals\CefRequestWrapper.cpp" />
@@ -232,12 +231,15 @@
<ClCompile Include="Internals\StringUtils.cpp" />
<ClCompile Include="Internals\StreamAdapter.cpp" />
<ClCompile Include="TypeUtils.cpp" />
<ClCompile Include="Wrappers\GlobalMethods.cpp" />
<ClCompile Include="Wrappers\CefAppWrapper.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BrowserCore.h" />
<ClInclude Include="BrowserSettings.h" />
<ClInclude Include="Cef.h" />
<ClInclude Include="CefCustomScheme.h" />
<ClInclude Include="Wrappers\CefAppWrapper.h" />
<ClInclude Include="ConsoleMessageEventArgs.h" />
<ClInclude Include="IDownloadHandler.h" />
<ClInclude Include="CefErrorCode.h" />
+9 -3
View File
@@ -21,7 +21,7 @@
<Filter Include="Header Files\Internals\JavascriptBinding">
<UniqueIdentifier>{4bc3c074-5cd6-4061-a5b8-b1b43688a707}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\CefWrappers">
<Filter Include="Source Files\Wrappers">
<UniqueIdentifier>{b5511138-8f2e-4ace-9e68-76929de8c004}</UniqueIdentifier>
</Filter>
</ItemGroup>
@@ -68,8 +68,11 @@
<ClCompile Include="SchemeHandlerResponse.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CefWrappers\GlobalMethods.cpp">
<Filter>Source Files\CefWrappers</Filter>
<ClCompile Include="Wrappers\GlobalMethods.cpp">
<Filter>Source Files\Wrappers</Filter>
</ClCompile>
<ClCompile Include="Wrappers\CefAppWrapper.cpp">
<Filter>Source Files\Wrappers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@@ -202,5 +205,8 @@
<ClInclude Include="CefCustomScheme.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Wrappers\CefAppWrapper.h">
<Filter>Source Files\Wrappers</Filter>
</ClInclude>
</ItemGroup>
</Project>
-34
View File
@@ -1,34 +0,0 @@
// Copyright © 2010-2013 The CefSharp Project. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
// This class exposes "global" CEF methods.
#include "Stdafx.h"
#include "include/cef_app.h"
using namespace System;
// TODO: Support the stuff that CefApp has. One important question is whether we go with the C++ API or make the (seemingly a bit
// strange) move to start using the C API instead. It may actually make it possible to write our code in a cleaner fashion. Worth
// thinking about.
public ref class WrappedCefApp
{
CefRefPtr<CefApp>* cefRefPtr;
public:
void* GetUnmanaged()
{
return cefRefPtr;
}
};
public ref class GlobalMethods
{
public:
static int CefExecuteProcess(IntPtr hInstance, WrappedCefApp^ cefApp)
{
CefMainArgs mainArgs((HINSTANCE)hInstance.ToPointer());
return ::CefExecuteProcess(mainArgs, *(CefRefPtr<CefApp>*)cefApp->GetUnmanaged());
}
};
+34
View File
@@ -0,0 +1,34 @@
// Copyright © 2010-2013 The CefSharp Project. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "Stdafx.h"
#include "CefAppWrapper.h"
namespace CefSharp
{
namespace Wrappers
{
CefAppWrapper::CefAppWrapper()
{
cefApp = new CefRefPtr<CefAppUnmanagedWrapper>(new CefAppUnmanagedWrapper());
}
CefAppWrapper::~CefAppWrapper()
{
if (is_disposed) return;
this->!CefAppWrapper();
is_disposed = true;
}
void* CefAppWrapper::GetUnmanaged()
{
return cefApp;
}
CefAppWrapper::!CefAppWrapper()
{
delete cefApp;
}
};
}
+35
View File
@@ -0,0 +1,35 @@
// Copyright © 2010-2013 The CefSharp Project. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "Stdafx.h"
#include "include/cef_app.h"
namespace CefSharp
{
namespace Wrappers
{
private class CefAppUnmanagedWrapper : CefApp
{
IMPLEMENT_REFCOUNTING(CefAppUnmanagedWrapper);
};
// TODO: Support the stuff that CefApp has. One important question is whether we go with the C++ API or make the (seemingly a bit
// strange) move to start using the C API instead. It may actually make it possible to write our code in a cleaner fashion. Worth
// thinking about.
public ref class CefAppWrapper
{
private:
CefRefPtr<CefAppUnmanagedWrapper>* cefApp;
bool is_disposed;
public:
CefAppWrapper();
~CefAppWrapper();
void* GetUnmanaged();
private:
!CefAppWrapper();
};
}
}
+27
View File
@@ -0,0 +1,27 @@
// Copyright © 2010-2013 The CefSharp Project. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
// This class exposes "global" CEF methods.
#include "Stdafx.h"
#include "CefAppWrapper.h"
#include "include/capi/cef_app_capi.h"
using namespace System;
namespace CefSharp
{
namespace Wrappers
{
public ref class GlobalMethods
{
public:
static int CefExecuteProcess(IntPtr hInstance, CefAppWrapper^ cefApp)
{
CefMainArgs cefMainArgs((HINSTANCE)hInstance.ToPointer());
return ::CefExecuteProcess(cefMainArgs, *(CefRefPtr<CefApp>*)cefApp->GetUnmanaged());
}
};
}
}