-
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
- Loading branch information
Showing
21 changed files
with
436 additions
and
36 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
99 changes: 99 additions & 0 deletions
99
...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,99 @@ | ||
/* 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/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 "ui/base/models/image_model.h" | ||
#include "url/gurl.h" | ||
|
||
namespace brave_ads { | ||
|
||
namespace { | ||
|
||
constexpr int kIconSize = 20; | ||
|
||
constexpr char kLearnMoreUrl[] = | ||
"https://search.brave.com/help/conversion-reporting"; | ||
|
||
} // namespace | ||
|
||
// static | ||
void CreativeSearchResultAdClickedInfoBarDelegate::Create( | ||
content::WebContents* web_contents, | ||
PrefService* prefs) { | ||
CHECK(web_contents); | ||
CHECK(prefs); | ||
|
||
if (!prefs->GetBoolean(prefs::kShouldShowSearchResultAdClickedInfoBar)) { | ||
return; | ||
} | ||
prefs->SetBoolean(prefs::kShouldShowSearchResultAdClickedInfoBar, false); | ||
|
||
infobars::ContentInfoBarManager* infobar_manager = | ||
infobars::ContentInfoBarManager::FromWebContents(web_contents); | ||
if (!infobar_manager) { | ||
return; | ||
} | ||
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; | ||
} | ||
|
||
ui::ImageModel CreativeSearchResultAdClickedInfoBarDelegate::GetIcon() const { | ||
return ui::ImageModel::FromVectorIcon(vector_icons::kProductIcon, | ||
ui::kColorIcon, kIconSize); | ||
} | ||
|
||
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_BRAVE_ADS_SEARCH_RESULT_AD_LEARN_MORE_OPT_OUT_CHOICES_LABEL); | ||
} | ||
|
||
GURL CreativeSearchResultAdClickedInfoBarDelegate::GetLinkURL() const { | ||
return GURL(kLearnMoreUrl); | ||
} | ||
|
||
bool CreativeSearchResultAdClickedInfoBarDelegate::LinkClicked( | ||
WindowOpenDisposition disposition) { | ||
ConfirmInfoBarDelegate::LinkClicked(disposition); | ||
// Return true to immediately close the infobar. | ||
return true; | ||
} | ||
|
||
} // namespace brave_ads |
45 changes: 45 additions & 0 deletions
45
...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,45 @@ | ||
/* 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; | ||
ui::ImageModel GetIcon() const override; | ||
std::u16string GetMessageText() const override; | ||
int GetButtons() const override; | ||
std::u16string GetLinkText() const override; | ||
GURL GetLinkURL() const override; | ||
bool LinkClicked(WindowOpenDisposition disposition) 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
Oops, something went wrong.