Skip to content

Commit

Permalink
Get context from frame_tree_node_id in AdblockCnameResolveHostClient
Browse files Browse the repository at this point in the history
The ResponseCallback can outlive the BraveRequestInfo context and thus
we can't trust it to retrieve the default storage partition. Instead,
let's go back to the original code where we would attempt to retrieve
the WebContents from the frame_tree_node_id, early returning if that
was not possible.

Resolves brave/brave-browser#16062
  • Loading branch information
mariospr committed May 25, 2021
1 parent a4d0529 commit bbc26cd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion browser/net/brave_ad_block_tp_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ class AdblockCnameResolveHostClient : public network::mojom::ResolveHostClient {
if (secure_dns_config.mode() == net::SecureDnsMode::kSecure)
optional_parameters->source = net::HostResolverSource::DNS;

auto* web_contents =
content::WebContents::FromFrameTreeNodeId(ctx->frame_tree_node_id);
if (!web_contents) {
start_time_ = base::TimeTicks::Now();
this->OnComplete(net::ERR_FAILED, net::ResolveErrorInfo(), base::nullopt);
return;
}

network::mojom::NetworkContext* network_context =
content::BrowserContext::GetDefaultStoragePartition(
ctx->browser_context)
web_contents->GetBrowserContext())
->GetNetworkContext();

start_time_ = base::TimeTicks::Now();
Expand Down

0 comments on commit bbc26cd

Please sign in to comment.