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_contents_drag_win.h" | 5 #include "content/browser/web_contents/web_contents_drag_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/pickle.h" | 15 #include "base/pickle.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "content/browser/download/drag_download_file.h" | 19 #include "content/browser/download/drag_download_file.h" |
20 #include "content/browser/download/drag_download_util.h" | 20 #include "content/browser/download/drag_download_util.h" |
21 #include "content/browser/web_contents/web_drag_dest_win.h" | 21 #include "content/browser/web_contents/web_drag_dest_win.h" |
22 #include "content/browser/web_contents/web_drag_source_win.h" | 22 #include "content/browser/web_contents/web_drag_source_win.h" |
23 #include "content/browser/web_contents/web_drag_utils_win.h" | 23 #include "content/browser/web_contents/web_drag_utils_win.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/content_browser_client.h" | 25 #include "content/public/browser/content_browser_client.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_view.h" | 27 #include "content/public/browser/web_contents_view.h" |
28 #include "content/public/browser/web_drag_dest_delegate.h" | 28 #include "content/public/browser/web_drag_dest_delegate.h" |
| 29 #include "content/public/common/drop_data.h" |
29 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
30 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
31 #include "ui/base/clipboard/clipboard.h" | 32 #include "ui/base/clipboard/clipboard.h" |
32 #include "ui/base/clipboard/custom_data_helper.h" | 33 #include "ui/base/clipboard/custom_data_helper.h" |
33 #include "ui/base/dragdrop/drag_utils.h" | 34 #include "ui/base/dragdrop/drag_utils.h" |
34 #include "ui/base/layout.h" | 35 #include "ui/base/layout.h" |
35 #include "ui/base/win/scoped_ole_initializer.h" | 36 #include "ui/base/win/scoped_ole_initializer.h" |
36 #include "ui/gfx/image/image_skia.h" | 37 #include "ui/gfx/image/image_skia.h" |
37 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
38 #include "ui/gfx/size.h" | 39 #include "ui/gfx/size.h" |
39 #include "webkit/common/webdropdata.h" | |
40 | 40 |
41 using WebKit::WebDragOperationsMask; | 41 using WebKit::WebDragOperationsMask; |
42 using WebKit::WebDragOperationCopy; | 42 using WebKit::WebDragOperationCopy; |
43 using WebKit::WebDragOperationLink; | 43 using WebKit::WebDragOperationLink; |
44 using WebKit::WebDragOperationMove; | 44 using WebKit::WebDragOperationMove; |
45 | 45 |
46 namespace content { | 46 namespace content { |
47 namespace { | 47 namespace { |
48 | 48 |
49 bool run_do_drag_drop = true; | 49 bool run_do_drag_drop = true; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 drag_dest_(drag_dest), | 148 drag_dest_(drag_dest), |
149 drag_ended_(false), | 149 drag_ended_(false), |
150 drag_end_callback_(drag_end_callback) { | 150 drag_end_callback_(drag_end_callback) { |
151 } | 151 } |
152 | 152 |
153 WebContentsDragWin::~WebContentsDragWin() { | 153 WebContentsDragWin::~WebContentsDragWin() { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
155 DCHECK(!drag_drop_thread_.get()); | 155 DCHECK(!drag_drop_thread_.get()); |
156 } | 156 } |
157 | 157 |
158 void WebContentsDragWin::StartDragging(const WebDropData& drop_data, | 158 void WebContentsDragWin::StartDragging(const DropData& drop_data, |
159 WebDragOperationsMask ops, | 159 WebDragOperationsMask ops, |
160 const gfx::ImageSkia& image, | 160 const gfx::ImageSkia& image, |
161 const gfx::Vector2d& image_offset) { | 161 const gfx::Vector2d& image_offset) { |
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
163 | 163 |
164 drag_source_ = new WebDragSource(source_window_, web_contents_); | 164 drag_source_ = new WebDragSource(source_window_, web_contents_); |
165 | 165 |
166 const GURL& page_url = web_contents_->GetURL(); | 166 const GURL& page_url = web_contents_->GetURL(); |
167 const std::string& page_encoding = web_contents_->GetEncoding(); | 167 const std::string& page_encoding = web_contents_->GetEncoding(); |
168 | 168 |
(...skipping 15 matching lines...) Expand all Loading... |
184 FROM_HERE, | 184 FROM_HERE, |
185 base::Bind(&WebContentsDragWin::StartBackgroundDragging, this, | 185 base::Bind(&WebContentsDragWin::StartBackgroundDragging, this, |
186 drop_data, ops, page_url, page_encoding, | 186 drop_data, ops, page_url, page_encoding, |
187 image, image_offset)); | 187 image, image_offset)); |
188 } | 188 } |
189 | 189 |
190 EnableBackgroundDraggingSupport(drag_drop_thread_->thread_id()); | 190 EnableBackgroundDraggingSupport(drag_drop_thread_->thread_id()); |
191 } | 191 } |
192 | 192 |
193 void WebContentsDragWin::StartBackgroundDragging( | 193 void WebContentsDragWin::StartBackgroundDragging( |
194 const WebDropData& drop_data, | 194 const DropData& drop_data, |
195 WebDragOperationsMask ops, | 195 WebDragOperationsMask ops, |
196 const GURL& page_url, | 196 const GURL& page_url, |
197 const std::string& page_encoding, | 197 const std::string& page_encoding, |
198 const gfx::ImageSkia& image, | 198 const gfx::ImageSkia& image, |
199 const gfx::Vector2d& image_offset) { | 199 const gfx::Vector2d& image_offset) { |
200 drag_drop_thread_id_ = base::PlatformThread::CurrentId(); | 200 drag_drop_thread_id_ = base::PlatformThread::CurrentId(); |
201 | 201 |
202 if (DoDragging(drop_data, ops, page_url, page_encoding, | 202 if (DoDragging(drop_data, ops, page_url, page_encoding, |
203 image, image_offset)) { | 203 image, image_offset)) { |
204 BrowserThread::PostTask( | 204 BrowserThread::PostTask( |
(...skipping 10 matching lines...) Expand all Loading... |
215 // 2) Stop the background thread. This is done in OnDataObjectDisposed. | 215 // 2) Stop the background thread. This is done in OnDataObjectDisposed. |
216 // Only drag_drop_thread_ member is accessed. | 216 // Only drag_drop_thread_ member is accessed. |
217 BrowserThread::PostTask( | 217 BrowserThread::PostTask( |
218 BrowserThread::UI, | 218 BrowserThread::UI, |
219 FROM_HERE, | 219 FROM_HERE, |
220 base::Bind(&DisableBackgroundDraggingSupport)); | 220 base::Bind(&DisableBackgroundDraggingSupport)); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void WebContentsDragWin::PrepareDragForDownload( | 224 void WebContentsDragWin::PrepareDragForDownload( |
225 const WebDropData& drop_data, | 225 const DropData& drop_data, |
226 ui::OSExchangeData* data, | 226 ui::OSExchangeData* data, |
227 const GURL& page_url, | 227 const GURL& page_url, |
228 const std::string& page_encoding) { | 228 const std::string& page_encoding) { |
229 // Parse the download metadata. | 229 // Parse the download metadata. |
230 string16 mime_type; | 230 string16 mime_type; |
231 base::FilePath file_name; | 231 base::FilePath file_name; |
232 GURL download_url; | 232 GURL download_url; |
233 if (!ParseDownloadMetadata(drop_data.download_metadata, | 233 if (!ParseDownloadMetadata(drop_data.download_metadata, |
234 &mime_type, | 234 &mime_type, |
235 &file_name, | 235 &file_name, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 web_contents_); | 270 web_contents_); |
271 ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(), | 271 ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(), |
272 download_file.get()); | 272 download_file.get()); |
273 data->SetDownloadFileInfo(file_download); | 273 data->SetDownloadFileInfo(file_download); |
274 | 274 |
275 // Enable asynchronous operation. | 275 // Enable asynchronous operation. |
276 ui::OSExchangeDataProviderWin::GetIAsyncOperation(*data)->SetAsyncMode(TRUE); | 276 ui::OSExchangeDataProviderWin::GetIAsyncOperation(*data)->SetAsyncMode(TRUE); |
277 } | 277 } |
278 | 278 |
279 void WebContentsDragWin::PrepareDragForFileContents( | 279 void WebContentsDragWin::PrepareDragForFileContents( |
280 const WebDropData& drop_data, ui::OSExchangeData* data) { | 280 const DropData& drop_data, ui::OSExchangeData* data) { |
281 static const int kMaxFilenameLength = 255; // FAT and NTFS | 281 static const int kMaxFilenameLength = 255; // FAT and NTFS |
282 base::FilePath file_name(drop_data.file_description_filename); | 282 base::FilePath file_name(drop_data.file_description_filename); |
283 | 283 |
284 // Images without ALT text will only have a file extension so we need to | 284 // Images without ALT text will only have a file extension so we need to |
285 // synthesize one from the provided extension and URL. | 285 // synthesize one from the provided extension and URL. |
286 if (file_name.BaseName().RemoveExtension().empty()) { | 286 if (file_name.BaseName().RemoveExtension().empty()) { |
287 const string16 extension = file_name.Extension(); | 287 const string16 extension = file_name.Extension(); |
288 // Retrieve the name from the URL. | 288 // Retrieve the name from the URL. |
289 file_name = base::FilePath( | 289 file_name = base::FilePath( |
290 net::GetSuggestedFilename(drop_data.url, "", "", "", "", "")); | 290 net::GetSuggestedFilename(drop_data.url, "", "", "", "", "")); |
291 if (file_name.value().size() + extension.size() > kMaxFilenameLength) { | 291 if (file_name.value().size() + extension.size() > kMaxFilenameLength) { |
292 file_name = base::FilePath(file_name.value().substr( | 292 file_name = base::FilePath(file_name.value().substr( |
293 0, kMaxFilenameLength - extension.size())); | 293 0, kMaxFilenameLength - extension.size())); |
294 } | 294 } |
295 file_name = file_name.ReplaceExtension(extension); | 295 file_name = file_name.ReplaceExtension(extension); |
296 } | 296 } |
297 data->SetFileContents(file_name, drop_data.file_contents); | 297 data->SetFileContents(file_name, drop_data.file_contents); |
298 } | 298 } |
299 | 299 |
300 void WebContentsDragWin::PrepareDragForUrl(const WebDropData& drop_data, | 300 void WebContentsDragWin::PrepareDragForUrl(const DropData& drop_data, |
301 ui::OSExchangeData* data) { | 301 ui::OSExchangeData* data) { |
302 if (drag_dest_->delegate() && | 302 if (drag_dest_->delegate() && |
303 drag_dest_->delegate()->AddDragData(drop_data, data)) { | 303 drag_dest_->delegate()->AddDragData(drop_data, data)) { |
304 return; | 304 return; |
305 } | 305 } |
306 | 306 |
307 data->SetURL(drop_data.url, drop_data.url_title); | 307 data->SetURL(drop_data.url, drop_data.url_title); |
308 } | 308 } |
309 | 309 |
310 bool WebContentsDragWin::DoDragging(const WebDropData& drop_data, | 310 bool WebContentsDragWin::DoDragging(const DropData& drop_data, |
311 WebDragOperationsMask ops, | 311 WebDragOperationsMask ops, |
312 const GURL& page_url, | 312 const GURL& page_url, |
313 const std::string& page_encoding, | 313 const std::string& page_encoding, |
314 const gfx::ImageSkia& image, | 314 const gfx::ImageSkia& image, |
315 const gfx::Vector2d& image_offset) { | 315 const gfx::Vector2d& image_offset) { |
316 ui::OSExchangeData data; | 316 ui::OSExchangeData data; |
317 | 317 |
318 if (!drop_data.download_metadata.empty()) { | 318 if (!drop_data.download_metadata.empty()) { |
319 PrepareDragForDownload(drop_data, &data, page_url, page_encoding); | 319 PrepareDragForDownload(drop_data, &data, page_url, page_encoding); |
320 | 320 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 FROM_HERE, | 434 FROM_HERE, |
435 base::Bind(&WebContentsDragWin::CloseThread, this)); | 435 base::Bind(&WebContentsDragWin::CloseThread, this)); |
436 } | 436 } |
437 | 437 |
438 // static | 438 // static |
439 void WebContentsDragWin::DisableDragDropForTesting() { | 439 void WebContentsDragWin::DisableDragDropForTesting() { |
440 run_do_drag_drop = false; | 440 run_do_drag_drop = false; |
441 } | 441 } |
442 | 442 |
443 } // namespace content | 443 } // namespace content |
OLD | NEW |