Skip to content

Commit

Permalink
Merge pull request #10225 from brave/pr10191_default-wallet_1.31.x
Browse files Browse the repository at this point in the history
Add new default wallet handling - deprecate Dapp detection and lazy load Crypto Wallets (uplift to 1.31.x)
  • Loading branch information
kjozwiak authored Sep 27, 2021
2 parents 3fcbb84 + 42bdbc0 commit 4138679
Show file tree
Hide file tree
Showing 33 changed files with 48 additions and 815 deletions.
10 changes: 2 additions & 8 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,8 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_BRAVE_WALLET_WEB3_PROVIDER_METAMASK" desc="Select control value for which web3 provider to use">
MetaMask
</message>
<message name="IDS_SETTINGS_BRAVE_WEB3_PROVIDER_DESC" desc="The description for Brave web3 provider select control in settings">
Ethereum provider for using Dapps
</message>
<message name="IDS_SETTINGS_LOAD_CRYPTO_WALLETS_ON_STARTUP" desc="The description for always loading the Crypto Wallets extension on startup">
Load Crypto Wallets on startup
</message>
<message name="IDS_SETTINGS_LOAD_CRYPTO_WALLETS_ON_STARTUP_DEPRECATED" desc="The description for always loading the Crypto Wallets extension on startup">
Load deprecated Crypto Wallets extension on startup
<message name="IDS_SETTINGS_DEFAULT_WALLET_DESC" desc="The default cryptocurrency wallet">
Default cryptocurrency wallet
</message>
<message name="IDS_SETTINGS_SHOW_BRAVE_WALLET_ICON_ON_TOOLBAR" desc="The description for showing the Brave wallet panel icon on the toolbar">
Show Brave Wallet icon on toolbar
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 @@ -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"
Expand Down
30 changes: 19 additions & 11 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions browser/brave_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion browser/ethereum_remote_client/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
1 change: 0 additions & 1 deletion browser/ethereum_remote_client/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
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 @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -53,46 +51,6 @@ base::Value MakeSelectValue(const std::u16string& 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)));
}

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()) {
Expand Down Expand Up @@ -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.
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 @@ -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)
Expand Down
Loading

0 comments on commit 4138679

Please sign in to comment.