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

Side by Side Diff: content/browser/web_contents/web_drag_source_win.cc

Issue 12086095: Fixed drag and drop into and out of Browser Plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed Comments Created 7 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_drag_source_win.h" 5 #include "content/browser/web_contents/web_drag_source_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/web_contents/web_drag_utils_win.h" 9 #include "content/browser/web_contents/web_drag_utils_win.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 17 matching lines...) Expand all
28 28
29 } // namespace 29 } // namespace
30 30
31 /////////////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////////////
32 // WebDragSource, public: 32 // WebDragSource, public:
33 33
34 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd, 34 WebDragSource::WebDragSource(gfx::NativeWindow source_wnd,
35 WebContents* web_contents) 35 WebContents* web_contents)
36 : ui::DragSourceWin(), 36 : ui::DragSourceWin(),
37 source_wnd_(source_wnd), 37 source_wnd_(source_wnd),
38 render_view_host_(web_contents->GetRenderViewHost()), 38 web_contents_(web_contents),
39 effect_(DROPEFFECT_NONE) { 39 effect_(DROPEFFECT_NONE) {
40 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED, 40 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_SWAPPED,
41 Source<WebContents>(web_contents)); 41 Source<WebContents>(web_contents));
42 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED, 42 registrar_.Add(this, NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
43 Source<WebContents>(web_contents)); 43 Source<WebContents>(web_contents));
44 } 44 }
45 45
46 WebDragSource::~WebDragSource() { 46 WebDragSource::~WebDragSource() {
47 } 47 }
48 48
49 void WebDragSource::OnDragSourceCancel() { 49 void WebDragSource::OnDragSourceCancel() {
50 // Delegate to the UI thread if we do drag-and-drop in the background thread. 50 // Delegate to the UI thread if we do drag-and-drop in the background thread.
51 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 51 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
52 BrowserThread::PostTask( 52 BrowserThread::PostTask(
53 BrowserThread::UI, FROM_HERE, 53 BrowserThread::UI, FROM_HERE,
54 base::Bind(&WebDragSource::OnDragSourceCancel, this)); 54 base::Bind(&WebDragSource::OnDragSourceCancel, this));
55 return; 55 return;
56 } 56 }
57 57
58 if (!render_view_host_) 58 if (!web_contents_)
59 return; 59 return;
60 60
61 gfx::Point client; 61 gfx::Point client;
62 gfx::Point screen; 62 gfx::Point screen;
63 GetCursorPositions(source_wnd_, &client, &screen); 63 GetCursorPositions(source_wnd_, &client, &screen);
64 render_view_host_->DragSourceEndedAt(client.x(), client.y(), 64 web_contents_->DragSourceEndedAt(client.x(), client.y(),
65 screen.x(), screen.y(), 65 screen.x(), screen.y(),
66 WebDragOperationNone); 66 WebDragOperationNone);
67 } 67 }
68 68
69 void WebDragSource::OnDragSourceDrop() { 69 void WebDragSource::OnDragSourceDrop() {
70 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which 70 // On Windows, we check for drag end in IDropSource::QueryContinueDrag which
71 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend" 71 // happens before IDropTarget::Drop is called. HTML5 requires the "dragend"
72 // event to happen after the "drop" event. Since Windows calls these two 72 // event to happen after the "drop" event. Since Windows calls these two
73 // directly after each other we can just post a task to handle the 73 // directly after each other we can just post a task to handle the
74 // OnDragSourceDrop after the current task. 74 // OnDragSourceDrop after the current task.
75 BrowserThread::PostTask( 75 BrowserThread::PostTask(
76 BrowserThread::UI, FROM_HERE, 76 BrowserThread::UI, FROM_HERE,
77 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this)); 77 base::Bind(&WebDragSource::DelayedOnDragSourceDrop, this));
78 } 78 }
79 79
80 void WebDragSource::DelayedOnDragSourceDrop() { 80 void WebDragSource::DelayedOnDragSourceDrop() {
81 if (!render_view_host_) 81 if (!web_contents_)
82 return; 82 return;
83 83
84 gfx::Point client; 84 gfx::Point client;
85 gfx::Point screen; 85 gfx::Point screen;
86 GetCursorPositions(source_wnd_, &client, &screen); 86 GetCursorPositions(source_wnd_, &client, &screen);
87 render_view_host_->DragSourceEndedAt( 87 web_contents_->DragSourceEndedAt(client.x(), client.y(), screen.x(),
88 client.x(), client.y(), screen.x(), screen.y(), 88 screen.y(), WinDragOpToWebDragOp(effect_));
89 WinDragOpToWebDragOp(effect_));
90 } 89 }
91 90
92 void WebDragSource::OnDragSourceMove() { 91 void WebDragSource::OnDragSourceMove() {
93 // Delegate to the UI thread if we do drag-and-drop in the background thread. 92 // Delegate to the UI thread if we do drag-and-drop in the background thread.
94 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 93 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
95 BrowserThread::PostTask( 94 BrowserThread::PostTask(
96 BrowserThread::UI, FROM_HERE, 95 BrowserThread::UI, FROM_HERE,
97 base::Bind(&WebDragSource::OnDragSourceMove, this)); 96 base::Bind(&WebDragSource::OnDragSourceMove, this));
98 return; 97 return;
99 } 98 }
100 99
101 if (!render_view_host_) 100 if (!web_contents_)
102 return; 101 return;
103 102
104 gfx::Point client; 103 gfx::Point client;
105 gfx::Point screen; 104 gfx::Point screen;
106 GetCursorPositions(source_wnd_, &client, &screen); 105 GetCursorPositions(source_wnd_, &client, &screen);
107 render_view_host_->DragSourceMovedTo(client.x(), client.y(), 106 web_contents_->DragSourceMovedTo(client.x(), client.y(),
108 screen.x(), screen.y()); 107 screen.x(), screen.y());
109 } 108 }
110 109
111 void WebDragSource::Observe(int type, 110 void WebDragSource::Observe(int type,
112 const NotificationSource& source, 111 const NotificationSource& source,
113 const NotificationDetails& details) { 112 const NotificationDetails& details) {
114 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) { 113 if (type == NOTIFICATION_WEB_CONTENTS_SWAPPED) {
115 // When the WebContents get swapped, our render view host goes away. 114 // When the WebContents get swapped, our render view host goes away.
116 // That's OK, we can continue the drag, we just can't send messages back to 115 // That's OK, we can continue the drag, we just can't send messages back to
117 // our drag source. 116 // our drag source.
118 render_view_host_ = NULL; 117 web_contents_ = NULL;
119 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) { 118 } else if (type == NOTIFICATION_WEB_CONTENTS_DISCONNECTED) {
120 // This could be possible when we close the tab and the source is still 119 // This could be possible when we close the tab and the source is still
121 // being used in DoDragDrop at the time that the virtual file is being 120 // being used in DoDragDrop at the time that the virtual file is being
122 // downloaded. 121 // downloaded.
123 render_view_host_ = NULL; 122 web_contents_ = NULL;
124 } 123 }
125 } 124 }
126 125
127 } // namespace content 126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698