Skip to content

Commit 485eaa8

Browse files
committed
review fixes
1 parent 32d62d4 commit 485eaa8

File tree

6 files changed

+44
-68
lines changed

6 files changed

+44
-68
lines changed

chromium_src/net/base/lookup_string_in_fixed_set.cc

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ int LookupSuffixInReversedSet(const unsigned char* graph,
5353
*suffix_length = strlen(decentralized_dns::kEthDomain) - 1;
5454
return kDafsaFound;
5555
}
56+
if (base::EndsWith(host, decentralized_dns::kDNSForEthDomain)) {
57+
*suffix_length = strlen(decentralized_dns::kDNSForEthDomain) - 1;
58+
return kDafsaFound;
59+
}
5660

5761
return LookupSuffixInReversedSet_ChromiumImpl(graph, length, include_private,
5862
host, suffix_length);

components/brave_rewards/browser/rewards_service_impl.cc

+21-18
Original file line numberDiff line numberDiff line change
@@ -651,18 +651,25 @@ void RewardsServiceImpl::OnLoad(SessionID tab_id, const GURL& url) {
651651
return;
652652
}
653653

654-
auto origin = url.GetOrigin();
655-
const std::string baseDomain =
656-
GetDomainAndRegistry(origin.host(), INCLUDE_PRIVATE_REGISTRIES);
657-
654+
auto origin = url.GetOrigin().host();
655+
std::string baseDomain =
656+
GetDomainAndRegistry(url.host(), INCLUDE_PRIVATE_REGISTRIES);
657+
#if BUILDFLAG(IPFS_ENABLED)
658+
if (baseDomain.empty()) {
659+
baseDomain = ipfs::GetRegistryDomainFromIPNS(url);
660+
if (!baseDomain.empty()) {
661+
origin = baseDomain;
662+
}
663+
}
664+
#endif
658665
if (baseDomain == "")
659666
return;
660667

661-
const std::string publisher_url = origin.scheme() + "://" + baseDomain + "/";
668+
const std::string publisher_url = url.scheme() + "://" + baseDomain + "/";
662669

663670
ledger::type::VisitDataPtr data = ledger::type::VisitData::New();
664671
data->tld = data->name = baseDomain;
665-
data->domain = origin.host(),
672+
data->domain = origin;
666673
data->path = url.path();
667674
data->tab_id = tab_id.id();
668675
data->url = publisher_url;
@@ -1767,20 +1774,16 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl(
17671774
return;
17681775
}
17691776

1770-
auto origin = parsed_url.GetOrigin();
1777+
auto origin = parsed_url.GetOrigin().spec();
17711778
std::string baseDomain =
1772-
GetDomainAndRegistry(origin.host(), INCLUDE_PRIVATE_REGISTRIES);
1779+
GetDomainAndRegistry(parsed_url.host(), INCLUDE_PRIVATE_REGISTRIES);
17731780
std::string path = parsed_url.PathForRequest();
17741781
#if BUILDFLAG(IPFS_ENABLED)
1775-
if (parsed_url.SchemeIs(ipfs::kIPNSScheme)) {
1776-
std::string cid;
1777-
if (!ipfs::GetRegistryDomainFromIPNS(parsed_url, &cid, &path))
1778-
return;
1779-
origin = GURL(parsed_url.scheme() + "://" + cid);
1780-
baseDomain = cid;
1781-
} else if (parsed_url.SchemeIs(ipfs::kIPFSScheme)) {
1782-
OnPanelPublisherInfo(ledger::type::Result::NOT_FOUND, nullptr, windowId);
1783-
return;
1782+
if (baseDomain.empty()) {
1783+
baseDomain = ipfs::GetRegistryDomainFromIPNS(parsed_url);
1784+
if (!baseDomain.empty()) {
1785+
origin = parsed_url.scheme() + "://" + baseDomain + "/";
1786+
}
17841787
}
17851788
#endif
17861789
if (baseDomain == "") {
@@ -1799,7 +1802,7 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl(
17991802
ledger::type::VisitDataPtr visit_data = ledger::type::VisitData::New();
18001803
visit_data->domain = visit_data->name = baseDomain;
18011804
visit_data->path = path;
1802-
visit_data->url = origin.spec();
1805+
visit_data->url = origin;
18031806
visit_data->favicon_url = favicon_url;
18041807

18051808
bat_ledger_->GetPublisherActivityFromUrl(

components/ipfs/ipfs_utils.cc

+5-15
Original file line numberDiff line numberDiff line change
@@ -389,25 +389,15 @@ GURL ContentHashToCIDv1URL(const std::string& contenthash) {
389389
return GURL(scheme + "://" + cidv1);
390390
}
391391

392-
bool GetRegistryDomainFromIPNS(const GURL& url,
393-
std::string* domain,
394-
std::string* path) {
392+
std::string GetRegistryDomainFromIPNS(const GURL& url) {
395393
if (!url.SchemeIs(ipfs::kIPNSScheme))
396-
return false;
397-
DCHECK(domain);
398-
DCHECK(path);
394+
return std::string();
399395
std::string cid;
400396
std::string ipfs_path;
401397
if (!ipfs::ParseCIDAndPathFromIPFSUrl(url, &cid, &ipfs_path) || cid.empty())
402-
return false;
403-
if (GetDomainAndRegistry(
404-
cid, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)
405-
.empty()) {
406-
return false;
407-
}
408-
*domain = cid;
409-
*path = ipfs_path;
410-
return !domain->empty();
398+
return std::string();
399+
return GetDomainAndRegistry(
400+
cid, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
411401
}
412402

413403
} // namespace ipfs

components/ipfs/ipfs_utils.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ bool ParsePeerConnectionString(const std::string& value,
6161
GURL ContentHashToCIDv1URL(const std::string& contenthash);
6262
bool IsAPIGateway(const GURL& url, version_info::Channel channel);
6363
bool IsIpfsResolveMethodDisabled(PrefService* prefs);
64-
bool GetRegistryDomainFromIPNS(const GURL& url,
65-
std::string* domain,
66-
std::string* path);
64+
std::string GetRegistryDomainFromIPNS(const GURL& url);
6765
} // namespace ipfs
6866

6967
#endif // BRAVE_COMPONENTS_IPFS_IPFS_UTILS_H_

components/ipfs/ipfs_utils_unittest.cc

+12-32
Original file line numberDiff line numberDiff line change
@@ -659,36 +659,16 @@ TEST_F(IpfsUtilsUnitTest, IsAPIGatewayTest) {
659659
}
660660

661661
TEST_F(IpfsUtilsUnitTest, IPNSRegistryDomain) {
662-
std::string cid;
663-
std::string path;
664-
ASSERT_FALSE(
665-
ipfs::GetRegistryDomainFromIPNS(GURL("ipfs://bafy"), &cid, &path));
666-
EXPECT_TRUE(cid.empty());
667-
EXPECT_TRUE(path.empty());
668-
669-
ASSERT_FALSE(
670-
ipfs::GetRegistryDomainFromIPNS(GURL("ipfs://QmfdSDf"), &cid, &path));
671-
EXPECT_TRUE(cid.empty());
672-
EXPECT_TRUE(path.empty());
673-
674-
ASSERT_FALSE(
675-
ipfs::GetRegistryDomainFromIPNS(GURL("ipns://QmfdSDf"), &cid, &path));
676-
EXPECT_TRUE(cid.empty());
677-
EXPECT_TRUE(path.empty());
678-
679-
ASSERT_FALSE(
680-
ipfs::GetRegistryDomainFromIPNS(GURL("ipns://bafyff"), &cid, &path));
681-
EXPECT_TRUE(cid.empty());
682-
EXPECT_TRUE(path.empty());
683-
684-
ASSERT_TRUE(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://brantly.eth.link"),
685-
&cid, &path));
686-
EXPECT_EQ(cid, "brantly.eth.link");
687-
EXPECT_TRUE(path.empty());
688-
689-
cid.clear();
690-
ASSERT_TRUE(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://brantly.eth/path"),
691-
&cid, &path));
692-
EXPECT_EQ(cid, "brantly.eth");
693-
EXPECT_EQ(path, "/path");
662+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("http://google.com")), "");
663+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("https://google.com")), "");
664+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipfs://bafy")), "");
665+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipfs://QmfdSDf")), "");
666+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://QmfdSDf/path")), "");
667+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://bafyff/path")), "");
668+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://brantly.eth.link")),
669+
"brantly.eth.link");
670+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://brantly.eth/path")),
671+
"brantly.eth");
672+
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://blah.google.com")),
673+
"google.com");
694674
}

net/decentralized_dns/constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ constexpr char kUnstoppableDomainsDoHResolver[] =
1313
"https://resolver.unstoppable.io/dns-query{?brave_UD}";
1414

1515
constexpr char kEthDomain[] = ".eth";
16+
constexpr char kDNSForEthDomain[] = ".eth.link";
1617
constexpr char kENSDoHResolver[] =
1718
"https://resolver.cloudflare-eth.com/dns-query{?brave_ENS}";
1819

0 commit comments

Comments
 (0)