|
10 | 10 | import android.content.Context; |
11 | 11 | import android.content.res.Configuration; |
12 | 12 | import android.net.Uri; |
| 13 | +import android.webkit.URLUtil; |
13 | 14 |
|
14 | 15 | import androidx.annotation.StringRes; |
15 | 16 |
|
|
20 | 21 | import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; |
21 | 22 | import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement; |
22 | 23 | import org.mozilla.vrbrowser.utils.StringUtils; |
| 24 | +import org.mozilla.vrbrowser.utils.UrlUtils; |
23 | 25 |
|
24 | 26 | import java.util.ArrayList; |
25 | 27 |
|
@@ -79,32 +81,36 @@ public void setDismissCallback(Runnable aCallback) { |
79 | 81 |
|
80 | 82 | public void setContextElement(ContextElement aContextElement) { |
81 | 83 | mItems = new ArrayList<>(); |
82 | | - mItems.add(new MenuWidget.MenuItem(aContextElement.linkUri, 0, null)); |
83 | 84 | final WidgetManagerDelegate widgetManager = mWidgetManager; |
84 | | - if (mWidgetManager.canOpenNewWindow()) { |
85 | | - mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_window_1), 0, () -> { |
| 85 | + if (aContextElement.linkUri != null && !aContextElement.linkUri.isEmpty()) { |
| 86 | + mItems.add(new MenuWidget.MenuItem(aContextElement.linkUri, 0, null)); |
| 87 | + if (mWidgetManager.canOpenNewWindow()) { |
| 88 | + mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_window_1), 0, () -> { |
| 89 | + if (!StringUtils.isEmpty(aContextElement.linkUri)) { |
| 90 | + widgetManager.openNewWindow(aContextElement.linkUri); |
| 91 | + } |
| 92 | + onDismiss(); |
| 93 | + })); |
| 94 | + } |
| 95 | + mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> { |
86 | 96 | if (!StringUtils.isEmpty(aContextElement.linkUri)) { |
87 | | - widgetManager.openNewWindow(aContextElement.linkUri); |
| 97 | + widgetManager.openNewTab(aContextElement.linkUri); |
| 98 | + GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU); |
88 | 99 | } |
89 | 100 | onDismiss(); |
90 | 101 | })); |
91 | | - } |
92 | | - mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_open_new_tab_1), 0, () -> { |
93 | 102 | if (!StringUtils.isEmpty(aContextElement.linkUri)) { |
94 | | - widgetManager.openNewTab(aContextElement.linkUri); |
95 | | - GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.CONTEXT_MENU); |
| 103 | + mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_download_link), 0, () -> { |
| 104 | + DownloadJob job = DownloadJob.fromLink(aContextElement); |
| 105 | + widgetManager.getFocusedWindow().startDownload(job, false); |
| 106 | + // TODO Add Download from context menu Telemetry |
| 107 | + onDismiss(); |
| 108 | + })); |
96 | 109 | } |
97 | | - onDismiss(); |
98 | | - })); |
99 | | - if (!StringUtils.isEmpty(aContextElement.linkUri)) { |
100 | | - mItems.add(new MenuWidget.MenuItem(getContext().getString(R.string.context_menu_download_link), 0, () -> { |
101 | | - DownloadJob job = DownloadJob.fromLink(aContextElement); |
102 | | - widgetManager.getFocusedWindow().startDownload(job, false); |
103 | | - // TODO Add Download from context menu Telemetry |
104 | | - onDismiss(); |
105 | | - })); |
| 110 | + } else { |
| 111 | + mItems.add(new MenuWidget.MenuItem(aContextElement.srcUri, 0, null)); |
106 | 112 | } |
107 | | - if (!StringUtils.isEmpty(aContextElement.srcUri)) { |
| 113 | + if (URLUtil.isHttpUrl(aContextElement.srcUri) || URLUtil.isHttpsUrl(aContextElement.srcUri)) { |
108 | 114 | @StringRes int srcText; |
109 | 115 | switch (aContextElement.type) { |
110 | 116 | case ContextElement.TYPE_IMAGE: |
|
0 commit comments