| OLD | NEW |
| 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_dest_win.h" | 5 #include "content/browser/web_contents/web_drag_dest_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 | 9 |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 delegate_->DragInitialize(web_contents_); | 108 delegate_->DragInitialize(web_contents_); |
| 109 | 109 |
| 110 // Don't pass messages to the renderer if an interstitial page is showing | 110 // Don't pass messages to the renderer if an interstitial page is showing |
| 111 // because we don't want the interstitial page to navigate. Instead, | 111 // because we don't want the interstitial page to navigate. Instead, |
| 112 // pass the messages on to a separate interstitial DropTarget handler. | 112 // pass the messages on to a separate interstitial DropTarget handler. |
| 113 if (web_contents_->ShowingInterstitialPage()) | 113 if (web_contents_->ShowingInterstitialPage()) |
| 114 return interstitial_drop_target_->OnDragEnter(data_object, effects); | 114 return interstitial_drop_target_->OnDragEnter(data_object, effects); |
| 115 | 115 |
| 116 // TODO(tc): PopulateWebDropData can be slow depending on what is in the | 116 // TODO(tc): PopulateWebDropData can be slow depending on what is in the |
| 117 // IDataObject. Maybe we can do this in a background thread. | 117 // IDataObject. Maybe we can do this in a background thread. |
| 118 WebDropData drop_data; | 118 drop_data_.reset(new WebDropData()); |
| 119 WebDropData::PopulateWebDropData(data_object, &drop_data); | 119 WebDropData::PopulateWebDropData(data_object, drop_data_.get()); |
| 120 | 120 |
| 121 if (drop_data.url.is_empty()) | 121 if (drop_data_->url.is_empty()) |
| 122 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, &drop_data.url); | 122 ui::OSExchangeDataProviderWin::GetPlainTextURL(data_object, |
| 123 &drop_data_->url); |
| 123 | 124 |
| 124 drag_cursor_ = WebDragOperationNone; | 125 drag_cursor_ = WebDragOperationNone; |
| 125 | 126 |
| 126 POINT client_pt = cursor_position; | 127 POINT client_pt = cursor_position; |
| 127 ScreenToClient(GetHWND(), &client_pt); | 128 ScreenToClient(GetHWND(), &client_pt); |
| 128 web_contents_->GetRenderViewHost()->DragTargetDragEnter(drop_data, | 129 web_contents_->GetRenderViewHost()->DragTargetDragEnter(*drop_data_, |
| 129 gfx::Point(client_pt.x, client_pt.y), | 130 gfx::Point(client_pt.x, client_pt.y), |
| 130 gfx::Point(cursor_position.x, cursor_position.y), | 131 gfx::Point(cursor_position.x, cursor_position.y), |
| 131 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); | 132 web_drag_utils_win::WinDragOpMaskToWebDragOpMask(effects)); |
| 132 | 133 |
| 133 if (delegate_) | 134 if (delegate_) |
| 134 delegate_->OnDragEnter(data_object); | 135 delegate_->OnDragEnter(data_object); |
| 135 | 136 |
| 136 // We lie here and always return a DROPEFFECT because we don't want to | 137 // We lie here and always return a DROPEFFECT because we don't want to |
| 137 // wait for the IPC call to return. | 138 // wait for the IPC call to return. |
| 138 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 139 return web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 168 return; | 169 return; |
| 169 | 170 |
| 170 if (web_contents_->ShowingInterstitialPage()) { | 171 if (web_contents_->ShowingInterstitialPage()) { |
| 171 interstitial_drop_target_->OnDragLeave(data_object); | 172 interstitial_drop_target_->OnDragLeave(data_object); |
| 172 } else { | 173 } else { |
| 173 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); | 174 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 if (delegate_) | 177 if (delegate_) |
| 177 delegate_->OnDragLeave(data_object); | 178 delegate_->OnDragLeave(data_object); |
| 179 |
| 180 drop_data_.reset(); |
| 178 } | 181 } |
| 179 | 182 |
| 180 DWORD WebDragDest::OnDrop(IDataObject* data_object, | 183 DWORD WebDragDest::OnDrop(IDataObject* data_object, |
| 181 DWORD key_state, | 184 DWORD key_state, |
| 182 POINT cursor_position, | 185 POINT cursor_position, |
| 183 DWORD effect) { | 186 DWORD effect) { |
| 184 DCHECK(current_rvh_); | 187 DCHECK(current_rvh_); |
| 185 if (current_rvh_ != web_contents_->GetRenderViewHost()) | 188 if (current_rvh_ != web_contents_->GetRenderViewHost()) |
| 186 OnDragEnter(data_object, key_state, cursor_position, effect); | 189 OnDragEnter(data_object, key_state, cursor_position, effect); |
| 187 | 190 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 198 gfx::Point(cursor_position.x, cursor_position.y)); | 201 gfx::Point(cursor_position.x, cursor_position.y)); |
| 199 | 202 |
| 200 if (delegate_) | 203 if (delegate_) |
| 201 delegate_->OnDrop(data_object); | 204 delegate_->OnDrop(data_object); |
| 202 | 205 |
| 203 current_rvh_ = NULL; | 206 current_rvh_ = NULL; |
| 204 | 207 |
| 205 // This isn't always correct, but at least it's a close approximation. | 208 // This isn't always correct, but at least it's a close approximation. |
| 206 // For now, we always map a move to a copy to prevent potential data loss. | 209 // For now, we always map a move to a copy to prevent potential data loss. |
| 207 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); | 210 DWORD drop_effect = web_drag_utils_win::WebDragOpToWinDragOp(drag_cursor_); |
| 208 return drop_effect != DROPEFFECT_MOVE ? drop_effect : DROPEFFECT_COPY; | 211 DWORD result = drop_effect != DROPEFFECT_MOVE ? |
| 212 drop_effect : DROPEFFECT_COPY; |
| 213 |
| 214 drop_data_.reset(); |
| 215 return result; |
| 209 } | 216 } |
| OLD | NEW |