Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: components/subresource_filter/core/common/indexed_ruleset.cc

Issue 2796133002: [subresource_filter] Don't store no-op rules in IndexedRuleset. (Closed)
Patch Set: Fix tests; add new tests. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/subresource_filter/core/common/indexed_ruleset_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/subresource_filter/core/common/indexed_ruleset.cc
diff --git a/components/subresource_filter/core/common/indexed_ruleset.cc b/components/subresource_filter/core/common/indexed_ruleset.cc
index c0e1b163ac8a546c78a13584d2c3aeac55eaf484..5e796e08710595b80588dd82506e042e9f95e037 100644
--- a/components/subresource_filter/core/common/indexed_ruleset.cc
+++ b/components/subresource_filter/core/common/indexed_ruleset.cc
@@ -30,7 +30,8 @@ class UrlRuleFlatBufferConverter {
// |rule| to FlatBuffer, are initialized (|options|, |anchor_right|, etc.).
UrlRuleFlatBufferConverter(const proto::UrlRule& rule) : rule_(rule) {
is_convertible_ = InitializeOptions() && InitializeElementTypes() &&
- InitializeActivationTypes() && InitializeUrlPattern();
+ InitializeActivationTypes() && InitializeUrlPattern() &&
+ IsMeaningful();
}
// Returns whether the |rule| can be converted to its FlatBuffers equivalent.
@@ -125,10 +126,15 @@ class UrlRuleFlatBufferConverter {
return false; // Unsupported element types.
}
element_types_ = static_cast<uint16_t>(rule_.element_types());
+
// Note: Normally we can not distinguish between the main plugin resource
// and any other loads it makes. We treat them both as OBJECT requests.
if (element_types_ & proto::ELEMENT_TYPE_OBJECT_SUBREQUEST)
element_types_ |= proto::ELEMENT_TYPE_OBJECT;
+
+ // Filtering popups is not supported.
+ element_types_ &= ~proto::ELEMENT_TYPE_POPUP;
+
return true;
}
@@ -141,6 +147,11 @@ class UrlRuleFlatBufferConverter {
return false; // Unsupported activation types.
}
activation_types_ = static_cast<uint8_t>(rule_.activation_types());
+
+ // No need in CSS activation, because the CSS rules are not supported.
+ activation_types_ &=
+ ~(proto::ACTIVATION_TYPE_ELEMHIDE | proto::ACTIVATION_TYPE_GENERICHIDE);
+
return true;
}
@@ -169,6 +180,9 @@ class UrlRuleFlatBufferConverter {
return true;
}
+ // Returns whether the rule is not a no-op after all the modifications above.
+ bool IsMeaningful() const { return element_types_ || activation_types_; }
+
const proto::UrlRule& rule_;
uint8_t options_ = 0;
@@ -186,7 +200,7 @@ class UrlRuleFlatBufferConverter {
// RulesetIndexer --------------------------------------------------------------
// static
-const int RulesetIndexer::kIndexedFormatVersion = 13;
+const int RulesetIndexer::kIndexedFormatVersion = 14;
RulesetIndexer::MutableUrlPatternIndex::MutableUrlPatternIndex() = default;
RulesetIndexer::MutableUrlPatternIndex::~MutableUrlPatternIndex() = default;
« no previous file with comments | « no previous file | components/subresource_filter/core/common/indexed_ruleset_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698