diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+TabObserver.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+TabObserver.swift index 23fa5d72003..98147deb8ab 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+TabObserver.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BVC+TabObserver.swift @@ -72,6 +72,7 @@ extension BrowserViewController: TabObserver { // dismiss wallet notification (e.g. after redirect to different origin) removeWalletNotificationAndClearOrigin() } else if FeatureList.kBraveWalletWebUIIOS?.enabled == true, + profileController.braveWalletAPI.isAllowed, let selectedTabVisibleURL = selectedTab.visibleURL, selectedTabVisibleURL.isWalletWebUIURL { diff --git a/ios/browser/ui/webui/BUILD.gn b/ios/browser/ui/webui/BUILD.gn index a88b152ed31..064efaa1ede 100644 --- a/ios/browser/ui/webui/BUILD.gn +++ b/ios/browser/ui/webui/BUILD.gn @@ -4,6 +4,9 @@ # You can obtain one at https://mozilla.org/MPL/2.0/. import("//brave/build/config.gni") +import("//brave/components/ai_chat/core/common/buildflags/buildflags.gni") +import("//brave/components/brave_ads/buildflags/buildflags.gni") +import("//brave/components/brave_wallet/common/buildflags/buildflags.gni") import("//build/config/features.gni") import("//mojo/public/tools/bindings/mojom.gni") @@ -15,17 +18,13 @@ source_set("webui") { deps = [ "//base", - "//brave/components/ai_chat/core/common", + "//brave/components/ai_chat/core/common/buildflags", "//brave/components/brave_account:features", - "//brave/components/brave_wallet/common", - "//brave/components/brave_wallet/common:common_constants", + "//brave/components/brave_ads/buildflags", + "//brave/components/brave_wallet/common/buildflags", "//brave/components/constants", "//brave/components/webui", - "//brave/ios/browser/brave_wallet", - "//brave/ios/browser/ui/webui/ads", - "//brave/ios/browser/ui/webui/ai_chat", "//brave/ios/browser/ui/webui/brave_account", - "//brave/ios/browser/ui/webui/brave_wallet", "//brave/ios/browser/ui/webui/skus", "//brave/ios/web/webui", "//components/prefs", @@ -39,6 +38,28 @@ source_set("webui") { "//ui/base", "//url", ] + + if (enable_ai_chat) { + deps += [ + "//brave/components/ai_chat/core/browser", + "//brave/components/ai_chat/core/common", + "//brave/ios/browser/ui/webui/ai_chat", + ] + } + + if (enable_brave_ads) { + deps += [ "//brave/ios/browser/ui/webui/ads" ] + } + + if (enable_brave_wallet) { + deps += [ + "//brave/components/brave_wallet/browser", + "//brave/components/brave_wallet/common", + "//brave/components/brave_wallet/common:common_constants", + "//brave/ios/browser/brave_wallet", + "//brave/ios/browser/ui/webui/brave_wallet", + ] + } } source_set("data_sources") { diff --git a/ios/browser/ui/webui/DEPS b/ios/browser/ui/webui/DEPS index a3329a676ef..85cb3b10d03 100644 --- a/ios/browser/ui/webui/DEPS +++ b/ios/browser/ui/webui/DEPS @@ -1,7 +1,10 @@ include_rules = [ "+brave/components/ai_chat/core/common", "+brave/components/brave_account/features.h", + "+brave/components/brave_ads", "+brave/components/brave_private_cdn", + "+brave/components/brave_rewards", + "+brave/components/brave_wallet/browser", "+brave/components/brave_wallet/common", "+brave/components/constants", "+brave/components/webui", diff --git a/ios/browser/ui/webui/brave_web_ui_controller_factory.mm b/ios/browser/ui/webui/brave_web_ui_controller_factory.mm index 47c89d78dca..b2f1a37f5b3 100644 --- a/ios/browser/ui/webui/brave_web_ui_controller_factory.mm +++ b/ios/browser/ui/webui/brave_web_ui_controller_factory.mm @@ -10,29 +10,45 @@ #include "base/feature_list.h" #include "base/memory/ptr_util.h" #include "base/no_destructor.h" -#include "brave/components/ai_chat/core/common/features.h" +#include "brave/components/ai_chat/core/common/buildflags/buildflags.h" #include "brave/components/brave_account/features.h" -#include "brave/components/brave_wallet/common/common_utils.h" -#include "brave/components/brave_wallet/common/web_ui_constants.h" +#include "brave/components/brave_ads/buildflags/buildflags.h" +#include "brave/components/brave_wallet/common/buildflags/buildflags.h" #include "brave/components/constants/pref_names.h" #include "brave/components/constants/url_constants.h" -#include "brave/ios/browser/ui/webui/ads/ads_internals_ui.h" -#include "brave/ios/browser/ui/webui/ai_chat/ai_chat_ui.h" -#include "brave/ios/browser/ui/webui/ai_chat/ai_chat_untrusted_conversation_ui.h" #include "brave/ios/browser/ui/webui/brave_account/brave_account_ui_ios.h" -#include "brave/ios/browser/ui/webui/brave_wallet/line_chart_ui.h" -#include "brave/ios/browser/ui/webui/brave_wallet/market_ui.h" -#include "brave/ios/browser/ui/webui/brave_wallet/nft_ui.h" -#include "brave/ios/browser/ui/webui/brave_wallet/wallet_page_ui.h" #include "brave/ios/browser/ui/webui/skus/skus_internals_ui.h" #include "build/build_config.h" #include "components/prefs/pref_service.h" +#include "ios/chrome/browser/shared/model/profile/profile_ios.h" #include "ios/chrome/browser/shared/model/url/chrome_url_constants.h" #include "ios/components/webui/web_ui_url_constants.h" #include "ios/web/public/browser_state.h" #include "ios/web/public/web_state.h" #include "url/gurl.h" +#if BUILDFLAG(ENABLE_BRAVE_ADS) +#include "brave/components/brave_rewards/core/pref_names.h" +#include "brave/ios/browser/ui/webui/ads/ads_internals_ui.h" +#endif + +#if BUILDFLAG(ENABLE_AI_CHAT) +#include "brave/components/ai_chat/core/browser/utils.h" +#include "brave/components/ai_chat/core/common/features.h" +#include "brave/ios/browser/ui/webui/ai_chat/ai_chat_ui.h" +#include "brave/ios/browser/ui/webui/ai_chat/ai_chat_untrusted_conversation_ui.h" +#endif + +#if BUILDFLAG(ENABLE_BRAVE_WALLET) +#include "brave/components/brave_wallet/browser/brave_wallet_utils.h" +#include "brave/components/brave_wallet/common/common_utils.h" +#include "brave/components/brave_wallet/common/web_ui_constants.h" +#include "brave/ios/browser/ui/webui/brave_wallet/line_chart_ui.h" +#include "brave/ios/browser/ui/webui/brave_wallet/market_ui.h" +#include "brave/ios/browser/ui/webui/brave_wallet/nft_ui.h" +#include "brave/ios/browser/ui/webui/brave_wallet/wallet_page_ui.h" +#endif + using web::WebUIIOS; using web::WebUIIOSController; @@ -49,6 +65,46 @@ std::unique_ptr NewWebUIIOS(WebUIIOS* web_ui, return std::make_unique(web_ui, url); } +#if BUILDFLAG(ENABLE_BRAVE_ADS) +template <> +std::unique_ptr NewWebUIIOS( + WebUIIOS* web_ui, + const GURL& url) { + ProfileIOS* profile = ProfileIOS::FromWebUIIOS(web_ui); + if (profile->GetPrefs()->GetBoolean( + brave_rewards::prefs::kDisabledByPolicy)) { + return nullptr; + } + return std::make_unique(web_ui, url); +} +#endif + +#if BUILDFLAG(ENABLE_AI_CHAT) +template <> +std::unique_ptr NewWebUIIOS(WebUIIOS* web_ui, + const GURL& url) { + ProfileIOS* profile = ProfileIOS::FromWebUIIOS(web_ui); + if (profile->IsOffTheRecord() || + !ai_chat::IsAIChatEnabled(profile->GetPrefs())) { + return nullptr; + } + return std::make_unique(web_ui, url); +} +#endif + +#if BUILDFLAG(ENABLE_BRAVE_WALLET) +template <> +std::unique_ptr NewWebUIIOS(WebUIIOS* web_ui, + const GURL& url) { + ProfileIOS* profile = ProfileIOS::FromWebUIIOS(web_ui); + if (profile->IsOffTheRecord() || + !brave_wallet::IsAllowed(profile->GetPrefs())) { + return nullptr; + } + return std::make_unique(web_ui, url); +} +#endif + template std::unique_ptr NewRegularProfileOnlyWebUIIOS( WebUIIOS* web_ui, @@ -61,13 +117,16 @@ std::unique_ptr NewRegularProfileOnlyWebUIIOS( WebUIIOSFactoryFunction GetUntrustedWebUIIOSFactoryFunction(const GURL& url) { DCHECK(url.SchemeIs(kChromeUIUntrustedScheme)); - const std::string_view url_host = url.host(); + [[maybe_unused]] const std::string_view url_host = url.host(); +#if BUILDFLAG(ENABLE_AI_CHAT) if (url_host == kAIChatUntrustedConversationUIHost && ai_chat::features::IsAIChatWebUIEnabled()) { return &NewRegularProfileOnlyWebUIIOS; } +#endif +#if BUILDFLAG(ENABLE_BRAVE_WALLET) if (brave_wallet::IsWalletWebUIEnabled()) { if (url_host == kUntrustedNftHost) { return &NewRegularProfileOnlyWebUIIOS; @@ -77,6 +136,7 @@ WebUIIOSFactoryFunction GetUntrustedWebUIIOSFactoryFunction(const GURL& url) { return &NewRegularProfileOnlyWebUIIOS; } } +#endif return nullptr; } @@ -95,19 +155,27 @@ WebUIIOSFactoryFunction GetWebUIIOSFactoryFunction(const GURL& url) { } std::string_view url_host = url.host(); + +#if BUILDFLAG(ENABLE_BRAVE_ADS) if (url_host == kAdsInternalsHost) { return &NewWebUIIOS; - } else if (url_host == kBraveAccountHost && - brave_account::features::IsBraveAccountEnabled()) { + } +#endif + if (url_host == kBraveAccountHost && + brave_account::features::IsBraveAccountEnabled()) { return &NewWebUIIOS; } else if (url_host == kSkusInternalsHost) { return &NewWebUIIOS; +#if BUILDFLAG(ENABLE_AI_CHAT) } else if (url_host == kAIChatUIHost && ai_chat::features::IsAIChatWebUIEnabled()) { - return &NewRegularProfileOnlyWebUIIOS; + return &NewWebUIIOS; +#endif +#if BUILDFLAG(ENABLE_BRAVE_WALLET) } else if (url_host == kWalletPageHost && brave_wallet::IsWalletWebUIEnabled()) { - return &NewRegularProfileOnlyWebUIIOS; + return &NewWebUIIOS; +#endif } return nullptr; }