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

Fixes #3168 Context menu fixes #3207

Merged
merged 2 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,11 @@ public void onFullScreen(@NonNull GeckoSession session, boolean aFullScreen) {
public void onContextMenu(GeckoSession session, int screenX, int screenY, ContextElement element) {
hideContextMenus();

// We don't show the menu for blobs
if (UrlUtils.isBlobUri(element.srcUri)) {
return;
}

mContextMenu = new ContextMenuWidget(getContext());
mContextMenu.mWidgetPlacement.parentHandle = getHandle();
mContextMenu.setDismissCallback(this::hideContextMenus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.content.res.Configuration;
import android.net.Uri;
import android.webkit.URLUtil;

import androidx.annotation.StringRes;

Expand All @@ -20,6 +21,7 @@
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.UrlUtils;

import java.util.ArrayList;

Expand Down Expand Up @@ -79,32 +81,36 @@ public void setDismissCallback(Runnable aCallback) {

public void setContextElement(ContextElement aContextElement) {
mItems = new ArrayList<>();
mItems.add(new MenuWidget.MenuItem(aContextElement.linkUri, 0, null));
final WidgetManagerDelegate widgetManager = mWidgetManager;
if (mWidgetManager.canOpenNewWindow()) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_window_1), 0, () -> {
if (aContextElement.linkUri != null && !aContextElement.linkUri.isEmpty()) {
mItems.add(new MenuWidget.MenuItem(aContextElement.linkUri, 0, null));
if (mWidgetManager.canOpenNewWindow()) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_window_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
widgetManager.openNewWindow(aContextElement.linkUri);
}
onDismiss();
}));
}
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
widgetManager.openNewWindow(aContextElement.linkUri);
widgetManager.openNewTab(aContextElement.linkUri);
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU);
}
onDismiss();
}));
}
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> {
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
widgetManager.openNewTab(aContextElement.linkUri);
GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU);
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_download_link), 0, () -> {
DownloadJob job = DownloadJob.fromLink(aContextElement);
widgetManager.getFocusedWindow().startDownload(job, false);
// TODO Add Download from context menu Telemetry
onDismiss();
}));
}
onDismiss();
}));
if (!StringUtils.isEmpty(aContextElement.linkUri)) {
mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_download_link), 0, () -> {
DownloadJob job = DownloadJob.fromLink(aContextElement);
widgetManager.getFocusedWindow().startDownload(job, false);
// TODO Add Download from context menu Telemetry
onDismiss();
}));
} else {
mItems.add(new MenuWidget.MenuItem(aContextElement.srcUri, 0, null));
}
if (!StringUtils.isEmpty(aContextElement.srcUri)) {
if (URLUtil.isHttpUrl(aContextElement.srcUri) || URLUtil.isHttpsUrl(aContextElement.srcUri)) {
@StringRes int srcText;
switch (aContextElement.type) {
case ContextElement.TYPE_IMAGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public static Boolean isFileUri(@Nullable String aUri) {
return aUri != null && aUri.startsWith("file");
}

public static Boolean isBlobUri(@Nullable String aUri) {
return aUri != null && aUri.startsWith("blob");
}

public static Boolean isBlankUri(@Nullable Context context, @Nullable String aUri) {
return context != null && aUri != null && aUri.equals(context.getString(R.string.about_blank));
}
Expand Down