| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/tab_contents/web_drop_target_win.h" | 5 #include "chrome/browser/tab_contents/web_drop_target_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 | 9 |
| 10 #include "app/os_exchange_data.h" | |
| 11 #include "app/os_exchange_data_provider_win.h" | |
| 12 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 10 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 11 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/tab_contents/web_drag_utils_win.h" | 13 #include "chrome/browser/tab_contents/web_drag_utils_win.h" |
| 16 #include "gfx/point.h" | 14 #include "gfx/point.h" |
| 17 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 18 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 19 #include "ui/base/clipboard/clipboard_util_win.h" | 17 #include "ui/base/clipboard/clipboard_util_win.h" |
| 18 #include "ui/base/dragdrop/os_exchange_data.h" |
| 19 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 20 #include "webkit/glue/webdropdata.h" | 20 #include "webkit/glue/webdropdata.h" |
| 21 #include "webkit/glue/window_open_disposition.h" | 21 #include "webkit/glue/window_open_disposition.h" |
| 22 | 22 |
| 23 using WebKit::WebDragOperationNone; | 23 using WebKit::WebDragOperationNone; |
| 24 using WebKit::WebDragOperationCopy; | 24 using WebKit::WebDragOperationCopy; |
| 25 using WebKit::WebDragOperationLink; | 25 using WebKit::WebDragOperationLink; |
| 26 using WebKit::WebDragOperationMove; | 26 using WebKit::WebDragOperationMove; |
| 27 using WebKit::WebDragOperationGeneric; | 27 using WebKit::WebDragOperationGeneric; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // pass the messages on to a separate interstitial DropTarget handler. | 103 // pass the messages on to a separate interstitial DropTarget handler. |
| 104 if (tab_contents_->showing_interstitial_page()) | 104 if (tab_contents_->showing_interstitial_page()) |
| 105 return interstitial_drop_target_->OnDragEnter(data_object, effects); | 105 return interstitial_drop_target_->OnDragEnter(data_object, effects); |
| 106 | 106 |
| 107 // TODO(tc): PopulateWebDropData can be slow depending on what is in the | 107 // TODO(tc): PopulateWebDropData can be slow depending on what is in the |
| 108 // IDataObject. Maybe we can do this in a background thread. | 108 // IDataObject. Maybe we can do this in a background thread. |
| 109 WebDropData drop_data(GetDragIdentity()); | 109 WebDropData drop_data(GetDragIdentity()); |
| 110 WebDropData::PopulateWebDropData(data_object, &drop_data); | 110 WebDropData::PopulateWebDropData(data_object, &drop_data); |
| 111 | 111 |
| 112 if (drop_data.url.is_empty()) | 112 if (drop_data.url.is_empty()) |
| 113 OSExchangeDataProviderWin::GetPlainTextURL(data_object, &drop_data.url); | 113 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, &drop_data.url); |
| 114 | 114 |
| 115 drag_cursor_ = WebDragOperationNone; | 115 drag_cursor_ = WebDragOperationNone; |
| 116 | 116 |
| 117 POINT client_pt = cursor_position; | 117 POINT client_pt = cursor_position; |
| 118 ScreenToClient(GetHWND(), &client_pt); | 118 ScreenToClient(GetHWND(), &client_pt); |
| 119 tab_contents_->render_view_host()->DragTargetDragEnter(drop_data, | 119 tab_contents_->render_view_host()->DragTargetDragEnter(drop_data, |
| 120 gfx::Point(client_pt.x, client_pt.y), | 120 gfx::Point(client_pt.x, client_pt.y), |
| 121 gfx::Point(cursor_position.x, cursor_position.y), | 121 gfx::Point(cursor_position.x, cursor_position.y), |
| 122 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 122 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); |
| 123 | 123 |
| 124 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with | 124 // This is non-null if tab_contents_ is showing an ExtensionDOMUI with |
| 125 // support for (at the moment experimental) drag and drop extensions. | 125 // support for (at the moment experimental) drag and drop extensions. |
| 126 if (tab_contents_->GetBookmarkDragDelegate()) { | 126 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 127 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 127 ui::OSExchangeData os_exchange_data( |
| 128 new ui::OSExchangeDataProviderWin(data_object)); |
| 128 BookmarkNodeData bookmark_drag_data; | 129 BookmarkNodeData bookmark_drag_data; |
| 129 if (bookmark_drag_data.Read(os_exchange_data)) | 130 if (bookmark_drag_data.Read(os_exchange_data)) |
| 130 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data); | 131 tab_contents_->GetBookmarkDragDelegate()->OnDragEnter(bookmark_drag_data); |
| 131 } | 132 } |
| 132 | 133 |
| 133 // We lie here and always return a DROPEFFECT because we don't want to | 134 // We lie here and always return a DROPEFFECT because we don't want to |
| 134 // wait for the IPC call to return. | 135 // wait for the IPC call to return. |
| 135 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 136 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 136 } | 137 } |
| 137 | 138 |
| 138 DWORD WebDropTarget::OnDragOver(IDataObject* data_object, | 139 DWORD WebDropTarget::OnDragOver(IDataObject* data_object, |
| 139 DWORD key_state, | 140 DWORD key_state, |
| 140 POINT cursor_position, | 141 POINT cursor_position, |
| 141 DWORD effects) { | 142 DWORD effects) { |
| 142 DCHECK(current_rvh_); | 143 DCHECK(current_rvh_); |
| 143 if (current_rvh_ != tab_contents_->render_view_host()) | 144 if (current_rvh_ != tab_contents_->render_view_host()) |
| 144 OnDragEnter(data_object, key_state, cursor_position, effects); | 145 OnDragEnter(data_object, key_state, cursor_position, effects); |
| 145 | 146 |
| 146 if (tab_contents_->showing_interstitial_page()) | 147 if (tab_contents_->showing_interstitial_page()) |
| 147 return interstitial_drop_target_->OnDragOver(data_object, effects); | 148 return interstitial_drop_target_->OnDragOver(data_object, effects); |
| 148 | 149 |
| 149 POINT client_pt = cursor_position; | 150 POINT client_pt = cursor_position; |
| 150 ScreenToClient(GetHWND(), &client_pt); | 151 ScreenToClient(GetHWND(), &client_pt); |
| 151 tab_contents_->render_view_host()->DragTargetDragOver( | 152 tab_contents_->render_view_host()->DragTargetDragOver( |
| 152 gfx::Point(client_pt.x, client_pt.y), | 153 gfx::Point(client_pt.x, client_pt.y), |
| 153 gfx::Point(cursor_position.x, cursor_position.y), | 154 gfx::Point(cursor_position.x, cursor_position.y), |
| 154 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 155 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); |
| 155 | 156 |
| 156 if (tab_contents_->GetBookmarkDragDelegate()) { | 157 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 157 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 158 ui::OSExchangeData os_exchange_data( |
| 159 new ui::OSExchangeDataProviderWin(data_object)); |
| 158 BookmarkNodeData bookmark_drag_data; | 160 BookmarkNodeData bookmark_drag_data; |
| 159 if (bookmark_drag_data.Read(os_exchange_data)) | 161 if (bookmark_drag_data.Read(os_exchange_data)) |
| 160 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data); | 162 tab_contents_->GetBookmarkDragDelegate()->OnDragOver(bookmark_drag_data); |
| 161 } | 163 } |
| 162 | 164 |
| 163 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 165 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void WebDropTarget::OnDragLeave(IDataObject* data_object) { | 168 void WebDropTarget::OnDragLeave(IDataObject* data_object) { |
| 167 DCHECK(current_rvh_); | 169 DCHECK(current_rvh_); |
| 168 if (current_rvh_ != tab_contents_->render_view_host()) | 170 if (current_rvh_ != tab_contents_->render_view_host()) |
| 169 return; | 171 return; |
| 170 | 172 |
| 171 if (tab_contents_->showing_interstitial_page()) { | 173 if (tab_contents_->showing_interstitial_page()) { |
| 172 interstitial_drop_target_->OnDragLeave(data_object); | 174 interstitial_drop_target_->OnDragLeave(data_object); |
| 173 } else { | 175 } else { |
| 174 tab_contents_->render_view_host()->DragTargetDragLeave(); | 176 tab_contents_->render_view_host()->DragTargetDragLeave(); |
| 175 } | 177 } |
| 176 | 178 |
| 177 if (tab_contents_->GetBookmarkDragDelegate()) { | 179 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 178 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 180 ui::OSExchangeData os_exchange_data( |
| 181 new ui::OSExchangeDataProviderWin(data_object)); |
| 179 BookmarkNodeData bookmark_drag_data; | 182 BookmarkNodeData bookmark_drag_data; |
| 180 if (bookmark_drag_data.Read(os_exchange_data)) | 183 if (bookmark_drag_data.Read(os_exchange_data)) |
| 181 tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data); | 184 tab_contents_->GetBookmarkDragDelegate()->OnDragLeave(bookmark_drag_data); |
| 182 } | 185 } |
| 183 } | 186 } |
| 184 | 187 |
| 185 DWORD WebDropTarget::OnDrop(IDataObject* data_object, | 188 DWORD WebDropTarget::OnDrop(IDataObject* data_object, |
| 186 DWORD key_state, | 189 DWORD key_state, |
| 187 POINT cursor_position, | 190 POINT cursor_position, |
| 188 DWORD effect) { | 191 DWORD effect) { |
| 189 DCHECK(current_rvh_); | 192 DCHECK(current_rvh_); |
| 190 if (current_rvh_ != tab_contents_->render_view_host()) | 193 if (current_rvh_ != tab_contents_->render_view_host()) |
| 191 OnDragEnter(data_object, key_state, cursor_position, effect); | 194 OnDragEnter(data_object, key_state, cursor_position, effect); |
| 192 | 195 |
| 193 if (tab_contents_->showing_interstitial_page()) | 196 if (tab_contents_->showing_interstitial_page()) |
| 194 interstitial_drop_target_->OnDragOver(data_object, effect); | 197 interstitial_drop_target_->OnDragOver(data_object, effect); |
| 195 | 198 |
| 196 if (tab_contents_->showing_interstitial_page()) | 199 if (tab_contents_->showing_interstitial_page()) |
| 197 return interstitial_drop_target_->OnDrop(data_object, effect); | 200 return interstitial_drop_target_->OnDrop(data_object, effect); |
| 198 | 201 |
| 199 POINT client_pt = cursor_position; | 202 POINT client_pt = cursor_position; |
| 200 ScreenToClient(GetHWND(), &client_pt); | 203 ScreenToClient(GetHWND(), &client_pt); |
| 201 tab_contents_->render_view_host()->DragTargetDrop( | 204 tab_contents_->render_view_host()->DragTargetDrop( |
| 202 gfx::Point(client_pt.x, client_pt.y), | 205 gfx::Point(client_pt.x, client_pt.y), |
| 203 gfx::Point(cursor_position.x, cursor_position.y)); | 206 gfx::Point(cursor_position.x, cursor_position.y)); |
| 204 | 207 |
| 205 if (tab_contents_->GetBookmarkDragDelegate()) { | 208 if (tab_contents_->GetBookmarkDragDelegate()) { |
| 206 OSExchangeData os_exchange_data(new OSExchangeDataProviderWin(data_object)); | 209 ui::OSExchangeData os_exchange_data( |
| 210 new ui::OSExchangeDataProviderWin(data_object)); |
| 207 BookmarkNodeData bookmark_drag_data; | 211 BookmarkNodeData bookmark_drag_data; |
| 208 if (bookmark_drag_data.Read(os_exchange_data)) | 212 if (bookmark_drag_data.Read(os_exchange_data)) |
| 209 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data); | 213 tab_contents_->GetBookmarkDragDelegate()->OnDrop(bookmark_drag_data); |
| 210 } | 214 } |
| 211 | 215 |
| 212 current_rvh_ = NULL; | 216 current_rvh_ = NULL; |
| 213 | 217 |
| 214 // This isn't always correct, but at least it's a close approximation. | 218 // This isn't always correct, but at least it's a close approximation. |
| 215 // For now, we always map a move to a copy to prevent potential data loss. | 219 // For now, we always map a move to a copy to prevent potential data loss. |
| 216 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 220 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 217 return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; | 221 return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; |
| 218 } | 222 } |
| OLD | NEW |