File: declarative_net_request_api.h

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 (264 lines) | stat: -rw-r--r-- 9,075 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// 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.

#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_DECLARATIVE_NET_REQUEST_API_H_
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_DECLARATIVE_NET_REQUEST_API_H_

#include <string>

#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/extension_function.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/permissions/permissions_data.h"
#include "net/http/http_response_headers.h"

namespace extensions {

namespace declarative_net_request {
class CompositeMatcher;
struct ReadJSONRulesResult;
struct RequestAction;
struct RequestParams;
}  // namespace declarative_net_request

namespace api::declarative_net_request::GetDynamicRules {
struct Params;
}

class DeclarativeNetRequestUpdateDynamicRulesFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestUpdateDynamicRulesFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.updateDynamicRules",
                             DECLARATIVENETREQUEST_UPDATEDYNAMICRULES)

 protected:
  ~DeclarativeNetRequestUpdateDynamicRulesFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;

 private:
  void OnDynamicRulesUpdated(std::optional<std::string> error);
};

class DeclarativeNetRequestGetDynamicRulesFunction : public ExtensionFunction {
 public:
  DeclarativeNetRequestGetDynamicRulesFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.getDynamicRules",
                             DECLARATIVENETREQUEST_GETDYNAMICRULES)

 protected:
  ~DeclarativeNetRequestGetDynamicRulesFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;

 private:
  void OnDynamicRulesFetched(
      api::declarative_net_request::GetDynamicRules::Params params,
      declarative_net_request::ReadJSONRulesResult read_json_result);
};

class DeclarativeNetRequestUpdateSessionRulesFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestUpdateSessionRulesFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.updateSessionRules",
                             DECLARATIVENETREQUEST_UPDATESESSIONRULES)

 protected:
  ~DeclarativeNetRequestUpdateSessionRulesFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;

 private:
  void OnSessionRulesUpdated(std::optional<std::string> error);
};

class DeclarativeNetRequestGetSessionRulesFunction : public ExtensionFunction {
 public:
  DeclarativeNetRequestGetSessionRulesFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.getSessionRules",
                             DECLARATIVENETREQUEST_GETSESSIONRULES)

 protected:
  ~DeclarativeNetRequestGetSessionRulesFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestUpdateEnabledRulesetsFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestUpdateEnabledRulesetsFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.updateEnabledRulesets",
                             DECLARATIVENETREQUEST_UPDATEENABLEDRULESETS)

 protected:
  ~DeclarativeNetRequestUpdateEnabledRulesetsFunction() override;

 private:
  void OnEnabledStaticRulesetsUpdated(std::optional<std::string> error);

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestGetEnabledRulesetsFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestGetEnabledRulesetsFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.getEnabledRulesets",
                             DECLARATIVENETREQUEST_GETENABLEDRULESETS)

 protected:
  ~DeclarativeNetRequestGetEnabledRulesetsFunction() override;

 private:
  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestUpdateStaticRulesFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestUpdateStaticRulesFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.updateStaticRules",
                             DECLARATIVENETREQUEST_UPDATESTATICRULES)

 protected:
  ~DeclarativeNetRequestUpdateStaticRulesFunction() override;

 private:
  void OnStaticRulesUpdated(std::optional<std::string> error);

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestGetDisabledRuleIdsFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestGetDisabledRuleIdsFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.getDisabledRuleIds",
                             DECLARATIVENETREQUEST_GETDISABLEDRULEIDS)

 protected:
  ~DeclarativeNetRequestGetDisabledRuleIdsFunction() override;

 private:
  void OnDisabledRuleIdsRead(std::vector<int> disabled_rule_ids);

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestGetMatchedRulesFunction : public ExtensionFunction {
 public:
  DeclarativeNetRequestGetMatchedRulesFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.getMatchedRules",
                             DECLARATIVENETREQUEST_GETMATCHEDRULES)

  static void set_disable_throttling_for_tests(
      bool disable_throttling_for_test) {
    disable_throttling_for_test_ = disable_throttling_for_test;
  }

 protected:
  ~DeclarativeNetRequestGetMatchedRulesFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
  void GetQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) const override;
  bool ShouldSkipQuotaLimiting() const override;

 private:
  static bool disable_throttling_for_test_;
};

class DeclarativeNetRequestSetExtensionActionOptionsFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestSetExtensionActionOptionsFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.setExtensionActionOptions",
                             DECLARATIVENETREQUEST_SETACTIONCOUNTASBADGETEXT)

 protected:
  ~DeclarativeNetRequestSetExtensionActionOptionsFunction() override;

  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestIsRegexSupportedFunction : public ExtensionFunction {
 public:
  DeclarativeNetRequestIsRegexSupportedFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.isRegexSupported",
                             DECLARATIVENETREQUEST_ISREGEXSUPPORTED)

 protected:
  ~DeclarativeNetRequestIsRegexSupportedFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestGetAvailableStaticRuleCountFunction
    : public ExtensionFunction {
 public:
  DeclarativeNetRequestGetAvailableStaticRuleCountFunction();
  DECLARE_EXTENSION_FUNCTION(
      "declarativeNetRequest.getAvailableStaticRuleCount",
      DECLARATIVENETREQUEST_GETAVAILABLESTATICRULECOUNT)

 protected:
  ~DeclarativeNetRequestGetAvailableStaticRuleCountFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;
};

class DeclarativeNetRequestTestMatchOutcomeFunction : public ExtensionFunction {
 public:
  DeclarativeNetRequestTestMatchOutcomeFunction();
  DECLARE_EXTENSION_FUNCTION("declarativeNetRequest.testMatchOutcome",
                             DECLARATIVENETREQUEST_TESTMATCHOUTCOME)

 protected:
  ~DeclarativeNetRequestTestMatchOutcomeFunction() override;

  // ExtensionFunction override:
  ExtensionFunction::ResponseAction Run() override;

 private:
  using TestResponseHeaders =
      api::declarative_net_request::TestMatchRequestDetails::ResponseHeaders;

  // Parse `test_headers` provided by the API function's args into a headers
  // object. Populates `error` and returns null if parsing fails or if the
  // resultant headers contain invalid names or values.
  scoped_refptr<const net::HttpResponseHeaders> ParseHeaders(
      std::optional<TestResponseHeaders>& test_headers,
      std::string& error) const;

  // Creates a base::Value::List which wraps a list of dnr_api::MatchedRule from
  // the provided `actions`. The base::Value::List will be returned as part of
  // this API function's response.
  base::Value::List CreateMatchedRulesFromActions(
      const std::vector<declarative_net_request::RequestAction>& actions) const;

  // Returns a list of matching actions for the given request `params` against
  // this extension's `matcher`.
  std::vector<declarative_net_request::RequestAction> GetActions(
      const declarative_net_request::CompositeMatcher& matcher,
      const declarative_net_request::RequestParams& params,
      declarative_net_request::RulesetMatchingStage stage,
      PermissionsData::PageAccess page_access) const;
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_DECLARATIVE_NET_REQUEST_API_H_