Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update adblock-rust to 0.8.0 #19648

Merged
merged 4 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions browser/brave_shields/ad_block_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2292,8 +2292,8 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringWindowScriptlet) {
UpdateAdBlockInstanceWithRules(
"b.com##+js(hjt)",
"[{"
"\"name\": \"hijacktest\","
"\"aliases\": [\"hjt\"],"
"\"name\": \"hijacktest.js\","
"\"aliases\": [\"hjt.js\"],"
"\"kind\": {\"mime\": \"application/javascript\"},"
"\"content\": \"" +
scriptlet_base64 + "\"}]");
Expand Down Expand Up @@ -2336,7 +2336,7 @@ IN_PROC_BROWSER_TEST_F(ScriptletDebugLogsFlagEnabledTest, CanDebugSetToTrue) {
UpdateAdBlockInstanceWithRules(
"b.com##+js(debuggable)",
"[{"
"\"name\": \"debuggable\","
"\"name\": \"debuggable.js\","
"\"aliases\": [],"
"\"kind\": {\"mime\": \"application/javascript\"},"
"\"content\": \"" +
Expand Down Expand Up @@ -2371,8 +2371,8 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CheckForDeAmpPref) {
UpdateAdBlockInstanceWithRules(
"b.*##+js(deamp)",
"[{"
"\"name\": \"deamp\","
"\"aliases\": [\"deamp\"],"
"\"name\": \"deamp.js\","
"\"aliases\": [\"deamp.js\"],"
"\"kind\": {\"mime\": \"application/javascript\"},"
"\"content\": \"" +
scriptlet_base64 + "\"}]");
Expand Down Expand Up @@ -2409,8 +2409,8 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringIframeScriptlet) {
UpdateAdBlockInstanceWithRules(
"b.com##+js(hjt)",
"[{"
"\"name\": \"hijacktest\","
"\"aliases\": [\"hjt\"],"
"\"name\": \"hijacktest.js\","
"\"aliases\": [\"hjt.js\"],"
"\"kind\": {\"mime\": \"application/javascript\"},"
"\"content\": \"" +
scriptlet_base64 + "\"}]");
Expand Down
2 changes: 1 addition & 1 deletion components/brave_shields/adblock/rs/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rust_static_library("rust_lib") {
cxx_bindings = [ "src/lib.rs" ]

deps = [
"//brave/third_party/rust/adblock/v0_7:lib",
"//brave/third_party/rust/adblock/v0_8:lib",
"//brave/third_party/rust/thiserror/v1:lib",
"//third_party/rust/serde_json/v1:lib",
]
Expand Down
2 changes: 1 addition & 1 deletion components/brave_shields/adblock/rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
adblock = { version = "0.7.16", default-features = false, features = ["full-regex-handling", "debug-info", "css-validation"] }
adblock = { version = "0.8.0", default-features = false, features = ["full-regex-handling", "regex-debug-info", "css-validation"] }
cxx = "1.0"
serde_json = "1.0"
thiserror = "1.0"
Expand Down
13 changes: 6 additions & 7 deletions components/brave_shields/adblock/rs/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
use std::time::Duration;

use crate::ffi::{
BlockerDebugInfo, BlockerResult, FilterListMetadata, OptionalString, OptionalU16,
RegexDebugEntry, RegexManagerDiscardPolicy,
};
use adblock::blocker::{
BlockerDebugInfo as InnerBlockerDebugInfo, BlockerResult as InnerBlockerResult,
BlockerResult, FilterListMetadata, OptionalString, OptionalU16, RegexDebugEntry,
RegexDebugInfo, RegexManagerDiscardPolicy,
};
use adblock::blocker::BlockerResult as InnerBlockerResult;
use adblock::lists::{ExpiresInterval, FilterListMetadata as InnerFilterListMetadata};
use adblock::regex_manager::{
RegexDebugEntry as InnerRegexDebugEntry,
RegexDebugInfo as InnerRegexDebugInfo,
RegexManagerDiscardPolicy as InnerRegexManagerDiscardPolicy,
};

Expand Down Expand Up @@ -47,8 +46,8 @@ impl From<InnerRegexDebugEntry> for RegexDebugEntry {
}
}

impl From<InnerBlockerDebugInfo> for BlockerDebugInfo {
fn from(info: InnerBlockerDebugInfo) -> Self {
impl From<InnerRegexDebugInfo> for RegexDebugInfo {
fn from(info: InnerRegexDebugInfo) -> Self {
Self {
regex_data: info.regex_data.into_iter().map(|e| e.into()).collect(),
compiled_regex_count: info.compiled_regex_count,
Expand Down
43 changes: 25 additions & 18 deletions components/brave_shields/adblock/rs/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
use std::collections::HashSet;
use std::str::Utf8Error;

use adblock::engine::Engine as InnerEngine;
use adblock::Engine as InnerEngine;
use adblock::lists::FilterSet;
use adblock::resources::{MimeType, Resource, ResourceType};
use adblock::url_parser::ResolvesDomain;
use cxx::{let_cxx_string, CxxString, CxxVector};

use crate::ffi::{
resolve_domain_position, BlockerDebugInfo, BlockerResult, BoxEngineResult,
ContentBlockingRulesResult, FilterListMetadata, RegexManagerDiscardPolicy, UnitResult,
resolve_domain_position, BlockerResult, BoxEngineResult, ContentBlockingRulesResult,
FilterListMetadata, RegexDebugInfo, RegexManagerDiscardPolicy, UnitResult,
VecStringResult,
};
use crate::result::InternalError;
Expand Down Expand Up @@ -140,12 +140,14 @@ impl Engine {
// The following strings are guaranteed to be
// UTF-8, so unwrapping directly should be okay.
self.engine
.check_network_urls_with_hostnames_subset(
url.to_str().unwrap(),
hostname.to_str().unwrap(),
source_hostname.to_str().unwrap(),
request_type.to_str().unwrap(),
Some(third_party_request),
.check_network_request_subset(
&adblock::request::Request::preparsed(
url.to_str().unwrap(),
hostname.to_str().unwrap(),
source_hostname.to_str().unwrap(),
request_type.to_str().unwrap(),
third_party_request,
),
previously_matched_rule,
force_check_exceptions,
)
Expand All @@ -163,12 +165,14 @@ impl Engine {
// The following strings are also UTF-8.
self.engine
.get_csp_directives(
url.to_str().unwrap(),
hostname.to_str().unwrap(),
source_hostname.to_str().unwrap(),
request_type.to_str().unwrap(),
Some(third_party_request),
)
&adblock::request::Request::preparsed(
url.to_str().unwrap(),
hostname.to_str().unwrap(),
source_hostname.to_str().unwrap(),
request_type.to_str().unwrap(),
third_party_request,
),
)
.unwrap_or_default()
}

Expand All @@ -188,6 +192,9 @@ impl Engine {
aliases: vec![],
kind: ResourceType::Mime(MimeType::from(content_type.to_str()?)),
content: data.to_string(),
dependencies: vec![],
/// user-added resources require full permissions
permission: adblock::resources::PermissionMask::from_bits(0b11111111),
};
Ok(self.engine.add_resource(resource)?)
}()
Expand All @@ -200,7 +207,7 @@ impl Engine {
.ok()
.and_then(|resources_json| serde_json::from_str::<Vec<Resource>>(resources_json).ok())
.and_then(|resources| {
self.engine.use_resources(&resources);
self.engine.use_resources(resources);
Some(())
})
.is_some()
Expand All @@ -227,8 +234,8 @@ impl Engine {
.into()
}

pub fn get_debug_info(&self) -> BlockerDebugInfo {
self.engine.get_debug_info().blocker_debug_info.into()
pub fn get_regex_debug_info(&self) -> RegexDebugInfo {
self.engine.get_regex_debug_info().into()
}

pub fn discard_regex(&mut self, regex_id: u64) {
Expand Down
4 changes: 2 additions & 2 deletions components/brave_shields/adblock/rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod ffi {
exceptions: &CxxVector<CxxString>,
) -> VecStringResult;
/// Returns the blocker debug info containing regex info.
fn get_debug_info(&self) -> BlockerDebugInfo;
fn get_regex_debug_info(&self) -> RegexDebugInfo;
/// Removes a regex entry by the id.
fn discard_regex(&mut self, regex_id: u64);
/// Sets a discard policy for the regex manager.
Expand Down Expand Up @@ -125,7 +125,7 @@ mod ffi {
usage_count: usize,
}

struct BlockerDebugInfo {
struct RegexDebugInfo {
regex_data: Vec<RegexDebugEntry>,
compiled_regex_count: usize,
}
Expand Down
2 changes: 1 addition & 1 deletion components/brave_shields/browser/ad_block_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ bool AdBlockEngine::TagExists(const std::string& tag) {

base::Value::Dict AdBlockEngine::GetDebugInfo() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const auto debug_info_struct = ad_block_client_->get_debug_info();
const auto debug_info_struct = ad_block_client_->get_regex_debug_info();
base::Value::List regex_list;
for (const auto& regex_entry : debug_info_struct.regex_data) {
base::Value::Dict regex_info;
Expand Down
1 change: 0 additions & 1 deletion components/speedreader/rust/lib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ rust_static_library("lib") {

deps = [
"src/readability:lib",
"//brave/third_party/rust/flate2/v1:lib",
"//brave/third_party/rust/html5ever/v0_25:lib",
"//brave/third_party/rust/kuchiki/v0_8:lib",
"//brave/third_party/rust/lifeguard/v0_6:lib",
Expand Down
1 change: 0 additions & 1 deletion components/speedreader/rust/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ include = [
]

[dependencies]
flate2 = { version = "1.0.25", features = ["rust_backend"], default-features = false }
html5ever = "0.25.1"
kuchiki = "0.8.1"
lol_html = "0.3.0"
Expand Down
24 changes: 2 additions & 22 deletions third_party/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 4 additions & 17 deletions third_party/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ wycheproof = "0.4"

[dependencies.adblock]
default-features = false
version = "0.7"
features = ["full-regex-handling", "debug-info", "css-validation"]
version = "0.8"
features = ["full-regex-handling", "regex-debug-info", "css-validation"]
gn-variables-lib = "if (is_ios) {\n features += [\n \"content-blocking\",\n \"serde_json\",\n ]\n deps += [ \"//third_party/rust/serde_json/v1:lib\" ]\n } else {\n features += [\n \"object-pooling\",\n \"lifeguard\",\n \"unsync-regex-caching\",\n ]\n deps += [ \"//brave/third_party/rust/lifeguard/v0_6:lib\" ]\n }\n"

[dependencies.bigdecimal]
Expand Down Expand Up @@ -107,11 +107,6 @@ default-features = false
version = "0.10"
features = ["color", "regex"]

[dependencies.flate2]
default-features = false
version = "1"
features = ["rust_backend"]

[dependencies.html5ever]
version = "0.25"
build-script-outputs = ["rules.rs"]
Expand Down Expand Up @@ -209,8 +204,8 @@ build-script-outputs = ["tables.rs"]
[dependencies.uuid]
version = "0.8"
features = ["serde"]
[patch.crates-io.adblock_v0_7]
path = "adblock/v0_7/crate"
[patch.crates-io.adblock_v0_8]
path = "adblock/v0_8/crate"
package = "adblock"

[patch.crates-io.addchain_v0_2]
Expand Down Expand Up @@ -513,10 +508,6 @@ package = "ff"
path = "ff/v0_13/crate"
package = "ff"

[patch.crates-io.flate2_v1]
path = "flate2/v1/crate"
package = "flate2"

[patch.crates-io.fnv_v1]
path = "fnv/v1/crate"
package = "fnv"
Expand Down Expand Up @@ -1001,10 +992,6 @@ package = "remove_dir_all"
path = "ripemd/v0_1/crate"
package = "ripemd"

[patch.crates-io.rmp-serde_v0_13]
path = "rmp_serde/v0_13/crate"
package = "rmp-serde"

[patch.crates-io.rmp-serde_v0_15]
path = "rmp_serde/v0_15/crate"
package = "rmp-serde"
Expand Down
6 changes: 0 additions & 6 deletions third_party/rust/adblock/v0_7/crate/.cargo_vcs_info.json

This file was deleted.

Loading