Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: content/browser/web_contents/web_drag_source_mac.mm

Issue 2674953003: Only generate suggested filenames when actually dragging an image. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.cc ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/web_contents/web_drag_source_mac.mm
diff --git a/content/browser/web_contents/web_drag_source_mac.mm b/content/browser/web_contents/web_drag_source_mac.mm
index 8990463bcbe28b70959c2859e6f271a530c85286..301fd88158c6288e4cfc4f3e7c999b659e05b9e6 100644
--- a/content/browser/web_contents/web_drag_source_mac.mm
+++ b/content/browser/web_contents/web_drag_source_mac.mm
@@ -53,38 +53,6 @@ namespace {
// |NSURLPboardType|.
NSString* const kNSURLTitlePboardType = @"public.url-name";
-// Converts a base::string16 into a FilePath. Use this method instead of
-// -[NSString fileSystemRepresentation] to prevent exceptions from being thrown.
-// See http://crbug.com/78782 for more info.
-base::FilePath FilePathFromFilename(const base::string16& filename) {
- NSString* str = SysUTF16ToNSString(filename);
- char buf[MAXPATHLEN];
- if (![str getFileSystemRepresentation:buf maxLength:sizeof(buf)])
- return base::FilePath();
- return base::FilePath(buf);
-}
-
-// Returns a filename appropriate for the drop data
-// TODO(viettrungluu): Refactor to make it common across platforms,
-// and move it somewhere sensible.
-base::FilePath GetFileNameFromDragData(const DropData& drop_data) {
- base::FilePath file_name(
- FilePathFromFilename(drop_data.file_description_filename));
-
- // Images without ALT text will only have a file extension so we need to
- // synthesize one from the provided extension and URL.
- if (file_name.empty()) {
- // Retrieve the name from the URL.
- base::string16 suggested_filename =
- net::GetSuggestedFilename(drop_data.url, "", "", "", "", "");
- const std::string extension = file_name.Extension();
- file_name = FilePathFromFilename(suggested_filename);
- file_name = file_name.ReplaceExtension(extension);
- }
-
- return file_name;
-}
-
// This helper's sole task is to write out data for a promised file; the caller
// is responsible for opening the file. It takes the drop data and an open file
// stream.
@@ -389,8 +357,12 @@ void PromiseWriterHelper(const DropData& drop_data,
if (!dropData_->file_contents.empty() ||
!dropData_->download_metadata.empty()) {
if (dropData_->download_metadata.empty()) {
- downloadFileName_ = GetFileNameFromDragData(*dropData_);
- net::GetMimeTypeFromExtension(downloadFileName_.Extension(), &mimeType);
+ base::Optional<base::FilePath> suggestedFilename =
+ dropData_->GetSafeFilenameForImageFileContents();
+ if (suggestedFilename) {
+ downloadFileName_ = std::move(*suggestedFilename);
+ net::GetMimeTypeFromExtension(downloadFileName_.Extension(), &mimeType);
+ }
} else {
base::string16 mimeType16;
base::FilePath fileName;
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.cc ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698