From f948fb0d9cb0dbece70b2b69259b0d5875bfcb25 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 17 Jan 2023 17:28:57 -0800 Subject: [PATCH 1/6] cleanup UrlCosmeticResources signature --- components/adblock_rust_ffi/src/lib.rs | 2 +- .../brave_shields/browser/ad_block_engine.cc | 13 ++++++++++--- .../brave_shields/browser/ad_block_engine.h | 2 +- .../brave_shields/browser/ad_block_service.cc | 19 +++++-------------- .../brave_shields/browser/ad_block_service.h | 2 +- .../browser/ad_block_service_helper.cc | 17 ++++++++--------- .../browser/ad_block_service_helper.h | 2 +- .../browser/cosmetic_filters_resources.cc | 3 +-- 8 files changed, 28 insertions(+), 32 deletions(-) diff --git a/components/adblock_rust_ffi/src/lib.rs b/components/adblock_rust_ffi/src/lib.rs index e936cd807a96..5017e4e73715 100644 --- a/components/adblock_rust_ffi/src/lib.rs +++ b/components/adblock_rust_ffi/src/lib.rs @@ -356,7 +356,7 @@ pub unsafe extern "C" fn engine_url_cosmetic_resources( assert!(!engine.is_null()); let engine = Box::leak(Box::from_raw(engine)); CString::new( - serde_json::to_string(&engine.url_cosmetic_resources(url)).unwrap_or_else(|_| "".into()), + serde_json::to_string(&engine.url_cosmetic_resources(url)).unwrap_or_else(|_| "{}".into()), ) .expect("Error: CString::new()") .into_raw() diff --git a/components/brave_shields/browser/ad_block_engine.cc b/components/brave_shields/browser/ad_block_engine.cc index 765e7aa2df8c..2ee20b77f326 100644 --- a/components/brave_shields/browser/ad_block_engine.cc +++ b/components/brave_shields/browser/ad_block_engine.cc @@ -178,10 +178,17 @@ bool AdBlockEngine::TagExists(const std::string& tag) { return base::Contains(tags_, tag); } -absl::optional AdBlockEngine::UrlCosmeticResources( - const std::string& url) { +base::Value::Dict AdBlockEngine::UrlCosmeticResources(const std::string& url) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return base::JSONReader::Read(ad_block_client_->urlCosmeticResources(url)); + absl::optional result = + base::JSONReader::Read(ad_block_client_->urlCosmeticResources(url)); + + if (!result) { + return base::Value::Dict(); + } else { + DCHECK(result->is_dict()); + return std::move(result->GetDict()); + } } base::Value::List AdBlockEngine::HiddenClassIdSelectors( diff --git a/components/brave_shields/browser/ad_block_engine.h b/components/brave_shields/browser/ad_block_engine.h index d05b50564e46..e90a7c73bb49 100644 --- a/components/brave_shields/browser/ad_block_engine.h +++ b/components/brave_shields/browser/ad_block_engine.h @@ -64,7 +64,7 @@ class AdBlockEngine : public base::SupportsWeakPtr { void EnableTag(const std::string& tag, bool enabled); bool TagExists(const std::string& tag); - absl::optional UrlCosmeticResources(const std::string& url); + base::Value::Dict UrlCosmeticResources(const std::string& url); base::Value::List HiddenClassIdSelectors( const std::vector& classes, const std::vector& ids, diff --git a/components/brave_shields/browser/ad_block_service.cc b/components/brave_shields/browser/ad_block_service.cc index 1265b656c0cc..2277f34258ce 100644 --- a/components/brave_shields/browser/ad_block_service.cc +++ b/components/brave_shields/browser/ad_block_service.cc @@ -170,24 +170,15 @@ absl::optional AdBlockService::GetCspDirectives( return csp_directives; } -absl::optional AdBlockService::UrlCosmeticResources( - const std::string& url) { +base::Value::Dict AdBlockService::UrlCosmeticResources(const std::string& url) { DCHECK(GetTaskRunner()->RunsTasksInCurrentSequence()); - absl::optional resources = - default_engine_->UrlCosmeticResources(url); + base::Value::Dict resources = default_engine_->UrlCosmeticResources(url); - if (!resources || !resources->is_dict()) { - return resources; - } - - absl::optional additional_resources = + base::Value::Dict additional_resources = additional_filters_engine_->UrlCosmeticResources(url); - if (additional_resources && additional_resources->is_dict()) { - MergeResourcesInto(std::move(additional_resources->GetDict()), - resources->GetIfDict(), - /*force_hide=*/true); - } + MergeResourcesInto(std::move(additional_resources), resources, + /*force_hide=*/true); return resources; } diff --git a/components/brave_shields/browser/ad_block_service.h b/components/brave_shields/browser/ad_block_service.h index 3ca3d828271f..922c749b0057 100644 --- a/components/brave_shields/browser/ad_block_service.h +++ b/components/brave_shields/browser/ad_block_service.h @@ -104,7 +104,7 @@ class AdBlockService { const GURL& url, blink::mojom::ResourceType resource_type, const std::string& tab_host); - absl::optional UrlCosmeticResources(const std::string& url); + base::Value::Dict UrlCosmeticResources(const std::string& url); base::Value::Dict HiddenClassIdSelectors( const std::vector& classes, const std::vector& ids, diff --git a/components/brave_shields/browser/ad_block_service_helper.cc b/components/brave_shields/browser/ad_block_service_helper.cc index 22fa2504af13..76401e80ecb2 100644 --- a/components/brave_shields/browser/ad_block_service_helper.cc +++ b/components/brave_shields/browser/ad_block_service_helper.cc @@ -42,18 +42,17 @@ void MergeCspDirectiveInto(absl::optional from, // will be moved into a possibly new field of `into` called // `force_hide_selectors`. void MergeResourcesInto(base::Value::Dict from, - base::Value::Dict* into, + base::Value::Dict& into, bool force_hide) { - DCHECK(into); base::Value::List* resources_hide_selectors = nullptr; if (force_hide) { - resources_hide_selectors = into->FindList("force_hide_selectors"); + resources_hide_selectors = into.FindList("force_hide_selectors"); if (!resources_hide_selectors) { resources_hide_selectors = - into->Set("force_hide_selectors", base::Value::List())->GetIfList(); + into.Set("force_hide_selectors", base::Value::List())->GetIfList(); } } else { - resources_hide_selectors = into->FindList("hide_selectors"); + resources_hide_selectors = into.FindList("hide_selectors"); } base::Value::List* from_resources_hide_selectors = from.FindList("hide_selectors"); @@ -64,7 +63,7 @@ void MergeResourcesInto(base::Value::Dict from, } base::Value::Dict* resources_style_selectors = - into->FindDict("style_selectors"); + into.FindDict("style_selectors"); base::Value::Dict* from_resources_style_selectors = from.FindDict("style_selectors"); if (resources_style_selectors && from_resources_style_selectors) { @@ -82,7 +81,7 @@ void MergeResourcesInto(base::Value::Dict from, } } - base::Value::List* resources_exceptions = into->FindList("exceptions"); + base::Value::List* resources_exceptions = into.FindList("exceptions"); base::Value::List* from_resources_exceptions = from.FindList("exceptions"); if (resources_exceptions && from_resources_exceptions) { for (auto& exception : *from_resources_exceptions) { @@ -90,7 +89,7 @@ void MergeResourcesInto(base::Value::Dict from, } } - auto* resources_injected_script = into->FindString("injected_script"); + auto* resources_injected_script = into.FindString("injected_script"); auto* from_resources_injected_script = from.FindString("injected_script"); if (resources_injected_script && from_resources_injected_script) { *resources_injected_script = base::StrCat( @@ -99,7 +98,7 @@ void MergeResourcesInto(base::Value::Dict from, auto from_resources_generichide = from.FindBool("generichide"); if (from_resources_generichide && *from_resources_generichide) { - into->Set("generichide", true); + into.Set("generichide", true); } } diff --git a/components/brave_shields/browser/ad_block_service_helper.h b/components/brave_shields/browser/ad_block_service_helper.h index e2f2d1a0530a..05f17301508d 100644 --- a/components/brave_shields/browser/ad_block_service_helper.h +++ b/components/brave_shields/browser/ad_block_service_helper.h @@ -20,7 +20,7 @@ void MergeCspDirectiveInto(absl::optional from, absl::optional* into); void MergeResourcesInto(base::Value::Dict from, - base::Value::Dict* into, + base::Value::Dict& into, bool force_hide); } // namespace brave_shields diff --git a/components/cosmetic_filters/browser/cosmetic_filters_resources.cc b/components/cosmetic_filters/browser/cosmetic_filters_resources.cc index 9236c53b880e..c0560374b191 100644 --- a/components/cosmetic_filters/browser/cosmetic_filters_resources.cc +++ b/components/cosmetic_filters/browser/cosmetic_filters_resources.cc @@ -71,8 +71,7 @@ void CosmeticFiltersResources::UrlCosmeticResources( UrlCosmeticResourcesCallback callback) { DCHECK(ad_block_service_->GetTaskRunner()->RunsTasksInCurrentSequence()); auto resources = ad_block_service_->UrlCosmeticResources(url); - std::move(callback).Run(resources ? std::move(resources.value()) - : base::Value()); + std::move(callback).Run(base::Value(std::move(resources))); } } // namespace cosmetic_filters From 610dbc1a38270024d518b7af4edc100854129d6e Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 17 Jan 2023 18:21:53 -0800 Subject: [PATCH 2/6] ignore filters with :has in standard blocking mode --- .../brave_shields/browser/ad_block_service.cc | 22 ++++++++++++++++++- .../brave_shields/browser/ad_block_service.h | 3 ++- .../browser/cosmetic_filters_resources.cc | 4 +++- .../browser/cosmetic_filters_resources.h | 1 + .../common/cosmetic_filters.mojom | 3 ++- .../renderer/cosmetic_filters_js_handler.cc | 5 +++-- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/components/brave_shields/browser/ad_block_service.cc b/components/brave_shields/browser/ad_block_service.cc index 2277f34258ce..cd02103bb995 100644 --- a/components/brave_shields/browser/ad_block_service.cc +++ b/components/brave_shields/browser/ad_block_service.cc @@ -170,10 +170,30 @@ absl::optional AdBlockService::GetCspDirectives( return csp_directives; } -base::Value::Dict AdBlockService::UrlCosmeticResources(const std::string& url) { +base::Value::Dict AdBlockService::UrlCosmeticResources( + const std::string& url, + bool aggressive_blocking) { DCHECK(GetTaskRunner()->RunsTasksInCurrentSequence()); base::Value::Dict resources = default_engine_->UrlCosmeticResources(url); + if (!aggressive_blocking) { + // `:has` procedural selectors from the default engine should not be hidden + // in standard blocking mode. + base::Value::List* default_hide_selectors = + resources.FindList("hide_selectors"); + if (default_hide_selectors) { + base::Value::List::iterator it = default_hide_selectors->begin(); + while (it < default_hide_selectors->end()) { + DCHECK(it->is_string()); + if (it->GetString().find(":has(") != std::string::npos) { + it = default_hide_selectors->erase(it); + } else { + it++; + } + } + } + } + base::Value::Dict additional_resources = additional_filters_engine_->UrlCosmeticResources(url); diff --git a/components/brave_shields/browser/ad_block_service.h b/components/brave_shields/browser/ad_block_service.h index 922c749b0057..dfff908d1fb3 100644 --- a/components/brave_shields/browser/ad_block_service.h +++ b/components/brave_shields/browser/ad_block_service.h @@ -104,7 +104,8 @@ class AdBlockService { const GURL& url, blink::mojom::ResourceType resource_type, const std::string& tab_host); - base::Value::Dict UrlCosmeticResources(const std::string& url); + base::Value::Dict UrlCosmeticResources(const std::string& url, + bool aggressive_blocking); base::Value::Dict HiddenClassIdSelectors( const std::vector& classes, const std::vector& ids, diff --git a/components/cosmetic_filters/browser/cosmetic_filters_resources.cc b/components/cosmetic_filters/browser/cosmetic_filters_resources.cc index c0560374b191..75bc2321debd 100644 --- a/components/cosmetic_filters/browser/cosmetic_filters_resources.cc +++ b/components/cosmetic_filters/browser/cosmetic_filters_resources.cc @@ -68,9 +68,11 @@ void CosmeticFiltersResources::HiddenClassIdSelectors( void CosmeticFiltersResources::UrlCosmeticResources( const std::string& url, + bool aggressive_blocking, UrlCosmeticResourcesCallback callback) { DCHECK(ad_block_service_->GetTaskRunner()->RunsTasksInCurrentSequence()); - auto resources = ad_block_service_->UrlCosmeticResources(url); + auto resources = + ad_block_service_->UrlCosmeticResources(url, aggressive_blocking); std::move(callback).Run(base::Value(std::move(resources))); } diff --git a/components/cosmetic_filters/browser/cosmetic_filters_resources.h b/components/cosmetic_filters/browser/cosmetic_filters_resources.h index 996c5594144a..6e48ec1c0b30 100644 --- a/components/cosmetic_filters/browser/cosmetic_filters_resources.h +++ b/components/cosmetic_filters/browser/cosmetic_filters_resources.h @@ -46,6 +46,7 @@ class CosmeticFiltersResources final // filtering to first party elements along with an initial set of rules and // scripts to apply for the given URL. void UrlCosmeticResources(const std::string& url, + bool aggressive_blocking, UrlCosmeticResourcesCallback callback) override; private: diff --git a/components/cosmetic_filters/common/cosmetic_filters.mojom b/components/cosmetic_filters/common/cosmetic_filters.mojom index 6a6beeba4c98..ffb1335376c8 100644 --- a/components/cosmetic_filters/common/cosmetic_filters.mojom +++ b/components/cosmetic_filters/common/cosmetic_filters.mojom @@ -8,5 +8,6 @@ interface CosmeticFiltersResources { mojo_base.mojom.DictionaryValue result); [Sync] - UrlCosmeticResources(string url) => (mojo_base.mojom.Value result); + UrlCosmeticResources(string url, bool aggressive_blocking) => ( + mojo_base.mojom.Value result); }; diff --git a/components/cosmetic_filters/renderer/cosmetic_filters_js_handler.cc b/components/cosmetic_filters/renderer/cosmetic_filters_js_handler.cc index 1a9014f73f77..ae986dd045e7 100644 --- a/components/cosmetic_filters/renderer/cosmetic_filters_js_handler.cc +++ b/components/cosmetic_filters/renderer/cosmetic_filters_js_handler.cc @@ -367,7 +367,7 @@ bool CosmeticFiltersJSHandler::ProcessURL( "Brave.CosmeticFilters.UrlCosmeticResources"); TRACE_EVENT1("brave.adblock", "UrlCosmeticResources", "url", url_.spec()); cosmetic_filters_resources_->UrlCosmeticResources( - url_.spec(), + url_.spec(), enabled_1st_party_cf_, base::BindOnce(&CosmeticFiltersJSHandler::OnUrlCosmeticResources, base::Unretained(this), std::move(callback.value()))); } else { @@ -376,7 +376,8 @@ bool CosmeticFiltersJSHandler::ProcessURL( SCOPED_UMA_HISTOGRAM_TIMER_MICROS( "Brave.CosmeticFilters.UrlCosmeticResourcesSync"); base::Value result; - cosmetic_filters_resources_->UrlCosmeticResources(url_.spec(), &result); + cosmetic_filters_resources_->UrlCosmeticResources( + url_.spec(), enabled_1st_party_cf_, &result); auto* dict = result.GetIfDict(); if (dict) From d6d2605736252f877834d96a8b03fed502fdf1f8 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 17 Jan 2023 18:23:54 -0800 Subject: [PATCH 3/6] update adblock-rust to v0.6.3 with `:has` support --- build/rust/Cargo.lock | 4 ++-- components/adblock_rust_ffi/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/rust/Cargo.lock b/build/rust/Cargo.lock index 8d6446735ab8..574c7f949adb 100644 --- a/build/rust/Cargo.lock +++ b/build/rust/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "adblock" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "337b39fa32c578802dc396a6413094746f8ecf628bb430e3294f1d70ccf26ecf" +checksum = "74c2a8bca136c13544c752e911da72ff64cca1dd955f701d0202b4a9d348d39f" dependencies = [ "base64 0.13.0", "bitflags", diff --git a/components/adblock_rust_ffi/Cargo.toml b/components/adblock_rust_ffi/Cargo.toml index 24fb19f3f546..eebac77ee04b 100644 --- a/components/adblock_rust_ffi/Cargo.toml +++ b/components/adblock_rust_ffi/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Brian R. Bondy "] edition = "2018" [dependencies] -adblock = { version = "0.6.2", default-features = false, features = ["full-regex-handling", "object-pooling", "unsync-regex-caching"] } +adblock = { version = "0.6.3", default-features = false, features = ["full-regex-handling", "object-pooling", "unsync-regex-caching"] } serde_json = "1.0" libc = "0.2" From ce3d3131bbaf86663e15ed2ea73ff3a248d91209 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 17 Jan 2023 18:46:55 -0800 Subject: [PATCH 4/6] add tests --- .../ad_block_service_browsertest.cc | 51 +++++++++++++++++++ .../browser/cosmetic_merge_unittest.cc | 2 +- test/data/cosmetic_filtering.html | 8 +++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index f1ae23ad4ec7..583555930ec1 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -1998,6 +1998,57 @@ IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringFrames) { EXPECT_EQ(base::Value(true), main_result.value); } +// Test cosmetic filtering ignores rules with the `:has` pseudoclass in standard +// blocking mode +IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, + CosmeticFilteringHasPseudoclassStandard) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + DisableAggressiveMode(); + UpdateAdBlockInstanceWithRules("b.com##.container:has(#promotion)\n"); + + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html"); + ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), tab_url)); + + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + + EXPECT_EQ(true, EvalJs(contents, + "checkSelector('.container', 'display', 'block')")); +} + +// Test cosmetic filtering applies rules with the `:has` pseudoclass in +// aggressive blocking mode +IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, + CosmeticFilteringHasPseudoclassAggressive) { + ASSERT_TRUE(InstallDefaultAdBlockExtension()); + UpdateAdBlockInstanceWithRules("b.com##.container:has(#promotion)\n"); + + GURL tab_url = + embedded_test_server()->GetURL("b.com", "/cosmetic_filtering.html"); + ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), tab_url)); + + content::WebContents* contents = + browser()->tab_strip_model()->GetActiveWebContents(); + + // the `#promotion` element's container is hidden + EXPECT_EQ("none", EvalJs(contents, + "window.getComputedStyle(document.getElementById('" + "promotion').parentElement).display")); + + // the `#real-user-content` element's container is not hidden + EXPECT_EQ("block", EvalJs(contents, + "window.getComputedStyle(document.getElementById('" + "real-user-content').parentElement).display")); + + // both inner elements have no new styles applied + EXPECT_EQ(true, EvalJs(contents, + "checkSelector('#promotion', 'display', 'block')")); + EXPECT_EQ(true, + EvalJs(contents, + "checkSelector('#real-user-content', 'display', 'block')")); +} + // Test cosmetic filtering ignores content determined to be 1st party IN_PROC_BROWSER_TEST_F(AdBlockServiceTest, CosmeticFilteringProtect1p) { ASSERT_TRUE(InstallDefaultAdBlockExtension()); diff --git a/components/brave_shields/browser/cosmetic_merge_unittest.cc b/components/brave_shields/browser/cosmetic_merge_unittest.cc index 08bec3ca1309..ba18bda71b84 100644 --- a/components/brave_shields/browser/cosmetic_merge_unittest.cc +++ b/components/brave_shields/browser/cosmetic_merge_unittest.cc @@ -32,7 +32,7 @@ class CosmeticResourceMergeTest : public testing::Test { base::JSONReader::Read(expected); ASSERT_TRUE(expected_val); - MergeResourcesInto(std::move(b_val->GetDict()), a_val->GetIfDict(), + MergeResourcesInto(std::move(b_val->GetDict()), *a_val->GetIfDict(), force_hide); ASSERT_EQ(*a_val, *expected_val); diff --git a/test/data/cosmetic_filtering.html b/test/data/cosmetic_filtering.html index 68964814f298..e2d5f1f8293b 100644 --- a/test/data/cosmetic_filtering.html +++ b/test/data/cosmetic_filtering.html @@ -94,5 +94,13 @@
+ + +
+
+
+
+
+
From df45ed2e07fbdd60115ea70eae54b89d5176538a Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 17 Jan 2023 18:54:56 -0800 Subject: [PATCH 5/6] update license headers to satisfy presubmit warnings --- components/adblock_rust_ffi/src/lib.rs | 5 +++++ .../cosmetic_filters/browser/cosmetic_filters_resources.cc | 6 +++--- .../cosmetic_filters/browser/cosmetic_filters_resources.h | 4 ++-- components/cosmetic_filters/common/cosmetic_filters.mojom | 5 +++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/components/adblock_rust_ffi/src/lib.rs b/components/adblock_rust_ffi/src/lib.rs index 5017e4e73715..92ae7c5fbb66 100644 --- a/components/adblock_rust_ffi/src/lib.rs +++ b/components/adblock_rust_ffi/src/lib.rs @@ -1,3 +1,8 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * 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 https://mozilla.org/MPL/2.0/. */ + use adblock::engine::Engine; use adblock::lists::FilterListMetadata; use adblock::resources::{MimeType, Resource, ResourceType}; diff --git a/components/cosmetic_filters/browser/cosmetic_filters_resources.cc b/components/cosmetic_filters/browser/cosmetic_filters_resources.cc index 75bc2321debd..511aef0fd71e 100644 --- a/components/cosmetic_filters/browser/cosmetic_filters_resources.cc +++ b/components/cosmetic_filters/browser/cosmetic_filters_resources.cc @@ -1,7 +1,7 @@ -/* Copyright (c) 2020 The Brave Authors. All rights reserved. +/* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 3.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "brave/components/cosmetic_filters/browser/cosmetic_filters_resources.h" diff --git a/components/cosmetic_filters/browser/cosmetic_filters_resources.h b/components/cosmetic_filters/browser/cosmetic_filters_resources.h index 6e48ec1c0b30..08dc7ed3eec2 100644 --- a/components/cosmetic_filters/browser/cosmetic_filters_resources.h +++ b/components/cosmetic_filters/browser/cosmetic_filters_resources.h @@ -1,7 +1,7 @@ /* Copyright (c) 2021 The Brave Authors. All rights reserved. * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 3.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ #ifndef BRAVE_COMPONENTS_COSMETIC_FILTERS_BROWSER_COSMETIC_FILTERS_RESOURCES_H_ #define BRAVE_COMPONENTS_COSMETIC_FILTERS_BROWSER_COSMETIC_FILTERS_RESOURCES_H_ diff --git a/components/cosmetic_filters/common/cosmetic_filters.mojom b/components/cosmetic_filters/common/cosmetic_filters.mojom index ffb1335376c8..90b8b5a05cf4 100644 --- a/components/cosmetic_filters/common/cosmetic_filters.mojom +++ b/components/cosmetic_filters/common/cosmetic_filters.mojom @@ -1,3 +1,8 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * 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 https://mozilla.org/MPL/2.0/. */ + module cosmetic_filters.mojom; import "mojo/public/mojom/base/values.mojom"; From e19627684e99b103b3d358c29014a27bf539e089 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 17 Jan 2023 18:56:37 -0800 Subject: [PATCH 6/6] apply 2 outstanding rustfmt changes in adblock_rust_ffi --- components/adblock_rust_ffi/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/adblock_rust_ffi/src/lib.rs b/components/adblock_rust_ffi/src/lib.rs index 92ae7c5fbb66..638a5a81dc24 100644 --- a/components/adblock_rust_ffi/src/lib.rs +++ b/components/adblock_rust_ffi/src/lib.rs @@ -97,8 +97,11 @@ pub unsafe extern "C" fn engine_create(rules: *const c_char) -> *mut Engine { /// Create a new `Engine`, interpreting `rules` as a null-terminated C string and then parsing as a /// filter list in ABP syntax. Also populates metadata from the filter list into `metadata`. #[no_mangle] -pub unsafe extern "C" fn engine_create_with_metadata(rules: *const c_char, metadata: *mut *mut FilterListMetadata) -> *mut Engine { - let rules = CStr::from_ptr(rules).to_str().unwrap_or_else(|_|{ +pub unsafe extern "C" fn engine_create_with_metadata( + rules: *const c_char, + metadata: *mut *mut FilterListMetadata, +) -> *mut Engine { + let rules = CStr::from_ptr(rules).to_str().unwrap_or_else(|_| { eprintln!("Failed to parse filter list with invalid UTF-8 content"); "" }); @@ -127,10 +130,7 @@ fn engine_create_from_str(rules: &str) -> (*mut FilterListMetadata, *mut Engine) let mut filter_set = adblock::lists::FilterSet::new(false); let metadata = filter_set.add_filter_list(&rules, Default::default()); let engine = Engine::from_filter_set(filter_set, true); - ( - Box::into_raw(Box::new(metadata)), - Box::into_raw(Box::new(engine)), - ) + (Box::into_raw(Box::new(metadata)), Box::into_raw(Box::new(engine))) } /// Checks if a `url` matches for the specified `Engine` within the context.