diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index 7f21b4e4b4e3..54e0eb8eb6dd 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -54,7 +54,6 @@ #include "brave/components/body_sniffer/body_sniffer_throttle.h" #include "brave/components/brave_federated/features.h" #include "brave/components/brave_rewards/browser/rewards_protocol_navigation_throttle.h" -#include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/brave_search/browser/brave_search_default_host.h" #include "brave/components/brave_search/browser/brave_search_default_host_private.h" #include "brave/components/brave_search/browser/brave_search_fallback_host.h" @@ -1171,12 +1170,10 @@ BraveContentBrowserClient::CreateThrottlesForNavigation( // navigation happens content::BrowserContext* context = handle->GetWebContents()->GetBrowserContext(); - PrefService* pref_service = user_prefs::UserPrefs::Get(context); - if (pref_service->GetBoolean(brave_rewards::prefs::kEnabled)) { - throttles.insert( - throttles.begin(), - std::make_unique( - handle)); + + if (auto rewards_throttle = brave_rewards::RewardsProtocolNavigationThrottle:: + MaybeCreateThrottleFor(handle)) { + throttles.insert(throttles.begin(), std::move(rewards_throttle)); } #if !BUILDFLAG(IS_ANDROID) diff --git a/components/brave_rewards/browser/BUILD.gn b/components/brave_rewards/browser/BUILD.gn index 3ec2f42a30c3..26a8478c2d44 100644 --- a/components/brave_rewards/browser/BUILD.gn +++ b/components/brave_rewards/browser/BUILD.gn @@ -52,6 +52,7 @@ static_library("browser") { "//components/os_crypt/sync:os_crypt", "//components/prefs", "//components/sessions", + "//components/user_prefs", "//content/public/browser", "//extensions/buildflags", "//mojo/public/cpp/bindings", diff --git a/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc b/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc index 98a9b090124c..c00434f30722 100644 --- a/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc +++ b/components/brave_rewards/browser/rewards_protocol_navigation_throttle.cc @@ -15,7 +15,11 @@ #include "base/strings/strcat.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" +#include "brave/components/brave_rewards/common/pref_names.h" #include "brave/components/brave_rewards/core/buildflags.h" +#include "components/prefs/pref_service.h" +#include "components/user_prefs/user_prefs.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_throttle.h" @@ -33,6 +37,19 @@ using content::WebContents; namespace brave_rewards { +// static +std::unique_ptr +RewardsProtocolNavigationThrottle::MaybeCreateThrottleFor( + content::NavigationHandle* navigation_handle) { + auto* pref_service = user_prefs::UserPrefs::Get( + navigation_handle->GetWebContents()->GetBrowserContext()); + if (!pref_service->GetBoolean(brave_rewards::prefs::kEnabled)) { + return nullptr; + } + + return std::make_unique(navigation_handle); +} + RewardsProtocolNavigationThrottle::RewardsProtocolNavigationThrottle( NavigationHandle* handle) : NavigationThrottle(handle) {