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 "app/mac/nsimage_cache.h" | 9 #include "app/mac/nsimage_cache.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ScopedCrashKey key(kUrlKey, value); | 62 ScopedCrashKey key(kUrlKey, value); |
63 | 63 |
64 // Images without ALT text will only have a file extension so we need to | 64 // Images without ALT text will only have a file extension so we need to |
65 // synthesize one from the provided extension and URL. | 65 // synthesize one from the provided extension and URL. |
66 FilePath file_name(FilePathFromFilename(drop_data.file_description_filename)); | 66 FilePath file_name(FilePathFromFilename(drop_data.file_description_filename)); |
67 file_name = file_name.BaseName().RemoveExtension(); | 67 file_name = file_name.BaseName().RemoveExtension(); |
68 | 68 |
69 if (file_name.empty()) { | 69 if (file_name.empty()) { |
70 // Retrieve the name from the URL. | 70 // Retrieve the name from the URL. |
71 string16 suggested_filename = | 71 string16 suggested_filename = |
72 net::GetSuggestedFilename(drop_data.url, "", "", string16()); | 72 net::GetSuggestedFilename(drop_data.url, "", "", "", string16()); |
73 file_name = FilePathFromFilename(suggested_filename); | 73 file_name = FilePathFromFilename(suggested_filename); |
74 } | 74 } |
75 | 75 |
76 file_name = file_name.ReplaceExtension(UTF16ToUTF8(drop_data.file_extension)); | 76 file_name = file_name.ReplaceExtension(UTF16ToUTF8(drop_data.file_extension)); |
77 | 77 |
78 return file_name; | 78 return file_name; |
79 } | 79 } |
80 | 80 |
81 // This class's sole task is to write out data for a promised file; the caller | 81 // This class's sole task is to write out data for a promised file; the caller |
82 // is responsible for opening the file. | 82 // is responsible for opening the file. |
(...skipping 312 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 std::string contentDisposition = | 405 download_util::GenerateFileNameFromSuggestedName( |
406 "attachment; filename=" + fileName.value(); | 406 downloadURL_, |
407 download_util::GenerateFileName(downloadURL_, | 407 fileName.value(), |
408 contentDisposition, | 408 UTF16ToUTF8(mimeType), |
409 std::string(), | 409 &downloadFileName_); |
410 UTF16ToUTF8(mimeType), | |
411 &downloadFileName_); | |
412 fileExtension = SysUTF8ToNSString(downloadFileName_.Extension()); | 410 fileExtension = SysUTF8ToNSString(downloadFileName_.Extension()); |
413 } | 411 } |
414 } | 412 } |
415 | 413 |
416 if (fileExtension) { | 414 if (fileExtension) { |
417 // File contents (with and without specific type), file (HFS) promise, | 415 // File contents (with and without specific type), file (HFS) promise, |
418 // TIFF. | 416 // TIFF. |
419 // TODO(viettrungluu): others? | 417 // TODO(viettrungluu): others? |
420 [pasteboard_ addTypes:[NSArray arrayWithObjects: | 418 [pasteboard_ addTypes:[NSArray arrayWithObjects: |
421 NSFileContentsPboardType, | 419 NSFileContentsPboardType, |
(...skipping 17 matching lines...) Expand all Loading... |
439 | 437 |
440 - (NSImage*)dragImage { | 438 - (NSImage*)dragImage { |
441 if (dragImage_) | 439 if (dragImage_) |
442 return dragImage_; | 440 return dragImage_; |
443 | 441 |
444 // Default to returning a generic image. | 442 // Default to returning a generic image. |
445 return app::mac::GetCachedImageWithName(@"nav.pdf"); | 443 return app::mac::GetCachedImageWithName(@"nav.pdf"); |
446 } | 444 } |
447 | 445 |
448 @end // @implementation WebDragSource (Private) | 446 @end // @implementation WebDragSource (Private) |
OLD | NEW |