Commit 5036efc2 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Read Later : Added context menu item

This CL adds :
1 - Show a context menu item for Read later
2 - A New label to be shown until user clicks on the menu item

Bug: 1145825
Change-Id: Ie0ccb1d56a76d3e6bf6ae38075d0a7bcbba6a6ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2520278
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarSinan Sahin <sinansahin@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825805}
parent 63668d1d
......@@ -63,6 +63,7 @@
<item type="id" name="contextmenu_save_link_as" />
<item type="id" name="contextmenu_share_link" />
<item type="id" name="contextmenu_direct_share_link" />
<item type="id" name="contextmenu_read_later" />
<!--Image Group -->
<item type="id" name="contextmenu_load_original_image" />
......
......@@ -10,6 +10,7 @@ import android.text.style.RelativeSizeSpan;
import android.text.style.SuperscriptSpan;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import org.chromium.base.ApiCompatibilityUtils;
......@@ -33,9 +34,9 @@ class ChromeContextMenuItem {
Item.OPEN_IN_BROWSER_ID, Item.OPEN_IN_NEW_TAB, Item.OPEN_IN_INCOGNITO_TAB,
Item.OPEN_IN_OTHER_WINDOW, Item.OPEN_IN_EPHEMERAL_TAB, Item.COPY_LINK_ADDRESS,
Item.COPY_LINK_TEXT, Item.SAVE_LINK_AS, Item.SHARE_LINK, Item.DIRECT_SHARE_LINK,
Item.LOAD_ORIGINAL_IMAGE, Item.SAVE_IMAGE, Item.OPEN_IMAGE, Item.OPEN_IMAGE_IN_NEW_TAB,
Item.OPEN_IMAGE_IN_EPHEMERAL_TAB, Item.COPY_IMAGE, Item.SEARCH_BY_IMAGE,
Item.SEARCH_WITH_GOOGLE_LENS, Item.SHOP_SIMILAR_PRODUCTS,
Item.READ_LATER, Item.LOAD_ORIGINAL_IMAGE, Item.SAVE_IMAGE, Item.OPEN_IMAGE,
Item.OPEN_IMAGE_IN_NEW_TAB, Item.OPEN_IMAGE_IN_EPHEMERAL_TAB, Item.COPY_IMAGE,
Item.SEARCH_BY_IMAGE, Item.SEARCH_WITH_GOOGLE_LENS, Item.SHOP_SIMILAR_PRODUCTS,
Item.SHOP_IMAGE_WITH_GOOGLE_LENS, Item.SEARCH_SIMILAR_PRODUCTS, Item.SHARE_IMAGE,
Item.DIRECT_SHARE_IMAGE, Item.CALL, Item.SEND_MESSAGE, Item.ADD_TO_CONTACTS, Item.COPY,
Item.SAVE_VIDEO, Item.OPEN_IN_CHROME})
......@@ -57,31 +58,32 @@ class ChromeContextMenuItem {
int SAVE_LINK_AS = 9;
int SHARE_LINK = 10;
int DIRECT_SHARE_LINK = 11;
int READ_LATER = 12;
// Image Group
int LOAD_ORIGINAL_IMAGE = 12;
int SAVE_IMAGE = 13;
int OPEN_IMAGE = 14;
int OPEN_IMAGE_IN_NEW_TAB = 15;
int OPEN_IMAGE_IN_EPHEMERAL_TAB = 16;
int COPY_IMAGE = 17;
int SEARCH_BY_IMAGE = 18;
int SEARCH_WITH_GOOGLE_LENS = 19;
int SHOP_SIMILAR_PRODUCTS = 20;
int SHOP_IMAGE_WITH_GOOGLE_LENS = 21;
int SEARCH_SIMILAR_PRODUCTS = 22;
int SHARE_IMAGE = 23;
int DIRECT_SHARE_IMAGE = 24;
int LOAD_ORIGINAL_IMAGE = 13;
int SAVE_IMAGE = 14;
int OPEN_IMAGE = 15;
int OPEN_IMAGE_IN_NEW_TAB = 16;
int OPEN_IMAGE_IN_EPHEMERAL_TAB = 17;
int COPY_IMAGE = 18;
int SEARCH_BY_IMAGE = 19;
int SEARCH_WITH_GOOGLE_LENS = 20;
int SHOP_SIMILAR_PRODUCTS = 21;
int SHOP_IMAGE_WITH_GOOGLE_LENS = 22;
int SEARCH_SIMILAR_PRODUCTS = 23;
int SHARE_IMAGE = 24;
int DIRECT_SHARE_IMAGE = 25;
// Message Group
int CALL = 25;
int SEND_MESSAGE = 26;
int ADD_TO_CONTACTS = 27;
int COPY = 28;
int CALL = 26;
int SEND_MESSAGE = 27;
int ADD_TO_CONTACTS = 28;
int COPY = 29;
// Video Group
int SAVE_VIDEO = 29;
int SAVE_VIDEO = 30;
// Other
int OPEN_IN_CHROME = 30;
int OPEN_IN_CHROME = 31;
// ALWAYS UPDATE!
int NUM_ENTRIES = 31;
int NUM_ENTRIES = 32;
}
/**
......@@ -100,6 +102,7 @@ class ChromeContextMenuItem {
R.id.contextmenu_save_link_as, // Item.SAVE_LINK_AS
R.id.contextmenu_share_link, // Item.SHARE_LINK
R.id.contextmenu_direct_share_link, // Item.DIRECT_SHARE_LINK
R.id.contextmenu_read_later, // Item.READ_LATER
R.id.contextmenu_load_original_image, // Item.LOAD_ORIGINAL_IMAGE
R.id.contextmenu_save_image, // Item.SAVE_IMAGE
R.id.contextmenu_open_image, // Item.OPEN_IMAGE
......@@ -137,6 +140,7 @@ class ChromeContextMenuItem {
R.string.contextmenu_save_link, // Item.SAVE_LINK_AS:
R.string.contextmenu_share_link, // Item.SHARE_LINK
0, // Item.DIRECT_SHARE_LINK is not handled by this mapping.
R.string.contextmenu_read_later, // Item.READ_LATER
R.string.contextmenu_load_original_image, // Item.LOAD_ORIGINAL_IMAGE:
R.string.contextmenu_save_image, // Item.SAVE_IMAGE:
R.string.contextmenu_open_image, // Item.OPEN_IMAGE:
......@@ -201,6 +205,8 @@ class ChromeContextMenuItem {
TemplateUrlServiceFactory.get()
.getDefaultSearchEngineTemplateUrl()
.getShortName());
case Item.READ_LATER:
return addOrRemoveNewLabel(context, item, null, showInProductHelp);
case Item.OPEN_IN_EPHEMERAL_TAB:
return addOrRemoveNewLabel(context, item,
ChromePreferenceKeys.CONTEXT_MENU_OPEN_IN_EPHEMERAL_TAB_CLICKED,
......@@ -235,9 +241,11 @@ class ChromeContextMenuItem {
* has already been selected before.
*/
private static CharSequence addOrRemoveNewLabel(
Context context, @Item int item, String prefKey, boolean showNewLabel) {
Context context, @Item int item, @Nullable String prefKey, boolean showNewLabel) {
String menuTitle = context.getString(getStringId(item));
if (!showNewLabel || SharedPreferencesManager.getInstance().readBoolean(prefKey, false)) {
if (!showNewLabel
|| (prefKey != null
&& SharedPreferencesManager.getInstance().readBoolean(prefKey, false))) {
return SpanApplier.removeSpanText(menuTitle, new SpanInfo("<new>", "</new>"));
}
return SpanApplier.applySpans(menuTitle,
......
......@@ -32,6 +32,7 @@ import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabCoordinator;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItem.Item;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator.ContextMenuUma.Action;
import org.chromium.chrome.browser.contextmenu.RevampedContextMenuCoordinator.ListItemType;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
......@@ -135,7 +136,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
Action.SHARE_LINK, Action.OPEN_IN_EPHEMERAL_TAB, Action.OPEN_IMAGE_IN_EPHEMERAL_TAB,
Action.DIRECT_SHARE_LINK, Action.DIRECT_SHARE_IMAGE, Action.SEARCH_WITH_GOOGLE_LENS,
Action.COPY_IMAGE, Action.SHOP_SIMILAR_PRODUCTS, Action.SHOP_IMAGE_WITH_GOOGLE_LENS,
Action.SEARCH_SIMILAR_PRODUCTS})
Action.SEARCH_SIMILAR_PRODUCTS, Action.READ_LATER})
@Retention(RetentionPolicy.SOURCE)
public @interface Action {
int OPEN_IN_NEW_TAB = 0;
......@@ -175,7 +176,8 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
int SHOP_SIMILAR_PRODUCTS = 30;
int SHOP_IMAGE_WITH_GOOGLE_LENS = 31;
int SEARCH_SIMILAR_PRODUCTS = 32;
int NUM_ENTRIES = 33;
int READ_LATER = 33;
int NUM_ENTRIES = 34;
}
// Note: these values must match the ContextMenuSaveLinkType enum in enums.xml.
......@@ -396,6 +398,10 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
if (!mItemDelegate.isIncognito()
&& UrlUtilities.isDownloadableScheme(mParams.getLinkUrl())) {
linkGroup.add(createListItem(Item.SAVE_LINK_AS));
if (ChromeFeatureList.isEnabled(ChromeFeatureList.READ_LATER)) {
linkGroup.add(
createListItem(Item.READ_LATER, shouldTriggerReadLaterHelpUi()));
}
}
linkGroup.add(createShareListItem(Item.SHARE_LINK, Item.DIRECT_SHARE_LINK));
if (UrlUtilities.isTelScheme(mParams.getLinkUrl())) {
......@@ -582,6 +588,12 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
&& tracker.shouldTriggerHelpUI(FeatureConstants.EPHEMERAL_TAB_FEATURE);
}
private boolean shouldTriggerReadLaterHelpUi() {
Tracker tracker = TrackerFactory.getTrackerForProfile(Profile.getLastUsedRegularProfile());
return tracker.isInitialized()
&& tracker.shouldTriggerHelpUI(FeatureConstants.READ_LATER_CONTEXT_MENU_FEATURE);
}
@Override
public boolean isIncognito() {
return mItemDelegate.isIncognito();
......@@ -680,6 +692,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator {
.build();
mShareDelegateSupplier.get().share(
linkShareParams, new ChromeShareExtras.Builder().setSaveLastUsed(true).build());
} else if (itemId == R.id.contextmenu_read_later) {
recordContextMenuSelection(ContextMenuUma.Action.READ_LATER);
// TODO(crbug/1145825): Implement backend action.
} else if (itemId == R.id.contextmenu_direct_share_link) {
recordContextMenuSelection(ContextMenuUma.Action.DIRECT_SHARE_LINK);
final ShareParams shareParams =
......
......@@ -90,6 +90,7 @@ public class ChromeContextMenuPopulatorTest {
HashMap<String, Boolean> features = new HashMap<String, Boolean>();
features.put(ChromeFeatureList.CONTEXT_MENU_SEARCH_WITH_GOOGLE_LENS, false);
features.put(ChromeFeatureList.EPHEMERAL_TAB_USING_BOTTOM_SHEET, false);
features.put(ChromeFeatureList.READ_LATER, false);
ChromeFeatureList.setTestFeatures(features);
}
......@@ -181,6 +182,7 @@ public class ChromeContextMenuPopulatorTest {
HashMap<String, Boolean> features = new HashMap<String, Boolean>();
features.put(ChromeFeatureList.EPHEMERAL_TAB_USING_BOTTOM_SHEET, true);
features.put(ChromeFeatureList.READ_LATER, false);
ChromeFeatureList.setTestFeatures(features);
initializePopulator(ChromeContextMenuPopulator.ContextMenuMode.NORMAL, params);
......
......@@ -2129,6 +2129,9 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
<message name="IDS_CONTEXTMENU_OPEN_IN_EPHEMERAL_TAB" desc="Context-sensitive menu item to open a quick preview of the selected linked page. Note that 'preview' is a verb, not a noun. We're also labeling it *New* to draw attention to it when first released. The selected link will open in an overlay panel on top of the current tab which will go away easily too. [CHAR-LIMIT=30]">
Preview page <ph name="BEGIN_NEW">&lt;new&gt;</ph>New<ph name="END_NEW">&lt;/new&gt;</ph>
</message>
<message name="IDS_CONTEXTMENU_READ_LATER" desc="Context sensitive menu item for marking a link to be read later. We're also labeling it *New* to draw attention to it when first released. [CHAR-LIMIT=30]">
Read later <ph name="BEGIN_NEW">&lt;new&gt;</ph>New<ph name="END_NEW">&lt;/new&gt;</ph>
</message>
<message name="IDS_CONTEXTMENU_PERFORMANCE_INFO_FAST" desc="This string is shown in the context sensitive menu for links and is shown underneath the link URL. It indicates to the user that the link's target page is fast-loading and responsive. [CHAR-LIMIT=30]">
Fast page
</message>
......
06e75fef54b699b8ce7b66b7a772f20b81bf120d
\ No newline at end of file
......@@ -64,6 +64,7 @@ public @interface FeatureConstants {
String PREVIEWS_OMNIBOX_UI_FEATURE = "IPH_PreviewsOmniboxUI";
String TRANSLATE_MENU_BUTTON_FEATURE = "IPH_TranslateMenuButton";
String EXPLORE_SITES_TILE_FEATURE = "IPH_ExploreSitesTile";
String READ_LATER_CONTEXT_MENU_FEATURE = "IPH_ReadLaterContextMenu";
/**
* An IPH feature that encourages users to get better translations by enabling access to page
......
......@@ -75,6 +75,8 @@ const base::Feature kIPHDownloadInfoBarDownloadsAreFasterFeature{
"IPH_DownloadInfoBarDownloadsAreFaster", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kIPHQuietNotificationPromptsFeature{
"IPH_QuietNotificationPrompts", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kIPHReadLaterContextMenuFeature{
"IPH_ReadLaterContextMenu", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kIPHEphemeralTabFeature{"IPH_EphemeralTab",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kIPHFeedCardMenuFeature{"IPH_FeedCardMenu",
......
......@@ -65,6 +65,7 @@ extern const base::Feature kIPHKeyboardAccessoryPaymentFillingFeature;
extern const base::Feature kIPHNewTabPageHomeButtonFeature;
extern const base::Feature kIPHPreviewsOmniboxUIFeature;
extern const base::Feature kIPHQuietNotificationPromptsFeature;
extern const base::Feature kIPHReadLaterContextMenuFeature;
extern const base::Feature kIPHTabGroupsQuicklyComparePagesFeature;
extern const base::Feature kIPHTabGroupsTapToSeeAnotherTabFeature;
extern const base::Feature kIPHTabGroupsYourTabsAreTogetherFeature;
......
......@@ -49,6 +49,7 @@ const base::Feature* const kAllFeatures[] = {
&kIPHPreviewsOmniboxUIFeature,
&kIPHPwaInstallAvailableFeature,
&kIPHQuietNotificationPromptsFeature,
&kIPHReadLaterContextMenuFeature,
&kIPHTabGroupsQuicklyComparePagesFeature,
&kIPHTabGroupsTapToSeeAnotherTabFeature,
&kIPHTabGroupsYourTabsAreTogetherFeature,
......
......@@ -99,6 +99,8 @@ DEFINE_VARIATION_PARAM(kIPHPwaInstallAvailableFeature,
"IPH_PwaInstallAvailableFeature");
DEFINE_VARIATION_PARAM(kIPHQuietNotificationPromptsFeature,
"IPH_QuietNotificationPrompts");
DEFINE_VARIATION_PARAM(kIPHReadLaterContextMenuFeature,
"IPH_ReadLaterContextMenu");
DEFINE_VARIATION_PARAM(kIPHTabGroupsQuicklyComparePagesFeature,
"IPH_TabGroupsQuicklyComparePages");
DEFINE_VARIATION_PARAM(kIPHTabGroupsTapToSeeAnotherTabFeature,
......@@ -192,6 +194,7 @@ constexpr flags_ui::FeatureEntry::FeatureVariation
VARIATION_ENTRY(kIPHPreviewsOmniboxUIFeature),
VARIATION_ENTRY(kIPHPwaInstallAvailableFeature),
VARIATION_ENTRY(kIPHQuietNotificationPromptsFeature),
VARIATION_ENTRY(kIPHReadLaterContextMenuFeature),
VARIATION_ENTRY(kIPHTabGroupsQuicklyComparePagesFeature),
VARIATION_ENTRY(kIPHTabGroupsTapToSeeAnotherTabFeature),
VARIATION_ENTRY(kIPHTabGroupsYourTabsAreTogetherFeature),
......
......@@ -12443,6 +12443,7 @@ Called by update_net_error_codes.py.-->
<int value="30" label="Shop Similar Products"/>
<int value="31" label="Shop image with Google Lens"/>
<int value="32" label="Search Similar Products"/>
<int value="33" label="Read later"/>
</enum>
<enum name="ContextMenuOptionDesktop">
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