File: extension_ruleset.fbs

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (220 lines) | stat: -rw-r--r-- 7,396 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

include "components/url_pattern_index/flat/url_pattern_index.fbs";

// NOTE: Increment kIndexedRulesetFormatVersion at
// extensions/browser/api/declarative_net_request/utils.cc whenever
// making a breaking change to this schema.

namespace extensions.declarative_net_request.flat;

/// The type of an action. Corresponds to
/// extensions::api::declarative_net_request::RuleActionType.
enum ActionType : ubyte {
  block,
  allow,
  redirect,
  upgrade_scheme,
  modify_headers,
  allow_all_requests,
  /// Number of actions. Must be the last entry.
  count
}

table QueryKeyValue {
  key : string (required);
  value : string (required);
  replace_only: bool = false;
}

table UrlTransform {
   scheme : string;
   host : string;

   clear_port : bool = false;
   port : string;

   clear_path : bool = false;
   path : string;

   clear_query : bool = false;

   /// If valid, doesn't include the '?' separator.
   query : string;

   /// Query params to be removed. These are already sorted and escaped using
   /// base::EscapeQueryParamValue.
   remove_query_params : [string];

   /// Query params to be added/replaced. These are already escaped using
   /// base::EscapeQueryParamValue.
   add_or_replace_query_params : [QueryKeyValue];

   clear_fragment : bool = false;

   /// If valid, doesn't include the '#' separator.
   fragment : string;

   username : string;
   password : string;
}

/// Additional extension related metadata for a url_pattern_index UrlRule.
table UrlRuleMetadata {
  /// ID of the UrlRule for which this metadata is stored.
  id : uint (key);

  /// Action type for this rule.
  action : ActionType;

  /// Redirect url for this rule. Should represent a valid GURL. At most one of
  /// |redirect_url| and |transform| should be specified for redirect rules.
  redirect_url : string;

  /// UrlTransform for this rule.
  transform : UrlTransform;

  /// A list of ModifyHeaderInfo, for both request and response headers. Valid
  /// for "modifyHeaders" rules.
  request_headers: [ModifyHeaderInfo];
  response_headers: [ModifyHeaderInfo];
}

// Extension embedder conditions for a flat::UrlRule. This is stored as a nested
// flatbuffer in `flat::UrlRule::embedder_conditions`. The constructed
// flatbuffer must use `kEmbedderConditionsBufferIdentifier` as the file
// identifier.
table EmbedderConditions {
  /// Sorted list of tab IDs to include/exclude.
  tab_ids_included: [int];
  tab_ids_excluded: [int];

  /// Headers to include/exclude. Note that `excluded_response_headers` will
  /// only match on header names.
  /// TODO(crbug.com/41482616): Consider relocating these header conditions as
  /// they apply to requests and what "embeds" the requests (such as the
  /// browser). One potentially suitable place would be a new table in the
  /// UrlPatternIndex for more complex conditions from requests and responses,
  /// especially if future components may reuse these conditions.
  response_headers: [HeaderCondition];
  excluded_response_headers: [HeaderCondition];
}

/// This provides a mapping from an index type to its index within
/// the |index_list| vector.
enum IndexType : ubyte {
  /// Index for rules that are evaluated during the onBeforeRequest stage of a
  /// request, excluding allowAllRequests rules.
  before_request_except_allow_all_requests = 0,

  /// Index for allowAllRequests rule. We have a separate index for these rules
  /// since they need to be evaluated separately when a navigation commits.
  allow_all_requests,

  modify_headers,

  /// Number of indices. Must be the last entry.
  count
}

/// Options for regex filters and substitutions for headers. Corresponds to
/// extensions::api::declarative_net_request::HeaderRegexOptions.
table RegexFilterOptions {
  /// Whether the regex should match all groups for the value. This is only
  /// relevant if a regex substitution is present and would thus need to be
  /// applied onto all matching groups. Equivalent to the "g" flag.
  /// Defaults to false.
  match_all: bool = false;
}

/// The type of header operation for modifyHeaders rules. Corresponds to
/// extensions::api::declarative_net_request::HeaderOperation.
enum HeaderOperation : ubyte {
  append,
  set,
  remove
}

/// Describes the header to be modified and operation to be performed on it.
/// Corresponds to extensions::api::declarative_net_request::ModifyHeaderInfo.
table ModifyHeaderInfo {
  operation: HeaderOperation;
  /// The name the header to be modified. Since header names are
  /// case-insensitive, the header name is normalized by converting it to
  /// lowercase.
  header: string;

  /// The value of the header to be set/appended. Should be specified only if
  /// |operation| is append or set.
  value: string;

  /// A regular expression to match against the header value. This follows the
  /// RE2 syntax for consistency with the rest of the API.
  regex_filter: string;

  /// Substitution pattern for the response header. `regexFilter` must be
  /// specified for this to be valid. Takes precedence over `value` and
  /// `operation` if specified and valid.
  regex_substitution: string;

  /// Options for the regex filter. If not specified, all options will be
  /// default.
  regex_options: RegexFilterOptions;
}

/// Describes the matching condition for a header, Corresponds to
/// extensions::api::declarative_net_request::HeaderInfo.
table HeaderCondition {
  /// The name of the header to be matched on.
  header: string;
  /// Header values to include or exclude for matching, if non-empty. This is
  /// converted into lowercase.
  values: [string];
  excluded_values: [string];
}

/// Completely represents a rule with a regex filter.
table RegexRule {
  /// The underlying UrlRule.
  url_rule: url_pattern_index.flat.UrlRule;

  /// The action to take.
  // TODO(tbodt): this is duplicated in the UrlRuleMetadata. We should either
  // use the action type in the metadata or not use UrlRuleMetadata at all for
  // regex rules.
  action_type: ActionType;

  /// The regex substitution pattern for this rule if specified.
  regex_substitution: string;
}

/// The top-level data structure used to store extensions URL rules for the
/// Declarative Net Request API.
table ExtensionIndexedRuleset {
  /// Vector of UrlPatternIndex. This will consist of `IndexType_count` indices.
  /// This index list is for rules that can be matched before a request is
  /// initiated.
  before_request_index_list : [url_pattern_index.flat.UrlPatternIndex];

  /// An index list of `IndexType_count` indices for rules that are matched
  /// after response headers have been received from a request.
  headers_received_index_list : [url_pattern_index.flat.UrlPatternIndex];

  /// Regex rules are not matched by UrlPatternIndex and so we don't build an
  /// index for them. This list is for rules that can be matched before a
  /// request is initiated.
  before_request_regex_rules: [RegexRule];

  /// List of regex rules that are matched after response headers have been
  /// received from a request.
  headers_received_regex_rules: [RegexRule];

  /// Extension related metadata. Sorted by id, to support fast lookup.
  extension_metadata : [UrlRuleMetadata];
}

root_type ExtensionIndexedRuleset;

file_identifier "EXTR";