Skip to content

Commit

Permalink
Merge pull request #8416 from brave/pr8402_no-more-blocked-by-extensi…
Browse files Browse the repository at this point in the history
…on_1.23.x

Don't check main frame requests through shields network delegate helper (uplift to 1.23.x)
  • Loading branch information
kjozwiak authored Apr 6, 2021
2 parents 0afaed2 + 751d14e commit 4f2694b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
32 changes: 32 additions & 0 deletions browser/brave_shields/domain_block_page_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DomainBlockTestBase : public AdBlockServiceTest {
[&](const net::test_server::HttpRequest& request) {
request_count_ += 1;
}));
content::SetupCrossSiteRedirector(embedded_test_server());
AdBlockServiceTest::SetUp();
}

Expand Down Expand Up @@ -299,6 +300,37 @@ IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoFetch) {
ASSERT_EQ(0, request_count_);
}

IN_PROC_BROWSER_TEST_F(DomainBlockTest, NoThirdPartyInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
ASSERT_TRUE(g_brave_browser_process->ad_block_custom_filters_service()
->UpdateCustomFilters("||b.com^$third-party"));

GURL url = embedded_test_server()->GetURL("a.com", "/simple_link.html");
GURL cross_url =
embedded_test_server()->GetURL("a.com", "/cross-site/b.com/simple.html");

// Navigate to a page on a.com. This should work normally.
NavigateTo(url);
ASSERT_FALSE(IsShowingInterstitial());

// Navigate to a page on the third-party b.com. There should be no
// interstitial shown.
EXPECT_EQ(true,
EvalJs(web_contents(), "clickLink('" + cross_url.spec() + "')"));
EXPECT_TRUE(WaitForLoadStop(web_contents()));

// No interstitial should be shown, since top-level requests are never
// third-party.
ASSERT_FALSE(IsShowingInterstitial());

// The default "blocked by an extension" interstitial also should not be
// shown. This would appear if the request was blocked by the network delegate
// helper.
const std::string location =
EvalJs(web_contents(), "window.location.href").ExtractString();
ASSERT_STRNE("chrome-error://chromewebdata/", location.c_str());
}

IN_PROC_BROWSER_TEST_F(DomainBlockDisabledTest, NoInterstitial) {
ASSERT_TRUE(InstallDefaultAdBlockExtension());
GURL url = embedded_test_server()->GetURL("a.com", "/simple.html");
Expand Down
7 changes: 7 additions & 0 deletions browser/net/brave_ad_block_tp_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ int OnBeforeURLRequest_AdBlockTPPreWork(const ResponseCallback& next_callback,
return net::OK;
}

// Requests for main frames are handled by DomainBlockNavigationThrottle,
// which can display a custom interstitial with an option to proceed if a
// block is made. We don't need to check these twice.
if (ctx->resource_type == blink::mojom::ResourceType::kMainFrame) {
return net::OK;
}

OnBeforeURLRequestAdBlockTP(next_callback, ctx);

return net::ERR_IO_PENDING;
Expand Down

0 comments on commit 4f2694b

Please sign in to comment.