-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove //brave/components/brave_ads/browser check_includes = false
- Loading branch information
Showing
26 changed files
with
381 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_ads/ads_service_delegate.h" | ||
|
||
#include <utility> | ||
|
||
#include "brave/browser/brave_ads/ad_units/notification_ad/notification_ad_platform_bridge.h" | ||
#include "brave/browser/brave_ads/application_state/notification_helper/notification_helper.h" | ||
#include "brave/browser/ui/brave_ads/notification_ad.h" | ||
#include "brave/components/brave_adaptive_captcha/brave_adaptive_captcha_service.h" | ||
#include "build/build_config.h" | ||
#include "chrome/browser/notifications/notification_display_service.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#if BUILDFLAG(IS_ANDROID) | ||
#include "brave/browser/notifications/brave_notification_platform_bridge_helper_android.h" | ||
#include "chrome/browser/android/service_tab_launcher.h" | ||
#include "content/public/browser/page_navigator.h" | ||
#else | ||
#include "chrome/browser/fullscreen.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_finder.h" | ||
#include "chrome/browser/ui/browser_navigator.h" | ||
#endif | ||
|
||
namespace brave_ads { | ||
|
||
AdsServiceDelegate::AdsServiceDelegate( | ||
Profile* profile, | ||
brave_adaptive_captcha::BraveAdaptiveCaptchaService* | ||
adaptive_captcha_service, | ||
NotificationDisplayService* notification_display_service, | ||
std::unique_ptr<NotificationAdPlatformBridge> | ||
notification_ad_platform_bridge) | ||
: profile_(profile), | ||
adaptive_captcha_service_(adaptive_captcha_service), | ||
notification_display_service_(notification_display_service), | ||
notification_ad_platform_bridge_( | ||
std::move(notification_ad_platform_bridge)) {} | ||
|
||
AdsServiceDelegate::~AdsServiceDelegate() {} | ||
|
||
void AdsServiceDelegate::OpenNewTabWithUrl(const GURL& url) { | ||
#if BUILDFLAG(IS_ANDROID) | ||
// ServiceTabLauncher can currently only launch new tabs | ||
const content::OpenURLParams params(url, content::Referrer(), | ||
WindowOpenDisposition::NEW_FOREGROUND_TAB, | ||
ui::PAGE_TRANSITION_LINK, true); | ||
ServiceTabLauncher::GetInstance()->LaunchTab( | ||
profile_, params, base::BindOnce([](content::WebContents*) {})); | ||
#else | ||
Browser* browser = chrome::FindTabbedBrowser(profile_, false); | ||
if (!browser) { | ||
browser = Browser::Create(Browser::CreateParams(profile_, true)); | ||
} | ||
NavigateParams nav_params(browser, url, ui::PAGE_TRANSITION_LINK); | ||
nav_params.disposition = WindowOpenDisposition::SINGLETON_TAB; | ||
nav_params.window_action = NavigateParams::SHOW_WINDOW; | ||
nav_params.path_behavior = NavigateParams::RESPECT; | ||
Navigate(&nav_params); | ||
#endif | ||
} | ||
|
||
void AdsServiceDelegate::InitNotificationHelper() { | ||
NotificationHelper::GetInstance()->InitForProfile(profile_); | ||
} | ||
|
||
bool AdsServiceDelegate:: | ||
CanShowSystemNotificationsWhileBrowserIsBackgrounded() { | ||
return NotificationHelper::GetInstance() | ||
->CanShowSystemNotificationsWhileBrowserIsBackgrounded(); | ||
} | ||
|
||
bool AdsServiceDelegate::DoesSupportSystemNotifications() { | ||
return NotificationHelper::GetInstance()->DoesSupportSystemNotifications(); | ||
} | ||
|
||
bool AdsServiceDelegate::CanShowNotifications() { | ||
return NotificationHelper::GetInstance()->CanShowNotifications(); | ||
} | ||
|
||
bool AdsServiceDelegate::ShowOnboardingNotification() { | ||
return NotificationHelper::GetInstance()->ShowOnboardingNotification(); | ||
} | ||
|
||
void AdsServiceDelegate::ShowScheduledCaptcha(const std::string& payment_id, | ||
const std::string& captcha_id) { | ||
adaptive_captcha_service_->ShowScheduledCaptcha(payment_id, captcha_id); | ||
} | ||
|
||
void AdsServiceDelegate::ClearScheduledCaptcha() { | ||
adaptive_captcha_service_->ClearScheduledCaptcha(); | ||
} | ||
|
||
void AdsServiceDelegate::SnoozeScheduledCaptcha() { | ||
adaptive_captcha_service_->SnoozeScheduledCaptcha(); | ||
} | ||
|
||
void AdsServiceDelegate::Display( | ||
const message_center::Notification& notification) { | ||
notification_display_service_->Display(NotificationHandler::Type::BRAVE_ADS, | ||
notification, nullptr); | ||
} | ||
|
||
void AdsServiceDelegate::Close(const std::string& notification_id) { | ||
notification_display_service_->Close(NotificationHandler::Type::BRAVE_ADS, | ||
notification_id); | ||
} | ||
|
||
void AdsServiceDelegate::ShowNotificationAd(const std::string& id, | ||
const std::u16string& title, | ||
const std::u16string& body) { | ||
notification_ad_platform_bridge_->ShowNotificationAd( | ||
NotificationAd(id, title, body, nullptr)); | ||
} | ||
|
||
void AdsServiceDelegate::CloseNotificationAd(const std::string& id) { | ||
notification_ad_platform_bridge_->CloseNotificationAd(id); | ||
} | ||
|
||
#if BUILDFLAG(IS_ANDROID) | ||
void AdsServiceDelegate::MaybeRegenerateNotification( | ||
const std::string& notification_id, | ||
const GURL& service_worker_scope) { | ||
BraveNotificationPlatformBridgeHelperAndroid::MaybeRegenerateNotification( | ||
placement_id, url); | ||
} | ||
#else | ||
bool AdsServiceDelegate::IsFullScreenMode() { | ||
return ::IsFullScreenMode(); | ||
} | ||
#endif | ||
} // namespace brave_ads |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_DELEGATE_H_ | ||
#define BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_DELEGATE_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/brave_ads/browser/ads_service.h" | ||
|
||
class Profile; | ||
|
||
namespace brave_adaptive_captcha { | ||
class BraveAdaptiveCaptchaService; | ||
} | ||
|
||
class NotificationDisplayService; | ||
|
||
namespace brave_ads { | ||
|
||
class NotificationAdPlatformBridge; | ||
|
||
// Singleton that owns all AdsService and associates them with Profiles. | ||
class AdsServiceDelegate : public AdsService::Delegate { | ||
public: | ||
explicit AdsServiceDelegate( | ||
Profile* profile, | ||
brave_adaptive_captcha::BraveAdaptiveCaptchaService* | ||
adaptive_captcha_service, | ||
NotificationDisplayService* notification_display_service, | ||
std::unique_ptr<NotificationAdPlatformBridge> | ||
notification_ad_platform_bridge); | ||
~AdsServiceDelegate() override; | ||
AdsServiceDelegate(const AdsServiceDelegate&) = delete; | ||
AdsServiceDelegate& operator=(const AdsServiceDelegate&) = delete; | ||
|
||
AdsServiceDelegate(AdsServiceDelegate&&) noexcept = delete; | ||
AdsServiceDelegate& operator=(AdsServiceDelegate&&) noexcept = delete; | ||
|
||
// AdsService::Delegate implementation | ||
void InitNotificationHelper() override; | ||
bool CanShowSystemNotificationsWhileBrowserIsBackgrounded() override; | ||
bool DoesSupportSystemNotifications() override; | ||
bool CanShowNotifications() override; | ||
bool ShowOnboardingNotification() override; | ||
void ShowScheduledCaptcha(const std::string& payment_id, | ||
const std::string& captcha_id) override; | ||
void ClearScheduledCaptcha() override; | ||
void SnoozeScheduledCaptcha() override; | ||
void Display(const message_center::Notification& notification) override; | ||
void Close(const std::string& notification_id) override; | ||
void ShowNotificationAd(const std::string& id, | ||
const std::u16string& title, | ||
const std::u16string& body) override; | ||
void CloseNotificationAd(const std::string& id) override; | ||
void OpenNewTabWithUrl(const GURL& url) override; | ||
#if BUILDFLAG(IS_ANDROID) | ||
void MaybeRegenerateNotification(const std::string& notification_id, | ||
const GURL& service_worker_scope) override; | ||
#else | ||
bool IsFullScreenMode() override; | ||
#endif | ||
private: | ||
raw_ptr<Profile> profile_; | ||
raw_ptr<brave_adaptive_captcha::BraveAdaptiveCaptchaService> | ||
adaptive_captcha_service_; | ||
raw_ptr<NotificationDisplayService> notification_display_service_; | ||
std::unique_ptr<NotificationAdPlatformBridge> | ||
notification_ad_platform_bridge_; | ||
}; | ||
|
||
} // namespace brave_ads | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_ADS_ADS_SERVICE_DELEGATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.