Side panel: Add way to hide custom context menu

In other Bookmark UIs, a bookmark's context menu is forced to close when
there are changes to the bookmark model. To accommodate this, this CL
adds new methods across the embedder and BubbleContentsWrapper to allow
us to close the custom context menu being shown.

Bug: 1222528
Change-Id: I034a6afbba1eb92768cba19160ea52aa8fe6a642
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3044229
Commit-Queue: John Lee <johntlee@chromium.org>
Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: Caroline Rising <corising@chromium.org>
Cr-Commit-Position: refs/heads/master@{#905014}
diff --git a/chrome/browser/ui/views/bubble/bubble_contents_wrapper.cc b/chrome/browser/ui/views/bubble/bubble_contents_wrapper.cc
index 94c6ff7..188be26 100644
--- a/chrome/browser/ui/views/bubble/bubble_contents_wrapper.cc
+++ b/chrome/browser/ui/views/bubble/bubble_contents_wrapper.cc
@@ -127,6 +127,11 @@
     host_->ShowCustomContextMenu(point, std::move(menu_model));
 }
 
+void BubbleContentsWrapper::HideContextMenu() {
+  if (host_)
+    host_->HideCustomContextMenu();
+}
+
 base::WeakPtr<BubbleContentsWrapper::Host> BubbleContentsWrapper::GetHost() {
   return host_;
 }
diff --git a/chrome/browser/ui/views/bubble/bubble_contents_wrapper.h b/chrome/browser/ui/views/bubble/bubble_contents_wrapper.h
index 156db34..b4da05af 100644
--- a/chrome/browser/ui/views/bubble/bubble_contents_wrapper.h
+++ b/chrome/browser/ui/views/bubble/bubble_contents_wrapper.h
@@ -38,6 +38,7 @@
     virtual void ShowCustomContextMenu(
         gfx::Point point,
         std::unique_ptr<ui::MenuModel> menu_model) {}
+    virtual void HideCustomContextMenu() {}
     virtual void ResizeDueToAutoResize(content::WebContents* source,
                                        const gfx::Size& new_size) {}
     virtual bool HandleKeyboardEvent(
@@ -73,6 +74,7 @@
   void ShowUI() override;
   void ShowContextMenu(gfx::Point point,
                        std::unique_ptr<ui::MenuModel> menu_model) override;
+  void HideContextMenu() override;
 
   // Reloads the WebContents hosting the WebUI.
   virtual void ReloadWebContents() = 0;
diff --git a/chrome/browser/ui/views/toolbar/read_later_toolbar_button.cc b/chrome/browser/ui/views/toolbar/read_later_toolbar_button.cc
index b85b7fb..c7dfbc48 100644
--- a/chrome/browser/ui/views/toolbar/read_later_toolbar_button.cc
+++ b/chrome/browser/ui/views/toolbar/read_later_toolbar_button.cc
@@ -68,6 +68,10 @@
         views::MenuAnchorPosition::kTopLeft, ui::MENU_SOURCE_MOUSE,
         contents_wrapper_->web_contents()->GetContentNativeView());
   }
+  void HideCustomContextMenu() override {
+    if (context_menu_runner_)
+      context_menu_runner_->Cancel();
+  }
 
  private:
   base::RepeatingClosure close_cb_;
diff --git a/ui/webui/mojo_bubble_web_ui_controller.h b/ui/webui/mojo_bubble_web_ui_controller.h
index de6b72ef..2a895d1 100644
--- a/ui/webui/mojo_bubble_web_ui_controller.h
+++ b/ui/webui/mojo_bubble_web_ui_controller.h
@@ -28,6 +28,7 @@
     virtual void CloseUI() = 0;
     virtual void ShowContextMenu(gfx::Point point,
                                  std::unique_ptr<ui::MenuModel> menu_model) = 0;
+    virtual void HideContextMenu() = 0;
   };
 
   // By default MojoBubbleWebUIController do not have normal WebUI bindings.