OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 file_name = file_name.ReplaceExtension(extension); | 73 file_name = file_name.ReplaceExtension(extension); |
74 } | 74 } |
75 | 75 |
76 return file_name; | 76 return file_name; |
77 } | 77 } |
78 | 78 |
79 // This helper's sole task is to write out data for a promised file; the caller | 79 // This helper's sole task is to write out data for a promised file; the caller |
80 // is responsible for opening the file. It takes the drop data and an open file | 80 // is responsible for opening the file. It takes the drop data and an open file |
81 // stream. | 81 // stream. |
82 void PromiseWriterHelper(const WebDropData& drop_data, | 82 void PromiseWriterHelper(const WebDropData& drop_data, |
83 FileStream* file_stream) { | 83 scoped_ptr<FileStream> file_stream) { |
84 DCHECK(file_stream); | 84 DCHECK(file_stream); |
85 file_stream->WriteSync(drop_data.file_contents.data(), | 85 file_stream->WriteSync(drop_data.file_contents.data(), |
86 drop_data.file_contents.length()); | 86 drop_data.file_contents.length()); |
87 | 87 |
88 if (file_stream) | 88 if (file_stream) |
89 file_stream->CloseSync(); | 89 file_stream->CloseSync(); |
90 } | 90 } |
91 | 91 |
92 } // namespace | 92 } // namespace |
93 | 93 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 335 |
336 FilePath fileName = downloadFileName_.empty() ? | 336 FilePath fileName = downloadFileName_.empty() ? |
337 GetFileNameFromDragData(*dropData_) : downloadFileName_; | 337 GetFileNameFromDragData(*dropData_) : downloadFileName_; |
338 FilePath filePath(SysNSStringToUTF8(path)); | 338 FilePath filePath(SysNSStringToUTF8(path)); |
339 filePath = filePath.Append(fileName); | 339 filePath = filePath.Append(fileName); |
340 | 340 |
341 // CreateFileStreamForDrop() will call file_util::PathExists(), | 341 // CreateFileStreamForDrop() will call file_util::PathExists(), |
342 // which is blocking. Since this operation is already blocking the | 342 // which is blocking. Since this operation is already blocking the |
343 // UI thread on OSX, it should be reasonable to let it happen. | 343 // UI thread on OSX, it should be reasonable to let it happen. |
344 base::ThreadRestrictions::ScopedAllowIO allowIO; | 344 base::ThreadRestrictions::ScopedAllowIO allowIO; |
345 FileStream* fileStream = | 345 scoped_ptr<FileStream> fileStream( |
346 drag_download_util::CreateFileStreamForDrop( | 346 drag_download_util::CreateFileStreamForDrop( |
347 &filePath, content::GetContentClient()->browser()->GetNetLog()); | 347 &filePath, content::GetContentClient()->browser()->GetNetLog())); |
348 if (!fileStream) | 348 if (!fileStream.get()) |
349 return nil; | 349 return nil; |
350 | 350 |
351 if (downloadURL_.is_valid()) { | 351 if (downloadURL_.is_valid()) { |
352 scoped_refptr<DragDownloadFile> dragFileDownloader(new DragDownloadFile( | 352 scoped_refptr<DragDownloadFile> dragFileDownloader(new DragDownloadFile( |
353 filePath, | 353 filePath, |
354 linked_ptr<net::FileStream>(fileStream), | 354 fileStream.Pass(), |
355 downloadURL_, | 355 downloadURL_, |
356 content::Referrer(contents_->GetURL(), dropData_->referrer_policy), | 356 content::Referrer(contents_->GetURL(), dropData_->referrer_policy), |
357 contents_->GetEncoding(), | 357 contents_->GetEncoding(), |
358 contents_)); | 358 contents_)); |
359 | 359 |
360 // The finalizer will take care of closing and deletion. | 360 // The finalizer will take care of closing and deletion. |
361 dragFileDownloader->Start( | 361 dragFileDownloader->Start( |
362 new drag_download_util::PromiseFileFinalizer(dragFileDownloader)); | 362 new drag_download_util::PromiseFileFinalizer(dragFileDownloader)); |
363 } else { | 363 } else { |
364 // The writer will take care of closing and deletion. | 364 // The writer will take care of closing and deletion. |
365 BrowserThread::PostTask(BrowserThread::FILE, | 365 BrowserThread::PostTask(BrowserThread::FILE, |
366 FROM_HERE, | 366 FROM_HERE, |
367 base::Bind(&PromiseWriterHelper, | 367 base::Bind(&PromiseWriterHelper, |
368 *dropData_, | 368 *dropData_, |
369 base::Owned(fileStream))); | 369 base::Passed(fileStream.Pass()))); |
370 } | 370 } |
371 | 371 |
372 // Once we've created the file, we should return the file name. | 372 // Once we've created the file, we should return the file name. |
373 return SysUTF8ToNSString(filePath.BaseName().value()); | 373 return SysUTF8ToNSString(filePath.BaseName().value()); |
374 } | 374 } |
375 | 375 |
376 @end // @implementation WebDragSource | 376 @end // @implementation WebDragSource |
377 | 377 |
378 | 378 |
379 @implementation WebDragSource (Private) | 379 @implementation WebDragSource (Private) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 - (NSImage*)dragImage { | 464 - (NSImage*)dragImage { |
465 if (dragImage_) | 465 if (dragImage_) |
466 return dragImage_; | 466 return dragImage_; |
467 | 467 |
468 // Default to returning a generic image. | 468 // Default to returning a generic image. |
469 return content::GetContentClient()->GetNativeImageNamed( | 469 return content::GetContentClient()->GetNativeImageNamed( |
470 IDR_DEFAULT_FAVICON).ToNSImage(); | 470 IDR_DEFAULT_FAVICON).ToNSImage(); |
471 } | 471 } |
472 | 472 |
473 @end // @implementation WebDragSource (Private) | 473 @end // @implementation WebDragSource (Private) |
OLD | NEW |