| Index: components/subresource_filter/core/common/url_pattern_index.cc
 | 
| diff --git a/components/subresource_filter/core/common/url_pattern_index.cc b/components/subresource_filter/core/common/url_pattern_index.cc
 | 
| index 574f577a32533c1d0811f55d579d152c22f0a3d7..0116049a5b82cd2e670a74581c636a4a3359f5ef 100644
 | 
| --- a/components/subresource_filter/core/common/url_pattern_index.cc
 | 
| +++ b/components/subresource_filter/core/common/url_pattern_index.cc
 | 
| @@ -24,6 +24,39 @@ namespace {
 | 
|  using FlatStringOffset = flatbuffers::Offset<flatbuffers::String>;
 | 
|  using FlatDomains = flatbuffers::Vector<FlatStringOffset>;
 | 
|  using FlatDomainsOffset = flatbuffers::Offset<FlatDomains>;
 | 
| +using ActivationMaskPair =
 | 
| +    std::pair<proto::ActivationType, flat::ActivationType>;
 | 
| +using ElementTypeMaskPair = std::pair<proto::ElementType, flat::ElementType>;
 | 
| +
 | 
| +const ActivationMaskPair kActivationMaskPairs[] = {
 | 
| +    {proto::ACTIVATION_TYPE_DOCUMENT, flat::ActivationType_DOCUMENT},
 | 
| +    {proto::ACTIVATION_TYPE_ELEMHIDE,
 | 
| +     flat::ActivationType_NONE},  // ELEMHIDE is not supported.
 | 
| +    {proto::ACTIVATION_TYPE_GENERICHIDE,
 | 
| +     flat::ActivationType_NONE},  // Generic block is not supported.
 | 
| +    {proto::ACTIVATION_TYPE_GENERICBLOCK, flat::ActivationType_GENERIC_BLOCK},
 | 
| +};
 | 
| +
 | 
| +const ElementTypeMaskPair kElementTypeMaskPairs[] = {
 | 
| +    {proto::ELEMENT_TYPE_OTHER, flat::ElementType_OTHER},
 | 
| +    {proto::ELEMENT_TYPE_SCRIPT, flat::ElementType_SCRIPT},
 | 
| +    {proto::ELEMENT_TYPE_IMAGE, flat::ElementType_IMAGE},
 | 
| +    {proto::ELEMENT_TYPE_STYLESHEET, flat::ElementType_STYLESHEET},
 | 
| +    {proto::ELEMENT_TYPE_OBJECT, flat::ElementType_OBJECT},
 | 
| +    {proto::ELEMENT_TYPE_XMLHTTPREQUEST, flat::ElementType_XMLHTTPREQUEST},
 | 
| +    {proto::ELEMENT_TYPE_OBJECT_SUBREQUEST,
 | 
| +     flat::ElementType_OBJECT},  // Normally we can not distinguish between the
 | 
| +                                 // main plugin resource and any other loads it
 | 
| +                                 // makes. We treat them both as OBJECT
 | 
| +                                 // requests.
 | 
| +    {proto::ELEMENT_TYPE_SUBDOCUMENT, flat::ElementType_SUBDOCUMENT},
 | 
| +    {proto::ELEMENT_TYPE_PING, flat::ElementType_PING},
 | 
| +    {proto::ELEMENT_TYPE_MEDIA, flat::ElementType_MEDIA},
 | 
| +    {proto::ELEMENT_TYPE_FONT, flat::ElementType_FONT},
 | 
| +    {proto::ELEMENT_TYPE_POPUP,
 | 
| +     flat::ElementType_NONE},  // Filterning popups is not supported.
 | 
| +    {proto::ELEMENT_TYPE_WEBSOCKET, flat::ElementType_WEBSOCKET},
 | 
| +};
 | 
|  
 | 
|  base::StringPiece ToStringPiece(const flatbuffers::String* string) {
 | 
|    DCHECK(string);
 | 
| @@ -142,6 +175,9 @@ class UrlRuleFlatBufferConverter {
 | 
|    }
 | 
|  
 | 
|    bool InitializeOptions() {
 | 
| +    static_assert(flat::OptionFlag_ANY <= std::numeric_limits<uint8_t>::max(),
 | 
| +                  "Option flags can not be stored in uint8_t.");
 | 
| +
 | 
|      if (rule_.semantics() == proto::RULE_SEMANTICS_WHITELIST) {
 | 
|        options_ |= flat::OptionFlag_IS_WHITELIST;
 | 
|      } else if (rule_.semantics() != proto::RULE_SEMANTICS_BLACKLIST) {
 | 
| @@ -170,33 +206,27 @@ class UrlRuleFlatBufferConverter {
 | 
|    }
 | 
|  
 | 
|    bool InitializeElementTypes() {
 | 
| -    static_assert(
 | 
| -        proto::ELEMENT_TYPE_ALL <= std::numeric_limits<uint16_t>::max(),
 | 
| -        "Element types can not be stored in uint16_t.");
 | 
| -    element_types_ = static_cast<uint16_t>(rule_.element_types());
 | 
| +    static_assert(flat::ElementType_ANY <= std::numeric_limits<uint16_t>::max(),
 | 
| +                  "Element types can not be stored in uint16_t.");
 | 
|  
 | 
| -    // 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;
 | 
| +    element_types_ = flat::ElementType_NONE;
 | 
|  
 | 
| -    // Ignore unknown element types.
 | 
| -    element_types_ &= proto::ELEMENT_TYPE_ALL;
 | 
| -    // Filtering popups is not supported.
 | 
| -    element_types_ &= ~proto::ELEMENT_TYPE_POPUP;
 | 
| +    for (const auto& pair : kElementTypeMaskPairs)
 | 
| +      if (rule_.element_types() & pair.first)
 | 
| +        element_types_ |= pair.second;
 | 
|  
 | 
|      return true;
 | 
|    }
 | 
|  
 | 
|    bool InitializeActivationTypes() {
 | 
|      static_assert(
 | 
| -        proto::ACTIVATION_TYPE_ALL <= std::numeric_limits<uint8_t>::max(),
 | 
| +        flat::ActivationType_ANY <= std::numeric_limits<uint8_t>::max(),
 | 
|          "Activation types can not be stored in uint8_t.");
 | 
| -    activation_types_ = static_cast<uint8_t>(rule_.activation_types());
 | 
| +    activation_types_ = flat::ActivationType_NONE;
 | 
|  
 | 
| -    // Only the following activation types are supported, ignore the others.
 | 
| -    activation_types_ &=
 | 
| -        proto::ACTIVATION_TYPE_DOCUMENT | proto::ACTIVATION_TYPE_GENERICBLOCK;
 | 
| +    for (const auto& pair : kActivationMaskPairs)
 | 
| +      if (rule_.activation_types() & pair.first)
 | 
| +        activation_types_ |= pair.second;
 | 
|  
 | 
|      return true;
 | 
|    }
 | 
| @@ -407,8 +437,9 @@ size_t GetLongestMatchingSubdomain(const url::Origin& origin,
 | 
|  bool DoesOriginMatchDomainList(const url::Origin& origin,
 | 
|                                 const flat::UrlRule& rule,
 | 
|                                 bool disable_generic_rules) {
 | 
| -  const bool is_generic = !rule.domains_included();
 | 
| -  DCHECK(is_generic || rule.domains_included()->size());
 | 
| +  const bool is_generic =
 | 
| +      !rule.domains_included() || !rule.domains_included()->size();
 | 
| +  // DCHECK(is_generic || rule.domains_included()->size());
 | 
|    if (disable_generic_rules && is_generic)
 | 
|      return false;
 | 
|  
 | 
| 
 |