From d866d17fddb39f49dd9ee6fd64145a60b6d958dd Mon Sep 17 00:00:00 2001
From: "mthiesse@chromium.org"
 <mthiesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Sat, 16 Mar 2013 09:25:43 +0000
Subject: Prevented connecting events to a SwappedOut RenderViewHost in
 WebContentsViewGtk

Added a check to see if the RenderWidgetHost passed to CreateViewForWidget is
SwappedOut before connecting events to it, or creating a DragDest from it.

Needed for: https://chromiumcodereview.appspot.com/12086095/
When a postMessage is sent to a guest process, like a BrowserPlugin guest,
WebContentsViewGtk::CreateViewForWidget is called with a swapped out
RenderWidgetHost. This RenderWidgetHost is then used as the WebDragDest for the
window, preventing the window from receiving Drag and Drop events.

BUG= 161112, 177667

Review URL: https://chromiumcodereview.appspot.com/12252016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188559 0039d316-1c4b-4281-b951-d872f2087c98
---
 content/browser/web_contents/web_drag_dest_gtk.cc | 26 ++++++++++++++---------
 1 file changed, 16 insertions(+), 10 deletions(-)

(limited to 'content/browser/web_contents/web_drag_dest_gtk.cc')

diff --git a/content/browser/web_contents/web_drag_dest_gtk.cc b/content/browser/web_contents/web_drag_dest_gtk.cc
index dcd89b0..fd2763f 100644
--- a/content/browser/web_contents/web_drag_dest_gtk.cc
+++ b/content/browser/web_contents/web_drag_dest_gtk.cc
@@ -27,6 +27,7 @@ using WebKit::WebDragOperationNone;
 namespace content {
 
 namespace {
+const int kNumGtkHandlers = 5;
 
 int GetModifierFlags(GtkWidget* widget) {
   int modifier_state = 0;
@@ -58,25 +59,30 @@ WebDragDestGtk::WebDragDestGtk(WebContents* web_contents, GtkWidget* widget)
                     static_cast<GdkDragAction>(GDK_ACTION_COPY |
                                                GDK_ACTION_LINK |
                                                GDK_ACTION_MOVE));
-  g_signal_connect(widget, "drag-motion",
-                   G_CALLBACK(OnDragMotionThunk), this);
-  g_signal_connect(widget, "drag-leave",
-                   G_CALLBACK(OnDragLeaveThunk), this);
-  g_signal_connect(widget, "drag-drop",
-                   G_CALLBACK(OnDragDropThunk), this);
-  g_signal_connect(widget, "drag-data-received",
-                   G_CALLBACK(OnDragDataReceivedThunk), this);
+
+  // If adding a handler, make sure to update kNumGtkHandlers and add it to the
+  // |handlers_| array so that it can be disconnected later on.
+  handlers_.reset(new int[kNumGtkHandlers]);
+  handlers_.get()[0] = g_signal_connect(
+      widget, "drag-motion", G_CALLBACK(OnDragMotionThunk), this);
+  handlers_.get()[1] = g_signal_connect(
+      widget, "drag-leave", G_CALLBACK(OnDragLeaveThunk), this);
+  handlers_.get()[2] = g_signal_connect(
+      widget, "drag-drop", G_CALLBACK(OnDragDropThunk), this);
+  handlers_.get()[3] = g_signal_connect(
+      widget, "drag-data-received", G_CALLBACK(OnDragDataReceivedThunk), this);
   // TODO(tony): Need a drag-data-delete handler for moving content out of
   // the WebContents.  http://crbug.com/38989
 
-  destroy_handler_ = g_signal_connect(
+  handlers_.get()[4] = g_signal_connect(
       widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &widget_);
 }
 
 WebDragDestGtk::~WebDragDestGtk() {
   if (widget_) {
     gtk_drag_dest_unset(widget_);
-    g_signal_handler_disconnect(widget_, destroy_handler_);
+    for (int i = 0; i < kNumGtkHandlers; ++i)
+      g_signal_handler_disconnect(widget_, handlers_.get()[i]);
   }
 }
 
-- 
cgit v1.1