Files
helium/patches/helium/core/ublock-helium-services.patch

260 lines
12 KiB
C++

--- a/components/helium_services/helium_services_helpers.cc
+++ b/components/helium_services/helium_services_helpers.cc
@@ -88,6 +88,11 @@ bool ShouldAccessUpdateService(const Pre
prefs.GetBoolean(prefs::kHeliumUpdateFetchingEnabled);
}
+bool ShouldAccessUBlockAssets(const PrefService& prefs) {
+ return ShouldAccessServices(prefs) &&
+ prefs.GetBoolean(prefs::kHeliumUBlockAssetsEnabled);
+}
+
GURL GetExtensionUpdateURL(const PrefService& prefs) {
if (!ShouldAccessExtensionService(prefs)) {
return GetDummyURL();
@@ -127,6 +132,14 @@ GURL GetBrowserUpdateURL(const PrefServi
#endif
}
+GURL GetUBlockAssetsURL(const PrefService& prefs) {
+ if (!ShouldAccessUBlockAssets(prefs)) {
+ return GetDummyURL();
+ }
+
+ return GetServicesBaseURL(prefs).Resolve("/ubo/assets.json");
+}
+
void ConfigurePrefChangeRegistrarFor(std::string_view pref_name,
PrefChangeRegistrar& registrar, const base::RepeatingClosure& observer) {
registrar.Add(prefs::kHeliumServicesEnabled, observer);
--- a/components/helium_services/helium_services_helpers.h
+++ b/components/helium_services/helium_services_helpers.h
@@ -21,12 +21,14 @@ const char kHeliumDummyOrigin[] =
COMPONENT_EXPORT(HELIUM) bool ShouldFetchBangs(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) bool ShouldAccessExtensionService(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) bool ShouldAccessUpdateService(const PrefService& prefs);
+COMPONENT_EXPORT(HELIUM) bool ShouldAccessUBlockAssets(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) GURL GetServicesBaseURL(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) GURL GetDummyURL();
COMPONENT_EXPORT(HELIUM) GURL GetExtensionUpdateURL(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) GURL GetWebstoreSnippetURL(const PrefService& prefs, std::string_view id);
COMPONENT_EXPORT(HELIUM) GURL GetSpellcheckURL(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) GURL GetBrowserUpdateURL(const PrefService& prefs);
+COMPONENT_EXPORT(HELIUM) GURL GetUBlockAssetsURL(const PrefService& prefs);
COMPONENT_EXPORT(HELIUM) std::optional<GURL> GetValidUserOverridenURL(std::string_view user_url_);
COMPONENT_EXPORT(HELIUM) void ConfigurePrefChangeRegistrarFor(std::string_view pref_name,
PrefChangeRegistrar& registrar, const base::RepeatingClosure& observer);
--- a/components/helium_services/pref_names.h
+++ b/components/helium_services/pref_names.h
@@ -33,6 +33,8 @@ inline constexpr char kHeliumUpdateFetch
inline constexpr char kHeliumSpellcheckEnabled[] =
"helium.services.spellcheck_files";
+inline constexpr char kHeliumUBlockAssetsEnabled[] =
+ "helium.services.ublock_assets";
} // namespace prefs
#endif // COMPONENTS_HELIUM_SERVICES_PREF_NAMES_H_
--- a/chrome/browser/extensions/api/settings_private/prefs_util.cc
+++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc
@@ -366,6 +366,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil
settings_api::PrefType::kBoolean;
(*s_allowlist)[::prefs::kHeliumUpdateFetchingEnabled] =
settings_api::PrefType::kBoolean;
+ (*s_allowlist)[::prefs::kHeliumUBlockAssetsEnabled] =
+ settings_api::PrefType::kBoolean;
(*s_allowlist)[::prefs::kHeliumServicesOrigin] =
settings_api::PrefType::kString;
(*s_allowlist)[::prefs::kHeliumServicesConsented] =
--- a/chrome/browser/ui/browser_ui_prefs.cc
+++ b/chrome/browser/ui/browser_ui_prefs.cc
@@ -218,6 +218,7 @@ void RegisterBrowserUserPrefs(user_prefs
registry->RegisterBooleanPref(prefs::kHeliumDidOnboarding, false);
registry->RegisterBooleanPref(prefs::kHeliumServicesConsented, false);
registry->RegisterBooleanPref(prefs::kHeliumUpdateFetchingEnabled, true);
+ registry->RegisterBooleanPref(prefs::kHeliumUBlockAssetsEnabled, true);
}
registry->RegisterBooleanPref(
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -33,6 +33,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/syslog_logging.h"
#include "base/task/single_thread_task_runner.h"
+#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
@@ -72,6 +73,9 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/crx_file/id_util.h"
+#include "components/helium_services/extension_ids.h"
+#include "components/helium_services/helium_services_helpers.h"
+#include "components/helium_services/pref_names.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/supervised_user/core/browser/supervised_user_preferences.h"
#include "content/public/browser/browser_thread.h"
@@ -206,6 +210,7 @@ ExtensionService::ExtensionService(
ready_(ready),
updater_(ExtensionUpdater::Get(profile)),
component_loader_(ComponentLoader::Get(profile_)),
+ can_access_ublock_assets_(helium::ShouldAccessUBlockAssets(*profile_->GetPrefs())),
error_controller_(error_controller),
external_install_manager_(ExternalInstallManager::Get(profile)),
extension_registrar_delegate_(
@@ -279,6 +284,33 @@ ExtensionService::ExtensionService(
prefs::kExtensionsUIDeveloperMode,
base::BindRepeating(&ExtensionService::OnDeveloperModePrefChanged,
base::Unretained(this)));
+ helium::ConfigurePrefChangeRegistrarFor(
+ prefs::kHeliumUBlockAssetsEnabled,
+ pref_change_registrar_,
+ base::BindRepeating(&ExtensionService::ToggleUBlockExtension,
+ base::Unretained(this)));
+}
+
+void ExtensionService::ToggleUBlockExtension() {
+ if (!extension_registrar_) {
+ return;
+ }
+
+ bool has_permission_now = helium::ShouldAccessUBlockAssets(*profile_->GetPrefs());
+ if (can_access_ublock_assets_ == has_permission_now) {
+ return;
+ }
+
+ can_access_ublock_assets_ = has_permission_now;
+
+ for (int seconds : {0, 5}) {
+ content::GetUIThreadTaskRunner({base::TaskPriority::BEST_EFFORT})->PostDelayedTask(
+ FROM_HERE,
+ base::BindOnce(&ExtensionRegistrar::ReloadExtension,
+ extension_registrar_->GetWeakPtr(),
+ helium::kUBlockOriginComponentId),
+ base::Seconds(seconds));
+ }
}
base::WeakPtr<ExtensionServiceInterface> ExtensionService::AsWeakPtr() {
--- a/chrome/browser/extensions/extension_service.h
+++ b/chrome/browser/extensions/extension_service.h
@@ -165,6 +165,8 @@ class ExtensionService : public Extensio
// KeyedService two-phase shutdown.
void Shutdown();
+ void ToggleUBlockExtension();
+
// Performs action based on verdicts received from the Extension Telemetry
// server. Currently, these verdicts are limited to off-store extensions.
void PerformActionBasedOnExtensionTelemetryServiceVerdicts(
@@ -355,6 +357,8 @@ class ExtensionService : public Extensio
// Used in test to ensure the service's shutdown method has been called.
bool is_shut_down_executed_ = false;
+ bool can_access_ublock_assets_;
+
// The controller for the UI that alerts the user about any blocklisted
// extensions. Not owned.
raw_ptr<ExtensionErrorController> error_controller_ = nullptr;
--- a/extensions/browser/api/storage/BUILD.gn
+++ b/extensions/browser/api/storage/BUILD.gn
@@ -60,6 +60,7 @@ source_set("storage") {
":settings_namespace",
":settings_observer",
"//base",
+ "//components/helium_services",
"//components/keyed_service/content",
"//components/value_store",
"//content/public/browser",
--- a/extensions/browser/api/storage/storage_frontend.cc
+++ b/extensions/browser/api/storage/storage_frontend.cc
@@ -25,6 +25,8 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/helium_services/helium_services_helpers.h"
#include "components/value_store/value_store_factory.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
@@ -222,6 +224,24 @@ void StorageFrontend::OnReadFinished(
if (success) {
get_result.data = result.PassSettings();
+
+ Profile* profile_ = Profile::FromBrowserContext(browser_context_);
+
+ if (Manifest::IsUBlockComponent(extension_id)
+ && storage_area == StorageAreaNamespace::kManaged
+ && helium::ShouldAccessUBlockAssets(*profile_->GetPrefs())) {
+
+ if (!get_result.data->FindDict("adminSettings")) {
+ get_result.data->Set("adminSettings", base::Value::Dict());
+ }
+
+ base::Value::Dict* adminSettings = get_result.data->FindDict("adminSettings");
+
+ if (!adminSettings->Find("assetsBootstrapLocation")) {
+ adminSettings->Set("assetsBootstrapLocation",
+ base::Value(helium::GetUBlockAssetsURL(*profile_->GetPrefs()).spec()));
+ }
+ }
}
std::move(callback).Run(std::move(get_result));
--- a/third_party/ublock/js/assets.js
+++ b/third_party/ublock/js/assets.js
@@ -525,7 +525,7 @@ let assetSourceRegistry = Object.create(
function getAssetSourceRegistry() {
if ( assetSourceRegistryPromise === undefined ) {
assetSourceRegistryPromise = cacheStorage.get(
- 'assetSourceRegistry'
+ 'assetSourceRegistry' + (µb.assetsBootstrapLocation ?? '')
).then(bin => {
if ( bin instanceof Object ) {
if ( bin.assetSourceRegistry instanceof Object ) {
--- a/chrome/app/settings_strings.grdp
+++ b/chrome/app/settings_strings.grdp
@@ -2002,6 +2002,12 @@
<message name="IDS_SETTINGS_HELIUM_SERVICES_UPDATE_DESCRIPTION" desc="Description of the toggle for automatic update downloads">
Helium will automatically download and install browser updates as they become available. We recommend keeping this setting enabled to ensure you get the latest security patches and features.
</message>
+ <message name="IDS_SETTINGS_HELIUM_SERVICES_UBO" desc="Description of the toggle for uBO filter lists">
+ Allow downloading filter lists for uBlock Origin
+ </message>
+ <message name="IDS_SETTINGS_HELIUM_SERVICES_UBO_DESCRIPTION" desc="Description of the toggle for automatic update downloads">
+ Helium will fetch fresh filter lists for uBlock Origin. All requests to lists are proxied to protect your privacy. When disabled, default filter lists will be loaded from local storage, which are only updated along with Helium. Optional filter lists will be requested without proxying.
+ </message>
<message name="IDS_SETTINGS_HELIUM_SERVICES_OVERRIDE" desc="Text input for overriding the Helium services server">
Use your own instance of Helium services
</message>
--- a/chrome/browser/resources/settings/privacy_page/services_page.html
+++ b/chrome/browser/resources/settings/privacy_page/services_page.html
@@ -69,6 +69,11 @@
sub-label="$i18n{heliumUpdatesToggleDescription}">
</settings-toggle-button>
</if>
+ <settings-toggle-button id="filterlistToggleButton"
+ pref="{{prefs.helium.services.ublock_assets}}"
+ label="$i18n{heliumUboToggle}"
+ sub-label="$i18n{heliumUboToggleDescription}">
+ </settings-toggle-button>
</cr-collapse>
</div>
</template>
--- a/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
+++ b/chrome/browser/ui/webui/settings/settings_localized_strings_provider.cc
@@ -2139,6 +2139,10 @@ void AddPrivacyStrings(content::WebUIDat
IDS_SETTINGS_HELIUM_SERVICES_UPDATE},
{"heliumUpdatesToggleDescription",
IDS_SETTINGS_HELIUM_SERVICES_UPDATE_DESCRIPTION},
+ {"heliumUboToggle",
+ IDS_SETTINGS_HELIUM_SERVICES_UBO},
+ {"heliumUboToggleDescription",
+ IDS_SETTINGS_HELIUM_SERVICES_UBO_DESCRIPTION},
{"heliumOriginOverride", IDS_SETTINGS_HELIUM_SERVICES_OVERRIDE},
{"heliumOriginOverrideDescription",
IDS_SETTINGS_HELIUM_SERVICES_OVERRIDE_DESCRIPTION},