-
Notifications
You must be signed in to change notification settings - Fork 873
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
Don't use CONTENT_SETTING_DEFAULT for FP setting #5879
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
source_set("common") { | ||
sources = [ | ||
"brave_shield_constants.h", | ||
"brave_shield_utils.cc", | ||
"brave_shield_utils.h", | ||
"features.cc", | ||
"features.h", | ||
] | ||
|
||
deps = [ | ||
"//base", | ||
"//components/content_settings/core/common", | ||
"//url", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/components/brave_shields/common/brave_shield_utils.h" | ||
|
||
#include "base/optional.h" | ||
#include "components/content_settings/core/common/content_settings_pattern.h" | ||
#include "url/gurl.h" | ||
|
||
ContentSetting GetBraveFPContentSettingFromRules( | ||
const ContentSettingsForOneType& fp_rules, | ||
const GURL& primary_url) { | ||
base::Optional<ContentSettingPatternSource> global_fp_rule; | ||
base::Optional<ContentSettingPatternSource> global_fp_balanced_rule; | ||
|
||
for (const auto& rule : fp_rules) { | ||
if (rule.primary_pattern != ContentSettingsPattern::Wildcard() && | ||
rule.primary_pattern.Matches(primary_url)) { | ||
if (rule.secondary_pattern == | ||
ContentSettingsPattern::FromString("https://balanced")) { | ||
return CONTENT_SETTING_DEFAULT; | ||
} | ||
if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) | ||
return rule.GetContentSetting(); | ||
} | ||
|
||
if (rule.primary_pattern == ContentSettingsPattern::Wildcard()) { | ||
if (rule.secondary_pattern == | ||
ContentSettingsPattern::FromString("https://balanced")) { | ||
DCHECK(!global_fp_rule); | ||
global_fp_balanced_rule = rule; | ||
} | ||
if (rule.secondary_pattern == ContentSettingsPattern::Wildcard()) { | ||
DCHECK(!global_fp_balanced_rule); | ||
global_fp_rule = rule; | ||
} | ||
} | ||
} | ||
|
||
if (global_fp_balanced_rule) | ||
return CONTENT_SETTING_DEFAULT; | ||
|
||
if (global_fp_rule) | ||
return global_fp_rule->GetContentSetting(); | ||
|
||
return CONTENT_SETTING_DEFAULT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Copyright 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_COMPONENTS_BRAVE_SHIELDS_COMMON_BRAVE_SHIELD_UTILS_H_ | ||
#define BRAVE_COMPONENTS_BRAVE_SHIELDS_COMMON_BRAVE_SHIELD_UTILS_H_ | ||
|
||
#include "components/content_settings/core/common/content_settings.h" | ||
|
||
class GURL; | ||
|
||
ContentSetting GetBraveFPContentSettingFromRules( | ||
const ContentSettingsForOneType& fp_rules, | ||
const GURL& primary_url); | ||
|
||
#endif // BRAVE_COMPONENTS_BRAVE_SHIELDS_COMMON_BRAVE_SHIELD_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need two rules for this. The secondary pattern is either "balanced" or it's a wildcard. It should never be both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to have one fp rule for one url. - e2213b5817d4dc3b3c12a12da47bff69295034f4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, it's still setting two rules here. We should never be setting both wildcard and balanced for the secondary pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this PR only set one rule for one url but two patterns.
If current www.brave.com has balanced, only one rule (second -
balanced
) is stored.and if user set other rule(allow), it will have only one rule (second -
*
) is stored.When new rule is stored previous balanced rule is not deleted automatically because both are different rule. So, clearing step is needed.
If we don't clear here, prefs could have two rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see. I missed the comment