-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use CONTENT_SETTING_DEFAULT for FP setting
CONTENT_SETTING_DEFAULT means deleting the current content setting. With DEFAULT, it always use global FP setting. But we want DEFAULT as a standard FP blocking instead of fallback to global settings. Use secondary pattern for marking setting as balanced mode.
- Loading branch information
Showing
7 changed files
with
148 additions
and
90 deletions.
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