mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 03:32:37 +00:00
c63b120f8e
Can be used to self host the browser SubProcess Uses reflection to load CefSharp.BrowserSubprocess.Core.dll This method is primarily used for .Net Core and does not load the WCF specific features required for synchronous javascript binding
50 lines
1.9 KiB
C++
50 lines
1.9 KiB
C++
// 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.
|
|
|
|
#include "Stdafx.h"
|
|
#include "SelfHost.h"
|
|
|
|
using namespace System;
|
|
using namespace System::IO;
|
|
using namespace CefSharp;
|
|
|
|
namespace CefSharp
|
|
{
|
|
namespace BrowserSubprocess
|
|
{
|
|
int SelfHost::Main(array<String^>^ args)
|
|
{
|
|
auto type = CommandLineArgsParser::GetArgumentValue(args, CefSharpArguments::SubProcessTypeArgument);
|
|
|
|
if (String::IsNullOrEmpty(type))
|
|
{
|
|
//If --type param missing from command line CEF/Chromium assums
|
|
//this is the main process (as all subprocesses must have a type param).
|
|
//Return -1 to indicate this behaviour.
|
|
return -1;
|
|
}
|
|
|
|
auto browserSubprocessDllPath = Path::Combine(Path::GetDirectoryName(SelfHost::typeid->Assembly->Location), "CefSharp.BrowserSubprocess.Core.dll");
|
|
#ifdef NETCOREAPP
|
|
auto browserSubprocessDll = System::Runtime::Loader::AssemblyLoadContext::Default->LoadFromAssemblyPath(browserSubprocessDllPath);
|
|
#else
|
|
auto browserSubprocessDll = System::Reflection::Assembly::LoadFrom(browserSubprocessDllPath);
|
|
#endif
|
|
auto browserSubprocessExecutableType = browserSubprocessDll->GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");
|
|
auto browserSubprocessExecutable = Activator::CreateInstance(browserSubprocessExecutableType);
|
|
|
|
auto mainMethod = browserSubprocessExecutableType->GetMethod("MainSelfHost", System::Reflection::BindingFlags::Static | System::Reflection::BindingFlags::Public);
|
|
auto argCount = mainMethod->GetParameters();
|
|
|
|
auto methodArgs = gcnew array<Object^>(1);
|
|
methodArgs[0] = args;
|
|
|
|
auto exitCode = mainMethod->Invoke(nullptr, methodArgs);
|
|
|
|
return (int)exitCode;
|
|
}
|
|
|
|
}
|
|
}
|