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

Side by Side Diff: content/browser/web_contents/web_drag_source_mac.mm

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import "content/browser/web_contents/web_drag_source_mac.h" 5 #import "content/browser/web_contents/web_drag_source_mac.h"
6 6
7 #include <sys/param.h> 7 #include <sys/param.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 namespace { 45 namespace {
46 46
47 // An unofficial standard pasteboard title type to be provided alongside the 47 // An unofficial standard pasteboard title type to be provided alongside the
48 // |NSURLPboardType|. 48 // |NSURLPboardType|.
49 NSString* const kNSURLTitlePboardType = @"public.url-name"; 49 NSString* const kNSURLTitlePboardType = @"public.url-name";
50 50
51 // Converts a string16 into a FilePath. Use this method instead of 51 // Converts a string16 into a FilePath. Use this method instead of
52 // -[NSString fileSystemRepresentation] to prevent exceptions from being thrown. 52 // -[NSString fileSystemRepresentation] to prevent exceptions from being thrown.
53 // See http://crbug.com/78782 for more info. 53 // See http://crbug.com/78782 for more info.
54 FilePath FilePathFromFilename(const string16& filename) { 54 base::FilePath FilePathFromFilename(const string16& filename) {
55 NSString* str = SysUTF16ToNSString(filename); 55 NSString* str = SysUTF16ToNSString(filename);
56 char buf[MAXPATHLEN]; 56 char buf[MAXPATHLEN];
57 if (![str getFileSystemRepresentation:buf maxLength:sizeof(buf)]) 57 if (![str getFileSystemRepresentation:buf maxLength:sizeof(buf)])
58 return FilePath(); 58 return base::FilePath();
59 return FilePath(buf); 59 return base::FilePath(buf);
60 } 60 }
61 61
62 // Returns a filename appropriate for the drop data 62 // Returns a filename appropriate for the drop data
63 // TODO(viettrungluu): Refactor to make it common across platforms, 63 // TODO(viettrungluu): Refactor to make it common across platforms,
64 // and move it somewhere sensible. 64 // and move it somewhere sensible.
65 FilePath GetFileNameFromDragData(const WebDropData& drop_data) { 65 base::FilePath GetFileNameFromDragData(const WebDropData& drop_data) {
66 FilePath file_name(FilePathFromFilename(drop_data.file_description_filename)); 66 base::FilePath file_name(
67 FilePathFromFilename(drop_data.file_description_filename));
67 68
68 // Images without ALT text will only have a file extension so we need to 69 // Images without ALT text will only have a file extension so we need to
69 // synthesize one from the provided extension and URL. 70 // synthesize one from the provided extension and URL.
70 if (file_name.empty()) { 71 if (file_name.empty()) {
71 // Retrieve the name from the URL. 72 // Retrieve the name from the URL.
72 string16 suggested_filename = 73 string16 suggested_filename =
73 net::GetSuggestedFilename(drop_data.url, "", "", "", "", ""); 74 net::GetSuggestedFilename(drop_data.url, "", "", "", "", "");
74 const std::string extension = file_name.Extension(); 75 const std::string extension = file_name.Extension();
75 file_name = FilePathFromFilename(suggested_filename); 76 file_name = FilePathFromFilename(suggested_filename);
76 file_name = file_name.ReplaceExtension(extension); 77 file_name = file_name.ReplaceExtension(extension);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 312 }
312 } 313 }
313 314
314 - (NSString*)dragPromisedFileTo:(NSString*)path { 315 - (NSString*)dragPromisedFileTo:(NSString*)path {
315 // Be extra paranoid; avoid crashing. 316 // Be extra paranoid; avoid crashing.
316 if (!dropData_.get()) { 317 if (!dropData_.get()) {
317 NOTREACHED() << "No drag-and-drop data available for promised file."; 318 NOTREACHED() << "No drag-and-drop data available for promised file.";
318 return nil; 319 return nil;
319 } 320 }
320 321
321 FilePath fileName = downloadFileName_.empty() ? 322 base::FilePath fileName = downloadFileName_.empty() ?
322 GetFileNameFromDragData(*dropData_) : downloadFileName_; 323 GetFileNameFromDragData(*dropData_) : downloadFileName_;
323 FilePath filePath(SysNSStringToUTF8(path)); 324 base::FilePath filePath(SysNSStringToUTF8(path));
324 filePath = filePath.Append(fileName); 325 filePath = filePath.Append(fileName);
325 326
326 // CreateFileStreamForDrop() will call file_util::PathExists(), 327 // CreateFileStreamForDrop() will call file_util::PathExists(),
327 // which is blocking. Since this operation is already blocking the 328 // which is blocking. Since this operation is already blocking the
328 // UI thread on OSX, it should be reasonable to let it happen. 329 // UI thread on OSX, it should be reasonable to let it happen.
329 base::ThreadRestrictions::ScopedAllowIO allowIO; 330 base::ThreadRestrictions::ScopedAllowIO allowIO;
330 scoped_ptr<FileStream> fileStream(content::CreateFileStreamForDrop( 331 scoped_ptr<FileStream> fileStream(content::CreateFileStreamForDrop(
331 &filePath, content::GetContentClient()->browser()->GetNetLog())); 332 &filePath, content::GetContentClient()->browser()->GetNetLog()));
332 if (!fileStream.get()) 333 if (!fileStream.get())
333 return nil; 334 return nil;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 std::string fileExtension; 382 std::string fileExtension;
382 383
383 // File. 384 // File.
384 if (!dropData_->file_contents.empty() || 385 if (!dropData_->file_contents.empty() ||
385 !dropData_->download_metadata.empty()) { 386 !dropData_->download_metadata.empty()) {
386 if (dropData_->download_metadata.empty()) { 387 if (dropData_->download_metadata.empty()) {
387 fileExtension = GetFileNameFromDragData(*dropData_).Extension(); 388 fileExtension = GetFileNameFromDragData(*dropData_).Extension();
388 net::GetMimeTypeFromExtension(fileExtension, &mimeType); 389 net::GetMimeTypeFromExtension(fileExtension, &mimeType);
389 } else { 390 } else {
390 string16 mimeType16; 391 string16 mimeType16;
391 FilePath fileName; 392 base::FilePath fileName;
392 if (content::ParseDownloadMetadata( 393 if (content::ParseDownloadMetadata(
393 dropData_->download_metadata, 394 dropData_->download_metadata,
394 &mimeType16, 395 &mimeType16,
395 &fileName, 396 &fileName,
396 &downloadURL_)) { 397 &downloadURL_)) {
397 // Generate the file name based on both mime type and proposed file 398 // Generate the file name based on both mime type and proposed file
398 // name. 399 // name.
399 std::string defaultName = 400 std::string defaultName =
400 content::GetContentClient()->browser()->GetDefaultDownloadName(); 401 content::GetContentClient()->browser()->GetDefaultDownloadName();
401 downloadFileName_ = 402 downloadFileName_ =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 - (NSImage*)dragImage { 462 - (NSImage*)dragImage {
462 if (dragImage_) 463 if (dragImage_)
463 return dragImage_; 464 return dragImage_;
464 465
465 // Default to returning a generic image. 466 // Default to returning a generic image.
466 return content::GetContentClient()->GetNativeImageNamed( 467 return content::GetContentClient()->GetNativeImageNamed(
467 IDR_DEFAULT_FAVICON).ToNSImage(); 468 IDR_DEFAULT_FAVICON).ToNSImage();
468 } 469 }
469 470
470 @end // @implementation WebDragSource (Private) 471 @end // @implementation WebDragSource (Private)
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_drag_source_mac.h ('k') | content/browser/webui/shared_resources_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698