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