Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit e07e155

Browse files
authored
Do not include copy link context menu item for file based resources (#3332)
1 parent a085a98 commit e07e155

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/WindowWidget.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,10 @@ public void onContextMenu(GeckoSession session, int screenX, int screenY, Contex
16091609
mContextMenu.mWidgetPlacement.parentHandle = getHandle();
16101610
mContextMenu.setDismissCallback(this::hideContextMenus);
16111611
mContextMenu.setContextElement(element);
1612+
if (!mContextMenu.hasActions()) {
1613+
hideContextMenus();
1614+
return;
1615+
}
16121616
mContextMenu.show(REQUEST_FOCUS);
16131617

16141618
mWidgetPlacement.tintColor = 0x555555FF;

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/menus/ContextMenuWidget.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.mozilla.vrbrowser.utils.UrlUtils;
2525

2626
import java.util.ArrayList;
27+
import java.util.function.Predicate;
2728

2829
public class ContextMenuWidget extends MenuWidget {
2930
ArrayList<MenuItem> mItems;
@@ -75,6 +76,10 @@ protected void onDismiss() {
7576
}
7677
}
7778

79+
public boolean hasActions() {
80+
return mItems.stream().anyMatch(menuItem -> menuItem.mCallback != null);
81+
}
82+
7883
public void setDismissCallback(Runnable aCallback) {
7984
mDismissCallback = aCallback;
8085
}
@@ -110,7 +115,7 @@ public void setContextElement(ContextElement aContextElement) {
110115
} else {
111116
mItems.add(new MenuWidget.MenuItem(aContextElement.srcUri, 0, null));
112117
}
113-
if (URLUtil.isHttpUrl(aContextElement.srcUri) || URLUtil.isHttpsUrl(aContextElement.srcUri)) {
118+
if (URLUtil.isNetworkUrl(aContextElement.srcUri)) {
114119
@StringRes int srcText;
115120
switch (aContextElement.type) {
116121
case ContextElement.TYPE_IMAGE:
@@ -133,33 +138,35 @@ public void setContextElement(ContextElement aContextElement) {
133138
onDismiss();
134139
}));
135140
}
136-
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
137-
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
138-
Uri uri;
139-
if (aContextElement.linkUri != null) {
140-
uri = Uri.parse(aContextElement.linkUri);
141-
142-
} else {
143-
uri = Uri.parse(aContextElement.srcUri);
144-
}
145-
if (uri != null) {
146-
String label = aContextElement.title;
147-
if (StringUtils.isEmpty(label)) {
148-
label = aContextElement.altText;
149-
}
150-
if (StringUtils.isEmpty(label)) {
151-
label = aContextElement.altText;
141+
if (URLUtil.isNetworkUrl(aContextElement.linkUri) || URLUtil.isNetworkUrl(aContextElement.srcUri)) {
142+
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_copy_link), 0, () -> {
143+
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
144+
Uri uri;
145+
if (aContextElement.linkUri != null) {
146+
uri = Uri.parse(aContextElement.linkUri);
147+
148+
} else {
149+
uri = Uri.parse(aContextElement.srcUri);
152150
}
153-
if (StringUtils.isEmpty(label)) {
154-
label = uri.toString();
155-
}
156-
ClipData clip = ClipData.newRawUri(label, uri);
157-
if (clipboard != null) {
158-
clipboard.setPrimaryClip(clip);
151+
if (uri != null) {
152+
String label = aContextElement.title;
153+
if (StringUtils.isEmpty(label)) {
154+
label = aContextElement.altText;
155+
}
156+
if (StringUtils.isEmpty(label)) {
157+
label = aContextElement.altText;
158+
}
159+
if (StringUtils.isEmpty(label)) {
160+
label = uri.toString();
161+
}
162+
ClipData clip = ClipData.newRawUri(label, uri);
163+
if (clipboard != null) {
164+
clipboard.setPrimaryClip(clip);
165+
}
159166
}
160-
}
161-
onDismiss();
162-
}));
167+
onDismiss();
168+
}));
169+
}
163170
updateMenuItems(mItems);
164171

165172
mWidgetPlacement.height = mItems.size() * WidgetPlacement.dpDimension(getContext(), R.dimen.context_menu_row_height);

0 commit comments

Comments
 (0)