Skip to content

Commit

Permalink
[Kartoffel][Clank] Adjust when the consent is shown
Browse files Browse the repository at this point in the history
Bug: 1401730
Change-Id: Idaf753d3fa8a620902905b92d650d808928014c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4111052
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Nicola Tommasi <tommasin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084377}
  • Loading branch information
Nicola Tommasi authored and Chromium LUCI CQ committed Dec 16, 2022
1 parent 08cffed commit 9a081ad
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.chromium.chrome.browser.feed.NtpFeedSurfaceLifecycleManager;
import org.chromium.chrome.browser.feed.componentinterfaces.SurfaceCoordinator;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.LifecycleObserver;
import org.chromium.chrome.browser.lifecycle.PauseResumeWithNativeObserver;
Expand All @@ -58,8 +57,6 @@
import org.chromium.chrome.browser.omnibox.OmniboxStub;
import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler;
import org.chromium.chrome.browser.privacy.settings.PrivacyPreferencesManagerImpl;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxDialogController;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxDialogLaunchContext;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileKey;
import org.chromium.chrome.browser.query_tiles.QueryTileSection.QueryInfo;
Expand Down Expand Up @@ -783,16 +780,6 @@ private void recordNTPShown() {
mJankTracker.startTrackingScenario(JankScenario.NEW_TAB_PAGE);
SuggestionsMetrics.recordSurfaceVisible();

// TODO(https://crbug.com/1330704): Find a way to decouple this.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.PRIVACY_SANDBOX_SETTINGS_3)) {
// Once the NTP is loaded, launch the Privacy Sandbox prompt, if needed. This will only
// be displayed to the user one time.
PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(
PrivacySandboxDialogLaunchContext.NEW_TAB_PAGE, mContext, mSettingsLauncher,
/*isIncognito=*/false, // NTP is not displayed in incognito.
mBottomSheetController);
}

FeatureNotificationUtils.registerIPHCallback(FeatureType.VOICE_SEARCH,
mNewTabPageLayout::maybeShowFeatureNotificationVoiceSearchIPH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.price_tracking.PriceTrackingFeatures;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxDialogController;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxDialogLaunchContext;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.read_later.ReadLaterIPHController;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
Expand Down Expand Up @@ -675,17 +674,10 @@ private void initializeIPH(boolean intentWithEffect) {

if (ChromeFeatureList.isEnabled(ChromeFeatureList.PRIVACY_SANDBOX_SETTINGS_3)
|| ChromeFeatureList.isEnabled(ChromeFeatureList.PRIVACY_SANDBOX_SETTINGS_4)) {
// hasNewNoticeBeenShownInCurrentSession is needed to assure a PrivacySandbox promo
// already ran in this session, outside the initializeIPH promo logic (e.g. in a NTP
// page), and thus avoiding other different promos to run in the same session.
// NB: This logic holds as long as the Privacy Sandbox promo has the highest priority,
// we need to update the logic otherwise.
didTriggerPromo = PrivacySandboxDialogController.hasNewNoticeBeenShownInCurrentSession()
|| PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(
PrivacySandboxDialogLaunchContext.BROWSER_START, mActivity,
new SettingsLauncherImpl(),
mTabModelSelectorSupplier.get().isIncognitoSelected(),
getBottomSheetController());
didTriggerPromo = PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(
mActivity, new SettingsLauncherImpl(),
mTabModelSelectorSupplier.get().isIncognitoSelected(),
getBottomSheetController());
}

if (!didTriggerPromo) {
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/privacy_sandbox/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ android_library("java") {
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxBridge.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxDialogConsent.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxDialogController.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxDialogLaunchContext.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxDialogNotice.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxHelpers.java",
"java/src/org/chromium/chrome/browser/privacy_sandbox/PrivacySandboxReferrer.java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ public class PrivacySandboxDialogController {
private static Boolean sShowNew;
private static boolean sDisableAnimations;
private static boolean sDisableEEANoticeForTesting;
// TODO(crbug.com/1330704): This variable and its usage can be removed when the PrivacySandbox
// promo logic will be decoupled from the NewTabPage.
private static boolean sNewNoticeShownInCurrentSession;

/**
* Launches an appropriate dialog if necessary and returns whether that happened.
*/
public static boolean maybeLaunchPrivacySandboxDialog(
@PrivacySandboxDialogLaunchContext int launchContext, Context context,
public static boolean maybeLaunchPrivacySandboxDialog(Context context,
@NonNull SettingsLauncher settingsLauncher, boolean isIncognito,
@Nullable BottomSheetController bottomSheetController) {
if (isIncognito) {
Expand Down Expand Up @@ -66,7 +62,6 @@ public static boolean maybeLaunchPrivacySandboxDialog(
new PrivacySandboxBottomSheetNotice(
context, bottomSheetController, settingsLauncher)
.showNotice(/*animate=*/!sDisableAnimations);
sNewNoticeShownInCurrentSession = true;
return true;
case PromptType.CONSENT:
dialog = new PrivacySandboxDialogConsent(context);
Expand Down Expand Up @@ -99,13 +94,6 @@ static boolean showNewNotice() {
return (sShowNew != null) ? sShowNew : true;
}

/**
* Returns true if the new notice has already been shown in the current session.
*/
public static boolean hasNewNoticeBeenShownInCurrentSession() {
return sNewNoticeShownInCurrentSession;
}

@VisibleForTesting
static Dialog getDialogForTesting() {
return sDialog != null ? sDialog.get() : null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,12 @@ private void renderViewWithId(int id, String renderId) {
}

private void launchDialog() {
launchDialog(PrivacySandboxDialogLaunchContext.BROWSER_START);
}

private void launchDialog(@PrivacySandboxDialogLaunchContext int context) {
TestThreadUtils.runOnUiThreadBlocking(() -> {
if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
}
PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(context,
PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(
sActivityTestRule.getActivity(), mSettingsLauncher, /*isIncognito=*/false,
mBottomSheetController);
mDialog = PrivacySandboxDialogController.getDialogForTesting();
Expand Down Expand Up @@ -255,7 +251,6 @@ public void testRenderROWNotice() throws IOException {
public void testControllerIncognito() throws IOException {
TestThreadUtils.runOnUiThreadBlocking(() -> {
PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(
PrivacySandboxDialogLaunchContext.BROWSER_START,
sActivityTestRule.getActivity(), mSettingsLauncher, /*isIncognito=*/true,
mBottomSheetController);
});
Expand Down Expand Up @@ -312,7 +307,7 @@ public void testControllerShowsConsent() throws IOException {
public void testControllerShowsBottomSheet() {
PrivacySandboxDialogController.setShowNewNoticeForTesting(true);
mFakePrivacySandboxBridge.setRequiredPromptType(PromptType.NOTICE);
launchDialog(PrivacySandboxDialogLaunchContext.NEW_TAB_PAGE);
launchDialog();
// Verify that the notice is shown and the action is recorded.
onViewWaiting(withId(R.id.privacy_sandbox_notice_sheet_title));
onViewWaiting(withId(R.id.ack_button));
Expand All @@ -324,7 +319,7 @@ public void testControllerShowsBottomSheet() {
(int) mFakePrivacySandboxBridge.getLastPromptAction());
onView(withId(R.id.privacy_sandbox_notice_sheet_title)).check(doesNotExist());

launchDialog(PrivacySandboxDialogLaunchContext.NEW_TAB_PAGE);
launchDialog();
// Click on the settings button and verify it worked correctly.
onViewWaiting(withId(R.id.privacy_sandbox_notice_sheet_title));
onViewWaiting(withId(R.id.settings_button));
Expand All @@ -338,31 +333,17 @@ public void testControllerShowsBottomSheet() {
eq(ctx), eq(PrivacySandboxSettingsFragmentV3.class), any(Bundle.class));
}

@Test
@SmallTest
public void testControllerShowsNoticeInAnyContext() {
PrivacySandboxDialogController.setShowNewNoticeForTesting(true);
mFakePrivacySandboxBridge.setRequiredPromptType(PromptType.NOTICE);
launchDialog(PrivacySandboxDialogLaunchContext.BROWSER_START);
onView(withText(R.string.privacy_sandbox_notice_sheet_title)).check(matches(isDisplayed()));

PrivacySandboxDialogController.setShowNewNoticeForTesting(true);
mFakePrivacySandboxBridge.setRequiredPromptType(PromptType.NOTICE);
launchDialog(PrivacySandboxDialogLaunchContext.NEW_TAB_PAGE);
onView(withText(R.string.privacy_sandbox_notice_sheet_title)).check(matches(isDisplayed()));
}

@Test
@SmallTest
public void testControllerWontShowNoticeWhenNewNoticeIsDisabled() {
PrivacySandboxDialogController.setShowNewNoticeForTesting(false);
mFakePrivacySandboxBridge.setRequiredPromptType(PromptType.NOTICE);
launchDialog(PrivacySandboxDialogLaunchContext.BROWSER_START);
launchDialog();
onView(withText(R.string.privacy_sandbox_notice_sheet_title)).check(doesNotExist());

PrivacySandboxDialogController.setShowNewNoticeForTesting(false);
mFakePrivacySandboxBridge.setRequiredPromptType(PromptType.NOTICE);
launchDialog(PrivacySandboxDialogLaunchContext.NEW_TAB_PAGE);
launchDialog();
onView(withText(R.string.privacy_sandbox_notice_sheet_title)).check(doesNotExist());
}

Expand Down

0 comments on commit 9a081ad

Please sign in to comment.