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

add flag for first-party blocking in standard blocking mode #9673

Merged
merged 2 commits into from
Aug 16, 2021

Conversation

antonok-edm
Copy link
Collaborator

@antonok-edm antonok-edm commented Aug 5, 2021

Resolves brave/brave-browser#17366

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Disable the new #brave-adblock-default-1p-blocking flag, then visit https://dev-pages.bravesoftware.com/filtering/network-requests.html and follow the directions, ensuring that the images are shown as described.

@antonok-edm antonok-edm requested a review from a team as a code owner August 5, 2021 17:47
@antonok-edm antonok-edm self-assigned this Aug 5, 2021
Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

chromium_src changes ++

@antonok-edm antonok-edm force-pushed the 1p-blocking-flag branch 3 times, most recently from 3729731 to 5c46bda Compare August 9, 2021 18:14
@@ -10,6 +10,10 @@
namespace brave_shields {
namespace features {

// When disabled, Brave will allow first-party requests in "standard" blocking
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rather rephrase it as "When enabled ..." :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the "disabled" state is less obvious behavior to those unfamiliar with adblocking - I added a description for both.

@iefremov
Copy link
Contributor

we need tests for this change

@@ -76,6 +76,7 @@ struct BraveRequestInfo {
// TODO(iefremov): rename to shields_up.
bool allow_brave_shields = true;
bool allow_ads = false;
bool aggressive_blocking = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

we need a comment for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@@ -138,6 +138,9 @@ std::shared_ptr<brave::BraveRequestInfo> BraveRequestInfo::MakeCTX(
brave_shields::GetBraveShieldsEnabled(map, ctx->tab_origin);
ctx->allow_ads = brave_shields::GetAdControlType(map, ctx->tab_origin) ==
brave_shields::ControlType::ALLOW;
ctx->aggressive_blocking =
brave_shields::GetCosmeticFilteringControlType(map, ctx->tab_origin) ==
Copy link
Contributor

Choose a reason for hiding this comment

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

this assignment is not really readable - I had to search through the source to understand that "aggressive" flag is stored as cosmetic filtering content setting, which we reuse here... So definitely needs a comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added as well

@@ -180,7 +180,7 @@ EngineFlags ShouldBlockRequestOnTaskRunner(

SCOPED_UMA_HISTOGRAM_TIMER("Brave.Adblock.ShouldBlockRequest");
g_brave_browser_process->ad_block_service()->ShouldStartRequest(
url_to_check, ctx->resource_type, source_host,
url_to_check, ctx->resource_type, source_host, ctx->aggressive_blocking,
Copy link
Contributor

Choose a reason for hiding this comment

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

I gather that at some point we can craft a struct with needed parameters, to avoid changing all of the signatures

brave_shields::features::kBraveAdblockDefault1pBlocking) ||
!SameDomainOrHost(
url,
url::Origin::CreateFromNormalizedTuple("https", tab_host.c_str(), 80),
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for c_str()

Copy link
Contributor

Choose a reason for hiding this comment

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

what are our expectations if tab_host is empty? AFAIR this is the SW case?

Copy link
Contributor

Choose a reason for hiding this comment

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

also, just curious whether we want to skip the check for all of the subresource types? Or maybe just scripts/whatever else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed c_str()

this is the same logic that's passed to the adblock engine already. It should be possible to refactor it to only happen in a single place later, but at the moment it's not trivial.

I'll leave @pes10k to comment on the resource types we want to apply this to.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this change is outdated, so apologies if this is talking into the void, but i dont see any reason to not apply to all requests. The "what does shields block in what configurations" logic is already complicated as it is. I dont think we should make the decision tree more complicated unless there is a compelling reason

@@ -66,27 +66,36 @@ void AdBlockService::ShouldStartRequest(
const GURL& url,
blink::mojom::ResourceType resource_type,
const std::string& tab_host,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we could pass Origin here...

@@ -66,27 +66,36 @@ void AdBlockService::ShouldStartRequest(
const GURL& url,
blink::mojom::ResourceType resource_type,
const std::string& tab_host,
bool aggressive_blocking,
Copy link
Contributor

Choose a reason for hiding this comment

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

@bridiver we have to refactor this hierarchy so that the facade method doesn't share its signature with general adblock / regional ablock / etc.

Here we add a parameter to the facade method, and that parameter is useless for all other methods

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree a lot of refactoring is needed in general. Several PRs are in the works

@iefremov
Copy link
Contributor

generally looks good, but we need some tests, since this code is a critical part of the browser

@pes10k
Copy link
Contributor

pes10k commented Aug 13, 2021

FWIW, i added a QA test too: https://dev-pages.brave.software/filtering/network-requests.html

Copy link
Contributor

@iefremov iefremov left a comment

Choose a reason for hiding this comment

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

Unblocking the merge since this looks urgent. Minors and tests can be a f/u

@antonok-edm antonok-edm merged commit a9f8e12 into master Aug 16, 2021
@antonok-edm antonok-edm deleted the 1p-blocking-flag branch August 16, 2021 03:22
@antonok-edm antonok-edm added this to the 1.30.x - Nightly milestone Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default (standard) network blocking policy to always allow 1p requests
6 participants