From: uazo Date: Thu, 29 Sep 2022 11:27:35 +0000 Subject: Eyeo Adblock for Cromite Change the normal behaviour of Eyeo Chromium SDK to suit Cromite logic. --- .../android/java/res/xml/main_preferences.xml | 19 +- .../adblock_chrome_content_browser_client.cc | 6 + .../adblock_chrome_content_browser_client.h | 4 + chrome/browser/adblock/android/BUILD.gn | 4 +- .../adblock/android/adblock_strings.grd | 56 +- .../java/res/layout/adblock_custom_item.xml | 14 +- .../layout/adblock_filter_lists_list_item.xml | 15 + ...ences.xml => eyeo_adblock_preferences.xml} | 42 +- .../AdblockAllowedDomainsFragment.java | 7 +- .../AdblockCustomFilterListsFragment.java | 37 +- .../AdblockCustomFiltersFragment.java | 7 +- .../settings/AdblockCustomItemFragment.java | 26 +- .../settings/AdblockFilterListsAdapter.java | 6 + .../settings/AdblockFilterListsFragment.java | 8 +- .../settings/AdblockSettingsFragment.java | 98 +- .../browser/chrome_content_browser_client.cc | 6 +- .../browser/chrome_content_browser_client.h | 6 +- .../adblock_private/adblock_private_api.cc | 76 +- .../api/adblock_private/adblock_private_api.h | 49 + .../eyeo_filtering_private_api.cc | 25 +- .../api/settings_private/prefs_util.cc | 14 + ...hrome_browser_main_extra_parts_profiles.cc | 2 - chrome/browser/resources/settings/BUILD.gn | 2 + .../settings/adblock_page/adblock_page.html | 218 + .../settings/adblock_page/adblock_page.ts | 319 + .../resources/settings/page_visibility.ts | 1 + chrome/browser/resources/settings/route.ts | 4 + chrome/browser/resources/settings/router.ts | 1 + chrome/browser/resources/settings/settings.ts | 1 + .../settings/settings_main/settings_main.html | 7 + .../settings/settings_main/settings_main.ts | 1 + .../settings/settings_menu/settings_menu.html | 5 + 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 | 85 +- .../components/adblock/AdblockController.java | 53 +- components/adblock/content/browser/BUILD.gn | 24 +- .../content/browser/adblock_blocking_page.cc | 183 + .../content/browser/adblock_blocking_page.h | 75 + .../browser/adblock_content_browser_client.h | 241 +- .../browser/adblock_internals_page_handler.cc | 9 +- .../browser/adblock_url_loader_factory.cc | 72 +- .../adblock_web_ui_controller_factory.cc | 1 + .../browser/adblock_webcontents_observer.cc | 63 +- .../browser/adblock_webcontents_observer.h | 5 +- .../content/browser/element_hider_impl.cc | 21 +- .../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 +- .../factories/subscription_service_factory.cc | 22 +- .../factories/subscription_service_factory.h | 1 + .../browser/frame_hierarchy_builder.cc | 1 + .../content/browser/page_view_stats.cc | 87 +- .../browser/resource_classification_runner.h | 7 + .../resource_classification_runner_impl.cc | 71 +- .../resource_classification_runner_impl.h | 8 + components/adblock/core/BUILD.gn | 41 +- components/adblock/core/common/BUILD.gn | 8 - .../adblock/core/common/adblock_constants.cc | 17 +- .../adblock/core/common/adblock_constants.h | 1 - .../adblock/core/common/adblock_prefs.cc | 66 +- .../adblock/core/common/adblock_prefs.h | 9 +- components/adblock/core/common/app_info.cc | 17 +- components/adblock/core/common/app_info.h | 1 - .../configuration/filtering_configuration.h | 5 + .../persistent_filtering_configuration.cc | 51 +- .../persistent_filtering_configuration.h | 8 +- .../core/converter/flatbuffer_converter.cc | 2 +- .../converter/parser/filter_classifier.cc | 5 +- .../adblock/core/converter/parser/metadata.cc | 14 +- .../core/converter/parser/test/test_rules.txt | 21 + .../core/converter/parser/url_filter.cc | 20 +- .../converter/parser/url_filter_options.cc | 34 +- .../serializer/filter_keyword_extractor.cc | 13 +- .../serializer/flatbuffer_serializer.cc | 102 +- components/adblock/core/features.cc | 6 +- .../core/net/adblock_resource_request_impl.cc | 26 +- components/adblock/core/resources/.gitignore | 2 +- components/adblock/core/resources/BUILD.gn | 5 +- .../core/resources/adblock_resources.grd | 5 +- .../core/resources/elemhide_for_selector.jst | 4 +- .../adblock/core/resources/elemhideemu.jst | 2 + .../resources/snippets/dist/dependencies.jst | 1690 ++++++ .../dist/isolated-first-all.source.jst | 5256 +++++++++++++++++ components/adblock/core/sha256_file.py | 75 + .../adblock/core/sitekey_storage_impl.cc | 17 +- .../core/subscription/conversion_executors.h | 1 + .../filtering_configuration_maintainer.h | 4 + ...filtering_configuration_maintainer_impl.cc | 36 +- .../filtering_configuration_maintainer_impl.h | 4 +- .../preloaded_subscription_provider_impl.cc | 4 +- ...recommended_subscription_installer_impl.cc | 1 + .../adblock/core/subscription/subscription.cc | 20 + .../adblock/core/subscription/subscription.h | 3 + .../subscription_collection_impl.cc | 7 +- .../core/subscription/subscription_config.cc | 86 +- .../core/subscription/subscription_config.h | 6 +- .../subscription_downloader_impl.cc | 19 +- .../subscription_persistent_metadata.h | 1 + .../subscription_persistent_metadata_impl.cc | 11 +- .../subscription_persistent_metadata_impl.h | 1 + .../subscription_persistent_storage_impl.cc | 11 +- .../core/subscription/subscription_service.h | 11 + .../subscription/subscription_service_impl.cc | 87 +- .../subscription/subscription_service_impl.h | 10 + .../subscription_validator_impl.cc | 6 +- components/adblock/features.gni | 2 +- 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 + .../resources/interstitial_enterprisewarn.css | 7 + .../websockets/websocket_connector_impl.cc | 6 +- .../public/browser/content_browser_client.cc | 4 +- .../public/browser/content_browser_client.h | 4 +- content/public/common/isolated_world_ids.h | 2 +- .../about_flags_cc/Stricter-popup-blocker.inc | 14 + .../blink/renderer/core/css/style_engine.cc | 8 + .../blink/renderer/core/css/style_engine.h | 1 + .../renderer/core/dom/events/event_target.cc | 5 +- .../renderer/core/exported/web_document.cc | 13 +- .../blink/renderer/core/html/html_element.cc | 8 +- .../definitions/adblock_private.d.ts | 14 + 127 files changed, 9444 insertions(+), 709 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 create mode 100644 components/adblock/core/sha256_file.py create mode 100644 components/content_settings/core/browser/bromite_content_settings/ads.inc create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Stricter-popup-blocker.inc diff --git a/chrome/android/java/res/xml/main_preferences.xml b/chrome/android/java/res/xml/main_preferences.xml --- a/chrome/android/java/res/xml/main_preferences.xml +++ b/chrome/android/java/res/xml/main_preferences.xml @@ -1,13 +1,4 @@ - - @@ -98,11 +89,6 @@ Use of this source code is governed by the GPLv3 that can be found in the compon - + GetOriginalProfile(); } + +HostContentSettingsMap* +AdblockChromeContentBrowserClient::GetHostContentSettingsMap( + content::BrowserContext* current_browser_context) { + return HostContentSettingsMapFactory::GetForProfile(current_browser_context); +} diff --git a/chrome/browser/adblock/adblock_chrome_content_browser_client.h b/chrome/browser/adblock/adblock_chrome_content_browser_client.h --- a/chrome/browser/adblock/adblock_chrome_content_browser_client.h +++ b/chrome/browser/adblock/adblock_chrome_content_browser_client.h @@ -20,12 +20,16 @@ #include "chrome/browser/chrome_content_browser_client.h" #include "components/adblock/content/browser/adblock_content_browser_client.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" class AdblockChromeContentBrowserClient : public adblock::AdblockContentBrowserClient { private: content::BrowserContext* GetBrowserContextForEyeoFactories( content::BrowserContext* current_browser_context) override; + HostContentSettingsMap* GetHostContentSettingsMap( + content::BrowserContext* current_browser_context) override; }; #endif // CHROME_BROWSER_ADBLOCK_ADBLOCK_CHROME_CONTENT_BROWSER_CLIENT_H_ diff --git a/chrome/browser/adblock/android/BUILD.gn b/chrome/browser/adblock/android/BUILD.gn --- a/chrome/browser/adblock/android/BUILD.gn +++ b/chrome/browser/adblock/android/BUILD.gn @@ -31,9 +31,11 @@ android_library("adblock_ui_java") { deps = [ ":java_ui_resources", "//base:base_java", + "//base:supplier_java", "//build/android:build_java", "//chrome/browser/preferences:java", "//chrome/browser/profiles/android:java", + "//chrome/browser/settings:java", "//components/adblock/android:adblock_controller_java", "//components/browser_ui/settings/android:java", "//components/prefs/android:java", @@ -69,7 +71,7 @@ android_resources("java_ui_resources") { "java/res/layout/adblock_custom_item_settings.xml", "java/res/layout/adblock_filter_lists_list_item.xml", "java/res/xml/adblock_more_options.xml", - "java/res/xml/adblock_preferences.xml", + "java/res/xml/eyeo_adblock_preferences.xml", ] deps = [ ":adblock_strings_grd" ] diff --git a/chrome/browser/adblock/android/adblock_strings.grd b/chrome/browser/adblock/android/adblock_strings.grd --- a/chrome/browser/adblock/android/adblock_strings.grd +++ b/chrome/browser/adblock/android/adblock_strings.grd @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with eyeo Chromium SDK. If not, see . --> - + @@ -186,10 +186,52 @@ - Ad blocking + Adblock Plus settings + + + Enable Adblock Plus + + + Check for updates now + + + Enable anti-circumvention and snippets + + + Snippets are pieces of JavaScript code, injected by the Adblock Plus, that execute within the context of a website and combat advanced ads that circumvent ordinary blocking. +The functionality is ONLY allowed for the list +https://www.cromite.org/filters/abp-filters-anti-cv.txt +which is activated by this setting. + + + Open ABP anti-circumvention filter list repo + + + Open https://gitlab.com/eyeo/anti-cv/abp-filters-anti-cv in the browser + + + https://gitlab.com/eyeo/anti-cv/abp-filters-anti-cv + + + Open ABP Snippets Overview + + + Open https://developers.eyeo.com/snippets/snippets-overview in the browser + + + https://developers.eyeo.com/snippets/snippets-overview + + + Filter lists (%s selected) + + + Custom ad filtering settings (%s selected) + + + Custom Filters (%s selected) - Allow ad blocking on websites in this app + Block ads on websites Filter lists @@ -222,10 +264,10 @@ More blocking options - Custom ad filtering settings + Custom ad filtering urls - Add custom filter lists + Add custom filter urls https://example.org/myFilterList.txt @@ -234,10 +276,10 @@ Custom Filters - Add custom filters + Add custom filters commands - Enter filter + Enter filter commands diff --git a/chrome/browser/adblock/android/java/res/layout/adblock_custom_item.xml b/chrome/browser/adblock/android/java/res/layout/adblock_custom_item.xml --- a/chrome/browser/adblock/android/java/res/layout/adblock_custom_item.xml +++ b/chrome/browser/adblock/android/java/res/layout/adblock_custom_item.xml @@ -25,14 +25,24 @@ tools:ignore="UseCompoundDrawables"> - + + + @@ -32,6 +32,43 @@ app:iconSpaceReserved="false" android:summary="@string/fragment_adblock_settings_filter_lists_summary" /> + + + + + + + + + + + + + + android:summary="@string/fragment_adblock_settings_auto_install_enabled_summary" + app:isPreferenceVisible="false" /> { public AdblockAllowedDomainsFragment() {} @Override @@ -34,6 +34,11 @@ public class AdblockAllowedDomainsFragment extends AdblockCustomItemFragment { getActivity().setTitle(R.string.fragment_adblock_settings_allowed_domains_title); } + @Override + protected String getItemText(String item) { + return item; + } + @Override protected List getItems() { return AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) diff --git a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFilterListsFragment.java b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFilterListsFragment.java --- a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFilterListsFragment.java +++ b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFilterListsFragment.java @@ -26,13 +26,14 @@ import android.widget.Toast; import org.chromium.chrome.browser.adblock.R; import org.chromium.chrome.browser.profiles.ProfileManager; import org.chromium.components.adblock.AdblockController; +import org.chromium.components.adblock.AdblockController.Subscription; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; -public class AdblockCustomFilterListsFragment extends AdblockCustomItemFragment { +public class AdblockCustomFilterListsFragment extends AdblockCustomItemFragment { private static final String TAG = AdblockCustomFilterListsFragment.class.getSimpleName(); public AdblockCustomFilterListsFragment() {} @@ -44,29 +45,19 @@ public class AdblockCustomFilterListsFragment extends AdblockCustomItemFragment } @Override - protected List getItems() { - final List installed = - AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .getInstalledSubscriptions(); - final List recommended = - AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .getRecommendedSubscriptions(); - final List customStrings = new ArrayList(); - for (final AdblockController.Subscription subscription : installed) { - if (recommended.contains(subscription)) { - continue; - } - // FIXME(kzlomek): Remove this after DPD-1613 - if (subscription - .url() - .toString() - .equals("https://easylist-downloads.adblockplus.org/exceptionrules.txt")) { - continue; - } - customStrings.add(subscription.url().toString()); - } + protected List getItems() { + return AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) + .getCustomSubscriptions(); + } + + @Override + protected String getItemText(Subscription item) { + return item.url().toString(); + } - return customStrings; + @Override + protected String getItemStatus(Subscription item) { + return item.getDescription(); } @Override diff --git a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFiltersFragment.java b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFiltersFragment.java --- a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFiltersFragment.java +++ b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomFiltersFragment.java @@ -25,9 +25,14 @@ import org.chromium.components.adblock.AdblockController; import java.util.List; -public class AdblockCustomFiltersFragment extends AdblockCustomItemFragment { +public class AdblockCustomFiltersFragment extends AdblockCustomItemFragment { public AdblockCustomFiltersFragment() {} + @Override + protected String getItemText(String item) { + return item; + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); diff --git a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomItemFragment.java b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomItemFragment.java --- a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomItemFragment.java +++ b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockCustomItemFragment.java @@ -30,10 +30,11 @@ import android.widget.TextView; import androidx.preference.PreferenceFragmentCompat; import org.chromium.chrome.browser.adblock.R; +import org.chromium.components.browser_ui.settings.SettingsFragment; import java.util.List; -public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat { +public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat implements SettingsFragment { private EditText mItem; private ImageView mAddButton; private ListView mListView; @@ -41,6 +42,11 @@ public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat public AdblockCustomItemFragment() {} + @Override + public @AnimationType int getAnimationType() { + return AnimationType.PROPERTY; + } + @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -75,7 +81,7 @@ public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat protected abstract void removeItemImpl(String item); - protected abstract List getItems(); + protected abstract List getItems(); protected abstract String getCustomItemTextViewText(); @@ -90,10 +96,12 @@ public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat // Holder for listview items private class Holder { TextView mItem; + TextView mStatus; ImageView mRemoveButton; Holder(View rootView) { mItem = rootView.findViewById(R.id.fragment_adblock_custom_item_title); + mStatus = rootView.findViewById(R.id.fragment_adblock_custom_item_status); mRemoveButton = rootView.findViewById(R.id.fragment_adblock_custom_item_remove); mRemoveButton.setContentDescription( AdblockCustomItemFragment.this.getCustomItemRemoveButtonContentDescription()); @@ -107,6 +115,7 @@ public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat String item = (String) v.getTag(); removeItemImpl(item); mAdapter.notifyDataSetChanged(); + mItem.setText(item); } }; @@ -134,16 +143,23 @@ public abstract class AdblockCustomItemFragment extends PreferenceFragmentCompat convertView.setTag(new Holder(convertView)); } - String item = (String) getItem(position); + T item = (T) getItem(position); Holder holder = (Holder) convertView.getTag(); - holder.mItem.setText(item.toString()); + holder.mItem.setText(getItemText(item)); + holder.mStatus.setText(getItemStatus(item)); holder.mRemoveButton.setOnClickListener(removeItemClickListener); - holder.mRemoveButton.setTag(item.toString()); + holder.mRemoveButton.setTag(getItemText(item)); return convertView; } } + protected abstract String getItemText(T item); + + protected String getItemStatus(T item) { + return null; + } + private void initControls() { mAddButton.setOnClickListener( new View.OnClickListener() { diff --git a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsAdapter.java b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsAdapter.java --- a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsAdapter.java +++ b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsAdapter.java @@ -79,10 +79,13 @@ public class AdblockFilterListsAdapter extends BaseAdapter implements OnClickLis mController.getInstalledSubscriptions(); boolean subscribed = false; boolean autoinstalled = false; + TextView status = view.findViewById(R.id.status); + status.setText(""); for (final AdblockController.Subscription subscription : subscriptions) { if (subscription.url().equals(item.url())) { subscribed = true; autoinstalled = subscription.autoinstalled(); + status.setText(subscription.getDescription()); break; } } @@ -93,6 +96,9 @@ public class AdblockFilterListsAdapter extends BaseAdapter implements OnClickLis TextView description = view.findViewById(R.id.name); description.setText(item.title()); description.setContentDescription(item.title() + "filer list item title text"); + + TextView url = view.findViewById(R.id.url); + url.setText(item.url().toString()); return view; } diff --git a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsFragment.java b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsFragment.java --- a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsFragment.java +++ b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockFilterListsFragment.java @@ -26,8 +26,9 @@ import androidx.fragment.app.ListFragment; import org.chromium.chrome.browser.adblock.R; import org.chromium.chrome.browser.profiles.ProfileManager; import org.chromium.components.adblock.AdblockController; +import org.chromium.components.browser_ui.settings.SettingsFragment; -public class AdblockFilterListsFragment extends ListFragment { +public class AdblockFilterListsFragment extends ListFragment implements SettingsFragment { private AdblockFilterListsAdapter mFilterListsAdapter; @Override @@ -54,4 +55,9 @@ public class AdblockFilterListsFragment extends ListFragment { super.onStart(); mFilterListsAdapter.start(); } + + @Override + public @AnimationType int getAnimationType() { + return AnimationType.PROPERTY; + } } diff --git a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockSettingsFragment.java b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockSettingsFragment.java --- a/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockSettingsFragment.java +++ b/chrome/browser/adblock/android/java/src/org/chromium/chrome/browser/adblock/settings/AdblockSettingsFragment.java @@ -13,27 +13,47 @@ package org.chromium.chrome.browser.adblock.settings; import android.os.Bundle; +import android.widget.Toast; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import org.chromium.base.supplier.MonotonicObservableSupplier; +import org.chromium.base.supplier.ObservableSuppliers; +import org.chromium.base.supplier.SettableMonotonicObservableSupplier; + import org.chromium.build.BuildConfig; import org.chromium.chrome.browser.adblock.R; import org.chromium.chrome.browser.preferences.Pref; +import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.ProfileManager; +import org.chromium.chrome.browser.settings.ChromeBaseSettingsFragment; import org.chromium.components.adblock.AdblockController; import org.chromium.components.browser_ui.settings.ChromeSwitchPreference; +import org.chromium.components.browser_ui.settings.SettingsFragment; import org.chromium.components.user_prefs.UserPrefs; -public class AdblockSettingsFragment extends PreferenceFragmentCompat - implements Preference.OnPreferenceChangeListener { +public class AdblockSettingsFragment + extends ChromeBaseSettingsFragment implements Preference.OnPreferenceChangeListener { private ChromeSwitchPreference mAdblockEnabled; private ChromeSwitchPreference mAcceptableAdsEnabled; private ChromeSwitchPreference mAutoInstalledEnabled; private Preference mFilterLists; private Preference mAllowedDomains; private Preference mMoreOptions; - + private Preference mStartUpdate; + private ChromeSwitchPreference mPrivilegedFilters; + + private static final String START_UPDATE_KEY = + "fragment_adblock_settings_start_update"; + private static final String PRIVILEGED_FILTERS_KEY = + "fragment_adblock_privileged_filters_enabled_key"; + private static final String FILTER_LISTS_KEY = + "fragment_adblock_settings_filter_lists_key"; + private static final String CUSTOM_FILTER_LISTS_KEY = + "fragment_adblock_more_options_custom_filter_lists_key"; + private static final String CUSTOM_FILTER_KEY = + "fragment_adblock_more_options_custom_filter_key"; private static final String SETTINGS_ENABLED_KEY = "fragment_adblock_settings_enabled_key"; private static final String SETTINGS_FILTER_LISTS_KEY = "fragment_adblock_settings_filter_lists_key"; @@ -51,10 +71,35 @@ public class AdblockSettingsFragment extends PreferenceFragmentCompat private static final int ON_OFF_TOGGLE_COUNT_TIME_WINDOW_MS = 3000; private long mOnOffTogleTimestamp; + private final SettableMonotonicObservableSupplier mPageTitle = + ObservableSuppliers.createMonotonic(); + + @Override + public @SettingsFragment.AnimationType int getAnimationType() { + return SettingsFragment.AnimationType.PROPERTY; + } + + @Override + public MonotonicObservableSupplier getPageTitle() { + return mPageTitle; + } + private void bindPreferences() { + mStartUpdate = findPreference(START_UPDATE_KEY); + mStartUpdate.setOnPreferenceClickListener(preference -> { + AdblockController.getInstance( + ProfileManager.getLastUsedRegularProfile()).startUpdate(); + Toast toast = Toast.makeText(getContext(), + "Checking for updates in progress", Toast.LENGTH_LONG); + toast.show(); + // handle the click so the default action isn't triggered. + return true; + }); + mPrivilegedFilters = (ChromeSwitchPreference) findPreference(PRIVILEGED_FILTERS_KEY); mAdblockEnabled = (ChromeSwitchPreference) findPreference(SETTINGS_ENABLED_KEY); mFilterLists = findPreference(SETTINGS_FILTER_LISTS_KEY); mAcceptableAdsEnabled = (ChromeSwitchPreference) findPreference(SETTINGS_AA_ENABLED_KEY); + mAcceptableAdsEnabled.setVisible(false); mAutoInstalledEnabled = (ChromeSwitchPreference) findPreference(SETTINGS_AUTO_INSTALL_ENABLED_KEY); mAllowedDomains = findPreference(SETTINGS_ALLOWED_DOMAINS_KEY); @@ -62,35 +107,43 @@ public class AdblockSettingsFragment extends PreferenceFragmentCompat } private boolean areMoreOptionsEnabled() { - return UserPrefs.get(ProfileManager.getLastUsedRegularProfile()) - .getBoolean(Pref.ADBLOCK_MORE_OPTIONS_ENABLED); + return false; } private void applyAdblockEnabled(boolean enabledValue) { - mFilterLists.setEnabled(enabledValue); - mAcceptableAdsEnabled.setEnabled(enabledValue); + mStartUpdate.setEnabled(enabledValue); mAutoInstalledEnabled.setEnabled(enabledValue); + mPrivilegedFilters.setEnabled(enabledValue); mAllowedDomains.setEnabled(enabledValue); mMoreOptions.setEnabled(enabledValue); mMoreOptions.setVisible(areMoreOptionsEnabled()); } private void synchronizePreferences() { - boolean enabled = - AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .isEnabled(); + AdblockController controller = + AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()); + + findPreference(FILTER_LISTS_KEY).setTitle( + getContext().getString(R.string.fragment_adblock_settings_filter_lists_title_count, + controller.getInstalledSubscriptions().size())); + findPreference(CUSTOM_FILTER_LISTS_KEY).setTitle( + getContext().getString(R.string.fragment_adblock_more_options_custom_filter_lists_title_count, + controller.getCustomSubscriptions().size())); + findPreference(CUSTOM_FILTER_KEY).setTitle( + getContext().getString(R.string.fragment_adblock_more_options_custom_filters_title_count, + controller.getCustomFilters().size())); + mPrivilegedFilters.setChecked(controller.isPrivilegedFiltersEnabled()); + mPrivilegedFilters.setOnPreferenceChangeListener(this); + boolean enabled = controller.isEnabled(); mAdblockEnabled.setChecked(enabled); mAdblockEnabled.setOnPreferenceChangeListener(this); applyAdblockEnabled(enabled); - mAcceptableAdsEnabled.setChecked( - AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .isAcceptableAdsEnabled()); + mAcceptableAdsEnabled.setChecked(controller.isAcceptableAdsEnabled()); mAcceptableAdsEnabled.setOnPreferenceChangeListener(this); mAutoInstalledEnabled.setChecked( - AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .isAutoInstallEnabled()); + controller.isAutoInstallEnabled()); mAutoInstalledEnabled.setOnPreferenceChangeListener(this); } @@ -122,7 +175,7 @@ public class AdblockSettingsFragment extends PreferenceFragmentCompat @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - addPreferencesFromResource(R.xml.adblock_preferences); + addPreferencesFromResource(R.xml.eyeo_adblock_preferences); bindPreferences(); synchronizePreferences(); } @@ -137,19 +190,16 @@ public class AdblockSettingsFragment extends PreferenceFragmentCompat public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference.getKey().equals(SETTINGS_ENABLED_KEY)) { AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .setEnabled((Boolean) newValue); + .setEnabled( + (Boolean) newValue); maybeEnableMoreOptions(); applyAdblockEnabled((Boolean) newValue); - } else if (preference.getKey().equals(SETTINGS_AA_ENABLED_KEY)) { - AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .setAcceptableAdsEnabled((Boolean) newValue); - } else { - assert preference.getKey().equals(SETTINGS_AUTO_INSTALL_ENABLED_KEY); - + } else if (preference.getKey().equals(PRIVILEGED_FILTERS_KEY)) { AdblockController.getInstance(ProfileManager.getLastUsedRegularProfile()) - .setAutoInstallEnabled((Boolean) newValue); + .setPrivilegedFiltersEnabled( + (Boolean) newValue); } return true; } diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -6637,7 +6637,9 @@ ChromeContentBrowserClient:: } bool ChromeContentBrowserClient::WillInterceptWebSocket( - content::RenderFrameHost* frame) { + content::RenderFrameHost* frame, + content::RenderProcessHost* process, + const url::Origin& origin) { #if BUILDFLAG(ENABLE_EXTENSIONS_CORE) if (!frame) { return false; @@ -6659,9 +6661,11 @@ bool ChromeContentBrowserClient::WillInterceptWebSocket( } void ChromeContentBrowserClient::CreateWebSocket( + content::RenderProcessHost* process, content::RenderFrameHost* frame, WebSocketFactory factory, const GURL& url, + const url::Origin& initiator_origin, const net::SiteForCookies& site_for_cookies, const std::optional& user_agent, mojo::PendingRemote diff --git a/chrome/browser/chrome_content_browser_client.h b/chrome/browser/chrome_content_browser_client.h --- a/chrome/browser/chrome_content_browser_client.h +++ b/chrome/browser/chrome_content_browser_client.h @@ -723,11 +723,15 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient { CreateURLLoaderHandlerForServiceWorkerInitiatedNavigationRequest( content::FrameTreeNodeId frame_tree_node_id, const network::ResourceRequest& resource_request) override; - bool WillInterceptWebSocket(content::RenderFrameHost* frame) override; + bool WillInterceptWebSocket(content::RenderFrameHost* frame, + content::RenderProcessHost* process, + const url::Origin& origin) override; void CreateWebSocket( + content::RenderProcessHost* process, content::RenderFrameHost* frame, WebSocketFactory factory, const GURL& url, + const url::Origin& initiator_origin, const net::SiteForCookies& site_for_cookies, const std::optional& user_agent, mojo::PendingRemote diff --git a/chrome/browser/extensions/api/adblock_private/adblock_private_api.cc b/chrome/browser/extensions/api/adblock_private/adblock_private_api.cc --- a/chrome/browser/extensions/api/adblock_private/adblock_private_api.cc +++ b/chrome/browser/extensions/api/adblock_private/adblock_private_api.cc @@ -17,6 +17,7 @@ #include "base/containers/flat_map.h" #include "base/i18n/time_formatting.h" +#include "base/strings/utf_string_conversions.h" #include "base/logging.h" #include "base/no_destructor.h" #include "base/values.h" @@ -94,27 +95,12 @@ std::vector CopySessionsStats( return result; } -std::string SubscriptionInstallationStateToString( - adblock::Subscription::InstallationState state) { - using State = adblock::Subscription::InstallationState; - switch (state) { - case State::Installed: - return "Installed"; - case State::AutoInstalled: - return "AutoInstalled"; - case State::Preloaded: - return "Preloaded"; - case State::Installing: - return "Installing"; - case State::Unknown: - return "Unknown"; - } - return ""; -} - std::vector CopySubscriptions( + raw_ptr subscription_service, const std::vector> current_subscriptions) { + raw_ptr metadata = + subscription_service->GetMetadata(); std::vector result; for (auto& sub : current_subscriptions) { api::adblock_private::Subscription js_sub; @@ -122,12 +108,13 @@ std::vector CopySubscriptions( js_sub.title = sub->GetTitle(); js_sub.current_version = sub->GetCurrentVersion(); js_sub.installation_state = - SubscriptionInstallationStateToString(sub->GetInstallationState()); - const auto installation_time = sub->GetInstallationTime(); + adblock::Subscription::SubscriptionInstallationStateToString(sub->GetInstallationState()); js_sub.last_installation_time = - installation_time.is_null() - ? "" - : base::TimeFormatAsIso8601(sub->GetInstallationTime()); + base::UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(sub->GetInstallationTime())); + if (metadata) { + js_sub.download_success_count = metadata->GetDownloadSuccessCount(sub->GetSourceUrl()); + js_sub.download_error_count = metadata->GetDownloadErrorCount(sub->GetSourceUrl()); + } result.emplace_back(std::move(js_sub)); } return result; @@ -367,6 +354,47 @@ void AdblockPrivateAPI::OnListenerAdded( namespace api { +AdblockPrivateStartUpdateFunction::AdblockPrivateStartUpdateFunction() {} + +AdblockPrivateStartUpdateFunction::~AdblockPrivateStartUpdateFunction() {} + +ExtensionFunction::ResponseAction AdblockPrivateStartUpdateFunction::Run() { + auto* subscription_service = + adblock::SubscriptionServiceFactory::GetForBrowserContext( + browser_context()); + subscription_service->StartUpdate(); + return RespondNow(NoArguments()); +} + +AdblockPrivateSetPrivilegedFiltersEnabledFunction::AdblockPrivateSetPrivilegedFiltersEnabledFunction() {} + +AdblockPrivateSetPrivilegedFiltersEnabledFunction::~AdblockPrivateSetPrivilegedFiltersEnabledFunction() {} + +ExtensionFunction::ResponseAction AdblockPrivateSetPrivilegedFiltersEnabledFunction::Run() { + std::optional params = + api::adblock_private::SetEnabled::Params::Create(args()); + EXTENSION_FUNCTION_VALIDATE(params); + + auto* subscription_service = + adblock::SubscriptionServiceFactory::GetForBrowserContext( + browser_context()); + subscription_service->SetPrivilegedFiltersEnabled(params->enabled); + return RespondNow(NoArguments()); +} + +AdblockPrivateIsPrivilegedFiltersEnabledFunction::AdblockPrivateIsPrivilegedFiltersEnabledFunction() {} + +AdblockPrivateIsPrivilegedFiltersEnabledFunction::~AdblockPrivateIsPrivilegedFiltersEnabledFunction() {} + +ExtensionFunction::ResponseAction AdblockPrivateIsPrivilegedFiltersEnabledFunction::Run() { + auto* subscription_service = + adblock::SubscriptionServiceFactory::GetForBrowserContext( + browser_context()); + return RespondNow( + ArgumentList(api::adblock_private::IsEnabled::Results::Create( + subscription_service->IsPrivilegedFiltersEnabled()))); +} + AdblockPrivateSetEnabledFunction::AdblockPrivateSetEnabledFunction() {} AdblockPrivateSetEnabledFunction::~AdblockPrivateSetEnabledFunction() {} @@ -555,7 +583,7 @@ AdblockPrivateGetInstalledSubscriptionsFunction::Run() { GetAdblockConfiguration(GetOriginalBrowserContext(browser_context())); return RespondNow(ArgumentList( api::adblock_private::GetInstalledSubscriptions::Results::Create( - CopySubscriptions(subscription_service->GetCurrentSubscriptions( + CopySubscriptions(subscription_service, subscription_service->GetCurrentSubscriptions( adblock_configuration))))); } diff --git a/chrome/browser/extensions/api/adblock_private/adblock_private_api.h b/chrome/browser/extensions/api/adblock_private/adblock_private_api.h --- a/chrome/browser/extensions/api/adblock_private/adblock_private_api.h +++ b/chrome/browser/extensions/api/adblock_private/adblock_private_api.h @@ -58,6 +58,55 @@ void BrowserContextKeyedAPIFactory< namespace api { +class AdblockPrivateStartUpdateFunction : public ExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("adblockPrivate.startUpdate", UNKNOWN) + AdblockPrivateStartUpdateFunction(); + + private: + ~AdblockPrivateStartUpdateFunction() override; + + ResponseAction Run() override; + + AdblockPrivateStartUpdateFunction(const AdblockPrivateStartUpdateFunction&) = + delete; + AdblockPrivateStartUpdateFunction& operator=( + const AdblockPrivateStartUpdateFunction&) = delete; +}; + + +class AdblockPrivateSetPrivilegedFiltersEnabledFunction : public ExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("adblockPrivate.setPrivilegedFiltersEnabled", UNKNOWN) + AdblockPrivateSetPrivilegedFiltersEnabledFunction(); + + private: + ~AdblockPrivateSetPrivilegedFiltersEnabledFunction() override; + + ResponseAction Run() override; + + AdblockPrivateSetPrivilegedFiltersEnabledFunction(const AdblockPrivateSetPrivilegedFiltersEnabledFunction&) = + delete; + AdblockPrivateSetPrivilegedFiltersEnabledFunction& operator=( + const AdblockPrivateSetPrivilegedFiltersEnabledFunction&) = delete; +}; + +class AdblockPrivateIsPrivilegedFiltersEnabledFunction : public ExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("adblockPrivate.isPrivilegedFiltersEnabled", UNKNOWN) + AdblockPrivateIsPrivilegedFiltersEnabledFunction(); + + private: + ~AdblockPrivateIsPrivilegedFiltersEnabledFunction() override; + + ResponseAction Run() override; + + AdblockPrivateIsPrivilegedFiltersEnabledFunction(const AdblockPrivateIsPrivilegedFiltersEnabledFunction&) = + delete; + AdblockPrivateIsPrivilegedFiltersEnabledFunction& operator=( + const AdblockPrivateIsPrivilegedFiltersEnabledFunction&) = delete; +}; + class AdblockPrivateSetEnabledFunction : public ExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("adblockPrivate.setEnabled", UNKNOWN) diff --git a/chrome/browser/extensions/api/eyeo_filtering_private/eyeo_filtering_private_api.cc b/chrome/browser/extensions/api/eyeo_filtering_private/eyeo_filtering_private_api.cc --- a/chrome/browser/extensions/api/eyeo_filtering_private/eyeo_filtering_private_api.cc +++ b/chrome/browser/extensions/api/eyeo_filtering_private/eyeo_filtering_private_api.cc @@ -17,8 +17,10 @@ #include "base/containers/flat_map.h" #include "base/i18n/time_formatting.h" +#include "base/strings/utf_string_conversions.h" #include "base/logging.h" #include "base/no_destructor.h" +#include "base/strings/stringprintf.h" #include "base/values.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/profiles/profile.h" @@ -30,6 +32,7 @@ #include "components/adblock/core/common/adblock_prefs.h" #include "components/adblock/core/common/adblock_utils.h" #include "components/adblock/core/common/content_type.h" +#include "components/adblock/core/subscription/subscription.h" #include "components/adblock/core/configuration/filtering_configuration.h" #include "components/adblock/core/configuration/persistent_filtering_configuration.h" #include "components/adblock/core/session_stats.h" @@ -95,24 +98,6 @@ std::vector CopySessionsStats( return result; } -std::string SubscriptionInstallationStateToString( - adblock::Subscription::InstallationState state) { - using State = adblock::Subscription::InstallationState; - switch (state) { - case State::Installed: - return "Installed"; - case State::AutoInstalled: - return "AutoInstalled"; - case State::Preloaded: - return "Preloaded"; - case State::Installing: - return "Installing"; - case State::Unknown: - return "Unknown"; - } - return ""; -} - std::vector CopySubscriptions( const std::vector> current_subscriptions) { @@ -123,12 +108,12 @@ std::vector CopySubscriptions( js_sub.title = sub->GetTitle(); js_sub.current_version = sub->GetCurrentVersion(); js_sub.installation_state = - SubscriptionInstallationStateToString(sub->GetInstallationState()); + adblock::Subscription::SubscriptionInstallationStateToString(sub->GetInstallationState()); const auto installation_time = sub->GetInstallationTime(); js_sub.last_installation_time = installation_time.is_null() ? "" - : base::TimeFormatAsIso8601(sub->GetInstallationTime()); + : base::UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime(sub->GetInstallationTime())); result.emplace_back(std::move(js_sub)); } return result; diff --git a/chrome/browser/extensions/api/settings_private/prefs_util.cc b/chrome/browser/extensions/api/settings_private/prefs_util.cc --- a/chrome/browser/extensions/api/settings_private/prefs_util.cc +++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc @@ -35,6 +35,7 @@ #include "chrome/browser/ui/toolbar/toolbar_pref_names.h" #include "chrome/common/extensions/api/settings_private.h" #include "chrome/common/pref_names.h" +#include "components/adblock/core/common/adblock_prefs.h" #include "components/autofill/core/common/autofill_prefs.h" #include "components/bookmarks/common/bookmark_pref_names.h" #include "components/browsing_data/core/pref_names.h" @@ -206,6 +207,19 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetAllowlistedKeys() { } s_allowlist = new PrefsUtil::TypedPrefMap(); + // Adblock settings + (*s_allowlist)[adblock::common::prefs::kEnableAdblockLegacy] = + settings_api::PrefType::kBoolean; + (*s_allowlist)[adblock::common::prefs::kEnableAcceptableAdsLegacy] = + settings_api::PrefType::kBoolean; + (*s_allowlist)[adblock::common::prefs::kAdblockSubscriptionsLegacy] = + settings_api::PrefType::kList; + (*s_allowlist)[adblock::common::prefs::kAdblockCustomSubscriptionsLegacy] = + settings_api::PrefType::kList; + (*s_allowlist)[adblock::common::prefs::kAdblockAllowedDomainsLegacy] = + settings_api::PrefType::kList; + (*s_allowlist)[adblock::common::prefs::kAdblockCustomFiltersLegacy] = + settings_api::PrefType::kList; // Miscellaneous (*s_allowlist)[::embedder_support::kAlternateErrorPagesEnabled] = settings_api::PrefType::kBoolean; diff --git a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc --- a/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc +++ b/chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.cc @@ -279,7 +279,6 @@ #include "chrome/common/buildflags.h" #include "chrome/common/chrome_features.h" #include "components/adblock/content/browser/factories/adblock_request_throttle_factory.h" -#include "components/adblock/content/browser/factories/adblock_telemetry_service_factory.h" #include "components/adblock/content/browser/factories/content_security_policy_injector_factory.h" #include "components/adblock/content/browser/factories/element_hider_factory.h" #include "components/adblock/content/browser/factories/resource_classification_runner_factory.h" @@ -998,7 +997,6 @@ void ChromeBrowserMainExtraPartsProfiles:: FederatedIdentityApiPermissionContextFactory::GetInstance(); FederatedIdentityAutoReauthnPermissionContextFactory::GetInstance(); FederatedIdentityPermissionContextFactory::GetInstance(); - adblock::AdblockTelemetryServiceFactory::GetInstance(); adblock::AdblockRequestThrottleFactory::GetInstance(); adblock::ContentSecurityPolicyInjectorFactory::GetInstance(); adblock::ElementHiderFactory::GetInstance(); diff --git a/chrome/browser/resources/settings/BUILD.gn b/chrome/browser/resources/settings/BUILD.gn --- a/chrome/browser/resources/settings/BUILD.gn +++ b/chrome/browser/resources/settings/BUILD.gn @@ -66,6 +66,7 @@ build_webui("build") { "ai_page/ai_site_add_dialog.ts", "ai_page/history_search_page.ts", "ai_page/offer_writing_help_page.ts", + "adblock_page/adblock_page.ts", "appearance_page/appearance_fonts_page.ts", "appearance_page/appearance_page.ts", "appearance_page/appearance_page_index.ts", @@ -439,6 +440,7 @@ build_webui("build") { ts_definitions = [ "//tools/typescript/definitions/autofill_private.d.ts", "//tools/typescript/definitions/chrome_event.d.ts", + "//tools/typescript/definitions/adblock_private.d.ts", "//tools/typescript/definitions/chrome_send.d.ts", "//tools/typescript/definitions/language_settings_private.d.ts", "//tools/typescript/definitions/management.d.ts", diff --git a/chrome/browser/resources/settings/adblock_page/adblock_page.html b/chrome/browser/resources/settings/adblock_page/adblock_page.html new file mode 100644 --- /dev/null +++ b/chrome/browser/resources/settings/adblock_page/adblock_page.html @@ -0,0 +1,218 @@ + + + + + + + +
+ +
+
+
Enable anti-circumvention and snippets
+
+ Snippets are pieces of JavaScript code, injected by the Adblock Plus, that execute within the context of a website and combat advanced ads that circumvent ordinary blocking. + The functionality is ONLY allowed for the list + abp-filters-anti-cv.txt + which is activated by this setting. +
Open ABP anti-circumvention filter list repo +
Open ABP Snippets Overview +
+
+
+ + +
+ +
+
+
+ + Check for updates now + +
+ +
+ +
+
Built in Subscriptions ([[countEnabled]] selected)
+
+ Add the languages in which you regularly browse websites in +
+
+
+ +
+ +
+
+
+
+ +
+ Allowed Domains ([[allowedDomainsCount]] added) +
+
+ Support your favorite websites by adding them to this list. You might see ads on them. +
+
+ +
+ +
+
+ + + Add + + +
+
+
+
+
+
+ +
+ Custom Subscriptions ([[customSubscriptions.length]] added) +
+
+ Add custom filter urls +
+
+ +
+ +
+
+ + + Add + + +
+
+
+
+
+
+ +
+ Custom Filters ([[customFilters.length]] added) +
+
+ Add custom filter commands +
+
+ +
+ +
+
+ + + Add + + +
+
+
+
+
+ +
+ +
diff --git a/chrome/browser/resources/settings/adblock_page/adblock_page.ts b/chrome/browser/resources/settings/adblock_page/adblock_page.ts new file mode 100644 --- /dev/null +++ b/chrome/browser/resources/settings/adblock_page/adblock_page.ts @@ -0,0 +1,319 @@ +/* + This file is part of Bromite. + + Bromite 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 3 of the License, or + (at your option) any later version. + + Bromite 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 Bromite. If not, see . +*/ +import 'chrome://resources/polymer/v3_0/iron-flex-layout/iron-flex-layout-classes.js'; +import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js'; +import 'chrome://resources/cr_elements/cr_button/cr_button.js'; +import 'chrome://resources/cr_elements/cr_shared_style.css.js'; +import 'chrome://resources/cr_elements/cr_collapse/cr_collapse.js'; +import 'chrome://resources/cr_elements/cr_toggle/cr_toggle.js'; +import 'chrome://resources/cr_elements/cr_expand_button/cr_expand_button.js'; +import 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.js'; +import 'chrome://resources/cr_elements/cr_input/cr_input.js'; +import 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.js'; +import '../settings_shared.css.js'; +import '../settings_page/settings_section.js'; +import '../controls/settings_toggle_button.js'; +import '../controls/settings_dropdown_menu.js'; + +import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js'; +import {BaseMixin} from '../base_mixin.js'; +import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; +import {SettingsToggleButtonElement} from '../controls/settings_toggle_button.js'; +import {PrefsMixin} from '/shared/settings/prefs/prefs_mixin.js'; +import {CrCheckboxElement} from 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.js'; +import {getTemplate} from './adblock_page.html.js'; +import {getToastManager} from 'chrome://resources/cr_elements/cr_toast/cr_toast_manager.js'; +import {getSearchManager} from '../search_settings.js'; +import type {SettingsPlugin} from '../settings_main/settings_plugin.js'; + +const SettingsAdblockPageElementBase = + I18nMixin(PrefsMixin(BaseMixin((PolymerElement)))); + +interface Subscription { + url: string; + title: string; + enabled: boolean; + current_version: string; + download_error_count: number; + download_success_count: number; + installation_state: string; + last_installation_time: string; +} + +export class SettingsAdblockPageElement extends SettingsAdblockPageElementBase + implements SettingsPlugin { + static get is() { + return 'settings-adblock-page'; + } + + static get template() { + return getTemplate(); + } + + static get properties() { + return { + customSubscriptionInput: String, + customFilterInput: String, + allowedDomainInput: String, + additionalMessage: String, + additionalMessageIcon: String, + countEnabled: Number, + allowedDomainsCount: Number, + isEnablePrivilegedFiltersToggle_: Boolean, + customSubscriptions: Array, + customFilters: Array, + allowedDomains: Array, + subscriptions: Array, + } + } + + // input fields updated by html + declare private customSubscriptionInput: string; + declare private customFilterInput: string; + declare private allowedDomainInput: string; + declare private additionalMessage: string; + declare private additionalMessageIcon: string; + declare private countEnabled: number; + declare private allowedDomainsCount: number; + declare private isEnablePrivilegedFiltersToggle_: boolean; + + // models that will fill templates lists in html + declare private customSubscriptions: Subscription[]; + declare private customFilters: Array; + declare private allowedDomains: Array; + declare private subscriptions: Subscription[]; + + private syncSubscriptions() { + this.subscriptions = [] + this.customSubscriptions = []; + + chrome.adblockPrivate?.getBuiltInSubscriptions(list => { + chrome.adblockPrivate.getInstalledSubscriptions(activelist => { + let new_subscriptions: Subscription[] = []; + let custom_subscriptions: Subscription[] = []; + + list.forEach(obj => { + new_subscriptions.push({ + title: obj.title, + enabled: false, + url: obj.url, + current_version: '', + download_error_count: 0, + download_success_count: 0, + installation_state: '', + last_installation_time: '' + }) + }) + + activelist.forEach(obj => { + var found = new_subscriptions.find(element => element.url == obj.url); + if (found === undefined) { + found = { + title: obj.title, + enabled: false, + url: obj.url, + current_version: '', + download_error_count: 0, + download_success_count: 0, + installation_state: '', + last_installation_time: '' + } + custom_subscriptions.push(found) + } + found.enabled = true; + found.current_version = obj.current_version; + found.download_error_count = obj.download_error_count; + found.download_success_count = obj.download_success_count; + found.installation_state = obj.installation_state; + found.last_installation_time = obj.last_installation_time; + }) + + this.subscriptions = new_subscriptions; + this.customSubscriptions = custom_subscriptions; + this.updateUI(); + }) + }); + } + + private updateUI() { + this.additionalMessage = ""; + this.additionalMessageIcon = ""; + this.countEnabled = 0; + + chrome.adblockPrivate?.isEnabled(enabled => { + if (!enabled) return; + + let c = 0; + this.subscriptions.forEach(obj => { + if (obj.enabled) c++; + }); + this.countEnabled = c; + if (this.countEnabled == 0 && + this.customSubscriptions.length == 0 && + this.customFilters.length == 0) { + this.additionalMessage = "No subscriptions selected. Adblock is not active."; + this.additionalMessageIcon = "cr:warning"; + } + }); + + chrome.adblockPrivate?.isPrivilegedFiltersEnabled(enabled => { + this.isEnablePrivilegedFiltersToggle_ = enabled; + }); + } + + private syncCustomFilters() { + chrome.adblockPrivate?.getCustomFilters(domain => { + this.customFilters = []; + domain.forEach(value => { + this.customFilters.push(value); + }) + this.updateUI(); + }); + } + + private syncAllowedDomains() { + this.allowedDomainsCount = 0; + chrome.adblockPrivate?.getAllowedDomains(domain => { + this.allowedDomains = []; + domain.forEach(value => { + this.allowedDomains.push(value); + }) + this.allowedDomainsCount = this.allowedDomains.length; + this.updateUI(); + }); + } + + public override ready() { + super.ready(); + + this.syncSubscriptions(); + this.syncCustomFilters(); + this.syncAllowedDomains(); + } + + private onAdblockEnabled_(event: Event) { + if ((event.target as SettingsToggleButtonElement).checked) { + chrome.adblockPrivate.setEnabled(true); + } else { + chrome.adblockPrivate.setEnabled(false); + } + this.updateUI(); + } + + private onEnablePrivilegedFiltersToggle_(_evt: any, enabled: boolean) { + chrome.adblockPrivate.setPrivilegedFiltersEnabled(enabled); + this.syncSubscriptions(); + } + + private cleanUrl(url: string) : string { + let cleanedUrl : string = ""; + try { + cleanedUrl = new URL(url).host; + } catch (err) { + try { + // one last try by adding schema + cleanedUrl = new URL("https://" + url).host; + } + catch (err) { + console.log("malformed url " + url); + return ""; + } + } + return cleanedUrl; + } + + private selectRecommendedSubscription(e: Event) { + const url = ((e.target as CrCheckboxElement).id); + const enabled = ((e.target as CrCheckboxElement).checked); + if (enabled) { + chrome.adblockPrivate.installSubscription(url); + } else { + chrome.adblockPrivate.uninstallSubscription(url); + } + this.updateUI(); + } + + private removeCustomFilter(e: Event) { + const filter = ((e.target as HTMLElement).id); + chrome.adblockPrivate.removeCustomFilter(filter); + const i = this.customFilters.indexOf(filter); + this.splice('customFilters', i, 1); + this.updateUI(); + } + + private addCustomFilter() { + if (this.customFilterInput == undefined || this.customFilterInput == "") return; + chrome.adblockPrivate.addCustomFilter(this.customFilterInput); + this.customFilterInput = ""; + this.syncCustomFilters(); + } + + private removeAllowedDomain(e: Event) { + const allowedDomain = ((e.target as HTMLElement).id); + chrome.adblockPrivate.removeAllowedDomain(allowedDomain); + const i = this.allowedDomains.indexOf(allowedDomain); + this.splice('allowedDomains', i, 1); + this.allowedDomainsCount = this.allowedDomains.length; + this.updateUI(); + } + + private addAllowedDomain() { + if (this.allowedDomainInput == undefined || this.allowedDomainInput == "") return; + const cleanedUrl = this.cleanUrl(this.allowedDomainInput); + if (cleanedUrl == "") return; + chrome.adblockPrivate.addAllowedDomain(cleanedUrl); + this.allowedDomainInput = ""; + this.syncAllowedDomains(); + } + + private removeCustomSubscription(e: Event) { + const url = ((e.target as HTMLElement).id); + const subscription = this.customSubscriptions.find( x => x.url = url); + chrome.adblockPrivate.uninstallSubscription(subscription!.url); + this.splice('customSubscriptions', this.customSubscriptions.indexOf(subscription!), 1); + this.updateUI(); + } + + private addCustomSubscription() { + if (this.customSubscriptionInput == undefined || this.customSubscriptionInput == "") return; + chrome.adblockPrivate.installSubscription(this.customSubscriptionInput); + this.customSubscriptionInput = ""; + this.syncSubscriptions(); + } + + private startUpdateCycle() { + const toastManager = getToastManager(); + chrome.adblockPrivate.startUpdate(); + toastManager.duration = 5000; + toastManager.show("Starting update..."); + } + + // SettingsPlugin implementation + async searchContents(query: string) { + const searchRequest = await getSearchManager().search(query, this); + return searchRequest.getSearchResult(); + } +} + +declare global { + interface HTMLElementTagNameMap { + 'settings-adblock-page': SettingsAdblockPageElement; + } +} + +customElements.define( + SettingsAdblockPageElement.is, SettingsAdblockPageElement); diff --git a/chrome/browser/resources/settings/page_visibility.ts b/chrome/browser/resources/settings/page_visibility.ts --- a/chrome/browser/resources/settings/page_visibility.ts +++ b/chrome/browser/resources/settings/page_visibility.ts @@ -9,6 +9,7 @@ import {loadTimeData} from './i18n_setup.js'; */ export interface PageVisibility { a11y?: boolean; + adblock?: boolean; ai?: boolean; appearance?: boolean|AppearancePageVisibility; autofill?: boolean; diff --git a/chrome/browser/resources/settings/route.ts b/chrome/browser/resources/settings/route.ts --- a/chrome/browser/resources/settings/route.ts +++ b/chrome/browser/resources/settings/route.ts @@ -275,6 +275,10 @@ function createRoutes(): SettingsRoutes { '/onStartup', 'onStartup', loadTimeData.getString('onStartup')); } + if (visibility.adblock !== false) { + r.ADBLOCK = r.BASIC.createSection('/adblock', 'adblock'); + } + // Advanced Routes r.ADVANCED = new Route('/advanced'); diff --git a/chrome/browser/resources/settings/router.ts b/chrome/browser/resources/settings/router.ts --- a/chrome/browser/resources/settings/router.ts +++ b/chrome/browser/resources/settings/router.ts @@ -13,6 +13,7 @@ import {loadTimeData} from './i18n_setup.js'; */ export interface SettingsRoutes { ABOUT: Route; + ADBLOCK: Route; ACCESSIBILITY: Route; ADDRESSES: Route; ADVANCED: Route; diff --git a/chrome/browser/resources/settings/settings.ts b/chrome/browser/resources/settings/settings.ts --- a/chrome/browser/resources/settings/settings.ts +++ b/chrome/browser/resources/settings/settings.ts @@ -67,6 +67,7 @@ export {HomeUrlInputElement} from './appearance_page/home_url_input.js'; export {SettingsAutofillAiEntriesListElement} from './autofill_page/autofill_ai_entries_list.js'; export {SettingsAutofillPageElement} from './autofill_page/autofill_page.js'; export {SettingsAutofillPageIndexElement} from './autofill_page/autofill_page_index.js'; +export {SettingsAdblockPageElement} from './adblock_page/adblock_page.js'; export {PasswordCheckReferrer, PasswordManagerImpl, PasswordManagerPage} from './autofill_page/password_manager_proxy.js'; export type {PasswordManagerProxy} from './autofill_page/password_manager_proxy.js'; export {BaseMixin} from './base_mixin.js'; diff --git a/chrome/browser/resources/settings/settings_main/settings_main.html b/chrome/browser/resources/settings/settings_main/settings_main.html --- a/chrome/browser/resources/settings/settings_main/settings_main.html +++ b/chrome/browser/resources/settings/settings_main/settings_main.html @@ -201,6 +201,13 @@ +
+ +
+