File: ruleset_source.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 (83 lines) | stat: -rw-r--r-- 3,024 bytes parent folder | download | duplicates (5)
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
// Copyright 2020 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_RULESET_SOURCE_H_
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULESET_SOURCE_H_

#include <cstdint>
#include <memory>
#include <string>

#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/api/declarative_net_request/constants.h"
#include "extensions/common/extension_id.h"

namespace extensions::declarative_net_request {
class ParseInfo;
class RulesetMatcher;

// Encapsulates information for a single extension ruleset.
class RulesetSource {
 public:
  // Bitflags to configure rule parsing behavior.
  enum ParseFlags {
    // Ignore all invalid or large regex rules.
    kNone = 0,

    // When an error is raised for a rule, further rule parsing is stopped. When
    // a warning is raised for a rule, the problematic rule is skipped, but the
    // parsing of the remaining rules continues. It is not possible to raise
    // both an error and a warning for a rule.

    kRaiseErrorOnInvalidRules = 1 << 0,
    kRaiseWarningOnInvalidRules = 1 << 1,

    kRaiseErrorOnLargeRegexRules = 1 << 2,
    kRaiseWarningOnLargeRegexRules = 1 << 3
  };

  RulesetSource(RulesetID id,
                size_t rule_count_limit,
                ExtensionId extension_id,
                bool enabled);
  virtual ~RulesetSource();
  RulesetSource(RulesetSource&&);
  RulesetSource& operator=(RulesetSource&&);
  RulesetSource(const RulesetSource&) = delete;
  RulesetSource& operator=(const RulesetSource&) = delete;

  // Each ruleset source within an extension has a distinct ID.
  RulesetID id() const { return id_; }

  // The maximum number of rules that will be indexed from this source.
  size_t rule_count_limit() const { return rule_count_limit_; }

  // The ID of the extension from which the ruleset originates from.
  const ExtensionId& extension_id() const { return extension_id_; }

  // Whether the ruleset is enabled by default (as specified in the extension
  // manifest for a static ruleset). Always true for a dynamic ruleset.
  bool enabled_by_default() const { return enabled_by_default_; }

  // Indexes the given `rules` in indexed/flatbuffer format.
  ParseInfo IndexRules(std::vector<api::declarative_net_request::Rule> rules,
                       uint8_t parse_flags) const;

  // Creates a verified RulesetMatcher corresponding to the buffer in `data`.
  // Returns kSuccess on success along with the ruleset `matcher`.
  LoadRulesetResult CreateVerifiedMatcher(
      std::string data,
      std::unique_ptr<RulesetMatcher>* matcher) const;

 private:
  RulesetID id_;
  size_t rule_count_limit_;
  ExtensionId extension_id_;
  bool enabled_by_default_;
};

}  // namespace extensions::declarative_net_request

#endif  // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_RULESET_SOURCE_H_