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

Don't check main frame requests through shields network delegate helper (uplift to 1.23.x) #8416

Merged
merged 1 commit into from
Apr 6, 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
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