Commit 4d61874e authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

[Context menu] Dismiss the menu on navigation

If a navigation occurs while the context menu is showing, the
RenderFrameHost becomes invalidated and causes a seg-fault if the user
tries to share the image.

This CL dismisses the menu on navigation to prevent this.

Bug: 1150622
Change-Id: I3aba40a2fae69715454ed753b4af623aca02006d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2553191Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Theresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830224}
parent c791e80a
......@@ -27,6 +27,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.widget.ContextMenuDialog;
import org.chromium.components.embedder_support.contextmenu.ContextMenuParams;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.ui.base.MenuSourceType;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modelutil.LayoutViewBuilder;
......@@ -58,6 +59,7 @@ public class RevampedContextMenuCoordinator implements ContextMenuUi {
private static final int INVALID_ITEM_ID = -1;
private WebContents mWebContents;
private WebContentsObserver mWebContentsObserver;
private RevampedContextMenuChipController mChipController;
private RevampedContextMenuHeaderCoordinator mHeaderCoordinator;
......@@ -197,6 +199,13 @@ public class RevampedContextMenuCoordinator implements ContextMenuUi {
clickItem((int) id, activity, onItemClicked);
});
mWebContentsObserver = new WebContentsObserver(mWebContents) {
@Override
public void navigationEntryCommitted() {
dismissDialog();
}
};
mDialog.show();
}
......@@ -268,6 +277,9 @@ public class RevampedContextMenuCoordinator implements ContextMenuUi {
}
private void dismissDialog() {
if (mWebContentsObserver != null) {
mWebContentsObserver.destroy();
}
if (mChipController != null) {
mChipController.dismissLensChipIfShowing();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment