-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ads] Add search result ad clicked InfoBar on desktop & android
- Loading branch information
Showing
13 changed files
with
281 additions
and
38 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
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
90 changes: 90 additions & 0 deletions
90
...rave_ads/creatives/search_result_ad/creative_search_result_ad_clicked_infobar_delegate.cc
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,90 @@ | ||
/* 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/creatives/search_result_ad/creative_search_result_ad_clicked_infobar_delegate.h" | ||
|
||
#include <memory> | ||
|
||
#include "brave/components/brave_ads/core/public/prefs/pref_names.h" | ||
#include "brave/components/vector_icons/vector_icons.h" | ||
#include "brave/grit/brave_generated_resources.h" | ||
#include "chrome/browser/infobars/confirm_infobar_creator.h" | ||
#include "components/infobars/content/content_infobar_manager.h" | ||
#include "components/infobars/core/infobar.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "components/strings/grit/components_strings.h" | ||
#include "components/vector_icons/vector_icons.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "url/gurl.h" | ||
|
||
namespace brave_ads { | ||
|
||
namespace { | ||
|
||
constexpr char kLearnMoreUrl[] = | ||
"https://support.brave.com/hc/en-us/articles/360026361072-Brave-Ads-FAQ"; | ||
|
||
} // namespace | ||
|
||
// static | ||
void CreativeSearchResultAdClickedInfoBarDelegate::Create( | ||
content::WebContents* web_contents, | ||
PrefService* prefs) { | ||
CHECK(web_contents); | ||
CHECK(prefs); | ||
|
||
infobars::ContentInfoBarManager* infobar_manager = | ||
infobars::ContentInfoBarManager::FromWebContents(web_contents); | ||
if (!infobar_manager) { | ||
return; | ||
} | ||
|
||
if (!prefs->GetBoolean(prefs::kShouldShowSearchResultAdClickedInfoBar)) { | ||
return; | ||
} | ||
prefs->SetBoolean(prefs::kShouldShowSearchResultAdClickedInfoBar, false); | ||
|
||
infobar_manager->AddInfoBar( | ||
CreateConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate>( | ||
new CreativeSearchResultAdClickedInfoBarDelegate()))); | ||
} | ||
|
||
CreativeSearchResultAdClickedInfoBarDelegate:: | ||
CreativeSearchResultAdClickedInfoBarDelegate() = default; | ||
|
||
CreativeSearchResultAdClickedInfoBarDelegate:: | ||
~CreativeSearchResultAdClickedInfoBarDelegate() = default; | ||
|
||
infobars::InfoBarDelegate::InfoBarIdentifier | ||
CreativeSearchResultAdClickedInfoBarDelegate::GetIdentifier() const { | ||
return SEARCH_RESULT_AD_CLICKED_INFOBAR_DELEGATE; | ||
} | ||
|
||
const gfx::VectorIcon& | ||
CreativeSearchResultAdClickedInfoBarDelegate::GetVectorIcon() const { | ||
return kLeoBraveIconMonochromeIcon; | ||
} | ||
|
||
std::u16string CreativeSearchResultAdClickedInfoBarDelegate::GetMessageText() | ||
const { | ||
return l10n_util::GetStringUTF16( | ||
IDS_BRAVE_ADS_SEARCH_RESULT_AD_CLICKED_INFOBAR_MESSAGE); | ||
} | ||
|
||
int CreativeSearchResultAdClickedInfoBarDelegate::GetButtons() const { | ||
return BUTTON_NONE; | ||
} | ||
|
||
std::u16string CreativeSearchResultAdClickedInfoBarDelegate::GetLinkText() | ||
const { | ||
return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | ||
} | ||
|
||
GURL CreativeSearchResultAdClickedInfoBarDelegate::GetLinkURL() const { | ||
return GURL(kLearnMoreUrl); | ||
} | ||
|
||
} // namespace brave_ads |
44 changes: 44 additions & 0 deletions
44
...brave_ads/creatives/search_result_ad/creative_search_result_ad_clicked_infobar_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* 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_CREATIVES_SEARCH_RESULT_AD_CREATIVE_SEARCH_RESULT_AD_CLICKED_INFOBAR_DELEGATE_H_ | ||
#define BRAVE_BROWSER_BRAVE_ADS_CREATIVES_SEARCH_RESULT_AD_CREATIVE_SEARCH_RESULT_AD_CLICKED_INFOBAR_DELEGATE_H_ | ||
|
||
#include "components/infobars/core/confirm_infobar_delegate.h" | ||
|
||
class PrefService; | ||
|
||
namespace content { | ||
class WebContents; | ||
} // namespace content | ||
|
||
namespace brave_ads { | ||
|
||
class CreativeSearchResultAdClickedInfoBarDelegate | ||
: public ConfirmInfoBarDelegate { | ||
public: | ||
CreativeSearchResultAdClickedInfoBarDelegate(); | ||
~CreativeSearchResultAdClickedInfoBarDelegate() override; | ||
|
||
CreativeSearchResultAdClickedInfoBarDelegate( | ||
const CreativeSearchResultAdClickedInfoBarDelegate&) = delete; | ||
CreativeSearchResultAdClickedInfoBarDelegate& operator=( | ||
const CreativeSearchResultAdClickedInfoBarDelegate&) = delete; | ||
|
||
static void Create(content::WebContents* web_contents, PrefService* prefs); | ||
|
||
private: | ||
// ConfirmInfoBarDelegate: | ||
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | ||
const gfx::VectorIcon& GetVectorIcon() const override; | ||
std::u16string GetMessageText() const override; | ||
int GetButtons() const override; | ||
std::u16string GetLinkText() const override; | ||
GURL GetLinkURL() const override; | ||
}; | ||
|
||
} // namespace brave_ads | ||
|
||
#endif // BRAVE_BROWSER_BRAVE_ADS_CREATIVES_SEARCH_RESULT_AD_CREATIVE_SEARCH_RESULT_AD_CLICKED_INFOBAR_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
Oops, something went wrong.