Commit 56d14ed0 authored by Scott Violet's avatar Scott Violet Committed by Chromium LUCI CQ

cct-incognito change

My intention is to merge this to 88.

This adds the following changes to cct:
1. context menu when in incognito mode no longer shows
   'open in chrome'. As the app menu explicitly doesn't show 'open in
   chrome' I'm assuming it's an over site that 'open in chrome' is
   shown in the context menu. If this isn't an over site, I can hide
   this behind the flag I previously added.
2. Makes it possible for first parties to use this regardless of the
   feature state if an extra is present. Reason for this is I plan to
   merge this to 88, in which the feature is disabled.
3. Makes it possible for colors to come from the intent. This is only
   enabled if an extra is present in the bundle and restricted to first
   parties.
4. Makes it possible for not show the incognito icon. This is only
   enabled if an extra is present in the bundle and restricted to first
   parties.

BUG=1157916
TEST=Various tests in CustomTabActivityIncognitoTest

Change-Id: I812f46e935dcae01b8d161893059ecf81c146522
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2582643
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarRohit Agarwal <roagarwal@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837117}
parent dcd2bb57
......@@ -428,6 +428,8 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/customtabs/CustomTabActivityLifecycleUmaTracker.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabBottomBarDelegate.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabColorProvider.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabColorProviderImpl.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabCompositorContentInitializer.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabDelegateFactory.java",
"java/src/org/chromium/chrome/browser/customtabs/CustomTabIncognitoManager.java",
......@@ -449,6 +451,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/customtabs/CustomTabsShareBroadcastReceiver.java",
"java/src/org/chromium/chrome/browser/customtabs/FirstMeaningfulPaintObserver.java",
"java/src/org/chromium/chrome/browser/customtabs/HiddenTabHolder.java",
"java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabColorProvider.java",
"java/src/org/chromium/chrome/browser/customtabs/IncognitoCustomTabIntentDataProvider.java",
"java/src/org/chromium/chrome/browser/customtabs/NavigationInfoCaptureTrigger.java",
"java/src/org/chromium/chrome/browser/customtabs/PageLoadMetricsObserver.java",
......
......@@ -532,4 +532,11 @@ public abstract class BrowserServicesIntentDataProvider {
public boolean shouldShowOpenInChromeMenuItem() {
return true;
}
/**
* @return Whether the incognito icon in the toolbar should be hidden in cct-incognito mode.
*/
public boolean shouldHideIncognitoIconOnToolbarInCct() {
return false;
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.customtabs;
import androidx.annotation.Nullable;
/**
* Provides the set of colors used by custom tabs.
*/
// TODO(sky): make BrowserServicesIntentDataProvider own this and move methods from
// BrowserServicesIntentDataProvider onto this.
public interface CustomTabColorProvider {
/**
* @return The color of the bottom bar.
*/
int getToolbarColor();
/**
* @return Whether the intent specifies a custom toolbar color.
*/
boolean hasCustomToolbarColor();
/**
* @return The navigation bar color specified in the intent, or null if not specified.
*/
@Nullable
Integer getNavigationBarColor();
/**
* @return The navigation bar divider color specified in the intent, or null if not specified.
*/
@Nullable
Integer getNavigationBarDividerColor();
/**
* @return The color of the bottom bar.
*/
int getBottomBarColor();
/**
* @return Initial RGB background color.
*/
int getInitialBackgroundColor();
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.customtabs;
import static androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT;
import static androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_SYSTEM;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
import org.chromium.base.IntentUtils;
import org.chromium.base.Log;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.ui.util.ColorUtils;
/**
* CustomTabColorProvider implementation used for normal profiles, in some cases incognito
* profiles.
*/
public final class CustomTabColorProviderImpl implements CustomTabColorProvider {
private static final String TAG = "CustomTabColorPrvdr";
private final boolean mHasCustomToolbarColor;
private final int mToolbarColor;
private final int mBottomBarColor;
@Nullable
private final Integer mNavigationBarColor;
@Nullable
private final Integer mNavigationBarDividerColor;
private final int mInitialBackgroundColor;
@NonNull
private static CustomTabColorSchemeParams getColorSchemeParams(Intent intent, int colorScheme) {
if (colorScheme == COLOR_SCHEME_SYSTEM) {
assert false : "Color scheme passed to IntentDataProvider should not be "
+ "COLOR_SCHEME_SYSTEM";
colorScheme = COLOR_SCHEME_LIGHT;
}
try {
return CustomTabsIntent.getColorSchemeParams(intent, colorScheme);
} catch (Throwable e) {
// Catch any un-parceling exceptions, like in IntentUtils#safe* methods
Log.e(TAG, "Failed to parse CustomTabColorSchemeParams");
return new CustomTabColorSchemeParams.Builder().build(); // Empty params
}
}
/**
* The colorScheme parameter specifies which color scheme the Custom Tab should use.
* It can currently be either {@link CustomTabsIntent#COLOR_SCHEME_LIGHT} or
* {@link CustomTabsIntent#COLOR_SCHEME_DARK}.
* If Custom Tab was launched with {@link CustomTabsIntent#COLOR_SCHEME_SYSTEM}, colorScheme
* must reflect the current system setting. When the system setting changes, a new
* CustomTabIntentDataProvider object must be created.
*/
public CustomTabColorProviderImpl(Intent intent, Context context, int colorScheme) {
assert intent != null;
assert context != null;
CustomTabColorSchemeParams params = getColorSchemeParams(intent, colorScheme);
mHasCustomToolbarColor = (params.toolbarColor != null);
mToolbarColor = retrieveToolbarColor(params, context, mHasCustomToolbarColor);
mBottomBarColor = retrieveBottomBarColor(params, mToolbarColor);
mNavigationBarColor = params.navigationBarColor == null
? null
: ColorUtils.getOpaqueColor(params.navigationBarColor);
mNavigationBarDividerColor = params.navigationBarDividerColor;
mInitialBackgroundColor = retrieveInitialBackgroundColor(intent);
}
/**
* Returns the color passed from the client app.
*/
private static int retrieveToolbarColor(CustomTabColorSchemeParams schemeParams,
Context context, boolean hasCustomToolbarColor) {
int defaultColor = ChromeColors.getDefaultThemeColor(
context.getResources(), /*forceDarkBgColor*/ false);
int color = hasCustomToolbarColor ? schemeParams.toolbarColor : defaultColor;
return ColorUtils.getOpaqueColor(color);
}
private static int retrieveBottomBarColor(
CustomTabColorSchemeParams schemeParams, int toolbarColor) {
int color = schemeParams.secondaryToolbarColor != null ? schemeParams.secondaryToolbarColor
: toolbarColor;
return ColorUtils.getOpaqueColor(color);
}
/**
* Returns the color to initialize the background of the Custom Tab with.
* If no valid color is set, Color.TRANSPARENT is returned.
*/
private static int retrieveInitialBackgroundColor(Intent intent) {
int defaultColor = Color.TRANSPARENT;
int color = IntentUtils.safeGetIntExtra(
intent, CustomTabIntentDataProvider.EXTRA_INITIAL_BACKGROUND_COLOR, defaultColor);
return color == Color.TRANSPARENT ? color : ColorUtils.getOpaqueColor(color);
}
@Override
public int getToolbarColor() {
return mToolbarColor;
}
@Override
public boolean hasCustomToolbarColor() {
return mHasCustomToolbarColor;
}
@Override
@Nullable
public Integer getNavigationBarColor() {
return mNavigationBarColor;
}
@Override
@Nullable
public Integer getNavigationBarDividerColor() {
return mNavigationBarDividerColor;
}
@Override
public int getBottomBarColor() {
return mBottomBarColor;
}
@Override
public int getInitialBackgroundColor() {
return mInitialBackgroundColor;
}
}
......@@ -475,13 +475,14 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
TabContextMenuItemDelegate createTabContextMenuItemDelegate(Tab tab) {
TabModelSelector tabModelSelector =
mActivity != null ? mActivity.getTabModelSelector() : null;
final boolean isIncognito = tab.isIncognito();
return new TabContextMenuItemDelegate(tab, tabModelSelector,
EphemeralTabCoordinator.isSupported() ? mEphemeralTabCoordinator::get : ()
-> null,
() -> {}, mActivity == null ? null : mActivity::getSnackbarManager) {
@Override
public boolean supportsOpenInChromeFromCct() {
return mShouldShowOpenInChromeMenuItemInContextMenu;
return mShouldShowOpenInChromeMenuItemInContextMenu && !isIncognito;
}
};
}
......
......@@ -4,15 +4,11 @@
package org.chromium.chrome.browser.customtabs;
import static androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_LIGHT;
import static androidx.browser.customtabs.CustomTabsIntent.COLOR_SCHEME_SYSTEM;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
......@@ -26,7 +22,6 @@ import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.browser.customtabs.CustomTabsSessionToken;
import androidx.browser.customtabs.TrustedWebUtils;
......@@ -49,11 +44,9 @@ import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.gsa.GSAState;
import org.chromium.chrome.browser.version.ChromeVersionInfo;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.TintedDrawable;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.device.mojom.ScreenOrientationLockType;
import org.chromium.ui.util.ColorUtils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
......@@ -225,24 +218,16 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
private final String mMediaViewerUrl;
private final boolean mEnableEmbeddedMediaExperience;
private final boolean mIsFromMediaLauncherActivity;
private final int mInitialBackgroundColor;
private final boolean mDisableStar;
private final boolean mDisableDownload;
private final @ActivityType int mActivityType;
@Nullable
private final Integer mNavigationBarColor;
@Nullable
private final Integer mNavigationBarDividerColor;
@Nullable
private final List<String> mTrustedWebActivityAdditionalOrigins;
@Nullable
private final TrustedWebActivityDisplayMode mTrustedWebActivityDisplayMode;
@Nullable
private String mUrlToLoad;
private boolean mHasCustomToolbarColor;
private int mToolbarColor;
private int mBottomBarColor;
private boolean mEnableUrlBarHiding;
private List<CustomButtonParams> mCustomButtonParams;
private Drawable mCloseButtonIcon;
......@@ -268,6 +253,9 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
@Nullable
private final int[] mGsaExperimentIds;
@NonNull
private final CustomTabColorProvider mColorProvider;
/**
* Add extras to customize menu items for opening Reader Mode UI custom tab from Chrome.
*/
......@@ -320,15 +308,9 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
IntentUtils.safeGetIntExtra(intent, EXTRA_UI_TYPE, CustomTabsUiType.DEFAULT);
mUiType = verifiedUiType(requestedUiType);
CustomTabColorSchemeParams params = getColorSchemeParams(intent, colorScheme);
mColorProvider = new CustomTabColorProviderImpl(intent, context, colorScheme);
retrieveCustomButtons(intent, context);
mToolbarColor = retrieveToolbarColor(params, context);
mBottomBarColor = retrieveBottomBarColor(params);
mNavigationBarColor = params.navigationBarColor == null
? null
: ColorUtils.getOpaqueColor(params.navigationBarColor);
mNavigationBarDividerColor = params.navigationBarDividerColor;
mInitialBackgroundColor = retrieveInitialBackgroundColor(intent);
mEnableUrlBarHiding = IntentUtils.safeGetBooleanExtra(
intent, CustomTabsIntent.EXTRA_ENABLE_URLBAR_HIDING, true);
......@@ -439,22 +421,6 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
return false;
}
@NonNull
private CustomTabColorSchemeParams getColorSchemeParams(Intent intent, int colorScheme) {
if (colorScheme == COLOR_SCHEME_SYSTEM) {
assert false : "Color scheme passed to IntentDataProvider should not be "
+ "COLOR_SCHEME_SYSTEM";
colorScheme = COLOR_SCHEME_LIGHT;
}
try {
return CustomTabsIntent.getColorSchemeParams(intent, colorScheme);
} catch (Throwable e) {
// Catch any un-parceling exceptions, like in IntentUtils#safe* methods
Log.e(TAG, "Failed to parse CustomTabColorSchemeParams");
return new CustomTabColorSchemeParams.Builder().build(); // Empty params
}
}
/**
* Get the verified UI type, according to the intent extras, and whether the intent is trusted.
* @param requestedUiType requested UI type in the intent, unqualified
......@@ -513,7 +479,8 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
&& CachedFeatureFlags.isEnabled(
ChromeFeatureList.SHARE_BY_DEFAULT_IN_CCT))) {
if (mToolbarButtons.isEmpty()) {
mToolbarButtons.add(CustomButtonParams.createShareButton(context, mToolbarColor));
mToolbarButtons.add(
CustomButtonParams.createShareButton(context, getToolbarColor()));
logShareOptionLocation(ShareOptionLocation.TOOLBAR);
} else if (mMenuEntries.isEmpty()) {
mShowShareItemInMenu = true;
......@@ -538,38 +505,6 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
shareOptionLocation, ShareOptionLocation.NUM_ENTRIES);
}
/**
* Returns the color passed from the client app.
*/
private int retrieveToolbarColor(CustomTabColorSchemeParams schemeParams, Context context) {
int defaultColor = ChromeColors.getDefaultThemeColor(
context.getResources(), /*forceDarkBgColor*/ false);
mHasCustomToolbarColor = (schemeParams.toolbarColor != null);
int color = mHasCustomToolbarColor ? schemeParams.toolbarColor : defaultColor;
return ColorUtils.getOpaqueColor(color);
}
/**
* Must be called after calling {@link #retrieveToolbarColor}.
*/
private int retrieveBottomBarColor(CustomTabColorSchemeParams schemeParams) {
int defaultColor = mToolbarColor;
int color = schemeParams.secondaryToolbarColor != null ? schemeParams.secondaryToolbarColor
: defaultColor;
return ColorUtils.getOpaqueColor(color);
}
/**
* Returns the color to initialize the background of the Custom Tab with.
* If no valid color is set, Color.TRANSPARENT is returned.
*/
private int retrieveInitialBackgroundColor(Intent intent) {
int defaultColor = Color.TRANSPARENT;
int color =
IntentUtils.safeGetIntExtra(intent, EXTRA_INITIAL_BACKGROUND_COLOR, defaultColor);
return color == Color.TRANSPARENT ? color : ColorUtils.getOpaqueColor(color);
}
private String resolveUrlToLoad(Intent intent) {
String url = IntentHandler.getUrlFromIntent(intent);
......@@ -706,24 +641,24 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
@Override
public int getToolbarColor() {
return mToolbarColor;
return mColorProvider.getToolbarColor();
}
@Override
public boolean hasCustomToolbarColor() {
return mHasCustomToolbarColor;
return mColorProvider.hasCustomToolbarColor();
}
@Override
@Nullable
public Integer getNavigationBarColor() {
return mNavigationBarColor;
return mColorProvider.getNavigationBarColor();
}
@Override
@Nullable
public Integer getNavigationBarDividerColor() {
return mNavigationBarDividerColor;
return mColorProvider.getNavigationBarDividerColor();
}
@Override
......@@ -754,7 +689,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
@Override
public int getBottomBarColor() {
return mBottomBarColor;
return mColorProvider.getBottomBarColor();
}
@Override
......@@ -831,7 +766,7 @@ public class CustomTabIntentDataProvider extends BrowserServicesIntentDataProvid
@Override
public int getInitialBackgroundColor() {
return mInitialBackgroundColor;
return mColorProvider.getInitialBackgroundColor();
}
@Override
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.customtabs;
import android.content.Context;
import android.graphics.Color;
import androidx.annotation.Nullable;
import org.chromium.components.browser_ui.styles.ChromeColors;
/**
* CustomTabColorProvider implementation used for normal provides, and some times incognito
* profiles.
*/
public final class IncognitoCustomTabColorProvider implements CustomTabColorProvider {
private final int mToolbarColor;
private final int mBottomBarColor;
private final int mNavigationBarColor;
public IncognitoCustomTabColorProvider(Context context) {
assert context != null;
mToolbarColor = mBottomBarColor = mNavigationBarColor = ChromeColors.getDefaultThemeColor(
context.getResources(), /*forceDarkBgColor*/ true);
}
@Override
public int getToolbarColor() {
return mToolbarColor;
}
@Override
public boolean hasCustomToolbarColor() {
return false;
}
@Override
@Nullable
public Integer getNavigationBarColor() {
return mNavigationBarColor;
}
@Override
@Nullable
public Integer getNavigationBarDividerColor() {
return null;
}
@Override
public int getBottomBarColor() {
return mBottomBarColor;
}
@Override
public int getInitialBackgroundColor() {
return Color.TRANSPARENT;
}
}
......@@ -31,7 +31,6 @@ import org.chromium.chrome.browser.browserservices.BrowserServicesIntentDataProv
import org.chromium.chrome.browser.flags.ActivityType;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.TintedDrawable;
import java.util.ArrayList;
......@@ -48,17 +47,29 @@ import java.util.List;
public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentDataProvider {
private static final int MAX_CUSTOM_MENU_ITEMS = 5;
// If set, the incognito icon is not shown. Only honored for first party requests.
public static final String EXTRA_HIDE_INCOGNITO_ICON =
"org.chromium.chrome.browser.customtabs.HIDE_INCOGNITO_ICON";
// If set, the colors match that of normal profiles. Only honored for first party requests.
public static final String EXTRA_USE_NORMAL_PROFILE_STYLE =
"org.chromium.chrome.browser.customtabs.USE_NORMAL_PROFILE_STYLE";
// If set, incognito is allowed regardless of the status of the feature. Only honored for first
// party requests.
public static final String EXTRA_FORCE_ENABLE_FOR_EXPERIMENT =
"org.chromium.chrome.browser.customtabs.FORCE_ENABLE_FOR_EXPERIMENT";
private final Intent mIntent;
private final CustomTabsSessionToken mSession;
private final boolean mIsTrustedIntent;
private final Bundle mAnimationBundle;
private final int mToolbarColor;
private final int mBottomBarColor;
private final int mNavigationBarColor;
private final CustomTabColorProvider mColorProvider;
private final int mTitleVisibilityState;
private final Drawable mCloseButtonIcon;
private final boolean mShowShareItem;
private final List<Pair<String, PendingIntent>> mMenuEntries = new ArrayList<>();
private final boolean mHideIncognitoIconOnToolbar;
@Nullable
private final String mUrlToLoad;
......@@ -70,7 +81,6 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
/**
* Constructs a {@link IncognitoCustomTabIntentDataProvider}.
* Incognito CCT would have a fix color scheme.
*/
public IncognitoCustomTabIntentDataProvider(Intent intent, Context context, int colorScheme) {
assert intent != null;
......@@ -82,12 +92,14 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
intent, CustomTabsIntent.EXTRA_EXIT_ANIMATION_BUNDLE);
mIsOpenedByChrome =
IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OPENED_BY_CHROME, false);
mToolbarColor = ChromeColors.getDefaultThemeColor(
context.getResources(), /*forceDarkBgColor*/ true);
mBottomBarColor = ChromeColors.getDefaultThemeColor(
context.getResources(), /*forceDarkBgColor*/ true);
mNavigationBarColor = ChromeColors.getDefaultThemeColor(
context.getResources(), /*forceDarkBgColor*/ true);
// Only allow first-parties to change the styling.
final boolean useNormalProfileColors = isIntentFromFirstParty(intent)
&& IntentUtils.safeGetBooleanExtra(intent, EXTRA_USE_NORMAL_PROFILE_STYLE, false);
mColorProvider = useNormalProfileColors
? new CustomTabColorProviderImpl(intent, context, colorScheme)
: new IncognitoCustomTabColorProvider(context);
mHideIncognitoIconOnToolbar = isIntentFromFirstParty(intent)
&& IntentUtils.safeGetBooleanExtra(intent, EXTRA_HIDE_INCOGNITO_ICON, false);
mCloseButtonIcon = TintedDrawable.constructTintedDrawable(context, R.drawable.btn_close);
mShowShareItem = IntentUtils.safeGetBooleanExtra(
intent, CustomTabsIntent.EXTRA_DEFAULT_SHARE_MENU_ITEM, false);
......@@ -165,6 +177,12 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
// incognito CCT request for all apps.
public static boolean isValidIncognitoIntent(Intent intent) {
if (!isIncognitoRequested(intent)) return false;
// Allow first parties to use for experimentation regardless of state of feature.
if (isIntentFromFirstParty(intent)
&& IntentUtils.safeGetBooleanExtra(
intent, EXTRA_FORCE_ENABLE_FOR_EXPERIMENT, false)) {
return true;
}
if (!isTrustedIntent(intent)) return false;
assert ChromeFeatureList.isInitialized();
return ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_INCOGNITO);
......@@ -233,7 +251,12 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
@Override
public int getToolbarColor() {
return mToolbarColor;
return mColorProvider.getToolbarColor();
}
@Override
public boolean hasCustomToolbarColor() {
return mColorProvider.hasCustomToolbarColor();
}
@Override
......@@ -249,12 +272,23 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
@Override
public int getBottomBarColor() {
return mBottomBarColor;
return mColorProvider.getBottomBarColor();
}
@Override
public int getInitialBackgroundColor() {
return mColorProvider.getInitialBackgroundColor();
}
@Override
public Integer getNavigationBarColor() {
return mNavigationBarColor;
return mColorProvider.getNavigationBarColor();
}
@Override
@Nullable
public Integer getNavigationBarDividerColor() {
return mColorProvider.getNavigationBarDividerColor();
}
@Override
......@@ -296,4 +330,9 @@ public class IncognitoCustomTabIntentDataProvider extends BrowserServicesIntentD
}
return list;
}
@Override
public boolean shouldHideIncognitoIconOnToolbarInCct() {
return mHideIncognitoIconOnToolbar;
}
}
......@@ -156,6 +156,8 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
private CustomTabLocationBar mLocationBar;
private LocationBarModel mLocationBarModel;
private boolean mIncognitoIconHidden;
private Runnable mTitleAnimationStarter = new Runnable() {
@Override
public void run() {
......@@ -331,6 +333,15 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
}
}
/**
* @param value Whether the incognito icon should be hidden.
*/
public void setIncognitoIconHidden(boolean value) {
if (mIncognitoIconHidden == value) return;
mIncognitoIconHidden = value;
requestLayout();
}
@Override
protected String getContentPublisher() {
Tab tab = getToolbarDataProvider().getTab();
......@@ -379,8 +390,9 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
}
private void updateToolbarLayoutMargin() {
// We show the Incognito logo for Incognito CCT case
if (getToolbarDataProvider().isIncognito()) mIncognitoImageView.setVisibility(VISIBLE);
final boolean shouldShowIncognitoIcon =
!mIncognitoIconHidden && getToolbarDataProvider().isIncognito();
mIncognitoImageView.setVisibility(shouldShowIncognitoIcon ? VISIBLE : GONE);
int startMargin = calculateStartMarginWhenCloseButtonVisibilityGone();
......
......@@ -125,6 +125,8 @@ public class CustomTabToolbarCoordinator {
manager.setToolbarShadowVisibility(View.GONE);
}
showCustomButtonsOnToolbar();
CustomTabToolbar toolbar = mActivity.findViewById(R.id.toolbar);
toolbar.setIncognitoIconHidden(mIntentDataProvider.shouldHideIncognitoIconOnToolbarInCct());
}
/**
......
......@@ -209,6 +209,41 @@ public class CustomTabActivityIncognitoTest {
.check(matches(not(isDisplayed())));
}
@Test
@MediumTest
@Features.DisableFeatures({ChromeFeatureList.CCT_INCOGNITO})
public void canLaunchFirstPartyIncognitoWithExtraWhenDisabled() throws Exception {
Intent intent = createMinimalIncognitoCustomTabIntent();
intent.putExtra(
IncognitoCustomTabIntentDataProvider.EXTRA_FORCE_ENABLE_FOR_EXPERIMENT, true);
CustomTabActivity activity = launchIncognitoCustomTab(intent);
assertTrue(activity.getActivityTab().isIncognito());
}
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
public void canHideToolbarIncognitoLogo() throws Exception {
Intent intent = createMinimalIncognitoCustomTabIntent();
// The icon is only hidden if an extra is supplied.
intent.putExtra(IncognitoCustomTabIntentDataProvider.EXTRA_HIDE_INCOGNITO_ICON, true);
launchIncognitoCustomTab(intent);
Espresso.onView(withId(R.id.incognito_cct_logo_image_view))
.check(matches(not(isDisplayed())));
}
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
public void canCustomizeToolbarColor() throws Exception {
Intent intent = createMinimalIncognitoCustomTabIntent();
// The color is only allowed if an extra is supplied.
intent.putExtra(IncognitoCustomTabIntentDataProvider.EXTRA_USE_NORMAL_PROFILE_STYLE, true);
intent.putExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, Color.RED);
CustomTabActivity activity = launchIncognitoCustomTab(intent);
assertEquals(Color.RED, getToolbarColor(activity));
}
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CCT_INCOGNITO})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment