rules.proto 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. syntax = "proto2";
  5. option optimize_for = LITE_RUNTIME;
  6. package url_pattern_index.proto;
  7. option java_package = "org.chromium.components.url_pattern_index.proto";
  8. // The type of a subresource filtering rule.
  9. enum RuleType {
  10. RULE_TYPE_UNSPECIFIED = 0;
  11. RULE_TYPE_COMMENT = 1; // Comment rule.
  12. RULE_TYPE_URL = 2; // Network level filtering rule based on URL pattern.
  13. RULE_TYPE_CSS = 3; // Element hiding rule based on a CSS selector.
  14. };
  15. // The format of a URL pattern.
  16. enum UrlPatternType {
  17. URL_PATTERN_TYPE_UNSPECIFIED = 0;
  18. // A pattern without special characters, e.g. "example.com".
  19. URL_PATTERN_TYPE_SUBSTRING = 1;
  20. // The pattern contains one or more wildcards, namely '*' and/or '^'
  21. // characters. The '*' matches any sequence of characters, while the '^'
  22. // matches a separator, i.e. anything but a letter, a digit, or one of [-._%].
  23. URL_PATTERN_TYPE_WILDCARDED = 2;
  24. // The pattern is a regular expression.
  25. URL_PATTERN_TYPE_REGEXP = 3;
  26. };
  27. // Types of anchors that can be used to constrain where a URL pattern must
  28. // begin/end in the URL in order to be considered a match.
  29. enum AnchorType {
  30. ANCHOR_TYPE_UNSPECIFIED = 0;
  31. // Acts like a '*' wildcard at the respective end of a pattern.
  32. ANCHOR_TYPE_NONE = 1;
  33. // The pattern must match from the start/until the end of the URL.
  34. ANCHOR_TYPE_BOUNDARY = 2;
  35. // The pattern must match starting with the TLD+n of the URL's domain, but the
  36. // scheme and subdomains (if any) can be arbitrary.
  37. ANCHOR_TYPE_SUBDOMAIN = 3;
  38. };
  39. // The types of subresource requests that a URL rule should be applied to.
  40. // Note: Values are used as flags in a bitmask.
  41. enum ElementType {
  42. option allow_alias = true;
  43. ELEMENT_TYPE_UNSPECIFIED = 0;
  44. ELEMENT_TYPE_OTHER = 1;
  45. ELEMENT_TYPE_SCRIPT = 2;
  46. ELEMENT_TYPE_IMAGE = 4;
  47. ELEMENT_TYPE_STYLESHEET = 8;
  48. ELEMENT_TYPE_OBJECT = 16;
  49. ELEMENT_TYPE_XMLHTTPREQUEST = 32;
  50. ELEMENT_TYPE_OBJECT_SUBREQUEST = 64;
  51. ELEMENT_TYPE_SUBDOCUMENT = 128;
  52. ELEMENT_TYPE_PING = 256;
  53. ELEMENT_TYPE_MEDIA = 512;
  54. ELEMENT_TYPE_FONT = 1024;
  55. ELEMENT_TYPE_POPUP = 2048;
  56. ELEMENT_TYPE_WEBSOCKET = 4096;
  57. ELEMENT_TYPE_WEBTRANSPORT = 8192;
  58. ELEMENT_TYPE_WEBBUNDLE = 16384;
  59. // NOTE: Keep these two values consistent with the values above.
  60. ELEMENT_TYPE_MAX = 16384;
  61. ELEMENT_TYPE_ALL = 32767;
  62. };
  63. // The options controlling whether or not to activate filtering for subresources
  64. // of documents that match the URL pattern of the rule.
  65. // Note: Values are used as flags in a bitmask.
  66. enum ActivationType {
  67. option allow_alias = true;
  68. ACTIVATION_TYPE_UNSPECIFIED = 0;
  69. ACTIVATION_TYPE_DOCUMENT = 1; // Disable all rules on the page.
  70. ACTIVATION_TYPE_ELEMHIDE = 2; // Disable CSS rules on the page.
  71. ACTIVATION_TYPE_GENERICHIDE = 4; // Disable generic CSS rules on the page.
  72. ACTIVATION_TYPE_GENERICBLOCK = 8; // Disable generic URL rules on the page.
  73. // NOTE: Keep these two values consistent with the values above.
  74. ACTIVATION_TYPE_MAX = 8;
  75. ACTIVATION_TYPE_ALL = 15;
  76. };
  77. // The semantics of a rule. Defines how the rule relates to other rules and how
  78. // it influences the filtering decision.
  79. enum RuleSemantics {
  80. RULE_SEMANTICS_UNSPECIFIED = 0;
  81. // Matching subresource requests should be aborted, matching elements should
  82. // be hidden.
  83. RULE_SEMANTICS_BLOCKLIST = 1;
  84. // If the rule matches, it suppresses any matching RULE_SEMANTICS_BLOCKLIST
  85. // rule.
  86. RULE_SEMANTICS_ALLOWLIST = 2;
  87. }
  88. // The type of relation between the source of the requested subresource and that
  89. // of the document.
  90. enum SourceType {
  91. SOURCE_TYPE_UNSPECIFIED = 0;
  92. SOURCE_TYPE_ANY = 1; // Doesn't matter.
  93. SOURCE_TYPE_THIRD_PARTY = 2; // Requesting a trird-party resource.
  94. SOURCE_TYPE_FIRST_PARTY = 3; // Requesting a first-party resource.
  95. }
  96. // An item of the domain list.
  97. message DomainListItem {
  98. // The UTF-8 representation of the domain, e.g. "subdomain.example.com".
  99. optional string domain = 1;
  100. // Defines whether the domain is excluded from the set of domains.
  101. optional bool exclude = 2;
  102. }
  103. // A network level filtering rule based on a URL pattern. Corresponds to
  104. // RULE_TYPE_URL.
  105. message UrlRule {
  106. // The semantics of the rule.
  107. optional RuleSemantics semantics = 1;
  108. // Restricts application of the rule to first-party/third-party requests.
  109. optional SourceType source_type = 2;
  110. // Stores the ElementTypes that the rule applies to as a bitwise OR of the
  111. // corresponding ElementType values.
  112. optional int32 element_types = 3;
  113. // Stores the ActivationTypes associated with the rule as a bitwise OR of the
  114. // corresponding ActivationType values.
  115. optional int32 activation_types = 4;
  116. // The rule applies only to subresources of documents loaded from included
  117. // domains (or subdomains thereof). If the list is empty, the rule is applied
  118. // on documents from all domains.
  119. // If `initiator_domains` is empty or only contains exceptions, the rule is
  120. // called generic.
  121. // Otherwise is it called domain specific, i.e. applies to a limited number of
  122. // domains.
  123. repeated DomainListItem initiator_domains = 5;
  124. // The format of |url_pattern|.
  125. optional UrlPatternType url_pattern_type = 6;
  126. // Defines where the URL pattern must start in the URL in order to be
  127. // considered a match. Never used with REGEXP patterns.
  128. optional AnchorType anchor_left = 7;
  129. // Defines where the URL pattern must end in the URL in order to be
  130. // considered a match. Never used with REGEXP patterns. Never equals to
  131. // ANCHOR_TYPE_SUBDOMAIN.
  132. optional AnchorType anchor_right = 8;
  133. // When set, the rule applies only to URLs that match |url_pattern| in a
  134. // case-sensitive way.
  135. // Not currently implemented.
  136. optional bool match_case = 9 [deprecated = true];
  137. // The URL pattern of the format prescribed by |url_pattern_type|.
  138. optional string url_pattern = 10;
  139. // The rule applies only for requests to the included domains (or subdomains
  140. // thereof). If the list is empty, the rule applies to requests to all
  141. // domains.
  142. repeated DomainListItem request_domains = 11;
  143. }
  144. // Element hiding rule based on a CSS selector. Corresponds to RULE_TYPE_CSS.
  145. message CssRule {
  146. // The semantics of the rule.
  147. optional RuleSemantics semantics = 1;
  148. // The list of domains, same as UrlRule::domains.
  149. repeated DomainListItem domains = 2;
  150. // A CSS selector as specified in http://www.w3.org/TR/css3-selectors.
  151. optional string css_selector = 3;
  152. }
  153. // A comment line.
  154. message Comment {
  155. // Comment text.
  156. optional string text = 1;
  157. // For special key-value comments, if any.
  158. optional string key = 2;
  159. optional string value = 3;
  160. }
  161. // A container for lists of non-comment rules collated by RuleType.
  162. message FilteringRules {
  163. repeated UrlRule url_rules = 1;
  164. repeated CssRule css_rules = 2;
  165. }