mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
Read the content blocking rules and make them available to the HTTP loader.
This commit is contained in:
parent
19b1cb4f07
commit
50fea8554e
7 changed files with 66 additions and 2 deletions
31
components/net/content_blocker.rs
Normal file
31
components/net/content_blocker.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use content_blocker_parser::{RuleList, parse_list};
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
use util::resource_files::read_resource_file;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref BLOCKED_CONTENT_RULES: Arc<Option<RuleList>> = Arc::new(create_rule_list());
|
||||
}
|
||||
|
||||
fn create_rule_list() -> Option<RuleList> {
|
||||
let contents = match read_resource_file("blocked-content.json") {
|
||||
Ok(c) => c,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let str_contents = match str::from_utf8(&contents) {
|
||||
Ok(c) => c,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let list = match parse_list(&str_contents) {
|
||||
Ok(l) => l,
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
Some(list)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue