Commit d3812689 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

PreviewTab: Inject the coordinator object for CCT

This CL injects EphemeralTabCoordinator object into the tab delegate
factory instead of instantiating it directly. This fixes a problem of
creating one coordinator per each tab.

Bug: 1064207, 1084731
Change-Id: I78187e2476410a4fcfe3efa85b51884640e1c757
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214802Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771720}
parent a2d7bf07
......@@ -343,7 +343,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
private TabWebContentsDelegateAndroid mWebContentsDelegateAndroid;
private ExternalNavigationDelegateImpl mNavigationDelegate;
private EphemeralTabCoordinator mEphemeralTabCoordinator;
private Supplier<EphemeralTabCoordinator> mEphemeralTabCoordinatorSupplier;
/**
* @param activity {@link ChromeActivity} instance.
......@@ -358,13 +358,18 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
* @param authUtils To determine whether apps are Google signed.
* @param multiWindowUtils To use to determine which ChromeTabbedActivity to open new tabs in.
* @param focusIntent A PendingIntent to launch to focus the client.
* @param externalIntentsPolicyProvider A provider of {@link ExternalIntentPolicy} that decides
* how to handle navigation to a new URL.
* @param ephemeralTabCoordinatorSupplier A provider of {@link EphemeralTabCoordinator} that
* shows preview tab.
*/
private CustomTabDelegateFactory(ChromeActivity<?> activity, boolean shouldHideBrowserControls,
boolean isOpenedByChrome, @Nullable String webApkScopeUrl,
@WebDisplayMode int displayMode, boolean shouldEnableEmbeddedMediaExperience,
BrowserControlsVisibilityDelegate visibilityDelegate, ExternalAuthUtils authUtils,
MultiWindowUtils multiWindowUtils, @Nullable PendingIntent focusIntent,
ExternalIntentsPolicyProvider externalIntentsPolicyProvider) {
ExternalIntentsPolicyProvider externalIntentsPolicyProvider,
Supplier<EphemeralTabCoordinator> ephemeralTabCoordinatorSupplier) {
mActivity = activity;
mShouldHideBrowserControls = shouldHideBrowserControls;
mIsOpenedByChrome = isOpenedByChrome;
......@@ -377,6 +382,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
mMultiWindowUtils = multiWindowUtils;
mFocusIntent = focusIntent;
mExternalIntentsPolicyProvider = externalIntentsPolicyProvider;
mEphemeralTabCoordinatorSupplier = ephemeralTabCoordinatorSupplier;
}
@Inject
......@@ -384,13 +390,14 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
BrowserServicesIntentDataProvider intentDataProvider,
CustomTabBrowserControlsVisibilityDelegate visibilityDelegate,
ExternalAuthUtils authUtils, MultiWindowUtils multiWindowUtils,
ExternalIntentsPolicyProvider externalIntentsPolicyProvider) {
ExternalIntentsPolicyProvider externalIntentsPolicyProvider,
Supplier<EphemeralTabCoordinator> ephemeralTabCoordinatorSupplier) {
this(activity, intentDataProvider.shouldEnableUrlBarHiding(),
intentDataProvider.isOpenedByChrome(), getWebApkScopeUrl(intentDataProvider),
getDisplayMode(intentDataProvider),
intentDataProvider.shouldEnableEmbeddedMediaExperience(), visibilityDelegate,
authUtils, multiWindowUtils, intentDataProvider.getFocusIntent(),
externalIntentsPolicyProvider);
externalIntentsPolicyProvider, ephemeralTabCoordinatorSupplier);
}
/**
......@@ -399,7 +406,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
*/
static CustomTabDelegateFactory createDummy() {
return new CustomTabDelegateFactory(null, false, false, null, WebDisplayMode.BROWSER, false,
null, null, null, null, null);
null, null, null, null, null, () -> null);
}
@Override
......@@ -451,16 +458,10 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
int contextMenuMode = getContextMenuMode(mActivityType);
Supplier<ShareDelegate> shareDelegateSupplier =
mActivity == null ? null : mActivity.getShareDelegateSupplier();
if (EphemeralTabCoordinator.isSupported() && mActivity != null) {
mEphemeralTabCoordinator = new EphemeralTabCoordinator(mActivity,
mActivity.getWindowAndroid(), mActivity.getWindow().getDecorView(),
mActivity.getActivityTabProvider(), mActivity::getCurrentTabCreator,
mActivity::getBottomSheetController, () -> false);
}
TabModelSelector tabModelSelector =
mActivity != null ? mActivity.getTabModelSelector() : null;
return new ChromeContextMenuPopulator(new TabContextMenuItemDelegate(tab, tabModelSelector,
() -> mEphemeralTabCoordinator),
mEphemeralTabCoordinatorSupplier),
shareDelegateSupplier, contextMenuMode, ExternalAuthUtils.getInstance());
}
......
......@@ -10,9 +10,11 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.CompositorViewHolder;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabCoordinator;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
......@@ -147,4 +149,17 @@ public class ChromeActivityCommonsModule {
public NotificationManagerProxy provideNotificationManagerProxy() {
return new NotificationManagerProxyImpl(mActivity.getApplicationContext());
}
@Provides
public Supplier<EphemeralTabCoordinator> provideEphemeralTabCoordinatorSupplier() {
return () -> {
// |isSupported| uses feature flag facility which is not ready at the point
// of injection. Delay the decision till the coordinator is actually used.
if (!EphemeralTabCoordinator.isSupported()) return null;
return new EphemeralTabCoordinator(mActivity, mActivity.getWindowAndroid(),
mActivity.getWindow().getDecorView(), mActivity.getActivityTabProvider(),
mActivity::getCurrentTabCreator, mActivity::getBottomSheetController,
() -> !mActivity.isCustomTab());
};
}
}
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