Skip to content

Core - Automatically merge enable-features/disable-features command-line arguments with existing values#5245

Open
SLT-World wants to merge 2 commits into
cefsharp:masterfrom
SLT-World:master
Open

Core - Automatically merge enable-features/disable-features command-line arguments with existing values#5245
SLT-World wants to merge 2 commits into
cefsharp:masterfrom
SLT-World:master

Conversation

@SLT-World
Copy link
Copy Markdown
Contributor

@SLT-World SLT-World commented May 9, 2026

Core - Automatically merge enable-features/disable-features command-line arguments with existing values.

Fixes: #5244

Summary:

  • I have added the ability to automatically merge enable-features/disable-features command-line arguments with existing values.
  • If CefSharpSettings.MergeFeaturesCommandLineArgs is false, any user-supplied list will remove and replace existing list.
  • The values were somehow being duplicated twice so a Contains check was added to mitigate that issue.

Changes: [specify the structures changed]

  • I have modified CefSharpApp.h and CefSharpSettings.cs.
    • Added MergeFeaturesCommandLineArgs to CefSharpSettings, defaults to true.
    • Modified logic to handle the merging of enable-features and disable-features lists in CefSharpApp.h.

How Has This Been Tested?
Operating System: Windows 11
Environment: Visual Studio 2022
Changes visibly function after appending and modifying

settings.CefCommandLineArgs.Add("disable-features", "GlobalMediaControls");
CefSharpSettings.MergeFeaturesCommandLineArgs = true;

within App.xaml.cs in CefSharp.Wpf.HwndHost.Example.

Screenshots (if appropriate):
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Updated documentation

Checklist:

  • Tested the code(if applicable)
  • Commented my code
  • Changed the documentation(if applicable)
  • New files have a license disclaimer
  • The formatting is consistent with the project (project supports .editorconfig)

Summary by CodeRabbit

  • New Features
    • Added a new MergeFeaturesCommandLineArgs setting (enabled by default) that changes how enable-features/disable-features command-line arguments are applied: when enabled incoming feature lists are merged with existing values instead of overwriting them, allowing more flexible feature-flag configuration.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6e76fd41-e99c-418c-af8d-d7c434556589

📥 Commits

Reviewing files that changed from the base of the PR and between eaf122d and d040de5.

📒 Files selected for processing (1)
  • CefSharp.Core.Runtime/Internals/CefSharpApp.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • CefSharp.Core.Runtime/Internals/CefSharpApp.h

📝 Walkthrough

Walkthrough

The PR adds a configurable setting to control how feature-related command-line arguments (enable-features and disable-features) are processed during CEF initialization. When enabled (default), incoming values are merged with existing values if missing; when disabled, the switch is replaced with the incoming value.

Changes

Feature Command-Line Argument Merge Control

Layer / File(s) Summary
Configuration Property
CefSharp/CefSharpSettings.cs
Introduces MergeFeaturesCommandLineArgs public static property that controls merge behavior for feature command-line arguments.
Default Initialization
CefSharp/CefSharpSettings.cs
Static constructor sets MergeFeaturesCommandLineArgs to true by default.
Merge Implementation
CefSharp.Core.Runtime/Internals/CefSharpApp.h
OnBeforeCommandLineProcessing now conditionally routes feature argument handling: merging appends values (checking for duplicates) when enabled; replacement mode removes and sets the value directly when disabled.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CefSharpApp
  participant CefSharpSettings
  participant CommandLine
  Client->>CefSharpApp: supply enable-features / disable-features arg
  CefSharpApp->>CefSharpSettings: read MergeFeaturesCommandLineArgs
  alt Merge enabled
    CefSharpApp->>CommandLine: read existing switch value
    CommandLine-->>CefSharpApp: existingValue
    CefSharpApp->>CefSharpApp: compare and append missing features
    CefSharpApp->>CommandLine: set updated switch value
  else Merge disabled
    CefSharpApp->>CommandLine: remove existing switch
    CefSharpApp->>CommandLine: set switch = incomingValue
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 In tiny hops the flags align,
Merge or set — the choice is mine.
Lists checked twice, appended right,
Chromium features sleep tonight. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: automatic merging of enable-features/disable-features command-line arguments with existing values.
Description check ✅ Passed The PR description includes all required sections from the template: Fixes, Summary, Changes, How Has This Been Tested, Types of changes, and Checklist with appropriate selections.
Linked Issues check ✅ Passed The PR successfully implements the key requirements from issue #5244: prevents crashes with Chrome runtime style and implements merging of enable-features/disable-features command-line arguments with existing values [#5244].
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue objectives: modifications to CefSharpApp.h and CefSharpSettings.cs align with implementing feature list merging functionality requested in #5244.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CefSharp.Core.Runtime/Internals/CefSharpApp.h`:
- Around line 212-228: The substring check using currentValue->Contains causes
incorrect duplicate detection; in the block gated by
CefSharpSettings::MergeFeaturesCommandLineArgs (around
commandLine->GetSwitchValue/name handling), replace the Contains-based logic
with proper comma-separated token parsing: split the existingValue (via
StringUtils::ToClr(existingValue)) and the incoming kvp->Value by commas, trim
whitespace, build a case-sensitive set/list of existing tokens, iterate the
incoming tokens and add only those not already present, then reconstruct the
merged comma-separated string and call commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(mergedValue));
this ensures exact-feature matching and correctly handles multi-feature inputs
like "Feature1,Feature2".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cdc755c2-d284-4ddc-b997-e038c8368ec6

📥 Commits

Reviewing files that changed from the base of the PR and between fd87988 and eea20a1.

📒 Files selected for processing (2)
  • CefSharp.Core.Runtime/Internals/CefSharpApp.h
  • CefSharp/CefSharpSettings.cs

Comment on lines +212 to +228
if (CefSharpSettings::MergeFeaturesCommandLineArgs)
{
CefString existingValue = commandLine->GetSwitchValue(name);
if (existingValue.empty())
{
commandLine->AppendSwitchWithValue(name, value);
}
else
{
String^ currentValue = StringUtils::ToClr(existingValue);
if (!currentValue->Contains(kvp->Value))
{
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(currentValue + "," + kvp->Value));
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Substring matching causes incorrect duplicate detection for feature lists.

The Contains() check at Line 222 uses substring matching instead of parsing the comma-separated feature list, leading to correctness issues:

False positives (features incorrectly detected as present):

  • Existing: "AutofillActorMode", New: "Autofill" → Contains returns true, "Autofill" never added
  • Existing: "EnableHangWatcher", New: "Hang" → Contains returns true, "Hang" never added

Missing features when adding multiple features:

  • Existing: "Feature1", New: "Feature1,Feature2" → Contains returns true, "Feature2" never added

Correct approach:
Split both the existing value and the new value by commas, then check each individual feature for presence before merging.

🐛 Proposed fix using proper comma-separated list handling
                            if (CefSharpSettings::MergeFeaturesCommandLineArgs)
                            {
                                CefString existingValue = commandLine->GetSwitchValue(name);
                                if (existingValue.empty())
                                {
                                    commandLine->AppendSwitchWithValue(name, value);
                                }
                                else
                                {
-                                   String^ currentValue = StringUtils::ToClr(existingValue);
-                                   if (!currentValue->Contains(kvp->Value))
-                                   {
-                                       commandLine->RemoveSwitch(name);
-                                       commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(currentValue + "," + kvp->Value));
-                                   }
+                                   String^ currentValue = StringUtils::ToClr(existingValue);
+                                   auto existingFeatures = gcnew HashSet<String^>(currentValue->Split(','));
+                                   auto newFeatures = kvp->Value->Split(',');
+                                   bool hasNewFeature = false;
+                                   for each (String^ feature in newFeatures)
+                                   {
+                                       if (!existingFeatures->Contains(feature))
+                                       {
+                                           existingFeatures->Add(feature);
+                                           hasNewFeature = true;
+                                       }
+                                   }
+                                   if (hasNewFeature)
+                                   {
+                                       commandLine->RemoveSwitch(name);
+                                       commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(String::Join(",", existingFeatures)));
+                                   }
                                }
                            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (CefSharpSettings::MergeFeaturesCommandLineArgs)
{
CefString existingValue = commandLine->GetSwitchValue(name);
if (existingValue.empty())
{
commandLine->AppendSwitchWithValue(name, value);
}
else
{
String^ currentValue = StringUtils::ToClr(existingValue);
if (!currentValue->Contains(kvp->Value))
{
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(currentValue + "," + kvp->Value));
}
}
}
if (CefSharpSettings::MergeFeaturesCommandLineArgs)
{
CefString existingValue = commandLine->GetSwitchValue(name);
if (existingValue.empty())
{
commandLine->AppendSwitchWithValue(name, value);
}
else
{
String^ currentValue = StringUtils::ToClr(existingValue);
auto existingFeatures = gcnew HashSet<String^>(currentValue->Split(','));
auto newFeatures = kvp->Value->Split(',');
bool hasNewFeature = false;
for each (String^ feature in newFeatures)
{
if (!existingFeatures->Contains(feature))
{
existingFeatures->Add(feature);
hasNewFeature = true;
}
}
if (hasNewFeature)
{
commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(String::Join(",", existingFeatures)));
}
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CefSharp.Core.Runtime/Internals/CefSharpApp.h` around lines 212 - 228, The
substring check using currentValue->Contains causes incorrect duplicate
detection; in the block gated by CefSharpSettings::MergeFeaturesCommandLineArgs
(around commandLine->GetSwitchValue/name handling), replace the Contains-based
logic with proper comma-separated token parsing: split the existingValue (via
StringUtils::ToClr(existingValue)) and the incoming kvp->Value by commas, trim
whitespace, build a case-sensitive set/list of existing tokens, iterate the
incoming tokens and add only those not already present, then reconstruct the
merged comma-separated string and call commandLine->RemoveSwitch(name);
commandLine->AppendSwitchWithValue(name, StringUtils::ToNative(mergedValue));
this ensures exact-feature matching and correctly handles multi-feature inputs
like "Feature1,Feature2".

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

@AppVeyorBot
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants