summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-21 17:43:06 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-21 17:43:06 +0000
commit28119ec7b28e0ab1ac4f3e7a1a59ff34beeb98d1 (patch)
treead61dbf9396d03ee0690ead135c83b8477b313f9 /chrome/browser
parent55b4a69202507b6950190ea06273b497e174fe01 (diff)
downloadchromium_src-28119ec7b28e0ab1ac4f3e7a1a59ff34beeb98d1.zip
chromium_src-28119ec7b28e0ab1ac4f3e7a1a59ff34beeb98d1.tar.gz
chromium_src-28119ec7b28e0ab1ac4f3e7a1a59ff34beeb98d1.tar.bz2
Fix another d&d crash that happens when the tab contents
is swapped out while a drag is happening. Since the tab contents is swapped out, our RVH that the drag started on is no longer valid. Simply null out the pointer and no longer try to send feedback to the drag source. This allows the user to continue the drag even though the source RVH is gone. BUG=16073 Review URL: http://codereview.chromium.org/159040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/tab_contents/web_drag_source.cc32
-rw-r--r--chrome/browser/tab_contents/web_drag_source.h17
-rw-r--r--chrome/browser/views/tab_contents/tab_contents_view_win.cc3
3 files changed, 45 insertions, 7 deletions
diff --git a/chrome/browser/tab_contents/web_drag_source.cc b/chrome/browser/tab_contents/web_drag_source.cc
index 8a9ce8b..9cfbb2d 100644
--- a/chrome/browser/tab_contents/web_drag_source.cc
+++ b/chrome/browser/tab_contents/web_drag_source.cc
@@ -11,6 +11,9 @@
#include "chrome/browser/tab_contents/web_drag_source.h"
#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/notification_type.h"
+#include "chrome/common/notification_service.h"
namespace {
@@ -33,13 +36,20 @@ static void GetCursorPositions(gfx::NativeWindow wnd, gfx::Point* client,
// WebDragSource, public:
WebDragSource::WebDragSource(gfx::NativeWindow source_wnd,
- RenderViewHost* render_view_host)
+ TabContents* tab_contents)
: BaseDragSource(),
source_wnd_(source_wnd),
- render_view_host_(render_view_host) {
+ render_view_host_(tab_contents->render_view_host()) {
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_SWAPPED,
+ Source<TabContents>(tab_contents));
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
+ Source<TabContents>(tab_contents));
}
void WebDragSource::OnDragSourceCancel() {
+ if (!render_view_host_)
+ return;
+
gfx::Point client;
gfx::Point screen;
GetCursorPositions(source_wnd_, &client, &screen);
@@ -48,6 +58,9 @@ void WebDragSource::OnDragSourceCancel() {
}
void WebDragSource::OnDragSourceDrop() {
+ if (!render_view_host_)
+ return;
+
gfx::Point client;
gfx::Point screen;
GetCursorPositions(source_wnd_, &client, &screen);
@@ -56,9 +69,24 @@ void WebDragSource::OnDragSourceDrop() {
}
void WebDragSource::OnDragSourceMove() {
+ if (!render_view_host_)
+ return;
+
gfx::Point client;
gfx::Point screen;
GetCursorPositions(source_wnd_, &client, &screen);
render_view_host_->DragSourceMovedTo(client.x(), client.y(),
screen.x(), screen.y());
}
+
+void WebDragSource::Observe(NotificationType type,
+ const NotificationSource& source, const NotificationDetails& details) {
+ if (NotificationType::TAB_CONTENTS_SWAPPED == type) {
+ // When the tab contents get swapped, our render view host goes away.
+ // That's OK, we can continue the drag, we just can't send messages back to
+ // our drag source.
+ render_view_host_ = NULL;
+ } else if (NotificationType::TAB_CONTENTS_DISCONNECTED) {
+ NOTREACHED();
+ }
+}
diff --git a/chrome/browser/tab_contents/web_drag_source.h b/chrome/browser/tab_contents/web_drag_source.h
index d1cd6e0..f80c6c6 100644
--- a/chrome/browser/tab_contents/web_drag_source.h
+++ b/chrome/browser/tab_contents/web_drag_source.h
@@ -8,6 +8,8 @@
#include "base/basictypes.h"
#include "base/gfx/native_widget_types.h"
#include "base/gfx/point.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
// TODO(port): Port this file.
#if defined(OS_WIN)
@@ -17,6 +19,7 @@
#endif
class RenderViewHost;
+class TabContents;
///////////////////////////////////////////////////////////////////////////////
//
@@ -27,12 +30,18 @@ class RenderViewHost;
// on their system. This object tells Windows whether or not the drag should
// continue, and supplies the appropriate cursors.
//
-class WebDragSource : public BaseDragSource {
+class WebDragSource : public BaseDragSource,
+ public NotificationObserver {
public:
- // Create a new DragSource for a given HWND and RenderViewHost.
- WebDragSource(gfx::NativeWindow source_wnd, RenderViewHost* render_view_host);
+ // Create a new DragSource for a given HWND and TabContents.
+ WebDragSource(gfx::NativeWindow source_wnd, TabContents* tab_contents);
virtual ~WebDragSource() { }
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
protected:
// BaseDragSource
virtual void OnDragSourceCancel();
@@ -51,6 +60,8 @@ class WebDragSource : public BaseDragSource {
// initiated terminates).
RenderViewHost* render_view_host_;
+ NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(WebDragSource);
};
diff --git a/chrome/browser/views/tab_contents/tab_contents_view_win.cc b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
index 543cff4..cd785d6 100644
--- a/chrome/browser/views/tab_contents/tab_contents_view_win.cc
+++ b/chrome/browser/views/tab_contents/tab_contents_view_win.cc
@@ -178,8 +178,7 @@ void TabContentsViewWin::StartDragging(const WebDropData& drop_data) {
if (!drop_data.plain_text.empty())
data->SetString(drop_data.plain_text);
- drag_source_ = new WebDragSource(GetNativeView(),
- tab_contents()->render_view_host());
+ drag_source_ = new WebDragSource(GetNativeView(), tab_contents());
DWORD effects;