chromiumoxide/handler/blockers/
mod.rs1pub mod adblock_patterns;
3pub mod intercept_manager;
5pub mod scripts;
7pub mod xhr;
9
10#[derive(Default, Debug)]
12pub struct TrieNode {
13 pub children: hashbrown::HashMap<char, TrieNode>,
15 pub is_end_of_word: bool,
17}
18
19#[derive(Debug)]
21pub struct Trie {
22 pub root: TrieNode,
24}
25
26impl Trie {
27 pub fn new() -> Self {
29 Trie {
30 root: TrieNode::default(),
31 }
32 }
33 pub fn insert(&mut self, word: &str) {
35 let mut node = &mut self.root;
36 for ch in word.chars() {
37 node = node.children.entry(ch).or_insert_with(TrieNode::default);
38 }
39 node.is_end_of_word = true;
40 }
41
42 #[inline]
44 pub fn contains_prefix(&self, text: &str) -> bool {
45 let mut node = &self.root;
46
47 for ch in text.chars() {
48 if let Some(next_node) = node.children.get(&ch) {
49 node = next_node;
50 if node.is_end_of_word {
51 return true;
52 }
53 } else {
54 break;
55 }
56 }
57
58 false
59 }
60}
61
62pub(crate) fn ignore_script_embedded(url: &str) -> bool {
64 crate::handler::blockers::scripts::URL_IGNORE_EMBEDED_TRIE.contains_prefix(url)
65}
66
67pub(crate) fn ignore_script_xhr(url: &str) -> bool {
69 crate::handler::blockers::xhr::URL_IGNORE_XHR_TRIE.contains_prefix(url)
70}
71
72pub(crate) fn ignore_script_xhr_media(url: &str) -> bool {
74 crate::handler::blockers::xhr::URL_IGNORE_XHR_MEDIA_TRIE.contains_prefix(url)
75}