diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp index fb018efb4..6d794d655 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp @@ -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() diff --git a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h index 0e72a354b..7971b87ef 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.h @@ -29,13 +29,13 @@ namespace CefSharp public: static const CefString kPromiseCreatorFunction; - CefAppUnmanagedWrapper(Action^ onBrowserCreated, Action^ onBrowserDestoryed) + CefAppUnmanagedWrapper(List^ schemes, Action^ onBrowserCreated, Action^ onBrowserDestoryed) { _onBrowserCreated = onBrowserCreated; _onBrowserDestroyed = onBrowserDestoryed; _browserWrappers = gcnew Dictionary(); _extensions = gcnew List(); - _schemes = gcnew List(); + _schemes = schemes; } ~CefAppUnmanagedWrapper() diff --git a/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h b/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h index b52dfe1dc..fa71c87ea 100644 --- a/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h +++ b/CefSharp.BrowserSubprocess.Core/CefAppWrapper.h @@ -22,11 +22,13 @@ namespace CefSharp MCefRefPtr _cefApp; public: - CefAppWrapper() + CefAppWrapper(IEnumerable^ args) { auto onBrowserCreated = gcnew Action(this, &CefAppWrapper::OnBrowserCreated); auto onBrowserDestroyed = gcnew Action(this, &CefAppWrapper::OnBrowserDestroyed); - _cefApp = new CefAppUnmanagedWrapper(onBrowserCreated, onBrowserDestroyed); + auto schemes = CefCustomScheme::ParseCommandLineArguments(args); + + _cefApp = new CefAppUnmanagedWrapper(schemes, onBrowserCreated, onBrowserDestroyed); }; !CefAppWrapper() diff --git a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj index fefa5acc4..c8b419011 100644 --- a/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj +++ b/CefSharp.BrowserSubprocess.Core/CefSharp.BrowserSubprocess.Core.vcxproj @@ -150,7 +150,6 @@ - diff --git a/CefSharp.BrowserSubprocess/CefGpuProcess.cs b/CefSharp.BrowserSubprocess/CefGpuProcess.cs deleted file mode 100644 index 651e2021e..000000000 --- a/CefSharp.BrowserSubprocess/CefGpuProcess.cs +++ /dev/null @@ -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 args) - : base(args) - { - } - } -} diff --git a/CefSharp.BrowserSubprocess/CefRenderProcess.cs b/CefSharp.BrowserSubprocess/CefRenderProcess.cs index 195bdabec..6a6e009ca 100644 --- a/CefSharp.BrowserSubprocess/CefRenderProcess.cs +++ b/CefSharp.BrowserSubprocess/CefRenderProcess.cs @@ -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; + + /// + /// The PID for the parent (browser) process + /// + private int? parentProcessId; private List browsers = new List(); - public CefRenderProcess(IEnumerable args) - : base(args) + public CefRenderProcess(IEnumerable args) : base(args) { - + parentProcessId = LocateParentProcessId(args); + } + + private static int? LocateParentProcessId(IEnumerable 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(); diff --git a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj index 48ac7dfe8..4c33057ee 100644 --- a/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj +++ b/CefSharp.BrowserSubprocess/CefSharp.BrowserSubprocess.csproj @@ -80,15 +80,10 @@ - - - - - @@ -103,10 +98,6 @@ {6c4bb501-2f8e-48ac-9ab5-8cfb2d74185c} CefSharp.BrowserSubprocess.Core - - {7b495581-2271-4f41-9476-acb86e8c864f} - CefSharp.Core - {a55848cc-10e7-40cb-addb-04740b16dd43} CefSharp diff --git a/CefSharp.BrowserSubprocess/CefSubProcess.cs b/CefSharp.BrowserSubprocess/CefSubProcess.cs index a3a9d1da6..fff54bd66 100644 --- a/CefSharp.BrowserSubprocess/CefSubProcess.cs +++ b/CefSharp.BrowserSubprocess/CefSubProcess.cs @@ -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 args) + public CefSubProcess(IEnumerable args) : base(args) { - LocateParentProcessId(args); - } - - private void LocateParentProcessId(IEnumerable 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) diff --git a/CefSharp.BrowserSubprocess/Program.cs b/CefSharp.BrowserSubprocess/Program.cs index f2ec00bb0..26345d42b 100644 --- a/CefSharp.BrowserSubprocess/Program.cs +++ b/CefSharp.BrowserSubprocess/Program.cs @@ -26,7 +26,7 @@ namespace CefSharp.BrowserSubprocess return result; } - public static CefSubProcess Create(IEnumerable args) + private static CefSubProcess Create(IEnumerable 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); diff --git a/CefSharp.Core/CefSettings.h b/CefSharp.Core/CefSettings.h index c1b4547c8..3706fcdb3 100644 --- a/CefSharp.Core/CefSettings.h +++ b/CefSharp.Core/CefSettings.h @@ -16,12 +16,12 @@ namespace CefSharp public ref class CefSettings { private: - List^ _cefCustomSchemes; List^ _cefExtensions; IDictionary^ _cefCommandLineArgs; internal: ::CefSettings* _cefSettings; + List^ _cefCustomSchemes; public: CefSettings() : _cefSettings(new ::CefSettings()) diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h index 56f541988..507160fa6 100644 --- a/CefSharp.Core/Internals/CefSharpApp.h +++ b/CefSharp.Core/Internals/CefSharpApp.h @@ -43,34 +43,53 @@ namespace CefSharp } } - virtual void OnBeforeChildProcessLaunch(CefRefPtr command_line) OVERRIDE + virtual void OnBeforeChildProcessLaunch(CefRefPtr 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 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^ 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^ 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) diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs index cd4dc4ed1..bce3c8d8a 100644 --- a/CefSharp.Example/CefExample.cs +++ b/CefSharp.Example/CefExample.cs @@ -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 diff --git a/CefSharp.Example/CefSharpSchemeHandlerFactory.cs b/CefSharp.Example/CefSharpSchemeHandlerFactory.cs index 3266cdac3..d8d43fce2 100644 --- a/CefSharp.Example/CefSharpSchemeHandlerFactory.cs +++ b/CefSharp.Example/CefSharpSchemeHandlerFactory.cs @@ -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) { diff --git a/CefSharp.Example/Resources/PopupTest.html b/CefSharp.Example/Resources/PopupTest.html index d2e460ea8..168639768 100644 --- a/CefSharp.Example/Resources/PopupTest.html +++ b/CefSharp.Example/Resources/PopupTest.html @@ -1,11 +1,11 @@  - - Popup Test - - - target=_blank + + Popup Test + + + target=_blank
- window.open() - + window.open() + diff --git a/CefSharp.Wpf.Example/MainWindow.xaml b/CefSharp.Wpf.Example/MainWindow.xaml index f3ff817f0..552ab695f 100644 --- a/CefSharp.Wpf.Example/MainWindow.xaml +++ b/CefSharp.Wpf.Example/MainWindow.xaml @@ -19,6 +19,7 @@ + diff --git a/CefSharp.Wpf.Example/MainWindow.xaml.cs b/CefSharp.Wpf.Example/MainWindow.xaml.cs index d48cff230..7e0bd4f15 100644 --- a/CefSharp.Wpf.Example/MainWindow.xaml.cs +++ b/CefSharp.Wpf.Example/MainWindow.xaml.cs @@ -116,6 +116,11 @@ namespace CefSharp.Wpf.Example url = "http://html5demos.com/drag"; break; } + case "PopupTestCustomScheme": + { + url = CefExample.PopupTestUrl; + break; + } } if (string.IsNullOrEmpty(url)) diff --git a/CefSharp/CefCustomScheme.cs b/CefSharp/CefCustomScheme.cs index fa69b85a7..f175e4574 100644 --- a/CefSharp/CefCustomScheme.cs +++ b/CefSharp/CefCustomScheme.cs @@ -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; } + + /// + /// Method used internally + /// + /// command line arguments + /// list of scheme objects + public static List ParseCommandLineArguments(IEnumerable args) + { + var schemes = args.FirstOrDefault(a => a.StartsWith(CefSharpArguments.CustomSchemeArgument)); + var customSchemes = new List(); + + 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; + } } } diff --git a/CefSharp/Internals/CefSharpArguments.cs b/CefSharp/Internals/CefSharpArguments.cs index 402ff03db..727a4c634 100644 --- a/CefSharp/Internals/CefSharpArguments.cs +++ b/CefSharp/Internals/CefSharpArguments.cs @@ -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"; } }