]> khamidou — GitHub mirrors - electron.git/commitdiff
browser: fix crash when switching to sibling menu from submenus
authorRobo <hop2deep@gmail.com>
Wed, 20 Jan 2016 02:59:44 +0000 (08:29 +0530)
committerRobo <hop2deep@gmail.com>
Wed, 20 Jan 2016 05:24:12 +0000 (10:54 +0530)
atom/browser/ui/views/menu_delegate.cc
atom/browser/ui/views/menu_delegate.h

index 8ef8bca72deec47458a52ea602c28ae44805f2cd..f0ecf13b36b65aa96bee3e55ee459a9d3dad2aaf 100644 (file)
@@ -105,24 +105,17 @@ views::MenuItemView* MenuDelegate::GetSiblingMenu(
   ui::MenuModel* model;
   if (menu_bar_->GetMenuButtonFromScreenPoint(screen_point, &model, &button) &&
       button->tag() != id_) {
-    // Switch to sibling menu on next tick, otherwise crash may happen.
+    DCHECK(menu_runner_->IsRunning());
+    menu_runner_->Cancel();
+    // After canceling the menu, we need to wait until next tick
+    // so we are out of nested message loop.
     content::BrowserThread::PostTask(
         content::BrowserThread::UI, FROM_HERE,
-        base::Bind(&MenuDelegate::SwitchToSiblingMenu,
-                   base::Unretained(this), button));
+        base::Bind(base::IgnoreResult(&views::MenuButton::Activate),
+                   base::Unretained(button)));
   }
 
   return nullptr;
 }
 
-void MenuDelegate::SwitchToSiblingMenu(views::MenuButton* button) {
-  menu_runner_->Cancel();
-  // After canceling the menu, we need to wait until next tick so we are out of
-  // nested message loop.
-  content::BrowserThread::PostTask(
-      content::BrowserThread::UI, FROM_HERE,
-      base::Bind(base::IgnoreResult(&views::MenuButton::Activate),
-                 base::Unretained(button)));
-}
-
 }  // namespace atom
index f83e5896c606ba8c446fe09eae7a2a9e55c8107a..211ddb57bc39086d183aeb96cce683cc901a99c7 100644 (file)
@@ -50,9 +50,6 @@ class MenuDelegate : public views::MenuDelegate {
       views::MenuButton** button) override;
 
  private:
-  // Close this menu and run the menu of |button|.
-  void SwitchToSiblingMenu(views::MenuButton* button);
-
   MenuBar* menu_bar_;
   int id_;
   scoped_ptr<views::MenuDelegate> adapter_;