Commit 589141da authored by Sophey Dong's avatar Sophey Dong Committed by Commit Bot

[Screenshot] Hide Screenshot option when in multi-window mode.

Bug: 1112281
Change-Id: I549d1cd20e78245c4df973b42bba3666c53881a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2383451
Commit-Queue: Sophey Dong <sophey@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803975}
parent e7bc8b04
...@@ -452,9 +452,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent> ...@@ -452,9 +452,10 @@ public abstract class ChromeActivity<C extends ChromeActivityComponent>
getLifecycleDispatcher().register(bottomContainer); getLifecycleDispatcher().register(bottomContainer);
// Should be called after TabModels are initialized. // Should be called after TabModels are initialized.
ShareDelegate shareDelegate = new ShareDelegateImpl( ShareDelegate shareDelegate =
mRootUiCoordinator.getBottomSheetController(), getActivityTabProvider(), new ShareDelegateImpl(mRootUiCoordinator.getBottomSheetController(),
new ShareDelegateImpl.ShareSheetDelegate(), isCustomTab()); getLifecycleDispatcher(), getActivityTabProvider(),
new ShareDelegateImpl.ShareSheetDelegate(), isCustomTab());
mShareDelegateSupplier.set(shareDelegate); 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
......
...@@ -17,6 +17,7 @@ import org.chromium.base.metrics.RecordUserAction; ...@@ -17,6 +17,7 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.feature_engagement.ScreenshotTabObserver; import org.chromium.chrome.browser.feature_engagement.ScreenshotTabObserver;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
import org.chromium.chrome.browser.printing.PrintShareActivity; import org.chromium.chrome.browser.printing.PrintShareActivity;
import org.chromium.chrome.browser.printing.TabPrinter; import org.chromium.chrome.browser.printing.TabPrinter;
...@@ -48,10 +49,11 @@ public class ShareDelegateImpl implements ShareDelegate { ...@@ -48,10 +49,11 @@ public class ShareDelegateImpl implements ShareDelegate {
static final String CANONICAL_URL_RESULT_HISTOGRAM = "Mobile.CanonicalURLResult"; static final String CANONICAL_URL_RESULT_HISTOGRAM = "Mobile.CanonicalURLResult";
private final BottomSheetController mBottomSheetController; private final BottomSheetController mBottomSheetController;
private final ShareSheetDelegate mDelegate; private final ActivityLifecycleDispatcher mLifecycleDispatcher;
private final Supplier<Tab> mTabProvider; private final Supplier<Tab> mTabProvider;
private final ShareSheetDelegate mDelegate;
private final boolean mIsCustomTab;
private long mShareStartTime; private long mShareStartTime;
private boolean mIsCustomTab;
private static boolean sScreenshotCaptureSkippedForTesting; private static boolean sScreenshotCaptureSkippedForTesting;
...@@ -59,15 +61,19 @@ public class ShareDelegateImpl implements ShareDelegate { ...@@ -59,15 +61,19 @@ public class ShareDelegateImpl implements ShareDelegate {
* Constructs a new {@link ShareDelegateImpl}. * Constructs a new {@link ShareDelegateImpl}.
* *
* @param controller The BottomSheetController for the current activity. * @param controller The BottomSheetController for the current activity.
* @param lifecycleDispatcher Dispatcher for activity lifecycle events, e.g. configuration
* changes.
* @param tabProvider Supplier for the current activity tab. * @param tabProvider Supplier for the current activity tab.
* @param delegate The ShareSheetDelegate for the current activity. * @param delegate The ShareSheetDelegate for the current activity.
* @param isCustomTab This share delegate is associated with a CCT. * @param isCustomTab This share delegate is associated with a CCT.
*/ */
public ShareDelegateImpl(BottomSheetController controller, Supplier<Tab> tabProvider, public ShareDelegateImpl(BottomSheetController controller,
ActivityLifecycleDispatcher lifecycleDispatcher, Supplier<Tab> tabProvider,
ShareSheetDelegate delegate, boolean isCustomTab) { ShareSheetDelegate delegate, boolean isCustomTab) {
mBottomSheetController = controller; mBottomSheetController = controller;
mDelegate = delegate; mLifecycleDispatcher = lifecycleDispatcher;
mTabProvider = tabProvider; mTabProvider = tabProvider;
mDelegate = delegate;
mIsCustomTab = isCustomTab; mIsCustomTab = isCustomTab;
} }
...@@ -77,8 +83,8 @@ public class ShareDelegateImpl implements ShareDelegate { ...@@ -77,8 +83,8 @@ public class ShareDelegateImpl implements ShareDelegate {
if (mShareStartTime == 0L) { if (mShareStartTime == 0L) {
mShareStartTime = System.currentTimeMillis(); mShareStartTime = System.currentTimeMillis();
} }
mDelegate.share(params, chromeShareExtras, mBottomSheetController, mTabProvider, mDelegate.share(params, chromeShareExtras, mBottomSheetController, mLifecycleDispatcher,
this::printTab, mShareStartTime, isSharingHubV1Enabled()); mTabProvider, this::printTab, mShareStartTime, isSharingHubV1Enabled());
mShareStartTime = 0; mShareStartTime = 0;
} }
...@@ -286,15 +292,16 @@ public class ShareDelegateImpl implements ShareDelegate { ...@@ -286,15 +292,16 @@ public class ShareDelegateImpl implements ShareDelegate {
* Trigger the share action for the specified params. * Trigger the share action for the specified params.
*/ */
void share(ShareParams params, ChromeShareExtras chromeShareExtras, void share(ShareParams params, ChromeShareExtras chromeShareExtras,
BottomSheetController controller, Supplier<Tab> tabProvider, BottomSheetController controller, ActivityLifecycleDispatcher lifecycleDispatcher,
Callback<Tab> printCallback, long shareStartTime, boolean sharingHubEnabled) { Supplier<Tab> tabProvider, Callback<Tab> printCallback, long shareStartTime,
boolean sharingHubEnabled) {
if (chromeShareExtras.shareDirectly()) { if (chromeShareExtras.shareDirectly()) {
ShareHelper.shareWithLastUsedComponent(params); ShareHelper.shareWithLastUsedComponent(params);
} else if (sharingHubEnabled && !chromeShareExtras.sharingTabGroup()) { } else if (sharingHubEnabled && !chromeShareExtras.sharingTabGroup()) {
// TODO(crbug.com/1085078): Sharing hub is suppressed for tab group sharing. // TODO(crbug.com/1085078): Sharing hub is suppressed for tab group sharing.
// Re-enable it when tab group sharing is supported by sharing hub. // Re-enable it when tab group sharing is supported by sharing hub.
ShareSheetCoordinator coordinator = ShareSheetCoordinator coordinator =
new ShareSheetCoordinator(controller, tabProvider, new ShareSheetCoordinator(controller, lifecycleDispatcher, tabProvider,
new ShareSheetPropertyModelBuilder(controller, new ShareSheetPropertyModelBuilder(controller,
ContextUtils.getApplicationContext().getPackageManager()), ContextUtils.getApplicationContext().getPackageManager()),
printCallback); printCallback);
......
...@@ -21,6 +21,7 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -21,6 +21,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.MetricsUtils.HistogramDelta; import org.chromium.base.test.util.MetricsUtils.HistogramDelta;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.share.ShareDelegateImpl.ShareSheetDelegate; import org.chromium.chrome.browser.share.ShareDelegateImpl.ShareSheetDelegate;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
...@@ -118,7 +119,8 @@ public class ShareDelegateImplIntegrationTest { ...@@ -118,7 +119,8 @@ public class ShareDelegateImplIntegrationTest {
ShareSheetDelegate delegate = new ShareSheetDelegate() { ShareSheetDelegate delegate = new ShareSheetDelegate() {
@Override @Override
void share(ShareParams params, ChromeShareExtras chromeShareParams, void share(ShareParams params, ChromeShareExtras chromeShareParams,
BottomSheetController controller, Supplier<Tab> tabProvider, BottomSheetController controller,
ActivityLifecycleDispatcher lifecycleDispatcher, Supplier<Tab> tabProvider,
Callback<Tab> printCallback, long shareStartTime, Callback<Tab> printCallback, long shareStartTime,
boolean sharingHubEnabled) { boolean sharingHubEnabled) {
paramsRef.set(params); paramsRef.set(params);
...@@ -129,6 +131,7 @@ public class ShareDelegateImplIntegrationTest { ...@@ -129,6 +131,7 @@ public class ShareDelegateImplIntegrationTest {
new ShareDelegateImpl(mActivityTestRule.getActivity() new ShareDelegateImpl(mActivityTestRule.getActivity()
.getRootUiCoordinatorForTesting() .getRootUiCoordinatorForTesting()
.getBottomSheetController(), .getBottomSheetController(),
mActivityTestRule.getActivity().getLifecycleDispatcher(),
mActivityTestRule.getActivity().getActivityTabProvider(), delegate, false) mActivityTestRule.getActivity().getActivityTabProvider(), delegate, false)
.share(mActivityTestRule.getActivity().getActivityTab(), false); .share(mActivityTestRule.getActivity().getActivityTab(), false);
}); });
......
...@@ -11,6 +11,7 @@ include_rules = [ ...@@ -11,6 +11,7 @@ include_rules = [
"+chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java", "+chrome/android/java/src/org/chromium/chrome/browser/init/ChromeBrowserInitializer.java",
"+chrome/android/java/src/org/chromium/chrome/browser/media/MediaViewerUtils.java", "+chrome/android/java/src/org/chromium/chrome/browser/media/MediaViewerUtils.java",
"+chrome/android/java/src/org/chromium/chrome/browser/modules/ModuleInstallUi.java", "+chrome/android/java/src/org/chromium/chrome/browser/modules/ModuleInstallUi.java",
"+chrome/android/java/src/org/chromium/chrome/browser/multiwindow/MultiWindowUtils.java",
"+chrome/android/java/src/org/chromium/chrome/browser/screenshot/EditorScreenshotTask.java", "+chrome/android/java/src/org/chromium/chrome/browser/screenshot/EditorScreenshotTask.java",
"+chrome/android/java/src/org/chromium/chrome/browser/share", "+chrome/android/java/src/org/chromium/chrome/browser/share",
"+chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java", "+chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java",
......
...@@ -97,9 +97,10 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -97,9 +97,10 @@ class ChromeProvidedSharingOptionsProvider {
/** /**
* Encapsulates a {@link PropertyModel} and the {@link ContentType}s it should be shown for. * Encapsulates a {@link PropertyModel} and the {@link ContentType}s it should be shown for.
*/ */
private class FirstPartyOption { private static class FirstPartyOption {
final Collection<Integer> mContentTypes; final Collection<Integer> mContentTypes;
final PropertyModel mPropertyModel; final PropertyModel mPropertyModel;
final boolean mDisableForMultiWindow;
/** /**
* Should only be used when the default property model constructed in the builder does not * Should only be used when the default property model constructed in the builder does not
...@@ -107,10 +108,13 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -107,10 +108,13 @@ class ChromeProvidedSharingOptionsProvider {
* *
* @param model Property model for the first party option. * @param model Property model for the first party option.
* @param contentTypes Content types to trigger for. * @param contentTypes Content types to trigger for.
* @param disableForMultiWindow If the feature should be disabled if in multi-window mode.
*/ */
FirstPartyOption(PropertyModel model, Collection<Integer> contentTypes) { FirstPartyOption(PropertyModel model, Collection<Integer> contentTypes,
boolean disableForMultiWindow) {
mPropertyModel = model; mPropertyModel = model;
mContentTypes = contentTypes; mContentTypes = contentTypes;
mDisableForMultiWindow = disableForMultiWindow;
} }
} }
...@@ -119,6 +123,7 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -119,6 +123,7 @@ class ChromeProvidedSharingOptionsProvider {
private int mIconLabel; private int mIconLabel;
private String mFeatureNameForMetrics; private String mFeatureNameForMetrics;
private Callback<View> mOnClickCallback; private Callback<View> mOnClickCallback;
private boolean mDisableForMultiWindow;
private final Integer[] mContentTypesInBuilder; private final Integer[] mContentTypesInBuilder;
FirstPartyOptionBuilder(Integer... contentTypes) { FirstPartyOptionBuilder(Integer... contentTypes) {
...@@ -141,6 +146,11 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -141,6 +146,11 @@ class ChromeProvidedSharingOptionsProvider {
return this; return this;
} }
FirstPartyOptionBuilder setDisableForMultiWindow(boolean disableForMultiWindow) {
mDisableForMultiWindow = disableForMultiWindow;
return this;
}
FirstPartyOption build() { FirstPartyOption build() {
PropertyModel model = ShareSheetPropertyModelBuilder.createPropertyModel( PropertyModel model = ShareSheetPropertyModelBuilder.createPropertyModel(
AppCompatResources.getDrawable(mActivity, mIcon), AppCompatResources.getDrawable(mActivity, mIcon),
...@@ -150,7 +160,8 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -150,7 +160,8 @@ class ChromeProvidedSharingOptionsProvider {
mBottomSheetController.hideContent(mBottomSheetContent, true); mBottomSheetController.hideContent(mBottomSheetContent, true);
mOnClickCallback.onResult(view); mOnClickCallback.onResult(view);
}); });
return new FirstPartyOption(model, Arrays.asList(mContentTypesInBuilder)); return new FirstPartyOption(
model, Arrays.asList(mContentTypesInBuilder), mDisableForMultiWindow);
} }
} }
...@@ -159,12 +170,14 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -159,12 +170,14 @@ class ChromeProvidedSharingOptionsProvider {
* contentTypes} being shared. * contentTypes} being shared.
* *
* @param contentTypes a {@link Set} of {@link ContentType}. * @param contentTypes a {@link Set} of {@link ContentType}.
* @param isMultiWindow if in multi-window mode.
* @return a list of {@link PropertyModel}s. * @return a list of {@link PropertyModel}s.
*/ */
List<PropertyModel> getPropertyModels(Set<Integer> contentTypes) { List<PropertyModel> getPropertyModels(Set<Integer> contentTypes, boolean isMultiWindow) {
List<PropertyModel> propertyModels = new ArrayList<>(); List<PropertyModel> propertyModels = new ArrayList<>();
for (FirstPartyOption firstPartyOption : mOrderedFirstPartyOptions) { for (FirstPartyOption firstPartyOption : mOrderedFirstPartyOptions) {
if (!Collections.disjoint(contentTypes, firstPartyOption.mContentTypes)) { if (!Collections.disjoint(contentTypes, firstPartyOption.mContentTypes)
&& !(isMultiWindow && firstPartyOption.mDisableForMultiWindow)) {
propertyModels.add(firstPartyOption.mPropertyModel); propertyModels.add(firstPartyOption.mPropertyModel);
} }
} }
...@@ -231,7 +244,8 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -231,7 +244,8 @@ class ChromeProvidedSharingOptionsProvider {
}); });
return new FirstPartyOption(propertyModel, return new FirstPartyOption(propertyModel,
Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.TEXT, Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.TEXT,
ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE)); ContentType.HIGHLIGHTED_TEXT, ContentType.IMAGE),
/*disableForMultiWindow=*/true);
} }
private FirstPartyOption createCopyLinkFirstPartyOption() { private FirstPartyOption createCopyLinkFirstPartyOption() {
......
...@@ -71,14 +71,7 @@ class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemClickLis ...@@ -71,14 +71,7 @@ class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemClickLis
messageView.setText(message); messageView.setText(message);
} }
RecyclerView topRow = this.getContentView().findViewById(R.id.share_sheet_chrome_apps); createChromeFeatureRecyclerViews(topRowModels);
if (topRowModels != null && topRowModels.size() > 0) {
View divider = this.getContentView().findViewById(R.id.share_sheet_divider);
divider.setVisibility(View.VISIBLE);
topRow.setVisibility(View.VISIBLE);
populateView(topRowModels, topRow);
topRow.addOnScrollListener(new ScrollEventReporter("SharingHubAndroid.TopRowScrolled"));
}
RecyclerView bottomRow = this.getContentView().findViewById(R.id.share_sheet_other_apps); RecyclerView bottomRow = this.getContentView().findViewById(R.id.share_sheet_other_apps);
populateView( populateView(
...@@ -87,6 +80,19 @@ class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemClickLis ...@@ -87,6 +80,19 @@ class ShareSheetBottomSheetContent implements BottomSheetContent, OnItemClickLis
new ScrollEventReporter("SharingHubAndroid.BottomRowScrolled")); new ScrollEventReporter("SharingHubAndroid.BottomRowScrolled"));
} }
void createChromeFeatureRecyclerViews(List<PropertyModel> chromeFeatureModels) {
RecyclerView chromeFeatureRow =
this.getContentView().findViewById(R.id.share_sheet_chrome_apps);
if (chromeFeatureModels != null && chromeFeatureModels.size() > 0) {
View divider = this.getContentView().findViewById(R.id.share_sheet_divider);
divider.setVisibility(View.VISIBLE);
chromeFeatureRow.setVisibility(View.VISIBLE);
populateView(chromeFeatureModels, chromeFeatureRow);
chromeFeatureRow.addOnScrollListener(
new ScrollEventReporter("SharingHubAndroid.TopRowScrolled"));
}
}
private void populateView(List<PropertyModel> models, RecyclerView view) { private void populateView(List<PropertyModel> models, RecyclerView view) {
ModelList modelList = new ModelList(); ModelList modelList = new ModelList();
for (PropertyModel model : models) { for (PropertyModel model : models) {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.share.share_sheet; package org.chromium.chrome.browser.share.share_sheet;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration;
import android.view.View; import android.view.View;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
...@@ -15,6 +16,9 @@ import org.chromium.base.metrics.RecordHistogram; ...@@ -15,6 +16,9 @@ import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.ConfigurationChangedObserver;
import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.share.ChromeShareExtras; import org.chromium.chrome.browser.share.ChromeShareExtras;
import org.chromium.chrome.browser.share.ShareHelper; import org.chromium.chrome.browser.share.ShareHelper;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -35,8 +39,9 @@ import java.util.Set; ...@@ -35,8 +39,9 @@ import java.util.Set;
* Coordinator for displaying the share sheet. * Coordinator for displaying the share sheet.
*/ */
// TODO(crbug/1022172): Should be package-protected once modularization is complete. // TODO(crbug/1022172): Should be package-protected once modularization is complete.
public class ShareSheetCoordinator public class ShareSheetCoordinator implements ActivityStateObserver, ChromeOptionShareCallback,
implements ActivityStateObserver, ChromeOptionShareCallback, View.OnLayoutChangeListener { ConfigurationChangedObserver,
View.OnLayoutChangeListener {
private static final String NO_SHARE_SHEET_MESSAGE = ""; private static final String NO_SHARE_SHEET_MESSAGE = "";
private final BottomSheetController mBottomSheetController; private final BottomSheetController mBottomSheetController;
private final Supplier<Tab> mTabProvider; private final Supplier<Tab> mTabProvider;
...@@ -44,25 +49,34 @@ public class ShareSheetCoordinator ...@@ -44,25 +49,34 @@ public class ShareSheetCoordinator
private final Callback<Tab> mPrintTabCallback; private final Callback<Tab> mPrintTabCallback;
private long mShareStartTime; private long mShareStartTime;
private boolean mExcludeFirstParty; private boolean mExcludeFirstParty;
private boolean mIsMultiWindow;
private Set<Integer> mContentTypes;
private Activity mActivity;
private ActivityLifecycleDispatcher mLifecycleDispatcher;
private ChromeProvidedSharingOptionsProvider mChromeProvidedSharingOptionsProvider;
private ShareSheetBottomSheetContent mBottomSheet; private ShareSheetBottomSheetContent mBottomSheet;
private WindowAndroid mWindowAndroid; private WindowAndroid mWindowAndroid;
private final BottomSheetObserver mBottomSheetObserver;
/** /**
* Constructs a new ShareSheetCoordinator. * Constructs a new ShareSheetCoordinator.
* *
* @param controller The {@link BottomSheetController} for the current activity. * @param controller The {@link BottomSheetController} for the current activity.
* @param lifecycleDispatcher Dispatcher for activity lifecycle events, e.g. configuration
* changes.
* @param tabProvider Supplier for the current activity tab. * @param tabProvider Supplier for the current activity tab.
* @param modelBuilder The {@link ShareSheetPropertyModelBuilder} for the share sheet. * @param modelBuilder The {@link ShareSheetPropertyModelBuilder} for the share sheet.
*/ */
// TODO(crbug/1022172): Should be package-protected once modularization is complete. // TODO(crbug/1022172): Should be package-protected once modularization is complete.
public ShareSheetCoordinator(BottomSheetController controller, Supplier<Tab> tabProvider, public ShareSheetCoordinator(BottomSheetController controller,
ActivityLifecycleDispatcher lifecycleDispatcher, Supplier<Tab> tabProvider,
ShareSheetPropertyModelBuilder modelBuilder, Callback<Tab> printTab) { ShareSheetPropertyModelBuilder modelBuilder, Callback<Tab> printTab) {
mBottomSheetController = controller; mBottomSheetController = controller;
mLifecycleDispatcher = lifecycleDispatcher;
mLifecycleDispatcher.register(this);
mTabProvider = tabProvider; mTabProvider = tabProvider;
mPropertyModelBuilder = modelBuilder; mPropertyModelBuilder = modelBuilder;
mPrintTabCallback = printTab; mPrintTabCallback = printTab;
mBottomSheetObserver = new EmptyBottomSheetObserver() { BottomSheetObserver bottomSheetObserver = new EmptyBottomSheetObserver() {
@Override @Override
public void onSheetContentChanged(BottomSheetContent bottomSheet) { public void onSheetContentChanged(BottomSheetContent bottomSheet) {
super.onSheetContentChanged(bottomSheet); super.onSheetContentChanged(bottomSheet);
...@@ -75,7 +89,7 @@ public class ShareSheetCoordinator ...@@ -75,7 +89,7 @@ public class ShareSheetCoordinator
} }
} }
}; };
mBottomSheetController.addObserver(mBottomSheetObserver); mBottomSheetController.addObserver(bottomSheetObserver);
} }
protected void destroy() { protected void destroy() {
...@@ -83,6 +97,10 @@ public class ShareSheetCoordinator ...@@ -83,6 +97,10 @@ public class ShareSheetCoordinator
mWindowAndroid.removeActivityStateObserver(this); mWindowAndroid.removeActivityStateObserver(this);
mWindowAndroid = null; mWindowAndroid = null;
} }
if (mLifecycleDispatcher != null) {
mLifecycleDispatcher.unregister(this);
mLifecycleDispatcher = null;
}
} }
// TODO(crbug/1022172): Should be package-protected once modularization is complete. // TODO(crbug/1022172): Should be package-protected once modularization is complete.
...@@ -94,8 +112,8 @@ public class ShareSheetCoordinator ...@@ -94,8 +112,8 @@ public class ShareSheetCoordinator
void showShareSheetWithMessage(String message, ShareParams params, void showShareSheetWithMessage(String message, ShareParams params,
ChromeShareExtras chromeShareExtras, long shareStartTime) { ChromeShareExtras chromeShareExtras, long shareStartTime) {
Activity activity = params.getWindow().getActivity().get(); mActivity = params.getWindow().getActivity().get();
if (activity == null) return; if (mActivity == null) return;
if (mWindowAndroid == null) { if (mWindowAndroid == null) {
mWindowAndroid = params.getWindow(); mWindowAndroid = params.getWindow();
...@@ -104,15 +122,14 @@ public class ShareSheetCoordinator ...@@ -104,15 +122,14 @@ public class ShareSheetCoordinator
} }
} }
mBottomSheet = new ShareSheetBottomSheetContent(activity, this); mBottomSheet = new ShareSheetBottomSheetContent(mActivity, this);
mShareStartTime = shareStartTime; mShareStartTime = shareStartTime;
Set<Integer> contentTypes = mContentTypes = ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras);
ShareSheetPropertyModelBuilder.getContentTypes(params, chromeShareExtras);
List<PropertyModel> chromeFeatures = List<PropertyModel> chromeFeatures =
createTopRowPropertyModels(activity, params, chromeShareExtras, contentTypes); createTopRowPropertyModels(mActivity, params, chromeShareExtras, mContentTypes);
List<PropertyModel> thirdPartyApps = createBottomRowPropertyModels( List<PropertyModel> thirdPartyApps = createBottomRowPropertyModels(
activity, params, contentTypes, chromeShareExtras.saveLastUsed()); mActivity, params, mContentTypes, chromeShareExtras.saveLastUsed());
mBottomSheet.createRecyclerViews(chromeFeatures, thirdPartyApps, message); mBottomSheet.createRecyclerViews(chromeFeatures, thirdPartyApps, message);
...@@ -145,12 +162,13 @@ public class ShareSheetCoordinator ...@@ -145,12 +162,13 @@ public class ShareSheetCoordinator
if (mExcludeFirstParty) { if (mExcludeFirstParty) {
return new ArrayList<>(); return new ArrayList<>();
} }
ChromeProvidedSharingOptionsProvider chromeProvidedSharingOptionsProvider = mChromeProvidedSharingOptionsProvider = new ChromeProvidedSharingOptionsProvider(activity,
new ChromeProvidedSharingOptionsProvider(activity, mTabProvider, mTabProvider, mBottomSheetController, mBottomSheet, shareParams, chromeShareExtras,
mBottomSheetController, mBottomSheet, shareParams, chromeShareExtras, mPrintTabCallback, mShareStartTime, this);
mPrintTabCallback, mShareStartTime, this); mIsMultiWindow = MultiWindowUtils.getInstance().isInMultiWindowMode(activity);
return chromeProvidedSharingOptionsProvider.getPropertyModels(contentTypes); return mChromeProvidedSharingOptionsProvider.getPropertyModels(
contentTypes, mIsMultiWindow);
} }
@VisibleForTesting @VisibleForTesting
...@@ -189,6 +207,25 @@ public class ShareSheetCoordinator ...@@ -189,6 +207,25 @@ public class ShareSheetCoordinator
} }
} }
// ConfigurationChangedObserver
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (mActivity == null) {
return;
}
boolean isMultiWindow = MultiWindowUtils.getInstance().isInMultiWindowMode(mActivity);
// mContentTypes is null if Chrome features should not be shown.
if (mIsMultiWindow == isMultiWindow || mContentTypes == null) {
return;
}
mIsMultiWindow = isMultiWindow;
mBottomSheet.createChromeFeatureRecyclerViews(
mChromeProvidedSharingOptionsProvider.getPropertyModels(
mContentTypes, mIsMultiWindow));
mBottomSheetController.requestShowContent(mBottomSheet, /*animate=*/false);
}
// View.OnLayoutChangeListener // View.OnLayoutChangeListener
@Override @Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
......
...@@ -113,7 +113,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -113,7 +113,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES); ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 4, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 4, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
...@@ -133,7 +133,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -133,7 +133,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES); ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 2, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 2, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
...@@ -151,7 +151,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -151,7 +151,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES); ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
...@@ -163,8 +163,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -163,8 +163,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
@Test @Test
@MediumTest @MediumTest
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15, @Features.EnableFeatures({ChromeFeatureList.CHROME_SHARING_HUB_V15})
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
@Features.DisableFeatures( @Features.DisableFeatures(
{ChromeFeatureList.CHROME_SHARE_SCREENSHOT, ChromeFeatureList.CHROME_SHARE_QRCODE, {ChromeFeatureList.CHROME_SHARE_SCREENSHOT, ChromeFeatureList.CHROME_SHARE_QRCODE,
ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID}) ChromeFeatureList.CHROME_SHARE_HIGHLIGHTS_ANDROID})
...@@ -173,13 +172,31 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -173,13 +172,31 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT)); ImmutableSet.of(ContentType.TEXT), /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 1, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 1, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text))); ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_text)));
} }
@Test
@MediumTest
@Features.EnableFeatures({ChromeFeatureList.CHROME_SHARE_SCREENSHOT})
public void createPropertyModels_multiWindow_doesNotIncludeScreenshot() {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels(
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, /*isMultiWindow=*/true);
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels,
ImmutableList.of(mActivity.getResources().getString(R.string.sharing_copy_url),
mActivity.getResources().getString(
R.string.send_tab_to_self_share_activity_title),
mActivity.getResources().getString(R.string.qr_code_share_icon_label)));
}
@Test @Test
@MediumTest @MediumTest
@Features.EnableFeatures( @Features.EnableFeatures(
...@@ -190,7 +207,8 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -190,7 +207,8 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE)); ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE),
/*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
...@@ -210,7 +228,8 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -210,7 +228,8 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/true);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE)); ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.IMAGE),
/*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 4, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 4, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
...@@ -229,7 +248,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -229,7 +248,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.TEXT)); ImmutableSet.of(ContentType.TEXT), /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 0, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 0, propertyModels.size());
} }
...@@ -243,7 +262,7 @@ public class ChromeProvidedSharingOptionsProviderTest { ...@@ -243,7 +262,7 @@ public class ChromeProvidedSharingOptionsProviderTest {
setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false); setUpChromeProvidedSharingOptionsProviderTest(/*printingEnabled=*/false);
List<PropertyModel> propertyModels = List<PropertyModel> propertyModels =
mChromeProvidedSharingOptionsProvider.getPropertyModels( mChromeProvidedSharingOptionsProvider.getPropertyModels(
ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT)); ImmutableSet.of(ContentType.HIGHLIGHTED_TEXT), /*isMultiWindow=*/false);
Assert.assertEquals("Incorrect number of property models.", 2, propertyModels.size()); Assert.assertEquals("Incorrect number of property models.", 2, propertyModels.size());
assertModelsAreInTheRightOrder(propertyModels, assertModelsAreInTheRightOrder(propertyModels,
......
...@@ -9,6 +9,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; ...@@ -9,6 +9,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anySet; import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
import android.app.Activity; import android.app.Activity;
import android.support.test.rule.ActivityTestRule; import android.support.test.rule.ActivityTestRule;
...@@ -21,12 +22,12 @@ import org.junit.Test; ...@@ -21,12 +22,12 @@ import org.junit.Test;
import org.junit.rules.TestRule; import org.junit.rules.TestRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.test.ChromeBrowserTestRule; import org.chromium.chrome.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.Features; import org.chromium.chrome.test.util.browser.Features;
...@@ -56,18 +57,21 @@ public final class ShareSheetCoordinatorTest { ...@@ -56,18 +57,21 @@ public final class ShareSheetCoordinatorTest {
public TestRule mFeatureProcessor = new Features.JUnitProcessor(); public TestRule mFeatureProcessor = new Features.JUnitProcessor();
@Mock @Mock
private ShareSheetPropertyModelBuilder mPropertyModelBuilder; private ActivityLifecycleDispatcher mLifecycleDispatcher;
@Mock @Mock
private ShareParams mParams; private BottomSheetController mController;
@Mock @Mock
private BottomSheetController mController; private ShareSheetPropertyModelBuilder mPropertyModelBuilder;
private Activity mActivity;
private ShareSheetCoordinator mShareSheetCoordinator; private ShareSheetCoordinator mShareSheetCoordinator;
@Before @Before
public void setUp() { public void setUp() {
mActivity = mActivityTestRule.getActivity();
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
PropertyModel testModel1 = new PropertyModel.Builder(ShareSheetItemViewProperties.ALL_KEYS) PropertyModel testModel1 = new PropertyModel.Builder(ShareSheetItemViewProperties.ALL_KEYS)
.with(ShareSheetItemViewProperties.ICON, null) .with(ShareSheetItemViewProperties.ICON, null)
...@@ -82,22 +86,21 @@ public final class ShareSheetCoordinatorTest { ...@@ -82,22 +86,21 @@ public final class ShareSheetCoordinatorTest {
ArrayList<PropertyModel> thirdPartyPropertyModels = ArrayList<PropertyModel> thirdPartyPropertyModels =
new ArrayList<>(Arrays.asList(testModel1, testModel2)); new ArrayList<>(Arrays.asList(testModel1, testModel2));
Mockito.when(mPropertyModelBuilder.selectThirdPartyApps( when(mPropertyModelBuilder.selectThirdPartyApps(
any(), anySet(), any(), anyBoolean(), any(), anyLong())) any(), anySet(), any(), anyBoolean(), any(), anyLong()))
.thenReturn(thirdPartyPropertyModels); .thenReturn(thirdPartyPropertyModels);
mShareSheetCoordinator = mShareSheetCoordinator = new ShareSheetCoordinator(
new ShareSheetCoordinator(mController, null, mPropertyModelBuilder, null); mController, mLifecycleDispatcher, null, mPropertyModelBuilder, null);
} }
@Test @Test
@MediumTest @MediumTest
public void disableFirstPartyFeatures() { public void disableFirstPartyFeatures() {
mShareSheetCoordinator.disableFirstPartyFeaturesForTesting(); mShareSheetCoordinator.disableFirstPartyFeaturesForTesting();
Activity activity = mActivityTestRule.getActivity();
List<PropertyModel> propertyModels = mShareSheetCoordinator.createTopRowPropertyModels( List<PropertyModel> propertyModels = mShareSheetCoordinator.createTopRowPropertyModels(
activity, mParams, /*chromeShareExtras=*/null, mActivity, /*shareParams=*/null, /*chromeShareExtras=*/null,
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES); ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES);
assertEquals("Property model list should be empty.", 0, propertyModels.size()); assertEquals("Property model list should be empty.", 0, propertyModels.size());
} }
...@@ -105,18 +108,18 @@ public final class ShareSheetCoordinatorTest { ...@@ -105,18 +108,18 @@ public final class ShareSheetCoordinatorTest {
@Test @Test
@MediumTest @MediumTest
public void testCreateBottomRowPropertyModels() { public void testCreateBottomRowPropertyModels() {
Activity activity = mActivityTestRule.getActivity();
List<PropertyModel> propertyModels = mShareSheetCoordinator.createBottomRowPropertyModels( List<PropertyModel> propertyModels = mShareSheetCoordinator.createBottomRowPropertyModels(
activity, mParams, ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES, mActivity, new ShareParams.Builder(null, "", "").build(),
ShareSheetPropertyModelBuilder.ALL_CONTENT_TYPES,
/*saveLastUsed=*/false); /*saveLastUsed=*/false);
assertEquals("Incorrect number of property models.", 3, propertyModels.size()); assertEquals("Incorrect number of property models.", 3, propertyModels.size());
assertEquals("First property model isn't testModel1.", "testModel1", assertEquals("First property model isn't testModel1.", "testModel1",
propertyModels.get(0).get(ShareSheetItemViewProperties.LABEL)); propertyModels.get(0).get(ShareSheetItemViewProperties.LABEL));
assertEquals("Second property model isn't testModel2.", "testModel2", assertEquals("Second property model isn't testModel2.", "testModel2",
propertyModels.get(1).get(ShareSheetItemViewProperties.LABEL)); propertyModels.get(1).get(ShareSheetItemViewProperties.LABEL));
assertEquals("Third property model isn't More.", assertEquals("Third property model isn't More.",
activity.getResources().getString(R.string.sharing_more_icon_label), mActivity.getResources().getString(R.string.sharing_more_icon_label),
propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL)); propertyModels.get(2).get(ShareSheetItemViewProperties.LABEL));
} }
} }
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