[ads] NTT reporting infobar notice (#28203)

This commit is contained in:
aseren
2025-04-25 12:01:33 -05:00
committed by GitHub
parent e357bd5d3f
commit faeca0afd9
30 changed files with 757 additions and 147 deletions
@@ -17,7 +17,8 @@ import java.lang.annotation.RetentionPolicy;
BraveInfoBarIdentifier.BRAVE_CONFIRM_P3A_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.SYNC_CANNOT_RUN_INFOBAR,
BraveInfoBarIdentifier.WEB_DISCOVERY_INFOBAR_DELEGATE,
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR
BraveInfoBarIdentifier.BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR,
BraveInfoBarIdentifier.NEW_TAB_TAKEOVER_INFOBAR_DELEGATE
})
@Retention(RetentionPolicy.SOURCE)
public @interface BraveInfoBarIdentifier {
@@ -29,4 +30,5 @@ public @interface BraveInfoBarIdentifier {
int SYNC_CANNOT_RUN_INFOBAR = 505;
int WEB_DISCOVERY_INFOBAR_DELEGATE = 506;
int BRAVE_SYNC_ACCOUNT_DELETED_INFOBAR = 507;
int NEW_TAB_TAKEOVER_INFOBAR_DELEGATE = 511;
}
@@ -1243,6 +1243,8 @@ public class BraveNewTabPageLayout
if (mNtpAdapter != null) {
mNtpAdapter.setNtpImage(ntpImage);
}
boolean wasWallpaperShown = true;
if (ntpImage instanceof Wallpaper && ((Wallpaper) ntpImage).isRichMedia()) {
setupSponsoredBackgroundContent();
} else if (ntpImage instanceof Wallpaper
@@ -1255,6 +1257,13 @@ public class BraveNewTabPageLayout
&& mSponsoredTab != null
&& NTPImageUtil.shouldEnableNTPFeature()) {
setBackgroundImage(ntpImage);
} else {
wasWallpaperShown = false;
}
if (wasWallpaperShown && ntpImage instanceof Wallpaper) {
BraveNewTabTakeoverInfobar infobar = new BraveNewTabTakeoverInfobar(mProfile);
infobar.maybeCreate();
}
}
@@ -0,0 +1,93 @@
/* Copyright (c) 2025 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/. */
package org.chromium.chrome.browser.ntp;
import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.infobar.BraveInfoBarIdentifier;
import org.chromium.chrome.browser.preferences.BravePref;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.ui.messages.infobar.BraveSimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.ui.messages.infobar.SimpleConfirmInfoBarBuilder;
import org.chromium.chrome.browser.util.TabUtils;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
public class BraveNewTabTakeoverInfobar {
private static final String TAG = "NewTabTakeover";
private static final String LEARN_MORE_URL =
"https://support.brave.com/hc/en-us/articles/35182999599501";
private final Profile mProfile;
public BraveNewTabTakeoverInfobar(Profile profile) {
mProfile = profile;
}
public void maybeCreate() {
try {
if (!shouldShowInfobar()) {
return;
}
recordInfobarWasShown();
BraveActivity activity = BraveActivity.getBraveActivity();
Tab tab = activity.getActivityTabProvider().get();
if (tab == null) return;
BraveSimpleConfirmInfoBarBuilder.create(
tab.getWebContents(),
new SimpleConfirmInfoBarBuilder.Listener() {
@Override
public void onInfoBarDismissed() {}
@Override
public boolean onInfoBarButtonClicked(boolean isPrimary) {
suppressInfobar();
return false;
}
@Override
public boolean onInfoBarLinkClicked() {
suppressInfobar();
TabUtils.openUrlInSameTab(LEARN_MORE_URL);
return true;
}
},
BraveInfoBarIdentifier.NEW_TAB_TAKEOVER_INFOBAR_DELEGATE,
activity,
/* drawableId= */ 0,
activity.getString(R.string.new_tab_takeover_infobar_message, ""),
/* primaryText= */ "",
/* secondaryText= */ "",
activity.getString(
R.string.new_tab_takeover_infobar_learn_more_opt_out_choices, ""),
/* autoExpire= */ true);
} catch (BraveActivity.BraveActivityNotFoundException e) {
Log.e(TAG, "maybeCreate infobar", e);
}
}
private boolean shouldShowInfobar() {
PrefService prefService = UserPrefs.get(mProfile);
final int infobarShowCount =
prefService.getInteger(BravePref.NEW_TAB_TAKEOVER_INFOBAR_SHOW_COUNT);
return infobarShowCount > 0;
}
private void recordInfobarWasShown() {
PrefService prefService = UserPrefs.get(mProfile);
final int infobarShowCount =
prefService.getInteger(BravePref.NEW_TAB_TAKEOVER_INFOBAR_SHOW_COUNT);
prefService.setInteger(BravePref.NEW_TAB_TAKEOVER_INFOBAR_SHOW_COUNT, infobarShowCount - 1);
}
private void suppressInfobar() {
PrefService prefService = UserPrefs.get(mProfile);
prefService.setInteger(BravePref.NEW_TAB_TAKEOVER_INFOBAR_SHOW_COUNT, 0);
}
}