-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core - Add BrowserSubprocess.SelfHost.Main
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
- Loading branch information
Showing
9 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include "Stdafx.h" | ||
|
||
namespace CefSharp | ||
{ | ||
namespace BrowserSubprocess | ||
{ | ||
/// <summary> | ||
/// SelfHost can be used to self host the BrowserSubProcess in your | ||
/// existing application (preferred approach for .Net Core). | ||
/// </summary> | ||
public ref class SelfHost | ||
{ | ||
public: | ||
/// <summary> | ||
/// This function should be called from the application entry point function (typically Program.Main) | ||
/// to execute a secondary process e.g. gpu, plugin, renderer, utility | ||
/// This overload is primarily intended to be used for .Net Core. | ||
/// - Pass in command line args | ||
/// - To support High DPI Displays you should call Cef.EnableHighDPISupport before any other processing | ||
/// or add the relevant entries to your app.manifest | ||
/// </summary> | ||
/// <param name="args">command line args</param> | ||
/// <returns> | ||
/// If called for the browser process (identified by no "type" command-line value) it will return immediately | ||
/// with a value of -1. If called for a recognized secondary process it will block until the process should exit | ||
/// and then return the process exit code. | ||
/// </returns | ||
static int Main(array<String^>^ args); | ||
|
||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters