Skip to content

Commit

Permalink
Reset SNS pref to re-opt in with updated interstitial (uplift to 1.62…
Browse files Browse the repository at this point in the history
….x) (#21370)

Uplift of #21353 (squashed) to beta
  • Loading branch information
brave-builds authored Dec 20, 2023
1 parent 5c1e050 commit b93b21d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 17 deletions.
35 changes: 35 additions & 0 deletions browser/decentralized_dns/test/utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,39 @@ TEST_F(UtilsUnitTest, ResolveMethodMigration) {
EXPECT_TRUE(IsENSResolveMethodAsk(local_state()));
}

TEST_F(UtilsUnitTest, SNSResolveMethodMigration) {
// Ask
EXPECT_TRUE(IsSnsResolveMethodAsk(local_state()));
EXPECT_FALSE(local_state()->GetBoolean(kSnsResolveMethodMigrated));

MigrateObsoleteLocalStatePrefs(local_state());

EXPECT_TRUE(IsSnsResolveMethodAsk(local_state()));
EXPECT_TRUE(local_state()->GetBoolean(kSnsResolveMethodMigrated));

// Enabled
local_state()->SetBoolean(kSnsResolveMethodMigrated, false);
local_state()->SetInteger(kSnsResolveMethod,
static_cast<int>(ResolveMethodTypes::ENABLED));
EXPECT_TRUE(IsSnsResolveMethodEnabled(local_state()));
EXPECT_FALSE(local_state()->GetBoolean(kSnsResolveMethodMigrated));

MigrateObsoleteLocalStatePrefs(local_state());

EXPECT_TRUE(IsSnsResolveMethodAsk(local_state()));
EXPECT_TRUE(local_state()->GetBoolean(kSnsResolveMethodMigrated));

// Disabled
local_state()->SetBoolean(kSnsResolveMethodMigrated, false);
local_state()->SetInteger(kSnsResolveMethod,
static_cast<int>(ResolveMethodTypes::DISABLED));
EXPECT_FALSE(local_state()->GetBoolean(kSnsResolveMethodMigrated));

MigrateObsoleteLocalStatePrefs(local_state());

EXPECT_EQ(local_state()->GetInteger(kSnsResolveMethod),
static_cast<int>(ResolveMethodTypes::DISABLED));
EXPECT_TRUE(local_state()->GetBoolean(kSnsResolveMethodMigrated));
}

} // namespace decentralized_dns
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ void DecentralizedDnsOptInPage::PopulateInterstitialStrings(
u"https://consensys.net/terms-of-use/",
u"https://consensys.net/privacy-policy/"};

const std::vector<std::u16string> syndica_links = {
u"https://syndica.io/terms-and-conditions/",
u"https://syndica.io/privacy-policy/"};
const std::u16string sns_wiki_link =
u"https://github.com/brave/brave-browser/wiki/"
u"Resolve-Methods-for-Solana-Name-Service";

if (IsUnstoppableDomainsTLD(request_url_.host_piece())) {
load_time_data.Set("tabTitle", brave_l10n::GetLocalizedResourceUTF16String(
Expand Down Expand Up @@ -106,16 +106,15 @@ void DecentralizedDnsOptInPage::PopulateInterstitialStrings(
base::ReplaceStringPlaceholders(
brave_l10n::GetLocalizedResourceUTF16String(
IDS_SNS_OPT_IN_PRIMARY_PARAGRAPH),
syndica_links, nullptr));
sns_wiki_link, nullptr));
} else {
NOTREACHED();
}

if (IsSnsTLD(request_url_.host_piece())) {
load_time_data.Set(
"primaryButtonText",
brave_l10n::GetLocalizedResourceUTF16String(
IDS_DECENTRALIZED_DNS_OPT_IN_PRIMARY_SYNDICA_BUTTON));
load_time_data.Set("primaryButtonText",
brave_l10n::GetLocalizedResourceUTF16String(
IDS_DECENTRALIZED_DNS_OPT_IN_PRIMARY_SNS_BUTTON));
} else {
load_time_data.Set("primaryButtonText",
brave_l10n::GetLocalizedResourceUTF16String(
Expand Down
4 changes: 4 additions & 0 deletions components/decentralized_dns/core/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ inline constexpr char kEnsOffchainResolveMethod[] =
// Enabled: Resolve domain name using Solana JSON-RPC server.
inline constexpr char kSnsResolveMethod[] = "brave.sns.resolve_method";

// Added 12/2023.
inline constexpr char kSnsResolveMethodMigrated[] =
"brave.sns.resolve_method_migrated";

} // namespace decentralized_dns

#endif // BRAVE_COMPONENTS_DECENTRALIZED_DNS_CORE_PREF_NAMES_H_
26 changes: 20 additions & 6 deletions components/decentralized_dns/core/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,39 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
static_cast<int>(EnsOffchainResolveMethod::kAsk));
registry->RegisterIntegerPref(kSnsResolveMethod,
static_cast<int>(ResolveMethodTypes::ASK));

// Register prefs for migration.
// Added 12/2023 to reset SNS pref to re-opt in with updated interstitial.
registry->RegisterBooleanPref(kSnsResolveMethodMigrated, false);
}

void MigrateObsoleteLocalStatePrefs(PrefService* local_state) {
// Added 05/2022
if (static_cast<int>(ResolveMethodTypes::DEPRECATED_DNS_OVER_HTTPS) ==
local_state->GetInteger(
decentralized_dns::kUnstoppableDomainsResolveMethod)) {
local_state->ClearPref(decentralized_dns::kUnstoppableDomainsResolveMethod);
local_state->GetInteger(kUnstoppableDomainsResolveMethod)) {
local_state->ClearPref(kUnstoppableDomainsResolveMethod);
}
if (static_cast<int>(ResolveMethodTypes::DEPRECATED_DNS_OVER_HTTPS) ==
local_state->GetInteger(decentralized_dns::kENSResolveMethod)) {
local_state->ClearPref(decentralized_dns::kENSResolveMethod);
local_state->GetInteger(kENSResolveMethod)) {
local_state->ClearPref(kENSResolveMethod);
}

// Added 12/2023
// Reset SNS resolve method to ask to re-opt in with updated interstitial.
if (!local_state->GetBoolean(kSnsResolveMethodMigrated)) {
if (local_state->GetInteger(kSnsResolveMethod) ==
static_cast<int>(ResolveMethodTypes::ENABLED)) {
local_state->ClearPref(kSnsResolveMethod);
}
local_state->SetBoolean(kSnsResolveMethodMigrated, true);
}
}

bool IsUnstoppableDomainsTLD(const std::string_view host) {
for (auto* domain : kUnstoppableDomains) {
if (base::EndsWith(host, domain))
if (base::EndsWith(host, domain)) {
return true;
}
}
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions components/resources/decentralized_dns_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
Enable support of Solana Name Service (SNS) in Brave?
</message>
<message name="IDS_SNS_OPT_IN_PRIMARY_PARAGRAPH" desc="Main paragraph of SNS opt-in interstitial page.">
Brave will be using Syndica to resolve .sol domain names. Brave hides your IP address. If you enable this, Syndica will see that someone is trying to visit these .sol domains but nothing else. See Syndica's <ph name="BEGIN_SYNDICA_TOU_LINK">&lt;a target="_blank" href="$1"&gt;</ph>terms of use<ph name="END_SYNDICA_TOU_LINK">&lt;/a&gt;</ph> and <ph name="BEGIN_SYNDICA_PRIVACY_LINK">&lt;a target="_blank" href="$2"&gt;</ph>privacy policy<ph name="END_SYNDICA_PRIVACY_LINK">&lt;/a&gt;</ph>.
Brave will be using a third-party to resolve .sol domain names. Brave hides your IP address. If you enable this, the third-party will see that someone is trying to visit these .sol domains but nothing else. For more information about which third-parties we use and their privacy policies, please see our <ph name="BEGIN_SNS_WIKI_LINK">&lt;a target="_blank" href="$1"&gt;</ph>help page<ph name="END_SNS_WIKI_LINK">&lt;/a&gt;</ph>.
</message>
<message name="IDS_DECENTRALIZED_DNS_OPT_IN_PRIMARY_BUTTON" desc="The text for the decentralized DNS opt-in interstitial primary button.">
Proceed using Infura server
</message>
<message name="IDS_DECENTRALIZED_DNS_OPT_IN_PRIMARY_INFURA_BUTTON" desc="The text for the decentralized DNS opt-in interstitial primary button for Infura.">
Proceed using Infura server
</message>
<message name="IDS_DECENTRALIZED_DNS_OPT_IN_PRIMARY_SYNDICA_BUTTON" desc="The text for the decentralized DNS opt-in interstitial primary button for Syndica.">
Proceed using Syndica server
<message name="IDS_DECENTRALIZED_DNS_OPT_IN_PRIMARY_SNS_BUTTON" desc="The text for the decentralized DNS opt-in interstitial primary button for SNS server.">
Proceed using an SNS server
</message>
<message name="IDS_DECENTRALIZED_DNS_OPT_IN_DONT_PROCEED_BUTTON" desc="The text for the don't proceed button in decentralized DNS opt-in interstitial page.">
Disable
Expand Down

0 comments on commit b93b21d

Please sign in to comment.