Skip to content

Commit

Permalink
Network Service - Register custom scheme in all process types
Browse files Browse the repository at this point in the history
The network services requires that custom schemes be registered, previously we only registered them in render processes.

Add SubProcessApp to handle scheme registration
CefAppUnmanagedWrapper inherits SubProcessApp now

#2743
  • Loading branch information
amaitland committed Jul 4, 2019
1 parent 7e084f7 commit e0268a3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 19 deletions.
8 changes: 0 additions & 8 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,4 @@ namespace CefSharp
CefRegisterExtension(StringUtils::ToNative(extension->Name), StringUtils::ToNative(extension->JavascriptCode), NULL);
}
}

void CefAppUnmanagedWrapper::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
for each (CefCustomScheme^ scheme in _schemes->AsReadOnly())
{
registrar->AddCustomScheme(StringUtils::ToNative(scheme->SchemeName), (int)scheme->Options);
}
}
}
10 changes: 3 additions & 7 deletions CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#pragma once

#include "Stdafx.h"
#include "include/cef_app.h"
#include "include/cef_base.h"

#include "SubProcessApp.h"
#include "CefBrowserWrapper.h"
#include "RegisterBoundObjectRegistry.h"

Expand All @@ -17,15 +17,14 @@ using namespace CefSharp::RenderProcess;
namespace CefSharp
{
// This class is the native subprocess level CEF object wrapper.
private class CefAppUnmanagedWrapper : CefApp, CefRenderProcessHandler
private class CefAppUnmanagedWrapper : SubProcessApp, CefRenderProcessHandler
{
private:
gcroot<IRenderProcessHandler^> _handler;
gcroot<Action<CefBrowserWrapper^>^> _onBrowserCreated;
gcroot<Action<CefBrowserWrapper^>^> _onBrowserDestroyed;
gcroot<ConcurrentDictionary<int, CefBrowserWrapper^>^> _browserWrappers;
gcroot<List<V8Extension^>^> _extensions;
gcroot<List<CefCustomScheme^>^> _schemes;
bool _focusedNodeChangedEnabled;
bool _legacyBindingEnabled;

Expand All @@ -37,14 +36,13 @@ namespace CefSharp
public:
static const CefString kPromiseCreatorScript;

CefAppUnmanagedWrapper(IRenderProcessHandler^ handler, List<CefCustomScheme^>^ schemes, bool enableFocusedNodeChanged, Action<CefBrowserWrapper^>^ onBrowserCreated, Action<CefBrowserWrapper^>^ onBrowserDestroyed)
CefAppUnmanagedWrapper(IRenderProcessHandler^ handler, List<CefCustomScheme^>^ schemes, bool enableFocusedNodeChanged, Action<CefBrowserWrapper^>^ onBrowserCreated, Action<CefBrowserWrapper^>^ onBrowserDestroyed) : SubProcessApp(schemes)
{
_handler = handler;
_onBrowserCreated = onBrowserCreated;
_onBrowserDestroyed = onBrowserDestroyed;
_browserWrappers = gcnew ConcurrentDictionary<int, CefBrowserWrapper^>();
_extensions = gcnew List<V8Extension^>();
_schemes = schemes;
_focusedNodeChangedEnabled = enableFocusedNodeChanged;
_javascriptObjects = gcnew Dictionary<String^, JavascriptObject^>();
_registerBoundObjectRegistry = gcnew RegisterBoundObjectRegistry();
Expand All @@ -65,7 +63,6 @@ namespace CefSharp
delete _onBrowserCreated;
delete _onBrowserDestroyed;
delete _extensions;
delete _schemes;
}

CefBrowserWrapper^ FindBrowserWrapper(int browserId);
Expand All @@ -79,7 +76,6 @@ namespace CefSharp
virtual DECL bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId sourceProcessId, CefRefPtr<CefProcessMessage> message) OVERRIDE;
virtual DECL void OnRenderThreadCreated(CefRefPtr<CefListValue> extraInfo) OVERRIDE;
virtual DECL void OnWebKitInitialized() OVERRIDE;
virtual DECL void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) OVERRIDE;
virtual DECL void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefDOMNode> node) OVERRIDE;
virtual DECL void OnUncaughtException(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Exception> exception, CefRefPtr<CefV8StackTrace> stackTrace) OVERRIDE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
<ClInclude Include="..\CefSharp.Core\Internals\Serialization\ObjectsSerialization.h" />
<ClInclude Include="..\CefSharp.Core\Internals\Serialization\Primitives.h" />
<ClInclude Include="..\CefSharp.Core\Internals\StringUtils.h" />
<ClInclude Include="SubProcessApp.h" />
<ClInclude Include="Async\JavascriptAsyncMethodCallback.h" />
<ClInclude Include="Async\JavascriptAsyncMethodHandler.h" />
<ClInclude Include="Async\JavascriptAsyncMethodWrapper.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
<ClInclude Include="JavascriptPostMessageHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SubProcessApp.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp">
Expand Down
10 changes: 7 additions & 3 deletions CefSharp.BrowserSubprocess.Core/SubProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "Stdafx.h"
#include "include/cef_app.h"
#include "include/cef_base.h"

#include "SubProcessApp.h"
#include "CefBrowserWrapper.h"
#include "CefAppUnmanagedWrapper.h"

Expand Down Expand Up @@ -71,13 +71,17 @@ namespace CefSharp
CefEnableHighDPISupport();
}

static int ExecuteProcess()
static int ExecuteProcess(IEnumerable<String^>^ args)
{
auto hInstance = Process::GetCurrentProcess()->Handle;

CefMainArgs cefMainArgs((HINSTANCE)hInstance.ToPointer());

return CefExecuteProcess(cefMainArgs, NULL, NULL);
auto schemes = CefCustomScheme::ParseCommandLineArguments(args);

CefRefPtr<CefApp> app = new SubProcessApp(schemes);

return CefExecuteProcess(cefMainArgs, app, NULL);
}
};
}
Expand Down
47 changes: 47 additions & 0 deletions CefSharp.BrowserSubprocess.Core/SubProcessApp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright © 2019 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"
#include "include/cef_app.h"

using namespace System::Collections::Generic;

namespace CefSharp
{
// CefApp implementation that's common across all subprocess types
public class SubProcessApp : public CefApp
{
private:
gcroot<List<CefCustomScheme^>^> _schemes;

public:
SubProcessApp(List<CefCustomScheme^>^ schemes)
{
_schemes = schemes;
}

~SubProcessApp()
{
delete _schemes;
_schemes = nullptr;
}

void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) OVERRIDE
{
for each (CefCustomScheme^ scheme in _schemes->AsReadOnly())
{
auto schemeName = StringUtils::ToNative(scheme->SchemeName);
auto schemeOptions = (int)scheme->Options;
if (!registrar->AddCustomScheme(schemeName, schemeOptions))
{
LOG(ERROR) << "SubProcessApp::OnRegisterCustomSchemes failed for schemeName:" << schemeName;
}
}
}

IMPLEMENT_REFCOUNTING(SubProcessApp);
};
}
2 changes: 1 addition & 1 deletion CefSharp.BrowserSubprocess/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static int Main(string[] args)
}
else
{
result = SubProcess.ExecuteProcess();
result = SubProcess.ExecuteProcess(args);
}

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

0 comments on commit e0268a3

Please sign in to comment.