Read the content blocking rules and make them available to the HTTP loader.

This commit is contained in:
Josh Matthews 2016-04-15 02:57:00 -04:00 committed by Anthony Ramine
parent 19b1cb4f07
commit 50fea8554e
7 changed files with 66 additions and 2 deletions

View file

@ -11,6 +11,7 @@ path = "lib.rs"
[dependencies] [dependencies]
bitflags = "0.7" bitflags = "0.7"
brotli = {git = "https://github.com/ende76/brotli-rs"} brotli = {git = "https://github.com/ende76/brotli-rs"}
content-blocker = "0.2"
cookie = {version = "0.2.4", features = ["serialize-rustc"]} cookie = {version = "0.2.4", features = ["serialize-rustc"]}
device = {git = "https://github.com/servo/devices"} device = {git = "https://github.com/servo/devices"}
devtools_traits = {path = "../devtools_traits"} devtools_traits = {path = "../devtools_traits"}
@ -18,6 +19,7 @@ flate2 = "0.2.0"
hyper = {version = "0.9", features = ["serde-serialization"]} hyper = {version = "0.9", features = ["serde-serialization"]}
immeta = "0.3.1" immeta = "0.3.1"
ipc-channel = {git = "https://github.com/servo/ipc-channel"} ipc-channel = {git = "https://github.com/servo/ipc-channel"}
lazy_static = "0.2"
log = "0.3.5" log = "0.3.5"
matches = "0.1" matches = "0.1"
mime = "0.2.0" mime = "0.2.0"

View 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)
}

View file

@ -2,9 +2,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use brotli::Decompressor; use brotli::Decompressor;
use connector::Connector; use connector::Connector;
use content_blocker_parser::RuleList;
use cookie; use cookie;
use cookie_storage::CookieStorage; use cookie_storage::CookieStorage;
use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest}; use devtools_traits::{ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest};
@ -104,6 +104,7 @@ pub struct HttpState {
pub hsts_list: Arc<RwLock<HstsList>>, pub hsts_list: Arc<RwLock<HstsList>>,
pub cookie_jar: Arc<RwLock<CookieStorage>>, pub cookie_jar: Arc<RwLock<CookieStorage>>,
pub auth_cache: Arc<RwLock<AuthCache>>, pub auth_cache: Arc<RwLock<AuthCache>>,
pub blocked_content: Arc<Option<RuleList>>,
} }
impl HttpState { impl HttpState {
@ -112,6 +113,7 @@ impl HttpState {
hsts_list: Arc::new(RwLock::new(HstsList::new())), hsts_list: Arc::new(RwLock::new(HstsList::new())),
cookie_jar: Arc::new(RwLock::new(CookieStorage::new())), cookie_jar: Arc::new(RwLock::new(CookieStorage::new())),
auth_cache: Arc::new(RwLock::new(AuthCache::new())), auth_cache: Arc::new(RwLock::new(AuthCache::new())),
blocked_content: Arc::new(None),
} }
} }
} }

View file

@ -16,6 +16,7 @@
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;
extern crate brotli; extern crate brotli;
extern crate content_blocker as content_blocker_parser;
extern crate cookie as cookie_rs; extern crate cookie as cookie_rs;
extern crate device; extern crate device;
extern crate devtools_traits; extern crate devtools_traits;
@ -23,6 +24,7 @@ extern crate flate2;
extern crate hyper; extern crate hyper;
extern crate immeta; extern crate immeta;
extern crate ipc_channel; extern crate ipc_channel;
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] #[no_link] extern crate matches; #[macro_use] #[no_link] extern crate matches;
#[macro_use] #[macro_use]
@ -49,6 +51,7 @@ pub mod about_loader;
pub mod bluetooth_thread; pub mod bluetooth_thread;
pub mod chrome_loader; pub mod chrome_loader;
pub mod connector; pub mod connector;
pub mod content_blocker;
pub mod cookie; pub mod cookie;
pub mod cookie_storage; pub mod cookie_storage;
pub mod data_loader; pub mod data_loader;

View file

@ -6,6 +6,7 @@
use about_loader; use about_loader;
use chrome_loader; use chrome_loader;
use connector::{Connector, create_http_connector}; use connector::{Connector, create_http_connector};
use content_blocker::BLOCKED_CONTENT_RULES;
use cookie; use cookie;
use cookie_storage::CookieStorage; use cookie_storage::CookieStorage;
use data_loader; use data_loader;
@ -453,7 +454,8 @@ impl CoreResourceManager {
let http_state = HttpState { let http_state = HttpState {
hsts_list: self.hsts_list.clone(), hsts_list: self.hsts_list.clone(),
cookie_jar: self.cookie_jar.clone(), cookie_jar: self.cookie_jar.clone(),
auth_cache: self.auth_cache.clone() auth_cache: self.auth_cache.clone(),
blocked_content: BLOCKED_CONTENT_RULES.clone(),
}; };
http_loader::factory(self.user_agent.clone(), http_loader::factory(self.user_agent.clone(),
http_state, http_state,

View file

@ -363,6 +363,16 @@ dependencies = [
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)", "webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
] ]
[[package]]
name = "content-blocker"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex 0.1.71 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.2.4" version = "0.2.4"
@ -1357,6 +1367,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"brotli 0.3.23 (git+https://github.com/ende76/brotli-rs)", "brotli 0.3.23 (git+https://github.com/ende76/brotli-rs)",
"content-blocker 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"device 0.0.1 (git+https://github.com/servo/devices)", "device 0.0.1 (git+https://github.com/servo/devices)",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
@ -1364,6 +1375,7 @@ dependencies = [
"hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)", "ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",

12
ports/cef/Cargo.lock generated
View file

@ -325,6 +325,16 @@ dependencies = [
"webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)", "webrender_traits 0.1.0 (git+https://github.com/servo/webrender_traits)",
] ]
[[package]]
name = "content-blocker"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex 0.1.71 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.2.4" version = "0.2.4"
@ -1262,6 +1272,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"brotli 0.3.23 (git+https://github.com/ende76/brotli-rs)", "brotli 0.3.23 (git+https://github.com/ende76/brotli-rs)",
"content-blocker 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"device 0.0.1 (git+https://github.com/servo/devices)", "device 0.0.1 (git+https://github.com/servo/devices)",
"devtools_traits 0.0.1", "devtools_traits 0.0.1",
@ -1269,6 +1280,7 @@ dependencies = [
"hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)",
"immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "immeta 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)", "ipc-channel 0.2.2 (git+https://github.com/servo/ipc-channel)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",