Add 'Open in new tab' in context menu created from native page for group
This CL modifies the context menu that is created from a native page to include both 'Open in new tab' and 'Open in new tab in group' as context menu items. The order of these two items is determined by TabUiFeatureUtilities#showContextMenuOpenNewTabInGroupItemFirst. Change-Id: I2fa98aaa861a9030e93fe5035668a093e490f989 Bug: 1188370 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2803791 Commit-Queue: Mei Liang <meiliang@chromium.org> Reviewed-by: Caitlin Fischer <caitlinfischer@google.com> Reviewed-by: Justin DeWitt <dewittj@chromium.org> Reviewed-by: Theresa <twellington@chromium.org> Reviewed-by: Cathy Li <chili@chromium.org> Cr-Commit-Position: refs/heads/master@{#885762}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
83c8bff1b8
commit
972a38dcfa
chrome/android
features
start_surface
internal
java
src
org
chromium
chrome
features
start_surface
tab_ui
java
src
org
chromium
chrome
browser
java
src
org
chromium
chrome
tools/metrics/actions
@ -41,6 +41,15 @@ class ExploreSurfaceNavigationDelegate implements NativePageNavigationDelegate {
|
||||
return newTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Tab openUrlInGroup(int windowOpenDisposition, LoadUrlParams loadUrlParams) {
|
||||
// 'open in group' has been disabled in crrev.com/c/2885469. We should never reach this
|
||||
// method.
|
||||
assert false; // NOTREACHED.
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void navigateToHelpPage() {
|
||||
openUrl(WindowOpenDisposition.CURRENT_TAB,
|
||||
|
@ -213,7 +213,9 @@ class MostVisitedListCoordinator implements TileGroup.Observer {
|
||||
* @param url The url to navigate to.
|
||||
*/
|
||||
@Override
|
||||
public void navigateToSuggestionUrl(int windowOpenDisposition, String url) {
|
||||
public void navigateToSuggestionUrl(
|
||||
int windowOpenDisposition, String url, boolean inGroup) {
|
||||
assert !inGroup;
|
||||
switch (windowOpenDisposition) {
|
||||
case WindowOpenDisposition.CURRENT_TAB:
|
||||
case WindowOpenDisposition.NEW_BACKGROUND_TAB:
|
||||
|
6
chrome/android/java/src/org/chromium/chrome/browser/explore_sites/ExploreSitesCategoryCardView.java
6
chrome/android/java/src/org/chromium/chrome/browser/explore_sites/ExploreSitesCategoryCardView.java
@ -110,6 +110,12 @@ public class ExploreSitesCategoryCardView extends LinearLayout {
|
||||
windowDisposition, new LoadUrlParams(getUrl(), PageTransition.AUTO_BOOKMARK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItemInGroup(int windowDisposition) {
|
||||
mNavigationDelegate.openUrlInGroup(
|
||||
windowDisposition, new LoadUrlParams(getUrl(), PageTransition.AUTO_BOOKMARK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeItem() {
|
||||
// Update the database on the C++ side.
|
||||
|
@ -33,9 +33,10 @@ import java.lang.annotation.RetentionPolicy;
|
||||
*/
|
||||
public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
@IntDef({ContextMenuItemId.SEARCH, ContextMenuItemId.OPEN_IN_NEW_TAB,
|
||||
ContextMenuItemId.OPEN_IN_INCOGNITO_TAB, ContextMenuItemId.OPEN_IN_NEW_WINDOW,
|
||||
ContextMenuItemId.SAVE_FOR_OFFLINE, ContextMenuItemId.ADD_TO_MY_APPS,
|
||||
ContextMenuItemId.REMOVE, ContextMenuItemId.LEARN_MORE})
|
||||
ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP, ContextMenuItemId.OPEN_IN_INCOGNITO_TAB,
|
||||
ContextMenuItemId.OPEN_IN_NEW_WINDOW, ContextMenuItemId.SAVE_FOR_OFFLINE,
|
||||
ContextMenuItemId.ADD_TO_MY_APPS, ContextMenuItemId.REMOVE,
|
||||
ContextMenuItemId.LEARN_MORE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ContextMenuItemId {
|
||||
// The order of the items will be based on the value of their ID. So if new items are added,
|
||||
@ -43,14 +44,15 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
// Values are also used for indexing - should start from 0 and can't have gaps.
|
||||
int SEARCH = 0;
|
||||
int OPEN_IN_NEW_TAB = 1;
|
||||
int OPEN_IN_INCOGNITO_TAB = 2;
|
||||
int OPEN_IN_NEW_WINDOW = 3;
|
||||
int SAVE_FOR_OFFLINE = 4;
|
||||
int ADD_TO_MY_APPS = 5;
|
||||
int REMOVE = 6;
|
||||
int LEARN_MORE = 7;
|
||||
int OPEN_IN_NEW_TAB_IN_GROUP = 2;
|
||||
int OPEN_IN_INCOGNITO_TAB = 3;
|
||||
int OPEN_IN_NEW_WINDOW = 4;
|
||||
int SAVE_FOR_OFFLINE = 5;
|
||||
int ADD_TO_MY_APPS = 6;
|
||||
int REMOVE = 7;
|
||||
int LEARN_MORE = 8;
|
||||
|
||||
int NUM_ENTRIES = 8;
|
||||
int NUM_ENTRIES = 9;
|
||||
}
|
||||
|
||||
private final NativePageNavigationDelegate mNavigationDelegate;
|
||||
@ -64,6 +66,11 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
/** Opens the current item the way specified by {@code windowDisposition}. */
|
||||
void openItem(int windowDisposition);
|
||||
|
||||
/**
|
||||
* Opens the current item the way specified by {@code windowDisposition} in a group.
|
||||
*/
|
||||
void openItemInGroup(int windowDisposition);
|
||||
|
||||
/** Remove the current item. */
|
||||
void removeItem();
|
||||
|
||||
@ -94,6 +101,9 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
@Override
|
||||
public void openItem(int windowDisposition) {}
|
||||
|
||||
@Override
|
||||
public void openItemInGroup(int windowDisposition) {}
|
||||
|
||||
@Override
|
||||
public void removeItem() {}
|
||||
|
||||
@ -152,7 +162,32 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
boolean hasItems = false;
|
||||
|
||||
for (@ContextMenuItemId int itemId = 0; itemId < ContextMenuItemId.NUM_ENTRIES; itemId++) {
|
||||
if (!shouldShowItem(itemId, delegate)) continue;
|
||||
if (!shouldShowItem(itemId, delegate)
|
||||
|| itemId == ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (itemId == ContextMenuItemId.OPEN_IN_NEW_TAB
|
||||
&& shouldShowItem(ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP, delegate)) {
|
||||
if (TabUiFeatureUtilities.showContextMenuOpenNewTabInGroupItemFirst()) {
|
||||
menu.add(Menu.NONE, ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP, Menu.NONE,
|
||||
getResourceIdForMenuItem(
|
||||
ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP))
|
||||
.setOnMenuItemClickListener(listener);
|
||||
menu.add(Menu.NONE, itemId, Menu.NONE, getResourceIdForMenuItem(itemId))
|
||||
.setOnMenuItemClickListener(listener);
|
||||
} else {
|
||||
menu.add(Menu.NONE, itemId, Menu.NONE, getResourceIdForMenuItem(itemId))
|
||||
.setOnMenuItemClickListener(listener);
|
||||
menu.add(Menu.NONE, ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP, Menu.NONE,
|
||||
getResourceIdForMenuItem(
|
||||
ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP))
|
||||
.setOnMenuItemClickListener(listener);
|
||||
}
|
||||
hasItems = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
menu.add(Menu.NONE, itemId, Menu.NONE, getResourceIdForMenuItem(itemId))
|
||||
.setOnMenuItemClickListener(listener);
|
||||
hasItems = true;
|
||||
@ -221,6 +256,9 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
return false;
|
||||
case ContextMenuItemId.OPEN_IN_NEW_TAB:
|
||||
return true;
|
||||
case ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP:
|
||||
return !TabUiFeatureUtilities.ENABLE_TAB_GROUP_AUTO_CREATION.getValue()
|
||||
&& mNavigationDelegate.isOpenInNewTabInGroupEnabled();
|
||||
case ContextMenuItemId.OPEN_IN_INCOGNITO_TAB:
|
||||
return mNavigationDelegate.isOpenInIncognitoEnabled();
|
||||
case ContextMenuItemId.OPEN_IN_NEW_WINDOW:
|
||||
@ -248,9 +286,12 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
switch (id) {
|
||||
case ContextMenuItemId.OPEN_IN_NEW_TAB:
|
||||
return (TabUiFeatureUtilities.isTabGroupsAndroidEnabled()
|
||||
&& TabUiFeatureUtilities.ENABLE_TAB_GROUP_AUTO_CREATION.getValue()
|
||||
&& mNavigationDelegate.isOpenInNewTabInGroupEnabled())
|
||||
? R.string.contextmenu_open_in_new_tab_group
|
||||
: R.string.contextmenu_open_in_new_tab;
|
||||
case ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP:
|
||||
return R.string.contextmenu_open_in_new_tab_group;
|
||||
case ContextMenuItemId.OPEN_IN_INCOGNITO_TAB:
|
||||
return R.string.contextmenu_open_in_incognito_tab;
|
||||
case ContextMenuItemId.OPEN_IN_NEW_WINDOW:
|
||||
@ -278,6 +319,10 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
|
||||
delegate.openItem(WindowOpenDisposition.NEW_BACKGROUND_TAB);
|
||||
RecordUserAction.record(mUserActionPrefix + ".ContextMenu.OpenItemInNewTab");
|
||||
return true;
|
||||
case ContextMenuItemId.OPEN_IN_NEW_TAB_IN_GROUP:
|
||||
delegate.openItemInGroup(WindowOpenDisposition.NEW_BACKGROUND_TAB);
|
||||
RecordUserAction.record(mUserActionPrefix + ".ContextMenu.OpenItemInNewTabInGroup");
|
||||
return true;
|
||||
case ContextMenuItemId.OPEN_IN_INCOGNITO_TAB:
|
||||
delegate.openItem(WindowOpenDisposition.OFF_THE_RECORD);
|
||||
RecordUserAction.record(mUserActionPrefix + ".ContextMenu.OpenItemInIncognitoTab");
|
||||
|
@ -39,4 +39,11 @@ public interface NativePageNavigationDelegate {
|
||||
*/
|
||||
@Nullable
|
||||
Tab openUrl(int windowOpenDisposition, LoadUrlParams loadUrlParams);
|
||||
|
||||
/**
|
||||
* Opens an URL with the desired disposition in a tab in group.
|
||||
* @return The tab where the URL is being loaded.
|
||||
*/
|
||||
@Nullable
|
||||
Tab openUrlInGroup(int windowOpenDisposition, LoadUrlParams loadUrlParams);
|
||||
}
|
||||
|
@ -80,6 +80,12 @@ public class NativePageNavigationDelegateImpl implements NativePageNavigationDel
|
||||
return loadingTab;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tab openUrlInGroup(int windowOpenDisposition, LoadUrlParams loadUrlParams) {
|
||||
return mTabModelSelector.openNewTab(loadUrlParams,
|
||||
TabLaunchType.FROM_LONGPRESS_BACKGROUND_IN_GROUP, mTab, /* incognito = */ false);
|
||||
}
|
||||
|
||||
private void openUrlInNewWindow(LoadUrlParams loadUrlParams) {
|
||||
TabDelegate tabDelegate = new TabDelegate(false);
|
||||
tabDelegate.createTabInOtherWindow(loadUrlParams, mActivity, mHost.getParentId());
|
||||
|
9
chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsNavigationDelegate.java
9
chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsNavigationDelegate.java
@ -40,9 +40,14 @@ public class SuggestionsNavigationDelegate extends NativePageNavigationDelegateI
|
||||
*
|
||||
* @param windowOpenDisposition How to open (new window, current tab, etc).
|
||||
* @param url The url to navigate to.
|
||||
* @param inGroup Whether the navigation is in a group.
|
||||
*/
|
||||
public void navigateToSuggestionUrl(int windowOpenDisposition, String url) {
|
||||
public void navigateToSuggestionUrl(int windowOpenDisposition, String url, boolean inGroup) {
|
||||
LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.AUTO_BOOKMARK);
|
||||
openUrl(windowOpenDisposition, loadUrlParams);
|
||||
if (inGroup) {
|
||||
openUrlInGroup(windowOpenDisposition, loadUrlParams);
|
||||
} else {
|
||||
openUrl(windowOpenDisposition, loadUrlParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ public class TileGroup implements MostVisitedSites.Observer {
|
||||
|
||||
void openMostVisitedItem(int windowDisposition, Tile tile);
|
||||
|
||||
void openMostVisitedItemInGroup(int windowDisposition, Tile tile);
|
||||
|
||||
/**
|
||||
* Gets the list of most visited sites.
|
||||
* @param observer The observer to be notified with the list of sites.
|
||||
@ -550,6 +552,14 @@ public class TileGroup implements MostVisitedSites.Observer {
|
||||
mTileGroupDelegate.openMostVisitedItem(windowDisposition, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItemInGroup(int windowDisposition) {
|
||||
Tile tile = findTile(mSuggestion);
|
||||
if (tile == null) return;
|
||||
|
||||
mTileGroupDelegate.openMostVisitedItemInGroup(windowDisposition, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeItem() {
|
||||
Tile tile = findTile(mSuggestion);
|
||||
|
@ -65,7 +65,19 @@ public class TileGroupDelegateImpl implements TileGroup.Delegate {
|
||||
recordOpenedTile(item);
|
||||
}
|
||||
|
||||
mNavigationDelegate.navigateToSuggestionUrl(windowDisposition, url);
|
||||
mNavigationDelegate.navigateToSuggestionUrl(windowDisposition, url, false);
|
||||
QueryTileUtils.onMostVisitedTileClicked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openMostVisitedItemInGroup(int windowDisposition, Tile item) {
|
||||
assert !mIsDestroyed;
|
||||
|
||||
String url = item.getUrl().getSpec();
|
||||
|
||||
recordOpenedTile(item);
|
||||
|
||||
mNavigationDelegate.navigateToSuggestionUrl(windowDisposition, url, true);
|
||||
QueryTileUtils.onMostVisitedTileClicked();
|
||||
}
|
||||
|
||||
|
@ -28416,6 +28416,8 @@ should be able to be added at any place in this file.
|
||||
<suffix name="OpenItemInIncognitoTab"
|
||||
label="Open a suggested item in an incognito tab."/>
|
||||
<suffix name="OpenItemInNewTab" label="Open a suggested item in a new tab."/>
|
||||
<suffix name="OpenItemInNewTabInGroup"
|
||||
label="Open a suggested item in a new tab in group."/>
|
||||
<suffix name="OpenItemInNewWindow"
|
||||
label="Open a suggested item in a new window."/>
|
||||
<suffix name="RemoveItem" label="Remove a suggested item."/>
|
||||
|
Reference in New Issue
Block a user