Commit 22cb4a0c authored by Sophey Dong's avatar Sophey Dong Committed by Commit Bot

[SharingHub] Show different copy options for link, text, and link+text.

Bug: 1129670, 1120093
Change-Id: I8b48d2c3ff9fda7fc347219f40deed60b9dd206d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426481
Commit-Queue: Sophey Dong <sophey@chromium.org>
Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811839}
parent fc68ec09
...@@ -106,6 +106,7 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -106,6 +106,7 @@ class ChromeProvidedSharingOptionsProvider {
*/ */
private static class FirstPartyOption { private static class FirstPartyOption {
final Collection<Integer> mContentTypes; final Collection<Integer> mContentTypes;
final Collection<Integer> mContentTypesToDisableFor;
final PropertyModel mPropertyModel; final PropertyModel mPropertyModel;
final boolean mDisableForMultiWindow; final boolean mDisableForMultiWindow;
...@@ -115,12 +116,14 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -115,12 +116,14 @@ 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 contentTypesToDisableFor Content types to disable for.
* @param disableForMultiWindow If the feature should be disabled if in multi-window mode. * @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) { Collection<Integer> contentTypesToDisableFor, boolean disableForMultiWindow) {
mPropertyModel = model; mPropertyModel = model;
mContentTypes = contentTypes; mContentTypes = contentTypes;
mContentTypesToDisableFor = contentTypesToDisableFor;
mDisableForMultiWindow = disableForMultiWindow; mDisableForMultiWindow = disableForMultiWindow;
} }
} }
...@@ -131,10 +134,12 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -131,10 +134,12 @@ class ChromeProvidedSharingOptionsProvider {
private String mFeatureNameForMetrics; private String mFeatureNameForMetrics;
private Callback<View> mOnClickCallback; private Callback<View> mOnClickCallback;
private boolean mDisableForMultiWindow; private boolean mDisableForMultiWindow;
private Integer[] mContentTypesToDisableFor;
private final Integer[] mContentTypesInBuilder; private final Integer[] mContentTypesInBuilder;
FirstPartyOptionBuilder(Integer... contentTypes) { FirstPartyOptionBuilder(Integer... contentTypes) {
mContentTypesInBuilder = contentTypes; mContentTypesInBuilder = contentTypes;
mContentTypesToDisableFor = new Integer[] {};
} }
FirstPartyOptionBuilder setIcon(int icon, int iconLabel) { FirstPartyOptionBuilder setIcon(int icon, int iconLabel) {
...@@ -153,6 +158,11 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -153,6 +158,11 @@ class ChromeProvidedSharingOptionsProvider {
return this; return this;
} }
FirstPartyOptionBuilder setContentTypesToDisableFor(Integer... contentTypesToDisableFor) {
mContentTypesToDisableFor = contentTypesToDisableFor;
return this;
}
FirstPartyOptionBuilder setDisableForMultiWindow(boolean disableForMultiWindow) { FirstPartyOptionBuilder setDisableForMultiWindow(boolean disableForMultiWindow) {
mDisableForMultiWindow = disableForMultiWindow; mDisableForMultiWindow = disableForMultiWindow;
return this; return this;
...@@ -167,8 +177,8 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -167,8 +177,8 @@ class ChromeProvidedSharingOptionsProvider {
mBottomSheetController.hideContent(mBottomSheetContent, true); mBottomSheetController.hideContent(mBottomSheetContent, true);
mOnClickCallback.onResult(view); mOnClickCallback.onResult(view);
}); });
return new FirstPartyOption( return new FirstPartyOption(model, Arrays.asList(mContentTypesInBuilder),
model, Arrays.asList(mContentTypesInBuilder), mDisableForMultiWindow); Arrays.asList(mContentTypesToDisableFor), mDisableForMultiWindow);
} }
} }
...@@ -184,6 +194,8 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -184,6 +194,8 @@ class ChromeProvidedSharingOptionsProvider {
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)
&& Collections.disjoint(
contentTypes, firstPartyOption.mContentTypesToDisableFor)
&& !(isMultiWindow && firstPartyOption.mDisableForMultiWindow)) { && !(isMultiWindow && firstPartyOption.mDisableForMultiWindow)) {
propertyModels.add(firstPartyOption.mPropertyModel); propertyModels.add(firstPartyOption.mPropertyModel);
} }
...@@ -202,8 +214,7 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -202,8 +214,7 @@ class ChromeProvidedSharingOptionsProvider {
mOrderedFirstPartyOptions.add(createCopyLinkFirstPartyOption()); mOrderedFirstPartyOptions.add(createCopyLinkFirstPartyOption());
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)) { if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)) {
mOrderedFirstPartyOptions.add(createCopyImageFirstPartyOption()); mOrderedFirstPartyOptions.add(createCopyImageFirstPartyOption());
} mOrderedFirstPartyOptions.add(createCopyFirstPartyOption());
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_SHARING_HUB_V15)) {
mOrderedFirstPartyOptions.add(createCopyTextFirstPartyOption()); mOrderedFirstPartyOptions.add(createCopyTextFirstPartyOption());
} }
mOrderedFirstPartyOptions.add(createSendTabToSelfFirstPartyOption()); mOrderedFirstPartyOptions.add(createSendTabToSelfFirstPartyOption());
...@@ -252,12 +263,14 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -252,12 +263,14 @@ 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),
/*contentTypesToDisableFor=*/Collections.emptySet(),
/*disableForMultiWindow=*/true); /*disableForMultiWindow=*/true);
} }
private FirstPartyOption createCopyLinkFirstPartyOption() { private FirstPartyOption createCopyLinkFirstPartyOption() {
return new FirstPartyOptionBuilder( return new FirstPartyOptionBuilder(
ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE) ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE)
.setContentTypesToDisableFor(ContentType.LINK_AND_TEXT)
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_url) .setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_url)
.setFeatureNameForMetrics("SharingHubAndroid.CopyURLSelected") .setFeatureNameForMetrics("SharingHubAndroid.CopyURLSelected")
.setOnClickCallback((view) -> { .setOnClickCallback((view) -> {
...@@ -283,8 +296,23 @@ class ChromeProvidedSharingOptionsProvider { ...@@ -283,8 +296,23 @@ class ChromeProvidedSharingOptionsProvider {
.build(); .build();
} }
private FirstPartyOption createCopyFirstPartyOption() {
return new FirstPartyOptionBuilder(ContentType.LINK_AND_TEXT)
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy)
.setFeatureNameForMetrics("SharingHubAndroid.CopySelected")
.setOnClickCallback((view) -> {
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(
Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(ClipData.newPlainText(
mShareParams.getTitle(), mShareParams.getTextAndUrl()));
Toast.makeText(mActivity, R.string.sharing_copied, Toast.LENGTH_SHORT).show();
})
.build();
}
private FirstPartyOption createCopyTextFirstPartyOption() { private FirstPartyOption createCopyTextFirstPartyOption() {
return new FirstPartyOptionBuilder(ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT) return new FirstPartyOptionBuilder(ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT)
.setContentTypesToDisableFor(ContentType.LINK_AND_TEXT)
.setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_text) .setIcon(R.drawable.ic_content_copy_black, R.string.sharing_copy_text)
.setFeatureNameForMetrics("SharingHubAndroid.CopyTextSelected") .setFeatureNameForMetrics("SharingHubAndroid.CopyTextSelected")
.setOnClickCallback((view) -> { .setOnClickCallback((view) -> {
......
...@@ -45,15 +45,17 @@ import java.util.Set; ...@@ -45,15 +45,17 @@ import java.util.Set;
// TODO(crbug/1022172): Should be package-protected once modularization is complete. // TODO(crbug/1022172): Should be package-protected once modularization is complete.
public class ShareSheetPropertyModelBuilder { public class ShareSheetPropertyModelBuilder {
@IntDef({ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT, @IntDef({ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT,
ContentType.IMAGE, ContentType.HIGHLIGHTED_TEXT, ContentType.OTHER_FILE_TYPE}) ContentType.HIGHLIGHTED_TEXT, ContentType.LINK_AND_TEXT, ContentType.IMAGE,
ContentType.OTHER_FILE_TYPE})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@interface ContentType { @interface ContentType {
int LINK_PAGE_VISIBLE = 0; int LINK_PAGE_VISIBLE = 0;
int LINK_PAGE_NOT_VISIBLE = 1; int LINK_PAGE_NOT_VISIBLE = 1;
int TEXT = 2; int TEXT = 2;
int IMAGE = 3; int HIGHLIGHTED_TEXT = 3;
int HIGHLIGHTED_TEXT = 4; int LINK_AND_TEXT = 4;
int OTHER_FILE_TYPE = 5; int IMAGE = 5;
int OTHER_FILE_TYPE = 6;
} }
private static final int MAX_NUM_APPS = 7; private static final int MAX_NUM_APPS = 7;
...@@ -61,9 +63,10 @@ public class ShareSheetPropertyModelBuilder { ...@@ -61,9 +63,10 @@ public class ShareSheetPropertyModelBuilder {
// Variations parameter name for the comma-separated list of third-party activity names. // Variations parameter name for the comma-separated list of third-party activity names.
private static final String PARAM_SHARING_HUB_THIRD_PARTY_APPS = "sharing-hub-third-party-apps"; private static final String PARAM_SHARING_HUB_THIRD_PARTY_APPS = "sharing-hub-third-party-apps";
static final HashSet<Integer> ALL_CONTENT_TYPES = new HashSet<>(Arrays.asList( static final HashSet<Integer> ALL_CONTENT_TYPES = new HashSet<>(
ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.TEXT, Arrays.asList(ContentType.LINK_PAGE_VISIBLE, ContentType.LINK_PAGE_NOT_VISIBLE,
ContentType.IMAGE, ContentType.HIGHLIGHTED_TEXT, ContentType.OTHER_FILE_TYPE)); ContentType.TEXT, ContentType.HIGHLIGHTED_TEXT, ContentType.LINK_AND_TEXT,
ContentType.IMAGE, ContentType.OTHER_FILE_TYPE));
private static final ArrayList<String> FALLBACK_ACTIVITIES = private static final ArrayList<String> FALLBACK_ACTIVITIES =
new ArrayList<>(Arrays.asList("com.whatsapp.ContactPicker", new ArrayList<>(Arrays.asList("com.whatsapp.ContactPicker",
"com.facebook.composer.shareintent.ImplicitShareIntentHandlerDefaultAlias", "com.facebook.composer.shareintent.ImplicitShareIntentHandlerDefaultAlias",
...@@ -126,6 +129,9 @@ public class ShareSheetPropertyModelBuilder { ...@@ -126,6 +129,9 @@ public class ShareSheetPropertyModelBuilder {
contentTypes.add(ContentType.TEXT); contentTypes.add(ContentType.TEXT);
} }
} }
if (!TextUtils.isEmpty(params.getUrl()) && !TextUtils.isEmpty(params.getText())) {
contentTypes.add(ContentType.LINK_AND_TEXT);
}
if (params.getFileUris() != null) { if (params.getFileUris() != null) {
if (!TextUtils.isEmpty(params.getFileContentType()) if (!TextUtils.isEmpty(params.getFileContentType())
&& params.getFileContentType().startsWith(IMAGE_TYPE)) { && params.getFileContentType().startsWith(IMAGE_TYPE)) {
......
...@@ -246,7 +246,7 @@ public final class ShareSheetPropertyModelBuilderTest { ...@@ -246,7 +246,7 @@ public final class ShareSheetPropertyModelBuilderTest {
assertEquals("Should contain correct content types.", assertEquals("Should contain correct content types.",
ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.OTHER_FILE_TYPE, ImmutableSet.of(ContentType.LINK_PAGE_NOT_VISIBLE, ContentType.OTHER_FILE_TYPE,
ContentType.TEXT), ContentType.TEXT, ContentType.LINK_AND_TEXT),
ShareSheetPropertyModelBuilder.getContentTypes(shareParams, shareExtras)); ShareSheetPropertyModelBuilder.getContentTypes(shareParams, shareExtras));
} }
......
...@@ -3978,6 +3978,10 @@ In Incognito, your activity might still be visible to websites that you visit, y ...@@ -3978,6 +3978,10 @@ In Incognito, your activity might still be visible to websites that you visit, y
More More
</message> </message>
<message name="IDS_SHARING_COPY" desc="Label for the Copy button in the sharing hub.">
Copy
</message>
<message name="IDS_SHARING_COPY_URL" desc="Label for the Copy URL button in the sharing hub."> <message name="IDS_SHARING_COPY_URL" desc="Label for the Copy URL button in the sharing hub.">
Copy link Copy link
</message> </message>
...@@ -3998,6 +4002,10 @@ In Incognito, your activity might still be visible to websites that you visit, y ...@@ -3998,6 +4002,10 @@ In Incognito, your activity might still be visible to websites that you visit, y
Link to text Link to text
</message> </message>
<message name="IDS_SHARING_COPIED" desc="Text shown in the toast notification when Copy is selected in the sharing hub.">
Copied
</message>
<message name="IDS_TEXT_COPIED" desc="Text shown in the toast notification when Copy Text is selected in the sharing hub."> <message name="IDS_TEXT_COPIED" desc="Text shown in the toast notification when Copy Text is selected in the sharing hub.">
Text Copied Text Copied
</message> </message>
......
ab18934f0393bc4dfa4f5af5efcd9e5ac764b925
\ No newline at end of file
3a225761ad2cb4bc0b102138b69946d67ec6671d
\ No newline at end of file
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