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