Skip to content

Fixed brave shiels panel in incognito. #29237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged

Fixed brave shiels panel in incognito. #29237

merged 3 commits into from
Jun 4, 2025

Conversation

boocmp
Copy link
Contributor

@boocmp boocmp commented May 26, 2025

Resolves brave/brave-browser#46186

There were two functions, SetBraveShieldsEnabled and ResetBraveShieldsEnabled. The second function set CONTENT_SETTING_DEFAULT for the content settings when shields were enabled on the page, while SetBraveShieldsEnabled would set CONTENT_SETTING_ALLOW in the same case. I've merged the logic of ResetBraveShieldsEnabled into SetBraveShieldsEnabled.

Now:

  1. SetBraveShieldsEnabled sets CONTENT_SETTING_DEFAULT when the user enables shields on the page in a regular profile
  2. SetBraveShieldsEnabled sets CONTENT_SETTING_ALLOW when the user enables shields on the page in an off-the-record profile, because BRAVE_SHIELDS content settings are registered to inherit values from the regular profile. Without explicitly setting ALLOW in off-the-record profiles, the getter would fall back to the regular profile's settings, which cause incorrect behavior described in the issue.

Other functions were also checked for similar issues. In cases where a problem arises, it has been confirmed that such a state cannot be reached from the UI, and DCHECKs have been added for values that are unused (and should not be used).

@boocmp boocmp self-assigned this May 26, 2025
@boocmp boocmp requested a review from DJAndries May 27, 2025 05:00
primary_pattern, ContentSettingsPattern::Wildcard(),
ContentSettingsType::BRAVE_SHIELDS, setting);

RecordShieldsToggled(local_state);
Copy link
Collaborator

Choose a reason for hiding this comment

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

please ensure RecordShieldsToggled is not called for OTR profiles

Copy link
Contributor Author

@boocmp boocmp Jun 3, 2025

Choose a reason for hiding this comment

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

PTAL this commit, may be we can use the same approach for other components

@boocmp boocmp requested a review from goodov June 3, 2025 10:09
@boocmp boocmp force-pushed the shields_panel branch 2 times, most recently from bc90289 to 97d497a Compare June 3, 2025 10:36
@boocmp
Copy link
Contributor Author

boocmp commented Jun 4, 2025

I'm going to move the P3A changes into the separate PR.

#define P3A_LAZY_CALLS(stream, is_enabled) \
!(is_enabled) ? (void)0 : ::brave_shields::P3ACallStream::Voidify() & (stream)

#define P3A(context) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

very clever, but imo this may be overkill given the relatively small amount of call sites. wdyt about just passing the map into the relevant "Record" functions and performing a simple OTR check inside each function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved this to a separate Draft PR. This PR only adds an explicit check for RecordShieldsToggled.

#29383

Copy link
Collaborator

@cdesouza-chromium cdesouza-chromium left a comment

Choose a reason for hiding this comment

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

LGTM

@boocmp boocmp merged commit ef289a2 into master Jun 4, 2025
18 checks passed
@boocmp boocmp deleted the shields_panel branch June 4, 2025 05:09
@github-actions github-actions bot added this to the 1.81.x - Nightly milestone Jun 4, 2025
@brave-builds
Copy link
Collaborator

Released in v1.81.45

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.

Private window Shields toggle doesn't update panel
4 participants