#include <sys/param.h>
#include "base/bind.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/mac/mac_util.h"
#include "base/pickle.h"
#include "content/public/common/url_constants.h"
#include "grit/ui_resources.h"
#include "net/base/escape.h"
-#include "net/base/file_stream.h"
+#include "net/base/filename_util.h"
#include "net/base/mime_util.h"
-#include "net/base/net_util.h"
#include "ui/base/clipboard/custom_data_helper.h"
#include "ui/base/dragdrop/cocoa_dnd_util.h"
#include "ui/gfx/image/image.h"
using content::DropData;
using content::PromiseFileFinalizer;
using content::RenderViewHostImpl;
-using net::FileStream;
namespace {
// |NSURLPboardType|.
NSString* const kNSURLTitlePboardType = @"public.url-name";
-// Converts a string16 into a FilePath. Use this method instead of
+// 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 string16& filename) {
+base::FilePath FilePathFromFilename(const base::string16& filename) {
NSString* str = SysUTF16ToNSString(filename);
char buf[MAXPATHLEN];
if (![str getFileSystemRepresentation:buf maxLength:sizeof(buf)])
// synthesize one from the provided extension and URL.
if (file_name.empty()) {
// Retrieve the name from the URL.
- string16 suggested_filename =
+ base::string16 suggested_filename =
net::GetSuggestedFilename(drop_data.url, "", "", "", "", "");
const std::string extension = file_name.Extension();
file_name = FilePathFromFilename(suggested_filename);
// is responsible for opening the file. It takes the drop data and an open file
// stream.
void PromiseWriterHelper(const DropData& drop_data,
- scoped_ptr<FileStream> file_stream) {
- DCHECK(file_stream);
- file_stream->WriteSync(drop_data.file_contents.data(),
+ base::File file) {
+ DCHECK(file.IsValid());
+ file.WriteAtCurrentPos(drop_data.file_contents.data(),
drop_data.file_contents.length());
}
- (void)lazyWriteToPasteboard:(NSPasteboard*)pboard forType:(NSString*)type {
// NSHTMLPboardType requires the character set to be declared. Otherwise, it
// assumes US-ASCII. Awesome.
- const string16 kHtmlHeader = ASCIIToUTF16(
+ const base::string16 kHtmlHeader = base::ASCIIToUTF16(
"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">");
// Be extra paranoid; avoid crashing.
operation &= ~NSDragOperationMove;
contents_->DragSourceEndedAt(localPoint.x, localPoint.y, screenPoint.x,
- screenPoint.y, static_cast<WebKit::WebDragOperation>(operation));
+ screenPoint.y, static_cast<blink::WebDragOperation>(operation));
}
// Make sure the pasteboard owner isn't us.
[pasteboard_ declareTypes:[NSArray array] owner:nil];
}
-- (void)moveDragTo:(NSPoint)screenPoint {
- if (!contents_)
- return;
- RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
- contents_->GetRenderViewHost());
- if (rvh) {
- // Convert |screenPoint| to view coordinates and flip it.
- NSPoint localPoint = NSZeroPoint;
- if ([contentsView_ window])
- localPoint = [self convertScreenPoint:screenPoint];
- NSRect viewFrame = [contentsView_ frame];
- localPoint.y = viewFrame.size.height - localPoint.y;
- // Flip |screenPoint|.
- NSRect screenFrame = [[[contentsView_ window] screen] frame];
- screenPoint.y = screenFrame.size.height - screenPoint.y;
-
- contents_->DragSourceMovedTo(localPoint.x, localPoint.y,
- screenPoint.x, screenPoint.y);
- }
-}
-
- (NSString*)dragPromisedFileTo:(NSString*)path {
// Be extra paranoid; avoid crashing.
if (!dropData_) {
base::FilePath filePath(SysNSStringToUTF8(path));
filePath = filePath.Append(downloadFileName_);
- // CreateFileStreamForDrop() will call base::PathExists(),
+ // CreateFileForDrop() will call base::PathExists(),
// which is blocking. Since this operation is already blocking the
// UI thread on OSX, it should be reasonable to let it happen.
base::ThreadRestrictions::ScopedAllowIO allowIO;
- scoped_ptr<FileStream> fileStream(content::CreateFileStreamForDrop(
- &filePath, content::GetContentClient()->browser()->GetNetLog()));
- if (!fileStream)
+ base::File file(content::CreateFileForDrop(&filePath));
+ if (!file.IsValid())
return nil;
if (downloadURL_.is_valid()) {
scoped_refptr<DragDownloadFile> dragFileDownloader(new DragDownloadFile(
filePath,
- fileStream.Pass(),
+ file.Pass(),
downloadURL_,
content::Referrer(contents_->GetLastCommittedURL(),
dropData_->referrer_policy),
FROM_HERE,
base::Bind(&PromiseWriterHelper,
*dropData_,
- base::Passed(&fileStream)));
+ base::Passed(&file)));
}
// The DragDownloadFile constructor may have altered the value of |filePath|
downloadFileName_ = GetFileNameFromDragData(*dropData_);
net::GetMimeTypeFromExtension(downloadFileName_.Extension(), &mimeType);
} else {
- string16 mimeType16;
+ base::string16 mimeType16;
base::FilePath fileName;
if (content::ParseDownloadMetadata(
dropData_->download_metadata,
// name.
std::string defaultName =
content::GetContentClient()->browser()->GetDefaultDownloadName();
- mimeType = UTF16ToUTF8(mimeType16);
+ mimeType = base::UTF16ToUTF8(mimeType16);
downloadFileName_ =
net::GenerateFileName(downloadURL_,
std::string(),