From 42bdbc05a839bdc0db822af07b8ebd8fbb23c795 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Thu, 23 Sep 2021 13:22:32 +0000 Subject: [PATCH] Uplift of #10191 (squashed) to beta --- app/brave_generated_resources.grd | 10 +- browser/brave_browser_main_parts.cc | 1 - browser/brave_content_browser_client.cc | 30 ++-- browser/brave_prefs_browsertest.cc | 2 - browser/brave_profile_prefs.cc | 1 - .../ethereum_remote_client_service.cc | 5 +- .../ethereum_remote_client_service.h | 4 +- browser/ethereum_remote_client/pref_names.cc | 1 - browser/ethereum_remote_client/pref_names.h | 1 - browser/extensions/api/brave_wallet_api.cc | 66 -------- browser/extensions/api/brave_wallet_api.h | 19 --- .../api/brave_wallet_api_browsertest.cc | 128 +-------------- .../api/settings_private/brave_prefs_util.cc | 4 - browser/extensions/brave_component_loader.cc | 10 +- browser/extensions/brave_wallet_apitest.cc | 97 ------------ browser/infobars/BUILD.gn | 15 -- .../crypto_wallets_infobar_delegate.cc | 147 ------------------ .../crypto_wallets_infobar_delegate.h | 56 ------- .../brave_wallet_page/brave_wallet_page.html | 18 +-- .../brave_wallet_page/brave_wallet_page.js | 2 +- .../webui/brave_web_ui_controller_factory.cc | 6 + .../settings_localized_strings_provider.cc | 6 +- common/extensions/api/brave_wallet.json | 26 ---- .../extension/brave_extension/BUILD.gn | 4 - .../brave_extension/background/events.ts | 4 - .../background/events/dappDetectionEvents.ts | 16 -- .../brave_extension/background/reducers.ts | 2 - .../reducers/dappDetectionReducer.ts | 44 ------ .../brave_extension/content_dapps.ts | 102 ------------ components/definitions/chromel.d.ts | 4 +- components/test/testData.ts | 1 - .../braveShieldsWithWallet/background.js | 28 ---- .../api_test/braveWallet/background.js | 3 +- 33 files changed, 48 insertions(+), 815 deletions(-) delete mode 100644 browser/infobars/crypto_wallets_infobar_delegate.cc delete mode 100644 browser/infobars/crypto_wallets_infobar_delegate.h delete mode 100644 components/brave_extension/extension/brave_extension/background/events/dappDetectionEvents.ts delete mode 100644 components/brave_extension/extension/brave_extension/background/reducers/dappDetectionReducer.ts delete mode 100644 components/brave_extension/extension/brave_extension/content_dapps.ts diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index c62105673306..510ecfca4b35 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -795,14 +795,8 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U MetaMask - - Ethereum provider for using Dapps - - - Load Crypto Wallets on startup - - - Load deprecated Crypto Wallets extension on startup + + Default cryptocurrency wallet Show Brave Wallet icon on toolbar diff --git a/browser/brave_browser_main_parts.cc b/browser/brave_browser_main_parts.cc index 283ac735b7f5..6938ecb90e8f 100644 --- a/browser/brave_browser_main_parts.cc +++ b/browser/brave_browser_main_parts.cc @@ -41,7 +41,6 @@ #if !defined(OS_ANDROID) #include "brave/browser/infobars/brave_confirm_p3a_infobar_delegate.h" -#include "brave/browser/infobars/crypto_wallets_infobar_delegate.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "components/infobars/content/content_infobar_manager.h" diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index fde76a618f50..c5f429a016e5 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -153,8 +153,10 @@ using extensions::ChromeContentBrowserClientExtensionsPart; #include "brave/browser/brave_wallet/brave_wallet_context_utils.h" #include "brave/browser/brave_wallet/eth_tx_controller_factory.h" #include "brave/browser/brave_wallet/rpc_controller_factory.h" +#include "brave/components/brave_wallet/browser/brave_wallet_constants.h" #include "brave/components/brave_wallet/browser/brave_wallet_provider_impl.h" #include "brave/components/brave_wallet/browser/brave_wallet_utils.h" +#include "brave/components/brave_wallet/browser/pref_names.h" #include "brave/components/brave_wallet/common/brave_wallet.mojom.h" #if !defined(OS_ANDROID) #include "brave/browser/brave_wallet/brave_wallet_provider_delegate_impl.h" @@ -670,17 +672,23 @@ bool BraveContentBrowserClient::HandleURLOverrideRewrite( } #if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED) && BUILDFLAG(ENABLE_EXTENSIONS) - // If the Crypto Wallets extension is loaded, then it replaces the WebUI - auto* service = - EthereumRemoteClientServiceFactory::GetForContext(browser_context); - if (service->IsCryptoWalletsReady() && - url->SchemeIs(content::kChromeUIScheme) && - url->host() == ethereum_remote_client_host) { - auto* registry = extensions::ExtensionRegistry::Get(browser_context); - if (registry->ready_extensions().GetByID( - ethereum_remote_client_extension_id)) { - *url = GURL(ethereum_remote_client_base_url); - return true; + auto* prefs = user_prefs::UserPrefs::Get(browser_context); + auto provider = static_cast<::brave_wallet::Web3ProviderTypes>( + prefs->GetInteger(kBraveWalletWeb3Provider)); + if (!brave_wallet::IsNativeWalletEnabled() || + provider == brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS) { + // If the Crypto Wallets extension is loaded, then it replaces the WebUI + auto* service = + EthereumRemoteClientServiceFactory::GetForContext(browser_context); + if (service->IsCryptoWalletsReady() && + url->SchemeIs(content::kChromeUIScheme) && + url->host() == ethereum_remote_client_host) { + auto* registry = extensions::ExtensionRegistry::Get(browser_context); + if (registry->ready_extensions().GetByID( + ethereum_remote_client_extension_id)) { + *url = GURL(ethereum_remote_client_base_url); + return true; + } } } #endif diff --git a/browser/brave_prefs_browsertest.cc b/browser/brave_prefs_browsertest.cc index 844a8091112b..d62794437d8b 100644 --- a/browser/brave_prefs_browsertest.cc +++ b/browser/brave_prefs_browsertest.cc @@ -102,8 +102,6 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) { EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( kIPFSCompanionEnabled)); #if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED) - EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( - kERCLoadCryptoWalletsOnStartup)); EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( kERCOptedIntoCryptoWallets)); #endif diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 427dd55d4803..939e0f41d68a 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -328,7 +328,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterIntegerPref(kERCPrefVersion, 0); registry->RegisterStringPref(kERCAES256GCMSivNonce, ""); registry->RegisterStringPref(kERCEncryptedSeed, ""); - registry->RegisterBooleanPref(kERCLoadCryptoWalletsOnStartup, false); registry->RegisterBooleanPref(kERCOptedIntoCryptoWallets, false); #endif diff --git a/browser/ethereum_remote_client/ethereum_remote_client_service.cc b/browser/ethereum_remote_client/ethereum_remote_client_service.cc index 55333e8d01e5..d849e70f6c19 100644 --- a/browser/ethereum_remote_client/ethereum_remote_client_service.cc +++ b/browser/ethereum_remote_client/ethereum_remote_client_service.cc @@ -297,7 +297,8 @@ void EthereumRemoteClientService::RemoveUnusedWeb3ProviderContentScripts() { if (erc_extension) { user_script_manager->OnExtensionLoaded(context_, erc_extension); } - } else if (provider != brave_wallet::Web3ProviderTypes::NONE) { + } else if (provider != brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS && + provider != brave_wallet::Web3ProviderTypes::BRAVE_WALLET) { if (metamask_extension) { user_script_manager->OnExtensionLoaded(context_, metamask_extension); } @@ -323,7 +324,7 @@ void EthereumRemoteClientService::OnExtensionInstalled( } } -void EthereumRemoteClientService::OnExtensionLoaded( +void EthereumRemoteClientService::OnExtensionReady( content::BrowserContext* browser_context, const extensions::Extension* extension) { if (extension->id() == metamask_extension_id || diff --git a/browser/ethereum_remote_client/ethereum_remote_client_service.h b/browser/ethereum_remote_client/ethereum_remote_client_service.h index 12d33fae8896..14e1a6580fe1 100644 --- a/browser/ethereum_remote_client/ethereum_remote_client_service.h +++ b/browser/ethereum_remote_client/ethereum_remote_client_service.h @@ -98,8 +98,8 @@ class EthereumRemoteClientService void OnExtensionInstalled(content::BrowserContext* browser_context, const extensions::Extension* extension, bool is_update) override; - void OnExtensionLoaded(content::BrowserContext* browser_context, - const extensions::Extension* extension) override; + void OnExtensionReady(content::BrowserContext* browser_context, + const extensions::Extension* extension) override; void OnExtensionUnloaded(content::BrowserContext* browser_context, const extensions::Extension* extension, extensions::UnloadedExtensionReason reason) override; diff --git a/browser/ethereum_remote_client/pref_names.cc b/browser/ethereum_remote_client/pref_names.cc index c41d1760d13a..650829bc70db 100644 --- a/browser/ethereum_remote_client/pref_names.cc +++ b/browser/ethereum_remote_client/pref_names.cc @@ -9,5 +9,4 @@ const char kERCAES256GCMSivNonce[] = "brave.wallet.aes_256_gcm_siv_nonce"; const char kERCEncryptedSeed[] = "brave.wallet.encrypted_seed"; const char kERCEnabledDeprecated[] = "brave.wallet.enabled"; const char kERCPrefVersion[] = "brave.wallet.pref_version"; -const char kERCLoadCryptoWalletsOnStartup[] = "brave.wallet.load_on_startup"; const char kERCOptedIntoCryptoWallets[] = "brave.wallet.opted_in"; diff --git a/browser/ethereum_remote_client/pref_names.h b/browser/ethereum_remote_client/pref_names.h index b5b101b2bf9d..b06f5c4d7113 100644 --- a/browser/ethereum_remote_client/pref_names.h +++ b/browser/ethereum_remote_client/pref_names.h @@ -11,7 +11,6 @@ extern const char kERCEncryptedSeed[]; // Deprecated in favor of kBraveWalletWeb3Provider extern const char kERCEnabledDeprecated[]; extern const char kERCPrefVersion[]; -extern const char kERCLoadCryptoWalletsOnStartup[]; extern const char kERCOptedIntoCryptoWallets[]; #endif // BRAVE_BROWSER_ETHEREUM_REMOTE_CLIENT_PREF_NAMES_H_ diff --git a/browser/extensions/api/brave_wallet_api.cc b/browser/extensions/api/brave_wallet_api.cc index a054d3134946..a02aeea7af47 100644 --- a/browser/extensions/api/brave_wallet_api.cc +++ b/browser/extensions/api/brave_wallet_api.cc @@ -15,7 +15,6 @@ #include "brave/browser/ethereum_remote_client/ethereum_remote_client_service_factory.h" #include "brave/browser/ethereum_remote_client/pref_names.h" #include "brave/browser/extensions/ethereum_remote_client_util.h" -#include "brave/browser/infobars/crypto_wallets_infobar_delegate.h" #include "brave/common/extensions/api/brave_wallet.h" #include "brave/components/brave_wallet/browser/brave_wallet_constants.h" #include "brave/components/brave_wallet/browser/brave_wallet_utils.h" @@ -24,7 +23,6 @@ #include "chrome/browser/extensions/api/tabs/tabs_constants.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/profiles/profile.h" -#include "components/infobars/content/content_infobar_manager.h" #include "components/prefs/pref_service.h" #include "content/public/browser/web_contents.h" #include "extensions/browser/extension_registry.h" @@ -53,46 +51,6 @@ base::Value MakeSelectValue(const std::u16string& name, namespace extensions { namespace api { -ExtensionFunction::ResponseAction -BraveWalletPromptToEnableWalletFunction::Run() { - std::unique_ptr params( - brave_wallet::PromptToEnableWallet::Params::Create(*args_)); - EXTENSION_FUNCTION_VALIDATE(params.get()); - - if (browser_context()->IsTor()) { - return RespondNow(Error("Not available in Tor context")); - } - - // Get web contents for this tab - content::WebContents* contents = nullptr; - if (!ExtensionTabUtil::GetTabById( - params->tab_id, - Profile::FromBrowserContext(browser_context()), - include_incognito_information(), - nullptr, - nullptr, - &contents, - nullptr)) { - return RespondNow(Error(tabs_constants::kTabNotFoundError, - base::NumberToString(params->tab_id))); - } - - infobars::ContentInfoBarManager* infobar_manager = - infobars::ContentInfoBarManager::FromWebContents(contents); - if (infobar_manager) { - CryptoWalletsInfoBarDelegate::InfobarSubType subtype = - CryptoWalletsInfoBarDelegate::InfobarSubType::GENERIC_SETUP; - auto* service = GetEthereumRemoteClientService(browser_context()); - if (service->ShouldShowLazyLoadInfobar()) { - subtype = CryptoWalletsInfoBarDelegate::InfobarSubType:: - LOAD_CRYPTO_WALLETS; - } - CryptoWalletsInfoBarDelegate::Create(infobar_manager, subtype); - } - - return RespondNow(NoArguments()); -} - ExtensionFunction::ResponseAction BraveWalletReadyFunction::Run() { if (browser_context()->IsTor()) { @@ -156,30 +114,6 @@ BraveWalletShouldPromptForSetupFunction::Run() { return RespondNow(OneArgument(base::Value(should_prompt))); } -ExtensionFunction::ResponseAction -BraveWalletShouldCheckForDappsFunction::Run() { - Profile* profile = Profile::FromBrowserContext(browser_context()); - if (browser_context()->IsTor()) { - return RespondNow(OneArgument(base::Value(false))); - } - auto provider = static_cast<::brave_wallet::Web3ProviderTypes>( - profile->GetPrefs()->GetInteger(kBraveWalletWeb3Provider)); - if (provider == ::brave_wallet::Web3ProviderTypes::BRAVE_WALLET) { - return RespondNow(OneArgument(base::Value(false))); - } - auto* registry = extensions::ExtensionRegistry::Get(profile); - bool has_metamask = - registry->ready_extensions().Contains(metamask_extension_id); - - auto* service = GetEthereumRemoteClientService(browser_context()); - bool dappDetection = - (provider == ::brave_wallet::Web3ProviderTypes::ASK && !has_metamask) || - (provider == ::brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS && - !service->IsCryptoWalletsReady()); - - return RespondNow(OneArgument(base::Value(dappDetection))); -} - ExtensionFunction::ResponseAction BraveWalletGetWalletSeedFunction::Run() { // make sure the passed in enryption key is 32 bytes. diff --git a/browser/extensions/api/brave_wallet_api.h b/browser/extensions/api/brave_wallet_api.h index aa3aa7049931..b116544988ad 100644 --- a/browser/extensions/api/brave_wallet_api.h +++ b/browser/extensions/api/brave_wallet_api.h @@ -15,16 +15,6 @@ class Profile; namespace extensions { namespace api { -class BraveWalletPromptToEnableWalletFunction : - public ExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("braveWallet.promptToEnableWallet", UNKNOWN) - - protected: - ~BraveWalletPromptToEnableWalletFunction() override {} - ResponseAction Run() override; -}; - class BraveWalletReadyFunction : public ExtensionFunction { public: @@ -44,15 +34,6 @@ class BraveWalletNotifyWalletUnlockFunction : public ExtensionFunction { ResponseAction Run() override; }; -class BraveWalletShouldCheckForDappsFunction : public ExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("braveWallet.shouldCheckForDapps", UNKNOWN) - - protected: - ~BraveWalletShouldCheckForDappsFunction() override {} - ResponseAction Run() override; -}; - class BraveWalletLoadUIFunction : public ExtensionFunction { public: DECLARE_EXTENSION_FUNCTION("braveWallet.loadUI", UNKNOWN) diff --git a/browser/extensions/api/brave_wallet_api_browsertest.cc b/browser/extensions/api/brave_wallet_api_browsertest.cc index 787bca32ccad..a5c8b9f7895f 100644 --- a/browser/extensions/api/brave_wallet_api_browsertest.cc +++ b/browser/extensions/api/brave_wallet_api_browsertest.cc @@ -6,7 +6,6 @@ #include "base/path_service.h" #include "base/scoped_observation.h" #include "brave/browser/ethereum_remote_client/ethereum_remote_client_constants.h" -#include "brave/browser/infobars/crypto_wallets_infobar_delegate.h" #include "brave/common/brave_paths.h" #include "brave/common/pref_names.h" #include "brave/components/brave_wallet/browser/brave_wallet_constants.h" @@ -16,8 +15,6 @@ #include "chrome/browser/ui/browser.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" -#include "components/infobars/content/content_infobar_manager.h" -#include "components/infobars/core/infobar.h" #include "components/prefs/pref_service.h" #include "content/public/test/browser_test.h" #include "content/public/test/browser_test_utils.h" @@ -28,14 +25,11 @@ #include "extensions/test/extension_test_message_listener.h" #include "net/dns/mock_host_resolver.h" -using namespace infobars; // NOLINT - namespace extensions { -class BraveWalletAPIBrowserTest : public InProcessBrowserTest, - public InfoBarManager::Observer { +class BraveWalletAPIBrowserTest : public InProcessBrowserTest { public: - BraveWalletAPIBrowserTest() : infobar_added_(false) {} + BraveWalletAPIBrowserTest() {} void WaitForBraveExtensionAdded() { // Brave extension must be loaded, otherwise dapp detection events @@ -45,14 +39,6 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest, ASSERT_TRUE(extension_listener.WaitUntilSatisfied()); } - void WaitForCryptoWalletsInfobarAdded() { - if (infobar_added_) { - return; - } - infobar_added_run_loop_ = std::make_unique(); - infobar_added_run_loop_->Run(); - } - void WaitForTabCount(int expected) { while (browser()->tab_strip_model()->count() != expected) base::RunLoop().RunUntilIdle(); @@ -102,53 +88,10 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest, ~BraveWalletAPIBrowserTest() override { } - void AddInfoBarObserver(infobars::ContentInfoBarManager* infobar_manager) { - DCHECK(!infobar_observer_.IsObserving()); - infobar_observer_.Observe(infobar_manager); - } - - void RemoveInfoBarObserver(infobars::ContentInfoBarManager* infobar_manager) { - DCHECK(infobar_observer_.IsObservingSource(infobar_manager)); - infobar_observer_.Reset(); - } - content::WebContents* active_contents() { return browser()->tab_strip_model()->GetActiveWebContents(); } - void CryptoWalletsInfoBarAccept(int expected_buttons) { - infobars::ContentInfoBarManager* infobar_manager = - infobars::ContentInfoBarManager::FromWebContents(active_contents()); - for (size_t i = 0; i < infobar_manager->infobar_count(); i++) { - InfoBarDelegate* delegate = infobar_manager->infobar_at(i)->delegate(); - if (delegate->GetIdentifier() == - InfoBarDelegate::CRYPTO_WALLETS_INFOBAR_DELEGATE) { - ConfirmInfoBarDelegate* confirm_delegate = - delegate->AsConfirmInfoBarDelegate(); - // Only the OK button should be present - ASSERT_EQ(confirm_delegate->GetButtons(), expected_buttons); - confirm_delegate->Accept(); - } - } - } - - void CryptoWalletsInfoBarCancel(int expected_buttons) { - infobars::ContentInfoBarManager* infobar_manager = - infobars::ContentInfoBarManager::FromWebContents(active_contents()); - for (size_t i = 0; i < infobar_manager->infobar_count(); i++) { - InfoBarDelegate* delegate = infobar_manager->infobar_at(i)->delegate(); - if (delegate->GetIdentifier() == - InfoBarDelegate::CRYPTO_WALLETS_INFOBAR_DELEGATE) { - ConfirmInfoBarDelegate* confirm_delegate = - delegate->AsConfirmInfoBarDelegate(); - // Only the OK button should be present - ASSERT_EQ(confirm_delegate->GetButtons(), - expected_buttons); - confirm_delegate->Cancel(); - } - } - } - bool NavigateToURLUntilLoadStop(const std::string& origin, const std::string& path) { ui_test_utils::NavigateToURL(browser(), @@ -158,75 +101,8 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest, private: scoped_refptr extension_; - base::ScopedObservation - infobar_observer_{this}; - bool infobar_added_; - std::unique_ptr infobar_added_run_loop_; - - // InfoBarManager::Observer: - void OnInfoBarAdded(InfoBar* infobar) override { - if (infobar_added_run_loop_ && - infobar->delegate()->GetIdentifier() == - InfoBarDelegate::CRYPTO_WALLETS_INFOBAR_DELEGATE) { - infobar_added_ = true; - infobar_added_run_loop_->Quit(); - } - } }; -IN_PROC_BROWSER_TEST_F(BraveWalletAPIBrowserTest, DappDetectionTestAccept) { - if (brave_wallet::IsNativeWalletEnabled()) { - browser()->profile()->GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::ASK)); - } - WaitForBraveExtensionAdded(); - infobars::ContentInfoBarManager* infobar_manager = - infobars::ContentInfoBarManager::FromWebContents(active_contents()); - AddInfoBarObserver(infobar_manager); - EXPECT_TRUE( - NavigateToURLUntilLoadStop("a.com", "/dapp.html")); - WaitForCryptoWalletsInfobarAdded(); - // Pref for Wallet should still be ask by default - auto provider = static_cast( - browser()->profile()->GetPrefs()->GetInteger(kBraveWalletWeb3Provider)); - ASSERT_EQ(provider, brave_wallet::Web3ProviderTypes::ASK); - CryptoWalletsInfoBarAccept( - ConfirmInfoBarDelegate::BUTTON_OK | - ConfirmInfoBarDelegate::BUTTON_CANCEL); - WaitForTabCount(2); - RemoveInfoBarObserver(infobar_manager); -} - -IN_PROC_BROWSER_TEST_F(BraveWalletAPIBrowserTest, InfoBarDontAsk) { - if (brave_wallet::IsNativeWalletEnabled()) { - browser()->profile()->GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::ASK)); - } - // Navigate to dapp - WaitForBraveExtensionAdded(); - infobars::ContentInfoBarManager* infobar_manager = - infobars::ContentInfoBarManager::FromWebContents(active_contents()); - AddInfoBarObserver(infobar_manager); - EXPECT_TRUE( - NavigateToURLUntilLoadStop("a.com", "/dapp.html")); - WaitForCryptoWalletsInfobarAdded(); - // Provider type should be Ask by default - auto provider_before = static_cast( - browser()->profile()->GetPrefs()->GetInteger(kBraveWalletWeb3Provider)); - ASSERT_EQ(provider_before, brave_wallet::Web3ProviderTypes::ASK); - // Click "Don't ask again" - CryptoWalletsInfoBarCancel( - ConfirmInfoBarDelegate::BUTTON_OK | - ConfirmInfoBarDelegate::BUTTON_CANCEL); - // Provider type should now be none - auto provider_after = static_cast( - browser()->profile()->GetPrefs()->GetInteger(kBraveWalletWeb3Provider)); - ASSERT_EQ(provider_after, brave_wallet::Web3ProviderTypes::NONE); - RemoveInfoBarObserver(infobar_manager); -} - IN_PROC_BROWSER_TEST_F(BraveWalletAPIBrowserTest, FakeInstallMetaMask) { if (brave_wallet::IsNativeWalletEnabled()) { diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc index b2d4cd8bbab3..52e3048a1abf 100644 --- a/browser/extensions/api/settings_private/brave_prefs_util.cc +++ b/browser/extensions/api/settings_private/brave_prefs_util.cc @@ -214,10 +214,6 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() { (*s_brave_allowlist)[kIPFSCompanionEnabled] = settings_api::PrefType::PREF_TYPE_BOOLEAN; -#if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED) - (*s_brave_allowlist)[kERCLoadCryptoWalletsOnStartup] = - settings_api::PrefType::PREF_TYPE_BOOLEAN; -#endif // Brave Wallet pref #if BUILDFLAG(BRAVE_WALLET_ENABLED) (*s_brave_allowlist)[kBraveWalletWeb3Provider] = diff --git a/browser/extensions/brave_component_loader.cc b/browser/extensions/brave_component_loader.cc index 8b9a6cf49f24..edaa1ab0a602 100644 --- a/browser/extensions/brave_component_loader.cc +++ b/browser/extensions/brave_component_loader.cc @@ -36,6 +36,8 @@ #include "brave/browser/ethereum_remote_client/ethereum_remote_client_constants.h" #include "brave/browser/ethereum_remote_client/pref_names.h" #include "brave/browser/extensions/ethereum_remote_client_util.h" +#include "brave/components/brave_wallet/browser/brave_wallet_constants.h" +#include "brave/components/brave_wallet/browser/pref_names.h" #endif using extensions::mojom::ManifestLocation; @@ -162,10 +164,12 @@ void BraveComponentLoader::AddEthereumRemoteClientExtension() { } void BraveComponentLoader::AddEthereumRemoteClientExtensionOnStartup() { - // Only load if the eagerly load Crypto Wallets setting is on and there is a - // project id configured in the build. + // Only load Crypto Wallets if it is set as the default wallet + auto provider = static_cast( + profile_prefs_->GetInteger(kBraveWalletWeb3Provider)); + if (HasInfuraProjectID() && - profile_prefs_->GetBoolean(kERCLoadCryptoWalletsOnStartup)) { + provider == brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS) { AddEthereumRemoteClientExtension(); } } diff --git a/browser/extensions/brave_wallet_apitest.cc b/browser/extensions/brave_wallet_apitest.cc index 7111d33885cf..597a206a9e86 100644 --- a/browser/extensions/brave_wallet_apitest.cc +++ b/browser/extensions/brave_wallet_apitest.cc @@ -177,102 +177,5 @@ IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, ASSERT_TRUE(catcher.GetNextResult()) << message_; } -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsDappDetectionWhenDefault) { - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsDappDetectionWhenAsk) { - GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::ASK)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsNoDappDetectionWhenNone) { - GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::NONE)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testNoDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsNoDappDetectionWhenMetaMask) { - GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::METAMASK)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testNoDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsNoDappDetectionWhenCryptoWallets) { - GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - LoadExtension(extension_dir_.AppendASCII("braveWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testNoDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsNoDappDetectionWhenBraveWallet) { - GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::BRAVE_WALLET)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - LoadExtension(extension_dir_.AppendASCII("braveWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testNoDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveShieldsDappDetectionWhenCryptoWalletsNotReady) { - GetPrefs()->SetInteger( - kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveShieldsWithWallet")); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), brave_extension_id, "testDappCheck()")); - ASSERT_TRUE(extension); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - } // namespace } // namespace extensions diff --git a/browser/infobars/BUILD.gn b/browser/infobars/BUILD.gn index c22609617db6..f92667330e30 100644 --- a/browser/infobars/BUILD.gn +++ b/browser/infobars/BUILD.gn @@ -1,4 +1,3 @@ -import("//brave/browser/ethereum_remote_client/buildflags/buildflags.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") import("//brave/components/ipfs/buildflags/buildflags.gni") import("//build/config/features.gni") @@ -32,20 +31,6 @@ source_set("infobars") { "//url", ] - if (ethereum_remote_client_enabled) { - sources += [ - "crypto_wallets_infobar_delegate.cc", - "crypto_wallets_infobar_delegate.h", - ] - - deps += [ - "//brave/browser/ethereum_remote_client", - "//brave/common:pref_names", - "//components/user_prefs:user_prefs", - "//extensions/common:common_constants", - ] - } - if (enable_ipfs) { deps += [ "//brave/components/ipfs", diff --git a/browser/infobars/crypto_wallets_infobar_delegate.cc b/browser/infobars/crypto_wallets_infobar_delegate.cc deleted file mode 100644 index dc339820b307..000000000000 --- a/browser/infobars/crypto_wallets_infobar_delegate.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "brave/browser/infobars/crypto_wallets_infobar_delegate.h" - -#include -#include - -#include "brave/browser/ethereum_remote_client/ethereum_remote_client_constants.h" -#include "brave/browser/ethereum_remote_client/ethereum_remote_client_service.h" -#include "brave/browser/ethereum_remote_client/ethereum_remote_client_service_factory.h" -#include "brave/browser/ui/brave_pages.h" -#include "brave/common/url_constants.h" -#include "brave/components/brave_wallet/browser/brave_wallet_constants.h" -#include "brave/components/brave_wallet/browser/pref_names.h" -#include "brave/grit/brave_generated_resources.h" -#include "chrome/browser/infobars/confirm_infobar_creator.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/grit/chromium_strings.h" -#include "components/infobars/content/content_infobar_manager.h" -#include "components/infobars/core/infobar.h" -#include "components/prefs/pref_service.h" -#include "components/strings/grit/components_strings.h" -#include "components/user_prefs/user_prefs.h" -#include "content/public/browser/browser_context.h" -#include "extensions/common/constants.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/views/vector_icons.h" - -// static -void CryptoWalletsInfoBarDelegate::Create( - infobars::ContentInfoBarManager* infobar_manager, - CryptoWalletsInfoBarDelegate::InfobarSubType subtype) { - infobar_manager->AddInfoBar( - CreateConfirmInfoBar(std::unique_ptr( - new CryptoWalletsInfoBarDelegate(subtype)))); -} - -CryptoWalletsInfoBarDelegate::CryptoWalletsInfoBarDelegate( - CryptoWalletsInfoBarDelegate::InfobarSubType subtype) : - subtype_(subtype) { -} - -CryptoWalletsInfoBarDelegate::~CryptoWalletsInfoBarDelegate() {} - -infobars::InfoBarDelegate::InfoBarIdentifier -CryptoWalletsInfoBarDelegate::GetIdentifier() const { - return CRYPTO_WALLETS_INFOBAR_DELEGATE; -} - -const gfx::VectorIcon& CryptoWalletsInfoBarDelegate::GetVectorIcon() const { - return views::kInfoIcon; -} - -void CryptoWalletsInfoBarDelegate::InfoBarDismissed() { -} - -std::u16string CryptoWalletsInfoBarDelegate::GetMessageText() const { - if (subtype_ == InfobarSubType::LOAD_CRYPTO_WALLETS) { - return l10n_util::GetStringUTF16(IDS_BRAVE_CRYPTO_WALLETS_LAZY_LOAD_TEXT); - } - return l10n_util::GetStringUTF16(IDS_BRAVE_CRYPTO_WALLETS_INFOBAR_TEXT); -} - -int CryptoWalletsInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - -std::u16string CryptoWalletsInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { - if (subtype_ == InfobarSubType::LOAD_CRYPTO_WALLETS) { - if (button == BUTTON_CANCEL) { - return l10n_util::GetStringUTF16(IDS_BRAVE_CRYPTO_WALLETS_SETTINGS); - } - return l10n_util::GetStringUTF16( - IDS_BRAVE_CRYPTO_WALLETS_START_AND_RELOAD); - } - - if (button == BUTTON_CANCEL) { - return l10n_util::GetStringUTF16(IDS_BRAVE_CRYPTO_WALLETS_DONT_ASK); - } - - return l10n_util::GetStringUTF16( - IDS_BRAVE_CRYPTO_WALLETS_SETUP_CRYPTO_WALLETS); -} - -std::u16string CryptoWalletsInfoBarDelegate::GetLinkText() const { - return l10n_util::GetStringUTF16(IDS_LEARN_MORE); -} - -GURL CryptoWalletsInfoBarDelegate::GetLinkURL() const { - return GURL(kCryptoWalletsLearnMoreURL); -} - -bool CryptoWalletsInfoBarDelegate::Accept() { - if (subtype_ == InfobarSubType::LOAD_CRYPTO_WALLETS) { - content::WebContents* web_contents = - infobars::ContentInfoBarManager::WebContentsFromInfoBar(infobar()); - if (web_contents) { - auto* browser_context = web_contents->GetBrowserContext(); - auto* service = - EthereumRemoteClientServiceFactory::GetForContext(browser_context); - service->MaybeLoadCryptoWalletsExtension( - base::BindOnce(&CryptoWalletsInfoBarDelegate::OnCryptoWalletsLoaded, - weak_ptr_factory_.GetWeakPtr(), web_contents)); - } - return true; - } - if (infobar() && infobar()->owner()) { - content::WebContents* web_contents = - infobars::ContentInfoBarManager::WebContentsFromInfoBar(infobar()); - if (web_contents) { - auto* browser_context = web_contents->GetBrowserContext(); - user_prefs::UserPrefs::Get(browser_context) - ->SetInteger(kBraveWalletWeb3Provider, - static_cast( - brave_wallet::Web3ProviderTypes::CRYPTO_WALLETS)); - Browser* browser = chrome::FindBrowserWithWebContents(web_contents); - brave::ShowBraveWallet(browser); - } - } - return true; -} - -bool CryptoWalletsInfoBarDelegate::Cancel() { - content::WebContents* web_contents = - infobars::ContentInfoBarManager::WebContentsFromInfoBar(infobar()); - if (web_contents) { - if (subtype_ == InfobarSubType::GENERIC_SETUP) { - auto* browser_context = web_contents->GetBrowserContext(); - user_prefs::UserPrefs::Get(browser_context) - ->SetInteger(kBraveWalletWeb3Provider, - static_cast(brave_wallet::Web3ProviderTypes::NONE)); - return true; - } - Browser* browser = chrome::FindBrowserWithWebContents(web_contents); - brave::ShowWalletSettings(browser); - } - return true; -} - -void CryptoWalletsInfoBarDelegate::OnCryptoWalletsLoaded( - content::WebContents* web_contents) { - web_contents->GetController().Reload(content::ReloadType::NORMAL, true); -} diff --git a/browser/infobars/crypto_wallets_infobar_delegate.h b/browser/infobars/crypto_wallets_infobar_delegate.h deleted file mode 100644 index d0c211558850..000000000000 --- a/browser/infobars/crypto_wallets_infobar_delegate.h +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (c) 2019 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_BROWSER_INFOBARS_CRYPTO_WALLETS_INFOBAR_DELEGATE_H_ -#define BRAVE_BROWSER_INFOBARS_CRYPTO_WALLETS_INFOBAR_DELEGATE_H_ - -#include "base/compiler_specific.h" -#include "base/memory/weak_ptr.h" -#include "components/infobars/core/confirm_infobar_delegate.h" -#include "url/gurl.h" - -class PrefService; - -namespace content { -class WebContents; -} // namespace content - -namespace infobars { -class ContentInfoBarManager; -} // namespace infobars - -// An infobar that is run with a string, buttons, and a "Learn More" link. -class CryptoWalletsInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - enum class InfobarSubType { LOAD_CRYPTO_WALLETS, GENERIC_SETUP }; - static void Create(infobars::ContentInfoBarManager* infobar_manager, - InfobarSubType subtype); - - private: - explicit CryptoWalletsInfoBarDelegate(InfobarSubType subtype); - CryptoWalletsInfoBarDelegate(const CryptoWalletsInfoBarDelegate&) = delete; - CryptoWalletsInfoBarDelegate& operator=(const CryptoWalletsInfoBarDelegate&) = - delete; - ~CryptoWalletsInfoBarDelegate() override; - - void OnCryptoWalletsLoaded(content::WebContents*); - bool ShouldShowLazyLoadInfobar(); - infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; - const gfx::VectorIcon& GetVectorIcon() const override; - void InfoBarDismissed() override; - std::u16string GetMessageText() const override; - int GetButtons() const override; - std::u16string GetButtonLabel(InfoBarButton button) const override; - std::u16string GetLinkText() const override; - GURL GetLinkURL() const override; - bool Accept() override; - bool Cancel() override; - - InfobarSubType subtype_; - - base::WeakPtrFactory weak_ptr_factory_{this}; -}; - -#endif // BRAVE_BROWSER_INFOBARS_CRYPTO_WALLETS_INFOBAR_DELEGATE_H_ diff --git a/browser/resources/settings/brave_wallet_page/brave_wallet_page.html b/browser/resources/settings/brave_wallet_page/brave_wallet_page.html index aec048c3068e..e0a2be002c98 100644 --- a/browser/resources/settings/brave_wallet_page/brave_wallet_page.html +++ b/browser/resources/settings/brave_wallet_page/brave_wallet_page.html @@ -26,24 +26,12 @@ }
-
$i18n{braveWeb3ProviderDesc}
- $i18n{defaultWalletDesc}
+ + menu-options="[[wallets_]]"> - -