OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/tab_contents/web_drag_source.h" | 5 #import "chrome/browser/ui/cocoa/tab_contents/web_drag_source.h" |
6 | 6 |
7 #include <sys/param.h> | 7 #include <sys/param.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "base/task.h" | 12 #include "base/task.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/download/download_util.h" | |
18 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" | 17 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
19 #include "content/browser/download/drag_download_file.h" | 18 #include "content/browser/download/drag_download_file.h" |
20 #include "content/browser/download/drag_download_util.h" | 19 #include "content/browser/download/drag_download_util.h" |
21 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 22 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
24 #include "net/base/file_stream.h" | 24 #include "net/base/file_stream.h" |
25 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
26 #include "ui/gfx/mac/nsimage_cache.h" | 26 #include "ui/gfx/mac/nsimage_cache.h" |
27 #include "webkit/glue/webdropdata.h" | 27 #include "webkit/glue/webdropdata.h" |
28 | 28 |
29 using base::SysNSStringToUTF8; | 29 using base::SysNSStringToUTF8; |
30 using base::SysUTF8ToNSString; | 30 using base::SysUTF8ToNSString; |
31 using base::SysUTF16ToNSString; | 31 using base::SysUTF16ToNSString; |
32 using net::FileStream; | 32 using net::FileStream; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 fileExtension = (dropData_->file_extension.length() > 0) ? | 395 fileExtension = (dropData_->file_extension.length() > 0) ? |
396 SysUTF16ToNSString(dropData_->file_extension.substr(1)) : @""; | 396 SysUTF16ToNSString(dropData_->file_extension.substr(1)) : @""; |
397 } else { | 397 } else { |
398 string16 mimeType; | 398 string16 mimeType; |
399 FilePath fileName; | 399 FilePath fileName; |
400 if (drag_download_util::ParseDownloadMetadata( | 400 if (drag_download_util::ParseDownloadMetadata( |
401 dropData_->download_metadata, | 401 dropData_->download_metadata, |
402 &mimeType, | 402 &mimeType, |
403 &fileName, | 403 &fileName, |
404 &downloadURL_)) { | 404 &downloadURL_)) { |
405 download_util::GenerateFileNameFromSuggestedName( | 405 // Generate the file name based on both mime type and proposed file |
406 downloadURL_, | 406 // name. |
407 fileName.value(), | 407 std::string defaultName = |
408 UTF16ToUTF8(mimeType), | 408 content::GetContentClient()->browser()->GetDefaultDownloadName(); |
409 &downloadFileName_); | 409 downloadFileName_ = |
| 410 net::GenerateFileName(downloadURL_, |
| 411 std::string(), |
| 412 std::string(), |
| 413 fileName.value(), |
| 414 UTF16ToUTF8(mimeType), |
| 415 defaultName); |
410 fileExtension = SysUTF8ToNSString(downloadFileName_.Extension()); | 416 fileExtension = SysUTF8ToNSString(downloadFileName_.Extension()); |
411 } | 417 } |
412 } | 418 } |
413 | 419 |
414 if (fileExtension) { | 420 if (fileExtension) { |
415 // File contents (with and without specific type), file (HFS) promise, | 421 // File contents (with and without specific type), file (HFS) promise, |
416 // TIFF. | 422 // TIFF. |
417 // TODO(viettrungluu): others? | 423 // TODO(viettrungluu): others? |
418 [pasteboard_ addTypes:[NSArray arrayWithObjects: | 424 [pasteboard_ addTypes:[NSArray arrayWithObjects: |
419 NSFileContentsPboardType, | 425 NSFileContentsPboardType, |
(...skipping 17 matching lines...) Expand all Loading... |
437 | 443 |
438 - (NSImage*)dragImage { | 444 - (NSImage*)dragImage { |
439 if (dragImage_) | 445 if (dragImage_) |
440 return dragImage_; | 446 return dragImage_; |
441 | 447 |
442 // Default to returning a generic image. | 448 // Default to returning a generic image. |
443 return gfx::GetCachedImageWithName(@"nav.pdf"); | 449 return gfx::GetCachedImageWithName(@"nav.pdf"); |
444 } | 450 } |
445 | 451 |
446 @end // @implementation WebDragSource (Private) | 452 @end // @implementation WebDragSource (Private) |
OLD | NEW |