diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 20:18:25 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-12 20:18:25 +0000 |
commit | 0834a4b75e40256a08e4a0b1bacab2e8b69da665 (patch) | |
tree | 7f283ebcf5b95a6c36de2e03667a80d0a00cb17a | |
parent | 21f1caa23bc5c8bc3fa611bcb229f23eb761aa9c (diff) | |
download | chromium_src-0834a4b75e40256a08e4a0b1bacab2e8b69da665.zip chromium_src-0834a4b75e40256a08e4a0b1bacab2e8b69da665.tar.gz chromium_src-0834a4b75e40256a08e4a0b1bacab2e8b69da665.tar.bz2 |
Exit DOMUI menu when browser window is destroyed.
This correctly exits the loop, then destroy menu2 instance
when the browser is closed while the menu is open.
BUG=chromium-os:7642
TEST=CloseWithAppMenuOpen browser test should pass.
Review URL: http://codereview.chromium.org/3643004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62328 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/views/native_menu_domui.cc | 38 |
2 files changed, 39 insertions, 8 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index e109d55..5dab3bf 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -562,16 +562,9 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { } #endif // !defined(OS_CHROMEOS) -#if defined(OS_CHROMEOS) -// crosbug.com/7642. -#define MAYBE_CloseWithAppMenuOpen DISABLED_CloseWithAppMenuOpen -#else -#define MAYBE_CloseWithAppMenuOpen CloseWithAppMenuOpen -#endif - // This test verifies we don't crash when closing the last window and the app // menu is showing. -IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_CloseWithAppMenuOpen) { +IN_PROC_BROWSER_TEST_F(BrowserTest, CloseWithAppMenuOpen) { if (browser_defaults::kBrowserAliveWithNoWindows) return; diff --git a/chrome/browser/chromeos/views/native_menu_domui.cc b/chrome/browser/chromeos/views/native_menu_domui.cc index 42c6482..27682ba 100644 --- a/chrome/browser/chromeos/views/native_menu_domui.cc +++ b/chrome/browser/chromeos/views/native_menu_domui.cc @@ -11,6 +11,7 @@ #include "base/string_util.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_window.h" #include "chrome/browser/chromeos/views/domui_menu_widget.h" #include "chrome/browser/chromeos/views/menu_locator.h" #include "chrome/browser/profile_manager.h" @@ -27,6 +28,26 @@ bool MenuTypeCanExecute(menus::MenuModel::ItemType type) { type == menus::MenuModel::TYPE_RADIO; } +gboolean Destroy(GtkWidget* widget, gpointer data) { + chromeos::NativeMenuDOMUI* domui_menu = + static_cast<chromeos::NativeMenuDOMUI*>(data); + domui_menu->Hide(); + return true; +} + +// Returns the active toplevel window. +gfx::NativeWindow FindActiveToplevelWindow() { + GList* toplevels = gtk_window_list_toplevels(); + while (toplevels) { + gfx::NativeWindow window = static_cast<gfx::NativeWindow>(toplevels->data); + if (gtk_window_is_active(window)) { + return window; + } + toplevels = g_list_next(toplevels); + } + return NULL; +} + // Currently opened menu. See RunMenuAt for reason why we need this. chromeos::NativeMenuDOMUI* current_ = NULL; @@ -102,6 +123,20 @@ void NativeMenuDOMUI::RunMenuAt(const gfx::Point& point, int alignment) { DCHECK(!menu_shown_); menu_shown_ = true; + // TODO(oshima): A menu must be deleted when parent window is + // closed. Menu2 doesn't know about the parent window, however, so + // we're using toplevel gtkwindow. This is probably sufficient, but + // I will update Menu2 to pass host view (which is necessary anyway + // to get the right position) and get a parent widnow through + // it. http://crosbug/7642 + gfx::NativeWindow parent = FindActiveToplevelWindow(); + gulong handle = 0; + if (parent) { + handle = g_signal_connect(G_OBJECT(parent), "destroy", + G_CALLBACK(&Destroy), + this); + } + // We need to turn on nestable tasks as a renderer uses tasks internally. // Without this, renderer cannnot finish loading page. bool nestable = MessageLoopForUI::current()->NestableTasksAllowed(); @@ -114,6 +149,9 @@ void NativeMenuDOMUI::RunMenuAt(const gfx::Point& point, int alignment) { NOTREACHED(); menu_shown_ = false; } + if (handle) + g_signal_handler_disconnect(G_OBJECT(parent), handle); + menu_widget_->Hide(); // Close All submenus. submenu_.reset(); |