remove legacy cosmetic filter migration code

This commit is contained in:
Anton Lazarev
2021-07-09 14:18:17 -07:00
parent 5db2287850
commit 910899c960
7 changed files with 0 additions and 117 deletions
@@ -131,22 +131,6 @@ void BraveShieldsHiddenClassIdSelectorsFunction::GetHiddenClassIdSelectorsOnUI(
Respond(ArgumentList(std::move(selectors)));
}
ExtensionFunction::ResponseAction
BraveShieldsMigrateLegacyCosmeticFiltersFunction::Run() {
std::unique_ptr<brave_shields::MigrateLegacyCosmeticFilters::Params> params(
brave_shields::MigrateLegacyCosmeticFilters::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
const bool success =
g_brave_browser_process->ad_block_custom_filters_service()
->MigrateLegacyCosmeticFilters(
params->legacy_filters.additional_properties);
auto callback_args = std::make_unique<base::ListValue>();
callback_args->Append(base::Value(success));
return RespondNow(ArgumentList(std::move(callback_args)));
}
ExtensionFunction::ResponseAction
BraveShieldsAddSiteCosmeticFilterFunction::Run() {
std::unique_ptr<brave_shields::AddSiteCosmeticFilter::Params> params(
@@ -48,18 +48,6 @@ class BraveShieldsHiddenClassIdSelectorsFunction : public ExtensionFunction {
std::unique_ptr<base::ListValue> selectors);
};
class BraveShieldsMigrateLegacyCosmeticFiltersFunction
: public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.migrateLegacyCosmeticFilters",
UNKNOWN)
protected:
~BraveShieldsMigrateLegacyCosmeticFiltersFunction() override {}
ResponseAction Run() override;
};
class BraveShieldsAddSiteCosmeticFilterFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.addSiteCosmeticFilter", UNKNOWN)
-29
View File
@@ -140,35 +140,6 @@
}
]
},
{
"name": "migrateLegacyCosmeticFilters",
"type": "function",
"description": "Appends the provided legacy cosmetic filters to the custom filters of brave://adblock",
"parameters": [
{
"name": "legacyFilters",
"type": "object",
"description": "Mapping from hostnames with stored legacy cosmetic filter rules to the corresponding lists of rules",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"type": "function",
"name": "callback",
"description": "Returns true if the filters were successfully stored, signifying that the old filters should be removed",
"parameters": [
{
"name": "success",
"type": "boolean"
}
]
}
]
},
{
"name": "addSiteCosmeticFilter",
"type": "function",
@@ -71,29 +71,6 @@ export const applyAdblockCosmeticFilters = (tabId: number, frameId: number, url:
})
}
// A very early implementation of cosmetic filtering used extension-local
// storage to store CSS selectors of elements to apply hide rules to on a
// per-site basis.
//
// If any of these legacy cosmetic filters are still present, this function
// will migrate them to share the adblock-rust infrastructure used by the
// custom filters engine from brave://adblock.
const tryMigratingLegacyCosmeticFilters = () => {
chrome.storage.local.get('cosmeticFilterList', (storeData = {}) => {
if (storeData.cosmeticFilterList !== undefined) {
const cosmeticFilterList = storeData.cosmeticFilterList
console.error(JSON.stringify(cosmeticFilterList))
chrome.braveShields.migrateLegacyCosmeticFilters(cosmeticFilterList, (success) => {
if (success) {
chrome.storage.local.remove('cosmeticFilterList')
} else {
console.error('Legacy cosmetic filter migration failed!')
}
})
}
})
}
export const addSiteCosmeticFilter = (host: string, cssSelector: string) => {
chrome.braveShields.addSiteCosmeticFilter(host, cssSelector)
}
@@ -101,7 +78,3 @@ export const addSiteCosmeticFilter = (host: string, cssSelector: string) => {
export const openFilterManagementPage = () => {
chrome.braveShields.openFilterManagementPage()
}
// Attempt to run the legacy filters migration during brave_extension
// initialization.
tryMigratingLegacyCosmeticFilters()
@@ -51,36 +51,6 @@ bool AdBlockCustomFiltersService::UpdateCustomFilters(
return true;
}
bool AdBlockCustomFiltersService::MigrateLegacyCosmeticFilters(
const std::map<std::string, std::vector<std::string>> legacyFilters) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
PrefService* local_state = delegate()->local_state();
if (!local_state)
return false;
std::string filters_update =
local_state->GetString(prefs::kAdBlockCustomFilters);
filters_update +=
"\n\n! Filters migrated from "
"'Right click > Brave > Block element via selector'";
for (const auto& hostEntry : legacyFilters) {
const std::string& host = hostEntry.first;
const std::vector<std::string>& hostSelectors = hostEntry.second;
for (const auto& selector : hostSelectors) {
if (selector.empty()) {
continue;
}
const std::string rule = '\n' + host + "##" + selector;
filters_update += rule;
}
}
return UpdateCustomFilters(filters_update);
}
void AdBlockCustomFiltersService::UpdateCustomFiltersOnFileTaskRunner(
const std::string& custom_filters) {
DCHECK(GetTaskRunner()->RunsTasksInCurrentSequence());
@@ -28,8 +28,6 @@ class AdBlockCustomFiltersService : public AdBlockBaseService {
std::string GetCustomFilters();
bool UpdateCustomFilters(const std::string& custom_filters);
bool MigrateLegacyCosmeticFilters(
const std::map<std::string, std::vector<std::string>> legacyFilters);
protected:
bool Init() override;
-1
View File
@@ -334,7 +334,6 @@ declare namespace chrome.braveShields {
}
const urlCosmeticResources: (url: string, callback: (resources: UrlSpecificResources) => void) => void
const hiddenClassIdSelectors: (classes: string[], ids: string[], exceptions: string[], callback: (selectors: string[], forceHideSelectors: string[]) => void) => void
const migrateLegacyCosmeticFilters: (legacyFilters: any, callback: (success: boolean) => void) => void
const addSiteCosmeticFilter: (origin: string, cssSelector: string) => void
const openFilterManagementPage: () => void