From 033b142e8042569df43e8be69c40f6e8a7023058 Mon Sep 17 00:00:00 2001 From: Carmelo Messina Date: Thu, 27 Mar 2025 10:06:05 +0100 Subject: [PATCH] Eyeo Adblock for Cromite: Added support for primary navigation block (#1850) An interstitial page with rules such as ||example.com^ is displayed, allowing the user to enter a temporary or persistent rule. --- build/patches/Eyeo-Adblock-for-Cromite.patch | 765 ++++++++++++++++--- 1 file changed, 673 insertions(+), 92 deletions(-) diff --git a/build/patches/Eyeo-Adblock-for-Cromite.patch b/build/patches/Eyeo-Adblock-for-Cromite.patch index 7e706907..1aab28f6 100644 --- a/build/patches/Eyeo-Adblock-for-Cromite.patch +++ b/build/patches/Eyeo-Adblock-for-Cromite.patch @@ -3,12 +3,7 @@ Date: Thu, 29 Sep 2022 11:27:35 +0000 Subject: Eyeo Adblock for Cromite Change the normal behaviour of Eyeo Chromium SDK to -suit Bromite logic. -Add blocking in service workers -Activates the pop-up blocking management present in adblockplus -but not active in upstream. -Added "enable-stricter-popup-blocker" flag for the global -deactivation of all pop-ups (default disabled) +suit Cromite logic. --- .../android/java/res/xml/main_preferences.xml | 19 +- .../adblock_chrome_content_browser_client.cc | 6 + @@ -17,7 +12,7 @@ deactivation of all pop-ups (default disabled) .../adblock/android/adblock_strings.grd | 54 +- .../java/res/layout/adblock_custom_item.xml | 14 +- .../layout/adblock_filter_lists_list_item.xml | 15 + - ...ences.xml => eyeo_adblock_preferences.xml} | 39 +- + ...ences.xml => eyeo_adblock_preferences.xml} | 42 +- .../AdblockAllowedDomainsFragment.java | 7 +- .../AdblockCustomFilterListsFragment.java | 37 +- .../AdblockCustomFiltersFragment.java | 7 +- @@ -44,15 +39,20 @@ deactivation of all pop-ups (default disabled) chrome/browser/ui/tab_helpers.cc | 3 +- .../extensions/api/_permission_features.json | 14 - .../common/extensions/api/adblock_private.idl | 8 + - .../adblock/android/adblock_controller_jni.cc | 75 +- + .../adblock/android/adblock_controller_jni.cc | 79 +- .../components/adblock/AdblockController.java | 51 +- - components/adblock/content/browser/BUILD.gn | 22 +- - .../browser/adblock_content_browser_client.h | 267 +- + components/adblock/content/browser/BUILD.gn | 24 +- + .../content/browser/adblock_blocking_page.cc | 182 + + .../content/browser/adblock_blocking_page.h | 75 + + .../browser/adblock_content_browser_client.h | 237 +- .../browser/adblock_internals_page_handler.cc | 9 +- - .../browser/adblock_url_loader_factory.cc | 46 +- - .../browser/adblock_webcontents_observer.cc | 21 +- + .../browser/adblock_url_loader_factory.cc | 70 +- + .../browser/adblock_webcontents_observer.cc | 59 +- .../browser/adblock_webcontents_observer.h | 5 +- .../content/browser/element_hider_impl.cc | 13 +- + .../content/browser/eyeo_document_info.cc | 15 + + .../content/browser/eyeo_document_info.h | 9 + + .../adblock_request_throttle_factory.cc | 2 +- .../adblock_telemetry_service_factory.cc | 7 - .../browser/factories/embedding_utils.cc | 2 - .../browser/factories/embedding_utils.h | 7 +- @@ -61,7 +61,7 @@ deactivation of all pop-ups (default disabled) .../browser/frame_hierarchy_builder.cc | 1 + .../content/browser/page_view_stats.cc | 71 +- .../browser/resource_classification_runner.h | 7 + - .../resource_classification_runner_impl.cc | 66 +- + .../resource_classification_runner_impl.cc | 71 +- .../resource_classification_runner_impl.h | 8 + components/adblock/core/BUILD.gn | 39 - components/adblock/core/common/BUILD.gn | 8 - @@ -70,15 +70,15 @@ deactivation of all pop-ups (default disabled) .../adblock/core/common/adblock_prefs.cc | 57 +- .../adblock/core/common/adblock_prefs.h | 7 +- components/adblock/core/common/app_info.cc | 12 - - .../configuration/filtering_configuration.h | 3 + - .../persistent_filtering_configuration.cc | 10 + - .../persistent_filtering_configuration.h | 3 + + .../configuration/filtering_configuration.h | 5 + + .../persistent_filtering_configuration.cc | 28 +- + .../persistent_filtering_configuration.h | 6 + .../core/converter/flatbuffer_converter.cc | 2 +- .../adblock/core/converter/parser/metadata.cc | 1 + .../core/converter/parser/test/test_rules.txt | 21 + - .../core/converter/parser/url_filter.cc | 10 +- + .../core/converter/parser/url_filter.cc | 15 +- .../converter/parser/url_filter_options.cc | 21 +- - .../serializer/flatbuffer_serializer.cc | 85 +- + .../serializer/flatbuffer_serializer.cc | 102 +- components/adblock/core/features.cc | 6 +- .../core/net/adblock_resource_request_impl.cc | 21 +- components/adblock/core/resources/.gitignore | 2 +- @@ -91,7 +91,7 @@ deactivation of all pop-ups (default disabled) .../adblock/core/sitekey_storage_impl.cc | 17 +- .../core/subscription/conversion_executors.h | 1 + .../filtering_configuration_maintainer.h | 4 + - ...filtering_configuration_maintainer_impl.cc | 33 +- + ...filtering_configuration_maintainer_impl.cc | 35 +- .../filtering_configuration_maintainer_impl.h | 4 +- .../preloaded_subscription_provider_impl.cc | 4 +- ...recommended_subscription_installer_impl.cc | 1 + @@ -113,6 +113,7 @@ deactivation of all pop-ups (default disabled) components/blocked_content/popup_blocker.cc | 9 +- components/blocked_content/popup_blocker.h | 3 + .../browser/bromite_content_settings/ads.inc | 3 + + components/error_page_strings.grdp | 16 + .../websockets/websocket_connector_impl.cc | 6 +- .../public/browser/content_browser_client.cc | 4 +- .../public/browser/content_browser_client.h | 4 +- @@ -124,10 +125,12 @@ deactivation of all pop-ups (default disabled) .../renderer/core/exported/web_document.cc | 13 +- .../blink/renderer/core/html/html_element.cc | 8 +- .../definitions/adblock_private.d.ts | 14 + - 114 files changed, 8783 insertions(+), 589 deletions(-) - rename chrome/browser/adblock/android/java/res/xml/{adblock_preferences.xml => eyeo_adblock_preferences.xml} (60%) + 120 files changed, 9154 insertions(+), 610 deletions(-) + rename chrome/browser/adblock/android/java/res/xml/{adblock_preferences.xml => eyeo_adblock_preferences.xml} (59%) create mode 100644 chrome/browser/resources/settings/adblock_page/adblock_page.html create mode 100644 chrome/browser/resources/settings/adblock_page/adblock_page.ts + create mode 100644 components/adblock/content/browser/adblock_blocking_page.cc + create mode 100644 components/adblock/content/browser/adblock_blocking_page.h create mode 100644 components/adblock/core/converter/parser/test/test_rules.txt create mode 100644 components/adblock/core/resources/snippets/dist/dependencies.jst create mode 100644 components/adblock/core/resources/snippets/dist/isolated-first-all.source.jst @@ -363,7 +366,7 @@ diff --git a/chrome/browser/adblock/android/java/res/layout/adblock_filter_lists + diff --git a/chrome/browser/adblock/android/java/res/xml/adblock_preferences.xml b/chrome/browser/adblock/android/java/res/xml/eyeo_adblock_preferences.xml -similarity index 60% +similarity index 59% rename from chrome/browser/adblock/android/java/res/xml/adblock_preferences.xml rename to chrome/browser/adblock/android/java/res/xml/eyeo_adblock_preferences.xml --- a/chrome/browser/adblock/android/java/res/xml/adblock_preferences.xml @@ -421,6 +424,16 @@ rename to chrome/browser/adblock/android/java/res/xml/eyeo_adblock_preferences.x ++ android:summary="@string/fragment_adblock_settings_auto_install_enabled_summary" ++ app:isPreferenceVisible="false" /> + + + & languages, const bool autoinstalled) { ScopedJavaLocalRef url_param( -@@ -57,13 +62,23 @@ ScopedJavaLocalRef ToJava(JNIEnv* env, +@@ -57,24 +62,40 @@ ScopedJavaLocalRef ToJava(JNIEnv* env, return Java_Subscription_Constructor(env, url_param, ConvertUTF8ToJavaString(env, title), ConvertUTF8ToJavaString(env, version), @@ -1845,9 +1858,12 @@ diff --git a/components/adblock/android/adblock_controller_jni.cc b/components/a ScopedJavaLocalRef url_class = GetClass(env, "java/net/URL"); jmethodID url_constructor = MethodID::Get( env, url_class.obj(), "", "(Ljava/lang/String;)V"); -@@ -72,7 +87,11 @@ std::vector> CSubscriptionsToJObjects( + std::vector> jobjects; + jobjects.reserve(subscriptions.size()); for (auto& sub : subscriptions) { - jobjects.push_back(ToJava( +- jobjects.push_back(ToJava( ++ if (sub->GetSourceUrl().SchemeIsHTTPOrHTTPS()) { ++ jobjects.push_back(ToJava( env, url_class, url_constructor, sub->GetSourceUrl().spec(), - sub->GetTitle(), sub->GetCurrentVersion(), std::vector{}, + sub->GetTitle(), sub->GetCurrentVersion(), @@ -1857,8 +1873,11 @@ diff --git a/components/adblock/android/adblock_controller_jni.cc b/components/a + std::vector{}, sub->GetInstallationState() == adblock::InstalledSubscription::InstallationState::AutoInstalled)); ++ } } -@@ -93,7 +112,11 @@ std::vector> CSubscriptionsToJObjects( + return jobjects; + } +@@ -93,7 +114,11 @@ std::vector> CSubscriptionsToJObjects( DCHECK(sub.url.is_valid()); if (sub.url.is_valid()) { jobjects.push_back(ToJava(env, url_class, url_constructor, @@ -1871,7 +1890,7 @@ diff --git a/components/adblock/android/adblock_controller_jni.cc b/components/a false)); } } -@@ -103,6 +126,52 @@ std::vector> CSubscriptionsToJObjects( +@@ -103,6 +128,52 @@ std::vector> CSubscriptionsToJObjects( } // namespace @@ -1924,7 +1943,7 @@ diff --git a/components/adblock/android/adblock_controller_jni.cc b/components/a static base::android::ScopedJavaLocalRef JNI_AdblockController_GetInstalledSubscriptions( JNIEnv* env, -@@ -118,7 +187,7 @@ JNI_AdblockController_GetInstalledSubscriptions( +@@ -118,7 +189,7 @@ JNI_AdblockController_GetInstalledSubscriptions( return ToJavaArrayOfObjects( env, CSubscriptionsToJObjects( @@ -2055,7 +2074,16 @@ diff --git a/components/adblock/content/browser/BUILD.gn b/components/adblock/co } source_set("browser_impl") { -@@ -56,8 +49,6 @@ source_set("browser_impl") { +@@ -44,6 +37,8 @@ source_set("browser_impl") { + "adblock_web_ui_controller_factory.h", + "adblock_webcontents_observer.cc", + "adblock_webcontents_observer.h", ++ "adblock_blocking_page.cc", ++ "adblock_blocking_page.h", + "content_security_policy_injector.h", + "content_security_policy_injector_impl.cc", + "content_security_policy_injector_impl.h", +@@ -56,8 +51,6 @@ source_set("browser_impl") { "eyeo_page_info.h", "factories/adblock_request_throttle_factory.cc", "factories/adblock_request_throttle_factory.h", @@ -2064,7 +2092,7 @@ diff --git a/components/adblock/content/browser/BUILD.gn b/components/adblock/co "factories/content_security_policy_injector_factory.cc", "factories/content_security_policy_injector_factory.h", "factories/element_hider_factory.cc", -@@ -89,15 +80,10 @@ source_set("browser_impl") { +@@ -89,15 +82,10 @@ source_set("browser_impl") { "session_stats_impl.h", ] @@ -2082,7 +2110,7 @@ diff --git a/components/adblock/content/browser/BUILD.gn b/components/adblock/co "//components/adblock/content/browser/mojom:adblock_internals", "//components/adblock/content/resources/adblock_internals:resources", "//components/adblock/core/converter:converter", -@@ -218,9 +204,5 @@ source_set("browser_tests") { +@@ -218,9 +206,5 @@ source_set("browser_tests") { "test/adblock_web_ui_browsertest.cc", ] @@ -2092,6 +2120,273 @@ diff --git a/components/adblock/content/browser/BUILD.gn b/components/adblock/co - deps = [ ":browser_tests_support" ] } +diff --git a/components/adblock/content/browser/adblock_blocking_page.cc b/components/adblock/content/browser/adblock_blocking_page.cc +new file mode 100644 +--- /dev/null ++++ b/components/adblock/content/browser/adblock_blocking_page.cc +@@ -0,0 +1,182 @@ ++/* ++ This file is part of Cromite. ++ ++ Cromite is free software: you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation, either version 2 of the License, or ++ (at your option) any later version. ++ ++ Cromite is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with Cromite. If not, see . ++*/ ++ ++#include "components/adblock/content/browser/adblock_blocking_page.h" ++ ++#include ++ ++#include "base/i18n/rtl.h" ++#include "base/strings/escape.h" ++#include "base/strings/strcat.h" ++#include "base/strings/utf_string_conversions.h" ++#include "components/grit/components_resources.h" ++#include "components/security_interstitials/content/security_interstitial_controller_client.h" ++#include "components/security_interstitials/core/common_string_util.h" ++#include "components/security_interstitials/core/metrics_helper.h" ++#include "components/security_interstitials/core/urls.h" ++#include "components/strings/grit/components_strings.h" ++#include "components/url_formatter/url_formatter.h" ++#include "net/base/net_errors.h" ++#include "ui/base/l10n/l10n_util.h" ++ ++namespace { ++ ++std::unique_ptr GetMetricsHelper( ++ const GURL& url) { ++ security_interstitials::MetricsHelper::ReportDetails settings; ++ settings.metric_prefix = "main_blocking_page"; ++ ++ return std::make_unique(url, settings, ++ nullptr); ++} ++ ++} ++ ++// static ++const security_interstitials::SecurityInterstitialPage::TypeID ++ AdBlockPage::kTypeForTesting = ++ &AdBlockPage::kTypeForTesting; ++ ++std::unique_ptr ++AdBlockPage::CreateBlockingPage( ++ content::WebContents* web_contents, ++ const GURL& url, ++ adblock::SubscriptionService* subscription_service, ++ const GURL& subscription_url) { ++ return make_unique( ++ web_contents, url, subscription_service, subscription_url, ++ std::make_unique< ++ security_interstitials::SecurityInterstitialControllerClient>( ++ web_contents, GetMetricsHelper(url), /*pref_service*/nullptr, ++ base::i18n::GetConfiguredLocale(), GURL(url::kAboutBlankURL), ++ /*settings_page_helper=*/nullptr)); ++} ++ ++AdBlockPage::AdBlockPage( ++ content::WebContents* web_contents, ++ const GURL& request_url, ++ adblock::SubscriptionService* subscription_service, ++ const GURL& subscription_url, ++ std::unique_ptr< ++ security_interstitials::SecurityInterstitialControllerClient> ++ controller_client) ++ : security_interstitials::SecurityInterstitialPage( ++ web_contents, ++ request_url, ++ std::move(controller_client)), ++ subscription_service_(subscription_service), ++ subscription_url_(subscription_url) { ++} ++ ++AdBlockPage::~AdBlockPage() = default; ++ ++security_interstitials::SecurityInterstitialPage::TypeID ++AdBlockPage::GetTypeForTesting() { ++ return AdBlockPage::kTypeForTesting; ++} ++ ++void AdBlockPage::PopulateInterstitialStrings( ++ base::Value::Dict& load_time_data) { ++ load_time_data.Set("type", "ENTERPRISE_WARN"); ++ load_time_data.Set("tabTitle", ++ l10n_util::GetStringUTF16(IDS_ERRORPAGES_TITLE_BLOCKED_BY_ADMINISTRATOR)); ++ load_time_data.Set("heading", ++ l10n_util::GetStringUTF16(IDS_ERRORPAGES_HEADING_BLOCKED_BY_ADMINISTRATOR)); ++ ++ std::u16string subscription_url_string(url_formatter::FormatUrl( ++ subscription_url_, url_formatter::kFormatUrlOmitNothing, ++ base::UnescapeRule::NORMAL, nullptr, nullptr, nullptr)); ++ load_time_data.Set("primaryParagraph", ++ l10n_util::GetStringFUTF16(IDS_ERRORPAGES_PRIMARY_PARAGRAPH_BLOCKED_BY_ADMINISTRATOR, ++ base::EscapeForHTML(subscription_url_string))); ++ ++ load_time_data.Set("show_recurrent_error_paragraph", false); ++ load_time_data.Set("recurrentErrorParagraph", ""); ++ load_time_data.Set("openDetails", ""); ++ load_time_data.Set("explanationParagraph", ""); ++ load_time_data.Set("finalParagraph", ""); ++ load_time_data.Set("optInLink", "optInLink"); ++ ++ load_time_data.Set("enhancedProtectionMessage", ""); ++ ++ load_time_data.Set("hide_primary_button", false); ++ load_time_data.Set("primaryButtonText", ++ l10n_util::GetStringUTF16(IDS_ERRORPAGES_PRIMARYBUTTONTEXT_BLOCKED_BY_ADMINISTRATOR)); ++ load_time_data.Set("proceedButtonText", ++ l10n_util::GetStringUTF16(IDS_ERRORPAGES_PROCEEDBUTTONTEXT_BLOCKED_BY_ADMINISTRATOR)); ++ load_time_data.Set("fontsize", ""); ++ ++ load_time_data.Set("overridable", false); ++ load_time_data.Set("bad_clock", false); ++ load_time_data.Set(security_interstitials::kDisplayCheckBox, false); ++} ++ ++void AdBlockPage::OnInterstitialClosing() {} ++ ++void AdBlockPage::CommandReceived(const std::string& command) { ++ if (command == "\"pageLoadComplete\"") { ++ // content::WaitForRenderFrameReady sends this message when the page ++ // load completes. Ignore it. ++ return; ++ } ++ ++ int cmd = 0; ++ bool retval = base::StringToInt(command, &cmd); ++ DCHECK(retval); ++ ++ switch (cmd) { ++ case security_interstitials::CMD_DONT_PROCEED: ++ case security_interstitials::CMD_PROCEED: ++ { ++ adblock::FilteringConfiguration* adblock_configuration = ++ subscription_service_->GetAdblockFilteringConfiguration(); ++ CHECK(adblock_configuration); ++ ++ GURL request_url = ++ security_interstitials::SecurityInterstitialPage::request_url(); ++ std::string filter = ++ "@@||" + request_url.host() + "^$document,popup"; ++ ++ if (cmd == security_interstitials::CMD_DONT_PROCEED) ++ adblock_configuration->AddTemporaryCustomFilter(filter); ++ else ++ adblock_configuration->AddCustomFilter(filter); ++ controller()->Reload(); ++ break; ++ } ++ case security_interstitials::CMD_OPEN_HELP_CENTER: ++ case security_interstitials::CMD_DO_REPORT: ++ case security_interstitials::CMD_DONT_REPORT: ++ case security_interstitials::CMD_SHOW_MORE_SECTION: ++ case security_interstitials::CMD_OPEN_DATE_SETTINGS: ++ case security_interstitials::CMD_OPEN_REPORTING_PRIVACY: ++ case security_interstitials::CMD_OPEN_WHITEPAPER: ++ case security_interstitials::CMD_RELOAD: ++ case security_interstitials::CMD_OPEN_DIAGNOSTIC: ++ case security_interstitials::CMD_OPEN_LOGIN: ++ case security_interstitials::CMD_REPORT_PHISHING_ERROR: ++ case security_interstitials::CMD_ERROR: ++ case security_interstitials::CMD_TEXT_FOUND: ++ case security_interstitials::CMD_TEXT_NOT_FOUND: ++ // Not supported by the URL blocking page. ++ NOTREACHED() << "Unsupported command: " << command; ++ } ++} ++ ++int AdBlockPage::GetHTMLTemplateId() { ++ return IDR_SECURITY_INTERSTITIAL_HTML; ++} +diff --git a/components/adblock/content/browser/adblock_blocking_page.h b/components/adblock/content/browser/adblock_blocking_page.h +new file mode 100644 +--- /dev/null ++++ b/components/adblock/content/browser/adblock_blocking_page.h +@@ -0,0 +1,75 @@ ++/* ++ This file is part of Cromite. ++ ++ Cromite is free software: you can redistribute it and/or modify ++ it under the terms of the GNU General Public License as published by ++ the Free Software Foundation, either version 2 of the License, or ++ (at your option) any later version. ++ ++ Cromite is distributed in the hope that it will be useful, ++ but WITHOUT ANY WARRANTY; without even the implied warranty of ++ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ GNU General Public License for more details. ++ ++ You should have received a copy of the GNU General Public License ++ along with Cromite. If not, see . ++*/ ++ ++#ifndef COMPONENTS_ADBLOCK_CONTENT_BROWSER_ADBLOCK_BLOCKING_PAGE_H_ ++#define COMPONENTS_ADBLOCK_CONTENT_BROWSER_ADBLOCK_BLOCKING_PAGE_H_ ++ ++#include ++ ++#include "components/adblock/core/subscription/subscription_service.h" ++#include "components/adblock/content/browser/adblock_filter_match.h" ++#include "components/adblock/content/browser/eyeo_document_info.h" ++#include "components/security_interstitials/content/security_interstitial_page.h" ++#include "components/security_interstitials/content/settings_page_helper.h" ++ ++class GURL; ++ ++class AdBlockPage ++ : public security_interstitials::SecurityInterstitialPage { ++ public: ++ // Interstitial type, used in tests. ++ static const security_interstitials::SecurityInterstitialPage::TypeID ++ kTypeForTesting; ++ ++ static std::unique_ptr CreateBlockingPage( ++ content::WebContents* web_contents, ++ const GURL& main_frame_url, ++ adblock::SubscriptionService* subscription_service, ++ const GURL& subscription_url); ++ ++ // |request_url| is the URL which triggered the interstitial page. It can be ++ // a main frame or a subresource URL. ++ AdBlockPage( ++ content::WebContents* web_contents, ++ const GURL& request_url, ++ adblock::SubscriptionService* subscription_service, ++ const GURL& subscription_url, ++ std::unique_ptr< ++ security_interstitials::SecurityInterstitialControllerClient> ++ controller); ++ ++ AdBlockPage(const AdBlockPage&) = delete; ++ AdBlockPage& operator=(const AdBlockPage&) = delete; ++ ++ ~AdBlockPage() override; ++ ++ // SecurityInterstitialPage: ++ security_interstitials::SecurityInterstitialPage::TypeID GetTypeForTesting() ++ override; ++ ++ protected: ++ void CommandReceived(const std::string& command) override; ++ void PopulateInterstitialStrings(base::Value::Dict& load_time_data) override; ++ void OnInterstitialClosing() override; ++ int GetHTMLTemplateId() override; ++ ++ private: ++ raw_ptr subscription_service_; ++ GURL subscription_url_; ++}; ++ ++#endif // COMPONENTS_ADBLOCK_CONTENT_BROWSER_ADBLOCK_BLOCKING_PAGE_H_ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h b/components/adblock/content/browser/adblock_content_browser_client.h --- a/components/adblock/content/browser/adblock_content_browser_client.h +++ b/components/adblock/content/browser/adblock_content_browser_client.h @@ -2242,8 +2537,9 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h + std::vector dns_aliases; classification_runner->CheckRequestFilterMatch( - subscription_service->GetCurrentSnapshot(), url, ContentType::Websocket, +- RequestInitiator(frame), + subscription_service->GetCurrentSnapshot(), url, dns_aliases, ContentType::Websocket, - RequestInitiator(frame), ++ RequestInitiator(initiator_origin.GetURL().GetAsReferrer()), base::BindOnce( &AdblockContentBrowserClient< ContentBrowserClientBase>::OnWebSocketFilterCheckCompleted, @@ -2260,7 +2556,7 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h site_for_cookies, user_agent, std::move(handshake_client)); } -@@ -211,6 +262,129 @@ void AdblockContentBrowserClient:: +@@ -211,6 +262,97 @@ void AdblockContentBrowserClient:: adblock::AdblockInternalsUI>(map); } @@ -2349,38 +2645,6 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h + bool user_gesture, + bool opener_suppressed, + bool* no_javascript_access) { -+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); -+ DCHECK(opener); -+ -+ if (IsFilteringNeeded(opener)) { -+ content::WebContents* web_contents = -+ content::WebContents::FromRenderFrameHost(opener); -+ auto* subscription_service = -+ adblock::SubscriptionServiceFactory::GetForBrowserContext( -+ web_contents->GetBrowserContext()); -+ -+ GURL popup_url(target_url); -+ web_contents->GetPrimaryMainFrame()->GetProcess()->FilterURL(false, -+ &popup_url); -+ auto* classification_runner = -+ adblock::ResourceClassificationRunnerFactory::GetForBrowserContext( -+ web_contents->GetBrowserContext()); -+ const auto popup_blocking_decision = -+ classification_runner->ShouldBlockPopup( -+ subscription_service->GetCurrentSnapshot(), popup_url, opener); -+ if (popup_blocking_decision == adblock::FilterMatchResult::kAllowRule) { -+ return true; -+ } -+ if (popup_blocking_decision == adblock::FilterMatchResult::kBlockRule) { -+ return false; -+ } -+ // Otherwise, if eyeo adblocking is disabled or there is no rule that -+ // explicitly allows or blocks a popup, fall back on Chromium's built-in -+ // popup blocker. -+ DCHECK(popup_blocking_decision == adblock::FilterMatchResult::kDisabled || -+ popup_blocking_decision == adblock::FilterMatchResult::kNoRule); -+ } -+ + return ChromeContentBrowserClient::CanCreateWindow( + opener, opener_url, opener_top_level_frame_url, source_origin, + container_type, target_url, referrer, frame_name, disposition, features, @@ -2390,7 +2654,7 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h template void AdblockContentBrowserClient:: WillCreateURLLoaderFactory( -@@ -250,29 +424,8 @@ void AdblockContentBrowserClient:: +@@ -250,29 +392,8 @@ void AdblockContentBrowserClient:: auto* eyeo_browser_context = GetBrowserContextForEyeoFactories(browser_context); bool use_adblock_proxy = @@ -2422,7 +2686,7 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h if (use_adblock_proxy) { auto [proxied_receiver, target_factory_remote] = factory_builder.Append(); -@@ -282,16 +435,18 @@ void AdblockContentBrowserClient:: +@@ -282,16 +403,18 @@ void AdblockContentBrowserClient:: AdblockContextData::StartProxying( eyeo_browser_context, initiator, std::move(proxied_receiver), std::move(target_factory_remote), @@ -2442,7 +2706,7 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h const net::SiteForCookies& site_for_cookies, const absl::optional& user_agent, mojo::PendingRemote -@@ -305,9 +460,9 @@ void AdblockContentBrowserClient:: +@@ -305,9 +428,9 @@ void AdblockContentBrowserClient:: result == adblock::FilterMatchResult::kBlockRule; if (!has_blocking_filter) { VLOG(1) << "[eyeo] Web socket allowed for " << url; @@ -2455,7 +2719,7 @@ diff --git a/components/adblock/content/browser/adblock_content_browser_client.h std::move(handshake_client)); return; } -@@ -324,16 +479,38 @@ void AdblockContentBrowserClient:: +@@ -324,16 +447,38 @@ void AdblockContentBrowserClient:: VLOG(1) << "[eyeo] Web socket blocked for " << url; } @@ -2562,7 +2826,23 @@ diff --git a/components/adblock/content/browser/adblock_url_loader_factory.cc b/ void CheckRewriteFilterMatch(CheckRewriteFilterMatchCallback callback); void OnRequestUrlClassified(CheckFilterMatchCallback callback, FilterMatchResult result); -@@ -358,7 +361,9 @@ void AdblockURLLoaderFactory::InProgressRequest::OnReceiveResponse( +@@ -246,6 +249,7 @@ class AdblockURLLoaderFactory::InProgressRequest + GURL request_url_; + int request_id_; + bool is_document_request_; ++ bool is_popup_; + ContentType adblock_resource_type_; + const raw_ptr factory_; + // There are the mojo pipe endpoints between this proxy and the renderer. +@@ -275,6 +279,7 @@ AdblockURLLoaderFactory::InProgressRequest::InProgressRequest( + : request_url_(request.url), + request_id_(request_id), + is_document_request_(IsDocumentRequest(request)), ++ is_popup_(false), + adblock_resource_type_(ToAdblockResourceType(request)), + factory_(factory), + target_client_(std::move(client)), +@@ -358,7 +363,9 @@ void AdblockURLLoaderFactory::InProgressRequest::OnReceiveResponse( VLOG(1) << "[eyeo] Sending headers for processing: " << request_url_; client_receiver_.Pause(); const scoped_refptr& headers = head->headers; @@ -2572,10 +2852,25 @@ diff --git a/components/adblock/content/browser/adblock_url_loader_factory.cc b/ headers, base::BindOnce(&InProgressRequest::OnProcessHeadersResult, weak_factory_.GetWeakPtr(), std::move(head), std::move(body), std::move(cached_metadata))); -@@ -420,8 +425,9 @@ void AdblockURLLoaderFactory::InProgressRequest::CheckFilterMatch( - FilterMatchResult::kNoRule); +@@ -405,6 +412,7 @@ void AdblockURLLoaderFactory::InProgressRequest::CheckFilterMatch( + auto subscription_service = factory_->config_.subscription_service; + if (is_document_request_) { + if (IsPopup(initiator)) { ++ is_popup_ = true; + auto* host = initiator.GetRenderFrameHost(); + factory_->config_.resource_classifier->CheckPopupFilterMatch( + subscription_service->GetCurrentSnapshot(), request_url_, *host, +@@ -415,13 +423,12 @@ void AdblockURLLoaderFactory::InProgressRequest::CheckFilterMatch( + base::BindOnce(&AdblockURLLoaderFactory::InProgressRequest:: + PostFilterMatchCallbackToUI, + weak_factory_.GetWeakPtr(), std::move(callback)))); +- } else { +- PostFilterMatchCallbackToUI(std::move(callback), +- FilterMatchResult::kNoRule); ++ return; } - } else { +- } else { ++ } + std::vector dns_aliases; factory_->config_.resource_classifier->CheckRequestFilterMatch( - subscription_service->GetCurrentSnapshot(), request_url_, @@ -2583,7 +2878,11 @@ diff --git a/components/adblock/content/browser/adblock_url_loader_factory.cc b/ adblock_resource_type_, initiator, base::BindOnce( &AdblockURLLoaderFactory::InProgressRequest::OnRequestUrlClassified, -@@ -433,6 +439,7 @@ void AdblockURLLoaderFactory::InProgressRequest::CheckFilterMatch( +@@ -429,10 +436,10 @@ void AdblockURLLoaderFactory::InProgressRequest::CheckFilterMatch( + base::BindOnce(&AdblockURLLoaderFactory::InProgressRequest:: + PostFilterMatchCallbackToUI, + weak_factory_.GetWeakPtr(), std::move(callback)))); +- } } void AdblockURLLoaderFactory::InProgressRequest::ProcessResponseHeaders( @@ -2629,10 +2928,38 @@ diff --git a/components/adblock/content/browser/adblock_url_loader_factory.cc b/ auto subscription_service = factory_->config_.subscription_service; factory_->config_.resource_classifier->CheckResponseFilterMatch( subscription_service->GetCurrentSnapshot(), request_url_, +@@ -661,6 +699,10 @@ void AdblockURLLoaderFactory::InProgressRequest::Start( + VLOG(1) << "[eyeo] Checking filter match for: " << request.url << " (" + << request.resource_type << ")"; + ++ if (IsRequestInitiatedByFrame()) { ++ SetPreCommitUrlForFrame(); ++ } ++ + CheckFilterMatch(base::BindOnce( + &InProgressRequest::OnRequestFilterMatchResult, + weak_factory_.GetWeakPtr(), std::move(target_loader), options, request, +@@ -729,10 +771,12 @@ void AdblockURLLoaderFactory::InProgressRequest::ApplyPostBlockingBehavior() + // some cleanup to preserve good user experience. + if (frame) { + if (is_document_request_) { +- // This path means we classified popup - close the window. +- auto* wc = content::WebContents::FromRenderFrameHost(frame); +- DCHECK(wc); +- wc->ClosePage(); ++ if (is_popup_) { ++ // This path means we classified popup - close the window. ++ auto* wc = content::WebContents::FromRenderFrameHost(frame); ++ DCHECK(wc); ++ wc->ClosePage(); ++ } + } else { + // We blocked a subresource request. Collapse whitespace around the + // blocked element. diff --git a/components/adblock/content/browser/adblock_webcontents_observer.cc b/components/adblock/content/browser/adblock_webcontents_observer.cc --- a/components/adblock/content/browser/adblock_webcontents_observer.cc +++ b/components/adblock/content/browser/adblock_webcontents_observer.cc -@@ -22,6 +22,8 @@ +@@ -22,10 +22,15 @@ #include "components/adblock/content/browser/request_initiator.h" #include "components/adblock/core/common/sitekey.h" #include "components/adblock/core/subscription/subscription_service.h" @@ -2641,7 +2968,14 @@ diff --git a/components/adblock/content/browser/adblock_webcontents_observer.cc #include "content/public/browser/navigation_handle.h" #include "net/base/url_util.h" #include "third_party/blink/public/common/frame/frame_owner_element_type.h" -@@ -84,6 +86,16 @@ bool ShouldSkipElementHiding(const GURL& url) { + ++#include "components/adblock/content/browser/adblock_blocking_page.h" ++#include "components/security_interstitials/content/security_interstitial_tab_helper.h" ++ + namespace { + const char* WindowOpenDispositionToString(WindowOpenDisposition value) { + switch (value) { +@@ -84,6 +89,16 @@ bool ShouldSkipElementHiding(const GURL& url) { !url.IsAboutBlank(); } @@ -2658,7 +2992,7 @@ diff --git a/components/adblock/content/browser/adblock_webcontents_observer.cc } // namespace namespace adblock { -@@ -94,14 +106,16 @@ AdblockWebContentObserver::AdblockWebContentObserver( +@@ -94,14 +109,16 @@ AdblockWebContentObserver::AdblockWebContentObserver( ElementHider* element_hider, SitekeyStorage* sitekey_storage, std::unique_ptr frame_hierarchy_builder, @@ -2677,12 +3011,47 @@ diff --git a/components/adblock/content/browser/adblock_webcontents_observer.cc AdblockWebContentObserver::~AdblockWebContentObserver() = default; -@@ -153,6 +167,9 @@ void AdblockWebContentObserver::DidFinishNavigation( +@@ -153,6 +170,44 @@ void AdblockWebContentObserver::DidFinishNavigation( VLOG(1) << "[eyeo] Unsupported scheme, skipping injection."; return; } + if (!IsFilteringNeeded(frame, settings_map_)) { + return; ++ } ++ if (navigation_handle->GetNetErrorCode() == net::ERR_BLOCKED_BY_ADMINISTRATOR ++ && navigation_handle->IsInMainFrame()) { ++ GURL subscription_url; ++ if (auto* rfh = content::RenderFrameHost::FromID( ++ navigation_handle->GetPreviousRenderFrameHostId())) { ++ EyeoDocumentInfo* document_info = ++ EyeoDocumentInfo::GetForCurrentDocument(rfh); ++ if (document_info) { ++ subscription_url = document_info->GetSubscriptionUrl(); ++ } ++ } ++ ++ auto* web_contents = navigation_handle->GetWebContents(); ++ security_interstitials::SecurityInterstitialTabHelper::CreateForWebContents(web_contents); ++ ++ std::unique_ptr blocking_page = ++ AdBlockPage::CreateBlockingPage( ++ navigation_handle->GetWebContents(), navigation_handle->GetURL(), ++ subscription_service_, ++ subscription_url); ++ std::string error_page_content = blocking_page->GetHTMLContents(); ++ ++ base::WeakPtr error_page_navigation_handle = ++ web_contents->GetController().LoadPostCommitErrorPage( ++ web_contents->GetPrimaryMainFrame(), url, ++ blocking_page->GetHTMLContents()); ++ if (error_page_navigation_handle) { ++ blocking_page->CreatedPostCommitErrorPageNavigation( ++ error_page_navigation_handle.get()); ++ security_interstitials::SecurityInterstitialTabHelper:: ++ AssociateBlockingPage(error_page_navigation_handle.get(), ++ std::move(blocking_page)); ++ } ++ return; + } if (!navigation_handle->IsErrorPage()) { // Element hiding for ordinary main frame (or iframe) @@ -2761,6 +3130,72 @@ diff --git a/components/adblock/content/browser/element_hider_impl.cc b/componen DVLOG(1) << "[eyeo] Element hiding - executed JS in frame" << " '" << render_frame_host->GetFrameName() << "'"; +diff --git a/components/adblock/content/browser/eyeo_document_info.cc b/components/adblock/content/browser/eyeo_document_info.cc +--- a/components/adblock/content/browser/eyeo_document_info.cc ++++ b/components/adblock/content/browser/eyeo_document_info.cc +@@ -47,4 +47,19 @@ void EyeoDocumentInfo::SetElementHidingDone() { + element_hiding_done_ = true; + } + ++void EyeoDocumentInfo::SetFilterMatchResult(FilterMatchResult result, ++ const GURL& subscription, ++ const std::string& configuration_name) { ++ result_ = result; ++ subscription_url_ = subscription; ++} ++ ++std::optional EyeoDocumentInfo::GetFilterMatchResult() const { ++ return result_; ++} ++ ++const GURL& EyeoDocumentInfo::GetSubscriptionUrl() const { ++ return subscription_url_; ++} ++ + } // namespace adblock +diff --git a/components/adblock/content/browser/eyeo_document_info.h b/components/adblock/content/browser/eyeo_document_info.h +--- a/components/adblock/content/browser/eyeo_document_info.h ++++ b/components/adblock/content/browser/eyeo_document_info.h +@@ -19,6 +19,7 @@ + #define COMPONENTS_ADBLOCK_CONTENT_BROWSER_EYEO_DOCUMENT_INFO_H_ + + #include "content/public/browser/document_user_data.h" ++#include "components/adblock/content/browser/adblock_filter_match.h" + #include "url/gurl.h" + + namespace adblock { +@@ -43,11 +44,19 @@ class EyeoDocumentInfo final + bool IsElementHidingDone() const; + void SetElementHidingDone(); + ++ void SetFilterMatchResult(FilterMatchResult result, ++ const GURL& subscription, ++ const std::string& configuration_name); ++ std::optional GetFilterMatchResult() const; ++ const GURL& GetSubscriptionUrl() const; ++ + private: + explicit EyeoDocumentInfo(content::RenderFrameHost* rfh); + + bool element_hiding_done_ = false; + GURL pre_commit_url_; ++ std::optional result_; ++ GURL subscription_url_; + + friend DocumentUserData; + DOCUMENT_USER_DATA_KEY_DECL(); +diff --git a/components/adblock/content/browser/factories/adblock_request_throttle_factory.cc b/components/adblock/content/browser/factories/adblock_request_throttle_factory.cc +--- a/components/adblock/content/browser/factories/adblock_request_throttle_factory.cc ++++ b/components/adblock/content/browser/factories/adblock_request_throttle_factory.cc +@@ -56,7 +56,7 @@ AdblockRequestThrottleFactory::BuildServiceInstanceForBrowserContext( + base::CommandLine::ForCurrentProcess()->HasSwitch( + adblock::switches::kDisableEyeoRequestThrottling) + ? base::TimeDelta() +- : base::Seconds(30); ++ : base::Seconds(5); + throttle->AllowRequestsAfter(initial_delay); + return std::move(throttle); + } diff --git a/components/adblock/content/browser/factories/adblock_telemetry_service_factory.cc b/components/adblock/content/browser/factories/adblock_telemetry_service_factory.cc --- a/components/adblock/content/browser/factories/adblock_telemetry_service_factory.cc +++ b/components/adblock/content/browser/factories/adblock_telemetry_service_factory.cc @@ -3058,7 +3493,15 @@ diff --git a/components/adblock/content/browser/resource_classification_runner.h diff --git a/components/adblock/content/browser/resource_classification_runner_impl.cc b/components/adblock/content/browser/resource_classification_runner_impl.cc --- a/components/adblock/content/browser/resource_classification_runner_impl.cc +++ b/components/adblock/content/browser/resource_classification_runner_impl.cc -@@ -156,6 +156,19 @@ void ResourceClassificationRunnerImpl::CheckPopupFilterMatch( +@@ -21,6 +21,7 @@ + #include "base/task/task_traits.h" + #include "base/task/thread_pool.h" + #include "base/trace_event/trace_event.h" ++#include "components/adblock/content/browser/eyeo_document_info.h" + #include "components/adblock/content/browser/frame_opener_info.h" + #include "components/adblock/content/browser/request_initiator.h" + #include "components/adblock/core/common/sitekey.h" +@@ -156,6 +157,19 @@ void ResourceClassificationRunnerImpl::CheckPopupFilterMatch( render_frame_host.GetGlobalId(), std::move(callback))); } @@ -3078,7 +3521,7 @@ diff --git a/components/adblock/content/browser/resource_classification_runner_i void ResourceClassificationRunnerImpl::CheckDocumentAllowlisted( SubscriptionService::Snapshot subscription_collections, const GURL& request_url, -@@ -208,6 +221,7 @@ void ResourceClassificationRunnerImpl::ProcessDocumentAllowlistedResponse( +@@ -208,6 +222,7 @@ void ResourceClassificationRunnerImpl::ProcessDocumentAllowlistedResponse( void ResourceClassificationRunnerImpl::CheckRequestFilterMatch( SubscriptionService::Snapshot subscription_collections, const GURL& request_url, @@ -3086,7 +3529,7 @@ diff --git a/components/adblock/content/browser/resource_classification_runner_i ContentType adblock_resource_type, const RequestInitiator& request_initiator, CheckFilterMatchCallback callback) { -@@ -234,7 +248,7 @@ void ResourceClassificationRunnerImpl::CheckRequestFilterMatch( +@@ -234,7 +249,7 @@ void ResourceClassificationRunnerImpl::CheckRequestFilterMatch( base::BindOnce( &ResourceClassificationRunnerImpl::CheckRequestFilterMatchInternal, resource_classifier_, std::move(subscription_collections), @@ -3095,7 +3538,7 @@ diff --git a/components/adblock/content/browser/resource_classification_runner_i std::move(site_key)), base::BindOnce( &ResourceClassificationRunnerImpl::OnCheckResourceFilterMatchComplete, -@@ -248,9 +262,16 @@ ResourceClassificationRunnerImpl::CheckRequestFilterMatchInternal( +@@ -248,9 +263,16 @@ ResourceClassificationRunnerImpl::CheckRequestFilterMatchInternal( const scoped_refptr& resource_classifier, SubscriptionService::Snapshot subscription_collections, const GURL request_url, @@ -3112,7 +3555,7 @@ diff --git a/components/adblock/content/browser/resource_classification_runner_i TRACE_EVENT1("eyeo", "ResourceClassificationRunnerImpl::" "CheckRequestFilterMatchInternal", -@@ -258,26 +279,35 @@ ResourceClassificationRunnerImpl::CheckRequestFilterMatchInternal( +@@ -258,26 +280,35 @@ ResourceClassificationRunnerImpl::CheckRequestFilterMatchInternal( DVLOG(1) << "[eyeo] CheckRequestFilterMatchInternal start"; @@ -3165,6 +3608,17 @@ diff --git a/components/adblock/content/browser/resource_classification_runner_i return CheckResourceFilterMatchResult{FilterMatchResult::kNoRule, {}, {}}; } +@@ -320,7 +351,9 @@ void ResourceClassificationRunnerImpl::NotifyResourceMatched( + // The frame has been destroyed, so we can't notify observers. + return; + } +- ++ EyeoDocumentInfo* document_info = ++ EyeoDocumentInfo::GetOrCreateForCurrentDocument(render_frame_host); ++ document_info->SetFilterMatchResult(result, subscription, configuration_name); + for (auto& observer : observers_) { + observer.OnRequestMatched( + url, result, parent_frame_urls, static_cast(content_type), diff --git a/components/adblock/content/browser/resource_classification_runner_impl.h b/components/adblock/content/browser/resource_classification_runner_impl.h --- a/components/adblock/content/browser/resource_classification_runner_impl.h +++ b/components/adblock/content/browser/resource_classification_runner_impl.h @@ -3469,6 +3923,15 @@ diff --git a/components/adblock/core/configuration/filtering_configuration.h b/c // Adding an existing filter list, or removing a non-existing filter list, are // NOPs and do not notify observers. virtual void AddFilterList(const GURL& url) = 0; +@@ -84,6 +87,8 @@ class FilteringConfiguration { + virtual void AddCustomFilter(const std::string& filter) = 0; + virtual void RemoveCustomFilter(const std::string& filter) = 0; + virtual std::vector GetCustomFilters() const = 0; ++ virtual void AddTemporaryCustomFilter(const std::string& filter) = 0; ++ virtual std::vector GetTemporaryCustomFilters() const = 0; + }; + + } // namespace adblock diff --git a/components/adblock/core/configuration/persistent_filtering_configuration.cc b/components/adblock/core/configuration/persistent_filtering_configuration.cc --- a/components/adblock/core/configuration/persistent_filtering_configuration.cc +++ b/components/adblock/core/configuration/persistent_filtering_configuration.cc @@ -3480,7 +3943,34 @@ diff --git a/components/adblock/core/configuration/persistent_filtering_configur #include "base/logging.h" -@@ -133,6 +134,7 @@ const std::string& PersistentFilteringConfiguration::GetName() const { +@@ -34,6 +35,7 @@ namespace { + constexpr auto kEnabledKey = std::string_view("enabled"); + constexpr auto kDomainsKey = std::string_view("domains"); + constexpr auto kCustomFiltersKey = std::string_view("filters"); ++constexpr auto kCustomTemporaryFiltersKey = std::string_view("temp_filters"); + constexpr auto kFilterListsKey = std::string_view("subscriptions"); + + base::Value::Dict ReadFromPrefs(PrefService* pref_service, +@@ -42,7 +44,9 @@ base::Value::Dict ReadFromPrefs(PrefService* pref_service, + pref_service->GetValue(common::prefs::kConfigurationsPrefsPath).GetDict(); + const auto* this_config = all_configurations.FindDict(configuration_name); + if (this_config) { +- return base::Value::Dict(this_config->Clone()); ++ auto clone = base::Value::Dict(this_config->Clone()); ++ clone.Remove(kCustomTemporaryFiltersKey); ++ return clone; + } + return base::Value::Dict(); + } +@@ -63,6 +67,7 @@ void SetDefaultValuesIfNeeded(base::Value::Dict& configuration) { + } + configuration.EnsureList(kDomainsKey); + configuration.EnsureList(kCustomFiltersKey); ++ configuration.EnsureList(kCustomTemporaryFiltersKey); + configuration.EnsureList(kFilterListsKey); + } + +@@ -133,6 +138,7 @@ const std::string& PersistentFilteringConfiguration::GetName() const { } void PersistentFilteringConfiguration::SetEnabled(bool enabled) { @@ -3488,7 +3978,7 @@ diff --git a/components/adblock/core/configuration/persistent_filtering_configur if (IsEnabled() == enabled) { return; } -@@ -141,6 +143,14 @@ void PersistentFilteringConfiguration::SetEnabled(bool enabled) { +@@ -141,6 +147,14 @@ void PersistentFilteringConfiguration::SetEnabled(bool enabled) { NotifyEnabledStateChanged(); } @@ -3503,6 +3993,25 @@ diff --git a/components/adblock/core/configuration/persistent_filtering_configur bool PersistentFilteringConfiguration::IsEnabled() const { const auto pref_value = dictionary_.FindBool(kEnabledKey); DCHECK(pref_value); +@@ -209,6 +223,18 @@ void PersistentFilteringConfiguration::RemoveCustomFilter( + } + } + ++void PersistentFilteringConfiguration::AddTemporaryCustomFilter( ++ const std::string& filter) { ++ if (AppendToList(dictionary_, kCustomTemporaryFiltersKey, filter)) { ++ NotifyCustomFiltersChanged(); ++ } ++} ++ ++std::vector PersistentFilteringConfiguration::GetTemporaryCustomFilters() ++ const { ++ return GetFromList(dictionary_, kCustomTemporaryFiltersKey); ++} ++ + std::vector PersistentFilteringConfiguration::GetCustomFilters() + const { + return GetFromList(dictionary_, kCustomFiltersKey); diff --git a/components/adblock/core/configuration/persistent_filtering_configuration.h b/components/adblock/core/configuration/persistent_filtering_configuration.h --- a/components/adblock/core/configuration/persistent_filtering_configuration.h +++ b/components/adblock/core/configuration/persistent_filtering_configuration.h @@ -3516,6 +4025,16 @@ diff --git a/components/adblock/core/configuration/persistent_filtering_configur void AddFilterList(const GURL& url) final; void RemoveFilterList(const GURL& url) final; std::vector GetFilterLists() const final; +@@ -61,6 +64,9 @@ class PersistentFilteringConfiguration final : public FilteringConfiguration { + void RemoveCustomFilter(const std::string& filter) final; + std::vector GetCustomFilters() const final; + ++ void AddTemporaryCustomFilter(const std::string& filter) final; ++ std::vector GetTemporaryCustomFilters() const final; ++ + static std::vector> + GetPersistedConfigurations(PrefService* pref_service); + static void RemovePersistedData(PrefService* pref_service, diff --git a/components/adblock/core/converter/flatbuffer_converter.cc b/components/adblock/core/converter/flatbuffer_converter.cc --- a/components/adblock/core/converter/flatbuffer_converter.cc +++ b/components/adblock/core/converter/flatbuffer_converter.cc @@ -3579,7 +4098,7 @@ diff --git a/components/adblock/core/converter/parser/url_filter.cc b/components piece.remove_suffix(1); } if (piece.find('|') == std::string_view::npos) { -@@ -133,21 +137,21 @@ absl::optional UrlFilter::FromString(std::string filter_str) { +@@ -133,25 +137,18 @@ absl::optional UrlFilter::FromString(std::string filter_str) { if (options->Csp().has_value() && options->Csp().value().empty() && !is_allowing) { @@ -3597,13 +4116,16 @@ diff --git a/components/adblock/core/converter/parser/url_filter.cc b/components return {}; } - if (!options->IsSubresource() && !options->ExceptionTypes().empty() && - !is_allowing) { +- if (!options->IsSubresource() && !options->ExceptionTypes().empty() && +- !is_allowing) { - VLOG(1) << "[eyeo] Exception options can only be used with allowing " -+ LOG(INFO) << "[eyeo] Exception options can only be used with allowing " - "filters"; - return {}; - } +- "filters"; +- return {}; +- } +- + filter_str.erase(option_selector_it); + } + diff --git a/components/adblock/core/converter/parser/url_filter_options.cc b/components/adblock/core/converter/parser/url_filter_options.cc --- a/components/adblock/core/converter/parser/url_filter_options.cc +++ b/components/adblock/core/converter/parser/url_filter_options.cc @@ -3776,6 +4298,30 @@ diff --git a/components/adblock/core/converter/serializer/flatbuffer_serializer. return; } +@@ -210,6 +291,23 @@ void FlatbufferSerializer::SerializeUrlFilter(const UrlFilter url_filter) { + keyword_pattern, offset); + } + ++ if (!url_filter.is_allowing) { ++ if (!options.IsSubresource()) { ++ for (auto exception_type : options.ExceptionTypes()) { ++ switch (exception_type) { ++ case UrlFilterOptions::ExceptionType::Document: ++ AddUrlFilterToIndex(url_subresource_block_, keyword_pattern, offset); ++ break; ++ case UrlFilterOptions::ExceptionType::Genericblock: ++ case UrlFilterOptions::ExceptionType::Generichide: ++ case UrlFilterOptions::ExceptionType::Elemhide: ++ break; ++ } ++ } ++ } ++ return; ++ } ++ + for (auto exception_type : options.ExceptionTypes()) { + switch (exception_type) { + case UrlFilterOptions::ExceptionType::Genericblock: diff --git a/components/adblock/core/features.cc b/components/adblock/core/features.cc --- a/components/adblock/core/features.cc +++ b/components/adblock/core/features.cc @@ -11028,6 +11574,15 @@ diff --git a/components/adblock/core/subscription/filtering_configuration_mainta } bool FilteringConfigurationMaintainerImpl::UninstallSubscriptionInternal( +@@ -473,6 +476,8 @@ void FilteringConfigurationMaintainerImpl::SetCustomFilters() { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + + std::vector filters = configuration_->GetCustomFilters(); ++ std::vector temp_filters = configuration_->GetTemporaryCustomFilters(); ++ filters.insert(filters.end(), temp_filters.begin(), temp_filters.end()); + std::ranges::transform(configuration_->GetAllowedDomains(), + std::back_inserter(filters), + &CreateDomainAllowlistingFilter); diff --git a/components/adblock/core/subscription/filtering_configuration_maintainer_impl.h b/components/adblock/core/subscription/filtering_configuration_maintainer_impl.h --- a/components/adblock/core/subscription/filtering_configuration_maintainer_impl.h +++ b/components/adblock/core/subscription/filtering_configuration_maintainer_impl.h @@ -11656,6 +12211,32 @@ new file mode 100644 + content_settings::WebsiteSettingsRegistry::GetInstance() + ->GetMutable(ContentSettingsType::ADS) + ->set_show_into_info_page(); +diff --git a/components/error_page_strings.grdp b/components/error_page_strings.grdp +--- a/components/error_page_strings.grdp ++++ b/components/error_page_strings.grdp +@@ -263,6 +263,22 @@ + Your organization doesn’t allow you to view this site + + ++ ++ Blocked by Adblock ++ ++ ++ Blocked by Adblock ++ ++ ++ Adblock doesn’t allow you to view this site (subscription url <strong>$1</strong>example.com/) ++ ++ ++ Allow navigation until restart ++ ++ ++ Add a custom persistent allow rule ++ ++ + + This content is blocked. Contact the site owner to fix the issue. + diff --git a/content/browser/websockets/websocket_connector_impl.cc b/content/browser/websockets/websocket_connector_impl.cc --- a/content/browser/websockets/websocket_connector_impl.cc +++ b/content/browser/websockets/websocket_connector_impl.cc