Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing dapp detection, crypto wallets infobar #7321

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,6 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_WEBTORRENT_ENABLED_DESC" desc="The description for WebTorrent switch in settings">
Uses WebTorrent to display torrents directly in the browser. Supports torrent files and magnet links.
</message>
<message name="IDS_BRAVE_WALLET_WEB3_PROVIDER_ASK" desc="Select control value for which web3 provider to use">
Ask
</message>
<message name="IDS_BRAVE_WALLET_WEB3_PROVIDER_NONE" desc="Select control value for which web3 provider to use">
None
</message>
Expand Down Expand Up @@ -940,25 +937,6 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_BRAVE_P3A_ENABLE_SETTING_SUBITEM" desc="Description that shows under main toggle setting for P3A">
This anonymous info only lets Brave estimate the overall usage of certain features.
</message>
<!-- Web3 detection -->
<message name="IDS_BRAVE_CRYPTO_WALLETS_LAZY_LOAD_TEXT" desc="Text that shows on the info bar when a Dapp is detected">
Would you like to start Crypto Wallets for Ethereum support?
</message>
<message name="IDS_BRAVE_CRYPTO_WALLETS_INFOBAR_TEXT" desc="Text that shows on the info bar when a Dapp is detected">
Set up Crypto Wallets to interact with this app and others like it.
</message>
<message name="IDS_BRAVE_CRYPTO_WALLETS_SETUP_CRYPTO_WALLETS" desc="Setup Crypto Wallets">
Setup Crypto Wallets
</message>
<message name="IDS_BRAVE_CRYPTO_WALLETS_START_AND_RELOAD" desc="Start Crypto Wallets and reload">
Start Crypto Wallets and reload
</message>
<message name="IDS_BRAVE_CRYPTO_WALLETS_SETTINGS" desc="Open Crypto Wallets settings">
Settings
</message>
<message name="IDS_BRAVE_CRYPTO_WALLETS_DONT_ASK" desc="Sets provider to none">
Don't ask again
</message>
<!-- IPFS -->
<message name="IDS_BRAVE_IPFS_INSTALL" desc="Install IPFS daemon infobar text">
IPFS resources detected. Would you like Brave to load them using a local IPFS node?
Expand Down
1 change: 0 additions & 1 deletion browser/brave_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterStringPref(kBraveWalletEncryptedSeed, "");
registry->RegisterIntegerPref(
kBraveWalletWeb3Provider,
static_cast<int>(BraveWalletWeb3ProviderTypes::ASK));
static_cast<int>(BraveWalletWeb3ProviderTypes::NONE));
registry->RegisterBooleanPref(kLoadCryptoWalletsOnStartup, false);
registry->RegisterBooleanPref(kOptedIntoCryptoWallets, false);
#endif
Expand Down
7 changes: 4 additions & 3 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(BraveWalletWeb3ProviderTypes::ASK));
EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
kLoadCryptoWalletsOnStartup));
static_cast<int>(BraveWalletWeb3ProviderTypes::NONE));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(
kLoadCryptoWalletsOnStartup));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kOptedIntoCryptoWallets));
#endif
Expand Down
66 changes: 0 additions & 66 deletions browser/extensions/api/brave_wallet_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -50,46 +48,6 @@ base::Value MakeSelectValue(const base::string16& name,
namespace extensions {
namespace api {

ExtensionFunction::ResponseAction
BraveWalletPromptToEnableWalletFunction::Run() {
std::unique_ptr<brave_wallet::PromptToEnableWallet::Params> 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()) {
Expand Down Expand Up @@ -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<BraveWalletWeb3ProviderTypes>(
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.
Expand Down Expand Up @@ -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));
Expand Down
19 changes: 0 additions & 19 deletions browser/extensions/api/brave_wallet_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
119 changes: 2 additions & 117 deletions browser/extensions/api/brave_wallet_api_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand All @@ -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<base::RunLoop>();
infobar_added_run_loop_->Run();
}

void WaitForTabCount(int expected) {
while (browser()->tab_strip_model()->count() != expected)
base::RunLoop().RunUntilIdle();
Expand Down Expand Up @@ -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(),
Expand All @@ -158,65 +100,8 @@ class BraveWalletAPIBrowserTest : public InProcessBrowserTest,

private:
scoped_refptr<const extensions::Extension> extension_;
ScopedObserver<InfoBarManager, InfoBarManager::Observer>
infobar_observer_;
bool infobar_added_;
std::unique_ptr<base::RunLoop> 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<BraveWalletWeb3ProviderTypes>(
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<BraveWalletWeb3ProviderTypes>(
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<BraveWalletWeb3ProviderTypes>(
browser()->profile()->GetPrefs()->GetInteger(kBraveWalletWeb3Provider));
ASSERT_EQ(provider_after, BraveWalletWeb3ProviderTypes::NONE);
RemoveInfoBarObserver(infobar_service);
}

IN_PROC_BROWSER_TEST_F(BraveWalletAPIBrowserTest,
FakeInstallMetaMask) {
WaitForBraveExtensionAdded();
Expand Down
Loading