Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cosmetic filtering extension version #9995

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
using brave_shields::features::kBraveAdblockCnameUncloaking;
using brave_shields::features::kBraveAdblockCollapseBlockedElements;
using brave_shields::features::kBraveAdblockCosmeticFiltering;
using brave_shields::features::kBraveAdblockCosmeticFilteringNative;
using brave_shields::features::kBraveAdblockCspRules;
using brave_shields::features::kBraveAdblockDefault1pBlocking;
using brave_shields::features::kBraveDarkModeBlock;
Expand Down Expand Up @@ -81,11 +80,6 @@ constexpr char kBraveAdblockCosmeticFilteringName[] =
constexpr char kBraveAdblockCosmeticFilteringDescription[] =
"Enable support for cosmetic filtering";

constexpr char kBraveAdblockCosmeticFilteringNativeName[] =
"Use native implementation for cosmetic filtering";
constexpr char kBraveAdblockCosmeticFilteringNativeDescription[] =
"Uses native implementation for cosmetic filtering instead of extension";

constexpr char kBraveAdblockCspRulesName[] = "Enable support for CSP rules";
constexpr char kBraveAdblockCspRulesDescription[] =
"Applies additional CSP rules to pages for which a $csp rule has been "
Expand Down Expand Up @@ -323,11 +317,6 @@ constexpr char kUseDevUpdaterUrlDescription[] =
flag_descriptions::kBraveAdblockCosmeticFilteringName, \
flag_descriptions::kBraveAdblockCosmeticFilteringDescription, kOsAll, \
FEATURE_VALUE_TYPE(kBraveAdblockCosmeticFiltering)}, \
{"brave-adblock-cosmetic-filtering-native", \
flag_descriptions::kBraveAdblockCosmeticFilteringNativeName, \
flag_descriptions::kBraveAdblockCosmeticFilteringNativeDescription, \
kOsMac | kOsWin | kOsLinux, \
FEATURE_VALUE_TYPE(kBraveAdblockCosmeticFilteringNative)}, \
{"brave-adblock-csp-rules", \
flag_descriptions::kBraveAdblockCspRulesName, \
flag_descriptions::kBraveAdblockCspRulesDescription, kOsAll, \
Expand Down
112 changes: 0 additions & 112 deletions browser/extensions/api/brave_shields_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <utility>

#include "base/feature_list.h"
#include "base/strings/string_number_conversions.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/browser/brave_shields/brave_shields_web_contents_observer.h"
Expand All @@ -20,7 +19,6 @@
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/brave_shields/browser/brave_shields_util.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "brave/components/brave_shields/common/features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h"
Expand All @@ -47,90 +45,6 @@ const char kInvalidControlTypeError[] = "Invalid ControlType.";

} // namespace

ExtensionFunction::ResponseAction
BraveShieldsUrlCosmeticResourcesFunction::Run() {
std::unique_ptr<brave_shields::UrlCosmeticResources::Params> params(
brave_shields::UrlCosmeticResources::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
g_brave_browser_process->ad_block_service()
->GetTaskRunner()
->PostTaskAndReplyWithResult(
FROM_HERE,
base::BindOnce(&BraveShieldsUrlCosmeticResourcesFunction::
GetUrlCosmeticResourcesOnTaskRunner,
this, params->url),
base::BindOnce(&BraveShieldsUrlCosmeticResourcesFunction::
GetUrlCosmeticResourcesOnUI,
this));
return RespondLater();
}

std::unique_ptr<base::ListValue>
BraveShieldsUrlCosmeticResourcesFunction::GetUrlCosmeticResourcesOnTaskRunner(
const std::string& url) {
absl::optional<base::Value> resources =
g_brave_browser_process->ad_block_service()->UrlCosmeticResources(url);

if (!resources || !resources->is_dict()) {
return std::unique_ptr<base::ListValue>();
}

auto result_list = std::make_unique<base::ListValue>();
result_list->Append(std::move(*resources));
return result_list;
}

void BraveShieldsUrlCosmeticResourcesFunction::GetUrlCosmeticResourcesOnUI(
std::unique_ptr<base::ListValue> resources) {
if (!resources) {
Respond(Error("Url-specific cosmetic resources could not be returned"));
return;
}
Respond(ArgumentList(std::move(resources)));
}

ExtensionFunction::ResponseAction
BraveShieldsHiddenClassIdSelectorsFunction::Run() {
std::unique_ptr<brave_shields::HiddenClassIdSelectors::Params> params(
brave_shields::HiddenClassIdSelectors::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
g_brave_browser_process->ad_block_service()
->GetTaskRunner()
->PostTaskAndReplyWithResult(
FROM_HERE,
base::BindOnce(&BraveShieldsHiddenClassIdSelectorsFunction::
GetHiddenClassIdSelectorsOnTaskRunner,
this, params->classes, params->ids,
params->exceptions),
base::BindOnce(&BraveShieldsHiddenClassIdSelectorsFunction::
GetHiddenClassIdSelectorsOnUI,
this));
return RespondLater();
}

std::unique_ptr<base::ListValue> BraveShieldsHiddenClassIdSelectorsFunction::
GetHiddenClassIdSelectorsOnTaskRunner(
const std::vector<std::string>& classes,
const std::vector<std::string>& ids,
const std::vector<std::string>& exceptions) {
absl::optional<base::Value> hide_selectors =
g_brave_browser_process->ad_block_service()->HiddenClassIdSelectors(
classes, ids, exceptions);

if (!hide_selectors || !hide_selectors->is_list())
return std::make_unique<base::ListValue>();

auto result_list =
std::make_unique<base::ListValue>(hide_selectors->GetList());

return result_list;
}

void BraveShieldsHiddenClassIdSelectorsFunction::GetHiddenClassIdSelectorsOnUI(
std::unique_ptr<base::ListValue> selectors) {
Respond(ArgumentList(std::move(selectors)));
}

ExtensionFunction::ResponseAction
BraveShieldsAddSiteCosmeticFilterFunction::Run() {
std::unique_ptr<brave_shields::AddSiteCosmeticFilter::Params> params(
Expand Down Expand Up @@ -238,32 +152,6 @@ BraveShieldsGetBraveShieldsEnabledFunction::Run() {
return RespondNow(OneArgument(base::Value(enabled)));
}

ExtensionFunction::ResponseAction
BraveShieldsShouldDoCosmeticFilteringFunction::Run() {
#if !defined(OS_ANDROID) && !defined(CHROME_OS)
if (base::FeatureList::IsEnabled(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls double-check unused headers, e.g. #include "base/feature_list.h" or #include "brave/components/brave_shields/common/features.h", maybe anything else

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include "brave/browser/brave_browser_process.h"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still have e.g.

  auto* custom_filters_service =
      g_brave_browser_process->ad_block_custom_filters_service();

so I can't remove brave_browser_process.h, but I removed the others

::brave_shields::features::kBraveAdblockCosmeticFilteringNative))
return RespondNow(OneArgument(base::Value(false)));
#endif
std::unique_ptr<brave_shields::ShouldDoCosmeticFiltering::Params>
params(
brave_shields::ShouldDoCosmeticFiltering::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());

const GURL url(params->url);
// we don't allow getting defaults from the extension
if (url.is_empty() || !url.is_valid()) {
return RespondNow(Error(kInvalidUrlError, params->url));
}

Profile* profile = Profile::FromBrowserContext(browser_context());
const bool enabled = ::brave_shields::ShouldDoCosmeticFiltering(
HostContentSettingsMapFactory::GetForProfile(profile),
url);

return RespondNow(OneArgument(base::Value(enabled)));
}

ExtensionFunction::ResponseAction
BraveShieldsSetCosmeticFilteringControlTypeFunction::Run() {
std::unique_ptr<brave_shields::SetCosmeticFilteringControlType::Params>
Expand Down
44 changes: 0 additions & 44 deletions browser/extensions/api/brave_shields_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,12 @@

#include <memory>
#include <string>
#include <vector>

#include "extensions/browser/extension_function.h"

namespace extensions {
namespace api {

class BraveShieldsUrlCosmeticResourcesFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.urlCosmeticResources", UNKNOWN)

protected:
~BraveShieldsUrlCosmeticResourcesFunction() override {}

ResponseAction Run() override;

private:
std::unique_ptr<base::ListValue> GetUrlCosmeticResourcesOnTaskRunner(
const std::string& url);
void GetUrlCosmeticResourcesOnUI(std::unique_ptr<base::ListValue> resources);
};

class BraveShieldsHiddenClassIdSelectorsFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.hiddenClassIdSelectors", UNKNOWN)

protected:
~BraveShieldsHiddenClassIdSelectorsFunction() override {}

ResponseAction Run() override;

private:
std::unique_ptr<base::ListValue> GetHiddenClassIdSelectorsOnTaskRunner(
const std::vector<std::string>& classes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector is no longer used

const std::vector<std::string>& ids,
const std::vector<std::string>& exceptions);
void GetHiddenClassIdSelectorsOnUI(
std::unique_ptr<base::ListValue> selectors);
};

class BraveShieldsAddSiteCosmeticFilterFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.addSiteCosmeticFilter", UNKNOWN)
Expand Down Expand Up @@ -109,16 +75,6 @@ class BraveShieldsGetBraveShieldsEnabledFunction : public ExtensionFunction {
ResponseAction Run() override;
};

class BraveShieldsShouldDoCosmeticFilteringFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("braveShields.shouldDoCosmeticFiltering", UNKNOWN)

protected:
~BraveShieldsShouldDoCosmeticFilteringFunction() override {}

ResponseAction Run() override;
};

class BraveShieldsSetCosmeticFilteringControlTypeFunction :
public ExtensionFunction {
public:
Expand Down
88 changes: 0 additions & 88 deletions common/extensions/api/brave_shields.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,73 +73,6 @@
"description": "Notifies the browser about the fact of showing the panel",
"parameters": []
},
{
"name": "urlCosmeticResources",
"type": "function",
"description": "Get a cosmetic adblocking stylesheet, generic style exceptions, script injections, and whether or not a generichide rule was present, all specific for the given URL",
"parameters": [
{
"name": "url",
"type": "string"
},
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "urlSpecificResources",
"type": "object",
"properties": {
"hide_selectors": {"type": "array", "items": {"type": "string"}, "description": "URL-specific CSS selectors that should be hidden from the page if they are determined to not include 1st party content"},
"style_selectors": {"type": "object", "additionalProperties": {"type": "array", "items": {"type": "string"}}, "description": "URL-specific CSS selectors that should be restyled, with their associated CSS style rules"},
"exceptions": {"type": "array", "items": {"type": "string"}, "description": "URL-specific overrides for generic cosmetic blocking selectors"},
"injected_script": {"type": "string", "description": "A script to inject as the page is loading"},
"force_hide_selectors": {"type": "array", "items": {"type": "string"}, "description": "URL-specific CSS selectors that should be hidden from the page"},
"generichide": {"type": "boolean", "description": "Indicates whether or not the URL matched a generichide exception rule"}
}
}
]
}
]
},
{
"name": "hiddenClassIdSelectors",
"type": "function",
"description": "Get a stylesheet of generic rules that may apply to the given set of classes and ids without any of the given excepted selectors",
"parameters": [
{
"name": "classes",
"type": "array",
"items": {"type": "string"}
},
{
"name": "ids",
"type": "array",
"items": {"type": "string"}
},
{
"name": "exceptions",
"type": "array",
"items": {"type": "string"}
},
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "selectors",
"type": "array",
"items": {"type": "string"}
},
{
"name": "forceHideSelectors",
"type": "array",
"items": {"type": "string"}
}
]
}
]
},
{
"name": "addSiteCosmeticFilter",
"type": "function",
Expand Down Expand Up @@ -184,27 +117,6 @@
}
]
},
{
"name": "shouldDoCosmeticFiltering",
"type": "function",
"description": "Determine whether or not to do cosmetic filtering on the given url",
"parameters": [
{
"name": "url",
"type": "string"
},
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "doCosmeticFiltering",
"type": "boolean"
}
]
}
]
},
{
"name": "setCosmeticFilteringControlType",
"type": "function",
Expand Down
4 changes: 0 additions & 4 deletions components/brave_extension/extension/brave_extension/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ transpile_web_ui("brave_extension") {
"content_dapps",
rebase_path("content_dapps.ts"),
],
[
"content_cosmetic",
rebase_path("content_cosmetic.ts"),
],
[
"content_element_picker",
rebase_path("content_element_picker.ts"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,32 +137,3 @@ export const shieldsReady: actions.ShieldsReady = () => {
type: types.SHIELDS_READY
}
}

export const generateClassIdStylesheet = (tabId: number, classes: string[], ids: string[]) => {
return {
type: types.GENERATE_CLASS_ID_STYLESHEET,
tabId,
classes,
ids
}
}

export const cosmeticFilterRuleExceptions: actions.CosmeticFilterRuleExceptions = (tabId: number, frameId: number, exceptions: string[], scriptlet: string, generichide: boolean) => {
return {
type: types.COSMETIC_FILTER_RULE_EXCEPTIONS,
tabId,
frameId,
exceptions,
scriptlet,
generichide
}
}

export const contentScriptsLoaded: actions.ContentScriptsLoaded = (tabId: number, frameId: number, url: string) => {
return {
type: types.CONTENT_SCRIPTS_LOADED,
tabId,
frameId,
url
}
}
Loading