mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-06 12:09:40 +00:00
Merge pull request #1268 from amaitland/fix/schemeregistration
Register Custom Schemes in all sub processes
This commit is contained in:
@@ -312,20 +312,6 @@ namespace CefSharp
|
||||
|
||||
_extensions->Add(ext);
|
||||
}
|
||||
|
||||
auto schemeList = extraInfo->GetList(1);
|
||||
|
||||
for (size_t i = 0; i < schemeList->GetSize(); i++)
|
||||
{
|
||||
auto item = schemeList->GetList(i);
|
||||
auto scheme = gcnew CefCustomScheme();
|
||||
scheme->SchemeName = StringUtils::ToClr(item->GetString(0));
|
||||
scheme->IsStandard = item->GetBool(1);
|
||||
scheme->IsLocal = item->GetBool(2);
|
||||
scheme->IsDisplayIsolated = item->GetBool(3);
|
||||
|
||||
_schemes->Add(scheme);
|
||||
}
|
||||
}
|
||||
|
||||
void CefAppUnmanagedWrapper::OnWebKitInitialized()
|
||||
|
||||
@@ -29,13 +29,13 @@ namespace CefSharp
|
||||
public:
|
||||
static const CefString kPromiseCreatorFunction;
|
||||
|
||||
CefAppUnmanagedWrapper(Action<CefBrowserWrapper^>^ onBrowserCreated, Action<CefBrowserWrapper^>^ onBrowserDestoryed)
|
||||
CefAppUnmanagedWrapper(List<CefCustomScheme^>^ schemes, Action<CefBrowserWrapper^>^ onBrowserCreated, Action<CefBrowserWrapper^>^ onBrowserDestoryed)
|
||||
{
|
||||
_onBrowserCreated = onBrowserCreated;
|
||||
_onBrowserDestroyed = onBrowserDestoryed;
|
||||
_browserWrappers = gcnew Dictionary<int, CefBrowserWrapper^>();
|
||||
_extensions = gcnew List<CefExtension^>();
|
||||
_schemes = gcnew List<CefCustomScheme^>();
|
||||
_schemes = schemes;
|
||||
}
|
||||
|
||||
~CefAppUnmanagedWrapper()
|
||||
|
||||
@@ -22,11 +22,13 @@ namespace CefSharp
|
||||
MCefRefPtr<CefAppUnmanagedWrapper> _cefApp;
|
||||
|
||||
public:
|
||||
CefAppWrapper()
|
||||
CefAppWrapper(IEnumerable<String^>^ args)
|
||||
{
|
||||
auto onBrowserCreated = gcnew Action<CefBrowserWrapper^>(this, &CefAppWrapper::OnBrowserCreated);
|
||||
auto onBrowserDestroyed = gcnew Action<CefBrowserWrapper^>(this, &CefAppWrapper::OnBrowserDestroyed);
|
||||
_cefApp = new CefAppUnmanagedWrapper(onBrowserCreated, onBrowserDestroyed);
|
||||
auto schemes = CefCustomScheme::ParseCommandLineArguments(args);
|
||||
|
||||
_cefApp = new CefAppUnmanagedWrapper(schemes, onBrowserCreated, onBrowserDestroyed);
|
||||
};
|
||||
|
||||
!CefAppWrapper()
|
||||
|
||||
@@ -150,7 +150,6 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\CefSharp.Core\Internals\MCefRefPtr.h" />
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright © 2010-2015 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.Collections.Generic;
|
||||
|
||||
namespace CefSharp.BrowserSubprocess
|
||||
{
|
||||
public class CefGpuProcess : CefSubProcess
|
||||
{
|
||||
public CefGpuProcess(IEnumerable<string> args)
|
||||
: base(args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,45 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
using System;
|
||||
using CefSharp.Internals;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.ServiceModel;
|
||||
using CefSharp.Internals;
|
||||
|
||||
namespace CefSharp.BrowserSubprocess
|
||||
{
|
||||
[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults=true)]
|
||||
public class CefRenderProcess : CefSubProcess
|
||||
{
|
||||
private int? parentBrowserId;
|
||||
|
||||
/// <summary>
|
||||
/// The PID for the parent (browser) process
|
||||
/// </summary>
|
||||
private int? parentProcessId;
|
||||
private List<CefBrowserWrapper> browsers = new List<CefBrowserWrapper>();
|
||||
|
||||
public CefRenderProcess(IEnumerable<string> args)
|
||||
: base(args)
|
||||
public CefRenderProcess(IEnumerable<string> args) : base(args)
|
||||
{
|
||||
|
||||
parentProcessId = LocateParentProcessId(args);
|
||||
}
|
||||
|
||||
private static int? LocateParentProcessId(IEnumerable<string> args)
|
||||
{
|
||||
// Format being parsed:
|
||||
// --channel=3828.2.1260352072\1102986608
|
||||
// We only really care about the PID (3828) part.
|
||||
const string channelPrefix = "--channel=";
|
||||
var channelArgument = args.SingleOrDefault(arg => arg.StartsWith(channelPrefix));
|
||||
if (channelArgument == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var parentProcessId = channelArgument
|
||||
.Substring(channelPrefix.Length)
|
||||
.Split('.')
|
||||
.First();
|
||||
return int.Parse(parentProcessId);
|
||||
}
|
||||
|
||||
protected override void DoDispose(bool isDisposing)
|
||||
@@ -42,14 +65,14 @@ namespace CefSharp.BrowserSubprocess
|
||||
parentBrowserId = browser.BrowserId;
|
||||
}
|
||||
|
||||
if (ParentProcessId == null || parentBrowserId == null)
|
||||
if (parentProcessId == null || parentBrowserId == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var browserId = browser.IsPopup ? parentBrowserId.Value : browser.BrowserId;
|
||||
|
||||
var serviceName = RenderprocessClientFactory.GetServiceName(ParentProcessId.Value, browserId);
|
||||
var serviceName = RenderprocessClientFactory.GetServiceName(parentProcessId.Value, browserId);
|
||||
|
||||
var binding = BrowserProcessServiceHost.CreateBinding();
|
||||
|
||||
|
||||
@@ -80,15 +80,10 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CefGpuProcess.cs" />
|
||||
<Compile Include="CefRenderProcess.cs" />
|
||||
<Compile Include="CefSubProcess.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
@@ -103,10 +98,6 @@
|
||||
<Project>{6c4bb501-2f8e-48ac-9ab5-8cfb2d74185c}</Project>
|
||||
<Name>CefSharp.BrowserSubprocess.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\CefSharp.Core\CefSharp.Core.vcxproj">
|
||||
<Project>{7b495581-2271-4f41-9476-acb86e8c864f}</Project>
|
||||
<Name>CefSharp.Core</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\CefSharp\CefSharp.csproj">
|
||||
<Project>{a55848cc-10e7-40cb-addb-04740b16dd43}</Project>
|
||||
<Name>CefSharp</Name>
|
||||
|
||||
@@ -4,35 +4,15 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CefSharp.Internals;
|
||||
|
||||
namespace CefSharp.BrowserSubprocess
|
||||
{
|
||||
public class CefSubProcess : CefAppWrapper
|
||||
{
|
||||
public int? ParentProcessId { get; private set; }
|
||||
|
||||
internal CefSubProcess(IEnumerable<string> args)
|
||||
public CefSubProcess(IEnumerable<string> args) : base(args)
|
||||
{
|
||||
LocateParentProcessId(args);
|
||||
}
|
||||
|
||||
private void LocateParentProcessId(IEnumerable<string> args)
|
||||
{
|
||||
// Format being parsed:
|
||||
// --channel=3828.2.1260352072\1102986608
|
||||
// We only really care about the PID (3828) part.
|
||||
const string channelPrefix = "--channel=";
|
||||
var channelArgument = args.SingleOrDefault(arg => arg.StartsWith(channelPrefix));
|
||||
if (channelArgument == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var parentProcessId = channelArgument
|
||||
.Substring(channelPrefix.Length)
|
||||
.Split('.')
|
||||
.First();
|
||||
ParentProcessId = int.Parse(parentProcessId);
|
||||
|
||||
}
|
||||
|
||||
public override void OnBrowserCreated(CefBrowserWrapper cefBrowserWrapper)
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace CefSharp.BrowserSubprocess
|
||||
return result;
|
||||
}
|
||||
|
||||
public static CefSubProcess Create(IEnumerable<string> args)
|
||||
private static CefSubProcess Create(IEnumerable<string> args)
|
||||
{
|
||||
const string typePrefix = "--type=";
|
||||
var typeArgument = args.SingleOrDefault(arg => arg.StartsWith(typePrefix));
|
||||
@@ -41,9 +41,6 @@ namespace CefSharp.BrowserSubprocess
|
||||
return wcfEnabled ? new CefRenderProcess(args) : new CefSubProcess(args);
|
||||
}
|
||||
case "gpu-process":
|
||||
{
|
||||
return new CefGpuProcess(args);
|
||||
}
|
||||
default:
|
||||
{
|
||||
return new CefSubProcess(args);
|
||||
|
||||
@@ -16,12 +16,12 @@ namespace CefSharp
|
||||
public ref class CefSettings
|
||||
{
|
||||
private:
|
||||
List<CefCustomScheme^>^ _cefCustomSchemes;
|
||||
List<CefExtension^>^ _cefExtensions;
|
||||
IDictionary<String^, String^>^ _cefCommandLineArgs;
|
||||
|
||||
internal:
|
||||
::CefSettings* _cefSettings;
|
||||
List<CefCustomScheme^>^ _cefCustomSchemes;
|
||||
|
||||
public:
|
||||
CefSettings() : _cefSettings(new ::CefSettings())
|
||||
|
||||
@@ -43,34 +43,53 @@ namespace CefSharp
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line) OVERRIDE
|
||||
virtual void OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> commandLine) OVERRIDE
|
||||
{
|
||||
if (CefSharpSettings::WcfEnabled)
|
||||
{
|
||||
command_line->AppendArgument(StringUtils::ToNative(CefSharpArguments::WcfEnabledArgument));
|
||||
commandLine->AppendArgument(StringUtils::ToNative(CefSharpArguments::WcfEnabledArgument));
|
||||
}
|
||||
|
||||
if (_cefSettings->_cefCustomSchemes->Count > 0)
|
||||
{
|
||||
String^ argument = "=";
|
||||
|
||||
for each(CefCustomScheme^ scheme in _cefSettings->CefCustomSchemes)
|
||||
{
|
||||
argument += scheme->SchemeName + "|";
|
||||
argument += (scheme->IsStandard ? "T" : "F") + "|";
|
||||
argument += (scheme->IsLocal ? "T" : "F") + "|";
|
||||
argument += (scheme->IsDisplayIsolated ? "T" : "F") + ";";
|
||||
}
|
||||
|
||||
argument = argument->TrimEnd(';');
|
||||
|
||||
commandLine->AppendArgument(StringUtils::ToNative(CefSharpArguments::CustomSchemeArgument + argument));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) OVERRIDE
|
||||
{
|
||||
if(_cefSettings->CefCommandLineArgs->Count == 0)
|
||||
return;
|
||||
|
||||
auto commandLine = command_line.get();
|
||||
|
||||
// Not clear what should happen if we
|
||||
// * already have some command line flags given (is this possible? Perhaps from globalCommandLine)
|
||||
// * have no flags given (-> call SetProgramm() with first argument?)
|
||||
|
||||
for each(KeyValuePair<String^, String^>^ kvp in _cefSettings->CefCommandLineArgs)
|
||||
if(_cefSettings->CefCommandLineArgs->Count > 0)
|
||||
{
|
||||
CefString name = StringUtils::ToNative(kvp->Key);
|
||||
CefString value = StringUtils::ToNative(kvp->Value);
|
||||
auto commandLine = command_line.get();
|
||||
|
||||
// Right now the command line args handed to the application (global command line) have higher
|
||||
// precedence than command line args provided by the app
|
||||
if(!commandLine->HasSwitch(name))
|
||||
commandLine->AppendSwitchWithValue(name, value);
|
||||
// Not clear what should happen if we
|
||||
// * already have some command line flags given (is this possible? Perhaps from globalCommandLine)
|
||||
// * have no flags given (-> call SetProgramm() with first argument?)
|
||||
|
||||
for each(KeyValuePair<String^, String^>^ kvp in _cefSettings->CefCommandLineArgs)
|
||||
{
|
||||
CefString name = StringUtils::ToNative(kvp->Key);
|
||||
CefString value = StringUtils::ToNative(kvp->Value);
|
||||
|
||||
// Right now the command line args handed to the application (global command line) have higher
|
||||
// precedence than command line args provided by the app
|
||||
if(!commandLine->HasSwitch(name))
|
||||
{
|
||||
commandLine->AppendSwitchWithValue(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,9 +97,6 @@ namespace CefSharp
|
||||
{
|
||||
for each (CefCustomScheme^ cefCustomScheme in _cefSettings->CefCustomSchemes)
|
||||
{
|
||||
// TODO: Causes an "assertion failed" error here: DCHECK_EQ(CefCallbackCToCpp::DebugObjCt, 0)
|
||||
// when the process is shutting down.
|
||||
|
||||
// TOOD: Consider adding error handling here. But where do we report any errors that may have occurred?
|
||||
registrar->AddCustomScheme(StringUtils::ToNative(cefCustomScheme->SchemeName), cefCustomScheme->IsStandard, cefCustomScheme->IsLocal, cefCustomScheme->IsDisplayIsolated);
|
||||
}
|
||||
@@ -100,21 +116,6 @@ namespace CefSharp
|
||||
}
|
||||
|
||||
extraInfo->SetList(0, extensionList);
|
||||
|
||||
auto schemeList = CefListValue::Create();
|
||||
|
||||
i = 0;
|
||||
for each(CefCustomScheme^ scheme in _cefSettings->CefCustomSchemes)
|
||||
{
|
||||
auto item = CefListValue::Create();
|
||||
item->SetString(0, StringUtils::ToNative(scheme->SchemeName));
|
||||
item->SetBool(1, scheme->IsStandard);
|
||||
item->SetBool(2, scheme->IsLocal);
|
||||
item->SetBool(3, scheme->IsDisplayIsolated);
|
||||
schemeList->SetList(i++, item);
|
||||
}
|
||||
|
||||
extraInfo->SetList(1, schemeList);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFCOUNTING(CefSharpApp)
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace CefSharp.Example
|
||||
public const string DefaultUrl = "custom://cefsharp/home.html";
|
||||
public const string BindingTestUrl = "custom://cefsharp/BindingTest.html";
|
||||
public const string PluginsTestUrl = "custom://cefsharp/plugins.html";
|
||||
public const string PopupTestUrl = "custom://cefsharp/PopupTest.html";
|
||||
public const string TestResourceUrl = "http://test/resource/load";
|
||||
public const string RenderProcessCrashedUrl = "http://processcrashed";
|
||||
public const string TestUnicodeResourceUrl = "http://test/resource/loadUnicode";
|
||||
@@ -119,6 +120,12 @@ namespace CefSharp.Example
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
|
||||
});
|
||||
|
||||
settings.RegisterScheme(new CefCustomScheme
|
||||
{
|
||||
SchemeName = CefSharpSchemeHandlerFactory.SchemeNameTest,
|
||||
SchemeHandlerFactory = new CefSharpSchemeHandlerFactory()
|
||||
});
|
||||
|
||||
settings.RegisterExtension(new CefExtension("cefsharp/example", Resources.extension));
|
||||
|
||||
Cef.OnContextInitialized = delegate
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace CefSharp.Example
|
||||
internal class CefSharpSchemeHandlerFactory : ISchemeHandlerFactory
|
||||
{
|
||||
public const string SchemeName = "custom";
|
||||
public const string SchemeNameTest = "test";
|
||||
|
||||
public IResourceHandler Create(IBrowser browser, IFrame frame, string schemeName, IRequest request)
|
||||
{
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>Popup Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="https://github.com/perlun/CefSharp" target="_blank">target=_blank</a>
|
||||
<head>
|
||||
<title>Popup Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<a href="https://github.com/CefSharp/CefSharp" target="_blank">target=_blank</a>
|
||||
<br />
|
||||
<a href="#" onclick="window.open('https://github.com/perlun/CefSharp')">window.open()</a>
|
||||
</body>
|
||||
<a href="#" onclick="window.open('https://github.com/CefSharp/CefSharp')">window.open()</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<MenuItem Header="_Binding Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="BindingTest"/>
|
||||
<MenuItem Header="_List Plugins" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="ListPlugins"/>
|
||||
<MenuItem Header="_Popup Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="PopupTest"/>
|
||||
<MenuItem Header="_Popup Test Custom Scheme" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="PopupTestCustomScheme"/>
|
||||
<MenuItem Header="_Fish Gl" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="FishGl"/>
|
||||
<MenuItem Header="_Microsoft Test Drive" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="MsTestDrive"/>
|
||||
<MenuItem Header="_Drag Demo" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="DragDemo"/>
|
||||
|
||||
@@ -116,6 +116,11 @@ namespace CefSharp.Wpf.Example
|
||||
url = "http://html5demos.com/drag";
|
||||
break;
|
||||
}
|
||||
case "PopupTestCustomScheme":
|
||||
{
|
||||
url = CefExample.PopupTestUrl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(url))
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CefSharp.Internals;
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
public class CefCustomScheme
|
||||
@@ -73,5 +77,35 @@ namespace CefSharp
|
||||
IsLocal = false;
|
||||
IsDisplayIsolated = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method used internally
|
||||
/// </summary>
|
||||
/// <param name="args">command line arguments</param>
|
||||
/// <returns>list of scheme objects</returns>
|
||||
public static List<CefCustomScheme> ParseCommandLineArguments(IEnumerable<string> args)
|
||||
{
|
||||
var schemes = args.FirstOrDefault(a => a.StartsWith(CefSharpArguments.CustomSchemeArgument));
|
||||
var customSchemes = new List<CefCustomScheme>();
|
||||
|
||||
if (!string.IsNullOrEmpty(schemes))
|
||||
{
|
||||
//Remove the "--custom-scheme=" part of the argument
|
||||
schemes.Substring(CefSharpArguments.CustomSchemeArgument.Length + 1).Split(';').ToList().ForEach(x =>
|
||||
{
|
||||
var tokens = x.Split('|');
|
||||
var customScheme = new CefCustomScheme
|
||||
{
|
||||
SchemeName = tokens[0],
|
||||
IsStandard = tokens[1] == "T",
|
||||
IsLocal = tokens[2] == "T",
|
||||
IsDisplayIsolated = tokens[3] == "T"
|
||||
};
|
||||
customSchemes.Add(customScheme);
|
||||
});
|
||||
}
|
||||
|
||||
return customSchemes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace CefSharp.Internals
|
||||
{
|
||||
public static class CefSharpArguments
|
||||
{
|
||||
public const string WcfEnabledArgument = "wcf-enabled";
|
||||
public const string WcfEnabledArgument = "--wcf-enabled";
|
||||
public const string CustomSchemeArgument = "--custom-scheme";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user