Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| index 5352ed1ad824e045a1fb6529adb4db81915e9f27..4d6dfb4d316d2005a53f3b32faa8f27a0199570e 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java |
| @@ -7,10 +7,10 @@ package org.chromium.chrome.browser.contextmenu; |
| import android.content.Context; |
| import android.net.MailTo; |
| import android.support.annotation.IntDef; |
| +import android.support.annotation.StringRes; |
| import android.text.TextUtils; |
| +import android.util.Pair; |
| import android.view.ContextMenu; |
| -import android.view.MenuInflater; |
| -import android.view.MenuItem; |
| import android.webkit.MimeTypeMap; |
| import org.chromium.base.CollectionUtil; |
| @@ -25,7 +25,10 @@ import org.chromium.chrome.browser.util.UrlUtilities; |
| import java.lang.annotation.Retention; |
| import java.lang.annotation.RetentionPolicy; |
| +import java.util.ArrayList; |
| +import java.util.Collections; |
| import java.util.HashSet; |
| +import java.util.List; |
| import java.util.Set; |
| /** |
| @@ -40,9 +43,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| */ |
| @Retention(RetentionPolicy.SOURCE) |
| @IntDef({ |
| - NORMAL_MODE, /* Default mode */ |
| - CUSTOM_TAB_MODE, /* Custom tab mode */ |
| - FULLSCREEN_TAB_MODE /* Full screen mode */ |
| + NORMAL_MODE, /* Default mode */ |
| + CUSTOM_TAB_MODE, /* Custom tab mode */ |
| + FULLSCREEN_TAB_MODE /* Full screen mode */ |
| }) |
| public @interface ContextMenuMode {} |
| @@ -50,32 +53,75 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| public static final int CUSTOM_TAB_MODE = 1; |
| public static final int FULLSCREEN_TAB_MODE = 2; |
| + /** |
| + * Defines the Groups of each Context Menu Item |
| + */ |
| + @Retention(RetentionPolicy.SOURCE) |
| + @IntDef({LINK, IMAGE, VIDEO, CUSTOM, OTHER}) |
| + public @interface ContextMenuGroup {} |
| + |
| + public static final int LINK = 0; |
| + public static final int IMAGE = 1; |
| + public static final int VIDEO = 2; |
| + public static final int CUSTOM = 3; |
| + public static final int OTHER = 4; |
| + |
| // Items that are included in all context menus. |
| - private static final Set<Integer> BASE_WHITELIST = CollectionUtil.newHashSet( |
| - R.id.contextmenu_copy_link_address, R.id.contextmenu_call, |
| - R.id.contextmenu_send_message, R.id.contextmenu_add_to_contacts, R.id.contextmenu_copy, |
| - R.id.contextmenu_copy_link_text, R.id.contextmenu_load_original_image, |
| - R.id.contextmenu_save_link_as, R.id.contextmenu_save_image, |
| - R.id.contextmenu_share_image, R.id.contextmenu_save_video); |
| + private static final Set<ContextMenuItem> BASE_WHITELIST = |
| + Collections.unmodifiableSet(CollectionUtil.newHashSet(ContextMenuItem.COPY_LINK_ADDRESS, |
| + ContextMenuItem.CALL, ContextMenuItem.SEND_MESSAGE, |
| + ContextMenuItem.ADD_TO_CONTACTS, ContextMenuItem.COPY, |
| + ContextMenuItem.COPY_LINK_TEXT, ContextMenuItem.LOAD_ORIGINAL_IMAGE, |
| + ContextMenuItem.SAVE_LINK_AS, ContextMenuItem.SAVE_IMAGE, |
| + ContextMenuItem.SHARE_IMAGE, ContextMenuItem.SAVE_VIDEO)); |
| // Items that are included for normal Chrome browser mode. |
| - private static final Set<Integer> NORMAL_MODE_WHITELIST = CollectionUtil.newHashSet( |
| - R.id.contextmenu_open_in_new_tab, R.id.contextmenu_open_in_other_window, |
| - R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_save_link_as, |
| - R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_by_image); |
| + private static final Set<ContextMenuItem> NORMAL_MODE_WHITELIST = |
| + Collections.unmodifiableSet(CollectionUtil.newHashSet(ContextMenuItem.OPEN_IN_NEW_TAB, |
| + ContextMenuItem.OPEN_IN_OTHER_WINDOW, ContextMenuItem.OPEN_IN_INCOGNITO_TAB, |
| + ContextMenuItem.SAVE_LINK_AS, ContextMenuItem.OPEN_IMAGE_IN_NEW_TAB, |
| + ContextMenuItem.SEARCH_BY_IMAGE)); |
| // Additional items for custom tabs mode. |
| - private static final Set<Integer> CUSTOM_TAB_MODE_WHITELIST = CollectionUtil.newHashSet( |
| - R.id.contextmenu_open_image, R.id.contextmenu_search_by_image, |
| - R.id.contextmenu_open_in_new_chrome_tab, R.id.contextmenu_open_in_chrome_incognito_tab, |
| - R.id.contextmenu_open_in_browser_id); |
| + private static final Set<ContextMenuItem> CUSTOM_TAB_MODE_WHITELIST = |
| + Collections.unmodifiableSet(CollectionUtil.newHashSet(ContextMenuItem.OPEN_IMAGE, |
| + ContextMenuItem.SEARCH_BY_IMAGE, ContextMenuItem.OPEN_IN_NEW_CHROME_TAB, |
| + ContextMenuItem.OPEN_IN_CHROME_INCOGNITO_TAB, |
| + ContextMenuItem.OPEN_IN_BROWSER_ID)); |
| // Additional items for fullscreen tabs mode. |
| - private static final Set<Integer> FULLSCREEN_TAB_MODE_WHITELIST = |
| - CollectionUtil.newHashSet(R.id.menu_id_open_in_chrome); |
| + private static final Set<ContextMenuItem> FULLSCREEN_TAB_MODE_WHITELIST = |
| + Collections.unmodifiableSet(CollectionUtil.newHashSet(ContextMenuItem.OPEN_IN_CHROME)); |
| + |
| + // The order of the items within each lists determines the order of the context menu. |
| + private static final List<ContextMenuItem> CUSTOM_TAB_GROUP = Collections.unmodifiableList( |
| + CollectionUtil.newArrayList(ContextMenuItem.OPEN_IN_NEW_CHROME_TAB, |
| + ContextMenuItem.OPEN_IN_CHROME_INCOGNITO_TAB, |
| + ContextMenuItem.OPEN_IN_BROWSER_ID)); |
| + |
| + private static final List<ContextMenuItem> LINK_GROUP = |
| + Collections.unmodifiableList(CollectionUtil.newArrayList( |
| + ContextMenuItem.OPEN_IN_OTHER_WINDOW, ContextMenuItem.OPEN_IN_NEW_TAB, |
| + ContextMenuItem.OPEN_IN_INCOGNITO_TAB, ContextMenuItem.COPY_LINK_ADDRESS, |
| + ContextMenuItem.COPY_LINK_TEXT, ContextMenuItem.SAVE_LINK_AS)); |
| + |
| + private static final List<ContextMenuItem> IMAGE_GROUP = |
| + Collections.unmodifiableList(CollectionUtil.newArrayList( |
| + ContextMenuItem.LOAD_ORIGINAL_IMAGE, ContextMenuItem.SAVE_IMAGE, |
| + ContextMenuItem.OPEN_IMAGE, ContextMenuItem.OPEN_IMAGE_IN_NEW_TAB, |
| + ContextMenuItem.SEARCH_BY_IMAGE, ContextMenuItem.SHARE_IMAGE)); |
| + |
| + private static final List<ContextMenuItem> MESSAGE_GROUP = Collections.unmodifiableList( |
| + CollectionUtil.newArrayList(ContextMenuItem.CALL, ContextMenuItem.SEND_MESSAGE, |
| + ContextMenuItem.ADD_TO_CONTACTS, ContextMenuItem.COPY)); |
| + |
| + private static final List<ContextMenuItem> VIDEO_GROUP = |
| + Collections.unmodifiableList(CollectionUtil.newArrayList(ContextMenuItem.SAVE_VIDEO)); |
| + |
| + private static final List<ContextMenuItem> OTHER_GROUP = Collections.unmodifiableList( |
| + CollectionUtil.newArrayList(ContextMenuItem.OPEN_IN_CHROME)); |
| private final ContextMenuItemDelegate mDelegate; |
| - private MenuInflater mMenuInflater; |
| private final int mMode; |
| static class ContextMenuUma { |
| @@ -178,141 +224,225 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| mDelegate.onDestroy(); |
| } |
| - @Override |
| - public void buildContextMenu(ContextMenu menu, Context context, ContextMenuParams params) { |
| + /** |
| + * Gets the link of the item or the alternate text of an image. |
| + * @return A string with either the link or with the alternate text. |
| + */ |
| + public static String createHeaderText(ContextMenuParams params) { |
| + String titleText = ""; |
| if (!TextUtils.isEmpty(params.getLinkUrl()) |
| && !params.getLinkUrl().equals(UrlConstants.ABOUT_BLANK_DISPLAY_URL)) { |
| - setHeaderText(context, menu, params.getLinkUrl()); |
| + titleText = params.getLinkUrl(); |
| } else if (!TextUtils.isEmpty(params.getTitleText())) { |
| - setHeaderText(context, menu, params.getTitleText()); |
| + titleText = params.getTitleText(); |
| } |
| + return titleText; |
| + } |
| - if (params.isFile()) return; |
| - |
| - if (mMenuInflater == null) mMenuInflater = new MenuInflater(context); |
| - |
| - mMenuInflater.inflate(R.menu.chrome_context_menu, menu); |
| - |
| - menu.setGroupVisible(R.id.contextmenu_group_anchor, params.isAnchor()); |
| - menu.setGroupVisible(R.id.contextmenu_group_image, params.isImage()); |
| - menu.setGroupVisible(R.id.contextmenu_group_video, params.isVideo()); |
| - menu.setGroupVisible(R.id.contextmenu_group_message, |
| - MailTo.isMailTo(params.getLinkUrl()) |
| - || UrlUtilities.isTelScheme(params.getLinkUrl())); |
| - |
| - Set<Integer> supportedOptions = new HashSet<>(); |
| + @Override |
| + public List<Pair<Integer, List<ContextMenuItem>>> buildContextMenu( |
| + ContextMenu menu, Context context, ContextMenuParams params) { |
| + // Add all items in a group |
| + Set<ContextMenuItem> supportedOptions = new HashSet<>(); |
| supportedOptions.addAll(BASE_WHITELIST); |
| if (mMode == FULLSCREEN_TAB_MODE) { |
| supportedOptions.addAll(FULLSCREEN_TAB_MODE_WHITELIST); |
| } else if (mMode == CUSTOM_TAB_MODE) { |
| supportedOptions.addAll(CUSTOM_TAB_MODE_WHITELIST); |
| - if (!ChromePreferenceManager.getInstance().getCachedChromeDefaultBrowser()) { |
| - menu.findItem(R.id.contextmenu_open_in_browser_id) |
| - .setTitle(mDelegate.getTitleForOpenTabInExternalApp()); |
| - } |
| } else { |
| supportedOptions.addAll(NORMAL_MODE_WHITELIST); |
| } |
| - Set<Integer> disabledOptions = getDisabledOptions(params); |
| - // Iterate through the entire menu list, if if doesn't exist in the map, don't show it. |
| - for (int i = 0; i < menu.size(); i++) { |
| - MenuItem item = menu.getItem(i); |
| - if (!item.isVisible()) continue; |
| - item.setVisible(supportedOptions.contains(item.getItemId()) |
| - && !disabledOptions.contains(item.getItemId())); |
| + Set<ContextMenuItem> disabledOptions = getDisabledOptions(params); |
| + Set<ContextMenuItem> menuOptions = new HashSet<>(); |
| + for (ContextMenuItem item : supportedOptions) { |
| + if (!disabledOptions.contains(item)) { |
| + menuOptions.add(item); |
| + } |
| } |
| - // Special case for searching by image element. |
| - if (supportedOptions.contains(R.id.contextmenu_search_by_image)) { |
| - menu.findItem(R.id.contextmenu_search_by_image) |
| - .setTitle(context.getString(R.string.contextmenu_search_web_for_image, |
| - TemplateUrlService.getInstance() |
| - .getDefaultSearchEngineTemplateUrl() |
| - .getShortName())); |
| + // Split the items into their respective groups. |
| + List<Pair<Integer, List<ContextMenuItem>>> groupedItems = new ArrayList<>(); |
| + if (params.isAnchor()) { |
| + populateItemGroup(LINK, R.string.contextmenu_link_title, groupedItems, supportedOptions, |
| + disabledOptions); |
| + } |
| + if (params.isImage()) { |
| + populateItemGroup(IMAGE, R.string.contextmenu_image_title, groupedItems, |
| + supportedOptions, disabledOptions); |
| + } |
| + if (params.isVideo()) { |
| + populateItemGroup(VIDEO, R.string.contextmenu_video_title, groupedItems, |
| + supportedOptions, disabledOptions); |
| + } |
| + // Handles special cases for custom tabs and fullscreen that are added to the top of the |
| + // context menu. |
| + List<ContextMenuItem> firstGroup = groupedItems.isEmpty() ? new ArrayList<ContextMenuItem>() |
| + : groupedItems.get(0).second; |
| + // If we have values or if it's entirely empty |
| + if (groupedItems.isEmpty()) { |
| + int titleResId = R.string.contextmenu_video_title; |
| + |
| + if (params.isAnchor()) { |
| + titleResId = R.string.contextmenu_link_title; |
| + } else if (params.isImage()) { |
| + titleResId = R.string.contextmenu_image_title; |
| + } |
| + groupedItems.add(new Pair<Integer, List<ContextMenuItem>>( |
| + titleResId, new ArrayList<ContextMenuItem>())); |
|
Ted C
2017/03/14 05:23:58
you need to use firstGroup here I think
JJ
2017/03/14 17:39:17
Sorry check the most recent version it has the cha
|
| + } |
| + |
| + List<ContextMenuItem> validItems = new ArrayList<>(); |
| + addValidItems(validItems, OTHER_GROUP, supportedOptions, disabledOptions); |
| + if (!validItems.isEmpty()) { |
| + groupedItems.get(groupedItems.size() - 1).second.addAll(validItems); |
|
Ted C
2017/03/14 05:23:58
sigh...this logic is sadly confusing at this point
JJ
2017/03/14 17:39:17
So I agree with the first change and the most rece
Ted C
2017/03/14 18:10:58
I think we should keep the logic as is. My commen
|
| + } |
| + |
| + if (mMode == CUSTOM_TAB_MODE) { |
| + validItems = new ArrayList<>(); |
| + addValidItems(validItems, CUSTOM_TAB_GROUP, supportedOptions, disabledOptions); |
| + if (!validItems.isEmpty()) { |
| + firstGroup.addAll(0, validItems); |
| + } |
| + } |
| + |
| + // Since we add a new item, on the off chance that there is nothing in it, we remove it. |
| + if (groupedItems.get(0).second.isEmpty()) { |
| + groupedItems.remove(0); |
| + } |
| + |
| + return groupedItems; |
| + } |
| + |
| + private void populateItemGroup(@ContextMenuGroup int contextMenuType, @StringRes int titleResId, |
| + List<Pair<Integer, List<ContextMenuItem>>> itemGroups, |
| + Set<ContextMenuItem> supportedOptions, Set<ContextMenuItem> disabledOptions) { |
| + List<ContextMenuItem> items = new ArrayList<>(); |
| + switch (contextMenuType) { |
| + case LINK: |
| + addValidItems(items, LINK_GROUP, supportedOptions, disabledOptions); |
| + addValidItems(items, MESSAGE_GROUP, supportedOptions, disabledOptions); |
| + break; |
| + case IMAGE: |
| + addValidItems(items, IMAGE_GROUP, supportedOptions, disabledOptions); |
| + break; |
| + case VIDEO: |
| + addValidItems(items, VIDEO_GROUP, supportedOptions, disabledOptions); |
| + break; |
| + // Handled in {@link #buildContextMenu} |
| + case OTHER: |
| + case CUSTOM: |
| + break; |
| + } |
| + |
| + if (items.isEmpty()) return; |
| + |
| + itemGroups.add(new Pair<>(titleResId, items)); |
| + } |
| + |
| + private void addValidItems(List<ContextMenuItem> validItems, List<ContextMenuItem> allItems, |
| + Set<ContextMenuItem> supportedOptions, Set<ContextMenuItem> disabledOptions) { |
| + for (int i = 0; i < allItems.size(); i++) { |
| + ContextMenuItem item = allItems.get(i); |
| + if (supportedOptions.contains(item) && !disabledOptions.contains(item)) { |
| + validItems.add(item); |
| + } |
| } |
| } |
| /** |
| * Given a set of params. It creates a list of items that should not be accessible in specific |
| - * instances. Since it doesn't have access to the menu groups, they need to be filtered outside |
| - * of this method. |
| + * instances. |
| * @param params The parameters used to create a list of items that should not be allowed. |
| */ |
| - private Set<Integer> getDisabledOptions(ContextMenuParams params) { |
| - Set<Integer> disabledOptions = new HashSet<>(); |
| + private Set<ContextMenuItem> getDisabledOptions(ContextMenuParams params) { |
| + Set<ContextMenuItem> disabledOptions = new HashSet<>(); |
| + if (!params.isAnchor()) { |
| + disabledOptions.addAll(LINK_GROUP); |
| + } |
| + if (!params.isImage()) { |
| + disabledOptions.addAll(IMAGE_GROUP); |
| + } |
| + if (!params.isVideo()) { |
| + disabledOptions.addAll(VIDEO_GROUP); |
| + } |
| + if (!MailTo.isMailTo(params.getLinkUrl()) |
| + && !UrlUtilities.isTelScheme(params.getLinkUrl())) { |
| + disabledOptions.addAll(MESSAGE_GROUP); |
| + } |
| + |
| if (params.isAnchor() && !mDelegate.isOpenInOtherWindowSupported()) { |
| - disabledOptions.add(R.id.contextmenu_open_in_other_window); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); |
| } |
| if (mDelegate.isIncognito() || !mDelegate.isIncognitoSupported()) { |
| - disabledOptions.add(R.id.contextmenu_open_in_incognito_tab); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); |
| } |
| if (params.getLinkText().trim().isEmpty() || params.isImage()) { |
| - disabledOptions.add(R.id.contextmenu_copy_link_text); |
| + disabledOptions.add(ContextMenuItem.COPY_LINK_TEXT); |
| } |
| if (params.isAnchor() && !UrlUtilities.isAcceptedScheme(params.getLinkUrl())) { |
| - disabledOptions.add(R.id.contextmenu_open_in_other_window); |
| - disabledOptions.add(R.id.contextmenu_open_in_new_tab); |
| - disabledOptions.add(R.id.contextmenu_open_in_incognito_tab); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); |
| } |
| if (MailTo.isMailTo(params.getLinkUrl())) { |
| - disabledOptions.add(R.id.contextmenu_copy_link_text); |
| - disabledOptions.add(R.id.contextmenu_copy_link_address); |
| + disabledOptions.add(ContextMenuItem.COPY_LINK_TEXT); |
| + disabledOptions.add(ContextMenuItem.COPY_LINK_ADDRESS); |
| if (!mDelegate.supportsSendEmailMessage()) { |
| - disabledOptions.add(R.id.contextmenu_send_message); |
| + disabledOptions.add(ContextMenuItem.SEND_MESSAGE); |
| } |
| if (TextUtils.isEmpty(MailTo.parse(params.getLinkUrl()).getTo()) |
| || !mDelegate.supportsAddToContacts()) { |
| - disabledOptions.add(R.id.contextmenu_add_to_contacts); |
| + disabledOptions.add(ContextMenuItem.ADD_TO_CONTACTS); |
| } |
| - disabledOptions.add(R.id.contextmenu_call); |
| + disabledOptions.add(ContextMenuItem.CALL); |
| } else if (UrlUtilities.isTelScheme(params.getLinkUrl())) { |
| - disabledOptions.add(R.id.contextmenu_copy_link_text); |
| - disabledOptions.add(R.id.contextmenu_copy_link_address); |
| + disabledOptions.add(ContextMenuItem.COPY_LINK_TEXT); |
| + disabledOptions.add(ContextMenuItem.COPY_LINK_ADDRESS); |
| if (!mDelegate.supportsCall()) { |
| - disabledOptions.add(R.id.contextmenu_call); |
| + disabledOptions.add(ContextMenuItem.CALL); |
| } |
| if (!mDelegate.supportsSendTextMessage()) { |
| - disabledOptions.add(R.id.contextmenu_send_message); |
| + disabledOptions.add(ContextMenuItem.SEND_MESSAGE); |
| } |
| if (!mDelegate.supportsAddToContacts()) { |
| - disabledOptions.add(R.id.contextmenu_add_to_contacts); |
| + disabledOptions.add(ContextMenuItem.ADD_TO_CONTACTS); |
| } |
| } |
| if (!UrlUtilities.isDownloadableScheme(params.getLinkUrl())) { |
| - disabledOptions.add(R.id.contextmenu_save_link_as); |
| + disabledOptions.add(ContextMenuItem.SAVE_LINK_AS); |
| } |
| boolean isSrcDownloadableScheme = UrlUtilities.isDownloadableScheme(params.getSrcUrl()); |
| if (params.isVideo()) { |
| boolean saveableAndDownloadable = params.canSaveMedia() && isSrcDownloadableScheme; |
| if (!saveableAndDownloadable) { |
| - disabledOptions.add(R.id.contextmenu_save_video); |
| + disabledOptions.add(ContextMenuItem.SAVE_VIDEO); |
| } |
| } else if (params.isImage() && params.imageWasFetchedLoFi()) { |
| DataReductionProxyUma.previewsLoFiContextMenuAction( |
| DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGE_CONTEXT_MENU_SHOWN); |
| // All image context menu items other than "Load image," "Open original image in |
| // new tab," and "Copy image URL" should be disabled on Lo-Fi images. |
| - disabledOptions.add(R.id.contextmenu_save_image); |
| - disabledOptions.add(R.id.contextmenu_open_image); |
| - disabledOptions.add(R.id.contextmenu_search_by_image); |
| - disabledOptions.add(R.id.contextmenu_share_image); |
| + disabledOptions.add(ContextMenuItem.SAVE_IMAGE); |
| + disabledOptions.add(ContextMenuItem.OPEN_IMAGE); |
| + disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); |
| + disabledOptions.add(ContextMenuItem.SHARE_IMAGE); |
| } else if (params.isImage() && !params.imageWasFetchedLoFi()) { |
| - disabledOptions.add(R.id.contextmenu_load_original_image); |
| + disabledOptions.add(ContextMenuItem.LOAD_ORIGINAL_IMAGE); |
| if (!isSrcDownloadableScheme) { |
| - disabledOptions.add(R.id.contextmenu_save_image); |
| + disabledOptions.add(ContextMenuItem.SAVE_IMAGE); |
| } |
| // Avoid showing open image option for same image which is already opened. |
| if (mDelegate.getPageUrl().equals(params.getSrcUrl())) { |
| - disabledOptions.add(R.id.contextmenu_open_image); |
| + disabledOptions.add(ContextMenuItem.OPEN_IMAGE); |
| } |
| final TemplateUrlService templateUrlServiceInstance = TemplateUrlService.getInstance(); |
| final boolean isSearchByImageAvailable = isSrcDownloadableScheme |
| @@ -321,26 +451,26 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| && templateUrlServiceInstance.getDefaultSearchEngineTemplateUrl() != null; |
| if (!isSearchByImageAvailable) { |
| - disabledOptions.add(R.id.contextmenu_search_by_image); |
| + disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); |
| } |
| } |
| // Hide all items that could spawn additional tabs until FRE has been completed. |
| if (!FirstRunStatus.getFirstRunFlowComplete()) { |
| - disabledOptions.add(R.id.contextmenu_open_image_in_new_tab); |
| - disabledOptions.add(R.id.contextmenu_open_in_other_window); |
| - disabledOptions.add(R.id.contextmenu_open_in_new_tab); |
| - disabledOptions.add(R.id.contextmenu_open_in_incognito_tab); |
| - disabledOptions.add(R.id.contextmenu_search_by_image); |
| - disabledOptions.add(R.id.menu_id_open_in_chrome); |
| + disabledOptions.add(ContextMenuItem.OPEN_IMAGE_IN_NEW_TAB); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_OTHER_WINDOW); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_TAB); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_INCOGNITO_TAB); |
| + disabledOptions.add(ContextMenuItem.SEARCH_BY_IMAGE); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_CHROME); |
| } |
| if (mMode == CUSTOM_TAB_MODE) { |
| if (ChromePreferenceManager.getInstance().getCachedChromeDefaultBrowser()) { |
| - disabledOptions.add(R.id.contextmenu_open_in_browser_id); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_BROWSER_ID); |
| } else { |
| - disabledOptions.add(R.id.contextmenu_open_in_new_chrome_tab); |
| - disabledOptions.add(R.id.contextmenu_open_in_chrome_incognito_tab); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_NEW_CHROME_TAB); |
| + disabledOptions.add(ContextMenuItem.OPEN_IN_CHROME_INCOGNITO_TAB); |
| } |
| } |
| @@ -349,22 +479,22 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| @Override |
| public boolean onItemSelected(ContextMenuHelper helper, ContextMenuParams params, int itemId) { |
| - if (itemId == R.id.contextmenu_open_in_other_window) { |
| + if (itemId == R.id.context_menu_open_in_other_window) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_OTHER_WINDOW); |
| mDelegate.onOpenInOtherWindow(params.getLinkUrl(), params.getReferrer()); |
| - } else if (itemId == R.id.contextmenu_open_in_new_tab) { |
| + } else if (itemId == R.id.context_menu_open_in_new_tab) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_NEW_TAB); |
| mDelegate.onOpenInNewTab(params.getLinkUrl(), params.getReferrer()); |
| - } else if (itemId == R.id.contextmenu_open_in_incognito_tab) { |
| + } else if (itemId == R.id.context_menu_open_in_incognito_tab) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IN_INCOGNITO_TAB); |
| mDelegate.onOpenInNewIncognitoTab(params.getLinkUrl()); |
| - } else if (itemId == R.id.contextmenu_open_image) { |
| + } else if (itemId == R.id.context_menu_open_image) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IMAGE); |
| mDelegate.onOpenImageUrl(params.getSrcUrl(), params.getReferrer()); |
| - } else if (itemId == R.id.contextmenu_open_image_in_new_tab) { |
| + } else if (itemId == R.id.context_menu_open_image_in_new_tab) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IMAGE_IN_NEW_TAB); |
| mDelegate.onOpenImageInNewTab(params.getSrcUrl(), params.getReferrer()); |
| - } else if (itemId == R.id.contextmenu_load_original_image) { |
| + } else if (itemId == R.id.context_menu_load_original_image) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_LOAD_ORIGINAL_IMAGE); |
| DataReductionProxyUma.previewsLoFiContextMenuAction( |
| DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGE_CONTEXT_MENU_CLICKED); |
| @@ -373,14 +503,14 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| DataReductionProxyUma.ACTION_LOFI_LOAD_IMAGE_CONTEXT_MENU_CLICKED_ON_PAGE); |
| } |
| mDelegate.onLoadOriginalImage(); |
| - } else if (itemId == R.id.contextmenu_copy_link_address) { |
| + } else if (itemId == R.id.context_menu_copy_link_address) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_LINK_ADDRESS); |
| mDelegate.onSaveToClipboard(params.getUnfilteredLinkUrl(), |
| ContextMenuItemDelegate.CLIPBOARD_TYPE_LINK_URL); |
| - } else if (itemId == R.id.contextmenu_call) { |
| + } else if (itemId == R.id.context_menu_call) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_CALL); |
| mDelegate.onCall(params.getLinkUrl()); |
| - } else if (itemId == R.id.contextmenu_send_message) { |
| + } else if (itemId == R.id.context_menu_send_message) { |
| if (MailTo.isMailTo(params.getLinkUrl())) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SEND_EMAIL); |
| mDelegate.onSendEmailMessage(params.getLinkUrl()); |
| @@ -388,10 +518,10 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SEND_TEXT_MESSAGE); |
| mDelegate.onSendTextMessage(params.getLinkUrl()); |
| } |
| - } else if (itemId == R.id.contextmenu_add_to_contacts) { |
| + } else if (itemId == R.id.context_menu_add_to_contacts) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_ADD_TO_CONTACTS); |
| mDelegate.onAddToContacts(params.getLinkUrl()); |
| - } else if (itemId == R.id.contextmenu_copy) { |
| + } else if (itemId == R.id.context_menu_copy) { |
| if (MailTo.isMailTo(params.getLinkUrl())) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_EMAIL_ADDRESS); |
| mDelegate.onSaveToClipboard(MailTo.parse(params.getLinkUrl()).getTo(), |
| @@ -401,41 +531,41 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| mDelegate.onSaveToClipboard(UrlUtilities.getTelNumber(params.getLinkUrl()), |
| ContextMenuItemDelegate.CLIPBOARD_TYPE_LINK_URL); |
| } |
| - } else if (itemId == R.id.contextmenu_copy_link_text) { |
| + } else if (itemId == R.id.context_menu_copy_link_text) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_COPY_LINK_TEXT); |
| mDelegate.onSaveToClipboard( |
| params.getLinkText(), ContextMenuItemDelegate.CLIPBOARD_TYPE_LINK_TEXT); |
| - } else if (itemId == R.id.contextmenu_save_image) { |
| + } else if (itemId == R.id.context_menu_save_image) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_IMAGE); |
| if (mDelegate.startDownload(params.getSrcUrl(), false)) { |
| helper.startContextMenuDownload( |
| false, mDelegate.isDataReductionProxyEnabledForURL(params.getSrcUrl())); |
| } |
| - } else if (itemId == R.id.contextmenu_save_video) { |
| + } else if (itemId == R.id.context_menu_save_video) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_VIDEO); |
| if (mDelegate.startDownload(params.getSrcUrl(), false)) { |
| helper.startContextMenuDownload(false, false); |
| } |
| - } else if (itemId == R.id.contextmenu_save_link_as) { |
| + } else if (itemId == R.id.context_menu_save_link_as) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SAVE_LINK); |
| String url = params.getUnfilteredLinkUrl(); |
| if (mDelegate.startDownload(url, true)) { |
| ContextMenuUma.recordSaveLinkTypes(url); |
| helper.startContextMenuDownload(true, false); |
| } |
| - } else if (itemId == R.id.contextmenu_search_by_image) { |
| + } else if (itemId == R.id.context_menu_search_by_image) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SEARCH_BY_IMAGE); |
| helper.searchForImage(); |
| - } else if (itemId == R.id.contextmenu_share_image) { |
| + } else if (itemId == R.id.context_menu_share_image) { |
| ContextMenuUma.record(params, ContextMenuUma.ACTION_SHARE_IMAGE); |
| helper.shareImage(); |
| } else if (itemId == R.id.menu_id_open_in_chrome) { |
| mDelegate.onOpenInChrome(params.getLinkUrl(), params.getPageUrl()); |
| - } else if (itemId == R.id.contextmenu_open_in_new_chrome_tab) { |
| + } else if (itemId == R.id.context_menu_open_in_new_chrome_tab) { |
| mDelegate.onOpenInNewChromeTabFromCCT(getUrl(params), false); |
| - } else if (itemId == R.id.contextmenu_open_in_chrome_incognito_tab) { |
| + } else if (itemId == R.id.context_menu_open_in_chrome_incognito_tab) { |
| mDelegate.onOpenInNewChromeTabFromCCT(getUrl(params), true); |
| - } else if (itemId == R.id.contextmenu_open_in_browser_id) { |
| + } else if (itemId == R.id.context_menu_open_in_browser_id) { |
| mDelegate.onOpenInDefaultBrowser(params.getLinkUrl()); |
| } else { |
| assert false; |
| @@ -456,9 +586,4 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { |
| return params.getLinkUrl(); |
| } |
| } |
| - |
| - private void setHeaderText(Context context, ContextMenu menu, String text) { |
| - ContextMenuTitleView title = new ContextMenuTitleView(context, text); |
| - menu.setHeaderView(title); |
| - } |
| } |