From b93b21df9c4128301ebf0d234582d7c6938c62c6 Mon Sep 17 00:00:00 2001 From: brave-builds <45370463+brave-builds@users.noreply.github.com> Date: Wed, 20 Dec 2023 03:40:29 +0100 Subject: [PATCH] Reset SNS pref to re-opt in with updated interstitial (uplift to 1.62.x) (#21370) Uplift of #21353 (squashed) to beta --- .../decentralized_dns/test/utils_unittest.cc | 35 +++++++++++++++++++ .../content/decentralized_dns_opt_in_page.cc | 15 ++++---- .../decentralized_dns/core/pref_names.h | 4 +++ components/decentralized_dns/core/utils.cc | 26 ++++++++++---- .../resources/decentralized_dns_strings.grdp | 6 ++-- 5 files changed, 69 insertions(+), 17 deletions(-) diff --git a/browser/decentralized_dns/test/utils_unittest.cc b/browser/decentralized_dns/test/utils_unittest.cc index 8651c1c3e6fa..b656554b59c6 100644 --- a/browser/decentralized_dns/test/utils_unittest.cc +++ b/browser/decentralized_dns/test/utils_unittest.cc @@ -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(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(ResolveMethodTypes::DISABLED)); + EXPECT_FALSE(local_state()->GetBoolean(kSnsResolveMethodMigrated)); + + MigrateObsoleteLocalStatePrefs(local_state()); + + EXPECT_EQ(local_state()->GetInteger(kSnsResolveMethod), + static_cast(ResolveMethodTypes::DISABLED)); + EXPECT_TRUE(local_state()->GetBoolean(kSnsResolveMethodMigrated)); +} + } // namespace decentralized_dns diff --git a/components/decentralized_dns/content/decentralized_dns_opt_in_page.cc b/components/decentralized_dns/content/decentralized_dns_opt_in_page.cc index 944361ffc439..ca27f398b166 100644 --- a/components/decentralized_dns/content/decentralized_dns_opt_in_page.cc +++ b/components/decentralized_dns/content/decentralized_dns_opt_in_page.cc @@ -71,9 +71,9 @@ void DecentralizedDnsOptInPage::PopulateInterstitialStrings( u"https://consensys.net/terms-of-use/", u"https://consensys.net/privacy-policy/"}; - const std::vector 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( @@ -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( diff --git a/components/decentralized_dns/core/pref_names.h b/components/decentralized_dns/core/pref_names.h index ebea30026bd6..a002357c5176 100644 --- a/components/decentralized_dns/core/pref_names.h +++ b/components/decentralized_dns/core/pref_names.h @@ -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_ diff --git a/components/decentralized_dns/core/utils.cc b/components/decentralized_dns/core/utils.cc index 70aadd29a690..b0bebd890e00 100644 --- a/components/decentralized_dns/core/utils.cc +++ b/components/decentralized_dns/core/utils.cc @@ -26,25 +26,39 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) { static_cast(EnsOffchainResolveMethod::kAsk)); registry->RegisterIntegerPref(kSnsResolveMethod, static_cast(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(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(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(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; } diff --git a/components/resources/decentralized_dns_strings.grdp b/components/resources/decentralized_dns_strings.grdp index a6df2b937626..0e8ad1e9a362 100644 --- a/components/resources/decentralized_dns_strings.grdp +++ b/components/resources/decentralized_dns_strings.grdp @@ -40,7 +40,7 @@ Enable support of Solana Name Service (SNS) in Brave? - 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 <a target="_blank" href="$1">terms of use</a> and <a target="_blank" href="$2">privacy policy</a>. + 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 <a target="_blank" href="$1">help page</a>. Proceed using Infura server @@ -48,8 +48,8 @@ Proceed using Infura server - - Proceed using Syndica server + + Proceed using an SNS server Disable