diff options
author | MHX348@motorola.com <MHX348@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 04:02:09 +0000 |
---|---|---|
committer | MHX348@motorola.com <MHX348@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 04:02:09 +0000 |
commit | e08635775e9b90962ccc6fe312e5ccb1ed1ea331 (patch) | |
tree | 0eb3594b2ad5e8666a41117fcd6c4c3dd2b93899 | |
parent | c49bcb63a32f868f67edf88bad7c8e0483828ab2 (diff) | |
download | chromium_src-e08635775e9b90962ccc6fe312e5ccb1ed1ea331.zip chromium_src-e08635775e9b90962ccc6fe312e5ccb1ed1ea331.tar.gz chromium_src-e08635775e9b90962ccc6fe312e5ccb1ed1ea331.tar.bz2 |
DCHECK while invoking extension infobar context menu for the second time
DCHECK failure occurs while trying to destroy the
ExtensionContextMenuModel object in InfoBarGtk without calling
RefCounted::Release().
Since ExtensionContextMenuModel is a refcounted class, its object needs
to be managed correctly with RefCounted::AddRef() & RefCounted::Release().
Moving the ownership of Menu Model to the sub classes of InfoBarGtk
to achieve this.
BUG=172921
TEST= Context menu opens for 'Sandwich' infobar sample extension without crash for the second time.
Review URL: https://chromiumcodereview.appspot.com/12092047
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180898 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 16 insertions, 12 deletions
diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc index 4a7e485..c69b5de 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc @@ -157,7 +157,7 @@ Browser* ExtensionInfoBarGtk::GetBrowser() { return BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser(); } -ui::MenuModel* ExtensionInfoBarGtk::BuildMenuModel() { +ExtensionContextMenuModel* ExtensionInfoBarGtk::BuildMenuModel() { const extensions::Extension* extension = delegate_->extension(); if (!extension->ShowConfigureContextMenus()) return NULL; @@ -182,13 +182,13 @@ gboolean ExtensionInfoBarGtk::OnButtonPress(GtkWidget* widget, if (event->button != 1) return FALSE; - ui::MenuModel* model = BuildMenuModel(); - if (!model) + context_menu_model_ = BuildMenuModel(); + if (!context_menu_model_) return FALSE; gtk_chrome_button_set_paint_state(GTK_CHROME_BUTTON(widget), GTK_STATE_ACTIVE); - ShowMenuWithModel(widget, this, model); + ShowMenuWithModel(widget, this, context_menu_model_); return TRUE; } diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h index a86a1db..a916d81 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h @@ -12,6 +12,7 @@ #include "chrome/browser/ui/gtk/menu_gtk.h" #include "ui/gfx/gtk_util.h" +class ExtensionContextMenuModel; class ExtensionResource; class ExtensionViewGtk; class MenuGtk; @@ -47,7 +48,7 @@ class ExtensionInfoBarGtk : public InfoBarGtk, // Returns the context menu model for this extension. Can be NULL if // extension context menus are disabled. - ui::MenuModel* BuildMenuModel(); + ExtensionContextMenuModel* BuildMenuModel(); CHROMEGTK_CALLBACK_1(ExtensionInfoBarGtk, void, OnSizeAllocate, GtkAllocation*); @@ -74,6 +75,9 @@ class ExtensionInfoBarGtk : public InfoBarGtk, // child properties. Reparenting becomes easier too. GtkWidget* alignment_; + // The model for the current menu displayed. + scoped_refptr<ExtensionContextMenuModel> context_menu_model_; + base::WeakPtrFactory<ExtensionInfoBarGtk> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(ExtensionInfoBarGtk); diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc index a7c57e8..a45920f 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc @@ -193,8 +193,7 @@ void InfoBarGtk::AddLabelWithInlineLink(const string16& display_text, void InfoBarGtk::ShowMenuWithModel(GtkWidget* sender, MenuGtk::Delegate* delegate, ui::MenuModel* model) { - menu_model_.reset(model); - menu_.reset(new MenuGtk(delegate, menu_model_.get())); + menu_.reset(new MenuGtk(delegate, model)); menu_->PopupForWidget(sender, 1, gtk_get_current_event_time()); } @@ -289,7 +288,6 @@ void InfoBarGtk::PlatformSpecificOnCloseSoon() { // We must close all menus and prevent any signals from being emitted while // we are animating the info bar closed. menu_.reset(); - menu_model_.reset(); signals_.reset(); } diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.h b/chrome/browser/ui/gtk/infobars/infobar_gtk.h index 96dad53..22d1608 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.h @@ -83,8 +83,7 @@ class InfoBarGtk : public InfoBar, size_t link_offset, GCallback callback); - // Shows the menu with |model| with the context of |sender|. InfobarGtk takes - // ownership of the model. + // Shows the menu with |model| with the context of |sender|. void ShowMenuWithModel(GtkWidget* sender, MenuGtk::Delegate* delegate, ui::MenuModel* model); @@ -132,7 +131,6 @@ class InfoBarGtk : public InfoBar, // The current menu displayed. Can be null. We own this on the base class so // we can cancel the menu while we're closing. - scoped_ptr<ui::MenuModel> menu_model_; scoped_ptr<MenuGtk> menu_; DISALLOW_COPY_AND_ASSIGN(InfoBarGtk); diff --git a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc index cb39cb7..09b93c3 100644 --- a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc @@ -193,7 +193,8 @@ TranslateInfoBarDelegate* TranslateInfoBarBase::GetDelegate() { } void TranslateInfoBarBase::OnOptionsClicked(GtkWidget* sender) { - ShowMenuWithModel(sender, NULL, new OptionsMenuModel(GetDelegate())); + menu_model_.reset(new OptionsMenuModel(GetDelegate())); + ShowMenuWithModel(sender, NULL, menu_model_.get()); } // TranslateInfoBarDelegate specific method: diff --git a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h index 7181b39..53f2a35 100644 --- a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h +++ b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h @@ -64,6 +64,9 @@ class TranslateInfoBarBase : public InfoBarGtk { // Changes the color of the background from normal to error color and back. scoped_ptr<ui::SlideAnimation> background_color_animation_; + // The model for the current menu displayed. + scoped_ptr<ui::MenuModel> menu_model_; + DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarBase); }; |