-
Notifications
You must be signed in to change notification settings - Fork 885
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
[ads] Add search result ad clicked InfoBar #25393
Open
aseren
wants to merge
2
commits into
master
Choose a base branch
from
issues/39625
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+442
−41
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
101 changes: 101 additions & 0 deletions
101
...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,101 @@ | ||
/* 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 "build/build_config.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 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::make_unique<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 { | ||
#if BUILDFLAG(IS_ANDROID) | ||
return ui::ImageModel(); | ||
#else | ||
return ui::ImageModel::FromVectorIcon(vector_icons::kProductIcon, | ||
ui::kColorIcon, /*icon_size=*/20); | ||
#endif // BUILDFLAG(IS_ANDROID) | ||
} | ||
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowed a circular dependency from
search_result_ad
target.cc @bridiver