From 01c1f2f5265f2a65e60323259f984f4c408c5dc8 Mon Sep 17 00:00:00 2001 From: Pete Miller Date: Tue, 20 Apr 2021 09:53:37 -0700 Subject: [PATCH 01/21] NTP: background is clickable when it is a branded wallpaper --- .../components/default/page/index.tsx | 11 +++++++++++ .../brave_new_tab_ui/containers/newTab/index.tsx | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/components/brave_new_tab_ui/components/default/page/index.tsx b/components/brave_new_tab_ui/components/default/page/index.tsx index 2c5aaf0a075c..d93656b0af6e 100644 --- a/components/brave_new_tab_ui/components/default/page/index.tsx +++ b/components/brave_new_tab_ui/components/default/page/index.tsx @@ -276,6 +276,17 @@ export const FooterContent = styled('div')` } ` +export const VisitableBackground = styled('a')` + z-index: -1; + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + display: block; + cursor: pointer; +` + function getPageBackground (p: HasImageProps) { // Page background is duplicated since a backdrop-filter's // ancestor which has blur must also have background. diff --git a/components/brave_new_tab_ui/containers/newTab/index.tsx b/components/brave_new_tab_ui/containers/newTab/index.tsx index a9ce5ad39cea..10e8c3823774 100644 --- a/components/brave_new_tab_ui/containers/newTab/index.tsx +++ b/components/brave_new_tab_ui/containers/newTab/index.tsx @@ -1140,6 +1140,13 @@ class NewTabPage extends React.Component { } + {isShowingBrandedWallpaper && newTabData.brandedWallpaperData && + newTabData.brandedWallpaperData.logo && + + } { newTabData.showToday && Date: Wed, 5 May 2021 11:15:31 -0700 Subject: [PATCH 02/21] remove CallJavascriptFunctionUnsafe from brave://adblock webui --- browser/ui/webui/brave_adblock_ui.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/browser/ui/webui/brave_adblock_ui.cc b/browser/ui/webui/brave_adblock_ui.cc index ebe11044a1c9..e0d0a29fed30 100644 --- a/browser/ui/webui/brave_adblock_ui.cc +++ b/browser/ui/webui/brave_adblock_ui.cc @@ -72,24 +72,21 @@ void AdblockDOMHandler::HandleEnableFilterList(const base::ListValue* args) { void AdblockDOMHandler::HandleGetCustomFilters(const base::ListValue* args) { DCHECK_EQ(args->GetSize(), 0U); + AllowJavascript(); const std::string custom_filters = g_brave_browser_process->ad_block_custom_filters_service() ->GetCustomFilters(); - if (!web_ui()->CanCallJavascript()) - return; - web_ui()->CallJavascriptFunctionUnsafe("brave_adblock.onGetCustomFilters", - base::Value(custom_filters)); + CallJavascriptFunction("brave_adblock.onGetCustomFilters", + base::Value(custom_filters)); } void AdblockDOMHandler::HandleGetRegionalLists(const base::ListValue* args) { DCHECK_EQ(args->GetSize(), 0U); - if (!web_ui()->CanCallJavascript()) - return; + AllowJavascript(); std::unique_ptr regional_lists = g_brave_browser_process->ad_block_regional_service_manager() ->GetRegionalLists(); - web_ui()->CallJavascriptFunctionUnsafe("brave_adblock.onGetRegionalLists", - *regional_lists); + CallJavascriptFunction("brave_adblock.onGetRegionalLists", *regional_lists); } void AdblockDOMHandler::HandleUpdateCustomFilters(const base::ListValue* args) { From 48626158d1686c4fa3ae5732ba32eda1315b47ce Mon Sep 17 00:00:00 2001 From: mkarolin Date: Fri, 7 May 2021 16:29:42 -0400 Subject: [PATCH 03/21] Fixes omnibox text selection color. Fixes brave/brave-browser#15690 Due to the cr91 upstream change below the omnibox selection color is now the same color as the focus ring of the omnibox. Since we override the focus ring to be our brand color, the selection is now also the brand color, which we don't want. This fix reverts the omnibox selection color to what it was in cr90 (kGoogleBlue200 for Light theme, kGoogleBlue800 for Dark). Chromium changes: This change redefined kColorId_TextfieldSelectionBackgroundFocused from explicit colors (gfx::kGoogleBlue200 and gfx::kGoogleBlue800 ) to fall back onto kColorId_LabelTextSelectionBackgroundFocused. https://source.chromium.org/chromium/chromium/src/+/76f9ef872febca7e3630db31c699ad2c2ec4e7a5 commit 76f9ef872febca7e3630db31c699ad2c2ec4e7a5 Author: Peter Kasting Date: Mon Feb 22 17:56:22 2021 +0000 Convert existing color definitions to more canonical forms. This defines as many colors as possible in terms of a small number of core colors. The primary benefit of this is to remove most dark mode color definitions (which will now be automatically correct). It also makes some relationships clearer. No behavior change intended (yet). Bug: none This change made kColorId_LabelTextSelectionBackgroundFocused fall back to AlphaBlend(kColorId_ProminentButtonColor, kColorId_WindowBackground, gfx::kGoogleGreyAlpha500) We redefine kColorId_ProminentButtonColor as kBraveColorBrand = RGB(0xfb, 0x54, 0x2b). https://source.chromium.org/chromium/chromium/src/+/c042fff0a7823aa4ebb0494d5b094f67f15aa4b3 commit c042fff0a7823aa4ebb0494d5b094f67f15aa4b3 Author: Peter Kasting Date: Wed Mar 24 21:10:08 2021 +0000 Tweak existing systematized colors. Primarily, this adjusts menus, tables, trees, and textfields to all use the same blue to represent a selected item (and that blue now matches the focus ring). Bug: 1061127 --- chromium_src/ui/native_theme/common_theme.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chromium_src/ui/native_theme/common_theme.cc b/chromium_src/ui/native_theme/common_theme.cc index c403402bddab..9d143fa2c45b 100644 --- a/chromium_src/ui/native_theme/common_theme.cc +++ b/chromium_src/ui/native_theme/common_theme.cc @@ -44,6 +44,8 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id, case NativeTheme::kColorId_LinkEnabled: case NativeTheme::kColorId_LinkPressed: return is_dark ? kBraveColorOrange300 : kBraveColorBrand; + case NativeTheme::kColorId_TextfieldSelectionBackgroundFocused: + return is_dark ? gfx::kGoogleBlue800 : gfx::kGoogleBlue200; default: break; } From 315277aa81ff2262bc5d9f1c0534f7e233df0787 Mon Sep 17 00:00:00 2001 From: zenparsing Date: Mon, 10 May 2021 00:27:33 -0400 Subject: [PATCH 04/21] Fix "verify wallet" button on tip dialog rewards onboarding --- .../shared/components/onboarding/rewards_tour_panels.tsx | 5 +++-- .../brave_rewards/resources/tip/components/tip_form.tsx | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/brave_rewards/resources/shared/components/onboarding/rewards_tour_panels.tsx b/components/brave_rewards/resources/shared/components/onboarding/rewards_tour_panels.tsx index a8fd0c941e61..2d45c7ebab6f 100644 --- a/components/brave_rewards/resources/shared/components/onboarding/rewards_tour_panels.tsx +++ b/components/brave_rewards/resources/shared/components/onboarding/rewards_tour_panels.tsx @@ -117,7 +117,8 @@ export function getVerifyWalletPanel ( locale: Locale, props: RewardsTourProps ): TourPanel | null { - if (!props.firstTimeSetup || props.onlyAnonWallet) { + if (!props.firstTimeSetup || props.onlyAnonWallet || + !props.onVerifyWalletClick) { return null } @@ -144,7 +145,7 @@ export function getVerifyWalletPanel ( formatMessage(getString('onboardingPanelBitflyerLearnMore'), { tags: { $1: (content) => ( - + {content} ) diff --git a/components/brave_rewards/resources/tip/components/tip_form.tsx b/components/brave_rewards/resources/tip/components/tip_form.tsx index 8140fb3d5197..1387e9a9f85c 100644 --- a/components/brave_rewards/resources/tip/components/tip_form.tsx +++ b/components/brave_rewards/resources/tip/components/tip_form.tsx @@ -126,6 +126,11 @@ export function TipForm () { const onTourDone = () => setShowTour(false) + const onVerifyClick = () => { + window.open('chrome://rewards/#verify', '_blank') + setShowTour(false) + } + return ( From 2389e59e36ab32b1830b46f5387732ad369619f9 Mon Sep 17 00:00:00 2001 From: Serg Date: Wed, 5 May 2021 14:08:29 -0400 Subject: [PATCH 05/21] Adds event emitter to window.ethereum object --- components/brave_wallet/renderer/BUILD.gn | 1 + components/brave_wallet/renderer/DEPS | 1 + .../renderer/brave_wallet_js_handler.cc | 78 ++++++++++++++++++- .../renderer/brave_wallet_js_handler.h | 6 ++ .../renderer/brave_wallet_response_helpers.cc | 30 +++++++ .../renderer/brave_wallet_response_helpers.h | 1 + components/brave_wallet/resources/BUILD.gn | 18 +++++ .../resources/brave_wallet_provider.js | 16 ++++ components/resources/BUILD.gn | 15 ++-- 9 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 components/brave_wallet/resources/BUILD.gn create mode 100644 components/brave_wallet/resources/brave_wallet_provider.js diff --git a/components/brave_wallet/renderer/BUILD.gn b/components/brave_wallet/renderer/BUILD.gn index 14709fd62dca..d82f0b7515aa 100644 --- a/components/brave_wallet/renderer/BUILD.gn +++ b/components/brave_wallet/renderer/BUILD.gn @@ -10,6 +10,7 @@ source_set("renderer") { deps = [ "//base", "//brave/components/brave_wallet/common:mojom", + "//brave/components/brave_wallet/resources:generated_resources", "//content/public/renderer", "//gin", "//mojo/public/cpp/bindings", diff --git a/components/brave_wallet/renderer/DEPS b/components/brave_wallet/renderer/DEPS index 45b1fb883757..af4ab54a334c 100644 --- a/components/brave_wallet/renderer/DEPS +++ b/components/brave_wallet/renderer/DEPS @@ -3,4 +3,5 @@ include_rules = [ "+gin", "+third_party/blink/public", "+v8/include", + "+ui/base", ] diff --git a/components/brave_wallet/renderer/brave_wallet_js_handler.cc b/components/brave_wallet/renderer/brave_wallet_js_handler.cc index 740aa0fa2f2e..ed4adc146174 100644 --- a/components/brave_wallet/renderer/brave_wallet_js_handler.cc +++ b/components/brave_wallet/renderer/brave_wallet_js_handler.cc @@ -10,9 +10,11 @@ #include "base/json/json_writer.h" #include "base/no_destructor.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "brave/components/brave_wallet/renderer/brave_wallet_response_helpers.h" #include "brave/components/brave_wallet/renderer/web3_provider_constants.h" +#include "brave/components/brave_wallet/resources/grit/brave_wallet_script_generated.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/v8_value_converter.h" #include "gin/arguments.h" @@ -21,12 +23,52 @@ #include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_script_source.h" +#include "ui/base/resource/resource_bundle.h" +namespace { + +static base::NoDestructor g_provider_script(""); + +const char kConnectEventScript[] = + R"((function() { + window.ethereum.emit('connect', '%s'); + })();)"; + +const char kDisconnectEventScript[] = + R"((function() { + window.ethereum.emit('disconnect', %s); + })();)"; + +const char kChainChangedEventScript[] = + R"((function() { + window.ethereum.emit('chainChanged', '%s'); + })();)"; + +const char kAccountsChangedEventScript[] = + R"((function() { + window.ethereum.emit('accountsChanged', %s); + })();)"; + +std::string LoadDataResource(const int id) { + auto& resource_bundle = ui::ResourceBundle::GetSharedInstance(); + if (resource_bundle.IsGzipped(id)) { + return resource_bundle.LoadDataResourceString(id); + } + + return resource_bundle.GetRawDataResource(id).as_string(); +} + +} // namespace namespace brave_wallet { BraveWalletJSHandler::BraveWalletJSHandler(content::RenderFrame* render_frame) - : render_frame_(render_frame) {} + : render_frame_(render_frame) { + if (g_provider_script->empty()) { + *g_provider_script = + LoadDataResource(IDR_BRAVE_WALLET_SCRIPT_BRAVE_WALLET_SCRIPT_BUNDLE_JS); + } +} BraveWalletJSHandler::~BraveWalletJSHandler() = default; @@ -49,6 +91,7 @@ void BraveWalletJSHandler::AddJavaScriptObjectToFrame( v8::Context::Scope context_scope(context); CreateEthereumObject(isolate, context); + InjectInitScript(); } void BraveWalletJSHandler::CreateEthereumObject( @@ -107,6 +150,9 @@ v8::Local BraveWalletJSHandler::Request( if (!out || !out->is_dict() || !out->GetAsDictionary(&out_dict)) return v8::Local(); + // Hardcode id to 1 as it is unused + ALLOW_UNUSED_LOCAL(out_dict->SetIntPath("id", 1)); + ALLOW_UNUSED_LOCAL(out_dict->SetStringPath("jsonrpc", "2.0")); std::string formed_input; if (!base::JSONWriter::Write(*out_dict, &formed_input)) return v8::Local(); @@ -165,4 +211,34 @@ void BraveWalletJSHandler::OnRequest( } } +void BraveWalletJSHandler::ExecuteScript(const std::string script) { + blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); + if (web_frame->IsProvisional()) + return; + + web_frame->ExecuteScript(blink::WebString::FromUTF8(script)); +} + +void BraveWalletJSHandler::InjectInitScript() { + ExecuteScript(*g_provider_script); +} + +void BraveWalletJSHandler::ConnectEvent(const std::string& chain_id) { + ExecuteScript(base::StringPrintf(kConnectEventScript, chain_id.c_str())); +} + +void BraveWalletJSHandler::DisconnectEvent(const std::string& message) { + ExecuteScript(base::StringPrintf(kDisconnectEventScript, + FormProviderErrorResponse(message).c_str())); +} + +void BraveWalletJSHandler::ChainChangedEvent(const std::string& chain_id) { + ExecuteScript(base::StringPrintf(kChainChangedEventScript, chain_id.c_str())); +} + +void BraveWalletJSHandler::AccountsChangedEvent(const std::string& accounts) { + ExecuteScript( + base::StringPrintf(kAccountsChangedEventScript, accounts.c_str())); +} + } // namespace brave_wallet diff --git a/components/brave_wallet/renderer/brave_wallet_js_handler.h b/components/brave_wallet/renderer/brave_wallet_js_handler.h index f6f6fc7977d5..10cbbaea8e39 100644 --- a/components/brave_wallet/renderer/brave_wallet_js_handler.h +++ b/components/brave_wallet/renderer/brave_wallet_js_handler.h @@ -22,6 +22,10 @@ class BraveWalletJSHandler { ~BraveWalletJSHandler(); void AddJavaScriptObjectToFrame(v8::Local context); + void ConnectEvent(const std::string& chain_id); + void DisconnectEvent(const std::string& message); + void ChainChangedEvent(const std::string& chain_id); + void AccountsChangedEvent(const std::string& accounts); private: void BindFunctionsToObject(v8::Isolate* isolate, @@ -37,6 +41,8 @@ class BraveWalletJSHandler { void CreateEthereumObject(v8::Isolate* isolate, v8::Local context); bool EnsureConnected(); + void InjectInitScript(); + void ExecuteScript(const std::string script); // A function to be called from JS v8::Local Request(v8::Isolate* isolate, diff --git a/components/brave_wallet/renderer/brave_wallet_response_helpers.cc b/components/brave_wallet/renderer/brave_wallet_response_helpers.cc index 16bc362ae897..efdab6700b31 100644 --- a/components/brave_wallet/renderer/brave_wallet_response_helpers.cc +++ b/components/brave_wallet/renderer/brave_wallet_response_helpers.cc @@ -8,6 +8,7 @@ #include #include "base/json/json_reader.h" +#include "base/json/json_writer.h" namespace brave_wallet { @@ -53,4 +54,33 @@ std::unique_ptr FormProviderResponse( return base::Value::ToUniquePtrValue(result->Clone()); } +std::string FormProviderErrorResponse(const std::string& controller_response) { + base::JSONReader::ValueWithError value_with_error = + base::JSONReader::ReadAndReturnValueWithError( + controller_response, base::JSONParserOptions::JSON_PARSE_RFC); + base::Optional& response = value_with_error.value; + + if (response) { + const base::Value* error = response->FindKey("error"); + if (error) { + std::string error_response; + if (!base::JSONWriter::Write(*error, &error_response)) + return ""; + + return error_response; + } + } + + ProviderErrors code = ProviderErrors::kUnsupportedMethod; + std::string message = + "Invalid response, could not parse JSON: " + controller_response; + + std::string error_response; + if (!base::JSONWriter::Write(*FormProviderResponse(code, message), + &error_response)) + return ""; + + return error_response; +} + } // namespace brave_wallet diff --git a/components/brave_wallet/renderer/brave_wallet_response_helpers.h b/components/brave_wallet/renderer/brave_wallet_response_helpers.h index 3c72b7017df8..37729d468fde 100644 --- a/components/brave_wallet/renderer/brave_wallet_response_helpers.h +++ b/components/brave_wallet/renderer/brave_wallet_response_helpers.h @@ -19,6 +19,7 @@ std::unique_ptr FormProviderResponse(ProviderErrors code, std::unique_ptr FormProviderResponse( const std::string& controller_response, bool* reject); +std::string FormProviderErrorResponse(const std::string& controller_response); } // namespace brave_wallet diff --git a/components/brave_wallet/resources/BUILD.gn b/components/brave_wallet/resources/BUILD.gn new file mode 100644 index 000000000000..aef4f506d0f3 --- /dev/null +++ b/components/brave_wallet/resources/BUILD.gn @@ -0,0 +1,18 @@ +import("//brave/components/common/typescript.gni") +import("//tools/grit/grit_rule.gni") +import("//tools/grit/repack.gni") + +transpile_web_ui("brave_wallet_script_resources") { + entry_points = [ [ + "brave_wallet_script", + rebase_path("brave_wallet_provider.js"), + ] ] + + resource_name = "brave_wallet_script" +} + +pack_web_resources("generated_resources") { + resource_name = "brave_wallet_script" + output_dir = "$root_gen_dir/brave/components/brave_wallet/resources" + deps = [ ":brave_wallet_script_resources" ] +} diff --git a/components/brave_wallet/resources/brave_wallet_provider.js b/components/brave_wallet/resources/brave_wallet_provider.js new file mode 100644 index 000000000000..601cd3075bc3 --- /dev/null +++ b/components/brave_wallet/resources/brave_wallet_provider.js @@ -0,0 +1,16 @@ +// Copyright (c) 2021 The Brave Authors. All rights reserved. +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. + +(function() { + if (!window.ethereum) { + return + } + var EventEmitter = require('events') + var BraveWeb3ProviderEventEmitter = new EventEmitter() + window.ethereum.on = BraveWeb3ProviderEventEmitter.on + window.ethereum.emit = BraveWeb3ProviderEventEmitter.emit + window.ethereum.removeListener = + BraveWeb3ProviderEventEmitter.removeListener +})() diff --git a/components/resources/BUILD.gn b/components/resources/BUILD.gn index a3a19e4ebdfc..5b71b7c6f1c8 100644 --- a/components/resources/BUILD.gn +++ b/components/resources/BUILD.gn @@ -89,11 +89,16 @@ repack("resources") { ] } - if (brave_wallet_enabled && !is_android) { - deps += [ "//brave/components/brave_wallet_ui:resources" ] - sources += [ - "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet.pak", - ] + if (brave_wallet_enabled) { + if (!is_android) { + deps += [ "//brave/components/brave_wallet_ui:resources" ] + sources += [ + "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet.pak", + ] + } + + deps += [ "//brave/components/brave_wallet/resources:generated_resources" ] + sources += [ "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet_script_generated.pak" ] } output = "$root_gen_dir/components/brave_components_resources.pak" From e572fb1320acd604fcfc9cf2e17af7ab60be2c28 Mon Sep 17 00:00:00 2001 From: Serg Date: Wed, 5 May 2021 16:31:52 -0400 Subject: [PATCH 06/21] Renames web3 provider generated resources --- components/brave_wallet/renderer/BUILD.gn | 2 +- components/brave_wallet/resources/BUILD.gn | 2 +- components/resources/BUILD.gn | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/brave_wallet/renderer/BUILD.gn b/components/brave_wallet/renderer/BUILD.gn index d82f0b7515aa..0047710f0eb1 100644 --- a/components/brave_wallet/renderer/BUILD.gn +++ b/components/brave_wallet/renderer/BUILD.gn @@ -10,7 +10,7 @@ source_set("renderer") { deps = [ "//base", "//brave/components/brave_wallet/common:mojom", - "//brave/components/brave_wallet/resources:generated_resources", + "//brave/components/brave_wallet/resources:ethereum_provider_generated_resources", "//content/public/renderer", "//gin", "//mojo/public/cpp/bindings", diff --git a/components/brave_wallet/resources/BUILD.gn b/components/brave_wallet/resources/BUILD.gn index aef4f506d0f3..c817a6cea9b7 100644 --- a/components/brave_wallet/resources/BUILD.gn +++ b/components/brave_wallet/resources/BUILD.gn @@ -11,7 +11,7 @@ transpile_web_ui("brave_wallet_script_resources") { resource_name = "brave_wallet_script" } -pack_web_resources("generated_resources") { +pack_web_resources("ethereum_provider_generated_resources") { resource_name = "brave_wallet_script" output_dir = "$root_gen_dir/brave/components/brave_wallet/resources" deps = [ ":brave_wallet_script_resources" ] diff --git a/components/resources/BUILD.gn b/components/resources/BUILD.gn index 5b71b7c6f1c8..0bc62f1ed0b4 100644 --- a/components/resources/BUILD.gn +++ b/components/resources/BUILD.gn @@ -92,12 +92,10 @@ repack("resources") { if (brave_wallet_enabled) { if (!is_android) { deps += [ "//brave/components/brave_wallet_ui:resources" ] - sources += [ - "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet.pak", - ] + sources += [ "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet.pak" ] } - deps += [ "//brave/components/brave_wallet/resources:generated_resources" ] + deps += [ "//brave/components/brave_wallet/resources:ethereum_provider_generated_resources" ] sources += [ "$root_gen_dir/brave/components/brave_wallet/resources/brave_wallet_script_generated.pak" ] } From af6e4d0d09eba1c7722558d6ad1389d5ef507110 Mon Sep 17 00:00:00 2001 From: Serg Date: Fri, 7 May 2021 14:00:53 -0400 Subject: [PATCH 07/21] Executes events emit via v8 instead of direct ExecuteScript --- components/brave_wallet/common/BUILD.gn | 11 +++ .../common/web3_provider_constants.cc | 15 ++++ .../web3_provider_constants.h | 11 ++- components/brave_wallet/renderer/BUILD.gn | 2 +- .../renderer/brave_wallet_js_handler.cc | 90 +++++++++++++------ .../renderer/brave_wallet_js_handler.h | 1 + .../renderer/brave_wallet_response_helpers.h | 2 +- 7 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 components/brave_wallet/common/web3_provider_constants.cc rename components/brave_wallet/{renderer => common}/web3_provider_constants.h (70%) diff --git a/components/brave_wallet/common/BUILD.gn b/components/brave_wallet/common/BUILD.gn index e17b1cd4b4b7..e6a6a5cc9bd0 100644 --- a/components/brave_wallet/common/BUILD.gn +++ b/components/brave_wallet/common/BUILD.gn @@ -7,6 +7,17 @@ source_set("common") { "features.cc", "features.h", ] + deps = [ + "//base", + ":common_constants", + ] +} + +source_set("common_constants") { + sources = [ + "web3_provider_constants.cc", + "web3_provider_constants.h", + ] deps = [ ":mojom" ] } diff --git a/components/brave_wallet/common/web3_provider_constants.cc b/components/brave_wallet/common/web3_provider_constants.cc new file mode 100644 index 000000000000..6fa49acc94d9 --- /dev/null +++ b/components/brave_wallet/common/web3_provider_constants.cc @@ -0,0 +1,15 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_wallet/common/web3_provider_constants.h" + +namespace brave_wallet { + +const char kConnectEvent[] = "connect"; +const char kDisconnectEvent[] = "disconnect"; +const char kChainChangedEvent[] = "chainChanged"; +const char kAccountsChangedEvent[] = "accountsChanged"; + +} // namespace brave_wallet diff --git a/components/brave_wallet/renderer/web3_provider_constants.h b/components/brave_wallet/common/web3_provider_constants.h similarity index 70% rename from components/brave_wallet/renderer/web3_provider_constants.h rename to components/brave_wallet/common/web3_provider_constants.h index 688cc6fb6768..8655925f7048 100644 --- a/components/brave_wallet/renderer/web3_provider_constants.h +++ b/components/brave_wallet/common/web3_provider_constants.h @@ -3,11 +3,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_BRAVE_WALLET_RENDERER_WEB3_PROVIDER_CONSTANTS_H_ -#define BRAVE_COMPONENTS_BRAVE_WALLET_RENDERER_WEB3_PROVIDER_CONSTANTS_H_ +#ifndef BRAVE_COMPONENTS_BRAVE_WALLET_COMMON_WEB3_PROVIDER_CONSTANTS_H_ +#define BRAVE_COMPONENTS_BRAVE_WALLET_COMMON_WEB3_PROVIDER_CONSTANTS_H_ namespace brave_wallet { +extern const char kConnectEvent[]; +extern const char kDisconnectEvent[]; +extern const char kChainChangedEvent[]; +extern const char kAccountsChangedEvent[]; + enum class ProviderErrors { kUserRejectedRequest = 4001, // User rejected the request kUnauthorized = 4100, // The requested account and/or method has not @@ -21,4 +26,4 @@ enum class ProviderErrors { } // namespace brave_wallet -#endif // BRAVE_COMPONENTS_BRAVE_WALLET_RENDERER_WEB3_PROVIDER_CONSTANTS_H_ +#endif // BRAVE_COMPONENTS_BRAVE_WALLET_COMMON_WEB3_PROVIDER_CONSTANTS_H_ diff --git a/components/brave_wallet/renderer/BUILD.gn b/components/brave_wallet/renderer/BUILD.gn index 0047710f0eb1..4d254def75f1 100644 --- a/components/brave_wallet/renderer/BUILD.gn +++ b/components/brave_wallet/renderer/BUILD.gn @@ -4,11 +4,11 @@ source_set("renderer") { "brave_wallet_js_handler.h", "brave_wallet_response_helpers.cc", "brave_wallet_response_helpers.h", - "web3_provider_constants.h", ] deps = [ "//base", + "//brave/components/brave_wallet/common:common_constants", "//brave/components/brave_wallet/common:mojom", "//brave/components/brave_wallet/resources:ethereum_provider_generated_resources", "//content/public/renderer", diff --git a/components/brave_wallet/renderer/brave_wallet_js_handler.cc b/components/brave_wallet/renderer/brave_wallet_js_handler.cc index ed4adc146174..fb3746840891 100644 --- a/components/brave_wallet/renderer/brave_wallet_js_handler.cc +++ b/components/brave_wallet/renderer/brave_wallet_js_handler.cc @@ -6,14 +6,16 @@ #include "brave/components/brave_wallet/renderer/brave_wallet_js_handler.h" #include +#include #include "base/json/json_writer.h" #include "base/no_destructor.h" +#include "base/strings/string16.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" +#include "brave/components/brave_wallet/common/web3_provider_constants.h" #include "brave/components/brave_wallet/renderer/brave_wallet_response_helpers.h" -#include "brave/components/brave_wallet/renderer/web3_provider_constants.h" #include "brave/components/brave_wallet/resources/grit/brave_wallet_script_generated.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/v8_value_converter.h" @@ -29,25 +31,9 @@ namespace { static base::NoDestructor g_provider_script(""); -const char kConnectEventScript[] = - R"((function() { - window.ethereum.emit('connect', '%s'); - })();)"; - -const char kDisconnectEventScript[] = - R"((function() { - window.ethereum.emit('disconnect', %s); - })();)"; - -const char kChainChangedEventScript[] = - R"((function() { - window.ethereum.emit('chainChanged', '%s'); - })();)"; - -const char kAccountsChangedEventScript[] = - R"((function() { - window.ethereum.emit('accountsChanged', %s); - })();)"; +// Hardcode id to 1 as it is unused +const uint32_t kRequestId = 1; +const char kRequestJsonRPC[] = "2.0"; std::string LoadDataResource(const int id) { auto& resource_bundle = ui::ResourceBundle::GetSharedInstance(); @@ -58,6 +44,45 @@ std::string LoadDataResource(const int id) { return resource_bundle.GetRawDataResource(id).as_string(); } +v8::MaybeLocal GetProperty(v8::Local context, + v8::Local object, + const base::string16& name) { + v8::Isolate* isolate = context->GetIsolate(); + v8::Local name_str = + gin::ConvertToV8(isolate, name).As(); + v8::Local object_obj; + if (!object->ToObject(context).ToLocal(&object_obj)) { + return v8::MaybeLocal(); + } + + return object_obj->Get(context, name_str); +} + +void CallMethodOfObject(blink::WebLocalFrame* web_frame, + const base::string16& object_name, + const base::string16& method_name, + base::Value arguments) { + if (web_frame->IsProvisional()) + return; + v8::Local context = web_frame->MainWorldScriptContext(); + v8::Context::Scope context_scope(context); + v8::Local object; + v8::Local method; + if (!GetProperty(context, context->Global(), object_name).ToLocal(&object) || + !GetProperty(context, object, method_name).ToLocal(&method)) { + return; + } + std::vector> args; + for (auto const& argument : arguments.GetList()) { + args.push_back(content::V8ValueConverter::Create()->ToV8Value(&argument, + context)); + } + + web_frame->ExecuteMethodAndReturnValue( + v8::Local::Cast(method), object, + static_cast(args.size()), args.data()).ToLocalChecked(); +} + } // namespace namespace brave_wallet { @@ -151,8 +176,8 @@ v8::Local BraveWalletJSHandler::Request( return v8::Local(); // Hardcode id to 1 as it is unused - ALLOW_UNUSED_LOCAL(out_dict->SetIntPath("id", 1)); - ALLOW_UNUSED_LOCAL(out_dict->SetStringPath("jsonrpc", "2.0")); + ALLOW_UNUSED_LOCAL(out_dict->SetIntPath("id", kRequestId)); + ALLOW_UNUSED_LOCAL(out_dict->SetStringPath("jsonrpc", kRequestJsonRPC)); std::string formed_input; if (!base::JSONWriter::Write(*out_dict, &formed_input)) return v8::Local(); @@ -223,22 +248,31 @@ void BraveWalletJSHandler::InjectInitScript() { ExecuteScript(*g_provider_script); } +void BraveWalletJSHandler::FireEvent(const std::string& event, + const std::string& event_args) { + base::Value args = base::Value(base::Value::Type::LIST); + args.Append(event); + args.Append(event_args); + CallMethodOfObject(render_frame_->GetWebFrame(), + STRING16_LITERAL("ethereum"), + STRING16_LITERAL("emit"), + std::move(args)); +} + void BraveWalletJSHandler::ConnectEvent(const std::string& chain_id) { - ExecuteScript(base::StringPrintf(kConnectEventScript, chain_id.c_str())); + FireEvent(kConnectEvent, chain_id); } void BraveWalletJSHandler::DisconnectEvent(const std::string& message) { - ExecuteScript(base::StringPrintf(kDisconnectEventScript, - FormProviderErrorResponse(message).c_str())); + FireEvent(kDisconnectEvent, message); } void BraveWalletJSHandler::ChainChangedEvent(const std::string& chain_id) { - ExecuteScript(base::StringPrintf(kChainChangedEventScript, chain_id.c_str())); + FireEvent(kChainChangedEvent, chain_id); } void BraveWalletJSHandler::AccountsChangedEvent(const std::string& accounts) { - ExecuteScript( - base::StringPrintf(kAccountsChangedEventScript, accounts.c_str())); + FireEvent(kAccountsChangedEvent, accounts); } } // namespace brave_wallet diff --git a/components/brave_wallet/renderer/brave_wallet_js_handler.h b/components/brave_wallet/renderer/brave_wallet_js_handler.h index 10cbbaea8e39..8e2639f84cd9 100644 --- a/components/brave_wallet/renderer/brave_wallet_js_handler.h +++ b/components/brave_wallet/renderer/brave_wallet_js_handler.h @@ -22,6 +22,7 @@ class BraveWalletJSHandler { ~BraveWalletJSHandler(); void AddJavaScriptObjectToFrame(v8::Local context); + void FireEvent(const std::string& event, const std::string& event_args); void ConnectEvent(const std::string& chain_id); void DisconnectEvent(const std::string& message); void ChainChangedEvent(const std::string& chain_id); diff --git a/components/brave_wallet/renderer/brave_wallet_response_helpers.h b/components/brave_wallet/renderer/brave_wallet_response_helpers.h index 37729d468fde..d5370274c9a6 100644 --- a/components/brave_wallet/renderer/brave_wallet_response_helpers.h +++ b/components/brave_wallet/renderer/brave_wallet_response_helpers.h @@ -10,7 +10,7 @@ #include #include "base/values.h" -#include "brave/components/brave_wallet/renderer/web3_provider_constants.h" +#include "brave/components/brave_wallet/common/web3_provider_constants.h" namespace brave_wallet { From 4911e5d74762103ae7f1a35d1250807144885063 Mon Sep 17 00:00:00 2001 From: wchen342 Date: Fri, 7 May 2021 01:12:53 +0300 Subject: [PATCH 08/21] Fix unsafe javascript calls in brave://rewards --- browser/ui/webui/brave_rewards_page_ui.cc | 346 +++++++--------------- 1 file changed, 108 insertions(+), 238 deletions(-) diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index b14659be616a..378714ac3cba 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -59,6 +59,8 @@ class RewardsDOMHandler : public WebUIMessageHandler, void Init(); // WebUIMessageHandler implementation. + void OnJavascriptAllowed() override; + void OnJavascriptDisallowed() override; void RegisterMessages() override; private: @@ -318,13 +320,7 @@ const char kAutoDetectedAdsSubdivisionTargeting[] = RewardsDOMHandler::RewardsDOMHandler() : weak_factory_(this) {} RewardsDOMHandler::~RewardsDOMHandler() { - if (rewards_service_) { - rewards_service_->RemoveObserver(this); - } - - if (ads_service_) { - ads_service_->RemoveObserver(this); - } + OnJavascriptDisallowed(); } void RewardsDOMHandler::RegisterMessages() { @@ -494,26 +490,38 @@ void RewardsDOMHandler::Init() { rewards_service_ = brave_rewards::RewardsServiceFactory::GetForProfile(profile); rewards_service_->StartProcess(base::DoNothing()); + + ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile); +} + +void RewardsDOMHandler::IsInitialized( + const base::ListValue* args) { + AllowJavascript(); + + if (rewards_service_ && rewards_service_->IsInitialized()) { + CallJavascriptFunction( + "brave_rewards.initialized", + base::Value(0)); + } +} + +void RewardsDOMHandler::OnJavascriptAllowed() { if (rewards_service_) { rewards_service_->AddObserver(this); } - ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile); if (ads_service_) { ads_service_->AddObserver(this); } } -void RewardsDOMHandler::IsInitialized( - const base::ListValue* args) { - if (!web_ui()->CanCallJavascript()) { - return; +void RewardsDOMHandler::OnJavascriptDisallowed() { + if (rewards_service_) { + rewards_service_->RemoveObserver(this); } - if (rewards_service_ && rewards_service_->IsInitialized()) { - web_ui()->CallJavascriptFunctionUnsafe( - "brave_rewards.initialized", - base::Value(0)); + if (ads_service_) { + ads_service_->RemoveObserver(this); } } @@ -528,10 +536,6 @@ void RewardsDOMHandler::GetRewardsParameters(const base::ListValue* args) { void RewardsDOMHandler::OnGetRewardsParameters( ledger::type::RewardsParametersPtr parameters) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::DictionaryValue data; if (parameters) { auto choices = std::make_unique(); @@ -543,16 +547,13 @@ void RewardsDOMHandler::OnGetRewardsParameters( data.SetDouble("autoContributeChoice", parameters->auto_contribute_choice); data.SetList("autoContributeChoices", std::move(choices)); } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.rewardsParameters", data); } void RewardsDOMHandler::OnRewardsInitialized( brave_rewards::RewardsService* rewards_service) { - if (!web_ui()->CanCallJavascript()) - return; - - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.initialized", base::Value(0)); } @@ -569,9 +570,8 @@ void RewardsDOMHandler::GetAutoContributeProperties( void RewardsDOMHandler::OnGetAutoContributeProperties( ledger::type::AutoContributePropertiesPtr properties) { - if (!web_ui()->CanCallJavascript() || !properties) { + if (!properties) return; - } base::DictionaryValue values; values.SetBoolean("enabledContribute", properties->enabled_contribute); @@ -582,7 +582,7 @@ void RewardsDOMHandler::OnGetAutoContributeProperties( properties->contribution_non_verified); values.SetBoolean("contributionVideos", properties->contribution_videos); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.autoContributeProperties", values); } @@ -591,10 +591,6 @@ void RewardsDOMHandler::OnFetchPromotions( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result, const ledger::type::PromotionList& list) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::ListValue promotions; for (const auto& item : list) { auto dict = std::make_unique(); @@ -610,7 +606,7 @@ void RewardsDOMHandler::OnFetchPromotions( dict.SetInteger("result", static_cast(result)); dict.SetKey("promotions", std::move(promotions)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.promotions", dict); + CallJavascriptFunction("brave_rewards.promotions", dict); } void RewardsDOMHandler::FetchPromotions(const base::ListValue* args) { @@ -625,10 +621,6 @@ void RewardsDOMHandler::OnClaimPromotion( const std::string& captcha_image, const std::string& hint, const std::string& captcha_id) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::DictionaryValue response; response.SetInteger("result", static_cast(result)); response.SetString("promotionId", promotion_id); @@ -636,7 +628,7 @@ void RewardsDOMHandler::OnClaimPromotion( response.SetString("captchaId", captcha_id); response.SetString("hint", hint); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.claimPromotion", response); } @@ -668,7 +660,7 @@ void RewardsDOMHandler::AttestPromotion(const base::ListValue *args) { if (!rewards_service_) { base::DictionaryValue finish; finish.SetInteger("status", 1); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.promotionFinish", finish); } @@ -688,10 +680,6 @@ void RewardsDOMHandler::OnAttestPromotion( const std::string& promotion_id, const ledger::type::Result result, ledger::type::PromotionPtr promotion) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::DictionaryValue promotion_dict; promotion_dict.SetString("promotionId", promotion_id); @@ -705,7 +693,7 @@ void RewardsDOMHandler::OnAttestPromotion( finish.SetInteger("result", static_cast(result)); finish.SetKey("promotion", std::move(promotion_dict)); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.promotionFinish", finish); } @@ -735,28 +723,23 @@ void RewardsDOMHandler::RecoverWallet(const base::ListValue *args) { void RewardsDOMHandler::OnRecoverWallet( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.recoverWalletData", base::Value(static_cast(result))); } void RewardsDOMHandler::OnGetReconcileStamp(uint64_t reconcile_stamp) { - if (web_ui()->CanCallJavascript()) { - std::string stamp = std::to_string(reconcile_stamp); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.reconcileStamp", - base::Value(stamp)); - } + std::string stamp = std::to_string(reconcile_stamp); + CallJavascriptFunction("brave_rewards.reconcileStamp", + base::Value(stamp)); } void RewardsDOMHandler::GetReconcileStamp(const base::ListValue* args) { - if (rewards_service_) + if (rewards_service_) { rewards_service_->GetReconcileStamp(base::Bind( &RewardsDOMHandler::OnGetReconcileStamp, weak_factory_.GetWeakPtr())); + } } void RewardsDOMHandler::OnAutoContributePropsReady( @@ -791,11 +774,7 @@ void RewardsDOMHandler::OnExcludedSitesChanged( brave_rewards::RewardsService* rewards_service, std::string publisher_id, bool excluded) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.excludedSiteChanged"); + CallJavascriptFunction("brave_rewards.excludedSiteChanged"); } void RewardsDOMHandler::OnNotificationAdded( @@ -809,14 +788,13 @@ void RewardsDOMHandler::OnNotificationDeleted( notification) { #if defined(OS_ANDROID) if (notification.type_ == - brave_rewards::RewardsNotificationService::REWARDS_NOTIFICATION_GRANT - && web_ui()->CanCallJavascript()) { + brave_rewards::RewardsNotificationService::REWARDS_NOTIFICATION_GRANT) { base::DictionaryValue finish; finish.SetInteger("status", false); finish.SetInteger("expiryTime", 0); finish.SetString("probi", "0"); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.grantFinish", finish); + CallJavascriptFunction("brave_rewards.grantFinish", finish); } #endif } @@ -907,10 +885,6 @@ void RewardsDOMHandler::RestorePublisher(const base::ListValue *args) { } void RewardsDOMHandler::OnPublisherList(ledger::type::PublisherInfoList list) { - if (!web_ui()->CanCallJavascript()) { - return; - } - auto publishers = std::make_unique(); for (auto const& item : list) { auto publisher = std::make_unique(); @@ -926,17 +900,13 @@ void RewardsDOMHandler::OnPublisherList(ledger::type::PublisherInfoList list) { publishers->Append(std::move(publisher)); } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.contributeList", *publishers); } void RewardsDOMHandler::OnExcludedSiteList( ledger::type::PublisherInfoList list) { - if (!web_ui()->CanCallJavascript()) { - return; - } - auto publishers = std::make_unique(); for (auto const& item : list) { auto publisher = std::make_unique(); @@ -949,23 +919,22 @@ void RewardsDOMHandler::OnExcludedSiteList( publishers->Append(std::move(publisher)); } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.excludedList", *publishers); } void RewardsDOMHandler::OnGetContributionAmount(double amount) { - if (web_ui()->CanCallJavascript()) { - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.contributionAmount", - base::Value(amount)); - } + CallJavascriptFunction("brave_rewards.contributionAmount", + base::Value(amount)); } void RewardsDOMHandler::GetAutoContributionAmount(const base::ListValue* args) { - if (rewards_service_) + if (rewards_service_) { rewards_service_->GetAutoContributionAmount( base::Bind(&RewardsDOMHandler::OnGetContributionAmount, weak_factory_.GetWeakPtr())); + } } void RewardsDOMHandler::OnReconcileComplete( @@ -975,15 +944,11 @@ void RewardsDOMHandler::OnReconcileComplete( const double amount, const ledger::type::RewardsType type, const ledger::type::ContributionProcessor processor) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::DictionaryValue complete; complete.SetKey("result", base::Value(static_cast(result))); complete.SetKey("type", base::Value(static_cast(type))); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.reconcileComplete", complete); } @@ -1007,9 +972,6 @@ void RewardsDOMHandler::GetRecurringTips( void RewardsDOMHandler::OnGetRecurringTips( ledger::type::PublisherInfoList list) { - if (!web_ui()->CanCallJavascript()) { - return; - } auto publishers = std::make_unique(); for (auto const& item : list) { @@ -1027,14 +989,11 @@ void RewardsDOMHandler::OnGetRecurringTips( publishers->Append(std::move(publisher)); } - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.recurringTips", + CallJavascriptFunction("brave_rewards.recurringTips", *publishers); } void RewardsDOMHandler::OnGetOneTimeTips(ledger::type::PublisherInfoList list) { - if (!web_ui()->CanCallJavascript()) { - return; - } auto publishers = std::make_unique(); for (auto const& item : list) { @@ -1052,7 +1011,7 @@ void RewardsDOMHandler::OnGetOneTimeTips(ledger::type::PublisherInfoList list) { publishers->Append(std::move(publisher)); } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.currentTips", *publishers); } @@ -1076,7 +1035,7 @@ void RewardsDOMHandler::GetContributionList(const base::ListValue *args) { } void RewardsDOMHandler::GetAdsData(const base::ListValue *args) { - if (!ads_service_ || !web_ui()->CanCallJavascript()) { + if (!ads_service_) { return; } @@ -1112,7 +1071,7 @@ void RewardsDOMHandler::GetAdsData(const base::ListValue *args) { #endif ads_data.SetBoolean("adsUIEnabled", ads_ui_enabled); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.adsData", ads_data); + CallJavascriptFunction("brave_rewards.adsData", ads_data); } void RewardsDOMHandler::GetAdsHistory(const base::ListValue* args) { @@ -1134,11 +1093,7 @@ void RewardsDOMHandler::GetAdsHistory(const base::ListValue* args) { } void RewardsDOMHandler::OnGetAdsHistory(const base::ListValue& ads_history) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.adsHistory", + CallJavascriptFunction("brave_rewards.adsHistory", ads_history); } @@ -1160,14 +1115,10 @@ void RewardsDOMHandler::ToggleAdThumbUp(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdThumbUp( const std::string& creative_instance_id, const int action) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("action", base::Value(action)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.onToggleAdThumbUp", + CallJavascriptFunction("brave_rewards.onToggleAdThumbUp", result); } @@ -1189,14 +1140,10 @@ void RewardsDOMHandler::ToggleAdThumbDown(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdThumbDown( const std::string& creative_instance_id, const int action) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("action", base::Value(action)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.onToggleAdThumbDown", + CallJavascriptFunction("brave_rewards.onToggleAdThumbDown", result); } @@ -1216,14 +1163,10 @@ void RewardsDOMHandler::ToggleAdOptInAction(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdOptInAction(const std::string& category, int action) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value result(base::Value::Type::DICTIONARY); result.SetKey("category", base::Value(category)); result.SetKey("action", base::Value(action)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.onToggleAdOptInAction", + CallJavascriptFunction("brave_rewards.onToggleAdOptInAction", result); } @@ -1243,14 +1186,10 @@ void RewardsDOMHandler::ToggleAdOptOutAction(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdOptOutAction(const std::string& category, int action) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value result(base::Value::Type::DICTIONARY); result.SetKey("category", base::Value(category)); result.SetKey("action", base::Value(action)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.onToggleAdOptOutAction", + CallJavascriptFunction("brave_rewards.onToggleAdOptOutAction", result); } @@ -1271,14 +1210,10 @@ void RewardsDOMHandler::ToggleSaveAd(const base::ListValue* args) { void RewardsDOMHandler::OnToggleSaveAd( const std::string& creative_instance_id, bool saved) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("saved", base::Value(saved)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.onToggleSaveAd", + CallJavascriptFunction("brave_rewards.onToggleSaveAd", result); } @@ -1298,14 +1233,10 @@ void RewardsDOMHandler::ToggleFlagAd(const base::ListValue* args) { void RewardsDOMHandler::OnToggleFlagAd( const std::string& creative_instance_id, bool flagged) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("flagged", base::Value(flagged)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.onToggleFlagAd", + CallJavascriptFunction("brave_rewards.onToggleFlagAd", result); } @@ -1335,7 +1266,7 @@ void RewardsDOMHandler::SaveAdsSetting(const base::ListValue* args) { } void RewardsDOMHandler::SetBackupCompleted(const base::ListValue *args) { - if (web_ui()->CanCallJavascript() && rewards_service_) { + if (rewards_service_) { rewards_service_->SetBackupCompleted(); } } @@ -1350,19 +1281,14 @@ void RewardsDOMHandler::GetPendingContributionsTotal( } void RewardsDOMHandler::OnGetPendingContributionsTotal(double amount) { - if (web_ui()->CanCallJavascript()) { - web_ui()->CallJavascriptFunctionUnsafe( - "brave_rewards.pendingContributionTotal", base::Value(amount)); - } + CallJavascriptFunction( + "brave_rewards.pendingContributionTotal", base::Value(amount)); } void RewardsDOMHandler::OnPendingContributionSaved( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { - if (!web_ui()->CanCallJavascript()) { - return; - } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.onPendingContributionSaved", base::Value(static_cast(result))); } @@ -1389,10 +1315,6 @@ void RewardsDOMHandler::OnGetStatement(const bool success, return; } - if (!web_ui()->CanCallJavascript()) { - return; - } - base::DictionaryValue history; history.SetDouble("adsEstimatedPendingRewards", @@ -1408,16 +1330,14 @@ void RewardsDOMHandler::OnGetStatement(const bool success, history.SetInteger("adsReceivedThisMonth", ads_received_this_month); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.statement", history); } void RewardsDOMHandler::OnStatementChanged( brave_rewards::RewardsService* rewards_service) { - if (web_ui()->CanCallJavascript()) { - web_ui()->CallJavascriptFunctionUnsafe( - "brave_rewards.statementChanged"); - } + CallJavascriptFunction( + "brave_rewards.statementChanged"); } void RewardsDOMHandler::OnAdRewardsChanged() { @@ -1428,20 +1348,14 @@ void RewardsDOMHandler::OnAdRewardsChanged() { void RewardsDOMHandler::OnRecurringTipSaved( brave_rewards::RewardsService* rewards_service, bool success) { - if (web_ui()->CanCallJavascript()) { - web_ui()->CallJavascriptFunctionUnsafe( - "brave_rewards.recurringTipSaved", base::Value(success)); - } + CallJavascriptFunction( + "brave_rewards.recurringTipSaved", base::Value(success)); } void RewardsDOMHandler::OnRecurringTipRemoved( brave_rewards::RewardsService* rewards_service, bool success) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.recurringTipRemoved", base::Value(success)); } @@ -1469,10 +1383,6 @@ void RewardsDOMHandler::GetPendingContributions( void RewardsDOMHandler::OnGetPendingContributions( ledger::type::PendingContributionInfoList list) { - if (!web_ui()->CanCallJavascript()) { - return; - } - auto contributions = std::make_unique(); for (auto const& item : list) { auto contribution = @@ -1495,7 +1405,7 @@ void RewardsDOMHandler::OnGetPendingContributions( contributions->Append(std::move(contribution)); } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.pendingContributions", *contributions); } @@ -1521,20 +1431,14 @@ void RewardsDOMHandler::RemoveAllPendingContributions( void RewardsDOMHandler::OnPendingContributionRemoved( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { - if (web_ui()->CanCallJavascript()) { - web_ui()->CallJavascriptFunctionUnsafe( - "brave_rewards.onRemovePendingContribution", - base::Value(static_cast(result))); - } + CallJavascriptFunction( + "brave_rewards.onRemovePendingContribution", + base::Value(static_cast(result))); } void RewardsDOMHandler::OnFetchBalance( const ledger::type::Result result, ledger::type::BalancePtr balance) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value balance_value(base::Value::Type::DICTIONARY); if (balance) { @@ -1554,7 +1458,7 @@ void RewardsDOMHandler::OnFetchBalance( base::DictionaryValue data; data.SetIntKey("status", static_cast(result)); data.SetKey("balance", std::move(balance_value)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.balance", data); + CallJavascriptFunction("brave_rewards.balance", data); } void RewardsDOMHandler::FetchBalance(const base::ListValue* args) { @@ -1577,29 +1481,27 @@ void RewardsDOMHandler::GetExternalWallet(const base::ListValue* args) { void RewardsDOMHandler::OnGetExternalWallet( const ledger::type::Result result, ledger::type::ExternalWalletPtr wallet) { - if (web_ui()->CanCallJavascript()) { - base::Value data(base::Value::Type::DICTIONARY); - - data.SetIntKey("result", static_cast(result)); - base::Value wallet_dict(base::Value::Type::DICTIONARY); - - if (wallet) { - wallet_dict.SetStringKey("type", wallet->type); - wallet_dict.SetStringKey("address", wallet->address); - wallet_dict.SetIntKey("status", static_cast(wallet->status)); - wallet_dict.SetStringKey("verifyUrl", wallet->verify_url); - wallet_dict.SetStringKey("addUrl", wallet->add_url); - wallet_dict.SetStringKey("withdrawUrl", wallet->withdraw_url); - wallet_dict.SetStringKey("userName", wallet->user_name); - wallet_dict.SetStringKey("accountUrl", wallet->account_url); - wallet_dict.SetStringKey("loginUrl", wallet->login_url); - } + base::Value data(base::Value::Type::DICTIONARY); - data.SetKey("wallet", std::move(wallet_dict)); + data.SetIntKey("result", static_cast(result)); + base::Value wallet_dict(base::Value::Type::DICTIONARY); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.externalWallet", - data); + if (wallet) { + wallet_dict.SetStringKey("type", wallet->type); + wallet_dict.SetStringKey("address", wallet->address); + wallet_dict.SetIntKey("status", static_cast(wallet->status)); + wallet_dict.SetStringKey("verifyUrl", wallet->verify_url); + wallet_dict.SetStringKey("addUrl", wallet->add_url); + wallet_dict.SetStringKey("withdrawUrl", wallet->withdraw_url); + wallet_dict.SetStringKey("userName", wallet->user_name); + wallet_dict.SetStringKey("accountUrl", wallet->account_url); + wallet_dict.SetStringKey("loginUrl", wallet->login_url); } + + data.SetKey("wallet", std::move(wallet_dict)); + + CallJavascriptFunction("brave_rewards.externalWallet", + data); } void RewardsDOMHandler::OnProcessRewardsPageUrl( @@ -1607,10 +1509,6 @@ void RewardsDOMHandler::OnProcessRewardsPageUrl( const std::string& wallet_type, const std::string& action, const base::flat_map& args) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::Value data(base::Value::Type::DICTIONARY); data.SetIntKey("result", static_cast(result)); data.SetStringKey("walletType", wallet_type); @@ -1622,7 +1520,7 @@ void RewardsDOMHandler::OnProcessRewardsPageUrl( } data.SetKey("args", std::move(new_args)); - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.processRewardsPageUrl", + CallJavascriptFunction("brave_rewards.processRewardsPageUrl", data); } @@ -1656,7 +1554,7 @@ void RewardsDOMHandler::OnDisconnectWallet( data.SetIntKey("result", static_cast(result)); data.SetStringKey("walletType", wallet_type); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.disconnectWallet", data); } @@ -1664,10 +1562,6 @@ void RewardsDOMHandler::OnDisconnectWallet( void RewardsDOMHandler::OnAdsEnabled( brave_rewards::RewardsService* rewards_service, bool ads_enabled) { - if (!web_ui()->CanCallJavascript()) { - return; - } - base::ListValue* emptyArgs = nullptr; GetAdsData(emptyArgs); GetAutoContributeProperties(emptyArgs); @@ -1681,26 +1575,18 @@ void RewardsDOMHandler::OnlyAnonWallet(const base::ListValue* args) { const bool allow = rewards_service_->OnlyAnonWallet(); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.onlyAnonWallet", base::Value(allow)); } void RewardsDOMHandler::OnUnblindedTokensReady( brave_rewards::RewardsService* rewards_service) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.unblindedTokensReady"); + CallJavascriptFunction("brave_rewards.unblindedTokensReady"); } void RewardsDOMHandler::ReconcileStampReset() { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe("brave_rewards.reconcileStampReset"); + CallJavascriptFunction("brave_rewards.reconcileStampReset"); } void RewardsDOMHandler::OnGetBalanceReport( @@ -1708,7 +1594,7 @@ void RewardsDOMHandler::OnGetBalanceReport( const uint32_t year, const ledger::type::Result result, ledger::type::BalanceReportInfoPtr report) { - if (!web_ui()->CanCallJavascript() || !report) { + if (!report) { return; } @@ -1724,7 +1610,7 @@ void RewardsDOMHandler::OnGetBalanceReport( data.SetIntKey("year", year); data.SetKey("report", std::move(report_base)); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.balanceReport", data); } @@ -1750,7 +1636,7 @@ void RewardsDOMHandler::OnGetMonthlyReport( const uint32_t month, const uint32_t year, ledger::type::MonthlyReportInfoPtr report) { - if (!web_ui()->CanCallJavascript() || !report) { + if (!report) { return; } @@ -1813,7 +1699,7 @@ void RewardsDOMHandler::OnGetMonthlyReport( data.SetKey("report", std::move(report_base)); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.monthlyReport", data); } @@ -1843,7 +1729,7 @@ void RewardsDOMHandler::OnGetAllMonthlyReportIds( list.Append(base::Value(item)); } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.monthlyReportIds", list); } @@ -1859,15 +1745,11 @@ void RewardsDOMHandler::GetAllMonthlyReportIds(const base::ListValue* args) { } void RewardsDOMHandler::GetCountryCode(const base::ListValue* args) { - if (!web_ui()->CanCallJavascript()) { - return; - } - const std::string locale = brave_l10n::LocaleHelper::GetInstance()->GetLocale(); const std::string country_code = brave_l10n::GetCountryCode(locale); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.countryCode", base::Value(country_code)); } @@ -1880,11 +1762,7 @@ void RewardsDOMHandler::CompleteReset(const base::ListValue* args) { } void RewardsDOMHandler::OnCompleteReset(const bool success) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.completeReset", base::Value(success)); } @@ -1908,16 +1786,12 @@ void RewardsDOMHandler::OnWalletCreatedForPaymentId( } void RewardsDOMHandler::OnGetPaymentId(ledger::type::BraveWalletPtr wallet) { - if (!web_ui()->CanCallJavascript()) { - return; - } - std::string payment_id; if (wallet) { payment_id = wallet->payment_id; } - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.paymentId", base::Value(payment_id)); } @@ -1933,22 +1807,18 @@ void RewardsDOMHandler::GetWalletPassphrase(const base::ListValue* args) { } void RewardsDOMHandler::OnGetWalletPassphrase(const std::string& passphrase) { - if (!web_ui()->CanCallJavascript()) { - return; - } - - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.walletPassphrase", base::Value(passphrase)); } void RewardsDOMHandler::GetOnboardingStatus(const base::ListValue* args) { - if (!rewards_service_ || !web_ui()->CanCallJavascript()) { + if (!rewards_service_) { return; } base::Value data(base::Value::Type::DICTIONARY); data.SetBoolKey("showOnboarding", rewards_service_->ShouldShowOnboarding()); - web_ui()->CallJavascriptFunctionUnsafe( + CallJavascriptFunction( "brave_rewards.onboardingStatus", data); } From 5d9ebaceb1f33f509d86ea687463db80d93a1b8b Mon Sep 17 00:00:00 2001 From: wchen342 Date: Fri, 7 May 2021 18:12:53 +0300 Subject: [PATCH 09/21] Add back IsJavascriptAllowed checks --- browser/ui/webui/brave_rewards_page_ui.cc | 221 ++++++++++++++++++---- 1 file changed, 179 insertions(+), 42 deletions(-) diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index 378714ac3cba..8ab7e94e6782 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -319,9 +319,7 @@ const char kAutoDetectedAdsSubdivisionTargeting[] = RewardsDOMHandler::RewardsDOMHandler() : weak_factory_(this) {} -RewardsDOMHandler::~RewardsDOMHandler() { - OnJavascriptDisallowed(); -} +RewardsDOMHandler::~RewardsDOMHandler() {} void RewardsDOMHandler::RegisterMessages() { #if defined(OS_ANDROID) @@ -536,6 +534,10 @@ void RewardsDOMHandler::GetRewardsParameters(const base::ListValue* args) { void RewardsDOMHandler::OnGetRewardsParameters( ledger::type::RewardsParametersPtr parameters) { + if (!IsJavascriptAllowed()) { + return; + } + base::DictionaryValue data; if (parameters) { auto choices = std::make_unique(); @@ -553,6 +555,9 @@ void RewardsDOMHandler::OnGetRewardsParameters( void RewardsDOMHandler::OnRewardsInitialized( brave_rewards::RewardsService* rewards_service) { + if (!IsJavascriptAllowed()) + return; + CallJavascriptFunction( "brave_rewards.initialized", base::Value(0)); @@ -570,7 +575,7 @@ void RewardsDOMHandler::GetAutoContributeProperties( void RewardsDOMHandler::OnGetAutoContributeProperties( ledger::type::AutoContributePropertiesPtr properties) { - if (!properties) + if (!IsJavascriptAllowed() || !properties) return; base::DictionaryValue values; @@ -591,6 +596,10 @@ void RewardsDOMHandler::OnFetchPromotions( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result, const ledger::type::PromotionList& list) { + if (!IsJavascriptAllowed()) { + return; + } + base::ListValue promotions; for (const auto& item : list) { auto dict = std::make_unique(); @@ -621,6 +630,10 @@ void RewardsDOMHandler::OnClaimPromotion( const std::string& captcha_image, const std::string& hint, const std::string& captcha_id) { + if (!IsJavascriptAllowed()) { + return; + } + base::DictionaryValue response; response.SetInteger("result", static_cast(result)); response.SetString("promotionId", promotion_id); @@ -680,6 +693,10 @@ void RewardsDOMHandler::OnAttestPromotion( const std::string& promotion_id, const ledger::type::Result result, ledger::type::PromotionPtr promotion) { + if (!IsJavascriptAllowed()) { + return; + } + base::DictionaryValue promotion_dict; promotion_dict.SetString("promotionId", promotion_id); @@ -723,15 +740,21 @@ void RewardsDOMHandler::RecoverWallet(const base::ListValue *args) { void RewardsDOMHandler::OnRecoverWallet( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction( "brave_rewards.recoverWalletData", base::Value(static_cast(result))); } void RewardsDOMHandler::OnGetReconcileStamp(uint64_t reconcile_stamp) { - std::string stamp = std::to_string(reconcile_stamp); - CallJavascriptFunction("brave_rewards.reconcileStamp", - base::Value(stamp)); + if (IsJavascriptAllowed()) { + std::string stamp = std::to_string(reconcile_stamp); + CallJavascriptFunction("brave_rewards.reconcileStamp", + base::Value(stamp)); + } } void RewardsDOMHandler::GetReconcileStamp(const base::ListValue* args) { @@ -774,6 +797,10 @@ void RewardsDOMHandler::OnExcludedSitesChanged( brave_rewards::RewardsService* rewards_service, std::string publisher_id, bool excluded) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction("brave_rewards.excludedSiteChanged"); } @@ -788,7 +815,8 @@ void RewardsDOMHandler::OnNotificationDeleted( notification) { #if defined(OS_ANDROID) if (notification.type_ == - brave_rewards::RewardsNotificationService::REWARDS_NOTIFICATION_GRANT) { + brave_rewards::RewardsNotificationService::REWARDS_NOTIFICATION_GRANT + && IsJavascriptAllowed()) { base::DictionaryValue finish; finish.SetInteger("status", false); finish.SetInteger("expiryTime", 0); @@ -885,6 +913,10 @@ void RewardsDOMHandler::RestorePublisher(const base::ListValue *args) { } void RewardsDOMHandler::OnPublisherList(ledger::type::PublisherInfoList list) { + if (!IsJavascriptAllowed()) { + return; + } + auto publishers = std::make_unique(); for (auto const& item : list) { auto publisher = std::make_unique(); @@ -907,6 +939,10 @@ void RewardsDOMHandler::OnPublisherList(ledger::type::PublisherInfoList list) { void RewardsDOMHandler::OnExcludedSiteList( ledger::type::PublisherInfoList list) { + if (!IsJavascriptAllowed()) { + return; + } + auto publishers = std::make_unique(); for (auto const& item : list) { auto publisher = std::make_unique(); @@ -925,8 +961,10 @@ void RewardsDOMHandler::OnExcludedSiteList( } void RewardsDOMHandler::OnGetContributionAmount(double amount) { - CallJavascriptFunction("brave_rewards.contributionAmount", - base::Value(amount)); + if (IsJavascriptAllowed()) { + CallJavascriptFunction("brave_rewards.contributionAmount", + base::Value(amount)); + } } void RewardsDOMHandler::GetAutoContributionAmount(const base::ListValue* args) { @@ -944,6 +982,10 @@ void RewardsDOMHandler::OnReconcileComplete( const double amount, const ledger::type::RewardsType type, const ledger::type::ContributionProcessor processor) { + if (!IsJavascriptAllowed()) { + return; + } + base::DictionaryValue complete; complete.SetKey("result", base::Value(static_cast(result))); complete.SetKey("type", base::Value(static_cast(type))); @@ -972,6 +1014,9 @@ void RewardsDOMHandler::GetRecurringTips( void RewardsDOMHandler::OnGetRecurringTips( ledger::type::PublisherInfoList list) { + if (!IsJavascriptAllowed()) { + return; + } auto publishers = std::make_unique(); for (auto const& item : list) { @@ -994,6 +1039,9 @@ void RewardsDOMHandler::OnGetRecurringTips( } void RewardsDOMHandler::OnGetOneTimeTips(ledger::type::PublisherInfoList list) { + if (!IsJavascriptAllowed()) { + return; + } auto publishers = std::make_unique(); for (auto const& item : list) { @@ -1035,7 +1083,7 @@ void RewardsDOMHandler::GetContributionList(const base::ListValue *args) { } void RewardsDOMHandler::GetAdsData(const base::ListValue *args) { - if (!ads_service_) { + if (!ads_service_ || !IsJavascriptAllowed()) { return; } @@ -1093,6 +1141,10 @@ void RewardsDOMHandler::GetAdsHistory(const base::ListValue* args) { } void RewardsDOMHandler::OnGetAdsHistory(const base::ListValue& ads_history) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction("brave_rewards.adsHistory", ads_history); } @@ -1115,6 +1167,10 @@ void RewardsDOMHandler::ToggleAdThumbUp(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdThumbUp( const std::string& creative_instance_id, const int action) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("action", base::Value(action)); @@ -1140,6 +1196,10 @@ void RewardsDOMHandler::ToggleAdThumbDown(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdThumbDown( const std::string& creative_instance_id, const int action) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("action", base::Value(action)); @@ -1163,6 +1223,10 @@ void RewardsDOMHandler::ToggleAdOptInAction(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdOptInAction(const std::string& category, int action) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value result(base::Value::Type::DICTIONARY); result.SetKey("category", base::Value(category)); result.SetKey("action", base::Value(action)); @@ -1186,6 +1250,10 @@ void RewardsDOMHandler::ToggleAdOptOutAction(const base::ListValue* args) { void RewardsDOMHandler::OnToggleAdOptOutAction(const std::string& category, int action) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value result(base::Value::Type::DICTIONARY); result.SetKey("category", base::Value(category)); result.SetKey("action", base::Value(action)); @@ -1210,6 +1278,10 @@ void RewardsDOMHandler::ToggleSaveAd(const base::ListValue* args) { void RewardsDOMHandler::OnToggleSaveAd( const std::string& creative_instance_id, bool saved) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("saved", base::Value(saved)); @@ -1233,6 +1305,10 @@ void RewardsDOMHandler::ToggleFlagAd(const base::ListValue* args) { void RewardsDOMHandler::OnToggleFlagAd( const std::string& creative_instance_id, bool flagged) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("flagged", base::Value(flagged)); @@ -1266,7 +1342,7 @@ void RewardsDOMHandler::SaveAdsSetting(const base::ListValue* args) { } void RewardsDOMHandler::SetBackupCompleted(const base::ListValue *args) { - if (rewards_service_) { + if (IsJavascriptAllowed() && rewards_service_) { rewards_service_->SetBackupCompleted(); } } @@ -1281,13 +1357,18 @@ void RewardsDOMHandler::GetPendingContributionsTotal( } void RewardsDOMHandler::OnGetPendingContributionsTotal(double amount) { - CallJavascriptFunction( - "brave_rewards.pendingContributionTotal", base::Value(amount)); + if (IsJavascriptAllowed()) { + CallJavascriptFunction( + "brave_rewards.pendingContributionTotal", base::Value(amount)); + } } void RewardsDOMHandler::OnPendingContributionSaved( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { + if (!IsJavascriptAllowed()) { + return; + } CallJavascriptFunction( "brave_rewards.onPendingContributionSaved", base::Value(static_cast(result))); @@ -1315,6 +1396,10 @@ void RewardsDOMHandler::OnGetStatement(const bool success, return; } + if (!IsJavascriptAllowed()) { + return; + } + base::DictionaryValue history; history.SetDouble("adsEstimatedPendingRewards", @@ -1336,8 +1421,10 @@ void RewardsDOMHandler::OnGetStatement(const bool success, void RewardsDOMHandler::OnStatementChanged( brave_rewards::RewardsService* rewards_service) { - CallJavascriptFunction( - "brave_rewards.statementChanged"); + if (IsJavascriptAllowed()) { + CallJavascriptFunction( + "brave_rewards.statementChanged"); + } } void RewardsDOMHandler::OnAdRewardsChanged() { @@ -1348,13 +1435,19 @@ void RewardsDOMHandler::OnAdRewardsChanged() { void RewardsDOMHandler::OnRecurringTipSaved( brave_rewards::RewardsService* rewards_service, bool success) { - CallJavascriptFunction( - "brave_rewards.recurringTipSaved", base::Value(success)); + if (IsJavascriptAllowed()) { + CallJavascriptFunction( + "brave_rewards.recurringTipSaved", base::Value(success)); + } } void RewardsDOMHandler::OnRecurringTipRemoved( brave_rewards::RewardsService* rewards_service, bool success) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction( "brave_rewards.recurringTipRemoved", base::Value(success)); } @@ -1383,6 +1476,10 @@ void RewardsDOMHandler::GetPendingContributions( void RewardsDOMHandler::OnGetPendingContributions( ledger::type::PendingContributionInfoList list) { + if (!IsJavascriptAllowed()) { + return; + } + auto contributions = std::make_unique(); for (auto const& item : list) { auto contribution = @@ -1431,14 +1528,20 @@ void RewardsDOMHandler::RemoveAllPendingContributions( void RewardsDOMHandler::OnPendingContributionRemoved( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { - CallJavascriptFunction( - "brave_rewards.onRemovePendingContribution", - base::Value(static_cast(result))); + if (IsJavascriptAllowed()) { + CallJavascriptFunction( + "brave_rewards.onRemovePendingContribution", + base::Value(static_cast(result))); + } } void RewardsDOMHandler::OnFetchBalance( const ledger::type::Result result, ledger::type::BalancePtr balance) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value balance_value(base::Value::Type::DICTIONARY); if (balance) { @@ -1481,27 +1584,29 @@ void RewardsDOMHandler::GetExternalWallet(const base::ListValue* args) { void RewardsDOMHandler::OnGetExternalWallet( const ledger::type::Result result, ledger::type::ExternalWalletPtr wallet) { - base::Value data(base::Value::Type::DICTIONARY); + if (IsJavascriptAllowed()) { + base::Value data(base::Value::Type::DICTIONARY); + + data.SetIntKey("result", static_cast(result)); + base::Value wallet_dict(base::Value::Type::DICTIONARY); + + if (wallet) { + wallet_dict.SetStringKey("type", wallet->type); + wallet_dict.SetStringKey("address", wallet->address); + wallet_dict.SetIntKey("status", static_cast(wallet->status)); + wallet_dict.SetStringKey("verifyUrl", wallet->verify_url); + wallet_dict.SetStringKey("addUrl", wallet->add_url); + wallet_dict.SetStringKey("withdrawUrl", wallet->withdraw_url); + wallet_dict.SetStringKey("userName", wallet->user_name); + wallet_dict.SetStringKey("accountUrl", wallet->account_url); + wallet_dict.SetStringKey("loginUrl", wallet->login_url); + } - data.SetIntKey("result", static_cast(result)); - base::Value wallet_dict(base::Value::Type::DICTIONARY); + data.SetKey("wallet", std::move(wallet_dict)); - if (wallet) { - wallet_dict.SetStringKey("type", wallet->type); - wallet_dict.SetStringKey("address", wallet->address); - wallet_dict.SetIntKey("status", static_cast(wallet->status)); - wallet_dict.SetStringKey("verifyUrl", wallet->verify_url); - wallet_dict.SetStringKey("addUrl", wallet->add_url); - wallet_dict.SetStringKey("withdrawUrl", wallet->withdraw_url); - wallet_dict.SetStringKey("userName", wallet->user_name); - wallet_dict.SetStringKey("accountUrl", wallet->account_url); - wallet_dict.SetStringKey("loginUrl", wallet->login_url); + CallJavascriptFunction("brave_rewards.externalWallet", + data); } - - data.SetKey("wallet", std::move(wallet_dict)); - - CallJavascriptFunction("brave_rewards.externalWallet", - data); } void RewardsDOMHandler::OnProcessRewardsPageUrl( @@ -1509,6 +1614,10 @@ void RewardsDOMHandler::OnProcessRewardsPageUrl( const std::string& wallet_type, const std::string& action, const base::flat_map& args) { + if (!IsJavascriptAllowed()) { + return; + } + base::Value data(base::Value::Type::DICTIONARY); data.SetIntKey("result", static_cast(result)); data.SetStringKey("walletType", wallet_type); @@ -1562,6 +1671,10 @@ void RewardsDOMHandler::OnDisconnectWallet( void RewardsDOMHandler::OnAdsEnabled( brave_rewards::RewardsService* rewards_service, bool ads_enabled) { + if (!IsJavascriptAllowed()) { + return; + } + base::ListValue* emptyArgs = nullptr; GetAdsData(emptyArgs); GetAutoContributeProperties(emptyArgs); @@ -1582,10 +1695,18 @@ void RewardsDOMHandler::OnlyAnonWallet(const base::ListValue* args) { void RewardsDOMHandler::OnUnblindedTokensReady( brave_rewards::RewardsService* rewards_service) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction("brave_rewards.unblindedTokensReady"); } void RewardsDOMHandler::ReconcileStampReset() { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction("brave_rewards.reconcileStampReset"); } @@ -1594,7 +1715,7 @@ void RewardsDOMHandler::OnGetBalanceReport( const uint32_t year, const ledger::type::Result result, ledger::type::BalanceReportInfoPtr report) { - if (!report) { + if (!IsJavascriptAllowed() || !report) { return; } @@ -1636,7 +1757,7 @@ void RewardsDOMHandler::OnGetMonthlyReport( const uint32_t month, const uint32_t year, ledger::type::MonthlyReportInfoPtr report) { - if (!report) { + if (!IsJavascriptAllowed() || !report) { return; } @@ -1745,6 +1866,10 @@ void RewardsDOMHandler::GetAllMonthlyReportIds(const base::ListValue* args) { } void RewardsDOMHandler::GetCountryCode(const base::ListValue* args) { + if (!IsJavascriptAllowed()) { + return; + } + const std::string locale = brave_l10n::LocaleHelper::GetInstance()->GetLocale(); const std::string country_code = brave_l10n::GetCountryCode(locale); @@ -1762,6 +1887,10 @@ void RewardsDOMHandler::CompleteReset(const base::ListValue* args) { } void RewardsDOMHandler::OnCompleteReset(const bool success) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction( "brave_rewards.completeReset", base::Value(success)); } @@ -1786,6 +1915,10 @@ void RewardsDOMHandler::OnWalletCreatedForPaymentId( } void RewardsDOMHandler::OnGetPaymentId(ledger::type::BraveWalletPtr wallet) { + if (!IsJavascriptAllowed()) { + return; + } + std::string payment_id; if (wallet) { payment_id = wallet->payment_id; @@ -1807,13 +1940,17 @@ void RewardsDOMHandler::GetWalletPassphrase(const base::ListValue* args) { } void RewardsDOMHandler::OnGetWalletPassphrase(const std::string& passphrase) { + if (!IsJavascriptAllowed()) { + return; + } + CallJavascriptFunction( "brave_rewards.walletPassphrase", base::Value(passphrase)); } void RewardsDOMHandler::GetOnboardingStatus(const base::ListValue* args) { - if (!rewards_service_) { + if (!rewards_service_ || !IsJavascriptAllowed()) { return; } base::Value data(base::Value::Type::DICTIONARY); From 60ec2daac8a08349e84b04c112eb1f9351f9fe12 Mon Sep 17 00:00:00 2001 From: wchen342 Date: Mon, 10 May 2021 20:28:36 +0300 Subject: [PATCH 10/21] Invalidate weak_factory_ in OnJavascriptDisallowed() --- browser/ui/webui/brave_rewards_page_ui.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index 8ab7e94e6782..fd91c1d5f656 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -521,6 +521,8 @@ void RewardsDOMHandler::OnJavascriptDisallowed() { if (ads_service_) { ads_service_->RemoveObserver(this); } + + weak_factory_.InvalidateWeakPtrs(); } void RewardsDOMHandler::GetRewardsParameters(const base::ListValue* args) { From d53e692415535175275514d08fe1fc80193d42bb Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Wed, 5 May 2021 10:04:42 -0500 Subject: [PATCH 11/21] Implement custom ad notification field trials --- .../dialogs/BraveAdsNotificationDialog.java | 3 +- browser/ui/brave_ads/BUILD.gn | 1 + .../brave_ads/ad_notification_header_view.cc | 6 +- browser/ui/brave_ads/ad_notification_popup.cc | 74 +++++---- browser/ui/brave_ads/ad_notification_popup.h | 6 +- browser/ui/brave_ads/padded_image_button.cc | 10 +- browser/ui/brave_ads/padded_image_view.cc | 4 +- .../ui/brave_ads/text_ad_notification_view.cc | 17 +- common/brave_channel_info.cc | 9 -- common/brave_channel_info.h | 3 - components/brave_ads/browser/BUILD.gn | 2 + .../brave_ads/browser/ads_service_impl.cc | 27 ++-- components/brave_ads/browser/features.cc | 148 ++++++++++++++++++ components/brave_ads/browser/features.h | 40 +++++ .../browser/notification_helper_android.cc | 11 +- .../browser/notification_helper_linux.cc | 5 +- .../browser/notification_helper_mac.mm | 6 +- .../browser/notification_helper_win.cc | 6 +- .../ads/ad_notifications/ad_notifications.cc | 9 -- 19 files changed, 295 insertions(+), 92 deletions(-) create mode 100644 components/brave_ads/browser/features.cc create mode 100644 components/brave_ads/browser/features.h diff --git a/browser/brave_ads/android/java/org/chromium/chrome/browser/dialogs/BraveAdsNotificationDialog.java b/browser/brave_ads/android/java/org/chromium/chrome/browser/dialogs/BraveAdsNotificationDialog.java index b4266bd7dea7..5456841cb5b1 100644 --- a/browser/brave_ads/android/java/org/chromium/chrome/browser/dialogs/BraveAdsNotificationDialog.java +++ b/browser/brave_ads/android/java/org/chromium/chrome/browser/dialogs/BraveAdsNotificationDialog.java @@ -44,6 +44,8 @@ public static void showAdNotification(Context context, final String notification } AlertDialog.Builder b = new AlertDialog.Builder(context); + mNotificationId = notificationId; + LayoutInflater inflater = LayoutInflater.from(context); b.setView(inflater.inflate(R.layout.brave_ads_custom_notification, null)); mAdsDialog = b.create(); @@ -75,7 +77,6 @@ public static void showAdNotification(Context context, final String notification ((TextView) mAdsDialog.findViewById(R.id.brave_ads_custom_notification_header)).setText(title); ((TextView) mAdsDialog.findViewById(R.id.brave_ads_custom_notification_body)).setText(body); - mNotificationId = notificationId; closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/browser/ui/brave_ads/BUILD.gn b/browser/ui/brave_ads/BUILD.gn index ff803086d824..5a683f1d789a 100644 --- a/browser/ui/brave_ads/BUILD.gn +++ b/browser/ui/brave_ads/BUILD.gn @@ -21,6 +21,7 @@ source_set("brave_ads") { "//brave/app:brave_generated_resources_grit", "//brave/app/vector_icons", "//brave/browser/profiles:util", + "//brave/components/brave_ads/browser", "//brave/components/brave_ads/common", "//components/prefs", "//skia", diff --git a/browser/ui/brave_ads/ad_notification_header_view.cc b/browser/ui/brave_ads/ad_notification_header_view.cc index a8b111052209..d9667f3042b5 100644 --- a/browser/ui/brave_ads/ad_notification_header_view.cc +++ b/browser/ui/brave_ads/ad_notification_header_view.cc @@ -54,9 +54,9 @@ constexpr SkColor kDarkModeTitleColor = SkColorSetRGB(0xe3, 0xe6, 0xec); const gfx::HorizontalAlignment kTitleHorizontalAlignment = gfx::ALIGN_LEFT; const gfx::VerticalAlignment kTitleVerticalAlignment = gfx::ALIGN_BOTTOM; -constexpr gfx::Insets kTitleBorderInsets(/* top */ 10, - /* left */ 6, - /* bottom */ 6, +constexpr gfx::Insets kTitleBorderInsets(/* top */ 11, + /* left */ 10, + /* bottom */ 3, /* right */ 0); } // namespace diff --git a/browser/ui/brave_ads/ad_notification_popup.cc b/browser/ui/brave_ads/ad_notification_popup.cc index bdb407554796..0f2e28beeb38 100644 --- a/browser/ui/brave_ads/ad_notification_popup.cc +++ b/browser/ui/brave_ads/ad_notification_popup.cc @@ -13,6 +13,7 @@ #include "brave/browser/ui/brave_ads/ad_notification_view.h" #include "brave/browser/ui/brave_ads/ad_notification_view_factory.h" #include "brave/browser/ui/brave_ads/bounds_util.h" +#include "brave/components/brave_ads/browser/features.h" #include "brave/components/brave_ads/common/pref_names.h" #include "brave/grit/brave_generated_resources.h" #include "build/build_config.h" @@ -29,6 +30,7 @@ #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" +#include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/shadow_util.h" #include "ui/gfx/shadow_value.h" #include "ui/gfx/skia_paint_util.h" @@ -49,9 +51,6 @@ namespace { // AdNotificationPopup management to NotificationPopupCollection std::map g_ad_notification_popups; -constexpr base::TimeDelta kFadeDuration = - base::TimeDelta::FromMilliseconds(200); - const int kShadowElevation = 5; constexpr SkColor kLightModeBackgroundColor = SkColorSetRGB(0xed, 0xf0, 0xf2); @@ -315,41 +314,44 @@ AdNotification AdNotificationPopup::GetAdNotification() const { return ad_notification_; } -gfx::Point AdNotificationPopup::GetDefaultOriginForSize( - const gfx::Size& size) const { - const gfx::Rect work_area = +gfx::Point AdNotificationPopup::GetDefaultOriginForSize(const gfx::Size& size) { + const gfx::Rect display_bounds = + display::Screen::GetScreen()->GetPrimaryDisplay().bounds(); + + const gfx::Rect display_work_area = display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); -#if defined(OS_WIN) - // Top right - const int kTopPadding = 10; - const int kRightPadding = 10; + // Calculate position + const double width = static_cast(display_bounds.width()); + const double normalized_display_coordinate_x = + features::AdNotificationNormalizedDisplayCoordinateX(); + int x = static_cast(width * normalized_display_coordinate_x); + x -= size.width() / 2.0; - const int x = work_area.right() - (size.width() + kRightPadding); - const int y = work_area.y() + kTopPadding; -#elif defined(OS_MAC) - // Top right to the left of macOS native notifications - const int kNativeNotificationWidth = 360; + const double height = static_cast(display_bounds.height()); + const double normalized_display_coordinate_y = + features::AdNotificationNormalizedDisplayCoordinateY(); + int y = static_cast(height * normalized_display_coordinate_y); + y -= size.height() / 2.0; - const int kTopPadding = 10; - const int kRightPadding = 10; + const gfx::Point origin(x, y); - const int x = work_area.right() - kNativeNotificationWidth - - (size.width() + kRightPadding); - const int y = work_area.y() + kTopPadding; -#elif defined(OS_LINUX) - // Top right - const int kTopPadding = 10; - const int kRightPadding = 10; + // Adjust to fit display work area + gfx::Rect bounds(origin, size); + bounds.AdjustToFit(display_work_area); - const int x = work_area.right() - (size.width() + kRightPadding); - const int y = work_area.y() + kTopPadding; -#endif + // Apply insets + const gfx::Vector2d insets(features::AdNotificationInsetX(), + features::AdNotificationInsetY()); + bounds += insets; - return gfx::Point(x, y); + // Adjust to fit display work area + bounds.AdjustToFit(display_work_area); + + return bounds.origin(); } -gfx::Point AdNotificationPopup::GetOriginForSize(const gfx::Size& size) const { +gfx::Point AdNotificationPopup::GetOriginForSize(const gfx::Size& size) { if (!profile_->GetPrefs()->HasPrefPath( prefs::kAdNotificationLastScreenPositionX) || !profile_->GetPrefs()->HasPrefPath( @@ -371,7 +373,7 @@ void AdNotificationPopup::SaveOrigin(const gfx::Point& origin) const { origin.y()); } -gfx::Rect AdNotificationPopup::CalculateBounds() const { +gfx::Rect AdNotificationPopup::CalculateBounds() { DCHECK(ad_notification_view_); gfx::Size size = ad_notification_view_->size(); DCHECK(!size.IsEmpty()); @@ -448,13 +450,21 @@ void AdNotificationPopup::CloseWidgetView() { void AdNotificationPopup::FadeIn() { animation_state_ = AnimationState::kFadeIn; - animation_->SetDuration(kFadeDuration); + + const base::TimeDelta fade_duration = + base::TimeDelta::FromMilliseconds(features::AdNotificationFadeDuration()); + animation_->SetDuration(fade_duration); + StartAnimation(); } void AdNotificationPopup::FadeOut() { animation_state_ = AnimationState::kFadeOut; - animation_->SetDuration(kFadeDuration); + + const base::TimeDelta fade_duration = + base::TimeDelta::FromMilliseconds(features::AdNotificationFadeDuration()); + animation_->SetDuration(fade_duration); + StartAnimation(); } diff --git a/browser/ui/brave_ads/ad_notification_popup.h b/browser/ui/brave_ads/ad_notification_popup.h index 74ab9aef6e55..a3f6257bf026 100644 --- a/browser/ui/brave_ads/ad_notification_popup.h +++ b/browser/ui/brave_ads/ad_notification_popup.h @@ -107,11 +107,11 @@ class AdNotificationPopup : public views::WidgetDelegateView, AdNotification ad_notification_; AdNotification GetAdNotification() const; - gfx::Point GetDefaultOriginForSize(const gfx::Size& size) const; - gfx::Point GetOriginForSize(const gfx::Size& size) const; + gfx::Point GetDefaultOriginForSize(const gfx::Size& size); + gfx::Point GetOriginForSize(const gfx::Size& size); void SaveOrigin(const gfx::Point& origin) const; - gfx::Rect CalculateBounds() const; + gfx::Rect CalculateBounds(); void RecomputeAlignment(); diff --git a/browser/ui/brave_ads/padded_image_button.cc b/browser/ui/brave_ads/padded_image_button.cc index d027d6743533..553b1c6e394f 100644 --- a/browser/ui/brave_ads/padded_image_button.cc +++ b/browser/ui/brave_ads/padded_image_button.cc @@ -21,9 +21,17 @@ namespace brave_ads { namespace { + constexpr SkColor kBackgroundColor = SK_ColorTRANSPARENT; -constexpr gfx::Insets kBorderInset(6); + +constexpr gfx::Insets kBorderInset( + /* top */ 4, + /* left */ 4, + /* bottom */ 0, + /* right */ 4); + const float kVisibleOpacity = 0.12f; + } // namespace PaddedImageButton::PaddedImageButton(PressedCallback callback) diff --git a/browser/ui/brave_ads/padded_image_view.cc b/browser/ui/brave_ads/padded_image_view.cc index c792d31b53a0..a81d65ae1eb8 100644 --- a/browser/ui/brave_ads/padded_image_view.cc +++ b/browser/ui/brave_ads/padded_image_view.cc @@ -18,9 +18,9 @@ namespace { constexpr SkColor kBackgroundColor = SK_ColorTRANSPARENT; constexpr gfx::Insets kBorderInset( - /* top */ 4, + /* top */ 2, /* left */ 6, - /* bottom */ 6, + /* bottom */ 0, /* right */ 6); } // namespace diff --git a/browser/ui/brave_ads/text_ad_notification_view.cc b/browser/ui/brave_ads/text_ad_notification_view.cc index 87681e41c502..9344e2a89f83 100644 --- a/browser/ui/brave_ads/text_ad_notification_view.cc +++ b/browser/ui/brave_ads/text_ad_notification_view.cc @@ -12,6 +12,7 @@ #include "brave/browser/ui/brave_ads/ad_notification_control_buttons_view.h" #include "brave/browser/ui/brave_ads/ad_notification_header_view.h" #include "brave/browser/ui/brave_ads/insets_util.h" +#include "build/build_config.h" #include "ui/gfx/color_palette.h" #include "ui/gfx/font.h" #include "ui/gfx/font_list.h" @@ -30,11 +31,11 @@ namespace brave_ads { namespace { const int kNotificationWidth = 350; -const int kNotificationHeight = 104; +const int kNotificationHeight = 100; constexpr gfx::Insets kContainerViewInsideBorderInsets( /* top */ 0, - /* left */ 16, + /* left */ 20, /* bottom */ 10, /* right */ 10); @@ -50,7 +51,14 @@ constexpr SkColor kLightModeBodyColor = SkColorSetRGB(0x45, 0x49, 0x55); constexpr SkColor kDarkModeBodyColor = SkColorSetRGB(0xd7, 0xdb, 0xe2); const int kBodyMaximumLines = 2; -const int kBodyLineSpacing = 3; + +#if defined(OS_WIN) +const int kBodyLineSpacing = 0; +#elif defined(OS_MAC) +const int kBodyLineSpacing = 2; +#elif defined(OS_LINUX) +const int kBodyLineSpacing = 2; +#endif const gfx::HorizontalAlignment kBodyHorizontalAlignment = gfx::ALIGN_LEFT; const gfx::VerticalAlignment kBodyVerticalAlignment = gfx::ALIGN_TOP; @@ -176,7 +184,8 @@ views::Label* TextAdNotificationView::CreateBodyLabel( AdjustInsetsForFontList(&border_insets, font_list); label->SetBorder(views::CreateEmptyBorder(border_insets)); - const int width = View::width() - GetInsets().width(); + const int width = View::width() - kContainerViewInsideBorderInsets.width() - + border_insets.width(); label->SizeToFit(width); label->SetHandlesTooltips(false); diff --git a/common/brave_channel_info.cc b/common/brave_channel_info.cc index cfed228c22bc..58599ea14f6f 100644 --- a/common/brave_channel_info.cc +++ b/common/brave_channel_info.cc @@ -24,13 +24,4 @@ std::string GetChannelName() { #endif // !OFFICIAL_BUILD } -bool IsNightlyOrDeveloperBuild() { -#if defined(OFFICIAL_BUILD) - return chrome::GetChannel() == version_info::Channel::CANARY || - chrome::GetChannel() == version_info::Channel::UNKNOWN; -#else // OFFICIAL_BUILD - return true; -#endif // !OFFICIAL_BUILD -} - } // namespace brave diff --git a/common/brave_channel_info.h b/common/brave_channel_info.h index be746088b834..16e58667f277 100644 --- a/common/brave_channel_info.h +++ b/common/brave_channel_info.h @@ -9,10 +9,7 @@ #include namespace brave { - std::string GetChannelName(); -bool IsNightlyOrDeveloperBuild(); - } #endif // BRAVE_COMMON_BRAVE_CHANNEL_INFO_H_ diff --git a/components/brave_ads/browser/BUILD.gn b/components/brave_ads/browser/BUILD.gn index 1311114e2cd7..2871fe9844fd 100644 --- a/components/brave_ads/browser/BUILD.gn +++ b/components/brave_ads/browser/BUILD.gn @@ -53,6 +53,8 @@ source_set("browser") { "component_updater/resource_component.h", "component_updater/resource_component_observer.h", "component_updater/resource_info.h", + "features.cc", + "features.h", "frequency_capping_helper.cc", "frequency_capping_helper.h", "notification_helper.cc", diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 62dbb3fa3f97..eca326df916e 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -46,6 +46,7 @@ #include "brave/browser/profiles/profile_util.h" #include "brave/common/brave_channel_info.h" #include "brave/components/brave_ads/browser/ads_p2a.h" +#include "brave/components/brave_ads/browser/features.h" #include "brave/components/brave_ads/browser/frequency_capping_helper.h" #include "brave/components/brave_ads/browser/notification_helper.h" #include "brave/components/brave_ads/common/pref_names.h" @@ -60,6 +61,7 @@ #include "brave/components/services/bat_ads/public/cpp/ads_client_mojo_bridge.h" #include "brave/components/services/bat_ads/public/interfaces/bat_ads.mojom.h" #include "brave/grit/brave_generated_resources.h" +#include "build/build_config.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/notifications/notification_display_service.h" #include "chrome/browser/profiles/profile.h" @@ -72,7 +74,6 @@ #endif #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/ui/browser_navigator_params.h" -#include "chrome/common/buildflags.h" #include "chrome/common/chrome_constants.h" #include "components/history/core/browser/history_service.h" #include "components/prefs/pref_service.h" @@ -1739,7 +1740,7 @@ std::string AdsServiceImpl::LoadDataResourceAndDecompressIfNeeded( } void AdsServiceImpl::ShowNotification(const ads::AdNotificationInfo& info) { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { std::unique_ptr platform_bridge = std::make_unique(profile_); @@ -1796,22 +1797,21 @@ void AdsServiceImpl::ShowNotification(const ads::AdNotificationInfo& info) { void AdsServiceImpl::StartNotificationTimeoutTimer(const std::string& uuid) { #if defined(OS_ANDROID) - if (!brave::IsNightlyOrDeveloperBuild()) { + if (!features::ShouldShowCustomAdNotifications()) { return; } #endif -#if !defined(OS_ANDROID) - const uint64_t timeout_in_seconds = 120; -#else - const uint64_t timeout_in_seconds = 30; -#endif - - notification_timers_[uuid] = std::make_unique(); + const int timeout_in_seconds = features::AdNotificationTimeout(); + if (timeout_in_seconds == 0) { + // Never time out + return; + } const base::TimeDelta timeout = base::TimeDelta::FromSeconds(timeout_in_seconds); + notification_timers_[uuid] = std::make_unique(); notification_timers_[uuid]->Start( FROM_HERE, timeout, base::BindOnce(&AdsServiceImpl::NotificationTimedOut, AsWeakPtr(), uuid)); @@ -1832,11 +1832,16 @@ bool AdsServiceImpl::StopNotificationTimeoutTimer(const std::string& uuid) { } bool AdsServiceImpl::ShouldShowNotifications() { + if (!features::IsAdNotificationsEnabled()) { + LOG(INFO) << "Notification not made: Feature is disabled"; + return false; + } + return NotificationHelper::GetInstance()->ShouldShowNotifications(); } void AdsServiceImpl::CloseNotification(const std::string& uuid) { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { std::unique_ptr platform_bridge = std::make_unique(profile_); diff --git a/components/brave_ads/browser/features.cc b/components/brave_ads/browser/features.cc new file mode 100644 index 000000000000..96c0bc7124da --- /dev/null +++ b/components/brave_ads/browser/features.cc @@ -0,0 +1,148 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_ads/browser/features.h" + +#include "base/feature_list.h" + +namespace brave_ads { +namespace features { + +const base::Feature kAdNotifications{"AdNotifications", + base::FEATURE_ENABLED_BY_DEFAULT}; + +namespace { + +// Set to true to show custom ad notifications or false to show system +// notifications +const char kFieldTrialParameterShouldShowCustomAdNotifications[] = + "should_show_custom_notifications"; +const bool kDefaultShouldShowCustomAdNotifications = true; + +// Ad notification timeout in seconds. Set to 0 to never time out +const char kFieldTrialParameterAdNotificationTimeout[] = + "ad_notification_timeout"; +#if !defined(OS_ANDROID) +const int kDefaultAdNotificationTimeout = 120; +#else +const int kDefaultAdNotificationTimeout = 30; +#endif + +#if !defined(OS_ANDROID) + +// Ad notification fade animation duration in milliseconds +const char kFieldTrialParameterAdNotificationFadeDuration[] = + "ad_notification_fade_duration"; +const int kDefaultAdNotificationFadeDuration = 200; + +// Ad notification normalized display coordinate for the x component should be +// between 0.0 and 1.0; coordinates outside this range will be adjusted to fit +// the work area. Set to 0.0 for left, 0.5 for center or 1.0 for right +const char kFieldTrialParameterAdNotificationNormalizedDisplayCoordinateX[] = + "ad_notification_normalized_display_coordinate_x"; +#if defined(OS_WIN) +const double kDefaultAdNotificationNormalizedDisplayCoordinateX = 1.0; +#elif defined(OS_MAC) +const double kDefaultAdNotificationNormalizedDisplayCoordinateX = 1.0; +#elif defined(OS_LINUX) +const double kDefaultAdNotificationNormalizedDisplayCoordinateX = 1.0; +#endif + +// Ad notification x inset within the display's work area specified in screen +// coordinates +const char kFieldTrialParameterAdNotificationInsetX[] = + "ad_notification_inset_x"; +#if defined(OS_WIN) +const int kDefaultAdNotificationInsetX = -13; +#elif defined(OS_MAC) +const int kSystemNotificationWidth = 360; +const int kDefaultAdNotificationInsetX = -(10 + kSystemNotificationWidth); +#elif defined(OS_LINUX) +const int kDefaultAdNotificationInsetX = -13; +#endif + +// Ad notification normalized display coordinate for the y component should be +// between 0.0 and 1.0; coordinates outside this range will be adjusted to fit +// the work area. Set to 0.0 for top, 0.5 for middle or 1.0 for bottom +const char kFieldTrialParameterAdNotificationNormalizedDisplayCoordinateY[] = + "ad_notification_normalized_display_coordinate_y"; +#if defined(OS_WIN) +const double kDefaultAdNotificationNormalizedDisplayCoordinateY = 0.0; +#elif defined(OS_MAC) +const double kDefaultAdNotificationNormalizedDisplayCoordinateY = 0.0; +#elif defined(OS_LINUX) +const double kDefaultAdNotificationNormalizedDisplayCoordinateY = 0.0; +#endif + +// Ad notification y inset within the display's work area specified in screen +// coordinates +const char kFieldTrialParameterAdNotificationInsetY[] = + "ad_notification_inset_y"; +#if defined(OS_WIN) +const int kDefaultAdNotificationInsetY = 18; +#elif defined(OS_MAC) +const int kDefaultAdNotificationInsetY = 11; +#elif defined(OS_LINUX) +const int kDefaultAdNotificationInsetY = 18; +#endif + +#endif // !defined(OS_ANDROID) + +} // namespace + +bool IsAdNotificationsEnabled() { + return base::FeatureList::IsEnabled(kAdNotifications); +} + +bool ShouldShowCustomAdNotifications() { + return GetFieldTrialParamByFeatureAsBool( + kAdNotifications, kFieldTrialParameterShouldShowCustomAdNotifications, + kDefaultShouldShowCustomAdNotifications); +} + +int AdNotificationTimeout() { + return GetFieldTrialParamByFeatureAsInt( + kAdNotifications, kFieldTrialParameterAdNotificationTimeout, + kDefaultAdNotificationTimeout); +} + +#if !defined(OS_ANDROID) + +int AdNotificationFadeDuration() { + return GetFieldTrialParamByFeatureAsInt( + kAdNotifications, kFieldTrialParameterAdNotificationFadeDuration, + kDefaultAdNotificationFadeDuration); +} + +double AdNotificationNormalizedDisplayCoordinateX() { + return GetFieldTrialParamByFeatureAsDouble( + kAdNotifications, + kFieldTrialParameterAdNotificationNormalizedDisplayCoordinateX, + kDefaultAdNotificationNormalizedDisplayCoordinateX); +} + +int AdNotificationInsetX() { + return GetFieldTrialParamByFeatureAsInt( + kAdNotifications, kFieldTrialParameterAdNotificationInsetX, + kDefaultAdNotificationInsetX); +} + +double AdNotificationNormalizedDisplayCoordinateY() { + return GetFieldTrialParamByFeatureAsDouble( + kAdNotifications, + kFieldTrialParameterAdNotificationNormalizedDisplayCoordinateY, + kDefaultAdNotificationNormalizedDisplayCoordinateY); +} + +int AdNotificationInsetY() { + return GetFieldTrialParamByFeatureAsInt( + kAdNotifications, kFieldTrialParameterAdNotificationInsetY, + kDefaultAdNotificationInsetY); +} + +#endif // !defined(OS_ANDROID) + +} // namespace features +} // namespace brave_ads diff --git a/components/brave_ads/browser/features.h b/components/brave_ads/browser/features.h new file mode 100644 index 000000000000..1c60106ce1e7 --- /dev/null +++ b/components/brave_ads/browser/features.h @@ -0,0 +1,40 @@ +/* Copyright (c) 2021 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_FEATURES_H_ +#define BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_FEATURES_H_ + +#include "build/build_config.h" + +namespace base { +struct Feature; +} // namespace base + +namespace brave_ads { +namespace features { + +extern const base::Feature kAdNotifications; + +bool IsAdNotificationsEnabled(); + +bool ShouldShowCustomAdNotifications(); + +int AdNotificationTimeout(); + +#if !defined(OS_ANDROID) + +int AdNotificationFadeDuration(); + +double AdNotificationNormalizedDisplayCoordinateX(); +int AdNotificationInsetX(); +double AdNotificationNormalizedDisplayCoordinateY(); +int AdNotificationInsetY(); + +#endif // !defined(OS_ANDROID) + +} // namespace features +} // namespace brave_ads + +#endif // BRAVE_COMPONENTS_BRAVE_ADS_BROWSER_FEATURES_H_ diff --git a/components/brave_ads/browser/notification_helper_android.cc b/components/brave_ads/browser/notification_helper_android.cc index f5e5dd185801..14590a593228 100644 --- a/components/brave_ads/browser/notification_helper_android.cc +++ b/components/brave_ads/browser/notification_helper_android.cc @@ -13,8 +13,8 @@ #include "brave/browser/brave_ads/android/jni_headers/BraveAdsSignupDialog_jni.h" #include "brave/browser/brave_ads/android/jni_headers/BraveAds_jni.h" #include "brave/build/android/jni_headers/BraveNotificationSettingsBridge_jni.h" -#include "brave/common/brave_channel_info.h" #include "brave/components/brave_ads/browser/background_helper.h" +#include "brave/components/brave_ads/browser/features.h" #include "chrome/android/chrome_jni_headers/NotificationSystemStatusUtil_jni.h" #include "chrome/browser/notifications/notification_channels_provider_android.h" @@ -34,7 +34,7 @@ NotificationHelperAndroid::NotificationHelperAndroid() = default; NotificationHelperAndroid::~NotificationHelperAndroid() = default; bool NotificationHelperAndroid::ShouldShowNotifications() { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { return true; } @@ -59,17 +59,18 @@ bool NotificationHelperAndroid::ShowMyFirstAdNotification() { return false; } - const bool use_custom_notifications = brave::IsNightlyOrDeveloperBuild(); + const bool should_show_custom_notifications = + features::ShouldShowCustomAdNotifications(); JNIEnv* env = base::android::AttachCurrentThread(); Java_BraveAdsSignupDialog_enqueueOnboardingNotificationNative( - env, use_custom_notifications); + env, should_show_custom_notifications); return true; } bool NotificationHelperAndroid::CanShowBackgroundNotifications() const { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { return true; } diff --git a/components/brave_ads/browser/notification_helper_linux.cc b/components/brave_ads/browser/notification_helper_linux.cc index b4c5431bb7d7..b313daf1c348 100644 --- a/components/brave_ads/browser/notification_helper_linux.cc +++ b/components/brave_ads/browser/notification_helper_linux.cc @@ -5,8 +5,7 @@ #include "brave/components/brave_ads/browser/notification_helper_linux.h" -#include "base/logging.h" -#include "brave/common/brave_channel_info.h" +#include "brave/components/brave_ads/browser/features.h" namespace brave_ads { @@ -15,7 +14,7 @@ NotificationHelperLinux::NotificationHelperLinux() = default; NotificationHelperLinux::~NotificationHelperLinux() = default; bool NotificationHelperLinux::ShouldShowNotifications() { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { return true; } diff --git a/components/brave_ads/browser/notification_helper_mac.mm b/components/brave_ads/browser/notification_helper_mac.mm index 2b25105e0aa4..d48b6917db19 100644 --- a/components/brave_ads/browser/notification_helper_mac.mm +++ b/components/brave_ads/browser/notification_helper_mac.mm @@ -13,7 +13,7 @@ #include "base/feature_list.h" #include "base/logging.h" #include "base/mac/mac_util.h" -#include "brave/common/brave_channel_info.h" +#include "brave/components/brave_ads/browser/features.h" #include "brave/components/brave_ads/browser/notification_helper_mac.h" #include "chrome/common/chrome_features.h" @@ -24,7 +24,7 @@ NotificationHelperMac::~NotificationHelperMac() = default; bool NotificationHelperMac::ShouldShowNotifications() { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { return true; } @@ -34,7 +34,7 @@ return true; } - if (!base::FeatureList::IsEnabled(features::kNativeNotifications)) { + if (!base::FeatureList::IsEnabled(::features::kNativeNotifications)) { LOG(WARNING) << "Native notification feature is disabled so falling back to" " Message Center"; return true; diff --git a/components/brave_ads/browser/notification_helper_win.cc b/components/brave_ads/browser/notification_helper_win.cc index 3650e597fe17..f78a79040f0b 100644 --- a/components/brave_ads/browser/notification_helper_win.cc +++ b/components/brave_ads/browser/notification_helper_win.cc @@ -12,7 +12,7 @@ #include "base/win/core_winrt_util.h" #include "base/win/scoped_hstring.h" #include "base/win/windows_version.h" -#include "brave/common/brave_channel_info.h" +#include "brave/components/brave_ads/browser/features.h" #include "chrome/common/chrome_features.h" #include "chrome/install_static/install_util.h" #include "chrome/installer/util/install_util.h" @@ -65,7 +65,7 @@ NotificationHelperWin::NotificationHelperWin() = default; NotificationHelperWin::~NotificationHelperWin() = default; bool NotificationHelperWin::ShouldShowNotifications() { - if (brave::IsNightlyOrDeveloperBuild()) { + if (features::ShouldShowCustomAdNotifications()) { return true; } @@ -81,7 +81,7 @@ bool NotificationHelperWin::ShouldShowNotifications() { return true; } - if (!base::FeatureList::IsEnabled(features::kNativeNotifications)) { + if (!base::FeatureList::IsEnabled(::features::kNativeNotifications)) { LOG(WARNING) << "Native notification feature is disabled so falling back to" " Message Center"; return true; diff --git a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc index 86eabd3bbdf1..f160cc52902d 100644 --- a/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc +++ b/vendor/bat-native-ads/src/bat/ads/internal/ads/ad_notifications/ad_notifications.cc @@ -21,7 +21,6 @@ #include "bat/ads/internal/logging.h" #include "bat/ads/pref_names.h" #include "bat/ads/result.h" -#include "brave/common/brave_channel_info.h" #if defined(OS_ANDROID) #include "base/android/build_info.h" @@ -182,10 +181,6 @@ uint64_t AdNotifications::Count() const { #if defined(OS_ANDROID) void AdNotifications::RemoveAllAfterReboot() { - if (brave::IsNightlyOrDeveloperBuild()) { - return; - } - database::table::AdEvents database_table; database_table.GetAll([=](const Result result, const AdEventList& ad_events) { if (result != Result::SUCCESS) { @@ -209,10 +204,6 @@ void AdNotifications::RemoveAllAfterReboot() { } void AdNotifications::RemoveAllAfterUpdate() { - if (brave::IsNightlyOrDeveloperBuild()) { - return; - } - const std::string current_version_code = base::android::BuildInfo::GetInstance()->package_version_code(); From 450d81103fde3935a6e1f7ac718ca318a7c71220 Mon Sep 17 00:00:00 2001 From: wchen342 Date: Mon, 10 May 2021 23:32:08 +0300 Subject: [PATCH 12/21] Format fix --- browser/ui/webui/brave_rewards_page_ui.cc | 168 ++++++++-------------- 1 file changed, 56 insertions(+), 112 deletions(-) diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index fd91c1d5f656..d36f417752d1 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -492,14 +492,11 @@ void RewardsDOMHandler::Init() { ads_service_ = brave_ads::AdsServiceFactory::GetForProfile(profile); } -void RewardsDOMHandler::IsInitialized( - const base::ListValue* args) { +void RewardsDOMHandler::IsInitialized(const base::ListValue* args) { AllowJavascript(); if (rewards_service_ && rewards_service_->IsInitialized()) { - CallJavascriptFunction( - "brave_rewards.initialized", - base::Value(0)); + CallJavascriptFunction("brave_rewards.initialized", base::Value(0)); } } @@ -521,7 +518,7 @@ void RewardsDOMHandler::OnJavascriptDisallowed() { if (ads_service_) { ads_service_->RemoveObserver(this); } - + weak_factory_.InvalidateWeakPtrs(); } @@ -551,8 +548,7 @@ void RewardsDOMHandler::OnGetRewardsParameters( data.SetDouble("autoContributeChoice", parameters->auto_contribute_choice); data.SetList("autoContributeChoices", std::move(choices)); } - CallJavascriptFunction( - "brave_rewards.rewardsParameters", data); + CallJavascriptFunction("brave_rewards.rewardsParameters", data); } void RewardsDOMHandler::OnRewardsInitialized( @@ -560,9 +556,7 @@ void RewardsDOMHandler::OnRewardsInitialized( if (!IsJavascriptAllowed()) return; - CallJavascriptFunction( - "brave_rewards.initialized", - base::Value(0)); + CallJavascriptFunction("brave_rewards.initialized", base::Value(0)); } void RewardsDOMHandler::GetAutoContributeProperties( @@ -589,9 +583,7 @@ void RewardsDOMHandler::OnGetAutoContributeProperties( properties->contribution_non_verified); values.SetBoolean("contributionVideos", properties->contribution_videos); - CallJavascriptFunction( - "brave_rewards.autoContributeProperties", - values); + CallJavascriptFunction("brave_rewards.autoContributeProperties", values); } void RewardsDOMHandler::OnFetchPromotions( @@ -643,9 +635,7 @@ void RewardsDOMHandler::OnClaimPromotion( response.SetString("captchaId", captcha_id); response.SetString("hint", hint); - CallJavascriptFunction( - "brave_rewards.claimPromotion", - response); + CallJavascriptFunction("brave_rewards.claimPromotion", response); } void RewardsDOMHandler::ClaimPromotion(const base::ListValue* args) { @@ -675,9 +665,7 @@ void RewardsDOMHandler::AttestPromotion(const base::ListValue *args) { if (!rewards_service_) { base::DictionaryValue finish; finish.SetInteger("status", 1); - CallJavascriptFunction( - "brave_rewards.promotionFinish", - finish); + CallJavascriptFunction("brave_rewards.promotionFinish", finish); } const std::string promotion_id = args->GetList()[0].GetString(); @@ -712,9 +700,7 @@ void RewardsDOMHandler::OnAttestPromotion( finish.SetInteger("result", static_cast(result)); finish.SetKey("promotion", std::move(promotion_dict)); - CallJavascriptFunction( - "brave_rewards.promotionFinish", - finish); + CallJavascriptFunction("brave_rewards.promotionFinish", finish); } void RewardsDOMHandler::OnPromotionFinished( @@ -746,16 +732,14 @@ void RewardsDOMHandler::OnRecoverWallet( return; } - CallJavascriptFunction( - "brave_rewards.recoverWalletData", - base::Value(static_cast(result))); + CallJavascriptFunction("brave_rewards.recoverWalletData", + base::Value(static_cast(result))); } void RewardsDOMHandler::OnGetReconcileStamp(uint64_t reconcile_stamp) { if (IsJavascriptAllowed()) { std::string stamp = std::to_string(reconcile_stamp); - CallJavascriptFunction("brave_rewards.reconcileStamp", - base::Value(stamp)); + CallJavascriptFunction("brave_rewards.reconcileStamp", base::Value(stamp)); } } @@ -816,9 +800,9 @@ void RewardsDOMHandler::OnNotificationDeleted( const brave_rewards::RewardsNotificationService::RewardsNotification& notification) { #if defined(OS_ANDROID) - if (notification.type_ == - brave_rewards::RewardsNotificationService::REWARDS_NOTIFICATION_GRANT - && IsJavascriptAllowed()) { + if (notification.type_ == brave_rewards::RewardsNotificationService:: + REWARDS_NOTIFICATION_GRANT && + IsJavascriptAllowed()) { base::DictionaryValue finish; finish.SetInteger("status", false); finish.SetInteger("expiryTime", 0); @@ -934,9 +918,7 @@ void RewardsDOMHandler::OnPublisherList(ledger::type::PublisherInfoList list) { publishers->Append(std::move(publisher)); } - CallJavascriptFunction( - "brave_rewards.contributeList", - *publishers); + CallJavascriptFunction("brave_rewards.contributeList", *publishers); } void RewardsDOMHandler::OnExcludedSiteList( @@ -957,15 +939,13 @@ void RewardsDOMHandler::OnExcludedSiteList( publishers->Append(std::move(publisher)); } - CallJavascriptFunction( - "brave_rewards.excludedList", - *publishers); + CallJavascriptFunction("brave_rewards.excludedList", *publishers); } void RewardsDOMHandler::OnGetContributionAmount(double amount) { if (IsJavascriptAllowed()) { CallJavascriptFunction("brave_rewards.contributionAmount", - base::Value(amount)); + base::Value(amount)); } } @@ -992,9 +972,7 @@ void RewardsDOMHandler::OnReconcileComplete( complete.SetKey("result", base::Value(static_cast(result))); complete.SetKey("type", base::Value(static_cast(type))); - CallJavascriptFunction( - "brave_rewards.reconcileComplete", - complete); + CallJavascriptFunction("brave_rewards.reconcileComplete", complete); } void RewardsDOMHandler::RemoveRecurringTip(const base::ListValue *args) { @@ -1036,8 +1014,7 @@ void RewardsDOMHandler::OnGetRecurringTips( publishers->Append(std::move(publisher)); } - CallJavascriptFunction("brave_rewards.recurringTips", - *publishers); + CallJavascriptFunction("brave_rewards.recurringTips", *publishers); } void RewardsDOMHandler::OnGetOneTimeTips(ledger::type::PublisherInfoList list) { @@ -1061,9 +1038,7 @@ void RewardsDOMHandler::OnGetOneTimeTips(ledger::type::PublisherInfoList list) { publishers->Append(std::move(publisher)); } - CallJavascriptFunction( - "brave_rewards.currentTips", - *publishers); + CallJavascriptFunction("brave_rewards.currentTips", *publishers); } void RewardsDOMHandler::GetOneTimeTips(const base::ListValue *args) { @@ -1147,8 +1122,7 @@ void RewardsDOMHandler::OnGetAdsHistory(const base::ListValue& ads_history) { return; } - CallJavascriptFunction("brave_rewards.adsHistory", - ads_history); + CallJavascriptFunction("brave_rewards.adsHistory", ads_history); } void RewardsDOMHandler::ToggleAdThumbUp(const base::ListValue* args) { @@ -1176,8 +1150,7 @@ void RewardsDOMHandler::OnToggleAdThumbUp( base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("action", base::Value(action)); - CallJavascriptFunction("brave_rewards.onToggleAdThumbUp", - result); + CallJavascriptFunction("brave_rewards.onToggleAdThumbUp", result); } void RewardsDOMHandler::ToggleAdThumbDown(const base::ListValue* args) { @@ -1205,8 +1178,7 @@ void RewardsDOMHandler::OnToggleAdThumbDown( base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("action", base::Value(action)); - CallJavascriptFunction("brave_rewards.onToggleAdThumbDown", - result); + CallJavascriptFunction("brave_rewards.onToggleAdThumbDown", result); } void RewardsDOMHandler::ToggleAdOptInAction(const base::ListValue* args) { @@ -1232,8 +1204,7 @@ void RewardsDOMHandler::OnToggleAdOptInAction(const std::string& category, base::Value result(base::Value::Type::DICTIONARY); result.SetKey("category", base::Value(category)); result.SetKey("action", base::Value(action)); - CallJavascriptFunction("brave_rewards.onToggleAdOptInAction", - result); + CallJavascriptFunction("brave_rewards.onToggleAdOptInAction", result); } void RewardsDOMHandler::ToggleAdOptOutAction(const base::ListValue* args) { @@ -1259,8 +1230,7 @@ void RewardsDOMHandler::OnToggleAdOptOutAction(const std::string& category, base::Value result(base::Value::Type::DICTIONARY); result.SetKey("category", base::Value(category)); result.SetKey("action", base::Value(action)); - CallJavascriptFunction("brave_rewards.onToggleAdOptOutAction", - result); + CallJavascriptFunction("brave_rewards.onToggleAdOptOutAction", result); } void RewardsDOMHandler::ToggleSaveAd(const base::ListValue* args) { @@ -1287,8 +1257,7 @@ void RewardsDOMHandler::OnToggleSaveAd( base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("saved", base::Value(saved)); - CallJavascriptFunction("brave_rewards.onToggleSaveAd", - result); + CallJavascriptFunction("brave_rewards.onToggleSaveAd", result); } void RewardsDOMHandler::ToggleFlagAd(const base::ListValue* args) { @@ -1314,8 +1283,7 @@ void RewardsDOMHandler::OnToggleFlagAd( base::Value result(base::Value::Type::DICTIONARY); result.SetKey("creativeInstanceId", base::Value(creative_instance_id)); result.SetKey("flagged", base::Value(flagged)); - CallJavascriptFunction("brave_rewards.onToggleFlagAd", - result); + CallJavascriptFunction("brave_rewards.onToggleFlagAd", result); } void RewardsDOMHandler::SaveAdsSetting(const base::ListValue* args) { @@ -1360,8 +1328,8 @@ void RewardsDOMHandler::GetPendingContributionsTotal( void RewardsDOMHandler::OnGetPendingContributionsTotal(double amount) { if (IsJavascriptAllowed()) { - CallJavascriptFunction( - "brave_rewards.pendingContributionTotal", base::Value(amount)); + CallJavascriptFunction("brave_rewards.pendingContributionTotal", + base::Value(amount)); } } @@ -1371,9 +1339,8 @@ void RewardsDOMHandler::OnPendingContributionSaved( if (!IsJavascriptAllowed()) { return; } - CallJavascriptFunction( - "brave_rewards.onPendingContributionSaved", - base::Value(static_cast(result))); + CallJavascriptFunction("brave_rewards.onPendingContributionSaved", + base::Value(static_cast(result))); } void RewardsDOMHandler::OnPublisherListNormalized( @@ -1417,15 +1384,13 @@ void RewardsDOMHandler::OnGetStatement(const bool success, history.SetInteger("adsReceivedThisMonth", ads_received_this_month); - CallJavascriptFunction( - "brave_rewards.statement", history); + CallJavascriptFunction("brave_rewards.statement", history); } void RewardsDOMHandler::OnStatementChanged( brave_rewards::RewardsService* rewards_service) { if (IsJavascriptAllowed()) { - CallJavascriptFunction( - "brave_rewards.statementChanged"); + CallJavascriptFunction("brave_rewards.statementChanged"); } } @@ -1438,8 +1403,8 @@ void RewardsDOMHandler::OnRecurringTipSaved( brave_rewards::RewardsService* rewards_service, bool success) { if (IsJavascriptAllowed()) { - CallJavascriptFunction( - "brave_rewards.recurringTipSaved", base::Value(success)); + CallJavascriptFunction("brave_rewards.recurringTipSaved", + base::Value(success)); } } @@ -1447,11 +1412,11 @@ void RewardsDOMHandler::OnRecurringTipRemoved( brave_rewards::RewardsService* rewards_service, bool success) { if (!IsJavascriptAllowed()) { - return; + return; } - CallJavascriptFunction( - "brave_rewards.recurringTipRemoved", base::Value(success)); + CallJavascriptFunction("brave_rewards.recurringTipRemoved", + base::Value(success)); } void RewardsDOMHandler::SetInlineTippingPlatformEnabled( @@ -1504,9 +1469,7 @@ void RewardsDOMHandler::OnGetPendingContributions( contributions->Append(std::move(contribution)); } - CallJavascriptFunction( - "brave_rewards.pendingContributions", - *contributions); + CallJavascriptFunction("brave_rewards.pendingContributions", *contributions); } void RewardsDOMHandler::RemovePendingContribution( @@ -1531,9 +1494,8 @@ void RewardsDOMHandler::OnPendingContributionRemoved( brave_rewards::RewardsService* rewards_service, const ledger::type::Result result) { if (IsJavascriptAllowed()) { - CallJavascriptFunction( - "brave_rewards.onRemovePendingContribution", - base::Value(static_cast(result))); + CallJavascriptFunction("brave_rewards.onRemovePendingContribution", + base::Value(static_cast(result))); } } @@ -1606,8 +1568,7 @@ void RewardsDOMHandler::OnGetExternalWallet( data.SetKey("wallet", std::move(wallet_dict)); - CallJavascriptFunction("brave_rewards.externalWallet", - data); + CallJavascriptFunction("brave_rewards.externalWallet", data); } } @@ -1631,8 +1592,7 @@ void RewardsDOMHandler::OnProcessRewardsPageUrl( } data.SetKey("args", std::move(new_args)); - CallJavascriptFunction("brave_rewards.processRewardsPageUrl", - data); + CallJavascriptFunction("brave_rewards.processRewardsPageUrl", data); } void RewardsDOMHandler::ProcessRewardsPageUrl(const base::ListValue* args) { @@ -1665,9 +1625,7 @@ void RewardsDOMHandler::OnDisconnectWallet( data.SetIntKey("result", static_cast(result)); data.SetStringKey("walletType", wallet_type); - CallJavascriptFunction( - "brave_rewards.disconnectWallet", - data); + CallJavascriptFunction("brave_rewards.disconnectWallet", data); } void RewardsDOMHandler::OnAdsEnabled( @@ -1690,9 +1648,7 @@ void RewardsDOMHandler::OnlyAnonWallet(const base::ListValue* args) { const bool allow = rewards_service_->OnlyAnonWallet(); - CallJavascriptFunction( - "brave_rewards.onlyAnonWallet", - base::Value(allow)); + CallJavascriptFunction("brave_rewards.onlyAnonWallet", base::Value(allow)); } void RewardsDOMHandler::OnUnblindedTokensReady( @@ -1733,9 +1689,7 @@ void RewardsDOMHandler::OnGetBalanceReport( data.SetIntKey("year", year); data.SetKey("report", std::move(report_base)); - CallJavascriptFunction( - "brave_rewards.balanceReport", - data); + CallJavascriptFunction("brave_rewards.balanceReport", data); } void RewardsDOMHandler::GetBalanceReport(const base::ListValue* args) { @@ -1822,9 +1776,7 @@ void RewardsDOMHandler::OnGetMonthlyReport( data.SetKey("report", std::move(report_base)); - CallJavascriptFunction( - "brave_rewards.monthlyReport", - data); + CallJavascriptFunction("brave_rewards.monthlyReport", data); } void RewardsDOMHandler::GetMonthlyReport(const base::ListValue* args) { @@ -1852,9 +1804,7 @@ void RewardsDOMHandler::OnGetAllMonthlyReportIds( list.Append(base::Value(item)); } - CallJavascriptFunction( - "brave_rewards.monthlyReportIds", - list); + CallJavascriptFunction("brave_rewards.monthlyReportIds", list); } void RewardsDOMHandler::GetAllMonthlyReportIds(const base::ListValue* args) { @@ -1876,8 +1826,8 @@ void RewardsDOMHandler::GetCountryCode(const base::ListValue* args) { brave_l10n::LocaleHelper::GetInstance()->GetLocale(); const std::string country_code = brave_l10n::GetCountryCode(locale); - CallJavascriptFunction( - "brave_rewards.countryCode", base::Value(country_code)); + CallJavascriptFunction("brave_rewards.countryCode", + base::Value(country_code)); } void RewardsDOMHandler::CompleteReset(const base::ListValue* args) { @@ -1893,8 +1843,7 @@ void RewardsDOMHandler::OnCompleteReset(const bool success) { return; } - CallJavascriptFunction( - "brave_rewards.completeReset", base::Value(success)); + CallJavascriptFunction("brave_rewards.completeReset", base::Value(success)); } void RewardsDOMHandler::GetPaymentId(const base::ListValue* args) { @@ -1926,9 +1875,7 @@ void RewardsDOMHandler::OnGetPaymentId(ledger::type::BraveWalletPtr wallet) { payment_id = wallet->payment_id; } - CallJavascriptFunction( - "brave_rewards.paymentId", - base::Value(payment_id)); + CallJavascriptFunction("brave_rewards.paymentId", base::Value(payment_id)); } void RewardsDOMHandler::GetWalletPassphrase(const base::ListValue* args) { @@ -1946,9 +1893,8 @@ void RewardsDOMHandler::OnGetWalletPassphrase(const std::string& passphrase) { return; } - CallJavascriptFunction( - "brave_rewards.walletPassphrase", - base::Value(passphrase)); + CallJavascriptFunction("brave_rewards.walletPassphrase", + base::Value(passphrase)); } void RewardsDOMHandler::GetOnboardingStatus(const base::ListValue* args) { @@ -1957,9 +1903,7 @@ void RewardsDOMHandler::GetOnboardingStatus(const base::ListValue* args) { } base::Value data(base::Value::Type::DICTIONARY); data.SetBoolKey("showOnboarding", rewards_service_->ShouldShowOnboarding()); - CallJavascriptFunction( - "brave_rewards.onboardingStatus", - data); + CallJavascriptFunction("brave_rewards.onboardingStatus", data); } void RewardsDOMHandler::SaveOnboardingResult(const base::ListValue* args) { From 2fc1c62eb3e760248748839d431ced919152307d Mon Sep 17 00:00:00 2001 From: Serg Date: Mon, 10 May 2021 21:39:32 -0400 Subject: [PATCH 13/21] Corrects a build of brave wallet after cr91 --- .../brave_wallet/renderer/brave_wallet_js_handler.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/components/brave_wallet/renderer/brave_wallet_js_handler.cc b/components/brave_wallet/renderer/brave_wallet_js_handler.cc index fb3746840891..b7efc68d542f 100644 --- a/components/brave_wallet/renderer/brave_wallet_js_handler.cc +++ b/components/brave_wallet/renderer/brave_wallet_js_handler.cc @@ -10,7 +10,6 @@ #include "base/json/json_writer.h" #include "base/no_destructor.h" -#include "base/strings/string16.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -46,7 +45,7 @@ std::string LoadDataResource(const int id) { v8::MaybeLocal GetProperty(v8::Local context, v8::Local object, - const base::string16& name) { + const std::u16string& name) { v8::Isolate* isolate = context->GetIsolate(); v8::Local name_str = gin::ConvertToV8(isolate, name).As(); @@ -59,8 +58,8 @@ v8::MaybeLocal GetProperty(v8::Local context, } void CallMethodOfObject(blink::WebLocalFrame* web_frame, - const base::string16& object_name, - const base::string16& method_name, + const std::u16string& object_name, + const std::u16string& method_name, base::Value arguments) { if (web_frame->IsProvisional()) return; @@ -254,8 +253,8 @@ void BraveWalletJSHandler::FireEvent(const std::string& event, args.Append(event); args.Append(event_args); CallMethodOfObject(render_frame_->GetWebFrame(), - STRING16_LITERAL("ethereum"), - STRING16_LITERAL("emit"), + u"ethereum", + u"emit", std::move(args)); } From 0fde59cbfb3e4a0f97abc21a16f12165bb703a73 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Tue, 4 May 2021 09:52:25 +0900 Subject: [PATCH 14/21] Fixed crypto.com widget shows invalid price fix https://github.com/brave/brave-browser/issues/15605 ticker prices raw data from crypto.com could be int or double. --- .../crypto_dot_com/browser/crypto_dot_com_json_parser.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc b/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc index 448a4f574ecd..fffeb30795df 100644 --- a/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc +++ b/components/crypto_dot_com/browser/crypto_dot_com_json_parser.cc @@ -55,10 +55,11 @@ bool CryptoDotComJSONParser::GetTickerInfoFromJSON( const base::Value* l = data->FindKey("l"); const base::Value* price = data->FindKey("a"); - if (!(v && v->is_double()) || - !(h && h->is_double()) || - !(l && l->is_double()) || - !(price && price->is_double())) { + // Number could be double or int. + if (!(v && (v->is_double() || v->is_int())) || + !(h && (h->is_double() || h->is_int())) || + !(l && (l->is_double() || l->is_int())) || + !(price && (price->is_double() || price->is_int()))) { info->insert({"volume", std::string()}); info->insert({"price", std::string()}); return false; From c18081d1051c8a9d195438b0e465282cda694bbc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 15:12:29 +0100 Subject: [PATCH 15/21] Bump hosted-git-info from 2.8.8 to 2.8.9 (#8756) Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.8 to 2.8.9. - [Release notes](https://github.com/npm/hosted-git-info/releases) - [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md) - [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.8...v2.8.9) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e371dd99255f..cc38059a5330 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12366,9 +12366,9 @@ } }, "hosted-git-info": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz", - "integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==", + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, "html-element-map": { From fe0c84b55c1f3453feb78b2adf044f0df3a35cbe Mon Sep 17 00:00:00 2001 From: Deep Pandya <5146988+deeppandya@users.noreply.github.com> Date: Tue, 11 May 2021 12:58:34 -0400 Subject: [PATCH 16/21] Remove BAP deprecation modal (#8762) --- android/brave_java_resources.gni | 5 - android/brave_java_sources.gni | 1 - .../chrome/browser/BraveRewardsHelper.java | 12 -- .../browser/BraveRewardsPanelPopup.java | 1 + .../DeprecateBAPModalDialogFragment.java | 106 --------------- .../chrome/browser/app/BraveActivity.java | 121 +----------------- .../browser/shields/ShieldsTooltipEnum.java | 4 - .../toolbar/top/BraveToolbarLayout.java | 71 +--------- .../java/res/drawable/ic_warning_triangle.xml | 10 -- .../res/drawable/ic_warning_triangle_2.xml | 10 -- .../res/drawable/rewards_modal_background.xml | 12 -- .../drawable/rewards_tooltip_background.xml | 13 -- .../fragment_deprecate_bap_modal_dialog.xml | 79 ------------ android/java/res/values/brave_colors.xml | 1 - .../android/strings/android_brave_strings.grd | 14 -- 15 files changed, 3 insertions(+), 457 deletions(-) delete mode 100644 android/java/org/chromium/chrome/browser/DeprecateBAPModalDialogFragment.java delete mode 100644 android/java/res/drawable/ic_warning_triangle.xml delete mode 100644 android/java/res/drawable/ic_warning_triangle_2.xml delete mode 100644 android/java/res/drawable/rewards_modal_background.xml delete mode 100644 android/java/res/drawable/rewards_tooltip_background.xml delete mode 100644 android/java/res/layout/fragment_deprecate_bap_modal_dialog.xml diff --git a/android/brave_java_resources.gni b/android/brave_java_resources.gni index 7a6eb775e662..673169daf7e0 100644 --- a/android/brave_java_resources.gni +++ b/android/brave_java_resources.gni @@ -614,8 +614,6 @@ brave_java_resources = [ "java/res/drawable/ic_toggle_up.xml", "java/res/drawable/ic_wallet_add.xml", "java/res/drawable/ic_warning_circle.xml", - "java/res/drawable/ic_warning_triangle.xml", - "java/res/drawable/ic_warning_triangle_2.xml", "java/res/drawable/image_credit_rounded_shape.xml", "java/res/drawable/modern_toolbar_background_grey_end_segment.xml", "java/res/drawable/ntp_widget_indicator_bg.xml", @@ -634,8 +632,6 @@ brave_java_resources = [ "java/res/drawable/rewards_button_purple_border.xml", "java/res/drawable/rewards_button_summary.xml", "java/res/drawable/rewards_image_button.xml", - "java/res/drawable/rewards_modal_background.xml", - "java/res/drawable/rewards_tooltip_background.xml", "java/res/drawable/rounded_corners.xml", "java/res/drawable/rounded_filled.xml", "java/res/drawable/rounded_filled_binance.xml", @@ -721,7 +717,6 @@ brave_java_resources = [ "java/res/layout/fragment_brave_rewards_onboarding.xml", "java/res/layout/fragment_cross_promotional_modal_dialog.xml", "java/res/layout/fragment_crypto_widget_bottom_sheet_dialog.xml", - "java/res/layout/fragment_deprecate_bap_modal_dialog.xml", "java/res/layout/fragment_onboarding_v2.xml", "java/res/layout/fragment_qr_code_share.xml", "java/res/layout/fragment_rate_dialog.xml", diff --git a/android/brave_java_sources.gni b/android/brave_java_sources.gni index a087901073cd..51b905749341 100644 --- a/android/brave_java_sources.gni +++ b/android/brave_java_sources.gni @@ -36,7 +36,6 @@ brave_java_sources = [ "../../brave/android/java/org/chromium/chrome/browser/BraveSyncReflectionUtils.java", "../../brave/android/java/org/chromium/chrome/browser/BraveUphold.java", "../../brave/android/java/org/chromium/chrome/browser/CrossPromotionalModalDialogFragment.java", - "../../brave/android/java/org/chromium/chrome/browser/DeprecateBAPModalDialogFragment.java", "../../brave/android/java/org/chromium/chrome/browser/InternetConnection.java", "../../brave/android/java/org/chromium/chrome/browser/QRCodeShareDialogFragment.java", "../../brave/android/java/org/chromium/chrome/browser/SetDefaultBrowserActivity.java", diff --git a/android/java/org/chromium/chrome/browser/BraveRewardsHelper.java b/android/java/org/chromium/chrome/browser/BraveRewardsHelper.java index edb8b3caea65..51694af2e3a8 100644 --- a/android/java/org/chromium/chrome/browser/BraveRewardsHelper.java +++ b/android/java/org/chromium/chrome/browser/BraveRewardsHelper.java @@ -54,7 +54,6 @@ public class BraveRewardsHelper implements LargeIconBridge.LargeIconCallback{ private static final String PREF_SHOW_ONBOARDING_MINI_MODAL = "show_onboarding_mini_modal"; private static final String PREF_NEXT_REWARDS_ONBOARDING_MODAL_DATE = "next_rewards_onboarding_modal_date"; - private static final String PREF_NEXT_BAP_MODAL_DATE = "next_bap_modal_date"; private static final String PREF_REWARDS_ENV_CHANGE = "rewards_env_change"; private static final String PREF_REWARDS_ONBOARDING_MODAL = "rewards_onboarding_modal"; private static final int FAVICON_CIRCLE_MEASUREMENTS = 70; // dp @@ -103,17 +102,6 @@ public static void setNextRewardsOnboardingModalDate(long nextDate) { sharedPreferencesEditor.apply(); } - public static long getNextBAPModalDate() { - return ContextUtils.getAppSharedPreferences().getLong(PREF_NEXT_BAP_MODAL_DATE, 0); - } - - public static void setNextBAPModalDate(long nextDate) { - SharedPreferences.Editor sharedPreferencesEditor = - ContextUtils.getAppSharedPreferences().edit(); - sharedPreferencesEditor.putLong(PREF_NEXT_BAP_MODAL_DATE, nextDate); - sharedPreferencesEditor.apply(); - } - public static void setRewardsOnboardingModalShown(boolean isShown) { SharedPreferences.Editor sharedPreferencesEditor = ContextUtils.getAppSharedPreferences().edit(); diff --git a/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java b/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java index 515c002d5b53..a0096f9cc7fd 100644 --- a/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java +++ b/android/java/org/chromium/chrome/browser/BraveRewardsPanelPopup.java @@ -2066,6 +2066,7 @@ public void updateDrawState(@NonNull TextPaint ds) { loginPopupWindow.setContentView(loginPopupView); view.post(new Runnable() { + @Override public void run() { if (SysUtils.isLowEndDevice()) { loginPopupWindow.setAnimationStyle(0); diff --git a/android/java/org/chromium/chrome/browser/DeprecateBAPModalDialogFragment.java b/android/java/org/chromium/chrome/browser/DeprecateBAPModalDialogFragment.java deleted file mode 100644 index ded1f01f2b91..000000000000 --- a/android/java/org/chromium/chrome/browser/DeprecateBAPModalDialogFragment.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright (c) 2021 The Brave Authors. All rights reserved. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -package org.chromium.chrome.browser; - -import android.content.DialogInterface; -import android.content.pm.ActivityInfo; -import android.content.res.Configuration; -import android.os.Bundle; -import android.util.DisplayMetrics; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.LinearLayout; - -import androidx.appcompat.widget.AppCompatImageView; -import androidx.fragment.app.DialogFragment; - -import org.chromium.chrome.R; -import org.chromium.chrome.browser.util.ConfigurationUtils; -import org.chromium.ui.base.DeviceFormFactor; - -public class DeprecateBAPModalDialogFragment - extends DialogFragment implements View.OnClickListener { - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - setDialogParams(); - } - - @Override - public void onResume() { - super.onResume(); - getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() { - @Override - public boolean onKey(android.content.DialogInterface dialog, int keyCode, - android.view.KeyEvent event) { - if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) { - dismiss(); - return true; - } else - return false; - } - }); - setDialogParams(); - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setStyle(STYLE_NO_TITLE, 0); - getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } - - @Override - public void onDestroyView() { - getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); - super.onDestroyView(); - } - - @Override - public View onCreateView( - LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_deprecate_bap_modal_dialog, container, false); - } - - @Override - public void onViewCreated(View view, Bundle savedInstanceState) { - Button mDoneButton = view.findViewById(R.id.btn_done); - mDoneButton.setOnClickListener(this); - } - - @Override - public void onClick(View view) { - dismiss(); - } - - private void setDialogParams() { - DisplayMetrics displayMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); - int mDeviceHeight = displayMetrics.heightPixels; - int mDeviceWidth = displayMetrics.widthPixels; - - WindowManager.LayoutParams params = getDialog().getWindow().getAttributes(); - boolean isTablet = DeviceFormFactor.isNonMultiDisplayContextOnTablet(getActivity()); - boolean isLandscape = ConfigurationUtils.isLandscape(getActivity()); - if (isTablet) { - params.width = (int) (0.5 * mDeviceWidth); - } else { - if (isLandscape) { - params.width = (int) (0.5 * mDeviceWidth); - } else { - params.width = (int) (0.9 * mDeviceWidth); - } - } - params.height = LinearLayout.LayoutParams.WRAP_CONTENT; - getDialog().getWindow().setAttributes(params); - } -} diff --git a/android/java/org/chromium/chrome/browser/app/BraveActivity.java b/android/java/org/chromium/chrome/browser/app/BraveActivity.java index b1c465fa49d7..a0fe4fef7256 100644 --- a/android/java/org/chromium/chrome/browser/app/BraveActivity.java +++ b/android/java/org/chromium/chrome/browser/app/BraveActivity.java @@ -44,23 +44,19 @@ import org.chromium.chrome.R; import org.chromium.chrome.browser.ApplicationLifetime; import org.chromium.chrome.browser.BraveConfig; -import org.chromium.chrome.browser.BraveFeatureList; import org.chromium.chrome.browser.BraveHelper; import org.chromium.chrome.browser.BraveRelaunchUtils; import org.chromium.chrome.browser.BraveRewardsHelper; import org.chromium.chrome.browser.BraveRewardsNativeWorker; -import org.chromium.chrome.browser.BraveRewardsObserver; import org.chromium.chrome.browser.BraveSyncReflectionUtils; import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.CrossPromotionalModalDialogFragment; -import org.chromium.chrome.browser.DeprecateBAPModalDialogFragment; import org.chromium.chrome.browser.LaunchIntentDispatcher; import org.chromium.chrome.browser.SetDefaultBrowserActivity; import org.chromium.chrome.browser.bookmarks.BookmarkBridge; import org.chromium.chrome.browser.bookmarks.BookmarkModel; import org.chromium.chrome.browser.brave_stats.BraveStatsUtil; import org.chromium.chrome.browser.dependency_injection.ChromeActivityComponent; -import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.informers.BraveAndroidSyncDisabledInformer; import org.chromium.chrome.browser.notifications.BraveSetDefaultBrowserNotificationService; @@ -111,8 +107,7 @@ * Brave's extension for ChromeActivity */ @JNINamespace("chrome::android") -public abstract class BraveActivity - extends ChromeActivity implements BraveRewardsObserver { +public abstract class BraveActivity extends ChromeActivity { public static final int SITE_BANNER_REQUEST_CODE = 33; public static final int VERIFY_WALLET_ACTIVITY_REQUEST_CODE = 34; public static final int USER_WALLET_ACTIVITY_REQUEST_CODE = 35; @@ -145,12 +140,9 @@ public abstract class BraveActivity public static final String ANDROID_PACKAGE_NAME = "android"; public static final String BRAVE_BLOG_URL = "http://www.brave.com/blog"; - private static final String JAPAN_COUNTRY_CODE = "JP"; - // Explicitly declare this variable to avoid build errors. // It will be removed in asm and parent variable will be used instead. protected ObservableSupplier mTabModelProfileSupplier; - private BraveRewardsNativeWorker mBraveRewardsNativeWorker; private static final List yandexRegions = Arrays.asList("AM", "AZ", "BY", "KG", "KZ", "MD", "RU", "TJ", "TM", "UZ"); @@ -164,20 +156,6 @@ public BraveActivity() { public void onResumeWithNative() { super.onResumeWithNative(); BraveActivityJni.get().restartStatsUpdater(); - if (ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS) - && !BravePrefServiceBridge.getInstance().getSafetynetCheckFailed()) { - if (mBraveRewardsNativeWorker == null) - mBraveRewardsNativeWorker = BraveRewardsNativeWorker.getInstance(); - mBraveRewardsNativeWorker.AddObserver(this); - } - } - - @Override - public void onPauseWithNative() { - super.onPauseWithNative(); - if (mBraveRewardsNativeWorker != null) { - mBraveRewardsNativeWorker.RemoveObserver(this); - } } @Override @@ -410,69 +388,6 @@ public void finishNativeInitialization() { calender.getTimeInMillis()); } checkSetDefaultBrowserModal(); - if (mBraveRewardsNativeWorker != null && mBraveRewardsNativeWorker.isRewardsEnabled() - && ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_REWARDS) - && !BravePrefServiceBridge.getInstance().getSafetynetCheckFailed()) { - mBraveRewardsNativeWorker.StartProcess(); - } - } - - @Override - public void OnRewardsParameters(int errorCode) { - if (errorCode == BraveRewardsNativeWorker.LEDGER_OK && mBraveRewardsNativeWorker != null - && mBraveRewardsNativeWorker.GetWalletBalance() != null - && mBraveRewardsNativeWorker.GetWalletBalance().getTotal() > 0) { - checkForDeprecateBAPDialog(); - } - } - - @Override - public void OnStartProcess() { - mBraveRewardsNativeWorker.GetRewardsParameters(); - } - - private void checkForDeprecateBAPDialog() { - String countryCode = Locale.getDefault().getCountry(); - if (countryCode.equals(JAPAN_COUNTRY_CODE) && !isRewardsPanelOpened() - && System.currentTimeMillis() > BraveRewardsHelper.getNextBAPModalDate()) { - Calendar toDayCalendar = Calendar.getInstance(); - Date todayDate = toDayCalendar.getTime(); - - Calendar march6Calendar = Calendar.getInstance(); - march6Calendar.set(Calendar.DAY_OF_MONTH, 6); - march6Calendar.set(Calendar.YEAR, 2021); - march6Calendar.set(Calendar.MONTH, 2); - march6Calendar.set(Calendar.HOUR_OF_DAY, 0); - march6Calendar.set(Calendar.MINUTE, 0); - march6Calendar.set(Calendar.SECOND, 0); - march6Calendar.set(Calendar.MILLISECOND, 0); - Date march6Date = march6Calendar.getTime(); - - Calendar march13Calendar = Calendar.getInstance(); - march13Calendar.set(Calendar.DAY_OF_MONTH, 13); - march13Calendar.set(Calendar.YEAR, 2021); - march13Calendar.set(Calendar.MONTH, 2); - march13Calendar.set(Calendar.HOUR_OF_DAY, 0); - march13Calendar.set(Calendar.MINUTE, 0); - march13Calendar.set(Calendar.SECOND, 0); - march13Calendar.set(Calendar.MILLISECOND, 0); - Date march13Date = march13Calendar.getTime(); - - boolean shouldSetNextDate = false; - if (todayDate.compareTo(march6Date) < 0) { - showRewardsTooltip(); - shouldSetNextDate = true; - } else if (todayDate.compareTo(march6Date) > 0 - && todayDate.compareTo(march13Date) < 0) { - showDeprecateBAPDialog(); - shouldSetNextDate = true; - } - if (shouldSetNextDate) { - Calendar calender = toDayCalendar; - calender.add(Calendar.DATE, DAYS_1); - BraveRewardsHelper.setNextBAPModalDate(calender.getTimeInMillis()); - } - } } private void checkSetDefaultBrowserModal() { @@ -587,14 +502,6 @@ public void hideRewardsOnboardingIcon() { } } - public void showRewardsTooltip() { - BraveToolbarLayout layout = (BraveToolbarLayout) findViewById(R.id.toolbar); - assert layout != null; - if (layout != null) { - layout.showRewardsTooltip(); - } - } - private void createNotificationChannel() { Context context = ContextUtils.getApplicationContext(); // Create the NotificationChannel, but only on API 26+ because @@ -715,24 +622,6 @@ public void openRewardsPanel() { } } - public boolean isRewardsPanelOpened() { - BraveToolbarLayout layout = (BraveToolbarLayout) findViewById(R.id.toolbar); - assert layout != null; - if (layout != null) { - return layout.isRewardsPanelOpened(); - } - return false; - } - - public boolean isShieldsTooltipShown() { - BraveToolbarLayout layout = (BraveToolbarLayout) findViewById(R.id.toolbar); - assert layout != null; - if (layout != null) { - return layout.isShieldsTooltipShown(); - } - return false; - } - public Tab selectExistingTab(String url) { Tab tab = getActivityTab(); if (tab != null && tab.getUrlString().equals(url)) { @@ -777,14 +666,6 @@ private void showCrossPromotionalDialog() { mCrossPromotionalModalDialogFragment.show(getSupportFragmentManager(), "CrossPromotionalModalDialogFragment"); } - public void showDeprecateBAPDialog() { - DeprecateBAPModalDialogFragment mDeprecateBAPModalDialogFragment = - new DeprecateBAPModalDialogFragment(); - mDeprecateBAPModalDialogFragment.setCancelable(false); - mDeprecateBAPModalDialogFragment.show( - getSupportFragmentManager(), "DeprecateBAPModalDialogFragment"); - } - static public ChromeTabbedActivity getChromeTabbedActivity() { for (Activity ref : ApplicationStatus.getRunningActivities()) { if (!(ref instanceof ChromeTabbedActivity)) continue; diff --git a/android/java/org/chromium/chrome/browser/shields/ShieldsTooltipEnum.java b/android/java/org/chromium/chrome/browser/shields/ShieldsTooltipEnum.java index 093f0c1e6ad0..98141c78efbb 100644 --- a/android/java/org/chromium/chrome/browser/shields/ShieldsTooltipEnum.java +++ b/android/java/org/chromium/chrome/browser/shields/ShieldsTooltipEnum.java @@ -23,9 +23,6 @@ public enum ShieldsTooltipEnum { HTTPS_UPGRADE_TOOLTIP(ShieldsTooltipEnumConstants.HTTPS_UPGRADE_TOOLTIP, R.string.tooltip_title_4, R.string.tooltip_text_4, R.color.shields_tooltip_arrow_color_2, R.drawable.shields_tooltip_background_2), - BAP_DEPRECATION_TOOLTIP(ShieldsTooltipEnumConstants.BAP_DEPRECATION_TOOLTIP, - R.string.rewards_tooltip_title, R.string.rewards_tooltip_text, - R.color.rewards_tooltip_arrow_color, R.drawable.rewards_tooltip_background), BRAVE_SHARE_STATS_TIER1_TOOLTIP(ShieldsTooltipEnumConstants.BRAVE_SHARE_STATS_TIER1_TOOLTIP, R.string.brave_stats_share_tooltip_tier1_title, R.string.brave_stats_share_tooltip_special_text, R.color.shields_tooltip_arrow_color_2, @@ -102,7 +99,6 @@ interface ShieldsTooltipEnumConstants { static final int VIDEO_ADS_BLOCKED_TOOLTIP = 1; static final int ADS_TRACKER_BLOCKED_TOOLTIP = 2; static final int HTTPS_UPGRADE_TOOLTIP = 3; - static final int BAP_DEPRECATION_TOOLTIP = 4; static final int BRAVE_SHARE_STATS_TIER1_TOOLTIP = 5; static final int BRAVE_SHARE_STATS_TIER2_TOOLTIP = 6; static final int BRAVE_SHARE_STATS_TIER3_TOOLTIP = 7; diff --git a/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayout.java b/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayout.java index 2a452dc0aafe..a30307c49f28 100644 --- a/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayout.java +++ b/android/java/org/chromium/chrome/browser/toolbar/top/BraveToolbarLayout.java @@ -159,7 +159,6 @@ public abstract class BraveToolbarLayout extends ToolbarLayout private boolean mIsInitialNotificationPosted; // initial red circle notification private PopupWindowTooltip mShieldsPopupWindowTooltip; - private PopupWindowTooltip mRewardsPopupWindowTooltip; private boolean mIsBottomToolbarVisible; @@ -374,8 +373,7 @@ public void onPageLoadFinished(final Tab tab, GURL url) { OnboardingPrefManager.getInstance().setTimeSavedNotificationStarted(true); } if (mBraveShieldsButton != null && mBraveShieldsButton.isShown() - && mBraveShieldsHandler != null && !mBraveShieldsHandler.isShowing() - && !isRewardsTooltipShown() && !isRewardsPanelOpened()) { + && mBraveShieldsHandler != null && !mBraveShieldsHandler.isShowing()) { checkForTooltip(tab); } } @@ -639,51 +637,6 @@ public void onClick(View view) { } } - public void showRewardsTooltip() { - ShieldsTooltipEnum shieldsTooltipEnum = ShieldsTooltipEnum.BAP_DEPRECATION_TOOLTIP; - mRewardsPopupWindowTooltip = new PopupWindowTooltip.Builder(getContext()) - .anchorView(mBraveRewardsButton) - .arrowColor(getContext().getResources().getColor( - shieldsTooltipEnum.getArrowColor())) - .gravity(Gravity.BOTTOM) - .dismissOnOutsideTouch(true) - .dismissOnInsideTouch(false) - .modal(true) - .contentView(R.layout.brave_shields_tooltip_layout) - .build(); - mRewardsPopupWindowTooltip.findViewById(R.id.shields_tooltip_layout) - .setBackgroundDrawable(ContextCompat.getDrawable( - getContext(), shieldsTooltipEnum.getTooltipBackground())); - - Button btnTooltip = mRewardsPopupWindowTooltip.findViewById(R.id.btn_tooltip); - btnTooltip.setText(getContext().getResources().getString(R.string.menu_learn_more)); - btnTooltip.setVisibility(View.VISIBLE); - btnTooltip.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - dismissRewardsTooltip(); - if (BraveActivity.getBraveActivity() != null) - BraveActivity.getBraveActivity().showDeprecateBAPDialog(); - } - }); - - TextView tooltipTitle = mRewardsPopupWindowTooltip.findViewById(R.id.txt_tooltip_title); - SpannableStringBuilder ssb = - new SpannableStringBuilder(new StringBuilder("\t\t") - .append(getContext().getResources().getString( - shieldsTooltipEnum.getTitle())) - .toString()); - ssb.setSpan(new ImageSpan( - getContext(), R.drawable.ic_warning_triangle, ImageSpan.ALIGN_BASELINE), - 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - tooltipTitle.setText(ssb, TextView.BufferType.SPANNABLE); - - TextView tooltipText = mRewardsPopupWindowTooltip.findViewById(R.id.txt_tooltip_text); - tooltipText.setText(getContext().getResources().getString(shieldsTooltipEnum.getText())); - - mRewardsPopupWindowTooltip.show(); - } - public void dismissShieldsTooltip() { if (mShieldsPopupWindowTooltip != null && mShieldsPopupWindowTooltip.isShowing()) { mShieldsPopupWindowTooltip.dismiss(); @@ -698,24 +651,9 @@ public void reopenShieldsPanel() { } } - public void dismissRewardsTooltip() { - if (mRewardsPopupWindowTooltip != null && mRewardsPopupWindowTooltip.isShowing()) { - mRewardsPopupWindowTooltip.dismiss(); - mRewardsPopupWindowTooltip = null; - } - } - - public boolean isRewardsTooltipShown() { - if (mRewardsPopupWindowTooltip != null) { - return mRewardsPopupWindowTooltip.isShowing(); - } - return false; - } - @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - dismissRewardsTooltip(); dismissShieldsTooltip(); reopenShieldsPanel(); } @@ -1133,13 +1071,6 @@ public void openRewardsPanel() { onClick(mBraveRewardsButton); } - public boolean isRewardsPanelOpened() { - if (mRewardsPopup != null) { - return mRewardsPopup.isShowing(); - } - return false; - } - public boolean isShieldsTooltipShown() { if (mShieldsPopupWindowTooltip != null) { return mShieldsPopupWindowTooltip.isShowing(); diff --git a/android/java/res/drawable/ic_warning_triangle.xml b/android/java/res/drawable/ic_warning_triangle.xml deleted file mode 100644 index bcb161fe6649..000000000000 --- a/android/java/res/drawable/ic_warning_triangle.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/android/java/res/drawable/ic_warning_triangle_2.xml b/android/java/res/drawable/ic_warning_triangle_2.xml deleted file mode 100644 index 9f37f31c82bf..000000000000 --- a/android/java/res/drawable/ic_warning_triangle_2.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/android/java/res/drawable/rewards_modal_background.xml b/android/java/res/drawable/rewards_modal_background.xml deleted file mode 100644 index 19d5431ed93a..000000000000 --- a/android/java/res/drawable/rewards_modal_background.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/android/java/res/drawable/rewards_tooltip_background.xml b/android/java/res/drawable/rewards_tooltip_background.xml deleted file mode 100644 index dc0e9b85ae63..000000000000 --- a/android/java/res/drawable/rewards_tooltip_background.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/android/java/res/layout/fragment_deprecate_bap_modal_dialog.xml b/android/java/res/layout/fragment_deprecate_bap_modal_dialog.xml deleted file mode 100644 index ece118f65625..000000000000 --- a/android/java/res/layout/fragment_deprecate_bap_modal_dialog.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - -