Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2461)

Unified Diff: chrome/browser/tab_contents/web_drag_source.cc

Issue 159040: Fix another d&d crash that happens when the tab contents (Closed)
Patch Set: revise comment Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tab_contents/web_drag_source.cc
diff --git a/chrome/browser/tab_contents/web_drag_source.cc b/chrome/browser/tab_contents/web_drag_source.cc
index 8a9ce8bdd37c3f8be694141b4356eec15c548000..9cfbb2d5cc19a5e56b8a89b6beadd2bbec907261 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();
+ }
+}
« no previous file with comments | « chrome/browser/tab_contents/web_drag_source.h ('k') | chrome/browser/views/tab_contents/tab_contents_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698