From c44998575032404d4d2a267cf4d9d5b571639b28 Mon Sep 17 00:00:00 2001 From: ryanml Date: Wed, 2 Dec 2020 15:47:52 -0700 Subject: [PATCH] Removing dapp detection, crypto wallets infobar Fixes brave/brave-browser#13009 --- app/brave_generated_resources.grd | 22 --- browser/brave_browser_main_parts.cc | 1 - browser/brave_profile_prefs.cc | 2 +- browser/brave_profile_prefs_browsertest.cc | 7 +- browser/extensions/api/brave_wallet_api.cc | 66 -------- browser/extensions/api/brave_wallet_api.h | 19 --- .../api/brave_wallet_api_browsertest.cc | 119 +-------------- browser/extensions/brave_wallet_apitest.cc | 91 ----------- browser/infobars/BUILD.gn | 16 -- .../crypto_wallets_infobar_delegate.cc | 144 ------------------ .../crypto_wallets_infobar_delegate.h | 53 ------- common/extensions/api/brave_wallet.json | 26 ---- .../extension/brave_extension/BUILD.gn | 1 - .../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 ------------- .../brave_wallet/brave_wallet_constants.h | 2 +- components/definitions/chromel.d.ts | 2 - components/test/testData.ts | 1 - .../braveShieldsWithWallet/background.js | 28 ---- .../api_test/braveWallet/background.js | 17 +-- 23 files changed, 9 insertions(+), 776 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 1e5eab7e5d4c..c5525da0be30 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -673,9 +673,6 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U Uses WebTorrent to display torrents directly in the browser. Supports torrent files and magnet links. - - Ask - None @@ -940,25 +937,6 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U This anonymous info only lets Brave estimate the overall usage of certain features. - - - Would you like to start Crypto Wallets for Ethereum support? - - - Set up Crypto Wallets to interact with this app and others like it. - - - Setup Crypto Wallets - - - Start Crypto Wallets and reload - - - Settings - - - Don't ask again - IPFS resources detected. Would you like Brave to load them using a local IPFS node? diff --git a/browser/brave_browser_main_parts.cc b/browser/brave_browser_main_parts.cc index b23fce2cb783..45efb2d5a5fd 100644 --- a/browser/brave_browser_main_parts.cc +++ b/browser/brave_browser_main_parts.cc @@ -31,7 +31,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 "chrome/browser/infobars/infobar_service.h" diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 012e37b8d62a..635d10093239 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -280,7 +280,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { registry->RegisterStringPref(kBraveWalletEncryptedSeed, ""); registry->RegisterIntegerPref( kBraveWalletWeb3Provider, - static_cast(BraveWalletWeb3ProviderTypes::ASK)); + static_cast(BraveWalletWeb3ProviderTypes::NONE)); registry->RegisterBooleanPref(kLoadCryptoWalletsOnStartup, false); registry->RegisterBooleanPref(kOptedIntoCryptoWallets, false); #endif diff --git a/browser/brave_profile_prefs_browsertest.cc b/browser/brave_profile_prefs_browsertest.cc index 37d9ef83c2f0..f87fead74cce 100644 --- a/browser/brave_profile_prefs_browsertest.cc +++ b/browser/brave_profile_prefs_browsertest.cc @@ -81,9 +81,10 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) { #if BUILDFLAG(BRAVE_WALLET_ENABLED) EXPECT_EQ( browser()->profile()->GetPrefs()->GetInteger(kBraveWalletWeb3Provider), - static_cast(BraveWalletWeb3ProviderTypes::ASK)); - EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( - kLoadCryptoWalletsOnStartup)); + static_cast(BraveWalletWeb3ProviderTypes::NONE)); + EXPECT_FALSE( + browser()->profile()->GetPrefs()->GetBoolean( + kLoadCryptoWalletsOnStartup)); EXPECT_FALSE( browser()->profile()->GetPrefs()->GetBoolean(kOptedIntoCryptoWallets)); #endif diff --git a/browser/extensions/api/brave_wallet_api.cc b/browser/extensions/api/brave_wallet_api.cc index 248fa6b327fd..5c0a26ad46af 100644 --- a/browser/extensions/api/brave_wallet_api.cc +++ b/browser/extensions/api/brave_wallet_api.cc @@ -11,14 +11,12 @@ #include "base/json/json_writer.h" #include "base/values.h" #include "brave/browser/extensions/brave_wallet_util.h" -#include "brave/browser/infobars/crypto_wallets_infobar_delegate.h" #include "brave/common/extensions/api/brave_wallet.h" #include "brave/components/brave_wallet/brave_wallet_constants.h" #include "brave/components/brave_wallet/pref_names.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/browser/extensions/api/tabs/tabs_constants.h" #include "chrome/browser/extensions/extension_tab_util.h" -#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "components/prefs/pref_service.h" #include "content/public/browser/web_contents.h" @@ -50,46 +48,6 @@ base::Value MakeSelectValue(const base::string16& 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))); - } - - InfoBarService* infobar_service = - InfoBarService::FromWebContents(contents); - if (infobar_service) { - CryptoWalletsInfoBarDelegate::InfobarSubType subtype = - CryptoWalletsInfoBarDelegate::InfobarSubType::GENERIC_SETUP; - auto* service = GetBraveWalletService(browser_context()); - if (service->ShouldShowLazyLoadInfobar()) { - subtype = CryptoWalletsInfoBarDelegate::InfobarSubType:: - LOAD_CRYPTO_WALLETS; - } - CryptoWalletsInfoBarDelegate::Create(infobar_service, subtype); - } - - return RespondNow(NoArguments()); -} - ExtensionFunction::ResponseAction BraveWalletReadyFunction::Run() { if (browser_context()->IsTor()) { @@ -137,27 +95,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( - profile->GetPrefs()->GetInteger(kBraveWalletWeb3Provider)); - auto* registry = extensions::ExtensionRegistry::Get(profile); - bool has_metamask = - registry->ready_extensions().Contains(metamask_extension_id); - - auto* service = GetBraveWalletService(browser_context()); - bool dappDetection = ( - provider == BraveWalletWeb3ProviderTypes::ASK && !has_metamask) || - (provider == BraveWalletWeb3ProviderTypes::CRYPTO_WALLETS && - !service->IsCryptoWalletsReady()); - - return RespondNow(OneArgument(base::Value(dappDetection))); -} - ExtensionFunction::ResponseAction BraveWalletGetWalletSeedFunction::Run() { // make sure the passed in enryption key is 32 bytes. @@ -240,9 +177,6 @@ BraveWalletGetWeb3ProviderFunction::Run() { ExtensionFunction::ResponseAction BraveWalletGetWeb3ProviderListFunction::Run() { base::Value list(base::Value::Type::LIST); - list.Append(MakeSelectValue( - l10n_util::GetStringUTF16(IDS_BRAVE_WALLET_WEB3_PROVIDER_ASK), - BraveWalletWeb3ProviderTypes::ASK)); list.Append(MakeSelectValue( l10n_util::GetStringUTF16(IDS_BRAVE_WALLET_WEB3_PROVIDER_NONE), BraveWalletWeb3ProviderTypes::NONE)); diff --git a/browser/extensions/api/brave_wallet_api.h b/browser/extensions/api/brave_wallet_api.h index e2736eedb31e..cd22109a6206 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: @@ -35,15 +25,6 @@ class BraveWalletReadyFunction : 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 757b7fa4770c..4f3d47256b9c 100644 --- a/browser/extensions/api/brave_wallet_api_browsertest.cc +++ b/browser/extensions/api/brave_wallet_api_browsertest.cc @@ -5,17 +5,14 @@ #include "base/path_service.h" #include "base/scoped_observer.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/brave_wallet_constants.h" #include "brave/components/brave_wallet/pref_names.h" -#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #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/core/infobar.h" #include "components/prefs/pref_service.h" #include "content/public/test/browser_test.h" #include "content/public/test/browser_test_utils.h" @@ -26,15 +23,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_observer_(this), - infobar_added_(false) { + BraveWalletAPIBrowserTest() { } void WaitForBraveExtensionAdded() { @@ -45,14 +38,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 +87,10 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest, ~BraveWalletAPIBrowserTest() override { } - void AddInfoBarObserver(InfoBarService* infobar_service) { - infobar_observer_.Add(infobar_service); - } - - void RemoveInfoBarObserver(InfoBarService* infobar_service) { - infobar_observer_.Remove(infobar_service); - } - content::WebContents* active_contents() { return browser()->tab_strip_model()->GetActiveWebContents(); } - void CryptoWalletsInfoBarAccept(int expected_buttons) { - InfoBarService* infobar_service = - InfoBarService::FromWebContents(active_contents()); - for (size_t i = 0; i < infobar_service->infobar_count(); i++) { - InfoBarDelegate* delegate = - infobar_service->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) { - InfoBarService* infobar_service = - InfoBarService::FromWebContents(active_contents()); - for (size_t i = 0; i < infobar_service->infobar_count(); i++) { - InfoBarDelegate* delegate = - infobar_service->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,65 +100,8 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest, private: scoped_refptr extension_; - ScopedObserver - infobar_observer_; - 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) { - WaitForBraveExtensionAdded(); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(active_contents()); - AddInfoBarObserver(infobar_service); - 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, BraveWalletWeb3ProviderTypes::ASK); - CryptoWalletsInfoBarAccept( - ConfirmInfoBarDelegate::BUTTON_OK | - ConfirmInfoBarDelegate::BUTTON_CANCEL); - WaitForTabCount(2); - RemoveInfoBarObserver(infobar_service); -} - -IN_PROC_BROWSER_TEST_F(BraveWalletAPIBrowserTest, InfoBarDontAsk) { - // Navigate to dapp - WaitForBraveExtensionAdded(); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(active_contents()); - AddInfoBarObserver(infobar_service); - 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, BraveWalletWeb3ProviderTypes::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, BraveWalletWeb3ProviderTypes::NONE); - RemoveInfoBarObserver(infobar_service); -} - IN_PROC_BROWSER_TEST_F(BraveWalletAPIBrowserTest, FakeInstallMetaMask) { WaitForBraveExtensionAdded(); diff --git a/browser/extensions/brave_wallet_apitest.cc b/browser/extensions/brave_wallet_apitest.cc index 4954d1848956..ec9bed365b98 100644 --- a/browser/extensions/brave_wallet_apitest.cc +++ b/browser/extensions/brave_wallet_apitest.cc @@ -117,20 +117,6 @@ IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, ASSERT_TRUE(catcher.GetNextResult()) << message_; } -IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, - BraveWalletWeb3ProviderAsk) { - GetPrefs()->SetInteger(kBraveWalletWeb3Provider, - static_cast(BraveWalletWeb3ProviderTypes::ASK)); - ResultCatcher catcher; - const Extension* extension = - LoadExtension(extension_dir_.AppendASCII("braveWallet")); - ASSERT_TRUE(extension); - ASSERT_TRUE(browsertest_util::ExecuteScriptInBackgroundPageNoWait( - browser()->profile(), ethereum_remote_client_extension_id, - "testProviderIsAsk()")); - ASSERT_TRUE(catcher.GetNextResult()) << message_; -} - IN_PROC_BROWSER_TEST_F(BraveWalletExtensionApiTest, BraveWalletWeb3ProviderNone) { GetPrefs()->SetInteger(kBraveWalletWeb3Provider, @@ -154,82 +140,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(BraveWalletWeb3ProviderTypes::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(BraveWalletWeb3ProviderTypes::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(BraveWalletWeb3ProviderTypes::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(BraveWalletWeb3ProviderTypes::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, - BraveShieldsDappDetectionWhenCryptoWalletsNotReady) { - GetPrefs()->SetInteger(kBraveWalletWeb3Provider, - static_cast(BraveWalletWeb3ProviderTypes::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 3d562832563d..15964f186231 100644 --- a/browser/infobars/BUILD.gn +++ b/browser/infobars/BUILD.gn @@ -1,6 +1,5 @@ import("//build/config/features.gni") import("//brave/components/brave_wayback_machine/buildflags/buildflags.gni") -import("//brave/components/brave_wallet/buildflags/buildflags.gni") import("//brave/components/brave_sync/buildflags/buildflags.gni") import("//brave/components/ipfs/buildflags/buildflags.gni") @@ -27,21 +26,6 @@ source_set("infobars") { "//url", ] - if (brave_wallet_enabled) { - sources += [ - "crypto_wallets_infobar_delegate.cc", - "crypto_wallets_infobar_delegate.h", - ] - - deps += [ - "//brave/browser/brave_wallet:brave_wallet", - "//brave/common:pref_names", - "//brave/components/brave_wallet", - "//components/user_prefs:user_prefs", - "//extensions/common:common_constants", - ] - } - if (ipfs_enabled) { sources += [ "ipfs_infobar_delegate.cc", diff --git a/browser/infobars/crypto_wallets_infobar_delegate.cc b/browser/infobars/crypto_wallets_infobar_delegate.cc deleted file mode 100644 index c59e5cd3abac..000000000000 --- a/browser/infobars/crypto_wallets_infobar_delegate.cc +++ /dev/null @@ -1,144 +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/brave_wallet/brave_wallet_service_factory.h" -#include "brave/browser/ui/brave_pages.h" -#include "brave/common/url_constants.h" -#include "brave/components/brave_wallet/brave_wallet_constants.h" -#include "brave/components/brave_wallet/brave_wallet_service.h" -#include "brave/components/brave_wallet/pref_names.h" -#include "brave/grit/brave_generated_resources.h" -#include "chrome/browser/infobars/infobar_service.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/grit/chromium_strings.h" -#include "chrome/browser/profiles/profile.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(InfoBarService* infobar_service, - CryptoWalletsInfoBarDelegate::InfobarSubType subtype) { - infobar_service->AddInfoBar(infobar_service->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() { -} - -base::string16 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; -} - -base::string16 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); -} - -base::string16 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 = - InfoBarService::WebContentsFromInfoBar(infobar()); - if (web_contents) { - auto* browser_context = web_contents->GetBrowserContext(); - Profile* profile = Profile::FromBrowserContext(browser_context); - auto* service = BraveWalletServiceFactory::GetForProfile(profile); - service->LoadCryptoWalletsExtension(base::BindOnce( - &CryptoWalletsInfoBarDelegate::OnCryptoWalletsLoaded, - base::Unretained(this), web_contents)); - } - return true; - } - if (infobar() && infobar()->owner()) { - content::WebContents* web_contents = - InfoBarService::WebContentsFromInfoBar(infobar()); - if (web_contents) { - auto* browser_context = web_contents->GetBrowserContext(); - user_prefs::UserPrefs::Get(browser_context)-> - SetInteger(kBraveWalletWeb3Provider, - static_cast(BraveWalletWeb3ProviderTypes::CRYPTO_WALLETS)); - Browser* browser = chrome::FindBrowserWithWebContents(web_contents); - brave::ShowBraveWallet(browser); - } - } - return true; -} - -bool CryptoWalletsInfoBarDelegate::Cancel() { - content::WebContents* web_contents = - InfoBarService::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(BraveWalletWeb3ProviderTypes::NONE)); - return true; - } - Browser* browser = chrome::FindBrowserWithWebContents(web_contents); - brave::ShowExtensionSettings(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 ff9645870500..000000000000 --- a/browser/infobars/crypto_wallets_infobar_delegate.h +++ /dev/null @@ -1,53 +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/macros.h" -#include "base/strings/string16.h" -#include "components/infobars/core/confirm_infobar_delegate.h" -#include "url/gurl.h" - -class InfoBarService; -class PrefService; - -namespace content { -class WebContents; -} - -// 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(InfoBarService* infobar_service, InfobarSubType subtype); - - private: - explicit CryptoWalletsInfoBarDelegate(InfobarSubType subtype); - ~CryptoWalletsInfoBarDelegate() override; - - void OnCryptoWalletsLoaded(content::WebContents*); - bool ShouldShowLazyLoadInfobar(); - infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; - const gfx::VectorIcon& GetVectorIcon() const override; - void InfoBarDismissed() override; - base::string16 GetMessageText() const override; - int GetButtons() const override; - base::string16 GetButtonLabel(InfoBarButton button) const override; - base::string16 GetLinkText() const override; - GURL GetLinkURL() const override; - bool Accept() override; - bool Cancel() override; - - InfobarSubType subtype_; - - DISALLOW_COPY_AND_ASSIGN(CryptoWalletsInfoBarDelegate); -}; - -#endif // BRAVE_BROWSER_INFOBARS_CRYPTO_WALLETS_INFOBAR_DELEGATE_H_ diff --git a/common/extensions/api/brave_wallet.json b/common/extensions/api/brave_wallet.json index af7530fdf47d..cd9060583bd1 100644 --- a/common/extensions/api/brave_wallet.json +++ b/common/extensions/api/brave_wallet.json @@ -13,16 +13,6 @@ ], "functions": [ { - "name": "promptToEnableWallet", - "type": "function", - "description": "Called when website detects a Dapp", - "parameters": [ - { - "name": "tabID", - "type": "integer" - } - ] - }, { "name": "ready", "type": "function", "description": "Called by Crypto Wallets when it is ready", @@ -43,22 +33,6 @@ ] } ] - }, { - "name": "shouldCheckForDapps", - "type": "function", - "description": "Called to determine if dapp detection should be performed", - "parameters": [ - { - "type": "function", - "name": "callback", - "parameters": [ - { - "name": "dappDetection", - "type": "boolean" - } - ] - } - ] }, { "name": "getWalletSeed", "type": "function", diff --git a/components/brave_extension/extension/brave_extension/BUILD.gn b/components/brave_extension/extension/brave_extension/BUILD.gn index 2e0e84155c1e..280c6d356ddc 100644 --- a/components/brave_extension/extension/brave_extension/BUILD.gn +++ b/components/brave_extension/extension/brave_extension/BUILD.gn @@ -8,7 +8,6 @@ transpile_web_ui("brave_extension") { ["brave_extension", rebase_path("braveShieldsPanel.tsx")], ["brave_extension_background", rebase_path("background.ts")], ["content", rebase_path("content.ts")], - ["content_dapps", rebase_path("content_dapps.ts")], ["content_cosmetic", rebase_path("content_cosmetic.ts")], ["webstore", rebase_path("webstore.ts")], ] diff --git a/components/brave_extension/extension/brave_extension/background/events.ts b/components/brave_extension/extension/brave_extension/background/events.ts index ca4fde5abb49..0bfcfd00f896 100644 --- a/components/brave_extension/extension/brave_extension/background/events.ts +++ b/components/brave_extension/extension/brave_extension/background/events.ts @@ -9,7 +9,3 @@ require('./events/runtimeEvents') require('./events/webNavigationEvents') require('./events/cosmeticFilterEvents') require('./events/settingsEvents') -// Only do detection events if the wallet API is available -if (chrome.braveWallet) { - require('./events/dappDetectionEvents') -} diff --git a/components/brave_extension/extension/brave_extension/background/events/dappDetectionEvents.ts b/components/brave_extension/extension/brave_extension/background/events/dappDetectionEvents.ts deleted file mode 100644 index f3e0da89a6dd..000000000000 --- a/components/brave_extension/extension/brave_extension/background/events/dappDetectionEvents.ts +++ /dev/null @@ -1,16 +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/. */ - -// content script listener for dapp detection. -chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { - switch (msg.type) { - case 'dappAvailable': { - if (sender.frameId === 0 && sender.tab) { - chrome.braveWallet.promptToEnableWallet(sender.tab.id) - } - break - } - } -}) diff --git a/components/brave_extension/extension/brave_extension/background/reducers.ts b/components/brave_extension/extension/brave_extension/background/reducers.ts index a72120fde8fa..75a8e6cefd15 100644 --- a/components/brave_extension/extension/brave_extension/background/reducers.ts +++ b/components/brave_extension/extension/brave_extension/background/reducers.ts @@ -5,11 +5,9 @@ import { combineReducers } from 'redux' import shieldsPanelReducer from './reducers/shieldsPanelReducer' -import dappDetectionReducer from './reducers/dappDetectionReducer' import runtimeReducer from './reducers/runtimeReducer' export default combineReducers({ shieldsPanel: shieldsPanelReducer, - dappDetection: dappDetectionReducer, runtime: runtimeReducer }) diff --git a/components/brave_extension/extension/brave_extension/background/reducers/dappDetectionReducer.ts b/components/brave_extension/extension/brave_extension/background/reducers/dappDetectionReducer.ts deleted file mode 100644 index 6fd5c2dce8d8..000000000000 --- a/components/brave_extension/extension/brave_extension/background/reducers/dappDetectionReducer.ts +++ /dev/null @@ -1,44 +0,0 @@ -/* 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/. */ - -import * as webNavigationTypes from '../../constants/webNavigationTypes' -import { isHttpOrHttps } from '../../helpers/urlUtils' -import { Actions } from '../../types/actions/index' - -export default function dappDetectionReducer (state = {}, action: Actions) { - switch (action.type) { - case webNavigationTypes.ON_COMMITTED: { - let blacklistedHost - try { - // The Dapp detection will be gone soon, but this will remove some false positives. - const host = new URL(action.url).host - blacklistedHost = ['google.com', 'nytimes.com'] - .reduce((accumulator, currentValue) => accumulator || host.endsWith(currentValue), false) - } catch (e) { - blacklistedHost = true - } - - if (chrome.braveWallet && action.isMainFrame && isHttpOrHttps(action.url) && - !blacklistedHost) { - chrome.braveWallet.shouldCheckForDapps((dappDetection) => { - if (!dappDetection) { - return - } - chrome.tabs.executeScript(action.tabId, { - file: 'out/content_dapps.bundle.js', - allFrames: false, - runAt: 'document_start', - frameId: 0 - }, () => { - if (chrome.runtime.lastError) { - console.warn('Dapp detection inject via execute script received an error:', chrome.runtime.lastError) - } - }) - }) - } - break - } - } - return state -} diff --git a/components/brave_extension/extension/brave_extension/content_dapps.ts b/components/brave_extension/extension/brave_extension/content_dapps.ts deleted file mode 100644 index 24aa88c3a66b..000000000000 --- a/components/brave_extension/extension/brave_extension/content_dapps.ts +++ /dev/null @@ -1,102 +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/. */ - -// For dapp detection: -// Redefine window.ethereum so that when window.ethereum is accessed by the page, -// we'll insert a meta header to say that this is a dapp and ethereum is installed. -// If the page itself accesses window.ethereum within the first 2 seconds, and the -// wallet is not installed yet, then we'll prompt to install it. - -// Minified version of the comment block that follows -// generated with pbpaste | uglifyjs --compress --mangle | pbcopy -const code = `!function(){let e=!1;function n(){if(!e){const n=document.createElement("meta");n.name="dapp-detected",document.head.appendChild(n),e=!0}}if(window.hasOwnProperty("ethereum")){if(window.__disableDappDetectionInsertion=!0,void 0===window.ethereum)return;n()}else{var t=window.ethereum;Object.defineProperty(window,"ethereum",{configurable:!0,enumerable:!1,set:function(e){window.__disableDappDetectionInsertion||n(),t=e},get:function(){if(!window.__disableDappDetectionInsertion){const e=arguments.callee;e&&e.caller&&e.caller.toString&&-1!==e.caller.toString().indexOf("getOwnPropertyNames")||n()}return t}})}}();` // NOLINT - -/* -const code = ` -(function() { - let alreadyInsertedMetaTag = false - - function __insertDappDetected() { - if (!alreadyInsertedMetaTag) { - const meta = document.createElement('meta') - meta.name = 'dapp-detected' - document.head.appendChild(meta) - alreadyInsertedMetaTag = true - } - } - - if (window.hasOwnProperty('ethereum')) { - // A closure can't be used for __disableDappDetectionInsertion var - // because some sites like www.wnyc.org do a second script execution - // via eval for some reason. - window.__disableDappDetectionInsertion = true - if (window.ethereum === undefined) { - return - } - __insertDappDetected() - } else { - // Likely oldEthereum is undefined and it has a property only because - // we defined it. Some sites like wnyc.org are evaling all scripts - // that exist again, so this is protection against multiple calls. - var oldEthereum = window.ethereum - Object.defineProperty(window, 'ethereum', { - configurable: true, - enumerable: false, - set: function (val) { - if (!window.__disableDappDetectionInsertion) - __insertDappDetected() - oldEthereum = val - }, - get: function () { - if (!window.__disableDappDetectionInsertion) { - // a special check to only detect when window.ethereum is used - // "explicitly", instead of accessed dynamically / enumerated through - // Object.getOwnPropertyNames - // - // getOwnPropertyNames will unfortunately enumerate propery names even when a property's - // enumerable flag is false :( - // - // this code will admittedly check source around the call site when source is available - // -- this is acknowledged to be a kludge. - // - // we want to err on the side of not showing this info bar, so adding some potential - // "false positives" here is not necessarily a bad thing. - // - // also, bbondy told me to do it. - // - mcu - // - const callee = arguments.callee - if (!callee || !callee.caller || !callee.caller.toString || - callee.caller.toString().indexOf('getOwnPropertyNames') === -1) { - __insertDappDetected() - } - } - return oldEthereum - } - }) - } -})() -`*/ - -// We need this script inserted as early as possible even before the load -// We can't check if ethereum exists here because this is an isolated world. -if (!document.querySelector('script[data-dapp-detection]')) { - const scriptEl = document.createElement('script') - scriptEl.dataset.dappDetection = '' - scriptEl.textContent = code; - (document.head || document.documentElement).appendChild(scriptEl) - - // If a website tries to access window.ethereum within the first 2 seconds, - // then we prompt to install Brave Crypto Wallets. - // If a website does not try to access window.ethereum, then we will not prompt. - window.setTimeout(() => { - const isDapp = document.querySelector('meta[name="dapp-detected"]') - if (isDapp) { - chrome.runtime.sendMessage({ - type: 'dappAvailable' - }) - } - }, 2000) -} diff --git a/components/brave_wallet/brave_wallet_constants.h b/components/brave_wallet/brave_wallet_constants.h index bfdfa3a5e4c1..e0a1f230eaff 100644 --- a/components/brave_wallet/brave_wallet_constants.h +++ b/components/brave_wallet/brave_wallet_constants.h @@ -6,7 +6,7 @@ #ifndef BRAVE_COMPONENTS_BRAVE_WALLET_BRAVE_WALLET_CONSTANTS_H_ #define BRAVE_COMPONENTS_BRAVE_WALLET_BRAVE_WALLET_CONSTANTS_H_ -enum class BraveWalletWeb3ProviderTypes { ASK, NONE, CRYPTO_WALLETS, METAMASK }; +enum class BraveWalletWeb3ProviderTypes { ASK_OBSOLETE, NONE, CRYPTO_WALLETS, METAMASK }; extern const char ethereum_remote_client_extension_id[]; extern const char ethereum_remote_client_extension_name[]; diff --git a/components/definitions/chromel.d.ts b/components/definitions/chromel.d.ts index 1cf7a1f0326f..813e7ffc0719 100644 --- a/components/definitions/chromel.d.ts +++ b/components/definitions/chromel.d.ts @@ -304,9 +304,7 @@ declare namespace chrome.braveShields { } declare namespace chrome.braveWallet { - const promptToEnableWallet: (tabId: number | undefined) => void const ready: () => void - const shouldCheckForDapps: (callback: (dappDetection: boolean) => void) => void const shouldPromptForSetup: (callback: (dappDetection: boolean) => void) => void const loadUI: (callback: () => void) => void } diff --git a/components/test/testData.ts b/components/test/testData.ts index 854b0bd89f36..6512f03cdd17 100644 --- a/components/test/testData.ts +++ b/components/test/testData.ts @@ -343,7 +343,6 @@ export const window = () => { } export const initialState = deepFreeze({ - dappDetection: {}, runtime: {}, shieldsPanel: { currentWindowId: -1, diff --git a/test/data/extensions/api_test/braveShieldsWithWallet/background.js b/test/data/extensions/api_test/braveShieldsWithWallet/background.js index 6a475cc9d2b1..7555c5c2bcff 100644 --- a/test/data/extensions/api_test/braveShieldsWithWallet/background.js +++ b/test/data/extensions/api_test/braveShieldsWithWallet/background.js @@ -16,31 +16,3 @@ function testBasics() { }, ]); } - -function testNoDappCheck() { - chrome.test.runTests([ - function testNotENabled() { - chrome.braveWallet.shouldCheckForDapps((dappDetection) => { - if (dappDetection) { - chrome.test.fail(); - } else { - chrome.test.succeed(); - } - }) - }, - ]); -} - -function testDappCheck() { - chrome.test.runTests([ - function testNotENabled() { - chrome.braveWallet.shouldCheckForDapps((dappDetection) => { - if (dappDetection) { - chrome.test.succeed(); - } else { - chrome.test.fail(); - } - }) - }, - ]); -} diff --git a/test/data/extensions/api_test/braveWallet/background.js b/test/data/extensions/api_test/braveWallet/background.js index 5dd7cd1db972..4ad3e19d08fc 100644 --- a/test/data/extensions/api_test/braveWallet/background.js +++ b/test/data/extensions/api_test/braveWallet/background.js @@ -105,20 +105,6 @@ function testProviderIsMetaMask() { ]) } -function testProviderIsAsk() { - chrome.test.runTests([ - function CryptoWalletsIsProvider() { - chrome.braveWallet.getWeb3Provider((provider) => { - if (provider.length === 0) { - chrome.test.succeed(); - } else { - chrome.test.fail(); - } - }) - } - ]) -} - function testProviderIsNone() { chrome.test.runTests([ function CryptoWalletsIsProvider() { @@ -138,8 +124,7 @@ function testBasics() { function braveWalletExtensionHasAccess() { if (chrome.braveWallet && chrome.braveWallet.shouldPromptForSetup && - chrome.braveWallet.loadUI && - chrome.braveWallet.promptToEnableWallet) { + chrome.braveWallet.loadUI) { chrome.test.succeed(); } else { chrome.test.fail();