aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/content_blocker.rs
blob: c30961263dcf3ee046c6cd32a64d3b519845c3a5 (plain) (blame)
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
/* 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)
}