Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1117)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java

Issue 2553163002: 📰 Fix crash when tapping the menu on closed NTP (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java
index 79910e5857edb491729a8f3a898764bae5f45968..fda2dde2e44a70f861edf9433745d4a84ba75af1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContextMenuManager.java
@@ -7,6 +7,7 @@
import android.app.Activity;
import android.support.annotation.IntDef;
import android.support.annotation.StringRes;
+import android.support.v13.view.ViewCompat;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
@@ -80,7 +81,7 @@ public ContextMenuManager(
* are tapped.
*/
public void createContextMenu(ContextMenu menu, View associatedView, Delegate delegate) {
- OnMenuItemClickListener listener = new ItemClickListener(delegate);
+ OnMenuItemClickListener listener = new ItemClickListener(delegate, associatedView);
boolean hasItems = false;
for (@ContextMenuItemId int itemId : MenuItemLabelMatcher.STRING_MAP.keySet()) {
@@ -167,13 +168,23 @@ private boolean shouldShowItem(@ContextMenuItemId int itemId, Delegate delegate)
private static class ItemClickListener implements OnMenuItemClickListener {
private final Delegate mDelegate;
+ private final View mAssociatedView;
- ItemClickListener(Delegate delegate) {
+ ItemClickListener(Delegate delegate, View associatedView) {
mDelegate = delegate;
+ mAssociatedView = associatedView;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
+ // If the user clicks a snippet then immediately long presses they will create a context
+ // menu while the snippet's URL loads in the background. This means that when they press
+ // an item on context menu the NTP will not actually be open. We add this check here to
+ // prevent taking any action if the user has left the NTP. (https://crbug.com/640468)
+ // Although the menu is supposed to be closed when we navigate away from the NTP, we
+ // have to keep this check because of race conditions. (https://crbug.com/668945)
+ if (!ViewCompat.isAttachedToWindow(mAssociatedView)) return true;
+
switch (item.getItemId()) {
case ID_OPEN_IN_NEW_WINDOW:
mDelegate.openItem(WindowOpenDisposition.NEW_WINDOW);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698