[GTK] Showing the context menu in the Web Inspector can crash the browser
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2012 06:27:30 +0000 (06:27 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2012 06:27:30 +0000 (06:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=88800

Patch by Arnaud Renevier <arno@renevier.net> on 2012-07-05
Reviewed by Carlos Garcia Campos.

Remove ContextMenuItem from its parent before appending it again to a
new parent

No new tests, behavior is unchanged.

* platform/gtk/ContextMenuGtk.cpp:
(WebCore::ContextMenu::appendItem):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@121945 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/gtk/ContextMenuGtk.cpp

index e2378f0..953eab8 100644 (file)
@@ -1,3 +1,18 @@
+2012-07-05  Arnaud Renevier  <arno@renevier.net>
+
+        [GTK] Showing the context menu in the Web Inspector can crash the browser
+        https://bugs.webkit.org/show_bug.cgi?id=88800
+
+        Reviewed by Carlos Garcia Campos.
+
+        Remove ContextMenuItem from its parent before appending it again to a
+        new parent
+
+        No new tests, behavior is unchanged.
+
+        * platform/gtk/ContextMenuGtk.cpp:
+        (WebCore::ContextMenu::appendItem):
+
 2012-07-05  Dongwoo Im  <dw.im@samsung.com>
 
         [EFL] Unreviewed, Fix build break when WEB_AUDIO is enabled.
index 62a7eec..8916525 100644 (file)
@@ -23,8 +23,9 @@
 
 #include "ContextMenu.h"
 
-#include <wtf/gobject/GOwnPtr.h>
 #include <gtk/gtk.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
 
 namespace WebCore {
 
@@ -48,10 +49,14 @@ void ContextMenu::appendItem(ContextMenuItem& item)
 {
     ASSERT(m_platformDescription);
 
-    GtkMenuItem* platformItem = item.releasePlatformDescription();
+    GRefPtr<GtkWidget> platformItem = GTK_WIDGET(item.releasePlatformDescription());
     ASSERT(platformItem);
-    gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), GTK_WIDGET(platformItem));
-    gtk_widget_show(GTK_WIDGET(platformItem));
+
+    if (GtkWidget* parent = gtk_widget_get_parent(platformItem.get()))
+        gtk_container_remove(GTK_CONTAINER(parent), platformItem.get());
+
+    gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), platformItem.get());
+    gtk_widget_show(platformItem.get());
 }
 
 void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)