Skip to content

Commit

Permalink
[PCCT-SideSheet] Use PCCT in discover feed settings
Browse files Browse the repository at this point in the history
-Include feature flag

(cherry picked from commit add35f1)

Bug: 1425232
Change-Id: I50833ccfd0be034055b18205c9334e81bbca734d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4347577
Commit-Queue: Zach Katz <katzz@google.com>
Reviewed-by: Justin DeWitt <dewittj@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Reviewed-by: Kevin Grosu <kgrosu@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1121881}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4375055
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/5672@{#57}
Cr-Branched-From: 5f2a724-refs/heads/main@{#1121455}
  • Loading branch information
Zach Katz authored and Chromium LUCI CQ committed Mar 27, 2023
1 parent cee2361 commit e80e285
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void cacheNativeFlags() {
ChromeFeatureList.sCctResizable90MaximumHeight,
ChromeFeatureList.sCctResizableForThirdParties,
ChromeFeatureList.sCctResizableSideSheet,
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings,
ChromeFeatureList.sCctResizableSideSheetForThirdParties,
ChromeFeatureList.sCctRetainableStateInMemory,
ChromeFeatureList.sCctToolbarCustomizations,
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6571,6 +6571,12 @@ const FeatureEntry kFeatureEntries[] = {
{"cct-resizable-side-sheet", flag_descriptions::kCCTResizableSideSheetName,
flag_descriptions::kCCTResizableSideSheetDescription, kOsAndroid,
FEATURE_VALUE_TYPE(chrome::android::kCCTResizableSideSheet)},
{"cct-resizable-side-sheet-discover-feed-settings",
flag_descriptions::kCCTResizableSideSheetDiscoverFeedSettingsName,
flag_descriptions::kCCTResizableSideSheetDiscoverFeedSettingsDescription,
kOsAndroid,
FEATURE_VALUE_TYPE(
chrome::android::kCCTResizableSideSheetDiscoverFeedSettings)},
{"cct-resizable-side-sheet-for-third-parties",
flag_descriptions::kCCTResizableSideSheetForThirdPartiesName,
flag_descriptions::kCCTResizableSideSheetForThirdPartiesDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
import android.view.View.OnClickListener;

import androidx.annotation.VisibleForTesting;
import androidx.browser.customtabs.CustomTabsClient;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.CustomTabsSession;

import org.chromium.base.Log;
import org.chromium.base.compat.ApiHelperForM;
import org.chromium.chrome.browser.feed.FeedServiceBridge;
import org.chromium.chrome.browser.feed.R;
import org.chromium.chrome.browser.feed.StreamKind;
import org.chromium.chrome.browser.feed.v2.FeedUserActionType;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.ui.modelutil.MVCListAdapter.ModelList;
import org.chromium.ui.modelutil.ModelListAdapter;
import org.chromium.ui.modelutil.PropertyModel;
Expand All @@ -41,6 +44,8 @@ public class FeedManagementMediator {
private final FollowManagementLauncher mFollowManagementLauncher;
private final AutoplayManagementLauncher mAutoplayManagementLauncher;
private final @StreamKind int mInitiatingStreamKind;
private CustomTabsClient mClient;
private CustomTabsSession mCustomTabsSession;

/**
* Interface to supply a method which can launch the FollowManagementActivity.
Expand Down Expand Up @@ -103,25 +108,51 @@ private PropertyModel generateListItem(

// TODO(petewil): Borrowed these from code we can't link to. How do I keep them in sync?
static final String TRUSTED_APPLICATION_CODE_EXTRA = "trusted_application_code_extra";
// TODO(katzz): Replace with intent extras to be defined in AndroidX;
static final String EXTRA_ACTIVITY_INITIAL_WIDTH_PX =
"androidx.browser.customtabs.extra.INITIAL_ACTIVITY_WIDTH_PX";
static final String EXTRA_ACTIVITY_INITIAL_HEIGHT_PX =
"androidx.browser.customtabs.extra.INITIAL_ACTIVITY_HEIGHT_PX";
static final String EXTRA_ACTIVITY_SIDE_SHEET_BREAKPOINT_DP =
"androidx.browser.customtabs.extra.ACTIVITY_SIDE_SHEET_BREAKPOINT_DP";

// Launch a new activity in the same task with the given uri as a CCT.
private void launchUriActivity(String uri) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setShowTitle(true);
builder.setShareState(CustomTabsIntent.SHARE_STATE_ON);
Intent intent = builder.build().intent;
intent.setData(Uri.parse(uri));
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName(mContext, "org.chromium.chrome.browser.customtabs.CustomTabActivity");

// Do the things that createCustomTabActivityIntent does:
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Needed for pre-N versions of android.
intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());

// Adding trusted extras lets us know that the intent came from Chrome.
intent.setPackage(mContext.getPackageName());
intent.putExtra(TRUSTED_APPLICATION_CODE_EXTRA, getAuthenticationToken());
mContext.startActivity(intent);
if (ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.isEnabled()) {
int displayHeight = mContext.getResources().getDisplayMetrics().heightPixels;
int displayWidth = mContext.getResources().getDisplayMetrics().widthPixels;
int initialHeight = Math.max(displayHeight, displayWidth);
int initialWidth = Math.max(displayHeight, displayWidth) / 2;
int breakPoint = (int) (Math.min(displayHeight, displayWidth)
/ mContext.getResources().getDisplayMetrics().density
+ 1);

CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setPackage(mContext.getPackageName());
// Adding trusted extras lets us know that the intent came from Chrome.
customTabsIntent.intent.putExtra(
TRUSTED_APPLICATION_CODE_EXTRA, getAuthenticationToken());
customTabsIntent.intent.setData(Uri.parse(uri));
customTabsIntent.intent.putExtra(EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, initialHeight);
customTabsIntent.intent.putExtra(EXTRA_ACTIVITY_INITIAL_WIDTH_PX, initialWidth);
customTabsIntent.intent.putExtra(EXTRA_ACTIVITY_SIDE_SHEET_BREAKPOINT_DP, breakPoint);
customTabsIntent.launchUrl(mContext, Uri.parse(uri));
} else {
Intent intent = builder.build().intent;
intent.setPackage(mContext.getPackageName());
// Adding trusted extras lets us know that the intent came from Chrome.
intent.putExtra(TRUSTED_APPLICATION_CODE_EXTRA, getAuthenticationToken());
intent.setData(Uri.parse(uri));
intent.setAction(Intent.ACTION_VIEW);
intent.setClassName(
mContext, "org.chromium.chrome.browser.customtabs.CustomTabActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Needed for pre-N versions of android.
intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
mContext.startActivity(intent);
}
// TODO(https://crbug.com/1195209): Record uma by calling ReportOtherUserAction
// on the stream.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.chromium.chrome.browser.feed.feedmanagement;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.verify;

import android.app.Activity;
Expand All @@ -27,6 +28,7 @@
import org.chromium.chrome.browser.feed.FeedServiceBridgeJni;
import org.chromium.chrome.browser.feed.StreamKind;
import org.chromium.chrome.browser.feed.v2.FeedUserActionType;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.ui.modelutil.MVCListAdapter.ModelList;

/**
Expand Down Expand Up @@ -67,41 +69,112 @@ public void setUpTest() {
}

@Test
public void testHandleActivityClick() {
public void testHandleActivityClick_FlagDisabled() {
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.setForTesting(false);
// Act
mFeedManagementMediator.handleActivityClick(null);

// Assert
Intent intent = mShadowActivity.peekNextStartedActivityForResult().intent;
assertEquals(
intent.getData(), Uri.parse("https://myactivity.google.com/myactivity?product=50"));
assertEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_WIDTH_PX, 0));
assertEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, 0));
verify(mFeedServiceBridgeJniMock)
.reportOtherUserAction(TEST_STREAM_KIND, FeedUserActionType.TAPPED_MANAGE_ACTIVITY);
}

@Test
public void testHandleActivityClick_FlagEnabled() {
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.setForTesting(true);
// Act
mFeedManagementMediator.handleActivityClick(null);

// Assert
Intent intent = mShadowActivity.peekNextStartedActivityForResult().intent;
assertEquals(
intent.getData(), Uri.parse("https://myactivity.google.com/myactivity?product=50"));
assertNotEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_WIDTH_PX, 0));
assertNotEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, 0));
verify(mFeedServiceBridgeJniMock)
.reportOtherUserAction(TEST_STREAM_KIND, FeedUserActionType.TAPPED_MANAGE_ACTIVITY);
}

@Test
public void testHandleInterestsClick() {
public void testHandleInterestsClick_FlagDisabled() {
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.setForTesting(false);
// Act
mFeedManagementMediator.handleInterestsClick(null);

// Assert
Intent intent = mShadowActivity.peekNextStartedActivityForResult().intent;
assertEquals(intent.getData(),
Uri.parse("https://www.google.com/preferences/interests/yourinterests?sh=n"));
assertEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_WIDTH_PX, 0));
assertEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, 0));
verify(mFeedServiceBridgeJniMock)
.reportOtherUserAction(
TEST_STREAM_KIND, FeedUserActionType.TAPPED_MANAGE_INTERESTS);
}

@Test
public void testHandleInterestsClick_FlagEnabled() {
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.setForTesting(true);
// Act
mFeedManagementMediator.handleInterestsClick(null);

// Assert
Intent intent = mShadowActivity.peekNextStartedActivityForResult().intent;
assertEquals(intent.getData(),
Uri.parse("https://www.google.com/preferences/interests/yourinterests?sh=n"));
assertNotEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_WIDTH_PX, 0));
assertNotEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, 0));
verify(mFeedServiceBridgeJniMock)
.reportOtherUserAction(
TEST_STREAM_KIND, FeedUserActionType.TAPPED_MANAGE_INTERESTS);
}

@Test
public void testHandleHiddenClick_FlagDisabled() {
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.setForTesting(false);
// Act
mFeedManagementMediator.handleHiddenClick(null);

// Assert
Intent intent = mShadowActivity.peekNextStartedActivityForResult().intent;
assertEquals(intent.getData(),
Uri.parse("https://www.google.com/preferences/interests/hidden?sh=n"));
assertEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_WIDTH_PX, 0));
assertEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, 0));
verify(mFeedServiceBridgeJniMock)
.reportOtherUserAction(
TEST_STREAM_KIND, FeedUserActionType.TAPPED_MANAGE_INTERESTS);
}

@Test
public void testHandleHiddenClick() {
public void testHandleHiddenClick_FlagEnabled() {
ChromeFeatureList.sCctResizableSideSheetDiscoverFeedSettings.setForTesting(true);
// Act
mFeedManagementMediator.handleHiddenClick(null);

// Assert
Intent intent = mShadowActivity.peekNextStartedActivityForResult().intent;
assertEquals(intent.getData(),
Uri.parse("https://www.google.com/preferences/interests/hidden?sh=n"));
assertNotEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_WIDTH_PX, 0));
assertNotEquals(
0, intent.getIntExtra(FeedManagementMediator.EXTRA_ACTIVITY_INITIAL_HEIGHT_PX, 0));
verify(mFeedServiceBridgeJniMock)
.reportOtherUserAction(
TEST_STREAM_KIND, FeedUserActionType.TAPPED_MANAGE_INTERESTS);
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/flag-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,11 @@
"owners": ["kgrosu", "jinsukkim", "twellington"],
"expiry_milestone": 121
},
{
"name": "cct-resizable-side-sheet-discover-feed-settings",
"owners": ["katzz", "kgrosu", "jinsukkim"],
"expiry_milestone": 130
},
{
"name": "cct-resizable-side-sheet-for-third-parties",
"owners": ["katzz", "kgrosu", "jinsukkim"],
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3619,6 +3619,10 @@ const char kCCTResizableForThirdPartiesDescription[] =
const char kCCTResizableSideSheetName[] = "Side sheet Custom Tabs";
const char kCCTResizableSideSheetDescription[] =
"Enable side sheet Custom Tabs";
const char kCCTResizableSideSheetDiscoverFeedSettingsName[] =
"Discover feed settings Partial Custom Tab";
const char kCCTResizableSideSheetDiscoverFeedSettingsDescription[] =
"Enable discover feed settings Partial Custom Tabs";
const char kCCTResizableSideSheetForThirdPartiesName[] =
"Side sheet Custom Tabs (third party)";
const char kCCTResizableSideSheetForThirdPartiesDescription[] =
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,8 @@ extern const char kCCTResizableForThirdPartiesName[];
extern const char kCCTResizableForThirdPartiesDescription[];
extern const char kCCTResizableSideSheetName[];
extern const char kCCTResizableSideSheetDescription[];
extern const char kCCTResizableSideSheetDiscoverFeedSettingsName[];
extern const char kCCTResizableSideSheetDiscoverFeedSettingsDescription[];
extern const char kCCTResizableSideSheetForThirdPartiesName[];
extern const char kCCTResizableSideSheetForThirdPartiesDescription[];

Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/flags/android/chrome_feature_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const base::Feature* const kFeaturesExposedToJava[] = {
&kCCTResizable90MaximumHeight,
&kCCTResizableForThirdParties,
&kCCTResizableSideSheet,
&kCCTResizableSideSheetDiscoverFeedSettings,
&kCCTResizableSideSheetForThirdParties,
&kCCTRetainingStateInMemory,
&kCCTResourcePrefetch,
Expand Down Expand Up @@ -608,6 +609,10 @@ BASE_FEATURE(kCCTResizableSideSheet,
"CCTResizableSideSheet",
base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kCCTResizableSideSheetDiscoverFeedSettings,
"CCTResizableSideSheetDiscoverFeedSettings",
base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kCCTResizableSideSheetForThirdParties,
"CCTResizableSideSheetForThirdParties",
base::FEATURE_DISABLED_BY_DEFAULT);
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/flags/android/chrome_feature_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ BASE_DECLARE_FEATURE(kCCTReportParallelRequestStatus);
BASE_DECLARE_FEATURE(kCCTResizable90MaximumHeight);
BASE_DECLARE_FEATURE(kCCTResizableForThirdParties);
BASE_DECLARE_FEATURE(kCCTResizableSideSheet);
BASE_DECLARE_FEATURE(kCCTResizableSideSheetDiscoverFeedSettings);
BASE_DECLARE_FEATURE(kCCTResizableSideSheetForThirdParties);
BASE_DECLARE_FEATURE(kCCTResourcePrefetch);
BASE_DECLARE_FEATURE(kCCTRetainingStateInMemory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public static boolean getFieldTrialParamByFeatureAsBoolean(
"CCTResizableAllowResizeByUserGesture";
public static final String CCT_RESIZABLE_FOR_THIRD_PARTIES = "CCTResizableForThirdParties";
public static final String CCT_RESIZABLE_SIDE_SHEET = "CCTResizableSideSheet";
public static final String CCT_RESIZABLE_SIDE_SHEET_DISCOVER_FEED_SETTINGS =
"CCTResizableSideSheetDiscoverFeedSettings";
public static final String CCT_RESIZABLE_SIDE_SHEET_FOR_THIRD_PARTIES =
"CCTResizableSideSheetForThirdParties";
public static final String CCT_RESOURCE_PREFETCH = "CCTResourcePrefetch";
Expand Down Expand Up @@ -602,6 +604,8 @@ public static boolean getFieldTrialParamByFeatureAsBoolean(
new CachedFlag(CCT_RESIZABLE_FOR_THIRD_PARTIES, true);
public static final CachedFlag sCctResizableSideSheet =
new CachedFlag(CCT_RESIZABLE_SIDE_SHEET, false);
public static final CachedFlag sCctResizableSideSheetDiscoverFeedSettings =
new CachedFlag(CCT_RESIZABLE_SIDE_SHEET_DISCOVER_FEED_SETTINGS, false);
public static final CachedFlag sCctResizableSideSheetForThirdParties =
new CachedFlag(CCT_RESIZABLE_SIDE_SHEET_FOR_THIRD_PARTIES, false);
public static final CachedFlag sCctRetainableStateInMemory =
Expand Down
4 changes: 4 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64622,6 +64622,8 @@ from previous Chrome versions.
<int value="1249861983" label="WebViewUseMetricsUploadService:disabled"/>
<int value="1250071868" label="disable-timezone-tracking-option"/>
<int value="1250776846" label="DnsProxyEnableDOH:enabled"/>
<int value="1251097300"
label="CCTResizableSideSheetDiscoverFeedSettings:enabled"/>
<int value="1251663392" label="ArcImageCopyPasteCompat:disabled"/>
<int value="1253001092" label="FeedShare:enabled"/>
<int value="1253698118" label="ash-disable-stable-overview-order"/>
Expand Down Expand Up @@ -65360,6 +65362,8 @@ from previous Chrome versions.
<int value="1667584730" label="WebXR:disabled"/>
<int value="1667886516"
label="PageInfoAboutThisSiteImprovedBottomSheet:enabled"/>
<int value="1667943654"
label="CCTResizableSideSheetDiscoverFeedSettings:disabled"/>
<int value="1668006393"
label="AutofillShowAutocompleteDeleteButton:disabled"/>
<int value="1668611601" label="enable-encrypted-media"/>
Expand Down

0 comments on commit e80e285

Please sign in to comment.