From 49f1aceee300e16218d0ffbb7011d2307a1424d2 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Fri, 3 Sep 2021 17:55:30 +0200 Subject: [PATCH] Migrate away from content::WebUI::RegisterDeprecatedMessageCallback() This is the second part of the migration started with the upgrade to Chromium 95.0.4628.3, which actually removes any usage of this method and replaces it with RegisterMessageCallback() + the proper callbacks. Chromium change: https://source.chromium.org/chromium/chromium/src/+/720e8acd2ca08ea8579b7d4438fe1a15cd577d2c commit 720e8acd2ca08ea8579b7d4438fe1a15cd577d2c Author: cammie Date: Wed Aug 25 19:15:45 2021 +0000 Code Health: Rename/replace content::WebUI::RegisterMessageCallback(). Special thanks to thestig@chromium.org for writing the original version of this patch at https://crrev.com/c/2496505. This CL renames the original RegisterMessageCallback() as RegisterDeprecatedMessageCallback() and adds a new version of RegisterMessageCallback() that passes a base::Value::ConstListView in the callback instead of const base::ListValue*, as base::ListValue is now deprecated. Most of the many callsites of the original RegisterMessageCallback() are converted to use RegisterDeprecatedMessageCallback() for the moment so that the migration to the new RegisterMessageCallback() can be split into future CLs (with tracking bug https://crbug.com/1243386). We do, however, use the new API in a couple spots (chrome/browser/ui/webui/crashes_ui.cc and chrome/browser/ui/webui/settings/chromeos/ambient_mode_handler.cc) to show that it works. We also update the examples for RegisterMessageCallback in docs/webui_explainer.md and docs/webui_in_components.md. AX-Relnotes: N/A. Bug: 1142540,1187062,1243386 --- browser/ui/webui/brave_adblock_ui.cc | 135 ++-- .../ui/webui/brave_rewards_internals_ui.cc | 122 ++- browser/ui/webui/brave_rewards_page_ui.cc | 720 ++++++++---------- browser/ui/webui/brave_tip_ui.cc | 175 ++--- browser/ui/webui/brave_welcome_ui.cc | 29 +- browser/ui/webui/ipfs_ui.cc | 54 +- browser/ui/webui/ipfs_ui.h | 18 +- .../brave_new_tab_message_handler.cc | 199 +++-- .../brave_new_tab_message_handler.h | 34 +- .../new_tab_page/top_sites_message_handler.cc | 76 +- .../new_tab_page/top_sites_message_handler.h | 16 +- .../settings/brave_appearance_handler.cc | 44 +- .../webui/settings/brave_appearance_handler.h | 8 +- .../brave_default_extensions_handler.cc | 144 ++-- .../brave_default_extensions_handler.h | 36 +- .../webui/settings/brave_privacy_handler.cc | 32 +- .../ui/webui/settings/brave_privacy_handler.h | 12 +- .../settings/brave_relaunch_handler_mac.h | 2 +- .../settings/brave_relaunch_handler_mac.mm | 4 +- .../ui/webui/settings/brave_sync_handler.cc | 107 ++- .../ui/webui/settings/brave_sync_handler.h | 12 +- .../settings/default_brave_shields_handler.cc | 131 ++-- .../settings/default_brave_shields_handler.h | 24 +- browser/ui/webui/tor_internals_ui.cc | 12 +- browser/ui/webui/tor_internals_ui.h | 4 +- browser/ui/webui/webcompat_reporter_ui.cc | 12 +- 26 files changed, 1020 insertions(+), 1142 deletions(-) diff --git a/browser/ui/webui/brave_adblock_ui.cc b/browser/ui/webui/brave_adblock_ui.cc index e00edabb4728..a49d5a115309 100644 --- a/browser/ui/webui/brave_adblock_ui.cc +++ b/browser/ui/webui/brave_adblock_ui.cc @@ -9,6 +9,7 @@ #include #include "base/scoped_observation.h" +#include "base/values.h" #include "brave/browser/brave_browser_process.h" #include "brave/browser/ui/webui/brave_webui_source.h" #include "brave/common/webui_url_constants.h" @@ -50,16 +51,16 @@ class AdblockDOMHandler void OnJavascriptDisallowed() override; private: - void HandleEnableFilterList(const base::ListValue* args); - void HandleGetCustomFilters(const base::ListValue* args); - void HandleGetRegionalLists(const base::ListValue* args); - void HandleGetListSubscriptions(const base::ListValue* args); - void HandleUpdateCustomFilters(const base::ListValue* args); - void HandleSubmitNewSubscription(const base::ListValue* args); - void HandleSetSubscriptionEnabled(const base::ListValue* args); - void HandleDeleteSubscription(const base::ListValue* args); - void HandleRefreshSubscription(const base::ListValue* args); - void HandleViewSubscriptionSource(const base::ListValue* args); + void HandleEnableFilterList(base::Value::ConstListView args); + void HandleGetCustomFilters(base::Value::ConstListView args); + void HandleGetRegionalLists(base::Value::ConstListView args); + void HandleGetListSubscriptions(base::Value::ConstListView args); + void HandleUpdateCustomFilters(base::Value::ConstListView args); + void HandleSubmitNewSubscription(base::Value::ConstListView args); + void HandleSetSubscriptionEnabled(base::Value::ConstListView args); + void HandleDeleteSubscription(base::Value::ConstListView args); + void HandleRefreshSubscription(base::Value::ConstListView args); + void HandleViewSubscriptionSource(base::Value::ConstListView args); void RefreshSubscriptionsList(); @@ -76,43 +77,43 @@ AdblockDOMHandler::AdblockDOMHandler() {} AdblockDOMHandler::~AdblockDOMHandler() {} void AdblockDOMHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.enableFilterList", base::BindRepeating(&AdblockDOMHandler::HandleEnableFilterList, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.getCustomFilters", base::BindRepeating(&AdblockDOMHandler::HandleGetCustomFilters, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.getRegionalLists", base::BindRepeating(&AdblockDOMHandler::HandleGetRegionalLists, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.getListSubscriptions", base::BindRepeating(&AdblockDOMHandler::HandleGetListSubscriptions, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.updateCustomFilters", base::BindRepeating(&AdblockDOMHandler::HandleUpdateCustomFilters, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.submitNewSubscription", base::BindRepeating(&AdblockDOMHandler::HandleSubmitNewSubscription, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.setSubscriptionEnabled", base::BindRepeating(&AdblockDOMHandler::HandleSetSubscriptionEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.deleteSubscription", base::BindRepeating(&AdblockDOMHandler::HandleDeleteSubscription, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.refreshSubscription", base::BindRepeating(&AdblockDOMHandler::HandleRefreshSubscription, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_adblock.viewSubscriptionSource", base::BindRepeating(&AdblockDOMHandler::HandleViewSubscriptionSource, base::Unretained(this))); @@ -134,20 +135,21 @@ void AdblockDOMHandler::OnServiceUpdateEvent() { RefreshSubscriptionsList(); } -void AdblockDOMHandler::HandleEnableFilterList(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 2U); - std::string uuid; - if (!args->GetString(0, &uuid)) - return; - bool enabled; - if (!args->GetBoolean(1, &enabled)) +void AdblockDOMHandler::HandleEnableFilterList( + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 2U); + if (!args[0].is_string() || !args[1].is_bool()) return; + + std::string uuid = args[0].GetString(); + bool enabled = args[1].GetBool(); g_brave_browser_process->ad_block_regional_service_manager() ->EnableFilterList(uuid, enabled); } -void AdblockDOMHandler::HandleGetCustomFilters(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void AdblockDOMHandler::HandleGetCustomFilters( + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); AllowJavascript(); const std::string custom_filters = g_brave_browser_process->ad_block_custom_filters_service() @@ -156,8 +158,9 @@ void AdblockDOMHandler::HandleGetCustomFilters(const base::ListValue* args) { base::Value(custom_filters)); } -void AdblockDOMHandler::HandleGetRegionalLists(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void AdblockDOMHandler::HandleGetRegionalLists( + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); AllowJavascript(); std::unique_ptr regional_lists = g_brave_browser_process->ad_block_regional_service_manager() @@ -166,30 +169,31 @@ void AdblockDOMHandler::HandleGetRegionalLists(const base::ListValue* args) { } void AdblockDOMHandler::HandleGetListSubscriptions( - const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); AllowJavascript(); RefreshSubscriptionsList(); } -void AdblockDOMHandler::HandleUpdateCustomFilters(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 1U); - std::string custom_filters; - if (!args->GetString(0, &custom_filters)) +void AdblockDOMHandler::HandleUpdateCustomFilters( + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 1U); + if (!args[0].is_string()) return; + std::string custom_filters = args[0].GetString(); g_brave_browser_process->ad_block_custom_filters_service() ->UpdateCustomFilters(custom_filters); } void AdblockDOMHandler::HandleSubmitNewSubscription( - const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 1U); AllowJavascript(); - std::string subscription_url_string; - if (!args->GetString(0, &subscription_url_string)) { + if (!args[0].is_string()) return; - } + + std::string subscription_url_string = args[0].GetString(); const GURL subscription_url = GURL(subscription_url_string); if (!subscription_url.is_valid()) { return; @@ -202,17 +206,14 @@ void AdblockDOMHandler::HandleSubmitNewSubscription( } void AdblockDOMHandler::HandleSetSubscriptionEnabled( - const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 2U); + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 2U); AllowJavascript(); - std::string subscription_url_string; - if (!args->GetString(0, &subscription_url_string)) { + if (!args[0].is_string() || !args[1].is_bool()) return; - } - bool enabled; - if (!args->GetBoolean(1, &enabled)) { - return; - } + + std::string subscription_url_string = args[0].GetString(); + bool enabled = args[1].GetBool(); const GURL subscription_url = GURL(subscription_url_string); if (!subscription_url.is_valid()) { return; @@ -223,13 +224,14 @@ void AdblockDOMHandler::HandleSetSubscriptionEnabled( RefreshSubscriptionsList(); } -void AdblockDOMHandler::HandleDeleteSubscription(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 1U); +void AdblockDOMHandler::HandleDeleteSubscription( + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 1U); AllowJavascript(); - std::string subscription_url_string; - if (!args->GetString(0, &subscription_url_string)) { + if (!args[0].is_string()) return; - } + + std::string subscription_url_string = args[0].GetString(); const GURL subscription_url = GURL(subscription_url_string); if (!subscription_url.is_valid()) { return; @@ -240,15 +242,16 @@ void AdblockDOMHandler::HandleDeleteSubscription(const base::ListValue* args) { RefreshSubscriptionsList(); } -void AdblockDOMHandler::HandleRefreshSubscription(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 1U); +void AdblockDOMHandler::HandleRefreshSubscription( + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 1U); // This handler does not call Javascript directly, but refreshing the // subscription will trigger the observer later, which will require it. AllowJavascript(); - std::string subscription_url_string; - if (!args->GetString(0, &subscription_url_string)) { + if (!args[0].is_string()) return; - } + + std::string subscription_url_string = args[0].GetString(); const GURL subscription_url = GURL(subscription_url_string); if (!subscription_url.is_valid()) { return; @@ -259,12 +262,12 @@ void AdblockDOMHandler::HandleRefreshSubscription(const base::ListValue* args) { } void AdblockDOMHandler::HandleViewSubscriptionSource( - const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 1U); - std::string subscription_url_string; - if (!args->GetString(0, &subscription_url_string)) { + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 1U); + if (!args[0].is_string()) return; - } + + std::string subscription_url_string = args[0].GetString(); const GURL subscription_url = GURL(subscription_url_string); if (!subscription_url.is_valid()) { return; diff --git a/browser/ui/webui/brave_rewards_internals_ui.cc b/browser/ui/webui/brave_rewards_internals_ui.cc index e28b3f1e9c87..a19dd2ad3114 100644 --- a/browser/ui/webui/brave_rewards_internals_ui.cc +++ b/browser/ui/webui/brave_rewards_internals_ui.cc @@ -42,28 +42,27 @@ class RewardsInternalsDOMHandler : public content::WebUIMessageHandler { void RegisterMessages() override; private: - void HandleGetRewardsInternalsInfo(const base::ListValue* args); + void HandleGetRewardsInternalsInfo(base::Value::ConstListView args); void OnGetRewardsInternalsInfo(ledger::type::RewardsInternalsInfoPtr info); - void GetBalance(const base::ListValue* args); - void OnGetBalance( - const ledger::type::Result result, - ledger::type::BalancePtr balance); - void GetContributions(const base::ListValue* args); + void GetBalance(base::Value::ConstListView args); + void OnGetBalance(const ledger::type::Result result, + ledger::type::BalancePtr balance); + void GetContributions(base::Value::ConstListView args); void OnGetContributions(ledger::type::ContributionInfoList contributions); - void GetPromotions(const base::ListValue* args); + void GetPromotions(base::Value::ConstListView args); void OnGetPromotions(ledger::type::PromotionList list); - void GetPartialLog(const base::ListValue* args); + void GetPartialLog(base::Value::ConstListView args); void OnGetPartialLog(const std::string& log); - void GetFulllLog(const base::ListValue* args); + void GetFulllLog(base::Value::ConstListView args); void OnGetFulllLog(const std::string& log); - void ClearLog(const base::ListValue* args); + void ClearLog(base::Value::ConstListView args); void OnClearLog(const bool success); - void GetExternalWallet(const base::ListValue* args); + void GetExternalWallet(base::Value::ConstListView args); void OnGetExternalWallet(const ledger::type::Result result, ledger::type::ExternalWalletPtr wallet); - void GetEventLogs(const base::ListValue* args); + void GetEventLogs(base::Value::ConstListView args); void OnGetEventLogs(ledger::type::EventLogs logs); - void GetAdDiagnostics(const base::ListValue* args); + void GetAdDiagnostics(base::Value::ConstListView args); void OnGetAdDiagnostics(const bool success, const std::string& json); brave_rewards::RewardsService* rewards_service_; // NOT OWNED @@ -80,44 +79,44 @@ RewardsInternalsDOMHandler::RewardsInternalsDOMHandler() RewardsInternalsDOMHandler::~RewardsInternalsDOMHandler() {} void RewardsInternalsDOMHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getRewardsInternalsInfo", base::BindRepeating( &RewardsInternalsDOMHandler::HandleGetRewardsInternalsInfo, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getBalance", base::BindRepeating(&RewardsInternalsDOMHandler::GetBalance, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getContributions", base::BindRepeating(&RewardsInternalsDOMHandler::GetContributions, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getPromotions", base::BindRepeating(&RewardsInternalsDOMHandler::GetPromotions, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getPartialLog", base::BindRepeating(&RewardsInternalsDOMHandler::GetPartialLog, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getFullLog", base::BindRepeating(&RewardsInternalsDOMHandler::GetFulllLog, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.clearLog", base::BindRepeating(&RewardsInternalsDOMHandler::ClearLog, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getExternalWallet", base::BindRepeating(&RewardsInternalsDOMHandler::GetExternalWallet, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getEventLogs", base::BindRepeating(&RewardsInternalsDOMHandler::GetEventLogs, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards_internals.getAdDiagnostics", base::BindRepeating(&RewardsInternalsDOMHandler::GetAdDiagnostics, base::Unretained(this))); @@ -138,7 +137,7 @@ void RewardsInternalsDOMHandler::OnJavascriptDisallowed() { } void RewardsInternalsDOMHandler::HandleGetRewardsInternalsInfo( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -166,16 +165,16 @@ void RewardsInternalsDOMHandler::OnGetRewardsInternalsInfo( info_dict); } -void RewardsInternalsDOMHandler::GetBalance(const base::ListValue* args) { +void RewardsInternalsDOMHandler::GetBalance(base::Value::ConstListView args) { if (!rewards_service_) { return; } AllowJavascript(); - rewards_service_->FetchBalance(base::BindOnce( - &RewardsInternalsDOMHandler::OnGetBalance, - weak_ptr_factory_.GetWeakPtr())); + rewards_service_->FetchBalance( + base::BindOnce(&RewardsInternalsDOMHandler::OnGetBalance, + weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnGetBalance( @@ -201,16 +200,17 @@ void RewardsInternalsDOMHandler::OnGetBalance( std::move(balance_value)); } -void RewardsInternalsDOMHandler::GetContributions(const base::ListValue *args) { +void RewardsInternalsDOMHandler::GetContributions( + base::Value::ConstListView args) { if (!rewards_service_) { return; } AllowJavascript(); - rewards_service_->GetAllContributions(base::BindOnce( - &RewardsInternalsDOMHandler::OnGetContributions, - weak_ptr_factory_.GetWeakPtr())); + rewards_service_->GetAllContributions( + base::BindOnce(&RewardsInternalsDOMHandler::OnGetContributions, + weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnGetContributions( @@ -220,7 +220,7 @@ void RewardsInternalsDOMHandler::OnGetContributions( } base::Value list(base::Value::Type::LIST); - for (const auto & item : contributions) { + for (const auto& item : contributions) { base::Value contribution(base::Value::Type::DICTIONARY); contribution.SetStringKey("id", item->contribution_id); contribution.SetDoubleKey("amount", item->amount); @@ -232,14 +232,11 @@ void RewardsInternalsDOMHandler::OnGetContributions( base::Value publishers(base::Value::Type::LIST); for (const auto& publisher_item : item->publishers) { base::Value publisher(base::Value::Type::DICTIONARY); - publisher.SetStringKey( - "contributionId", - publisher_item->contribution_id); + publisher.SetStringKey("contributionId", publisher_item->contribution_id); publisher.SetStringKey("publisherKey", publisher_item->publisher_key); publisher.SetDoubleKey("totalAmount", publisher_item->total_amount); - publisher.SetDoubleKey( - "contributedAmount", - publisher_item->contributed_amount); + publisher.SetDoubleKey("contributedAmount", + publisher_item->contributed_amount); publishers.Append(std::move(publisher)); } contribution.SetPath("publishers", std::move(publishers)); @@ -250,16 +247,17 @@ void RewardsInternalsDOMHandler::OnGetContributions( std::move(list)); } -void RewardsInternalsDOMHandler::GetPromotions(const base::ListValue *args) { +void RewardsInternalsDOMHandler::GetPromotions( + base::Value::ConstListView args) { if (!rewards_service_) { return; } AllowJavascript(); - rewards_service_->GetAllPromotions(base::BindOnce( - &RewardsInternalsDOMHandler::OnGetPromotions, - weak_ptr_factory_.GetWeakPtr())); + rewards_service_->GetAllPromotions( + base::BindOnce(&RewardsInternalsDOMHandler::OnGetPromotions, + weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnGetPromotions( @@ -269,7 +267,7 @@ void RewardsInternalsDOMHandler::OnGetPromotions( } base::ListValue promotions; - for (const auto & item : list) { + for (const auto& item : list) { auto dict = std::make_unique(); dict->SetDouble("amount", item->approximate_value); dict->SetString("promotionId", item->id); @@ -287,7 +285,8 @@ void RewardsInternalsDOMHandler::OnGetPromotions( std::move(promotions)); } -void RewardsInternalsDOMHandler::GetPartialLog(const base::ListValue *args) { +void RewardsInternalsDOMHandler::GetPartialLog( + base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -296,9 +295,8 @@ void RewardsInternalsDOMHandler::GetPartialLog(const base::ListValue *args) { rewards_service_->LoadDiagnosticLog( g_partial_log_max_lines, - base::BindOnce( - &RewardsInternalsDOMHandler::OnGetPartialLog, - weak_ptr_factory_.GetWeakPtr())); + base::BindOnce(&RewardsInternalsDOMHandler::OnGetPartialLog, + weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnGetPartialLog(const std::string& log) { @@ -310,7 +308,7 @@ void RewardsInternalsDOMHandler::OnGetPartialLog(const std::string& log) { base::Value(log)); } -void RewardsInternalsDOMHandler::GetFulllLog(const base::ListValue *args) { +void RewardsInternalsDOMHandler::GetFulllLog(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -318,10 +316,8 @@ void RewardsInternalsDOMHandler::GetFulllLog(const base::ListValue *args) { AllowJavascript(); rewards_service_->LoadDiagnosticLog( - -1, - base::BindOnce( - &RewardsInternalsDOMHandler::OnGetFulllLog, - weak_ptr_factory_.GetWeakPtr())); + -1, base::BindOnce(&RewardsInternalsDOMHandler::OnGetFulllLog, + weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnGetFulllLog(const std::string& log) { @@ -332,17 +328,15 @@ void RewardsInternalsDOMHandler::OnGetFulllLog(const std::string& log) { CallJavascriptFunction("brave_rewards_internals.fullLog", base::Value(log)); } -void RewardsInternalsDOMHandler::ClearLog(const base::ListValue *args) { +void RewardsInternalsDOMHandler::ClearLog(base::Value::ConstListView args) { if (!rewards_service_) { return; } AllowJavascript(); - rewards_service_->ClearDiagnosticLog( - base::BindOnce( - &RewardsInternalsDOMHandler::OnClearLog, - weak_ptr_factory_.GetWeakPtr())); + rewards_service_->ClearDiagnosticLog(base::BindOnce( + &RewardsInternalsDOMHandler::OnClearLog, weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnClearLog(const bool success) { @@ -358,7 +352,7 @@ void RewardsInternalsDOMHandler::OnClearLog(const bool success) { } void RewardsInternalsDOMHandler::GetExternalWallet( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -393,7 +387,7 @@ void RewardsInternalsDOMHandler::OnGetExternalWallet( CallJavascriptFunction("brave_rewards_internals.externalWallet", data); } -void RewardsInternalsDOMHandler::GetEventLogs(const base::ListValue* args) { +void RewardsInternalsDOMHandler::GetEventLogs(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -401,9 +395,8 @@ void RewardsInternalsDOMHandler::GetEventLogs(const base::ListValue* args) { AllowJavascript(); rewards_service_->GetEventLogs( - base::BindOnce( - &RewardsInternalsDOMHandler::OnGetEventLogs, - weak_ptr_factory_.GetWeakPtr())); + base::BindOnce(&RewardsInternalsDOMHandler::OnGetEventLogs, + weak_ptr_factory_.GetWeakPtr())); } void RewardsInternalsDOMHandler::OnGetEventLogs(ledger::type::EventLogs logs) { @@ -425,7 +418,8 @@ void RewardsInternalsDOMHandler::OnGetEventLogs(ledger::type::EventLogs logs) { CallJavascriptFunction("brave_rewards_internals.eventLogs", std::move(data)); } -void RewardsInternalsDOMHandler::GetAdDiagnostics(const base::ListValue* args) { +void RewardsInternalsDOMHandler::GetAdDiagnostics( + base::Value::ConstListView args) { if (!ads_service_) { NOTREACHED(); return; diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index fbeb0f9087f3..4dcde1092731 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -7,8 +7,8 @@ #include -#include #include +#include #include #include "base/i18n/time_formatting.h" @@ -41,9 +41,9 @@ #include "content/public/common/bindings_policy.h" #if defined(OS_ANDROID) -#include "content/public/browser/url_data_source.h" #include "chrome/browser/ui/webui/favicon_source.h" #include "components/favicon_base/favicon_url_parser.h" +#include "content/public/browser/url_data_source.h" #endif using content::WebUIMessageHandler; @@ -51,10 +51,11 @@ using content::WebUIMessageHandler; namespace { // The handler for Javascript messages for Brave about: pages -class RewardsDOMHandler : public WebUIMessageHandler, - public brave_ads::AdsServiceObserver, - public brave_rewards::RewardsNotificationServiceObserver, - public brave_rewards::RewardsServiceObserver { +class RewardsDOMHandler + : public WebUIMessageHandler, + public brave_ads::AdsServiceObserver, + public brave_rewards::RewardsNotificationServiceObserver, + public brave_rewards::RewardsServiceObserver { public: RewardsDOMHandler(); ~RewardsDOMHandler() override; @@ -67,65 +68,57 @@ class RewardsDOMHandler : public WebUIMessageHandler, void RegisterMessages() override; private: - void RestartBrowser(const base::ListValue* args); - void IsInitialized(const base::ListValue* args); - void GetRewardsParameters(const base::ListValue* args); - void GetAutoContributeProperties(const base::ListValue* args); - void FetchPromotions(const base::ListValue* args); - void ClaimPromotion(const base::ListValue* args); - void AttestPromotion(const base::ListValue* args); - void RecoverWallet(const base::ListValue* args); - void GetReconcileStamp(const base::ListValue* args); - void SaveSetting(const base::ListValue* args); + void RestartBrowser(base::Value::ConstListView args); + void IsInitialized(base::Value::ConstListView args); + void GetRewardsParameters(base::Value::ConstListView args); + void GetAutoContributeProperties(base::Value::ConstListView args); + void FetchPromotions(base::Value::ConstListView args); + void ClaimPromotion(base::Value::ConstListView args); + void AttestPromotion(base::Value::ConstListView args); + void RecoverWallet(base::Value::ConstListView args); + void GetReconcileStamp(base::Value::ConstListView args); + void SaveSetting(base::Value::ConstListView args); void OnPublisherList(ledger::type::PublisherInfoList list); void OnExcludedSiteList(ledger::type::PublisherInfoList list); - void ExcludePublisher(const base::ListValue* args); - void RestorePublishers(const base::ListValue* args); - void RestorePublisher(const base::ListValue* args); - void GetAutoContributionAmount(const base::ListValue* args); - void RemoveRecurringTip(const base::ListValue* args); - void GetRecurringTips(const base::ListValue* args); - void GetOneTimeTips(const base::ListValue* args); - void GetContributionList(const base::ListValue* args); - void GetAdsData(const base::ListValue* args); - void GetAdsHistory(const base::ListValue* args); + void ExcludePublisher(base::Value::ConstListView args); + void RestorePublishers(base::Value::ConstListView args); + void RestorePublisher(base::Value::ConstListView args); + void GetAutoContributionAmount(base::Value::ConstListView args); + void RemoveRecurringTip(base::Value::ConstListView args); + void GetRecurringTips(base::Value::ConstListView args); + void GetOneTimeTips(base::Value::ConstListView args); + void GetContributionList(base::Value::ConstListView args); + void GetAdsData(base::Value::ConstListView args); + void GetAdsHistory(base::Value::ConstListView args); void OnGetAdsHistory(const base::ListValue& history); - void ToggleAdThumbUp(const base::ListValue* args); - void OnToggleAdThumbUp( - const std::string& creative_instance_id, - const int action); - void ToggleAdThumbDown(const base::ListValue* args); - void OnToggleAdThumbDown( - const std::string& creative_instance_id, - const int action); - void ToggleAdOptInAction(const base::ListValue* args); - void OnToggleAdOptInAction( - const std::string& category, - const int action); - void ToggleAdOptOutAction(const base::ListValue* args); - void OnToggleAdOptOutAction( - const std::string& category, - const int action); - void ToggleSaveAd(const base::ListValue* args); - void OnToggleSaveAd( - const std::string& creative_instance_id, - const bool saved); - void ToggleFlagAd(const base::ListValue* args); - void OnToggleFlagAd( - const std::string& creative_instance_id, - const bool flagged); - void SaveAdsSetting(const base::ListValue* args); - void SetBackupCompleted(const base::ListValue* args); + void ToggleAdThumbUp(base::Value::ConstListView args); + void OnToggleAdThumbUp(const std::string& creative_instance_id, + const int action); + void ToggleAdThumbDown(base::Value::ConstListView args); + void OnToggleAdThumbDown(const std::string& creative_instance_id, + const int action); + void ToggleAdOptInAction(base::Value::ConstListView args); + void OnToggleAdOptInAction(const std::string& category, const int action); + void ToggleAdOptOutAction(base::Value::ConstListView args); + void OnToggleAdOptOutAction(const std::string& category, const int action); + void ToggleSaveAd(base::Value::ConstListView args); + void OnToggleSaveAd(const std::string& creative_instance_id, + const bool saved); + void ToggleFlagAd(base::Value::ConstListView args); + void OnToggleFlagAd(const std::string& creative_instance_id, + const bool flagged); + void SaveAdsSetting(base::Value::ConstListView args); + void SetBackupCompleted(base::Value::ConstListView args); void OnGetContributionAmount(double amount); void OnGetAutoContributeProperties( ledger::type::AutoContributePropertiesPtr properties); void OnGetReconcileStamp(uint64_t reconcile_stamp); void OnAutoContributePropsReady( ledger::type::AutoContributePropertiesPtr properties); - void GetPendingContributionsTotal(const base::ListValue* args); + void GetPendingContributionsTotal(base::Value::ConstListView args); void OnGetPendingContributionsTotal(double amount); - void GetStatement(const base::ListValue* args); - void GetExcludedSites(const base::ListValue* args); + void GetStatement(base::Value::ConstListView args); + void GetExcludedSites(base::Value::ConstListView args); void OnGetStatement(const bool success, const int64_t next_payment_date, @@ -137,71 +130,68 @@ class RewardsDOMHandler : public WebUIMessageHandler, void OnGetOneTimeTips(ledger::type::PublisherInfoList list); - void GetEnabledInlineTippingPlatforms(const base::ListValue* args); - void SetInlineTippingPlatformEnabled(const base::ListValue* args); + void GetEnabledInlineTippingPlatforms(base::Value::ConstListView args); + void SetInlineTippingPlatformEnabled(base::Value::ConstListView args); - void GetPendingContributions(const base::ListValue* args); + void GetPendingContributions(base::Value::ConstListView args); void OnGetPendingContributions( ledger::type::PendingContributionInfoList list); - void RemovePendingContribution(const base::ListValue* args); - void RemoveAllPendingContributions(const base::ListValue* args); - void FetchBalance(const base::ListValue* args); - void OnFetchBalance( - const ledger::type::Result result, - ledger::type::BalancePtr balance); + void RemovePendingContribution(base::Value::ConstListView args); + void RemoveAllPendingContributions(base::Value::ConstListView args); + void FetchBalance(base::Value::ConstListView args); + void OnFetchBalance(const ledger::type::Result result, + ledger::type::BalancePtr balance); - void GetExternalWallet(const base::ListValue* args); + void GetExternalWallet(base::Value::ConstListView args); void OnGetExternalWallet(const ledger::type::Result result, ledger::type::ExternalWalletPtr wallet); - void ProcessRewardsPageUrl(const base::ListValue* args); + void ProcessRewardsPageUrl(base::Value::ConstListView args); void OnProcessRewardsPageUrl( - const ledger::type::Result result, - const std::string& wallet_type, - const std::string& action, - const base::flat_map& args); + const ledger::type::Result result, + const std::string& wallet_type, + const std::string& action, + const base::flat_map& args); - void DisconnectWallet(const base::ListValue* args); + void DisconnectWallet(base::Value::ConstListView args); - void GetBalanceReport(const base::ListValue* args); + void GetBalanceReport(base::Value::ConstListView args); - void OnGetBalanceReport( - const uint32_t month, - const uint32_t year, - const ledger::type::Result result, - ledger::type::BalanceReportInfoPtr report); + void OnGetBalanceReport(const uint32_t month, + const uint32_t year, + const ledger::type::Result result, + ledger::type::BalanceReportInfoPtr report); - void GetMonthlyReport(const base::ListValue* args); + void GetMonthlyReport(base::Value::ConstListView args); - void GetAllMonthlyReportIds(const base::ListValue* args); - void GetCountryCode(const base::ListValue* args); + void GetAllMonthlyReportIds(base::Value::ConstListView args); + void GetCountryCode(base::Value::ConstListView args); - void OnGetMonthlyReport( - const uint32_t month, - const uint32_t year, - ledger::type::MonthlyReportInfoPtr report); + void OnGetMonthlyReport(const uint32_t month, + const uint32_t year, + ledger::type::MonthlyReportInfoPtr report); void OnGetAllMonthlyReportIds(const std::vector& ids); void OnGetRewardsParameters(ledger::type::RewardsParametersPtr parameters); - void CompleteReset(const base::ListValue* args); + void CompleteReset(base::Value::ConstListView args); - void GetPaymentId(const base::ListValue* args); + void GetPaymentId(base::Value::ConstListView args); void OnWalletCreatedForPaymentId(ledger::type::Result result); void OnGetPaymentId(ledger::type::BraveWalletPtr wallet); - void GetWalletPassphrase(const base::ListValue* args); + void GetWalletPassphrase(base::Value::ConstListView args); void OnGetWalletPassphrase(const std::string& pass); - void GetOnboardingStatus(const base::ListValue* args); - void SaveOnboardingResult(const base::ListValue* args); - void GetExternalWalletProviders(const base::ListValue* args); - void SetExternalWalletType(const base::ListValue* args); + void GetOnboardingStatus(base::Value::ConstListView args); + void SaveOnboardingResult(base::Value::ConstListView args); + void GetExternalWalletProviders(base::Value::ConstListView args); + void SetExternalWalletType(base::Value::ConstListView args); void OnExternalWalletTypeUpdated(const ledger::type::Result result, ledger::type::ExternalWalletPtr wallet); @@ -209,21 +199,17 @@ class RewardsDOMHandler : public WebUIMessageHandler, // RewardsServiceObserver implementation void OnRewardsInitialized( brave_rewards::RewardsService* rewards_service) override; - void OnFetchPromotions( - brave_rewards::RewardsService* rewards_service, - const ledger::type::Result result, - const ledger::type::PromotionList& list) override; - void OnPromotionFinished( - brave_rewards::RewardsService* rewards_service, - const ledger::type::Result result, - ledger::type::PromotionPtr promotion) override; - void OnRecoverWallet( - brave_rewards::RewardsService* rewards_service, - const ledger::type::Result result) override; - void OnExcludedSitesChanged( - brave_rewards::RewardsService* rewards_service, - std::string publisher_id, - bool excluded) override; + void OnFetchPromotions(brave_rewards::RewardsService* rewards_service, + const ledger::type::Result result, + const ledger::type::PromotionList& list) override; + void OnPromotionFinished(brave_rewards::RewardsService* rewards_service, + const ledger::type::Result result, + ledger::type::PromotionPtr promotion) override; + void OnRecoverWallet(brave_rewards::RewardsService* rewards_service, + const ledger::type::Result result) override; + void OnExcludedSitesChanged(brave_rewards::RewardsService* rewards_service, + std::string publisher_id, + bool excluded) override; void OnReconcileComplete( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result, @@ -236,47 +222,41 @@ class RewardsDOMHandler : public WebUIMessageHandler, brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) override; - void OnPublisherListNormalized( - brave_rewards::RewardsService* rewards_service, - ledger::type::PublisherInfoList list) override; + void OnPublisherListNormalized(brave_rewards::RewardsService* rewards_service, + ledger::type::PublisherInfoList list) override; void OnStatementChanged( brave_rewards::RewardsService* rewards_service) override; - void OnRecurringTipSaved( - brave_rewards::RewardsService* rewards_service, - bool success) override; + void OnRecurringTipSaved(brave_rewards::RewardsService* rewards_service, + bool success) override; - void OnRecurringTipRemoved( - brave_rewards::RewardsService* rewards_service, - bool success) override; + void OnRecurringTipRemoved(brave_rewards::RewardsService* rewards_service, + bool success) override; void OnPendingContributionRemoved( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) override; - void OnDisconnectWallet( - brave_rewards::RewardsService* rewards_service, - const ledger::type::Result result, - const std::string& wallet_type) override; + void OnDisconnectWallet(brave_rewards::RewardsService* rewards_service, + const ledger::type::Result result, + const std::string& wallet_type) override; void OnAdsEnabled(brave_rewards::RewardsService* rewards_service, bool ads_enabled) override; - void OnClaimPromotion( - const std::string& promotion_id, - const ledger::type::Result result, - const std::string& captcha_image, - const std::string& hint, - const std::string& captcha_id); + void OnClaimPromotion(const std::string& promotion_id, + const ledger::type::Result result, + const std::string& captcha_image, + const std::string& hint, + const std::string& captcha_id); - void OnAttestPromotion( - const std::string& promotion_id, - const ledger::type::Result result, - ledger::type::PromotionPtr promotion); + void OnAttestPromotion(const std::string& promotion_id, + const ledger::type::Result result, + ledger::type::PromotionPtr promotion); void OnUnblindedTokensReady( - brave_rewards::RewardsService* rewards_service) override; + brave_rewards::RewardsService* rewards_service) override; void ReconcileStampReset() override; @@ -292,7 +272,7 @@ class RewardsDOMHandler : public WebUIMessageHandler, const brave_rewards::RewardsNotificationService::RewardsNotification& notification) override; void OnAllNotificationsDeleted(brave_rewards::RewardsNotificationService* - rewards_notification_service) override; + rewards_notification_service) override; void OnGetNotification( brave_rewards::RewardsNotificationService* rewards_notification_service, const brave_rewards::RewardsNotificationService::RewardsNotification& @@ -306,7 +286,7 @@ class RewardsDOMHandler : public WebUIMessageHandler, void OnAdRewardsChanged() override; brave_rewards::RewardsService* rewards_service_; // NOT OWNED - brave_ads::AdsService* ads_service_; // NOT OWNED + brave_ads::AdsService* ads_service_; // NOT OWNED base::ScopedObservation @@ -344,207 +324,207 @@ void RewardsDOMHandler::RegisterMessages() { profile, chrome::FaviconUrlFormat::kFaviconLegacy)); #endif - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.restartBrowser", base::BindRepeating(&RewardsDOMHandler::RestartBrowser, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.isInitialized", base::BindRepeating(&RewardsDOMHandler::IsInitialized, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getRewardsParameters", base::BindRepeating(&RewardsDOMHandler::GetRewardsParameters, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getAutoContributeProperties", base::BindRepeating(&RewardsDOMHandler::GetAutoContributeProperties, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.fetchPromotions", base::BindRepeating(&RewardsDOMHandler::FetchPromotions, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.claimPromotion", base::BindRepeating(&RewardsDOMHandler::ClaimPromotion, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.attestPromotion", base::BindRepeating(&RewardsDOMHandler::AttestPromotion, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.recoverWallet", base::BindRepeating(&RewardsDOMHandler::RecoverWallet, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getReconcileStamp", base::BindRepeating(&RewardsDOMHandler::GetReconcileStamp, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.saveSetting", base::BindRepeating(&RewardsDOMHandler::SaveSetting, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.excludePublisher", base::BindRepeating(&RewardsDOMHandler::ExcludePublisher, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.restorePublishers", base::BindRepeating(&RewardsDOMHandler::RestorePublishers, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.restorePublisher", base::BindRepeating(&RewardsDOMHandler::RestorePublisher, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getContributionAmount", base::BindRepeating(&RewardsDOMHandler::GetAutoContributionAmount, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.removeRecurringTip", base::BindRepeating(&RewardsDOMHandler::RemoveRecurringTip, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getRecurringTips", base::BindRepeating(&RewardsDOMHandler::GetRecurringTips, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getOneTimeTips", base::BindRepeating(&RewardsDOMHandler::GetOneTimeTips, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getContributionList", base::BindRepeating(&RewardsDOMHandler::GetContributionList, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getAdsData", base::BindRepeating(&RewardsDOMHandler::GetAdsData, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getAdsHistory", base::BindRepeating(&RewardsDOMHandler::GetAdsHistory, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.toggleAdThumbUp", base::BindRepeating(&RewardsDOMHandler::ToggleAdThumbUp, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.toggleAdThumbDown", base::BindRepeating(&RewardsDOMHandler::ToggleAdThumbDown, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.toggleAdOptInAction", base::BindRepeating(&RewardsDOMHandler::ToggleAdOptInAction, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.toggleAdOptOutAction", base::BindRepeating(&RewardsDOMHandler::ToggleAdOptOutAction, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.toggleSaveAd", base::BindRepeating(&RewardsDOMHandler::ToggleSaveAd, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.toggleFlagAd", base::BindRepeating(&RewardsDOMHandler::ToggleFlagAd, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.saveAdsSetting", base::BindRepeating(&RewardsDOMHandler::SaveAdsSetting, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.setBackupCompleted", base::BindRepeating(&RewardsDOMHandler::SetBackupCompleted, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getPendingContributionsTotal", base::BindRepeating(&RewardsDOMHandler::GetPendingContributionsTotal, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getStatement", base::BindRepeating(&RewardsDOMHandler::GetStatement, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getEnabledInlineTippingPlatforms", base::BindRepeating(&RewardsDOMHandler::GetEnabledInlineTippingPlatforms, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.setInlineTippingPlatformEnabled", base::BindRepeating(&RewardsDOMHandler::SetInlineTippingPlatformEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getPendingContributions", base::BindRepeating(&RewardsDOMHandler::GetPendingContributions, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.removePendingContribution", base::BindRepeating(&RewardsDOMHandler::RemovePendingContribution, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.removeAllPendingContribution", base::BindRepeating(&RewardsDOMHandler::RemoveAllPendingContributions, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getExcludedSites", base::BindRepeating(&RewardsDOMHandler::GetExcludedSites, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.fetchBalance", base::BindRepeating(&RewardsDOMHandler::FetchBalance, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getExternalWallet", base::BindRepeating(&RewardsDOMHandler::GetExternalWallet, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.processRewardsPageUrl", base::BindRepeating(&RewardsDOMHandler::ProcessRewardsPageUrl, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.disconnectWallet", base::BindRepeating(&RewardsDOMHandler::DisconnectWallet, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getBalanceReport", base::BindRepeating(&RewardsDOMHandler::GetBalanceReport, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getMonthlyReport", base::BindRepeating(&RewardsDOMHandler::GetMonthlyReport, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getMonthlyReportIds", base::BindRepeating(&RewardsDOMHandler::GetAllMonthlyReportIds, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getCountryCode", base::BindRepeating(&RewardsDOMHandler::GetCountryCode, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.completeReset", base::BindRepeating(&RewardsDOMHandler::CompleteReset, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getPaymentId", base::BindRepeating(&RewardsDOMHandler::GetPaymentId, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getWalletPassphrase", base::BindRepeating(&RewardsDOMHandler::GetWalletPassphrase, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getOnboardingStatus", base::BindRepeating(&RewardsDOMHandler::GetOnboardingStatus, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.saveOnboardingResult", base::BindRepeating(&RewardsDOMHandler::SaveOnboardingResult, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.getExternalWalletProviders", base::BindRepeating(&RewardsDOMHandler::GetExternalWalletProviders, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brave_rewards.setExternalWalletType", base::BindRepeating(&RewardsDOMHandler::SetExternalWalletType, base::Unretained(this))); @@ -560,12 +540,12 @@ void RewardsDOMHandler::Init() { ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile); } -void RewardsDOMHandler::RestartBrowser(const base::ListValue* args) { +void RewardsDOMHandler::RestartBrowser(base::Value::ConstListView args) { AllowJavascript(); chrome::AttemptRestart(); } -void RewardsDOMHandler::IsInitialized(const base::ListValue* args) { +void RewardsDOMHandler::IsInitialized(base::Value::ConstListView args) { AllowJavascript(); if (rewards_service_ && rewards_service_->IsInitialized()) { @@ -592,15 +572,14 @@ void RewardsDOMHandler::OnJavascriptDisallowed() { weak_factory_.InvalidateWeakPtrs(); } -void RewardsDOMHandler::GetRewardsParameters(const base::ListValue* args) { +void RewardsDOMHandler::GetRewardsParameters(base::Value::ConstListView args) { if (!rewards_service_) return; AllowJavascript(); - rewards_service_->GetRewardsParameters( - base::BindOnce(&RewardsDOMHandler::OnGetRewardsParameters, - weak_factory_.GetWeakPtr())); + rewards_service_->GetRewardsParameters(base::BindOnce( + &RewardsDOMHandler::OnGetRewardsParameters, weak_factory_.GetWeakPtr())); } void RewardsDOMHandler::OnGetRewardsParameters( @@ -632,7 +611,7 @@ void RewardsDOMHandler::OnRewardsInitialized( } void RewardsDOMHandler::GetAutoContributeProperties( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!rewards_service_) return; @@ -643,13 +622,13 @@ void RewardsDOMHandler::GetAutoContributeProperties( weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::SetExternalWalletType(const base::ListValue* args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::SetExternalWalletType(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) return; AllowJavascript(); - const std::string wallet_type = args->GetList()[0].GetString(); + const std::string wallet_type = args[0].GetString(); rewards_service_->SetExternalWalletType(wallet_type); rewards_service_->GetExternalWallet( @@ -675,9 +654,9 @@ void RewardsDOMHandler::OnGetAutoContributeProperties( values.SetBoolean("enabledContribute", properties->enabled_contribute); values.SetInteger("contributionMinTime", properties->contribution_min_time); values.SetInteger("contributionMinVisits", - properties->contribution_min_visits); + properties->contribution_min_visits); values.SetBoolean("contributionNonVerified", - properties->contribution_non_verified); + properties->contribution_non_verified); values.SetBoolean("contributionVideos", properties->contribution_videos); CallJavascriptFunction("brave_rewards.autoContributeProperties", values); @@ -709,19 +688,18 @@ void RewardsDOMHandler::OnFetchPromotions( CallJavascriptFunction("brave_rewards.promotions", dict); } -void RewardsDOMHandler::FetchPromotions(const base::ListValue* args) { +void RewardsDOMHandler::FetchPromotions(base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->FetchPromotions(); } } -void RewardsDOMHandler::OnClaimPromotion( - const std::string& promotion_id, - const ledger::type::Result result, - const std::string& captcha_image, - const std::string& hint, - const std::string& captcha_id) { +void RewardsDOMHandler::OnClaimPromotion(const std::string& promotion_id, + const ledger::type::Result result, + const std::string& captcha_image, + const std::string& hint, + const std::string& captcha_id) { if (!IsJavascriptAllowed()) { return; } @@ -736,15 +714,15 @@ void RewardsDOMHandler::OnClaimPromotion( CallJavascriptFunction("brave_rewards.claimPromotion", response); } -void RewardsDOMHandler::ClaimPromotion(const base::ListValue* args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::ClaimPromotion(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - const std::string promotion_id = args->GetList()[0].GetString(); + const std::string promotion_id = args[0].GetString(); #if !defined(OS_ANDROID) rewards_service_->ClaimPromotion( @@ -757,9 +735,8 @@ void RewardsDOMHandler::ClaimPromotion(const base::ListValue* args) { #endif } - -void RewardsDOMHandler::AttestPromotion(const base::ListValue *args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::AttestPromotion(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); AllowJavascript(); if (!rewards_service_) { @@ -769,21 +746,18 @@ void RewardsDOMHandler::AttestPromotion(const base::ListValue *args) { return; } - const std::string promotion_id = args->GetList()[0].GetString(); - const std::string solution = args->GetList()[1].GetString(); + const std::string promotion_id = args[0].GetString(); + const std::string solution = args[1].GetString(); rewards_service_->AttestPromotion( - promotion_id, - solution, - base::BindOnce( - &RewardsDOMHandler::OnAttestPromotion, - weak_factory_.GetWeakPtr(), - promotion_id)); + promotion_id, solution, + base::BindOnce(&RewardsDOMHandler::OnAttestPromotion, + weak_factory_.GetWeakPtr(), promotion_id)); } void RewardsDOMHandler::OnAttestPromotion( const std::string& promotion_id, - const ledger::type::Result result, - ledger::type::PromotionPtr promotion) { + const ledger::type::Result result, + ledger::type::PromotionPtr promotion) { if (!IsJavascriptAllowed()) { return; } @@ -812,17 +786,14 @@ void RewardsDOMHandler::OnPromotionFinished( return; } - OnAttestPromotion( - promotion->id, - result, - promotion->Clone()); + OnAttestPromotion(promotion->id, result, promotion->Clone()); } -void RewardsDOMHandler::RecoverWallet(const base::ListValue *args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::RecoverWallet(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (rewards_service_) { AllowJavascript(); - const std::string pass_phrase = args->GetList()[0].GetString(); + const std::string pass_phrase = args[0].GetString(); rewards_service_->RecoverWallet(pass_phrase); } } @@ -845,7 +816,7 @@ void RewardsDOMHandler::OnGetReconcileStamp(uint64_t reconcile_stamp) { } } -void RewardsDOMHandler::GetReconcileStamp(const base::ListValue* args) { +void RewardsDOMHandler::GetReconcileStamp(base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->GetReconcileStamp(base::BindOnce( @@ -856,9 +827,8 @@ void RewardsDOMHandler::GetReconcileStamp(const base::ListValue* args) { void RewardsDOMHandler::OnAutoContributePropsReady( ledger::type::AutoContributePropertiesPtr properties) { auto filter = ledger::type::ActivityInfoFilter::New(); - auto pair = ledger::type::ActivityInfoFilterOrderPair::New( - "ai.percent", - false); + auto pair = + ledger::type::ActivityInfoFilterOrderPair::New("ai.percent", false); filter->order_by.push_back(std::move(pair)); filter->min_duration = properties->contribution_min_time; filter->reconcile_stamp = properties->reconcile_stamp; @@ -873,7 +843,7 @@ void RewardsDOMHandler::OnAutoContributePropsReady( weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::GetExcludedSites(const base::ListValue* args) { +void RewardsDOMHandler::GetExcludedSites(base::Value::ConstListView args) { AllowJavascript(); rewards_service_->GetExcludedList(base::BindOnce( &RewardsDOMHandler::OnExcludedSiteList, weak_factory_.GetWeakPtr())); @@ -926,13 +896,13 @@ void RewardsDOMHandler::OnGetAllNotifications( const brave_rewards::RewardsNotificationService::RewardsNotificationsList& notifications_list) {} -void RewardsDOMHandler::SaveSetting(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::SaveSetting(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); AllowJavascript(); if (rewards_service_) { - const std::string key = args->GetList()[0].GetString(); - const std::string value = args->GetList()[1].GetString(); + const std::string key = args[0].GetString(); + const std::string value = args[1].GetString(); if (key == "contributionMonthly") { rewards_service_->SetAutoContributionAmount(std::stod(value)); @@ -972,18 +942,18 @@ void RewardsDOMHandler::SaveSetting(const base::ListValue* args) { } } -void RewardsDOMHandler::ExcludePublisher(const base::ListValue *args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::ExcludePublisher(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - const std::string publisherKey = args->GetList()[0].GetString(); + const std::string publisherKey = args[0].GetString(); rewards_service_->SetPublisherExclude(publisherKey, true); } -void RewardsDOMHandler::RestorePublishers(const base::ListValue *args) { +void RewardsDOMHandler::RestorePublishers(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -992,14 +962,14 @@ void RewardsDOMHandler::RestorePublishers(const base::ListValue *args) { rewards_service_->RestorePublishers(); } -void RewardsDOMHandler::RestorePublisher(const base::ListValue *args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::RestorePublisher(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - std::string publisherKey = args->GetList()[0].GetString(); + std::string publisherKey = args[0].GetString(); rewards_service_->SetPublisherExclude(publisherKey, false); } @@ -1054,7 +1024,8 @@ void RewardsDOMHandler::OnGetContributionAmount(double amount) { } } -void RewardsDOMHandler::GetAutoContributionAmount(const base::ListValue* args) { +void RewardsDOMHandler::GetAutoContributionAmount( + base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->GetAutoContributionAmount( @@ -1081,22 +1052,20 @@ void RewardsDOMHandler::OnReconcileComplete( CallJavascriptFunction("brave_rewards.reconcileComplete", complete); } -void RewardsDOMHandler::RemoveRecurringTip(const base::ListValue *args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::RemoveRecurringTip(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (rewards_service_) { AllowJavascript(); - const std::string publisherKey = args->GetList()[0].GetString(); + const std::string publisherKey = args[0].GetString(); rewards_service_->RemoveRecurringTip(publisherKey); } } -void RewardsDOMHandler::GetRecurringTips( - const base::ListValue *args) { +void RewardsDOMHandler::GetRecurringTips(base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->GetRecurringTips(base::BindOnce( - &RewardsDOMHandler::OnGetRecurringTips, - weak_factory_.GetWeakPtr())); + &RewardsDOMHandler::OnGetRecurringTips, weak_factory_.GetWeakPtr())); } } @@ -1149,16 +1118,15 @@ void RewardsDOMHandler::OnGetOneTimeTips(ledger::type::PublisherInfoList list) { CallJavascriptFunction("brave_rewards.currentTips", *publishers); } -void RewardsDOMHandler::GetOneTimeTips(const base::ListValue *args) { +void RewardsDOMHandler::GetOneTimeTips(base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->GetOneTimeTips(base::BindOnce( - &RewardsDOMHandler::OnGetOneTimeTips, - weak_factory_.GetWeakPtr())); + &RewardsDOMHandler::OnGetOneTimeTips, weak_factory_.GetWeakPtr())); } } -void RewardsDOMHandler::GetContributionList(const base::ListValue *args) { +void RewardsDOMHandler::GetContributionList(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -1170,7 +1138,7 @@ void RewardsDOMHandler::GetContributionList(const base::ListValue *args) { weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::GetAdsData(const base::ListValue *args) { +void RewardsDOMHandler::GetAdsData(base::Value::ConstListView args) { if (!ads_service_) { return; } @@ -1195,19 +1163,19 @@ void RewardsDOMHandler::GetAdsData(const base::ListValue *args) { const std::string auto_detected_subdivision_targeting_code = ads_service_->GetAutoDetectedAdsSubdivisionTargetingCode(); ads_data.SetString(kAutoDetectedAdsSubdivisionTargeting, - auto_detected_subdivision_targeting_code); + auto_detected_subdivision_targeting_code); const bool should_allow_subdivision_ad_targeting = ads_service_->ShouldAllowAdsSubdivisionTargeting(); ads_data.SetBoolean(kShouldAllowAdsSubdivisionTargeting, - should_allow_subdivision_ad_targeting); + should_allow_subdivision_ad_targeting); ads_data.SetBoolean("adsUIEnabled", true); CallJavascriptFunction("brave_rewards.adsData", ads_data); } -void RewardsDOMHandler::GetAdsHistory(const base::ListValue* args) { +void RewardsDOMHandler::GetAdsHistory(base::Value::ConstListView args) { if (!ads_service_) { return; } @@ -1217,14 +1185,15 @@ void RewardsDOMHandler::GetAdsHistory(const base::ListValue* args) { const base::Time to_time = base::Time::Now(); const uint64_t to_timestamp = to_time.ToDoubleT(); - const base::Time from_time = to_time - - base::TimeDelta::FromDays(kDaysOfAdsHistory - 1); + const base::Time from_time = + to_time - base::TimeDelta::FromDays(kDaysOfAdsHistory - 1); const base::Time from_time_local_midnight = from_time.LocalMidnight(); const uint64_t from_timestamp = from_time_local_midnight.ToDoubleT(); - ads_service_->GetAdsHistory(from_timestamp, to_timestamp, + ads_service_->GetAdsHistory( + from_timestamp, to_timestamp, base::BindOnce(&RewardsDOMHandler::OnGetAdsHistory, - weak_factory_.GetWeakPtr())); + weak_factory_.GetWeakPtr())); } void RewardsDOMHandler::OnGetAdsHistory(const base::ListValue& ads_history) { @@ -1235,17 +1204,17 @@ void RewardsDOMHandler::OnGetAdsHistory(const base::ListValue& ads_history) { CallJavascriptFunction("brave_rewards.adsHistory", ads_history); } -void RewardsDOMHandler::ToggleAdThumbUp(const base::ListValue* args) { - CHECK_EQ(3U, args->GetSize()); +void RewardsDOMHandler::ToggleAdThumbUp(base::Value::ConstListView args) { + CHECK_EQ(3U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string id = args->GetList()[0].GetString(); - const std::string creative_set_id = args->GetList()[1].GetString(); - const int action = args->GetList()[2].GetInt(); + const std::string id = args[0].GetString(); + const std::string creative_set_id = args[1].GetString(); + const int action = args[2].GetInt(); ads_service_->ToggleAdThumbUp( id, creative_set_id, action, base::BindOnce(&RewardsDOMHandler::OnToggleAdThumbUp, @@ -1265,17 +1234,17 @@ void RewardsDOMHandler::OnToggleAdThumbUp( CallJavascriptFunction("brave_rewards.onToggleAdThumbUp", result); } -void RewardsDOMHandler::ToggleAdThumbDown(const base::ListValue* args) { - CHECK_EQ(3U, args->GetSize()); +void RewardsDOMHandler::ToggleAdThumbDown(base::Value::ConstListView args) { + CHECK_EQ(3U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string id = args->GetList()[0].GetString(); - const std::string creative_set_id = args->GetList()[1].GetString(); - const int action = args->GetList()[2].GetInt(); + const std::string id = args[0].GetString(); + const std::string creative_set_id = args[1].GetString(); + const int action = args[2].GetInt(); ads_service_->ToggleAdThumbDown( id, creative_set_id, action, base::BindOnce(&RewardsDOMHandler::OnToggleAdThumbDown, @@ -1295,16 +1264,16 @@ void RewardsDOMHandler::OnToggleAdThumbDown( CallJavascriptFunction("brave_rewards.onToggleAdThumbDown", result); } -void RewardsDOMHandler::ToggleAdOptInAction(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::ToggleAdOptInAction(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string category = args->GetList()[0].GetString(); - const int action = args->GetList()[1].GetInt(); + const std::string category = args[0].GetString(); + const int action = args[1].GetInt(); ads_service_->ToggleAdOptInAction( category, action, base::BindOnce(&RewardsDOMHandler::OnToggleAdOptInAction, @@ -1323,16 +1292,16 @@ void RewardsDOMHandler::OnToggleAdOptInAction(const std::string& category, CallJavascriptFunction("brave_rewards.onToggleAdOptInAction", result); } -void RewardsDOMHandler::ToggleAdOptOutAction(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::ToggleAdOptOutAction(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string category = args->GetList()[0].GetString(); - const int action = args->GetList()[1].GetInt(); + const std::string category = args[0].GetString(); + const int action = args[1].GetInt(); ads_service_->ToggleAdOptOutAction( category, action, base::BindOnce(&RewardsDOMHandler::OnToggleAdOptOutAction, @@ -1351,25 +1320,24 @@ void RewardsDOMHandler::OnToggleAdOptOutAction(const std::string& category, CallJavascriptFunction("brave_rewards.onToggleAdOptOutAction", result); } -void RewardsDOMHandler::ToggleSaveAd(const base::ListValue* args) { - CHECK_EQ(3U, args->GetSize()); +void RewardsDOMHandler::ToggleSaveAd(base::Value::ConstListView args) { + CHECK_EQ(3U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string creative_instance_id = args->GetList()[0].GetString(); - const std::string creative_set_id = args->GetList()[1].GetString(); - const bool saved = args->GetList()[2].GetBool(); + const std::string creative_instance_id = args[0].GetString(); + const std::string creative_set_id = args[1].GetString(); + const bool saved = args[2].GetBool(); ads_service_->ToggleSaveAd(creative_instance_id, creative_set_id, saved, - base::BindOnce(&RewardsDOMHandler::OnToggleSaveAd, - weak_factory_.GetWeakPtr())); + base::BindOnce(&RewardsDOMHandler::OnToggleSaveAd, + weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::OnToggleSaveAd( - const std::string& creative_instance_id, - bool saved) { +void RewardsDOMHandler::OnToggleSaveAd(const std::string& creative_instance_id, + bool saved) { if (!IsJavascriptAllowed()) { return; } @@ -1380,24 +1348,24 @@ void RewardsDOMHandler::OnToggleSaveAd( CallJavascriptFunction("brave_rewards.onToggleSaveAd", result); } -void RewardsDOMHandler::ToggleFlagAd(const base::ListValue* args) { - CHECK_EQ(3U, args->GetSize()); +void RewardsDOMHandler::ToggleFlagAd(base::Value::ConstListView args) { + CHECK_EQ(3U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string creative_instance_id = args->GetList()[0].GetString(); - const std::string creative_set_id = args->GetList()[1].GetString(); - const bool flagged = args->GetList()[2].GetBool(); + const std::string creative_instance_id = args[0].GetString(); + const std::string creative_set_id = args[1].GetString(); + const bool flagged = args[2].GetBool(); ads_service_->ToggleFlagAd(creative_instance_id, creative_set_id, flagged, - base::BindOnce(&RewardsDOMHandler::OnToggleFlagAd, - weak_factory_.GetWeakPtr())); + base::BindOnce(&RewardsDOMHandler::OnToggleFlagAd, + weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::OnToggleFlagAd( - const std::string& creative_instance_id, bool flagged) { +void RewardsDOMHandler::OnToggleFlagAd(const std::string& creative_instance_id, + bool flagged) { if (!IsJavascriptAllowed()) { return; } @@ -1408,16 +1376,16 @@ void RewardsDOMHandler::OnToggleFlagAd( CallJavascriptFunction("brave_rewards.onToggleFlagAd", result); } -void RewardsDOMHandler::SaveAdsSetting(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::SaveAdsSetting(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); if (!ads_service_) { return; } AllowJavascript(); - const std::string key = args->GetList()[0].GetString(); - const std::string value = args->GetList()[1].GetString(); + const std::string key = args[0].GetString(); + const std::string value = args[1].GetString(); if (key == "adsEnabled") { const auto is_enabled = @@ -1431,11 +1399,10 @@ void RewardsDOMHandler::SaveAdsSetting(const base::ListValue* args) { ads_service_->SetAutoDetectedAdsSubdivisionTargetingCode(value); } - base::ListValue* emptyArgs = nullptr; - GetAdsData(emptyArgs); + GetAdsData(base::Value::ConstListView()); } -void RewardsDOMHandler::SetBackupCompleted(const base::ListValue *args) { +void RewardsDOMHandler::SetBackupCompleted(base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->SetBackupCompleted(); @@ -1443,7 +1410,7 @@ void RewardsDOMHandler::SetBackupCompleted(const base::ListValue *args) { } void RewardsDOMHandler::GetPendingContributionsTotal( - const base::ListValue* args) { + base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->GetPendingContributionsTotal( @@ -1475,8 +1442,7 @@ void RewardsDOMHandler::OnPublisherListNormalized( OnPublisherList(std::move(list)); } -void RewardsDOMHandler::GetStatement( - const base::ListValue* args) { +void RewardsDOMHandler::GetStatement(base::Value::ConstListView args) { AllowJavascript(); ads_service_->GetAccountStatement(base::BindOnce( &RewardsDOMHandler::OnGetStatement, weak_factory_.GetWeakPtr())); @@ -1538,7 +1504,7 @@ void RewardsDOMHandler::OnRecurringTipRemoved( } void RewardsDOMHandler::GetEnabledInlineTippingPlatforms( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); // TODO(zenparsing): Consider using a PrefChangeRegistrar to monitor changes @@ -1560,14 +1526,11 @@ void RewardsDOMHandler::GetEnabledInlineTippingPlatforms( } void RewardsDOMHandler::SetInlineTippingPlatformEnabled( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); - std::string key; - args->GetString(0, &key); - - std::string value; - args->GetString(1, &value); + std::string key = args[0].GetString(); + std::string value = args[1].GetString(); if (rewards_service_) { rewards_service_->SetInlineTippingPlatformEnabled(key, value == "true"); @@ -1575,7 +1538,7 @@ void RewardsDOMHandler::SetInlineTippingPlatformEnabled( } void RewardsDOMHandler::GetPendingContributions( - const base::ListValue* args) { + base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->GetPendingContributions( @@ -1596,19 +1559,18 @@ void RewardsDOMHandler::OnGetPendingContributions( std::make_unique(base::Value::Type::DICTIONARY); contribution->SetKey("id", base::Value(static_cast(item->id))); contribution->SetKey("publisherKey", base::Value(item->publisher_key)); - contribution->SetKey("status", - base::Value(static_cast(item->status))); + contribution->SetKey("status", base::Value(static_cast(item->status))); contribution->SetKey("name", base::Value(item->name)); contribution->SetKey("provider", base::Value(item->provider)); contribution->SetKey("url", base::Value(item->url)); contribution->SetKey("favIcon", base::Value(item->favicon_url)); contribution->SetKey("amount", base::Value(item->amount)); contribution->SetKey("addedDate", - base::Value(std::to_string(item->added_date))); + base::Value(std::to_string(item->added_date))); contribution->SetKey("type", base::Value(static_cast(item->type))); contribution->SetKey("viewingId", base::Value(item->viewing_id)); contribution->SetKey("expirationDate", - base::Value(std::to_string(item->expiration_date))); + base::Value(std::to_string(item->expiration_date))); contributions->Append(std::move(contribution)); } @@ -1616,20 +1578,20 @@ void RewardsDOMHandler::OnGetPendingContributions( } void RewardsDOMHandler::RemovePendingContribution( - const base::ListValue* args) { - CHECK_EQ(1U, args->GetSize()); + base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - const uint64_t id = args->GetList()[0].GetInt(); + const uint64_t id = args[0].GetInt(); rewards_service_->RemovePendingContribution(id); } void RewardsDOMHandler::RemoveAllPendingContributions( - const base::ListValue* args) { + base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->RemoveAllPendingContributions(); @@ -1645,9 +1607,8 @@ void RewardsDOMHandler::OnPendingContributionRemoved( } } -void RewardsDOMHandler::OnFetchBalance( - const ledger::type::Result result, - ledger::type::BalancePtr balance) { +void RewardsDOMHandler::OnFetchBalance(const ledger::type::Result result, + ledger::type::BalancePtr balance) { if (!IsJavascriptAllowed()) { return; } @@ -1674,16 +1635,15 @@ void RewardsDOMHandler::OnFetchBalance( CallJavascriptFunction("brave_rewards.balance", data); } -void RewardsDOMHandler::FetchBalance(const base::ListValue* args) { +void RewardsDOMHandler::FetchBalance(base::Value::ConstListView args) { if (rewards_service_) { AllowJavascript(); rewards_service_->FetchBalance(base::BindOnce( - &RewardsDOMHandler::OnFetchBalance, - weak_factory_.GetWeakPtr())); + &RewardsDOMHandler::OnFetchBalance, weak_factory_.GetWeakPtr())); } } -void RewardsDOMHandler::GetExternalWallet(const base::ListValue* args) { +void RewardsDOMHandler::GetExternalWallet(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -1741,23 +1701,22 @@ void RewardsDOMHandler::OnProcessRewardsPageUrl( CallJavascriptFunction("brave_rewards.processRewardsPageUrl", data); } -void RewardsDOMHandler::ProcessRewardsPageUrl(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::ProcessRewardsPageUrl(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - const std::string path = args->GetList()[0].GetString(); - const std::string query = args->GetList()[1].GetString(); + const std::string path = args[0].GetString(); + const std::string query = args[1].GetString(); rewards_service_->ProcessRewardsPageUrl( - path, - query, + path, query, base::BindOnce(&RewardsDOMHandler::OnProcessRewardsPageUrl, weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::DisconnectWallet(const base::ListValue* args) { +void RewardsDOMHandler::DisconnectWallet(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -1766,9 +1725,9 @@ void RewardsDOMHandler::DisconnectWallet(const base::ListValue* args) { } void RewardsDOMHandler::OnDisconnectWallet( - brave_rewards::RewardsService* rewards_service, - const ledger::type::Result result, - const std::string& wallet_type) { + brave_rewards::RewardsService* rewards_service, + const ledger::type::Result result, + const std::string& wallet_type) { base::Value data(base::Value::Type::DICTIONARY); data.SetIntKey("result", static_cast(result)); data.SetStringKey("walletType", wallet_type); @@ -1783,10 +1742,9 @@ void RewardsDOMHandler::OnAdsEnabled( return; } - base::ListValue* emptyArgs = nullptr; - GetAdsData(emptyArgs); - GetAutoContributeProperties(emptyArgs); - GetOnboardingStatus(emptyArgs); + GetAdsData(base::Value::ConstListView()); + GetAutoContributeProperties(base::Value::ConstListView()); + GetOnboardingStatus(base::Value::ConstListView()); } void RewardsDOMHandler::OnUnblindedTokensReady( @@ -1830,23 +1788,20 @@ void RewardsDOMHandler::OnGetBalanceReport( CallJavascriptFunction("brave_rewards.balanceReport", data); } -void RewardsDOMHandler::GetBalanceReport(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::GetBalanceReport(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - const uint32_t month = args->GetList()[0].GetInt(); - const uint32_t year = args->GetList()[1].GetInt(); + const uint32_t month = args[0].GetInt(); + const uint32_t year = args[1].GetInt(); rewards_service_->GetBalanceReport( - month, - year, + month, year, base::BindOnce(&RewardsDOMHandler::OnGetBalanceReport, - weak_factory_.GetWeakPtr(), - month, - year)); + weak_factory_.GetWeakPtr(), month, year)); } void RewardsDOMHandler::OnGetMonthlyReport( @@ -1873,9 +1828,8 @@ void RewardsDOMHandler::OnGetMonthlyReport( base::Value transaction_report(base::Value::Type::DICTIONARY); transaction_report.SetDoubleKey("amount", item->amount); transaction_report.SetIntKey("type", static_cast(item->type)); - transaction_report.SetIntKey( - "processor", - static_cast(item->processor)); + transaction_report.SetIntKey("processor", + static_cast(item->processor)); transaction_report.SetIntKey("created_at", item->created_at); transactions.Append(std::move(transaction_report)); @@ -1901,9 +1855,8 @@ void RewardsDOMHandler::OnGetMonthlyReport( base::Value contribution_report(base::Value::Type::DICTIONARY); contribution_report.SetDoubleKey("amount", contribution->amount); contribution_report.SetIntKey("type", static_cast(contribution->type)); - contribution_report.SetIntKey( - "processor", - static_cast(contribution->processor)); + contribution_report.SetIntKey("processor", + static_cast(contribution->processor)); contribution_report.SetIntKey("created_at", contribution->created_at); contribution_report.SetKey("publishers", std::move(publishers)); contributions.Append(std::move(contribution_report)); @@ -1919,24 +1872,21 @@ void RewardsDOMHandler::OnGetMonthlyReport( CallJavascriptFunction("brave_rewards.monthlyReport", data); } -void RewardsDOMHandler::GetMonthlyReport(const base::ListValue* args) { - CHECK_EQ(2U, args->GetSize()); +void RewardsDOMHandler::GetMonthlyReport(base::Value::ConstListView args) { + CHECK_EQ(2U, args.size()); if (!rewards_service_) { return; } AllowJavascript(); - const uint32_t month = args->GetList()[0].GetInt(); - const uint32_t year = args->GetList()[1].GetInt(); + const uint32_t month = args[0].GetInt(); + const uint32_t year = args[1].GetInt(); rewards_service_->GetMonthlyReport( - month, - year, + month, year, base::BindOnce(&RewardsDOMHandler::OnGetMonthlyReport, - weak_factory_.GetWeakPtr(), - month, - year)); + weak_factory_.GetWeakPtr(), month, year)); } void RewardsDOMHandler::OnGetAllMonthlyReportIds( @@ -1949,7 +1899,8 @@ void RewardsDOMHandler::OnGetAllMonthlyReportIds( CallJavascriptFunction("brave_rewards.monthlyReportIds", list); } -void RewardsDOMHandler::GetAllMonthlyReportIds(const base::ListValue* args) { +void RewardsDOMHandler::GetAllMonthlyReportIds( + base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -1958,10 +1909,10 @@ void RewardsDOMHandler::GetAllMonthlyReportIds(const base::ListValue* args) { rewards_service_->GetAllMonthlyReportIds( base::BindOnce(&RewardsDOMHandler::OnGetAllMonthlyReportIds, - weak_factory_.GetWeakPtr())); + weak_factory_.GetWeakPtr())); } -void RewardsDOMHandler::GetCountryCode(const base::ListValue* args) { +void RewardsDOMHandler::GetCountryCode(base::Value::ConstListView args) { AllowJavascript(); const std::string locale = @@ -1972,7 +1923,7 @@ void RewardsDOMHandler::GetCountryCode(const base::ListValue* args) { base::Value(country_code)); } -void RewardsDOMHandler::CompleteReset(const base::ListValue* args) { +void RewardsDOMHandler::CompleteReset(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -1989,7 +1940,7 @@ void RewardsDOMHandler::OnCompleteReset(const bool success) { CallJavascriptFunction("brave_rewards.completeReset", base::Value(success)); } -void RewardsDOMHandler::GetPaymentId(const base::ListValue* args) { +void RewardsDOMHandler::GetPaymentId(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -2000,14 +1951,13 @@ void RewardsDOMHandler::GetPaymentId(const base::ListValue* args) { // to retrieve a payment ID. rewards_service_->CreateWallet( base::BindOnce(&RewardsDOMHandler::OnWalletCreatedForPaymentId, - weak_factory_.GetWeakPtr())); + weak_factory_.GetWeakPtr())); } void RewardsDOMHandler::OnWalletCreatedForPaymentId( ledger::type::Result result) { - rewards_service_->GetBraveWallet( - base::BindOnce(&RewardsDOMHandler::OnGetPaymentId, - weak_factory_.GetWeakPtr())); + rewards_service_->GetBraveWallet(base::BindOnce( + &RewardsDOMHandler::OnGetPaymentId, weak_factory_.GetWeakPtr())); } void RewardsDOMHandler::OnGetPaymentId(ledger::type::BraveWalletPtr wallet) { @@ -2023,7 +1973,7 @@ void RewardsDOMHandler::OnGetPaymentId(ledger::type::BraveWalletPtr wallet) { CallJavascriptFunction("brave_rewards.paymentId", base::Value(payment_id)); } -void RewardsDOMHandler::GetWalletPassphrase(const base::ListValue* args) { +void RewardsDOMHandler::GetWalletPassphrase(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -2042,7 +1992,7 @@ void RewardsDOMHandler::OnGetWalletPassphrase(const std::string& passphrase) { base::Value(passphrase)); } -void RewardsDOMHandler::GetOnboardingStatus(const base::ListValue* args) { +void RewardsDOMHandler::GetOnboardingStatus(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -2052,18 +2002,18 @@ void RewardsDOMHandler::GetOnboardingStatus(const base::ListValue* args) { CallJavascriptFunction("brave_rewards.onboardingStatus", data); } -void RewardsDOMHandler::SaveOnboardingResult(const base::ListValue* args) { - CHECK_EQ(1U, args->GetSize()); +void RewardsDOMHandler::SaveOnboardingResult(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) return; AllowJavascript(); - if (args->GetList()[0].GetString() == "opted-in") + if (args[0].GetString() == "opted-in") rewards_service_->EnableRewards(); } void RewardsDOMHandler::GetExternalWalletProviders( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!rewards_service_) return; @@ -2093,7 +2043,7 @@ BraveRewardsPageUI::BraveRewardsPageUI(content::WebUI* web_ui, #endif /*disable_trusted_types_csp=*/true); auto handler_owner = std::make_unique(); - RewardsDOMHandler * handler = handler_owner.get(); + RewardsDOMHandler* handler = handler_owner.get(); web_ui->AddMessageHandler(std::move(handler_owner)); handler->Init(); } diff --git a/browser/ui/webui/brave_tip_ui.cc b/browser/ui/webui/brave_tip_ui.cc index 3a3e0b112f2b..84f054f788e6 100644 --- a/browser/ui/webui/brave_tip_ui.cc +++ b/browser/ui/webui/brave_tip_ui.cc @@ -52,13 +52,11 @@ class TipMessageHandler : public WebUIMessageHandler, void RegisterMessages() override; // RewardsServiceObserver: - void OnRecurringTipSaved( - RewardsService* rewards_service, - bool success) override; + void OnRecurringTipSaved(RewardsService* rewards_service, + bool success) override; - void OnRecurringTipRemoved( - RewardsService* rewards_service, - bool success) override; + void OnRecurringTipRemoved(RewardsService* rewards_service, + bool success) override; void OnReconcileComplete( RewardsService* rewards_service, @@ -72,21 +70,21 @@ class TipMessageHandler : public WebUIMessageHandler, private: // Message handlers - void DialogReady(const base::ListValue* args); - void GetPublisherBanner(const base::ListValue* args); - void GetRewardsParameters(const base::ListValue* args); - void GetOnboardingStatus(const base::ListValue* args); - void SaveOnboardingResult(const base::ListValue* args); - void OnTip(const base::ListValue* args); - void GetRecurringTips(const base::ListValue* args); - void GetReconcileStamp(const base::ListValue* args); - void GetAutoContributeAmount(const base::ListValue* args); - void SetAutoContributeAmount(const base::ListValue* args); - void GetAdsPerHour(const base::ListValue* args); - void SetAdsPerHour(const base::ListValue* args); - void TweetTip(const base::ListValue* args); - void GetExternalWallet(const base::ListValue* args); - void FetchBalance(const base::ListValue* args); + void DialogReady(base::Value::ConstListView args); + void GetPublisherBanner(base::Value::ConstListView args); + void GetRewardsParameters(base::Value::ConstListView args); + void GetOnboardingStatus(base::Value::ConstListView args); + void SaveOnboardingResult(base::Value::ConstListView args); + void OnTip(base::Value::ConstListView args); + void GetRecurringTips(base::Value::ConstListView args); + void GetReconcileStamp(base::Value::ConstListView args); + void GetAutoContributeAmount(base::Value::ConstListView args); + void SetAutoContributeAmount(base::Value::ConstListView args); + void GetAdsPerHour(base::Value::ConstListView args); + void SetAdsPerHour(base::Value::ConstListView args); + void TweetTip(base::Value::ConstListView args); + void GetExternalWallet(base::Value::ConstListView args); + void FetchBalance(base::Value::ConstListView args); // Rewards service callbacks void GetReconcileStampCallback(uint64_t reconcile_stamp); @@ -102,14 +100,13 @@ class TipMessageHandler : public WebUIMessageHandler, void GetShareURLCallback(const std::string& url); - void FetchBalanceCallback( - const ledger::type::Result result, - ledger::type::BalancePtr balance); + void FetchBalanceCallback(const ledger::type::Result result, + ledger::type::BalancePtr balance); void GetRewardsParametersCallback( - ledger::type::RewardsParametersPtr parameters); + ledger::type::RewardsParametersPtr parameters); - RewardsService* rewards_service_ = nullptr; // NOT OWNED + RewardsService* rewards_service_ = nullptr; // NOT OWNED brave_ads::AdsService* ads_service_ = nullptr; // NOT OWNED base::WeakPtrFactory weak_factory_{this}; }; @@ -123,79 +120,78 @@ TipMessageHandler::~TipMessageHandler() { } void TipMessageHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "dialogReady", base::BindRepeating(&TipMessageHandler::DialogReady, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getPublisherBanner", base::BindRepeating(&TipMessageHandler::GetPublisherBanner, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getRewardsParameters", base::BindRepeating(&TipMessageHandler::GetRewardsParameters, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getOnboardingStatus", base::BindRepeating(&TipMessageHandler::GetOnboardingStatus, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "saveOnboardingResult", base::BindRepeating(&TipMessageHandler::SaveOnboardingResult, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "onTip", base::BindRepeating(&TipMessageHandler::OnTip, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getRecurringTips", base::BindRepeating(&TipMessageHandler::GetRecurringTips, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getReconcileStamp", base::BindRepeating(&TipMessageHandler::GetReconcileStamp, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getAutoContributeAmount", base::BindRepeating(&TipMessageHandler::GetAutoContributeAmount, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setAutoContributeAmount", base::BindRepeating(&TipMessageHandler::SetAutoContributeAmount, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getAdsPerHour", base::BindRepeating(&TipMessageHandler::GetAdsPerHour, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setAdsPerHour", base::BindRepeating(&TipMessageHandler::SetAdsPerHour, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "tweetTip", base::BindRepeating(&TipMessageHandler::TweetTip, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "fetchBalance", base::BindRepeating(&TipMessageHandler::FetchBalance, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getExternalWallet", base::BindRepeating(&TipMessageHandler::GetExternalWallet, base::Unretained(this))); } -void TipMessageHandler::OnRecurringTipRemoved( - RewardsService* rewards_service, - bool success) { +void TipMessageHandler::OnRecurringTipRemoved(RewardsService* rewards_service, + bool success) { if (!IsJavascriptAllowed()) { return; } @@ -203,9 +199,8 @@ void TipMessageHandler::OnRecurringTipRemoved( FireWebUIListener("recurringTipRemoved", base::Value(success)); } -void TipMessageHandler::OnRecurringTipSaved( - RewardsService* rewards_service, - bool success) { +void TipMessageHandler::OnRecurringTipSaved(RewardsService* rewards_service, + bool success) { if (!IsJavascriptAllowed()) { return; } @@ -240,7 +235,7 @@ void TipMessageHandler::OnUnblindedTokensReady( FireWebUIListener("unblindedTokensReady"); } -void TipMessageHandler::DialogReady(const base::ListValue* args) { +void TipMessageHandler::DialogReady(base::Value::ConstListView args) { Profile* profile = Profile::FromWebUI(web_ui()); if (!rewards_service_) { @@ -260,9 +255,9 @@ void TipMessageHandler::DialogReady(const base::ListValue* args) { } } -void TipMessageHandler::GetPublisherBanner(const base::ListValue* args) { - CHECK_EQ(1U, args->GetSize()); - const std::string publisher_key = args->GetList()[0].GetString(); +void TipMessageHandler::GetPublisherBanner(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); + const std::string publisher_key = args[0].GetString(); if (publisher_key.empty() || !rewards_service_) { return; @@ -274,7 +269,7 @@ void TipMessageHandler::GetPublisherBanner(const base::ListValue* args) { weak_factory_.GetWeakPtr())); } -void TipMessageHandler::GetRewardsParameters(const base::ListValue* args) { +void TipMessageHandler::GetRewardsParameters(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -284,7 +279,7 @@ void TipMessageHandler::GetRewardsParameters(const base::ListValue* args) { weak_factory_.GetWeakPtr())); } -void TipMessageHandler::GetOnboardingStatus(const base::ListValue* args) { +void TipMessageHandler::GetOnboardingStatus(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -294,20 +289,20 @@ void TipMessageHandler::GetOnboardingStatus(const base::ListValue* args) { FireWebUIListener("onboardingStatusUpdated", data); } -void TipMessageHandler::SaveOnboardingResult(const base::ListValue* args) { - CHECK_EQ(1U, args->GetSize()); +void TipMessageHandler::SaveOnboardingResult(base::Value::ConstListView args) { + CHECK_EQ(1U, args.size()); if (!rewards_service_) return; - if (args->GetList()[0].GetString() == "opted-in") + if (args[0].GetString() == "opted-in") rewards_service_->EnableRewards(); } -void TipMessageHandler::OnTip(const base::ListValue* args) { - CHECK_EQ(3U, args->GetSize()); - const std::string publisher_key = args->GetList()[0].GetString(); - const double amount = args->GetList()[1].GetDouble(); - const bool recurring = args->GetList()[2].GetBool(); +void TipMessageHandler::OnTip(base::Value::ConstListView args) { + CHECK_EQ(3U, args.size()); + const std::string publisher_key = args[0].GetString(); + const double amount = args[1].GetDouble(); + const bool recurring = args[2].GetBool(); if (publisher_key.empty() || !rewards_service_) { return; @@ -320,7 +315,7 @@ void TipMessageHandler::OnTip(const base::ListValue* args) { } } -void TipMessageHandler::GetReconcileStamp(const base::ListValue* args) { +void TipMessageHandler::GetReconcileStamp(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -330,7 +325,8 @@ void TipMessageHandler::GetReconcileStamp(const base::ListValue* args) { weak_factory_.GetWeakPtr())); } -void TipMessageHandler::GetAutoContributeAmount(const base::ListValue* args) { +void TipMessageHandler::GetAutoContributeAmount( + base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -340,9 +336,10 @@ void TipMessageHandler::GetAutoContributeAmount(const base::ListValue* args) { weak_factory_.GetWeakPtr())); } -void TipMessageHandler::SetAutoContributeAmount(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); - double amount = args->GetList()[0].GetDouble(); +void TipMessageHandler::SetAutoContributeAmount( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); + double amount = args[0].GetDouble(); if (!rewards_service_ || amount < 0) { return; } @@ -351,7 +348,7 @@ void TipMessageHandler::SetAutoContributeAmount(const base::ListValue* args) { FireWebUIListener("autoContributeAmountUpdated", base::Value(amount)); } -void TipMessageHandler::GetAdsPerHour(const base::ListValue* args) { +void TipMessageHandler::GetAdsPerHour(base::Value::ConstListView args) { if (!ads_service_) { return; } @@ -360,9 +357,9 @@ void TipMessageHandler::GetAdsPerHour(const base::ListValue* args) { FireWebUIListener("adsPerHourUpdated", base::Value(adsPerHour)); } -void TipMessageHandler::SetAdsPerHour(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); - const double adsPerHour = args->GetList()[0].GetDouble(); +void TipMessageHandler::SetAdsPerHour(base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); + const double adsPerHour = args[0].GetDouble(); if (!ads_service_ || adsPerHour < 0) { return; } @@ -371,18 +368,17 @@ void TipMessageHandler::SetAdsPerHour(const base::ListValue* args) { FireWebUIListener("adsPerHourUpdated", base::Value(adsPerHour)); } -void TipMessageHandler::TweetTip(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 2U); - const std::string name = args->GetList()[0].GetString(); - const std::string tweet_id = args->GetList()[1].GetString(); +void TipMessageHandler::TweetTip(base::Value::ConstListView args) { + CHECK_EQ(args.size(), 2U); + const std::string name = args[0].GetString(); + const std::string tweet_id = args[1].GetString(); if (name.empty() || !rewards_service_) { return; } const std::string comment = l10n_util::GetStringFUTF8( - IDS_BRAVE_REWARDS_LOCAL_COMPLIMENT_TWEET, - base::UTF8ToUTF16(name)); + IDS_BRAVE_REWARDS_LOCAL_COMPLIMENT_TWEET, base::UTF8ToUTF16(name)); const std::string hashtag = l10n_util::GetStringUTF8( IDS_BRAVE_REWARDS_LOCAL_COMPLIMENT_TWEET_HASHTAG); @@ -398,16 +394,15 @@ void TipMessageHandler::TweetTip(const base::ListValue* args) { weak_factory_.GetWeakPtr())); } -void TipMessageHandler::FetchBalance(const base::ListValue* args) { +void TipMessageHandler::FetchBalance(base::Value::ConstListView args) { if (!rewards_service_) { return; } rewards_service_->FetchBalance(base::BindOnce( - &TipMessageHandler::FetchBalanceCallback, - weak_factory_.GetWeakPtr())); + &TipMessageHandler::FetchBalanceCallback, weak_factory_.GetWeakPtr())); } -void TipMessageHandler::GetExternalWallet(const base::ListValue* args) { +void TipMessageHandler::GetExternalWallet(base::Value::ConstListView args) { if (!rewards_service_) { return; } @@ -416,13 +411,13 @@ void TipMessageHandler::GetExternalWallet(const base::ListValue* args) { weak_factory_.GetWeakPtr())); } -void TipMessageHandler::GetRecurringTips(const base::ListValue* args) { +void TipMessageHandler::GetRecurringTips(base::Value::ConstListView args) { if (!rewards_service_) { return; } - rewards_service_->GetRecurringTips(base::BindOnce( - &TipMessageHandler::GetRecurringTipsCallback, - weak_factory_.GetWeakPtr())); + rewards_service_->GetRecurringTips( + base::BindOnce(&TipMessageHandler::GetRecurringTipsCallback, + weak_factory_.GetWeakPtr())); } void TipMessageHandler::GetRewardsParametersCallback( @@ -535,16 +530,12 @@ void TipMessageHandler::GetShareURLCallback(const std::string& url) { Profile::FromWebUI(web_ui())); browser_displayer.browser()->OpenURL(content::OpenURLParams( - gurl, - content::Referrer(), - WindowOpenDisposition::NEW_FOREGROUND_TAB, - ui::PAGE_TRANSITION_AUTO_TOPLEVEL, - false)); + gurl, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, + ui::PAGE_TRANSITION_AUTO_TOPLEVEL, false)); } -void TipMessageHandler::FetchBalanceCallback( - const ledger::type::Result result, - ledger::type::BalancePtr balance) { +void TipMessageHandler::FetchBalanceCallback(const ledger::type::Result result, + ledger::type::BalancePtr balance) { if (!IsJavascriptAllowed()) { return; } diff --git a/browser/ui/webui/brave_welcome_ui.cc b/browser/ui/webui/brave_welcome_ui.cc index 4249f80299e9..bf35307b1042 100644 --- a/browser/ui/webui/brave_welcome_ui.cc +++ b/browser/ui/webui/brave_welcome_ui.cc @@ -59,16 +59,15 @@ void RecordP3AHistogram(int screen_number, bool finished) { // The handler for Javascript messages for the chrome://welcome page class WelcomeDOMHandler : public WebUIMessageHandler { public: - WelcomeDOMHandler() { - } + WelcomeDOMHandler() {} ~WelcomeDOMHandler() override; // WebUIMessageHandler implementation. void RegisterMessages() override; private: - void HandleImportNowRequested(const base::ListValue* args); - void HandleRecordP3A(const base::ListValue* args); + void HandleImportNowRequested(base::Value::ConstListView args); + void HandleRecordP3A(base::Value::ConstListView args); Browser* GetBrowser(); int screen_number_ = 0; @@ -87,28 +86,27 @@ Browser* WelcomeDOMHandler::GetBrowser() { } void WelcomeDOMHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "importNowRequested", base::BindRepeating(&WelcomeDOMHandler::HandleImportNowRequested, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "recordP3A", base::BindRepeating(&WelcomeDOMHandler::HandleRecordP3A, base::Unretained(this))); } -void WelcomeDOMHandler::HandleImportNowRequested(const base::ListValue* args) { +void WelcomeDOMHandler::HandleImportNowRequested( + base::Value::ConstListView args) { chrome::ShowSettingsSubPageInTabbedBrowser(GetBrowser(), - chrome::kImportDataSubPage); + chrome::kImportDataSubPage); } -void WelcomeDOMHandler::HandleRecordP3A(const base::ListValue* args) { - if (!args[0].is_int()) +void WelcomeDOMHandler::HandleRecordP3A(base::Value::ConstListView args) { + if (!args[0].is_int() || !args[1].is_bool() || !args[2].is_bool()) return; screen_number_ = args[0].GetInt(); - if (!args->GetBoolean(1, &finished_)) - return; - if (!args->GetBoolean(2, &skipped_)) - return; + finished_ = args[1].GetBool(); + skipped_ = args[1].GetBool(); if (screen_number_) { // It is 1-based on JS side, we want 0-based. @@ -162,5 +160,4 @@ BraveWelcomeUI::BraveWelcomeUI(content::WebUI* web_ui, const std::string& name) profile->GetPrefs()->SetBoolean(prefs::kHasSeenWelcomePage, true); } -BraveWelcomeUI::~BraveWelcomeUI() { -} +BraveWelcomeUI::~BraveWelcomeUI() {} diff --git a/browser/ui/webui/ipfs_ui.cc b/browser/ui/webui/ipfs_ui.cc index 1bcd2be18f27..01c9102b10a6 100644 --- a/browser/ui/webui/ipfs_ui.cc +++ b/browser/ui/webui/ipfs_ui.cc @@ -46,39 +46,39 @@ IPFSDOMHandler::IPFSDOMHandler() : weak_ptr_factory_{this} {} IPFSDOMHandler::~IPFSDOMHandler() {} void IPFSDOMHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.getConnectedPeers", base::BindRepeating(&IPFSDOMHandler::HandleGetConnectedPeers, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.getAddressesConfig", base::BindRepeating(&IPFSDOMHandler::HandleGetAddressesConfig, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.getDaemonStatus", base::BindRepeating(&IPFSDOMHandler::HandleGetDaemonStatus, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.launchDaemon", base::BindRepeating(&IPFSDOMHandler::HandleLaunchDaemon, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.shutdownDaemon", base::BindRepeating(&IPFSDOMHandler::HandleShutdownDaemon, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.restartDaemon", base::BindRepeating(&IPFSDOMHandler::HandleRestartDaemon, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.getRepoStats", base::BindRepeating(&IPFSDOMHandler::HandleGetRepoStats, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.getNodeInfo", base::BindRepeating(&IPFSDOMHandler::HandleGetNodeInfo, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "ipfs.garbageCollection", base::BindRepeating(&IPFSDOMHandler::HandleGarbageCollection, base::Unretained(this))); @@ -100,8 +100,8 @@ IPFSUI::IPFSUI(content::WebUI* web_ui, const std::string& name) IPFSUI::~IPFSUI() {} -void IPFSDOMHandler::HandleGetConnectedPeers(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleGetConnectedPeers(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -125,8 +125,8 @@ void IPFSDOMHandler::OnGetConnectedPeers( std::move(stats_value)); } -void IPFSDOMHandler::HandleGetAddressesConfig(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleGetAddressesConfig(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -157,16 +157,16 @@ void IPFSDOMHandler::OnGetAddressesConfig(bool success, std::move(config_value)); } -void IPFSDOMHandler::HandleGetDaemonStatus(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleGetDaemonStatus(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; CallOnGetDaemonStatus(web_ui(), std::string()); } -void IPFSDOMHandler::HandleLaunchDaemon(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleLaunchDaemon(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; LaunchDaemon(); @@ -221,8 +221,8 @@ void IPFSDOMHandler::OnIpfsShutdown() { CallOnGetDaemonStatus(web_ui(), std::string()); } -void IPFSDOMHandler::HandleShutdownDaemon(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleShutdownDaemon(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -235,8 +235,8 @@ void IPFSDOMHandler::HandleShutdownDaemon(const base::ListValue* args) { service->ShutdownDaemon(base::NullCallback()); } -void IPFSDOMHandler::HandleRestartDaemon(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleRestartDaemon(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -250,8 +250,8 @@ void IPFSDOMHandler::HandleRestartDaemon(const base::ListValue* args) { } } -void IPFSDOMHandler::HandleGetRepoStats(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleGetRepoStats(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -281,8 +281,8 @@ void IPFSDOMHandler::OnGetRepoStats(bool success, std::move(stats_value)); } -void IPFSDOMHandler::HandleGetNodeInfo(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleGetNodeInfo(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -296,8 +296,8 @@ void IPFSDOMHandler::HandleGetNodeInfo(const base::ListValue* args) { weak_ptr_factory_.GetWeakPtr())); } -void IPFSDOMHandler::HandleGarbageCollection(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void IPFSDOMHandler::HandleGarbageCollection(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; diff --git a/browser/ui/webui/ipfs_ui.h b/browser/ui/webui/ipfs_ui.h index b695030a7482..4b8d6e0126ce 100644 --- a/browser/ui/webui/ipfs_ui.h +++ b/browser/ui/webui/ipfs_ui.h @@ -39,23 +39,23 @@ class IPFSDOMHandler : public content::WebUIMessageHandler, void OnInstallationEvent(ipfs::ComponentUpdaterEvents event) override; private: - void HandleGetConnectedPeers(const base::ListValue* args); - void HandleGetAddressesConfig(const base::ListValue* args); + void HandleGetConnectedPeers(base::Value::ConstListView args); + void HandleGetAddressesConfig(base::Value::ConstListView args); void OnGetAddressesConfig(bool success, const ipfs::AddressesConfig& config); - void HandleGetDaemonStatus(const base::ListValue* args); - void HandleLaunchDaemon(const base::ListValue* args); + void HandleGetDaemonStatus(base::Value::ConstListView args); + void HandleLaunchDaemon(base::Value::ConstListView args); void LaunchDaemon(); void OnLaunchDaemon(bool success); - void HandleShutdownDaemon(const base::ListValue* args); - void HandleRestartDaemon(const base::ListValue* args); + void HandleShutdownDaemon(base::Value::ConstListView args); + void HandleRestartDaemon(base::Value::ConstListView args); void OnShutdownDaemon(bool success); - void HandleGetRepoStats(const base::ListValue* args); + void HandleGetRepoStats(base::Value::ConstListView args); void OnGetRepoStats(bool success, const ipfs::RepoStats& stats); - void HandleGetNodeInfo(const base::ListValue* args); + void HandleGetNodeInfo(base::Value::ConstListView args); void OnGetNodeInfo(bool success, const ipfs::NodeInfo& info); - void HandleGarbageCollection(const base::ListValue* args); + void HandleGarbageCollection(base::Value::ConstListView args); void OnGarbageCollection(bool success, const std::string& error); base::ScopedObservation diff --git a/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.cc b/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.cc index 8f64bce3de25..3730274a01f2 100644 --- a/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.cc +++ b/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.cc @@ -42,11 +42,12 @@ #include "components/prefs/pref_service.h" #include "content/public/browser/web_ui_data_source.h" +using ntp_background_images::ViewCounterServiceFactory; using ntp_background_images::features::kBraveNTPBrandedWallpaper; -using ntp_background_images::prefs::kNewTabPageShowBackgroundImage; -using ntp_background_images::prefs::kNewTabPageShowSponsoredImagesBackgroundImage; // NOLINT using ntp_background_images::prefs::kBrandedWallpaperNotificationDismissed; -using ntp_background_images::ViewCounterServiceFactory; +using ntp_background_images::prefs::kNewTabPageShowBackgroundImage; +using ntp_background_images::prefs:: + kNewTabPageShowSponsoredImagesBackgroundImage; // NOLINT #if BUILDFLAG(CRYPTO_DOT_COM_ENABLED) #include "brave/components/crypto_dot_com/common/pref_names.h" @@ -69,14 +70,12 @@ bool IsPrivateNewTab(Profile* profile) { base::DictionaryValue GetStatsDictionary(PrefService* prefs) { base::DictionaryValue stats_data; stats_data.SetInteger( - "adsBlockedStat", - prefs->GetUint64(kAdsBlocked) + prefs->GetUint64(kTrackersBlocked)); - stats_data.SetInteger( - "javascriptBlockedStat", - prefs->GetUint64(kJavascriptBlocked)); - stats_data.SetInteger( - "fingerprintingBlockedStat", - prefs->GetUint64(kFingerprintingBlocked)); + "adsBlockedStat", + prefs->GetUint64(kAdsBlocked) + prefs->GetUint64(kTrackersBlocked)); + stats_data.SetInteger("javascriptBlockedStat", + prefs->GetUint64(kJavascriptBlocked)); + stats_data.SetInteger("fingerprintingBlockedStat", + prefs->GetUint64(kFingerprintingBlocked)); stats_data.SetDouble( "bandwidthSavedStat", prefs->GetUint64(brave_perf_predictor::prefs::kBandwidthSavedBytes)); @@ -138,12 +137,7 @@ base::DictionaryValue GetTorPropertiesDictionary(bool connected, // TODO(petemill): Move p3a to own NTP component so it can // be used by other platforms. -enum class NTPCustomizeUsage { - kNeverOpened, - kOpened, - kOpenedAndEdited, - kSize -}; +enum class NTPCustomizeUsage { kNeverOpened, kOpened, kOpenedAndEdited, kSize }; const char kNTPCustomizeUsageStatus[] = "brave.new_tab_page.customize_p3a_usage"; @@ -180,7 +174,8 @@ bool BraveNewTabMessageHandler::CanPromptBraveTalk(base::Time now) { } BraveNewTabMessageHandler* BraveNewTabMessageHandler::Create( - content::WebUIDataSource* source, Profile* profile) { + content::WebUIDataSource* source, + Profile* profile) { // // Initial Values // Should only contain data that is static @@ -196,19 +191,16 @@ BraveNewTabMessageHandler* BraveNewTabMessageHandler::Create( is_ads_supported_locale_ = ads_service_->IsSupportedLocale(); } - source->AddBoolean( - "featureFlagBraveNTPSponsoredImagesWallpaper", - base::FeatureList::IsEnabled(kBraveNTPBrandedWallpaper) && - is_ads_supported_locale_); + source->AddBoolean("featureFlagBraveNTPSponsoredImagesWallpaper", + base::FeatureList::IsEnabled(kBraveNTPBrandedWallpaper) && + is_ads_supported_locale_); source->AddBoolean("braveTalkPromptAllowed", BraveNewTabMessageHandler::CanPromptBraveTalk()); // Private Tab info if (IsPrivateNewTab(profile)) { - source->AddBoolean( - "isTor", profile->IsTor()); - source->AddBoolean( - "isQwant", brave::IsRegionForQwant(profile)); + source->AddBoolean("isTor", profile->IsTor()); + source->AddBoolean("isQwant", brave::IsRegionForQwant(profile)); } return new BraveNewTabMessageHandler(profile); } @@ -234,79 +226,79 @@ void BraveNewTabMessageHandler::RegisterMessages() { // - Stats // - Preferences // - PrivatePage properties - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getNewTabPagePreferences", base::BindRepeating(&BraveNewTabMessageHandler::HandleGetPreferences, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getNewTabPageStats", base::BindRepeating(&BraveNewTabMessageHandler::HandleGetStats, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getNewTabPagePrivateProperties", base::BindRepeating( &BraveNewTabMessageHandler::HandleGetPrivateProperties, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getNewTabPageTorProperties", base::BindRepeating(&BraveNewTabMessageHandler::HandleGetTorProperties, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "toggleAlternativePrivateSearchEngine", base::BindRepeating(&BraveNewTabMessageHandler:: HandleToggleAlternativeSearchEngineProvider, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "saveNewTabPagePref", base::BindRepeating(&BraveNewTabMessageHandler::HandleSaveNewTabPagePref, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "registerNewTabPageView", base::BindRepeating( &BraveNewTabMessageHandler::HandleRegisterNewTabPageView, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "brandedWallpaperLogoClicked", base::BindRepeating( &BraveNewTabMessageHandler::HandleBrandedWallpaperLogoClicked, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getBrandedWallpaperData", base::BindRepeating( &BraveNewTabMessageHandler::HandleGetBrandedWallpaperData, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "customizeClicked", base::BindRepeating(&BraveNewTabMessageHandler::HandleCustomizeClicked, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayInteractionBegin", base::BindRepeating( &BraveNewTabMessageHandler::HandleTodayInteractionBegin, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayOnCardVisit", base::BindRepeating(&BraveNewTabMessageHandler::HandleTodayOnCardVisit, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayOnCardViews", base::BindRepeating(&BraveNewTabMessageHandler::HandleTodayOnCardViews, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayOnPromotedCardView", base::BindRepeating( &BraveNewTabMessageHandler::HandleTodayOnPromotedCardView, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayGetDisplayAd", base::BindRepeating(&BraveNewTabMessageHandler::HandleTodayGetDisplayAd, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayOnDisplayAdVisit", base::BindRepeating( &BraveNewTabMessageHandler::HandleTodayOnDisplayAdVisit, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "todayOnDisplayAdView", base::BindRepeating( &BraveNewTabMessageHandler::HandleTodayOnDisplayAdView, @@ -434,30 +426,31 @@ void BraveNewTabMessageHandler::OnJavascriptDisallowed() { } void BraveNewTabMessageHandler::HandleGetPreferences( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); PrefService* prefs = profile_->GetPrefs(); auto data = GetPreferencesDictionary(prefs); - ResolveJavascriptCallback(args->GetList()[0], data); + ResolveJavascriptCallback(args[0], data); } -void BraveNewTabMessageHandler::HandleGetStats(const base::ListValue* args) { +void BraveNewTabMessageHandler::HandleGetStats( + base::Value::ConstListView args) { AllowJavascript(); PrefService* prefs = profile_->GetPrefs(); auto data = GetStatsDictionary(prefs); - ResolveJavascriptCallback(args->GetList()[0], data); + ResolveJavascriptCallback(args[0], data); } void BraveNewTabMessageHandler::HandleGetPrivateProperties( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); PrefService* prefs = profile_->GetPrefs(); auto data = GetPrivatePropertiesDictionary(prefs); - ResolveJavascriptCallback(args->GetList()[0], data); + ResolveJavascriptCallback(args[0], data); } void BraveNewTabMessageHandler::HandleGetTorProperties( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); #if BUILDFLAG(ENABLE_TOR) auto data = GetTorPropertiesDictionary( @@ -466,17 +459,17 @@ void BraveNewTabMessageHandler::HandleGetTorProperties( #else auto data = GetTorPropertiesDictionary(false, ""); #endif - ResolveJavascriptCallback(args->GetList()[0], data); + ResolveJavascriptCallback(args[0], data); } void BraveNewTabMessageHandler::HandleToggleAlternativeSearchEngineProvider( - const base::ListValue* args) { + base::Value::ConstListView args) { brave::ToggleUseAlternativeSearchEngineProvider(profile_); } void BraveNewTabMessageHandler::HandleSaveNewTabPagePref( - const base::ListValue* args) { - if (args->GetSize() != 2) { + base::Value::ConstListView args) { + if (args.size() != 2) { LOG(ERROR) << "Invalid input"; return; } @@ -485,8 +478,8 @@ void BraveNewTabMessageHandler::HandleSaveNewTabPagePref( kNTPCustomizeUsageStatus, g_browser_process->local_state()); PrefService* prefs = profile_->GetPrefs(); // Collect args - std::string settingsKeyInput = args->GetList()[0].GetString(); - auto settingsValue = args->GetList()[1].Clone(); + std::string settingsKeyInput = args[0].GetString(); + auto settingsValue = args[1].Clone(); std::string settingsKey; // Handle string settings @@ -556,7 +549,7 @@ void BraveNewTabMessageHandler::HandleSaveNewTabPagePref( } void BraveNewTabMessageHandler::HandleRegisterNewTabPageView( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); // Decrement original value only if there's actual branded content @@ -565,20 +558,20 @@ void BraveNewTabMessageHandler::HandleRegisterNewTabPageView( } void BraveNewTabMessageHandler::HandleBrandedWallpaperLogoClicked( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); - if (args->GetSize() != 1) { + if (args.size() != 1) { LOG(ERROR) << "Invalid input"; return; } if (auto* service = ViewCounterServiceFactory::GetForProfile(profile_)) { - auto* creative_instance_id = args->GetList()[0].FindStringKey( - ntp_background_images::kCreativeInstanceIDKey); - auto* destination_url = args->GetList()[0].FindStringPath( - ntp_background_images::kLogoDestinationURLPath); - auto* wallpaper_id = args->GetList()[0].FindStringPath( - ntp_background_images::kWallpaperIDKey); + auto* creative_instance_id = + args[0].FindStringKey(ntp_background_images::kCreativeInstanceIDKey); + auto* destination_url = + args[0].FindStringPath(ntp_background_images::kLogoDestinationURLPath); + auto* wallpaper_id = + args[0].FindStringPath(ntp_background_images::kWallpaperIDKey); DCHECK(creative_instance_id); DCHECK(destination_url); @@ -592,12 +585,12 @@ void BraveNewTabMessageHandler::HandleBrandedWallpaperLogoClicked( } void BraveNewTabMessageHandler::HandleGetBrandedWallpaperData( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); auto* service = ViewCounterServiceFactory::GetForProfile(profile_); - auto data = service ? service->GetCurrentWallpaperForDisplay() - : base::Value(); + auto data = + service ? service->GetCurrentWallpaperForDisplay() : base::Value(); if (!data.is_none()) { DCHECK(data.is_dict()); @@ -606,11 +599,11 @@ void BraveNewTabMessageHandler::HandleGetBrandedWallpaperData( service->BrandedWallpaperWillBeDisplayed(wallpaper_id); } - ResolveJavascriptCallback(args->GetList()[0], std::move(data)); + ResolveJavascriptCallback(args[0], std::move(data)); } void BraveNewTabMessageHandler::HandleCustomizeClicked( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); brave::RecordValueIfGreater( NTPCustomizeUsage::kOpened, "Brave.NTP.CustomizeUsageStatus", @@ -618,54 +611,51 @@ void BraveNewTabMessageHandler::HandleCustomizeClicked( } void BraveNewTabMessageHandler::HandleTodayInteractionBegin( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); // Track if user has ever scrolled to Brave Today. UMA_HISTOGRAM_EXACT_LINEAR("Brave.Today.HasEverInteracted", 1, 1); // Track how many times in the past week // user has scrolled to Brave Today. - WeeklyStorage session_count_storage( - profile_->GetPrefs(), kBraveTodayWeeklySessionCount); + WeeklyStorage session_count_storage(profile_->GetPrefs(), + kBraveTodayWeeklySessionCount); session_count_storage.AddDelta(1); uint64_t total_session_count = session_count_storage.GetWeeklySum(); constexpr int kSessionCountBuckets[] = {0, 1, 3, 7, 12, 18, 25, 1000}; const int* it_count = std::lower_bound(kSessionCountBuckets, std::end(kSessionCountBuckets), - total_session_count); + total_session_count); int answer = it_count - kSessionCountBuckets; UMA_HISTOGRAM_EXACT_LINEAR("Brave.Today.WeeklySessionCount", answer, base::size(kSessionCountBuckets) + 1); } void BraveNewTabMessageHandler::HandleTodayOnCardVisit( - const base::ListValue* args) { + base::Value::ConstListView args) { // Argument should be how many cards visited in this session. // We need the front-end to give us this since this class // will be destroyed and re-created when the user navigates "back", // but the front-end will have access to history state in order to // keep a count for the session. - int cards_visited_total = args->GetList()[0].GetInt(); + int cards_visited_total = args[0].GetInt(); // Track how many Brave Today cards have been viewed per session // (each NTP / NTP Message Handler is treated as 1 session). - WeeklyStorage storage( - profile_->GetPrefs(), kBraveTodayWeeklyCardVisitsCount); + WeeklyStorage storage(profile_->GetPrefs(), kBraveTodayWeeklyCardVisitsCount); storage.ReplaceTodaysValueIfGreater(cards_visited_total); // Send the session with the highest count of cards viewed. uint64_t total = storage.GetHighestValueInWeek(); constexpr int kBuckets[] = {0, 1, 3, 6, 10, 15, 100}; - const int* it_count = - std::lower_bound(kBuckets, std::end(kBuckets), - total); + const int* it_count = std::lower_bound(kBuckets, std::end(kBuckets), total); int answer = it_count - kBuckets; UMA_HISTOGRAM_EXACT_LINEAR("Brave.Today.WeeklyMaxCardVisitsCount", answer, base::size(kBuckets) + 1); // Record ad click if a promoted card was read. - if (args->GetSize() < 4) { + if (args.size() < 4) { return; } - std::string item_id = args->GetList()[1].GetString(); - std::string creative_instance_id = args->GetList()[2].GetString(); - bool is_promoted = args->GetList()[3].GetBool(); + std::string item_id = args[1].GetString(); + std::string creative_instance_id = args[2].GetString(); + bool is_promoted = args[0].GetList()[3].GetBool(); if (is_promoted && !item_id.empty() && !creative_instance_id.empty()) { auto* ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile_); ads_service_->OnPromotedContentAdEvent( @@ -675,30 +665,27 @@ void BraveNewTabMessageHandler::HandleTodayOnCardVisit( } void BraveNewTabMessageHandler::HandleTodayOnCardViews( - const base::ListValue* args) { + base::Value::ConstListView args) { // Argument should be how many cards viewed in this session. - int cards_viewed_total = args->GetList()[0].GetInt(); + int cards_viewed_total = args[0].GetInt(); // Track how many Brave Today cards have been viewed per session // (each NTP / NTP Message Handler is treated as 1 session). - WeeklyStorage storage( - profile_->GetPrefs(), kBraveTodayWeeklyCardViewsCount); + WeeklyStorage storage(profile_->GetPrefs(), kBraveTodayWeeklyCardViewsCount); storage.ReplaceTodaysValueIfGreater(cards_viewed_total); // Send the session with the highest count of cards viewed. uint64_t total = storage.GetHighestValueInWeek(); constexpr int kBuckets[] = {0, 1, 4, 12, 20, 40, 80, 1000}; - const int* it_count = - std::lower_bound(kBuckets, std::end(kBuckets), - total); + const int* it_count = std::lower_bound(kBuckets, std::end(kBuckets), total); int answer = it_count - kBuckets; UMA_HISTOGRAM_EXACT_LINEAR("Brave.Today.WeeklyMaxCardViewsCount", answer, base::size(kBuckets) + 1); } void BraveNewTabMessageHandler::HandleTodayOnPromotedCardView( - const base::ListValue* args) { + base::Value::ConstListView args) { // Argument should be how many cards viewed in this session. - std::string creative_instance_id = args->GetList()[0].GetString(); - std::string item_id = args->GetList()[1].GetString(); + std::string creative_instance_id = args[0].GetString(); + std::string item_id = args[1].GetString(); if (!item_id.empty() && !creative_instance_id.empty()) { auto* ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile_); ads_service_->OnPromotedContentAdEvent( @@ -708,10 +695,9 @@ void BraveNewTabMessageHandler::HandleTodayOnPromotedCardView( } void BraveNewTabMessageHandler::HandleTodayGetDisplayAd( - const base::ListValue* args) { + base::Value::ConstListView args) { AllowJavascript(); - std::string callback_id; - args->GetString(0, &callback_id); + std::string callback_id = args[0].GetString(); auto* ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile_); if (!ads_service_) { ResolveJavascriptCallback(base::Value(callback_id), @@ -739,12 +725,11 @@ void BraveNewTabMessageHandler::HandleTodayGetDisplayAd( } void BraveNewTabMessageHandler::HandleTodayOnDisplayAdVisit( - const base::ListValue* args) { + base::Value::ConstListView args) { // Collect params - std::string item_id; - std::string creative_instance_id; - args->GetString(0, &item_id); - args->GetString(1, &creative_instance_id); + std::string item_id = args[0].GetString(); + std::string creative_instance_id = args[1].GetString(); + // Validate if (item_id.empty()) { LOG(ERROR) << "News: asked to record visit for an ad without ad id"; @@ -769,12 +754,10 @@ void BraveNewTabMessageHandler::HandleTodayOnDisplayAdVisit( } void BraveNewTabMessageHandler::HandleTodayOnDisplayAdView( - const base::ListValue* args) { + base::Value::ConstListView args) { // Collect params - std::string item_id; - std::string creative_instance_id; - args->GetString(0, &item_id); - args->GetString(1, &creative_instance_id); + std::string item_id = args[0].GetString(); + std::string creative_instance_id = args[1].GetString(); // Validate if (item_id.empty()) { diff --git a/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.h b/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.h index f079eb074288..c9bb5595abfa 100644 --- a/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.h +++ b/browser/ui/webui/new_tab_page/brave_new_tab_message_handler.h @@ -52,26 +52,26 @@ class BraveNewTabMessageHandler : public content::WebUIMessageHandler, void OnJavascriptAllowed() override; void OnJavascriptDisallowed() override; - void HandleGetPreferences(const base::ListValue* args); - void HandleGetStats(const base::ListValue* args); - void HandleGetPrivateProperties(const base::ListValue* args); - void HandleGetTorProperties(const base::ListValue* args); - void HandleSaveNewTabPagePref(const base::ListValue* args); + void HandleGetPreferences(base::Value::ConstListView args); + void HandleGetStats(base::Value::ConstListView args); + void HandleGetPrivateProperties(base::Value::ConstListView args); + void HandleGetTorProperties(base::Value::ConstListView args); + void HandleSaveNewTabPagePref(base::Value::ConstListView args); void HandleToggleAlternativeSearchEngineProvider( - const base::ListValue* args); - void HandleRegisterNewTabPageView(const base::ListValue* args); - void HandleBrandedWallpaperLogoClicked(const base::ListValue* args); - void HandleGetBrandedWallpaperData(const base::ListValue* args); - void HandleCustomizeClicked(const base::ListValue* args); + base::Value::ConstListView args); + void HandleRegisterNewTabPageView(base::Value::ConstListView args); + void HandleBrandedWallpaperLogoClicked(base::Value::ConstListView args); + void HandleGetBrandedWallpaperData(base::Value::ConstListView args); + void HandleCustomizeClicked(base::Value::ConstListView args); // TODO(petemill): Today should get it's own message handler // or service. - void HandleTodayInteractionBegin(const base::ListValue* args); - void HandleTodayOnCardVisit(const base::ListValue* args); - void HandleTodayOnCardViews(const base::ListValue* args); - void HandleTodayOnPromotedCardView(const base::ListValue* args); - void HandleTodayGetDisplayAd(const base::ListValue* args); - void HandleTodayOnDisplayAdVisit(const base::ListValue* args); - void HandleTodayOnDisplayAdView(const base::ListValue* args); + void HandleTodayInteractionBegin(base::Value::ConstListView args); + void HandleTodayOnCardVisit(base::Value::ConstListView args); + void HandleTodayOnCardViews(base::Value::ConstListView args); + void HandleTodayOnPromotedCardView(base::Value::ConstListView args); + void HandleTodayGetDisplayAd(base::Value::ConstListView args); + void HandleTodayOnDisplayAdVisit(base::Value::ConstListView args); + void HandleTodayOnDisplayAdView(base::Value::ConstListView args); void OnStatsChanged(); void OnPreferencesChanged(); diff --git a/browser/ui/webui/new_tab_page/top_sites_message_handler.cc b/browser/ui/webui/new_tab_page/top_sites_message_handler.cc index 4eb8cf5840a6..07463b730777 100644 --- a/browser/ui/webui/new_tab_page/top_sites_message_handler.cc +++ b/browser/ui/webui/new_tab_page/top_sites_message_handler.cc @@ -44,37 +44,37 @@ TopSitesMessageHandler::TopSitesMessageHandler(Profile* profile) TopSitesMessageHandler::~TopSitesMessageHandler() = default; void TopSitesMessageHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "updateMostVisitedInfo", base::BindRepeating(&TopSitesMessageHandler::HandleUpdateMostVisitedInfo, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "deleteMostVisitedTile", base::BindRepeating(&TopSitesMessageHandler::HandleDeleteMostVisitedTile, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "reorderMostVisitedTile", base::BindRepeating(&TopSitesMessageHandler::HandleReorderMostVisitedTile, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "restoreMostVisitedDefaults", base::BindRepeating( &TopSitesMessageHandler::HandleRestoreMostVisitedDefaults, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "undoMostVisitedTileAction", base::BindRepeating( &TopSitesMessageHandler::HandleUndoMostVisitedTileAction, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setMostVisitedSettings", base::BindRepeating(&TopSitesMessageHandler::HandleSetMostVisitedSettings, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "addNewTopSite", base::BindRepeating(&TopSitesMessageHandler::HandleAddNewTopSite, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "editTopSite", base::BindRepeating(&TopSitesMessageHandler::HandleEditTopSite, base::Unretained(this))); @@ -180,7 +180,7 @@ bool TopSitesMessageHandler::IsShortcutsVisible() const { } void TopSitesMessageHandler::HandleUpdateMostVisitedInfo( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!most_visited_sites_) return; @@ -191,16 +191,16 @@ void TopSitesMessageHandler::HandleUpdateMostVisitedInfo( } void TopSitesMessageHandler::HandleDeleteMostVisitedTile( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!most_visited_sites_) return; AllowJavascript(); - std::string url; - if (!args->GetString(0, &url)) + if (!args[0].is_string()) return; + std::string url = args[0].GetString(); GURL gurl(url); // same as `MostVisitedHandler::DeleteMostVisitedTile` @@ -213,21 +213,18 @@ void TopSitesMessageHandler::HandleDeleteMostVisitedTile( } void TopSitesMessageHandler::HandleReorderMostVisitedTile( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!most_visited_sites_) return; AllowJavascript(); - std::string url; - if (!args->GetString(0, &url)) - return; - - if (!args[1].is_int()) + if (!args[0].is_string() || !args[1].is_int()) return; // same as `MostVisitedHandler::ReorderMostVisitedTile` if (most_visited_sites_->IsCustomLinksEnabled()) { + std::string url = args[0].GetString(); GURL gurl(url); int new_pos = args[1].GetInt(); most_visited_sites_->ReorderCustomLink(gurl, new_pos); @@ -235,7 +232,7 @@ void TopSitesMessageHandler::HandleReorderMostVisitedTile( } void TopSitesMessageHandler::HandleRestoreMostVisitedDefaults( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!most_visited_sites_) return; @@ -250,7 +247,7 @@ void TopSitesMessageHandler::HandleRestoreMostVisitedDefaults( } void TopSitesMessageHandler::HandleUndoMostVisitedTileAction( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!most_visited_sites_) return; @@ -266,19 +263,17 @@ void TopSitesMessageHandler::HandleUndoMostVisitedTileAction( } void TopSitesMessageHandler::HandleSetMostVisitedSettings( - const base::ListValue* args) { + base::Value::ConstListView args) { if (!most_visited_sites_) return; AllowJavascript(); - bool custom_links_enabled; - if (!args->GetBoolean(0, &custom_links_enabled)) + if (!args[0].is_bool() || !args[1].is_bool()) return; - bool visible; - if (!args->GetBoolean(1, &visible)) - return; + bool custom_links_enabled = args[0].GetBool(); + bool visible = args[1].GetBool(); // similar to `NewTabPageHandler::SetMostVisitedSettings` bool old_visible = IsShortcutsVisible(); @@ -295,24 +290,21 @@ void TopSitesMessageHandler::HandleSetMostVisitedSettings( } } -void TopSitesMessageHandler::HandleEditTopSite(const base::ListValue* args) { +void TopSitesMessageHandler::HandleEditTopSite( + base::Value::ConstListView args) { if (!most_visited_sites_) return; AllowJavascript(); - std::string url; - if (!args->GetString(0, &url)) + if (!args[0].is_string() || !args[1].is_string() || !args[2].is_string()) return; - DCHECK(!url.empty()); - std::string new_url; - if (!args->GetString(1, &new_url)) - return; + std::string url = args[0].GetString(); + DCHECK(!url.empty()); - std::string title; - if (!args->GetString(2, &title)) - return; + std::string new_url = args[1].GetString(); + std::string title = args[2].GetString(); // |new_url| can be empty if user only want to change title. // Stop editing if we can't make |new_url| valid. @@ -342,20 +334,20 @@ void TopSitesMessageHandler::HandleEditTopSite(const base::ListValue* args) { } } -void TopSitesMessageHandler::HandleAddNewTopSite(const base::ListValue* args) { +void TopSitesMessageHandler::HandleAddNewTopSite( + base::Value::ConstListView args) { if (!most_visited_sites_) return; AllowJavascript(); - std::string url; - if (!args->GetString(0, &url)) + if (!args[0].is_string() || !args[1].is_string()) return; + + std::string url = args[0].GetString(); DCHECK(!url.empty()); - std::string title; - if (!args->GetString(1, &title)) - return; + std::string title = args[1].GetString(); // Stop adding if we can't make |url| valid. if (!GetValidURLStringForTopSite(&url)) diff --git a/browser/ui/webui/new_tab_page/top_sites_message_handler.h b/browser/ui/webui/new_tab_page/top_sites_message_handler.h index 52aabb23bba0..9ac6eadf6919 100644 --- a/browser/ui/webui/new_tab_page/top_sites_message_handler.h +++ b/browser/ui/webui/new_tab_page/top_sites_message_handler.h @@ -50,14 +50,14 @@ class TopSitesMessageHandler : public content::WebUIMessageHandler, bool IsShortcutsVisible() const; // handlers - void HandleUpdateMostVisitedInfo(const base::ListValue* args); - void HandleDeleteMostVisitedTile(const base::ListValue* args); - void HandleReorderMostVisitedTile(const base::ListValue* args); - void HandleRestoreMostVisitedDefaults(const base::ListValue* args); - void HandleUndoMostVisitedTileAction(const base::ListValue* args); - void HandleSetMostVisitedSettings(const base::ListValue* args); - void HandleEditTopSite(const base::ListValue* args); - void HandleAddNewTopSite(const base::ListValue* args); + void HandleUpdateMostVisitedInfo(base::Value::ConstListView args); + void HandleDeleteMostVisitedTile(base::Value::ConstListView args); + void HandleReorderMostVisitedTile(base::Value::ConstListView args); + void HandleRestoreMostVisitedDefaults(base::Value::ConstListView args); + void HandleUndoMostVisitedTileAction(base::Value::ConstListView args); + void HandleSetMostVisitedSettings(base::Value::ConstListView args); + void HandleEditTopSite(base::Value::ConstListView args); + void HandleAddNewTopSite(base::Value::ConstListView args); Profile* profile_; std::unique_ptr most_visited_sites_; diff --git a/browser/ui/webui/settings/brave_appearance_handler.cc b/browser/ui/webui/settings/brave_appearance_handler.cc index 99f1dc04e973..2fbb1c17d7ba 100644 --- a/browser/ui/webui/settings/brave_appearance_handler.cc +++ b/browser/ui/webui/settings/brave_appearance_handler.cc @@ -21,7 +21,6 @@ #include "components/prefs/pref_service.h" #include "content/public/browser/web_ui.h" - BraveAppearanceHandler::BraveAppearanceHandler() { local_state_change_registrar_.Init(g_browser_process->local_state()); local_state_change_registrar_.Add( @@ -39,36 +38,37 @@ void BraveAppearanceHandler::RegisterMessages() { profile_state_change_registrar_.Add( kNewTabPageShowsOptions, base::BindRepeating(&BraveAppearanceHandler::OnPreferenceChanged, - base::Unretained(this))); + base::Unretained(this))); profile_state_change_registrar_.Add( prefs::kHomePageIsNewTabPage, base::BindRepeating(&BraveAppearanceHandler::OnPreferenceChanged, - base::Unretained(this))); + base::Unretained(this))); profile_state_change_registrar_.Add( prefs::kHomePage, base::BindRepeating(&BraveAppearanceHandler::OnPreferenceChanged, - base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + base::Unretained(this))); + web_ui()->RegisterMessageCallback( "setBraveThemeType", base::BindRepeating(&BraveAppearanceHandler::SetBraveThemeType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getBraveThemeType", base::BindRepeating(&BraveAppearanceHandler::GetBraveThemeType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getNewTabShowsOptionsList", base::BindRepeating(&BraveAppearanceHandler::GetNewTabShowsOptionsList, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "shouldShowNewTabDashboardSettings", base::BindRepeating( &BraveAppearanceHandler::ShouldShowNewTabDashboardSettings, base::Unretained(this))); } -void BraveAppearanceHandler::SetBraveThemeType(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); +void BraveAppearanceHandler::SetBraveThemeType( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(args[0].is_int()); AllowJavascript(); @@ -77,14 +77,14 @@ void BraveAppearanceHandler::SetBraveThemeType(const base::ListValue* args) { static_cast(int_type)); } -void BraveAppearanceHandler::GetBraveThemeType(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); - +void BraveAppearanceHandler::GetBraveThemeType( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); // GetBraveThemeType() should be used because settings option displays all // available options including default. ResolveJavascriptCallback( - args->GetList()[0], + args[0], base::Value(static_cast(dark_mode::GetBraveDarkModeType()))); } @@ -105,8 +105,7 @@ void BraveAppearanceHandler::OnBackgroundPreferenceChanged( void BraveAppearanceHandler::OnPreferenceChanged(const std::string& pref_name) { if (IsJavascriptAllowed()) { - if (pref_name == kNewTabPageShowsOptions || - pref_name == prefs::kHomePage || + if (pref_name == kNewTabPageShowsOptions || pref_name == prefs::kHomePage || pref_name == prefs::kHomePageIsNewTabPage) { FireWebUIListener( "show-new-tab-dashboard-settings-changed", @@ -117,18 +116,17 @@ void BraveAppearanceHandler::OnPreferenceChanged(const std::string& pref_name) { } void BraveAppearanceHandler::GetNewTabShowsOptionsList( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); - ResolveJavascriptCallback(args->GetList()[0], + ResolveJavascriptCallback(args[0], brave::GetNewTabShowsOptionsList(profile_)); } void BraveAppearanceHandler::ShouldShowNewTabDashboardSettings( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); ResolveJavascriptCallback( - args->GetList()[0], - base::Value(brave::ShouldNewTabShowDashboard(profile_))); + args[0], base::Value(brave::ShouldNewTabShowDashboard(profile_))); } diff --git a/browser/ui/webui/settings/brave_appearance_handler.h b/browser/ui/webui/settings/brave_appearance_handler.h index ec94d1df4b59..b1cf0847d277 100644 --- a/browser/ui/webui/settings/brave_appearance_handler.h +++ b/browser/ui/webui/settings/brave_appearance_handler.h @@ -30,10 +30,10 @@ class BraveAppearanceHandler : public settings::SettingsPageUIHandler { void OnBraveDarkModeChanged(); void OnBackgroundPreferenceChanged(const std::string& pref_name); void OnPreferenceChanged(const std::string& pref_name); - void SetBraveThemeType(const base::ListValue* args); - void GetBraveThemeType(const base::ListValue* args); - void GetNewTabShowsOptionsList(const base::ListValue* args); - void ShouldShowNewTabDashboardSettings(const base::ListValue* args); + void SetBraveThemeType(base::Value::ConstListView args); + void GetBraveThemeType(base::Value::ConstListView args); + void GetNewTabShowsOptionsList(base::Value::ConstListView args); + void ShouldShowNewTabDashboardSettings(base::Value::ConstListView args); Profile* profile_ = nullptr; PrefChangeRegistrar local_state_change_registrar_; diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.cc b/browser/ui/webui/settings/brave_default_extensions_handler.cc index e75f2bc8edab..ca4c18d0d056 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.cc +++ b/browser/ui/webui/settings/brave_default_extensions_handler.cc @@ -81,43 +81,43 @@ void BraveDefaultExtensionsHandler::RegisterMessages() { if (service) { ipfs_service_observer_.Observe(service); } - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "notifyIpfsNodeStatus", base::BindRepeating(&BraveDefaultExtensionsHandler::CheckIpfsNodeStatus, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setIPFSStorageMax", base::BindRepeating(&BraveDefaultExtensionsHandler::SetIPFSStorageMax, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "importIpnsKey", base::BindRepeating(&BraveDefaultExtensionsHandler::ImportIpnsKey, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "launchIPFSService", base::BindRepeating(&BraveDefaultExtensionsHandler::LaunchIPFSService, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "exportIPNSKey", base::BindRepeating(&BraveDefaultExtensionsHandler::ExportIPNSKey, base::Unretained(this))); #endif - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setWebTorrentEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::SetWebTorrentEnabled, base::Unretained(this))); #if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED) - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setBraveWalletEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::SetBraveWalletEnabled, base::Unretained(this))); #endif - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setHangoutsEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::SetHangoutsEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setIPFSCompanionEnabled", base::BindRepeating( &BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled, @@ -125,36 +125,36 @@ void BraveDefaultExtensionsHandler::RegisterMessages() { // TODO(petemill): If anything outside this handler is responsible for causing // restart-neccessary actions, then this should be moved to a generic handler // and the flag should be moved to somewhere more static / singleton-like. - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getRestartNeeded", base::BindRepeating(&BraveDefaultExtensionsHandler::GetRestartNeeded, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setTorEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::SetTorEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "isTorEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::IsTorEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "isTorManaged", base::BindRepeating(&BraveDefaultExtensionsHandler::IsTorManaged, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setWidevineEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::SetWidevineEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "isWidevineEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::IsWidevineEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "isDecentralizedDnsEnabled", base::BindRepeating( &BraveDefaultExtensionsHandler::IsDecentralizedDnsEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getDecentralizedDnsResolveMethodList", base::BindRepeating( &BraveDefaultExtensionsHandler::GetDecentralizedDnsResolveMethodList, @@ -192,19 +192,18 @@ bool BraveDefaultExtensionsHandler::IsRestartNeeded() { } void BraveDefaultExtensionsHandler::GetRestartNeeded( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); - ResolveJavascriptCallback(args->GetList()[0], base::Value(IsRestartNeeded())); + ResolveJavascriptCallback(args[0], base::Value(IsRestartNeeded())); } void BraveDefaultExtensionsHandler::SetWebTorrentEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool enabled; - args->GetBoolean(0, &enabled); + bool enabled = args[0].GetBool(); extensions::ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->extension_service(); @@ -226,11 +225,10 @@ void BraveDefaultExtensionsHandler::SetWebTorrentEnabled( } void BraveDefaultExtensionsHandler::SetHangoutsEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool enabled; - args->GetBoolean(0, &enabled); + bool enabled = args[0].GetBool(); extensions::ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->extension_service(); @@ -274,21 +272,22 @@ void BraveDefaultExtensionsHandler::OnRestartNeededChanged() { } } -void BraveDefaultExtensionsHandler::SetTorEnabled(const base::ListValue* args) { +void BraveDefaultExtensionsHandler::SetTorEnabled( + base::Value::ConstListView args) { #if BUILDFLAG(ENABLE_TOR) - CHECK_EQ(args->GetSize(), 1U); - bool enabled; - args->GetBoolean(0, &enabled); + CHECK_EQ(args.size(), 1U); + bool enabled = args[0].GetBool(); AllowJavascript(); TorProfileServiceFactory::SetTorDisabled(!enabled); #endif } -void BraveDefaultExtensionsHandler::IsTorEnabled(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); +void BraveDefaultExtensionsHandler::IsTorEnabled( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); ResolveJavascriptCallback( - args->GetList()[0], + args[0], #if BUILDFLAG(ENABLE_TOR) base::Value(!TorProfileServiceFactory::IsTorDisabled())); #else @@ -307,8 +306,9 @@ void BraveDefaultExtensionsHandler::OnTorEnabledChanged() { } } -void BraveDefaultExtensionsHandler::IsTorManaged(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); +void BraveDefaultExtensionsHandler::IsTorManaged( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); #if BUILDFLAG(ENABLE_TOR) const bool is_managed = g_browser_process->local_state() @@ -319,25 +319,24 @@ void BraveDefaultExtensionsHandler::IsTorManaged(const base::ListValue* args) { #endif AllowJavascript(); - ResolveJavascriptCallback(args->GetList()[0], base::Value(is_managed)); + ResolveJavascriptCallback(args[0], base::Value(is_managed)); } void BraveDefaultExtensionsHandler::SetWidevineEnabled( - const base::ListValue* args) { + base::Value::ConstListView args) { #if BUILDFLAG(ENABLE_WIDEVINE) - CHECK_EQ(args->GetSize(), 1U); - bool enabled; - args->GetBoolean(0, &enabled); + CHECK_EQ(args.size(), 1U); + bool enabled = args[0].GetBool(); enabled ? EnableWidevineCdmComponent() : DisableWidevineCdmComponent(); AllowJavascript(); #endif } void BraveDefaultExtensionsHandler::IsWidevineEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); - ResolveJavascriptCallback(args->GetList()[0], + ResolveJavascriptCallback(args[0], #if BUILDFLAG(ENABLE_WIDEVINE) base::Value(IsWidevineOptedIn())); #else @@ -357,11 +356,11 @@ void BraveDefaultExtensionsHandler::OnWidevineEnabledChanged() { } } -void BraveDefaultExtensionsHandler::ExportIPNSKey(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); +void BraveDefaultExtensionsHandler::ExportIPNSKey( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - std::string key_name; - args->GetString(0, &key_name); + std::string key_name = args[0].GetString(); DCHECK(!key_name.empty()); auto* web_contents = web_ui()->GetWebContents(); select_file_dialog_ = ui::SelectFileDialog::Create( @@ -386,11 +385,10 @@ void BraveDefaultExtensionsHandler::ExportIPNSKey(const base::ListValue* args) { } void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool enabled; - args->GetBoolean(0, &enabled); + bool enabled = args[0].GetBool(); extensions::ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->extension_service(); @@ -421,11 +419,10 @@ void BraveDefaultExtensionsHandler::SetIPFSCompanionEnabled( #if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED) void BraveDefaultExtensionsHandler::SetBraveWalletEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool enabled; - args->GetBoolean(0, &enabled); + bool enabled = args[0].GetBool(); extensions::ExtensionService* service = extensions::ExtensionSystem::Get(profile_)->extension_service(); @@ -440,11 +437,11 @@ void BraveDefaultExtensionsHandler::SetBraveWalletEnabled( #endif void BraveDefaultExtensionsHandler::IsDecentralizedDnsEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); AllowJavascript(); ResolveJavascriptCallback( - args->GetList()[0], + args[0], #if BUILDFLAG(DECENTRALIZED_DNS_ENABLED) base::Value(decentralized_dns::IsDecentralizedDnsEnabled())); #else @@ -453,24 +450,23 @@ void BraveDefaultExtensionsHandler::IsDecentralizedDnsEnabled( } void BraveDefaultExtensionsHandler::GetDecentralizedDnsResolveMethodList( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 2U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 2U); AllowJavascript(); #if BUILDFLAG(DECENTRALIZED_DNS_ENABLED) decentralized_dns::Provider provider = - static_cast(args->GetList()[1].GetInt()); - ResolveJavascriptCallback(args->GetList()[0], + static_cast(args[1].GetInt()); + ResolveJavascriptCallback(args[0], decentralized_dns::GetResolveMethodList(provider)); #else - ResolveJavascriptCallback(args->GetList()[0], - base::Value(base::Value::Type::LIST)); + ResolveJavascriptCallback(args[0], base::Value(base::Value::Type::LIST)); #endif } #if BUILDFLAG(ENABLE_IPFS) void BraveDefaultExtensionsHandler::LaunchIPFSService( - const base::ListValue* args) { + base::Value::ConstListView args) { ipfs::IpfsService* service = ipfs::IpfsServiceFactory::GetForContext(profile_); if (!service) { @@ -481,8 +477,8 @@ void BraveDefaultExtensionsHandler::LaunchIPFSService( } void BraveDefaultExtensionsHandler::SetIPFSStorageMax( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(args[0].is_int()); CHECK(profile_); int storage_max_gb = args[0].GetInt(); @@ -539,11 +535,11 @@ void BraveDefaultExtensionsHandler::FileSelectionCanceled(void* params) { dialog_key_.clear(); } -void BraveDefaultExtensionsHandler::ImportIpnsKey(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); +void BraveDefaultExtensionsHandler::ImportIpnsKey( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - std::string key_name; - args->GetString(0, &key_name); + std::string key_name = args[0].GetString(); auto* web_contents = web_ui()->GetWebContents(); select_file_dialog_ = ui::SelectFileDialog::Create( this, std::make_unique(web_contents)); @@ -565,7 +561,7 @@ void BraveDefaultExtensionsHandler::ImportIpnsKey(const base::ListValue* args) { } void BraveDefaultExtensionsHandler::CheckIpfsNodeStatus( - const base::ListValue* args) { + base::Value::ConstListView args) { NotifyNodeStatus(); } diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.h b/browser/ui/webui/settings/brave_default_extensions_handler.h index c8caa14c74e2..e64e6a028c26 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.h +++ b/browser/ui/webui/settings/brave_default_extensions_handler.h @@ -42,23 +42,23 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler void OnJavascriptAllowed() override {} void OnJavascriptDisallowed() override {} - void GetRestartNeeded(const base::ListValue* args); - void SetWebTorrentEnabled(const base::ListValue* args); - void SetHangoutsEnabled(const base::ListValue* args); - void SetIPFSCompanionEnabled(const base::ListValue* args); - void SetMediaRouterEnabled(const base::ListValue* args); + void GetRestartNeeded(base::Value::ConstListView args); + void SetWebTorrentEnabled(base::Value::ConstListView args); + void SetHangoutsEnabled(base::Value::ConstListView args); + void SetIPFSCompanionEnabled(base::Value::ConstListView args); + void SetMediaRouterEnabled(base::Value::ConstListView args); #if BUILDFLAG(ETHEREUM_REMOTE_CLIENT_ENABLED) - void SetBraveWalletEnabled(const base::ListValue* args); + void SetBraveWalletEnabled(base::Value::ConstListView args); #endif - void SetTorEnabled(const base::ListValue* args); - void IsTorEnabled(const base::ListValue* args); + void SetTorEnabled(base::Value::ConstListView args); + void IsTorEnabled(base::Value::ConstListView args); void OnTorEnabledChanged(); - void IsTorManaged(const base::ListValue* args); - void SetWidevineEnabled(const base::ListValue* args); - void IsWidevineEnabled(const base::ListValue* args); + void IsTorManaged(base::Value::ConstListView args); + void SetWidevineEnabled(base::Value::ConstListView args); + void IsWidevineEnabled(base::Value::ConstListView args); void OnWidevineEnabledChanged(); - void IsDecentralizedDnsEnabled(const base::ListValue* args); - void GetDecentralizedDnsResolveMethodList(const base::ListValue* args); + void IsDecentralizedDnsEnabled(base::Value::ConstListView args); + void GetDecentralizedDnsResolveMethodList(base::Value::ConstListView args); void InitializePrefCallbacks(); @@ -72,10 +72,10 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler bool IsRestartNeeded(); #if BUILDFLAG(ENABLE_IPFS) - void SetIPFSStorageMax(const base::ListValue* args); - void ImportIpnsKey(const base::ListValue* args); - void LaunchIPFSService(const base::ListValue* args); - void ExportIPNSKey(const base::ListValue* args); + void SetIPFSStorageMax(base::Value::ConstListView args); + void ImportIpnsKey(base::Value::ConstListView args); + void LaunchIPFSService(base::Value::ConstListView args); + void ExportIPNSKey(base::Value::ConstListView args); // ui::SelectFileDialog::Listener void FileSelected(const base::FilePath& path, @@ -91,7 +91,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler void OnIpfsLaunched(bool result, int64_t pid) override; void OnIpfsShutdown() override; void OnIpnsKeysLoaded(bool success) override; - void CheckIpfsNodeStatus(const base::ListValue* args); + void CheckIpfsNodeStatus(base::Value::ConstListView args); void NotifyNodeStatus(); std::string dialog_key_; diff --git a/browser/ui/webui/settings/brave_privacy_handler.cc b/browser/ui/webui/settings/brave_privacy_handler.cc index 93dc78d10403..bd2717f1f974 100644 --- a/browser/ui/webui/settings/brave_privacy_handler.cc +++ b/browser/ui/webui/settings/brave_privacy_handler.cc @@ -46,18 +46,18 @@ void BravePrivacyHandler::RegisterMessages() { profile_ = Profile::FromWebUI(web_ui()); #if BUILDFLAG(BRAVE_P3A_ENABLED) - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setP3AEnabled", base::BindRepeating(&BravePrivacyHandler::SetP3AEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getP3AEnabled", base::BindRepeating(&BravePrivacyHandler::GetP3AEnabled, base::Unretained(this))); #endif - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setStatsUsagePingEnabled", base::BindRepeating(&BravePrivacyHandler::SetStatsUsagePingEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getStatsUsagePingEnabled", base::BindRepeating(&BravePrivacyHandler::GetStatsUsagePingEnabled, base::Unretained(this))); @@ -80,35 +80,35 @@ void BravePrivacyHandler::AddLoadTimeData(content::WebUIDataSource* data_source, void BravePrivacyHandler::SetLocalStateBooleanEnabled( const std::string& path, - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); - - bool enabled; - args->GetBoolean(0, &enabled); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); + if (!args[0].is_bool()) + return; + bool enabled = args[0].GetBool(); PrefService* local_state = g_browser_process->local_state(); local_state->SetBoolean(path, enabled); } void BravePrivacyHandler::GetLocalStateBooleanEnabled( const std::string& path, - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); PrefService* local_state = g_browser_process->local_state(); bool enabled = local_state->GetBoolean(path); AllowJavascript(); - ResolveJavascriptCallback(args->GetList()[0].Clone(), base::Value(enabled)); + ResolveJavascriptCallback(args[0].Clone(), base::Value(enabled)); } void BravePrivacyHandler::SetStatsUsagePingEnabled( - const base::ListValue* args) { + base::Value::ConstListView args) { SetLocalStateBooleanEnabled(kStatsReportingEnabled, args); } void BravePrivacyHandler::GetStatsUsagePingEnabled( - const base::ListValue* args) { + base::Value::ConstListView args) { GetLocalStateBooleanEnabled(kStatsReportingEnabled, args); } @@ -122,11 +122,11 @@ void BravePrivacyHandler::OnStatsUsagePingEnabledChanged() { } #if BUILDFLAG(BRAVE_P3A_ENABLED) -void BravePrivacyHandler::SetP3AEnabled(const base::ListValue* args) { +void BravePrivacyHandler::SetP3AEnabled(base::Value::ConstListView args) { SetLocalStateBooleanEnabled(brave::kP3AEnabled, args); } -void BravePrivacyHandler::GetP3AEnabled(const base::ListValue* args) { +void BravePrivacyHandler::GetP3AEnabled(base::Value::ConstListView args) { GetLocalStateBooleanEnabled(brave::kP3AEnabled, args); } diff --git a/browser/ui/webui/settings/brave_privacy_handler.h b/browser/ui/webui/settings/brave_privacy_handler.h index f5d56f0dabc0..f417860a0083 100644 --- a/browser/ui/webui/settings/brave_privacy_handler.h +++ b/browser/ui/webui/settings/brave_privacy_handler.h @@ -32,17 +32,17 @@ class BravePrivacyHandler : public settings::SettingsPageUIHandler { void OnJavascriptDisallowed() override {} void SetLocalStateBooleanEnabled(const std::string& path, - const base::ListValue* args); + base::Value::ConstListView args); void GetLocalStateBooleanEnabled(const std::string& path, - const base::ListValue* args); + base::Value::ConstListView args); - void SetStatsUsagePingEnabled(const base::ListValue* args); - void GetStatsUsagePingEnabled(const base::ListValue* args); + void SetStatsUsagePingEnabled(base::Value::ConstListView args); + void GetStatsUsagePingEnabled(base::Value::ConstListView args); void OnStatsUsagePingEnabledChanged(); #if BUILDFLAG(BRAVE_P3A_ENABLED) - void SetP3AEnabled(const base::ListValue* args); - void GetP3AEnabled(const base::ListValue* args); + void SetP3AEnabled(base::Value::ConstListView args); + void GetP3AEnabled(base::Value::ConstListView args); void OnP3AEnabledChanged(); #endif diff --git a/browser/ui/webui/settings/brave_relaunch_handler_mac.h b/browser/ui/webui/settings/brave_relaunch_handler_mac.h index 594dd1f2909e..96b2738c774d 100644 --- a/browser/ui/webui/settings/brave_relaunch_handler_mac.h +++ b/browser/ui/webui/settings/brave_relaunch_handler_mac.h @@ -20,7 +20,7 @@ class BraveRelaunchHandler : public settings::SettingsPageUIHandler { void OnJavascriptAllowed() override {} void OnJavascriptDisallowed() override {} - void Relaunch(const base::ListValue* args); + void Relaunch(base::Value::ConstListView args); DISALLOW_COPY_AND_ASSIGN(BraveRelaunchHandler); }; diff --git a/browser/ui/webui/settings/brave_relaunch_handler_mac.mm b/browser/ui/webui/settings/brave_relaunch_handler_mac.mm index 1eba787760cf..ef42554bfef6 100644 --- a/browser/ui/webui/settings/brave_relaunch_handler_mac.mm +++ b/browser/ui/webui/settings/brave_relaunch_handler_mac.mm @@ -8,11 +8,11 @@ #import "brave/browser/mac/sparkle_glue.h" void BraveRelaunchHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "relaunchOnMac", base::BindRepeating(&BraveRelaunchHandler::Relaunch, base::Unretained(this))); } -void BraveRelaunchHandler::Relaunch(const base::ListValue* args) { +void BraveRelaunchHandler::Relaunch(base::Value::ConstListView args) { [[SparkleGlue sharedSparkleGlue] relaunch]; } diff --git a/browser/ui/webui/settings/brave_sync_handler.cc b/browser/ui/webui/settings/brave_sync_handler.cc index 7a1af40a27c9..98c3836f2e27 100644 --- a/browser/ui/webui/settings/brave_sync_handler.cc +++ b/browser/ui/webui/settings/brave_sync_handler.cc @@ -32,26 +32,26 @@ BraveSyncHandler::~BraveSyncHandler() {} void BraveSyncHandler::RegisterMessages() { profile_ = Profile::FromWebUI(web_ui()); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "SyncGetDeviceList", base::BindRepeating(&BraveSyncHandler::HandleGetDeviceList, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "SyncSetupSetSyncCode", base::BindRepeating(&BraveSyncHandler::HandleSetSyncCode, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "SyncSetupGetSyncCode", base::BindRepeating(&BraveSyncHandler::HandleGetSyncCode, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "SyncGetQRCode", base::BindRepeating(&BraveSyncHandler::HandleGetQRCode, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "SyncSetupReset", base::BindRepeating(&BraveSyncHandler::HandleReset, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "SyncDeleteDevice", base::BindRepeating(&BraveSyncHandler::HandleDeleteDevice, base::Unretained(this))); @@ -75,43 +75,42 @@ void BraveSyncHandler::OnDeviceInfoChange() { FireWebUIListener("device-info-changed", GetSyncDeviceList()); } -void BraveSyncHandler::HandleGetDeviceList(const base::ListValue* args) { +void BraveSyncHandler::HandleGetDeviceList(base::Value::ConstListView args) { AllowJavascript(); - const auto& list = args->GetList(); - CHECK_EQ(1U, list.size()); - const base::Value* callback_id; - CHECK(args->Get(0, &callback_id)); + CHECK_EQ(1U, args.size()); + CHECK(args[0].is_int()); + const base::Value& callback_id = args[0]; - ResolveJavascriptCallback(*callback_id, GetSyncDeviceList()); + ResolveJavascriptCallback(callback_id, GetSyncDeviceList()); } -void BraveSyncHandler::HandleGetSyncCode(const base::ListValue* args) { +void BraveSyncHandler::HandleGetSyncCode(base::Value::ConstListView args) { AllowJavascript(); - CHECK_EQ(1U, args->GetSize()); - const base::Value* callback_id; - CHECK(args->Get(0, &callback_id)); + CHECK_EQ(1U, args.size()); + CHECK(args[0].is_int()); + const base::Value& callback_id = args[0]; auto* sync_service = GetSyncService(); std::string sync_code; if (sync_service) sync_code = sync_service->GetOrCreateSyncCode(); - ResolveJavascriptCallback(*callback_id, base::Value(sync_code)); + ResolveJavascriptCallback(callback_id, base::Value(sync_code)); } -void BraveSyncHandler::HandleGetQRCode(const base::ListValue* args) { +void BraveSyncHandler::HandleGetQRCode(base::Value::ConstListView args) { AllowJavascript(); - CHECK_EQ(2U, args->GetSize()); - const base::Value* callback_id; - CHECK(args->Get(0, &callback_id)); - const base::Value* sync_code; - CHECK(args->Get(1, &sync_code)); + CHECK_EQ(2U, args.size()); + CHECK(args[0].is_int()); + CHECK(args[1].is_int()); + const base::Value& callback_id = args[0]; + const base::Value& sync_code = args[1]; std::vector seed; - if (!brave_sync::crypto::PassphraseToBytes32(sync_code->GetString(), &seed)) { + if (!brave_sync::crypto::PassphraseToBytes32(sync_code.GetString(), &seed)) { LOG(ERROR) << "invalid sync code when generating qr code"; - RejectJavascriptCallback(*callback_id, base::Value("invalid sync code")); + RejectJavascriptCallback(callback_id, base::Value("invalid sync code")); return; } @@ -119,8 +118,8 @@ void BraveSyncHandler::HandleGetQRCode(const base::ListValue* args) { // seed then we will have 64 bytes input data const std::string sync_code_hex = base::HexEncode(seed.data(), seed.size()); - base::Value callback_id_disconnect(callback_id->Clone()); - base::Value callback_id_arg(callback_id->Clone()); + base::Value callback_id_disconnect(callback_id.Clone()); + base::Value callback_id_arg(callback_id.Clone()); qr_code_service_remote_ = qrcode_generator::LaunchQRCodeGeneratorService(); qr_code_service_remote_.set_disconnect_handler( @@ -147,42 +146,42 @@ void BraveSyncHandler::HandleGetQRCode(const base::ListValue* args) { std::move(callback_id_arg))); } -void BraveSyncHandler::HandleSetSyncCode(const base::ListValue* args) { +void BraveSyncHandler::HandleSetSyncCode(base::Value::ConstListView args) { AllowJavascript(); - CHECK_EQ(2U, args->GetSize()); - const base::Value* callback_id; - CHECK(args->Get(0, &callback_id)); - const base::Value* sync_code; - CHECK(args->Get(1, &sync_code)); + CHECK_EQ(2U, args.size()); + CHECK(args[0].is_int()); + CHECK(args[1].is_int()); + const base::Value& callback_id = args[0]; + const base::Value& sync_code = args[1]; - if (sync_code->GetString().empty()) { + if (sync_code.GetString().empty()) { LOG(ERROR) << "No sync code parameter provided!"; - RejectJavascriptCallback(*callback_id, base::Value(false)); + RejectJavascriptCallback(callback_id, base::Value(false)); return; } auto* sync_service = GetSyncService(); - if (!sync_service || !sync_service->SetSyncCode(sync_code->GetString())) { - RejectJavascriptCallback(*callback_id, base::Value(false)); + if (!sync_service || !sync_service->SetSyncCode(sync_code.GetString())) { + RejectJavascriptCallback(callback_id, base::Value(false)); return; } - ResolveJavascriptCallback(*callback_id, base::Value(true)); + ResolveJavascriptCallback(callback_id, base::Value(true)); } -void BraveSyncHandler::HandleReset(const base::ListValue* args) { +void BraveSyncHandler::HandleReset(base::Value::ConstListView args) { AllowJavascript(); - CHECK_EQ(1U, args->GetSize()); - const base::Value* callback_id; - CHECK(args->Get(0, &callback_id)); + CHECK_EQ(1U, args.size()); + CHECK(args[0].is_int()); + const base::Value& callback_id = args[0]; auto* sync_service = GetSyncService(); if (!sync_service) { - ResolveJavascriptCallback(*callback_id, base::Value(true)); + ResolveJavascriptCallback(callback_id, base::Value(true)); return; } - base::Value callback_id_arg(callback_id->Clone()); + base::Value callback_id_arg(callback_id.Clone()); auto* device_info_sync_service = DeviceInfoSyncServiceFactory::GetForProfile(profile_); brave_sync::ResetSync(sync_service, device_info_sync_service, @@ -191,28 +190,28 @@ void BraveSyncHandler::HandleReset(const base::ListValue* args) { std::move(callback_id_arg))); } -void BraveSyncHandler::HandleDeleteDevice(const base::ListValue* args) { +void BraveSyncHandler::HandleDeleteDevice(base::Value::ConstListView args) { AllowJavascript(); - CHECK_EQ(2U, args->GetSize()); - const base::Value* callback_id; - CHECK(args->Get(0, &callback_id)); - const base::Value* device_id_value; - CHECK(args->Get(1, &device_id_value)); + CHECK_EQ(2U, args.size()); + CHECK(args[0].is_int()); + CHECK(args[1].is_int()); + const base::Value& callback_id = args[0]; + const base::Value& device_id_value = args[1]; - std::string device_guid = device_id_value->GetString(); + std::string device_guid = device_id_value.GetString(); if (device_guid.empty()) { LOG(ERROR) << "No device id to remove!"; - RejectJavascriptCallback(*callback_id, base::Value(false)); + RejectJavascriptCallback(callback_id, base::Value(false)); return; } auto* sync_service = GetSyncService(); if (!sync_service) { - ResolveJavascriptCallback(*callback_id, base::Value(false)); + ResolveJavascriptCallback(callback_id, base::Value(false)); return; } - base::Value callback_id_arg(callback_id->Clone()); + base::Value callback_id_arg(callback_id.Clone()); auto* device_info_sync_service = DeviceInfoSyncServiceFactory::GetForProfile(profile_); brave_sync::DeleteDevice(sync_service, device_info_sync_service, device_guid); diff --git a/browser/ui/webui/settings/brave_sync_handler.h b/browser/ui/webui/settings/brave_sync_handler.h index 3fbd450ace55..f6b4c7f85007 100644 --- a/browser/ui/webui/settings/brave_sync_handler.h +++ b/browser/ui/webui/settings/brave_sync_handler.h @@ -37,12 +37,12 @@ class BraveSyncHandler : public settings::SettingsPageUIHandler, void OnJavascriptDisallowed() override; // Custom message handlers: - void HandleGetDeviceList(const base::ListValue* args); - void HandleGetSyncCode(const base::ListValue* args); - void HandleSetSyncCode(const base::ListValue* args); - void HandleGetQRCode(const base::ListValue* args); - void HandleReset(const base::ListValue* args); - void HandleDeleteDevice(const base::ListValue* args); + void HandleGetDeviceList(base::Value::ConstListView args); + void HandleGetSyncCode(base::Value::ConstListView args); + void HandleSetSyncCode(base::Value::ConstListView args); + void HandleGetQRCode(base::Value::ConstListView args); + void HandleReset(base::Value::ConstListView args); + void HandleDeleteDevice(base::Value::ConstListView args); void OnResetDone(base::Value callback_id); diff --git a/browser/ui/webui/settings/default_brave_shields_handler.cc b/browser/ui/webui/settings/default_brave_shields_handler.cc index ecbd33f2ac18..5b038d4efbb0 100644 --- a/browser/ui/webui/settings/default_brave_shields_handler.cc +++ b/browser/ui/webui/settings/default_brave_shields_handler.cc @@ -22,193 +22,168 @@ using brave_shields::ControlTypeToString; void DefaultBraveShieldsHandler::RegisterMessages() { profile_ = Profile::FromWebUI(web_ui()); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "isAdControlEnabled", base::BindRepeating(&DefaultBraveShieldsHandler::IsAdControlEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setAdControlType", base::BindRepeating(&DefaultBraveShieldsHandler::SetAdControlType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "isFirstPartyCosmeticFilteringEnabled", base::BindRepeating( &DefaultBraveShieldsHandler::IsFirstPartyCosmeticFilteringEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setCosmeticFilteringControlType", base::BindRepeating( &DefaultBraveShieldsHandler::SetCosmeticFilteringControlType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getCookieControlType", base::BindRepeating(&DefaultBraveShieldsHandler::GetCookieControlType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setCookieControlType", base::BindRepeating(&DefaultBraveShieldsHandler::SetCookieControlType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "getFingerprintingControlType", base::BindRepeating( &DefaultBraveShieldsHandler::GetFingerprintingControlType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setFingerprintingControlType", base::BindRepeating( &DefaultBraveShieldsHandler::SetFingerprintingControlType, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setHTTPSEverywhereEnabled", base::BindRepeating( &DefaultBraveShieldsHandler::SetHTTPSEverywhereEnabled, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "setNoScriptControlType", base::BindRepeating(&DefaultBraveShieldsHandler::SetNoScriptControlType, base::Unretained(this))); } void DefaultBraveShieldsHandler::IsAdControlEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); ControlType setting = brave_shields::GetAdControlType( HostContentSettingsMapFactory::GetForProfile(profile_), GURL()); AllowJavascript(); - ResolveJavascriptCallback( - args->GetList()[0].Clone(), - base::Value(setting == ControlType::BLOCK)); + ResolveJavascriptCallback(args[0].Clone(), + base::Value(setting == ControlType::BLOCK)); } -void DefaultBraveShieldsHandler::SetAdControlType(const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); +void DefaultBraveShieldsHandler::SetAdControlType( + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool value; - args->GetBoolean(0, &value); + bool value = args[0].GetBool(); brave_shields::SetAdControlType( HostContentSettingsMapFactory::GetForProfile(profile_), - value ? ControlType::BLOCK - : ControlType::ALLOW, - GURL(), + value ? ControlType::BLOCK : ControlType::ALLOW, GURL(), g_browser_process->local_state()); } void DefaultBraveShieldsHandler::IsFirstPartyCosmeticFilteringEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); bool enabled = brave_shields::IsFirstPartyCosmeticFilteringEnabled( - HostContentSettingsMapFactory::GetForProfile(profile_), - GURL()); + HostContentSettingsMapFactory::GetForProfile(profile_), GURL()); AllowJavascript(); - ResolveJavascriptCallback( - args->GetList()[0].Clone(), - base::Value(enabled)); + ResolveJavascriptCallback(args[0].Clone(), base::Value(enabled)); } void DefaultBraveShieldsHandler::SetCosmeticFilteringControlType( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - std::string value; - args->GetString(0, &value); + std::string value = args[0].GetString(); brave_shields::SetCosmeticFilteringControlType( HostContentSettingsMapFactory::GetForProfile(profile_), - ControlTypeFromString(value), - GURL(), - g_browser_process->local_state()); + ControlTypeFromString(value), GURL(), g_browser_process->local_state()); } void DefaultBraveShieldsHandler::GetCookieControlType( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); ControlType setting = brave_shields::GetCookieControlType( - HostContentSettingsMapFactory::GetForProfile(profile_), - GURL()); + HostContentSettingsMapFactory::GetForProfile(profile_), GURL()); AllowJavascript(); - ResolveJavascriptCallback( - args->GetList()[0].Clone(), - base::Value(ControlTypeToString(setting))); + ResolveJavascriptCallback(args[0].Clone(), + base::Value(ControlTypeToString(setting))); } void DefaultBraveShieldsHandler::SetCookieControlType( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - std::string value; - args->GetString(0, &value); + std::string value = args[0].GetString(); brave_shields::SetCookieControlType( HostContentSettingsMapFactory::GetForProfile(profile_), - ControlTypeFromString(value), - GURL(), - g_browser_process->local_state()); + ControlTypeFromString(value), GURL(), g_browser_process->local_state()); } void DefaultBraveShieldsHandler::GetFingerprintingControlType( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); ControlType setting = brave_shields::GetFingerprintingControlType( - HostContentSettingsMapFactory::GetForProfile(profile_), - GURL()); + HostContentSettingsMapFactory::GetForProfile(profile_), GURL()); AllowJavascript(); - ResolveJavascriptCallback( - args->GetList()[0].Clone(), - base::Value(ControlTypeToString(setting))); + ResolveJavascriptCallback(args[0].Clone(), + base::Value(ControlTypeToString(setting))); } void DefaultBraveShieldsHandler::SetFingerprintingControlType( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - std::string value; - args->GetString(0, &value); + std::string value = args[0].GetString(); brave_shields::SetFingerprintingControlType( HostContentSettingsMapFactory::GetForProfile(profile_), - ControlTypeFromString(value), - GURL(), - g_browser_process->local_state()); + ControlTypeFromString(value), GURL(), g_browser_process->local_state()); } void DefaultBraveShieldsHandler::SetHTTPSEverywhereEnabled( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool value; - args->GetBoolean(0, &value); + bool value = args[0].GetBool(); brave_shields::SetHTTPSEverywhereEnabled( - HostContentSettingsMapFactory::GetForProfile(profile_), - value, - GURL(), + HostContentSettingsMapFactory::GetForProfile(profile_), value, GURL(), g_browser_process->local_state()); } void DefaultBraveShieldsHandler::SetNoScriptControlType( - const base::ListValue* args) { - CHECK_EQ(args->GetSize(), 1U); + base::Value::ConstListView args) { + CHECK_EQ(args.size(), 1U); CHECK(profile_); - bool value; - args->GetBoolean(0, &value); + bool value = args[0].GetBool(); brave_shields::SetNoScriptControlType( HostContentSettingsMapFactory::GetForProfile(profile_), - value ? ControlType::BLOCK - : ControlType::ALLOW, - GURL(), + value ? ControlType::BLOCK : ControlType::ALLOW, GURL(), g_browser_process->local_state()); } diff --git a/browser/ui/webui/settings/default_brave_shields_handler.h b/browser/ui/webui/settings/default_brave_shields_handler.h index 109841a146c1..5301a3240c2b 100644 --- a/browser/ui/webui/settings/default_brave_shields_handler.h +++ b/browser/ui/webui/settings/default_brave_shields_handler.h @@ -21,18 +21,18 @@ class DefaultBraveShieldsHandler : public settings::SettingsPageUIHandler { void OnJavascriptAllowed() override {} void OnJavascriptDisallowed() override {} - void SetAdControlType(const base::ListValue* args); - void IsAdControlEnabled(const base::ListValue* args); - void SetCosmeticFilteringControlType(const base::ListValue* args); - void IsFirstPartyCosmeticFilteringEnabled(const base::ListValue* args); - void SetCookieControlType(const base::ListValue* args); - void GetCookieControlType(const base::ListValue* args); - void SetFingerprintingControlType(const base::ListValue* args); - void GetFingerprintingControlType(const base::ListValue* args); - void SetHTTPSEverywhereEnabled(const base::ListValue* args); - void GetHTTPSEverywhereEnabled(const base::ListValue* args); - void SetNoScriptControlType(const base::ListValue* args); - void GetNoScriptControlType(const base::ListValue* args); + void SetAdControlType(base::Value::ConstListView args); + void IsAdControlEnabled(base::Value::ConstListView args); + void SetCosmeticFilteringControlType(base::Value::ConstListView args); + void IsFirstPartyCosmeticFilteringEnabled(base::Value::ConstListView args); + void SetCookieControlType(base::Value::ConstListView args); + void GetCookieControlType(base::Value::ConstListView args); + void SetFingerprintingControlType(base::Value::ConstListView args); + void GetFingerprintingControlType(base::Value::ConstListView args); + void SetHTTPSEverywhereEnabled(base::Value::ConstListView args); + void GetHTTPSEverywhereEnabled(base::Value::ConstListView args); + void SetNoScriptControlType(base::Value::ConstListView args); + void GetNoScriptControlType(base::Value::ConstListView args); Profile* profile_ = nullptr; diff --git a/browser/ui/webui/tor_internals_ui.cc b/browser/ui/webui/tor_internals_ui.cc index 787a3dd8890c..c7702c5b5b63 100644 --- a/browser/ui/webui/tor_internals_ui.cc +++ b/browser/ui/webui/tor_internals_ui.cc @@ -26,19 +26,19 @@ TorInternalsDOMHandler::~TorInternalsDOMHandler() { } void TorInternalsDOMHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "tor_internals.getTorGeneralInfo", base::BindRepeating(&TorInternalsDOMHandler::HandleGetTorGeneralInfo, base::Unretained(this))); - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "tor_internals.getTorLog", base::BindRepeating(&TorInternalsDOMHandler::HandleGetTorLog, base::Unretained(this))); } void TorInternalsDOMHandler::HandleGetTorGeneralInfo( - const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; @@ -53,8 +53,8 @@ void TorInternalsDOMHandler::HandleGetTorGeneralInfo( std::move(info)); } -void TorInternalsDOMHandler::HandleGetTorLog(const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 0U); +void TorInternalsDOMHandler::HandleGetTorLog(base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 0U); if (!web_ui()->CanCallJavascript()) return; tor_launcher_factory_->GetTorLog(base::BindOnce( diff --git a/browser/ui/webui/tor_internals_ui.h b/browser/ui/webui/tor_internals_ui.h index 71eca07dc0ea..d76ebb11ee37 100644 --- a/browser/ui/webui/tor_internals_ui.h +++ b/browser/ui/webui/tor_internals_ui.h @@ -26,8 +26,8 @@ class TorInternalsDOMHandler : public content::WebUIMessageHandler, void RegisterMessages() override; private: - void HandleGetTorGeneralInfo(const base::ListValue* args); - void HandleGetTorLog(const base::ListValue* args); + void HandleGetTorGeneralInfo(base::Value::ConstListView args); + void HandleGetTorLog(base::Value::ConstListView args); void OnGetTorLog(bool success, const std::string& log); diff --git a/browser/ui/webui/webcompat_reporter_ui.cc b/browser/ui/webui/webcompat_reporter_ui.cc index 303bb7ca457c..c907b07044ec 100644 --- a/browser/ui/webui/webcompat_reporter_ui.cc +++ b/browser/ui/webui/webcompat_reporter_ui.cc @@ -30,7 +30,7 @@ class WebcompatReporterDOMHandler : public content::WebUIMessageHandler { void RegisterMessages() override; private: - void HandleSubmitReport(const base::ListValue* args); + void HandleSubmitReport(base::Value::ConstListView args); std::unique_ptr uploader_; DISALLOW_COPY_AND_ASSIGN(WebcompatReporterDOMHandler); @@ -44,19 +44,19 @@ WebcompatReporterDOMHandler::WebcompatReporterDOMHandler( WebcompatReporterDOMHandler::~WebcompatReporterDOMHandler() = default; void WebcompatReporterDOMHandler::RegisterMessages() { - web_ui()->RegisterDeprecatedMessageCallback( + web_ui()->RegisterMessageCallback( "webcompat_reporter.submitReport", base::BindRepeating(&WebcompatReporterDOMHandler::HandleSubmitReport, base::Unretained(this))); } void WebcompatReporterDOMHandler::HandleSubmitReport( - const base::ListValue* args) { - DCHECK_EQ(args->GetSize(), 1U); - std::string site_url; - if (!args->GetString(0, &site_url)) + base::Value::ConstListView args) { + DCHECK_EQ(args.size(), 1U); + if (!args[0].is_string()) return; + std::string site_url = args[0].GetString(); uploader_->SubmitReport(site_url); }