chromium/components/subresource_filter/tools/rule_parser/rule.h

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains definitions of data structures needed for representing
// filtering/hiding rules as parsed from EasyList. See the following links for
// detailed explanation on available rule types and their syntax:
//  https://adblockplus.org/en/filters
//  https://adblockplus.org/en/filter-cheatsheet
// For out-of-documentation options see the following:
//  https://adblockplus.org/forum/viewtopic.php?t=9353
//  https://adblockplus.org/development-builds/experimental-pop-up-blocking-support
//  https://adblockplus.org/development-builds/new-filter-options-generichide-and-genericblock
//
// TODO(pkalinnikov): Consider removing these classes, leaving only the
// corresponding protobuf structures.

#ifndef COMPONENTS_SUBRESOURCE_FILTER_TOOLS_RULE_PARSER_RULE_H_
#define COMPONENTS_SUBRESOURCE_FILTER_TOOLS_RULE_PARSER_RULE_H_

#include <ostream>
#include <string>
#include <vector>

#include "components/subresource_filter/tools/rule_parser/rule_options.h"
#include "components/url_pattern_index/proto/rules.pb.h"

namespace subresource_filter {

UrlPatternType;
RuleType;
AnchorType;

// Represents the three values in a kind of tri-state logic.
enum class TriState {};

// A single URL filtering rule as parsed from EasyList.
// TODO(pkalinnikov): Add 'sitekey', 'collapse', and 'donottrack' options.
struct UrlRule {};

// A single CSS element hiding rule as parsed from EasyList.
struct CssRule {};

// Sorts domain patterns in decreasing order of length (and alphabetically
// within same-length groups).
void CanonicalizeDomainList(std::vector<std::string>* domains);

// Converts protobuf |rule| into its canonical EasyList string representation.
std::string ToString(const url_pattern_index::proto::UrlRule& rule);
std::string ToString(const url_pattern_index::proto::CssRule& rule);

// For testing.
std::ostream& operator<<(std::ostream& os, const UrlRule& rule);
std::ostream& operator<<(std::ostream& os, const CssRule& rule);

}  // namespace subresource_filter

#endif  // COMPONENTS_SUBRESOURCE_FILTER_TOOLS_RULE_PARSER_RULE_H_