Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Remove the Rewards extension #13191

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ if (is_android) {

if (is_mac) {
group("framework_bundle_data") {
deps = [
"components/brave_extension/extension/brave_extension:brave_extension_framework_bundle_data",
"components/brave_rewards/resources/extension:framework_bundle_data",
]
deps = [ "components/brave_extension/extension/brave_extension:brave_extension_framework_bundle_data" ]
}
}

Expand All @@ -145,7 +142,6 @@ group("unpacked_resources") {
if (enable_extensions) {
deps = [
"//brave/components/brave_extension/extension/brave_extension:locales",
"//brave/components/brave_rewards/resources/extension:locales",
]
}
}
Expand Down Expand Up @@ -250,7 +246,6 @@ if (!is_mac && !is_android && !is_ios) {
group("brave_extensions_locale_dist_resources") {
deps = [
"//brave/components/brave_extension/extension/brave_extension:locales",
"//brave/components/brave_rewards/resources/extension:locales",
]

public_deps = []
Expand All @@ -265,13 +260,6 @@ if (!is_mac && !is_android && !is_ios) {
}

foreach(locale, platform_pak_locales) {
copy("brave_rewards_locales_${locale}") {
deps = [ "//brave/components/brave_rewards/resources/extension:locales_$locale" ]

locale = string_replace(locale, "-", "_")
sources = [ "$root_out_dir/resources/brave_rewards/_locales/$locale/messages.json" ]
outputs = [ "$brave_dist_dir/resources/brave_rewards/_locales/$locale/{{source_file_part}}" ]
}
copy("brave_shields_locales_${locale}") {
deps = [ "//brave/components/brave_extension/extension/brave_extension:locales_$locale" ]

Expand Down
1 change: 1 addition & 0 deletions app/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ aggregate_vector_icons("brave_vector_icons") {
icon_directory = "."

sources = [
"bat.icon",
"brave_ads_close_button.icon",
"brave_ads_dark_mode_info_button.icon",
"brave_ads_light_mode_info_button.icon",
Expand Down
39 changes: 39 additions & 0 deletions app/vector_icons/bat.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
CANVAS_DIMENSIONS, 16,
PATH_COLOR_ARGB, 0xFF, 0xFF, 0x47, 0x24,
MOVE_TO, 0.03f, 14.56f,
R_LINE_TO, 4.68f, -2.75f,
LINE_TO, 7.94f, 6.15f,
V_LINE_TO, 0.69f,
R_CUBIC_TO, -0.09f, 0, -0.17f, 0.06f, -0.23f, 0.17f,
LINE_TO, 3.88f, 7.57f,
LINE_TO, 0.06f, 14.27f,
R_CUBIC_TO, -0.06f, 0.11f, -0.07f, 0.22f, -0.03f, 0.29f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0x9E, 0x1F, 0x63,
MOVE_TO, 7.94f, 0.69f,
V_LINE_TO, 6.15f,
R_LINE_TO, 3.23f, 5.66f,
R_LINE_TO, 4.68f, 2.75f,
R_CUBIC_TO, 0.04f, -0.07f, 0.04f, -0.18f, -0.03f, -0.29f,
R_LINE_TO, -3.83f, -6.7f,
LINE_TO, 8.18f, 0.86f,
R_CUBIC_TO, -0.06f, -0.11f, -0.15f, -0.17f, -0.23f, -0.17f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0x66, 0x2D, 0x91,
MOVE_TO, 15.85f, 14.56f,
R_LINE_TO, -4.68f, -2.75f,
H_LINE_TO, 4.71f,
LINE_TO, 0.03f, 14.56f,
R_CUBIC_TO, 0.04f, 0.08f, 0.13f, 0.12f, 0.26f, 0.12f,
H_LINE_TO, 15.59f,
R_CUBIC_TO, 0.13f, 0, 0.22f, -0.05f, 0.26f, -0.12f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0xFF, 0xFF, 0xFF,
MOVE_TO, 4.71f, 11.81f,
R_H_LINE_TO, 6.46f,
LINE_TO, 7.94f, 6.15f,
LINE_TO, 4.71f, 11.81f,
CLOSE
7 changes: 0 additions & 7 deletions brave_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ template("brave_extra_paks") {
]
}

if (enable_extensions) {
sources += [ "$root_gen_dir/brave/components/brave_rewards/resources/extension/brave_rewards_extension_resources.pak" ]

deps +=
[ "//brave/components/brave_rewards/resources/extension:resources" ]
}

if (defined(invoker.deps)) {
deps += invoker.deps
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <utility>

#include "base/memory/raw_ptr.h"
#include "brave/browser/brave_rewards/rewards_panel_helper.h"
#include "brave/browser/brave_rewards/rewards_panel_service.h"
#include "brave/browser/brave_rewards/rewards_panel_service_factory.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/components/brave_adaptive_captcha/brave_adaptive_captcha_service.h"
Expand All @@ -28,9 +29,14 @@ class CaptchaDelegate
explicit CaptchaDelegate(content::BrowserContext* context)
: context_(context) {}

bool ShowScheduledCaptcha(const std::string& payment_id,
void ShowScheduledCaptcha(const std::string& payment_id,
const std::string& captcha_id) override {
return brave_rewards::ShowRewardsPanel(context_, true);
auto* service = brave_rewards::RewardsPanelServiceFactory::GetForProfile(
Profile::FromBrowserContext(context_));

if (service) {
service->ShowAdaptiveCaptcha();
}
}

private:
Expand Down
78 changes: 15 additions & 63 deletions browser/brave_ads/brave_ads_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,21 @@

#include "brave/browser/brave_ads/brave_ads_host.h"

#include <memory>
#include <string>
#include <utility>

#include "brave/browser/brave_ads/ads_service_factory.h"
#include "brave/browser/brave_ads/search_result_ad/search_result_ad_service_factory.h"
#include "brave/browser/brave_rewards/rewards_panel_service_factory.h"
#include "brave/browser/brave_rewards/rewards_service_factory.h"
#include "brave/browser/extensions/api/brave_action_api.h"
#include "brave/browser/extensions/brave_component_loader.h"
#include "brave/components/brave_ads/browser/ads_service.h"
#include "brave/components/brave_ads/content/browser/search_result_ad/search_result_ad_service.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"

namespace brave_ads {

namespace {

constexpr char kAdsEnableRelativeUrl[] = "request_ads_enabled_panel.html";

} // namespace

BraveAdsHost::BraveAdsHost(Profile* profile, content::WebContents* web_contents)
: profile_(profile),
tab_id_(sessions::SessionTabHelper::IdForTab(web_contents)) {
Expand Down Expand Up @@ -69,9 +55,9 @@ void BraveAdsHost::RequestAdsEnabled(RequestAdsEnabledCallback callback) {
DCHECK(callback);

const AdsService* ads_service = AdsServiceFactory::GetForProfile(profile_);
brave_rewards::RewardsService* rewards_service =
brave_rewards::RewardsServiceFactory::GetForProfile(profile_);
if (!rewards_service || !ads_service || !ads_service->IsSupportedLocale()) {
auto* panel_service =
brave_rewards::RewardsPanelServiceFactory::GetForProfile(profile_);
if (!panel_service || !ads_service || !ads_service->IsSupportedLocale()) {
std::move(callback).Run(false);
return;
}
Expand All @@ -88,61 +74,27 @@ void BraveAdsHost::RequestAdsEnabled(RequestAdsEnabledCallback callback) {

callbacks_.push_back(std::move(callback));

rewards_service_observation_.Observe(rewards_service);
panel_observation_.Observe(panel_service);

if (!ShowRewardsPopup(rewards_service)) {
if (!panel_service->ShowBraveTalkOptIn()) {
RunCallbacksAndReset(false);
}
}

void BraveAdsHost::OnRequestAdsEnabledPopupClosed(bool ads_enabled) {
// If ads were enabled then do nothing and wait for ads enabled event.
if (!ads_enabled) {
RunCallbacksAndReset(false);
}
}

void BraveAdsHost::OnAdsEnabled(brave_rewards::RewardsService* rewards_service,
bool ads_enabled) {
DCHECK(rewards_service);

RunCallbacksAndReset(ads_enabled);
}

bool BraveAdsHost::ShowRewardsPopup(
brave_rewards::RewardsService* rewards_service) {
DCHECK(rewards_service);

Browser* browser = chrome::FindBrowserWithProfile(profile_);
DCHECK(browser);

auto* extension_service =
extensions::ExtensionSystem::Get(profile_)->extension_service();
if (!extension_service) {
return false;
}

extensions::BraveComponentLoader* component_loader =
static_cast<extensions::BraveComponentLoader*>(
extension_service->component_loader());
DCHECK(component_loader);

if (!component_loader->Exists(brave_rewards_extension_id)) {
component_loader->AddRewardsExtension();

rewards_service->StartProcess(base::DoNothing());
}

std::string error;
return extensions::BraveActionAPI::ShowActionUI(
browser, brave_rewards_extension_id,
std::make_unique<std::string>(kAdsEnableRelativeUrl), &error);
void BraveAdsHost::OnRewardsPanelClosed(Browser* browser) {
// TODO(zenparsing): Make sure that popup is not closed until after ads has
// been successfully enabled. We might not be able to ensure that. Also, do
// we want to listen again for "ads enabled" so that if they are enabled in
// some other way we can hear that? Ideally, enabling Ads should be
// synchronous (with perhaps asynchronous side-effects).
auto* ads_service = AdsServiceFactory::GetForProfile(profile_);
RunCallbacksAndReset(ads_service && ads_service->IsEnabled());
}

void BraveAdsHost::RunCallbacksAndReset(bool result) {
DCHECK(!callbacks_.empty());

rewards_service_observation_.Reset();
panel_observation_.Reset();

for (auto& callback : callbacks_) {
std::move(callback).Run(result);
Expand Down
16 changes: 5 additions & 11 deletions browser/brave_ads/brave_ads_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "brave/browser/brave_rewards/rewards_panel_service.h"
#include "brave/components/brave_ads/common/brave_ads_host.mojom.h"
#include "brave/components/brave_rewards/browser/rewards_service.h"
#include "brave/components/brave_rewards/browser/rewards_service_observer.h"
#include "components/sessions/core/session_id.h"

class Profile;
Expand All @@ -26,7 +25,7 @@ namespace brave_ads {

// The class handles ads requests from renderer side for Desktop platforms.
class BraveAdsHost : public brave_ads::mojom::BraveAdsHost,
public brave_rewards::RewardsServiceObserver {
public brave_rewards::RewardsPanelService::Observer {
public:
BraveAdsHost(Profile* profile, content::WebContents* web_contents);
BraveAdsHost(const BraveAdsHost&) = delete;
Expand All @@ -39,21 +38,16 @@ class BraveAdsHost : public brave_ads::mojom::BraveAdsHost,
MaybeTriggerAdViewedEventCallback callback) override;
void RequestAdsEnabled(RequestAdsEnabledCallback callback) override;

// brave_rewards::RewardsServiceObserver
void OnRequestAdsEnabledPopupClosed(bool ads_enabled) override;
void OnAdsEnabled(brave_rewards::RewardsService* rewards_service,
bool ads_enabled) override;
// brave_rewards::RewardsPanelService::Observer
void OnRewardsPanelClosed(Browser* browser) override;

private:
bool ShowRewardsPopup(brave_rewards::RewardsService* rewards_service);
void RunCallbacksAndReset(bool result);

raw_ptr<Profile> profile_ = nullptr;
SessionID tab_id_;
std::vector<RequestAdsEnabledCallback> callbacks_;
base::ScopedObservation<brave_rewards::RewardsService,
brave_rewards::RewardsServiceObserver>
rewards_service_observation_{this};
brave_rewards::RewardsPanelService::Observation panel_observation_{this};
};

} // namespace brave_ads
Expand Down
12 changes: 4 additions & 8 deletions browser/brave_ads/request_ads_enabled_api_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "brave/components/brave_rewards/browser/test/common/rewards_browsertest_util.h"
#include "brave/components/brave_rewards/common/pref_names.h"
#include "brave/components/constants/brave_paths.h"
#include "brave/components/constants/webui_url_constants.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
Expand All @@ -27,7 +28,6 @@
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "extensions/common/constants.h"
#include "net/dns/mock_host_resolver.h"

// npm run test -- brave_browser_tests --filter=RequestAdsEnabledApiTest*
Expand Down Expand Up @@ -119,13 +119,9 @@ class RequestAdsEnabledApiTestBase : public InProcessBrowserTest {
static_cast<const content::Source<content::WebContents>&>(source);
*popup_contents = web_contents_source.ptr();

// Check that this notification is for the Rewards panel and not, say,
// the extension background page.
std::string url = (*popup_contents)->GetLastCommittedURL().spec();
std::string rewards_panel_url = std::string("chrome-extension://") +
brave_rewards_extension_id +
"/request_ads_enabled_panel.html";
return url == rewards_panel_url;
// Check that this notification is for the Rewards panel.
std::string host = (*popup_contents)->GetLastCommittedURL().host();
return host == kBraveRewardsPanelHost;
};

content::WindowedNotificationObserver popup_observer(
Expand Down
4 changes: 4 additions & 0 deletions browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@ using extensions::ChromeContentBrowserClientExtensionsPart;
#include "brave/browser/new_tab/new_tab_shows_navigation_throttle.h"
#include "brave/browser/ui/webui/brave_federated/federated_internals.mojom.h"
#include "brave/browser/ui/webui/brave_federated/federated_internals_ui.h"
#include "brave/browser/ui/webui/brave_rewards/rewards_panel_ui.h"
#include "brave/browser/ui/webui/brave_shields/shields_panel_ui.h"
#include "brave/browser/ui/webui/brave_wallet/wallet_page_ui.h"
#include "brave/browser/ui/webui/brave_wallet/wallet_panel_ui.h"
#include "brave/browser/ui/webui/new_tab_page/brave_new_tab_ui.h"
#include "brave/components/brave_new_tab_ui/brave_new_tab_page.mojom.h"
#include "brave/components/brave_rewards/common/brave_rewards_panel.mojom.h"
#include "brave/components/brave_shields/common/brave_shields_panel.mojom.h"
#include "brave/components/brave_today/common/brave_news.mojom.h"
#include "brave/components/brave_today/common/features.h"
Expand Down Expand Up @@ -535,6 +537,8 @@ void BraveContentBrowserClient::RegisterBrowserInterfaceBindersForFrame(
chrome::internal::RegisterWebUIControllerInterfaceBinder<
brave_shields::mojom::PanelHandlerFactory, ShieldsPanelUI>(map);
}
chrome::internal::RegisterWebUIControllerInterfaceBinder<
brave_rewards::mojom::PanelHandlerFactory, RewardsPanelUI>(map);
if (base::FeatureList::IsEnabled(
brave_federated::features::kFederatedLearning)) {
chrome::internal::RegisterWebUIControllerInterfaceBinder<
Expand Down
Loading