File tree Expand file tree Collapse file tree
CefSharp.Core.Runtime/Internals Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -209,10 +209,30 @@ namespace CefSharp
209209
210210 if (kvp->Key == " disable-features" || kvp->Key == " enable-features" )
211211 {
212- // Temp workaround so we can set the disable-features/enable-features command line argument
213- // See https://github.com/cefsharp/CefSharp/issues/2408
214- commandLine->AppendSwitchWithValue (name, value);
212+ if (CefSharpSettings::MergeFeaturesCommandLineArgs)
213+ {
214+ CefString existingValue = commandLine->GetSwitchValue (name);
215+ if (existingValue.empty ())
216+ {
217+ commandLine->AppendSwitchWithValue (name, value);
218+ }
219+ else
220+ {
221+ String^ merged = CommandLineArgsMerger::MergeFeatures (StringUtils::ToClr (existingValue), kvp->Value );
222+
223+ commandLine->RemoveSwitch (name);
224+ commandLine->AppendSwitchWithValue (name, StringUtils::ToNative (merged));
225+ }
226+ }
227+ else
228+ {
229+ // Temp workaround so we can set the disable-features/enable-features command line argument
230+ // See https://github.com/cefsharp/CefSharp/issues/2408
231+ commandLine->RemoveSwitch (name);
232+ commandLine->AppendSwitchWithValue (name, value);
233+ }
215234 }
235+
216236 // Right now the command line args handed to the application (global command line) have higher
217237 // precedence than command line args provided by the app
218238 else if (!commandLine->HasSwitch (name))
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ static CefSharpSettings()
2121 WcfTimeout = TimeSpan . FromSeconds ( 2 ) ;
2222#endif
2323 SubprocessExitIfParentProcessClosed = true ;
24+ MergeFeaturesCommandLineArgs = true ;
2425 }
2526
2627#if ! NETCOREAPP
@@ -82,6 +83,12 @@ static CefSharpSettings()
8283 /// </summary>
8384 public static bool FocusedNodeChangedEnabled { get ; set ; }
8485
86+ /// <summary>
87+ /// Any enable-features/disable-features command line arguments will be automatically merged with existing values if supplied.
88+ /// This currently defaults to true.
89+ /// </summary>
90+ public static bool MergeFeaturesCommandLineArgs { get ; set ; }
91+
8592 /// <summary>
8693 /// CefSharp.WinForms and CefSharp.Wpf.HwndHost ONLY!
8794 /// The default is to create <see cref="CefRuntimeStyle.Alloy"/>
Original file line number Diff line number Diff line change 1+ // Copyright © 2015 The CefSharp Authors. All rights reserved.
2+ //
3+ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+ using System ;
6+ using System . Collections . Generic ;
7+
8+ namespace CefSharp . Internals
9+ {
10+ /// <summary>
11+ /// Use this static class to merge command line arguments.
12+ /// </summary>
13+ public sealed class CommandLineArgsMerger
14+ {
15+ /// <summary>
16+ /// Returns the merged command line features.
17+ /// </summary>
18+ /// <param name="existing">The existing features.</param>
19+ /// <param name="incoming">The features that should be merged.</param>
20+ /// <returns> the merged command line features. </returns>
21+ public static string MergeFeatures ( string existing , string incoming )
22+ {
23+ var features = new List < string > ( ) ;
24+
25+ if ( ! string . IsNullOrWhiteSpace ( existing ) )
26+ {
27+ foreach ( var item in existing . Split ( ',' ) )
28+ {
29+ var trimmed = item . Trim ( ) ;
30+ if ( ! features . Contains ( trimmed ) )
31+ {
32+ features . Add ( trimmed ) ;
33+ }
34+ }
35+ }
36+
37+ if ( ! string . IsNullOrWhiteSpace ( incoming ) )
38+ {
39+ foreach ( var item in incoming . Split ( ',' ) )
40+ {
41+ var trimmed = item . Trim ( ) ;
42+ if ( ! features . Contains ( trimmed ) )
43+ {
44+ features . Add ( trimmed ) ;
45+ }
46+ }
47+ }
48+
49+ return string . Join ( "," , features ) ;
50+ }
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments