Commit a4c66116 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Fix sharing for pre-warmed CCTs.

CCTs that have been pre-warmed create a Tab prior to the
ShareDelegate being available.  This switches to passing a Supplier
around for late binding access.

BUG=1034460

Change-Id: I8127b2928cd8de523683b8fa1a2f1e4bd3f50374
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006259
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732923}
parent cb022faa
......@@ -275,7 +275,6 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
private EphemeralTabCoordinator mEphemeralTabCoordinator;
private UpdateNotificationController mUpdateNotificationController;
private StatusBarColorController mStatusBarColorController;
private ShareDelegate mShareDelegate;
// Timestamp in ms when initial layout inflation begins
private long mInflateInitialLayoutBeginMs;
......@@ -463,10 +462,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
mManualFillingComponent.getKeyboardExtensionViewResizer());
// Should be called after TabModels are initialized.
mShareDelegate = new ShareDelegateImpl(mRootUiCoordinator.getBottomSheetController(),
getActivityTabProvider(), new ShareDelegateImpl.ShareSheetDelegate(),
getCurrentTabCreator());
mShareDelegateSupplier.set(mShareDelegate);
ShareDelegate shareDelegate = new ShareDelegateImpl(
mRootUiCoordinator.getBottomSheetController(), getActivityTabProvider(),
new ShareDelegateImpl.ShareSheetDelegate(), getCurrentTabCreator());
mShareDelegateSupplier.set(shareDelegate);
// If onStart was called before postLayoutInflation (because inflation was done in a
// background thread) then make sure to call the relevant methods belatedly.
......@@ -1795,7 +1794,7 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
* @return An {@link ObservableSupplier} that will supply the {@link ShareDelegate} when
* it is ready.
*/
protected ObservableSupplier<ShareDelegate> getShareDelegateSupplier() {
public ObservableSupplier<ShareDelegate> getShareDelegateSupplier() {
return mShareDelegateSupplier;
}
......@@ -2411,13 +2410,6 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
return mRootUiCoordinator.getBottomSheetController();
}
/**
* @return A {@link ShareDelegate}.
*/
public ShareDelegate getShareDelegate() {
return mShareDelegate;
}
@VisibleForTesting
public RootUiCoordinator getRootUiCoordinatorForTesting() {
return mRootUiCoordinator;
......
......@@ -48,7 +48,7 @@ public class TabbedModeTabDelegateFactory implements TabDelegateFactory {
@Override
public ContextMenuPopulator createContextMenuPopulator(Tab tab) {
return new ChromeContextMenuPopulator(new TabContextMenuItemDelegate(tab),
mShareDelegateSupplier.get(), ChromeContextMenuPopulator.ContextMenuMode.NORMAL);
mShareDelegateSupplier, ChromeContextMenuPopulator.ContextMenuMode.NORMAL);
}
@Override
......
......@@ -17,6 +17,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabPanel;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItem.Item;
......@@ -53,7 +54,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
private static final String TAG = "CCMenuPopulator";
private final ContextMenuItemDelegate mDelegate;
private final @ContextMenuMode int mMode;
private final ShareDelegate mShareDelegate;
private final Supplier<ShareDelegate> mShareDelegateSupplier;
private boolean mEnableLensWithSearchByImageText;
// True when the tracker indicates IPH in the form of "new" label needs to be shown.
......@@ -250,14 +251,14 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
* Builds a {@link ChromeContextMenuPopulator}.
* @param delegate The {@link ContextMenuItemDelegate} that will be notified with actions
* to perform when menu items are selected.
* @param shareDelegate The {@link ShareDelegate} that will be notified when a share action is
* performed.
* @param shareDelegate The Supplier of {@link ShareDelegate} that will be notified when a share
* action is performed.
* @param mode Defines the context menu mode
*/
public ChromeContextMenuPopulator(ContextMenuItemDelegate delegate, ShareDelegate shareDelegate,
@ContextMenuMode int mode) {
public ChromeContextMenuPopulator(ContextMenuItemDelegate delegate,
Supplier<ShareDelegate> shareDelegate, @ContextMenuMode int mode) {
mDelegate = delegate;
mShareDelegate = shareDelegate;
mShareDelegateSupplier = shareDelegate;
mMode = mode;
}
......@@ -583,7 +584,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
.setShareDirectly(false)
.setSaveLastUsed(true)
.build();
mShareDelegate.share(linkShareParams);
mShareDelegateSupplier.get().share(linkShareParams);
} else if (itemId == R.id.contextmenu_search_with_google_lens) {
ContextMenuUma.record(params, ContextMenuUma.Action.SEARCH_WITH_GOOGLE_LENS);
helper.searchWithGoogleLens(mDelegate.isIncognito());
......
......@@ -19,6 +19,7 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.PackageManagerUtils;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.ShortcutHelper;
......@@ -356,7 +357,6 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
private final MultiWindowUtils mMultiWindowUtils;
private final PendingIntent mFocusIntent;
private ExternalIntentsPolicyProvider mExternalIntentsPolicyProvider;
private final ShareDelegate mShareDelegate;
private TabWebContentsDelegateAndroid mWebContentsDelegateAndroid;
private ExternalNavigationDelegateImpl mNavigationDelegate;
......@@ -380,8 +380,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
@WebDisplayMode int displayMode, boolean shouldEnableEmbeddedMediaExperience,
BrowserControlsVisibilityDelegate visibilityDelegate, ExternalAuthUtils authUtils,
MultiWindowUtils multiWindowUtils, @Nullable PendingIntent focusIntent,
ExternalIntentsPolicyProvider externalIntentsPolicyProvider,
ShareDelegate shareDelegate) {
ExternalIntentsPolicyProvider externalIntentsPolicyProvider) {
mActivity = activity;
mShouldHideBrowserControls = shouldHideBrowserControls;
mIsOpenedByChrome = isOpenedByChrome;
......@@ -394,7 +393,6 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
mMultiWindowUtils = multiWindowUtils;
mFocusIntent = focusIntent;
mExternalIntentsPolicyProvider = externalIntentsPolicyProvider;
mShareDelegate = shareDelegate;
}
@Inject
......@@ -408,7 +406,7 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
getDisplayMode(intentDataProvider),
intentDataProvider.shouldEnableEmbeddedMediaExperience(), visibilityDelegate,
authUtils, multiWindowUtils, intentDataProvider.getFocusIntent(),
externalIntentsPolicyProvider, activity.getShareDelegate());
externalIntentsPolicyProvider);
}
/**
......@@ -417,7 +415,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
......@@ -473,8 +471,10 @@ public class CustomTabDelegateFactory implements TabDelegateFactory {
public ContextMenuPopulator createContextMenuPopulator(Tab tab) {
@ChromeContextMenuPopulator.ContextMenuMode
int contextMenuMode = getContextMenuMode(mActivityType);
Supplier<ShareDelegate> shareDelegateSupplier =
mActivity == null ? null : mActivity.getShareDelegateSupplier();
return new ChromeContextMenuPopulator(
new TabContextMenuItemDelegate(tab), mShareDelegate, contextMenuMode);
new TabContextMenuItemDelegate(tab), shareDelegateSupplier, contextMenuMode);
}
/**
......
......@@ -253,7 +253,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
mLocationBarDelegate.clearOmniboxFocus();
// TODO(mdjones): This should only share the displayed URL instead of the background
// tab.
((TabImpl) activityTab).getActivity().getShareDelegate().share(activityTab, false);
((TabImpl) activityTab)
.getActivity()
.getShareDelegateSupplier()
.get()
.share(activityTab, false);
} else if (R.id.url_edit_icon == view.getId()) {
ENUMERATED_SUGGESTION_ACTION.record(SuggestionAction.EDIT);
ACTION_EDIT_URL_SUGGESTION_EDIT.record();
......
......@@ -689,10 +689,10 @@ public class TabImpl implements Tab {
* @return {@link ChromeActivity} that currently contains this {@link Tab} in its
* {@link TabModel}.
*/
public ChromeActivity getActivity() {
public ChromeActivity<?> getActivity() {
if (getWindowAndroid() == null) return null;
Activity activity = ContextUtils.activityFromContext(getWindowAndroid().getContext().get());
if (activity instanceof ChromeActivity) return (ChromeActivity) activity;
if (activity instanceof ChromeActivity) return (ChromeActivity<?>) activity;
return null;
}
......
......@@ -134,7 +134,7 @@ class WebappActionsNotificationManager {
// Not routing through onMenuOrKeyboardAction to control UMA String.
Tab tab = webappActivity.getActivityTab();
boolean isIncognito = tab.isIncognito();
webappActivity.getShareDelegate().share(tab, false);
webappActivity.getShareDelegateSupplier().get().share(tab, false);
RecordUserAction.record("Webapp.NotificationShare");
return true;
} else if (ACTION_OPEN_IN_CHROME.equals(intent.getAction())) {
......
......@@ -186,8 +186,8 @@ public class ShareServiceImpl implements ShareService {
.setCallback(innerCallback);
if (files == null || files.length == 0) {
ChromeActivity activity = (ChromeActivity) mWindow.getActivity().get();
activity.getShareDelegate().share(paramsBuilder.build());
ChromeActivity<?> activity = (ChromeActivity<?>) mWindow.getActivity().get();
activity.getShareDelegateSupplier().get().share(paramsBuilder.build());
return;
}
......
......@@ -54,8 +54,9 @@ public class SharedFileCollator implements Callback<Integer> {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
if (result == MojoResult.OK) {
ChromeActivity activity = (ChromeActivity) mParams.getWindow().getActivity().get();
activity.getShareDelegate().share(mParams);
ChromeActivity<?> activity =
(ChromeActivity<?>) mParams.getWindow().getActivity().get();
activity.getShareDelegateSupplier().get().share(mParams);
} else {
callback.call(ShareError.INTERNAL_ERROR);
}
......
......@@ -76,8 +76,8 @@ public class ChromeContextMenuPopulatorTest {
}
private void initializePopulator(@ContextMenuMode int mode) {
mPopulator =
Mockito.spy(new ChromeContextMenuPopulator(mItemDelegate, mShareDelegate, mode));
mPopulator = Mockito.spy(
new ChromeContextMenuPopulator(mItemDelegate, () -> mShareDelegate, mode));
doReturn(mTemplateUrlService).when(mPopulator).getTemplateUrlService();
doReturn(false).when(mPopulator).shouldTriggerEphemeralTabHelpUi();
}
......
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