Commit dfd6e35e authored by Ravjit Singh Uppal's avatar Ravjit Singh Uppal Committed by Commit Bot

Display discarded extension patterns in settings

Currently we throw away invalid wildcard patterns set using extension apis for Flash.
After this CL instead of throwing them away, we display them in the site settings page.

Bug: 1102380, 1073883
Change-Id: Ic9b1d40157cecca3db9673ee92cf208423c71bc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2282742Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Ravjit Singh Uppal <ravjit@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785383}
parent 8dc45d04
......@@ -32,6 +32,14 @@ std::unique_ptr<RuleIterator> CustomExtensionProvider::GetRuleIterator(
incognito);
}
std::unique_ptr<RuleIterator> CustomExtensionProvider::GetDiscardedRuleIterator(
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
bool incognito) const {
return extensions_settings_->GetDiscardedRuleIterator(
content_type, resource_identifier, incognito);
}
bool CustomExtensionProvider::SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
......
......@@ -30,6 +30,11 @@ class CustomExtensionProvider : public ObservableProvider,
const ResourceIdentifier& resource_identifier,
bool incognito) const override;
std::unique_ptr<RuleIterator> GetDiscardedRuleIterator(
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
bool incognito) const override;
bool SetWebsiteSetting(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
......
......@@ -38,6 +38,51 @@ using content_settings::ResourceIdentifier;
namespace extensions {
namespace {
enum class FilterType {
WANT_DISCARDED_PATTERNS,
WANT_VALID_PATTERNS,
};
class FilterRuleIterator : public RuleIterator {
public:
FilterRuleIterator(std::unique_ptr<RuleIterator> iterator,
const FilterType filter_type)
: iterator_(std::move(iterator)), filter_type_(filter_type) {}
~FilterRuleIterator() override = default;
bool HasNext() const override {
if (!iterator_)
return false;
if (current_rule_)
return true;
while (iterator_->HasNext()) {
current_rule_ = iterator_->Next();
if (!((filter_type_ == FilterType::WANT_DISCARDED_PATTERNS) ^
current_rule_->primary_pattern.HasHostWildcards())) {
return true;
}
}
return false;
}
Rule Next() override {
DCHECK(current_rule_.has_value());
Rule rule = std::move(*current_rule_);
current_rule_.reset();
return rule;
}
private:
std::unique_ptr<RuleIterator> iterator_;
const FilterType filter_type_;
mutable base::Optional<Rule> current_rule_;
};
} // namespace
struct ContentSettingsStore::ExtensionEntry {
// Extension id.
std::string id;
......@@ -64,6 +109,36 @@ std::unique_ptr<RuleIterator> ContentSettingsStore::GetRuleIterator(
ContentSettingsType type,
const content_settings::ResourceIdentifier& identifier,
bool incognito) const {
if (base::FeatureList::IsEnabled(
content_settings::kDisallowWildcardsInPluginContentSettings) &&
type == ContentSettingsType::PLUGINS) {
return std::make_unique<FilterRuleIterator>(
GetAllRulesIterator(type, identifier, incognito),
FilterType::WANT_VALID_PATTERNS);
} else {
return GetAllRulesIterator(type, identifier, incognito);
}
}
std::unique_ptr<RuleIterator> ContentSettingsStore::GetDiscardedRuleIterator(
ContentSettingsType type,
const content_settings::ResourceIdentifier& identifier,
bool incognito) const {
if (base::FeatureList::IsEnabled(
content_settings::kDisallowWildcardsInPluginContentSettings) &&
type == ContentSettingsType::PLUGINS) {
return std::make_unique<FilterRuleIterator>(
GetAllRulesIterator(type, identifier, incognito),
FilterType::WANT_DISCARDED_PATTERNS);
} else {
return std::make_unique<content_settings::EmptyRuleIterator>();
}
}
std::unique_ptr<RuleIterator> ContentSettingsStore::GetAllRulesIterator(
ContentSettingsType type,
const content_settings::ResourceIdentifier& identifier,
bool incognito) const {
std::vector<std::unique_ptr<RuleIterator>> iterators;
// The individual |RuleIterators| shouldn't lock; pass |lock_| to the
......@@ -107,12 +182,6 @@ void ContentSettingsStore::SetExtensionContentSetting(
const content_settings::ResourceIdentifier& identifier,
ContentSetting setting,
ExtensionPrefsScope scope) {
if (base::FeatureList::IsEnabled(
content_settings::kDisallowWildcardsInPluginContentSettings) &&
type == ContentSettingsType::PLUGINS &&
primary_pattern.HasHostWildcards()) {
return;
}
{
base::AutoLock lock(lock_);
OriginIdentifierValueMap* map = GetValueMap(ext_id, scope);
......
......@@ -59,6 +59,16 @@ class ContentSettingsStore
const content_settings::ResourceIdentifier& identifier,
bool incognito) const;
std::unique_ptr<content_settings::RuleIterator> GetDiscardedRuleIterator(
ContentSettingsType type,
const content_settings::ResourceIdentifier& identifier,
bool incognito) const;
std::unique_ptr<content_settings::RuleIterator> GetAllRulesIterator(
ContentSettingsType type,
const content_settings::ResourceIdentifier& identifier,
bool incognito) const;
// Sets the content |setting| for |pattern| of extension |ext_id|. The
// |incognito| flag allow to set whether the provided setting is for
// incognito mode only.
......
......@@ -407,6 +407,13 @@ TEST_F(ContentSettingsStoreTest, DisallowWildcardsInFlash) {
// Here we will have one rule because wildcard patterns are allowed for
// ContentSettingsType::COOKIES.
ASSERT_EQ(rules.size(), 1u);
std::unique_ptr<content_settings::RuleIterator> discarded_rules_iterator =
store()->GetDiscardedRuleIterator(ContentSettingsType::PLUGINS,
std::string(), false);
ASSERT_TRUE(discarded_rules_iterator->HasNext());
ASSERT_EQ(discarded_rules_iterator->Next().primary_pattern, primary_pattern);
ASSERT_FALSE(discarded_rules_iterator->HasNext());
}
} // namespace extensions
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment