* Add enable_brave_wallet GN variable and build flag This adds a new GN build flag 'enable_brave_wallet' that can be set to false to exclude Brave Wallet from the build. The flag is true by default to maintain current behavior. Changes include: - Add enable_brave_wallet declare_args in build/config/BUILDCONFIG.gn - Create brave_wallet/common/buildflags with ENABLE_BRAVE_WALLET flag - Update all BUILD.gn and sources.gni files to use the new flag - Add wallet buildflags dependencies via minimal one-line imports * Add patches for wallet buildflags in Chromium BUILD files Adds minimal one-line patches to import wallet buildflags dependencies in Chromium source files. This allows Chromium code to conditionally depend on wallet headers. Patches: - chrome/browser/ui/hid/BUILD.gn - net/BUILD.gn - third_party/blink/common/BUILD.gn - third_party/blink/public/common/BUILD.gn - third_party/blink/renderer/modules/permissions/BUILD.gn * Guard wallet code in Chromium source overrides Updates chromium_src overrides to conditionally compile wallet-related code based on enable_brave_wallet flag. This includes: - Adding DEPS files to allow buildflags dependencies - Guarding wallet permission handling with #if BUILDFLAG(ENABLE_BRAVE_WALLET) - Keeping wallet permission enum values unconditionally to maintain profile interchangeability between wallet-enabled and wallet-disabled builds - Updating component registration and preference handling Key changes: - Permission enums remain stable across build configs for UMA and persistence - Wallet permission handling code only compiled when wallet enabled - DEPS files updated to allow buildflags includes * Guard wallet UI code in front-end TypeScript and Mojom Conditionally compiles wallet-related UI code in TypeScript and Mojom interfaces based on enable_brave_wallet preprocessor flag. Changes: - Settings menu: Use lastInserted pattern for menu item ordering - Page visibility: Guard wallet page visibility checks - Browser commands: Guard wallet command handling - Routes: Conditionally include wallet routes - Add non-null assertions for DOM insertions in TypeScript - Update Mojom interfaces to conditionally include wallet enums Front-end code uses <if expr="enable_brave_wallet"> preprocessor directives to exclude wallet UI when the feature is disabled. * Guard wallet usage in non-wallet Brave code Conditionally compiles wallet-related code in non-wallet Brave files based on enable_brave_wallet build flag. Changes include: - browser/: Guard wallet service factories, preferences, and helpers - components/: Guard wallet dependencies in rewards, sidebar, and DNS - renderer/: Conditionally register wallet content settings - utility/: Guard wallet component registration - ios/: Add optional chaining for wallet feature flags - test/: Guard wallet-related test code Key files: - brave_stats_updater.cc: Guard wallet pref registration with #if - brave_profile_prefs.cc: Conditionally register wallet preferences - sidebar_service.cc: Guard wallet panel items - iOS WalletConstants.swift: Use optional chaining for feature checks This allows building Brave without wallet while maintaining profile compatibility between wallet-enabled and wallet-disabled builds. * Add static_assert for ENABLE_BRAVE_WALLET in wallet headers Adds compile-time assertions to wallet headers to ensure they are only included when wallet is enabled. This prevents accidental usage of wallet APIs when enable_brave_wallet=false. Added static_assert(BUILDFLAG(ENABLE_BRAVE_WALLET)) to: browser/brave_wallet/ (11 files): - asset_ratio_service_factory.h - brave_wallet_context_utils.h - brave_wallet_ipfs_service_factory.h - brave_wallet_provider_delegate_impl.h - brave_wallet_service_factory.h - brave_wallet_tab_helper.h - meld_integration_service_factory.h - wallet_notification_service_factory.h - simulation_service_factory.h - swap_service_factory.h - wallet_data_files_installer_delegate_impl.h components/brave_wallet/browser/ (15 files): - brave_wallet_p3a_private.h - brave_wallet_prefs.h - brave_wallet_service.h - brave_wallet_utils.h - ens_resolver_task.h - json_rpc_service_test_utils.h - json_rpc_service.h - keyring_service_observer_base.h - keyring_service.h - network_manager.h - permission_utils.h - pref_names.h - test_utils.h - tx_service.h - wallet_data_files_installer.h components/brave_wallet/common/ (6 files): - brave_wallet_types.h - common_utils.h - eth_abi_utils.h - features.h - hex_utils.h - pref_names.h Also includes minor wallet code updates to use buildflags and guard zcash-specific test code. * Follow up fixes after Parts 1-7
95 lines
3.2 KiB
C++
95 lines
3.2 KiB
C++
/* Copyright (c) 2021 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_PROFILES_BRAVE_RENDERER_UPDATER_H_
|
|
#define BRAVE_BROWSER_PROFILES_BRAVE_RENDERER_UPDATER_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "base/memory/raw_ptr.h"
|
|
#include "brave/common/brave_renderer_configuration.mojom-forward.h"
|
|
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
|
|
#include "brave/components/tor/buildflags/buildflags.h"
|
|
#include "components/keyed_service/core/keyed_service.h"
|
|
#include "components/prefs/pref_change_registrar.h"
|
|
#include "components/prefs/pref_member.h"
|
|
#include "mojo/public/cpp/bindings/associated_remote.h"
|
|
|
|
class Profile;
|
|
|
|
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
namespace brave_wallet {
|
|
class KeyringService;
|
|
}
|
|
#endif // BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
|
|
namespace content {
|
|
class RenderProcessHost;
|
|
}
|
|
|
|
class BraveRendererUpdater : public KeyedService {
|
|
public:
|
|
BraveRendererUpdater(Profile* profile,
|
|
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
brave_wallet::KeyringService* keyring_service,
|
|
#endif
|
|
PrefService* local_state);
|
|
BraveRendererUpdater(const BraveRendererUpdater&) = delete;
|
|
BraveRendererUpdater& operator=(const BraveRendererUpdater&) = delete;
|
|
~BraveRendererUpdater() override;
|
|
|
|
// Initialize a newly-started renderer process.
|
|
void InitializeRenderer(content::RenderProcessHost* render_process_host);
|
|
|
|
private:
|
|
std::vector<mojo::AssociatedRemote<brave::mojom::BraveRendererConfiguration>>
|
|
GetRendererConfigurations();
|
|
|
|
mojo::AssociatedRemote<brave::mojom::BraveRendererConfiguration>
|
|
GetRendererConfiguration(content::RenderProcessHost* render_process_host);
|
|
|
|
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
// Update renderers if wallet keyring has been initialized
|
|
void CheckActiveWalletAndMaybeUpdateRenderers();
|
|
|
|
// Update active wallet bool, returns true if status has changed
|
|
bool CheckActiveWallet();
|
|
#endif // BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
|
|
// Update all renderers due to a configuration change.
|
|
void UpdateAllRenderers();
|
|
|
|
// Update the given renderer due to a configuration change.
|
|
void UpdateRenderer(
|
|
mojo::AssociatedRemote<brave::mojom::BraveRendererConfiguration>*
|
|
renderer_configuration);
|
|
|
|
raw_ptr<Profile> profile_ = nullptr;
|
|
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
raw_ptr<brave_wallet::KeyringService> keyring_service_ = nullptr;
|
|
#endif
|
|
raw_ptr<PrefService> local_state_ = nullptr;
|
|
PrefChangeRegistrar pref_change_registrar_;
|
|
PrefChangeRegistrar local_state_change_registrar_;
|
|
|
|
// Prefs that we sync to the renderers.
|
|
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
IntegerPrefMember brave_wallet_ethereum_provider_;
|
|
IntegerPrefMember brave_wallet_solana_provider_;
|
|
IntegerPrefMember brave_wallet_cardano_provider_;
|
|
#endif
|
|
BooleanPrefMember de_amp_enabled_;
|
|
#if BUILDFLAG(ENABLE_TOR)
|
|
BooleanPrefMember onion_only_in_tor_windows_;
|
|
#endif
|
|
BooleanPrefMember widevine_enabled_;
|
|
#if BUILDFLAG(ENABLE_BRAVE_WALLET)
|
|
bool is_wallet_allowed_for_context_ = false;
|
|
bool is_wallet_created_ = false;
|
|
#endif
|
|
};
|
|
|
|
#endif // BRAVE_BROWSER_PROFILES_BRAVE_RENDERER_UPDATER_H_
|