Commit 3b20ab76 authored by asanka@chromium.org's avatar asanka@chromium.org

Allow dragging a download only after the download is complete.

This was already the case on views and cocoa. However GTK was allowing a drag
after the large icon finishes loading. This CL also updates callers to
use GetTargetFilePath() on the DownloadItem instead of GetFullPath().
For a completed download, both methods are equivalent, but we prefer
the former as it is clear that the path being requested is the final
target path.

BUG=116551


Review URL: https://chromiumcodereview.appspot.com/11801022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176159 0039d316-1c4b-4281-b951-d872f2087c98
parent fc47e9ec
......@@ -251,9 +251,10 @@ void DriveDownloadObserver::OnDownloadUpdated(
}
void DriveDownloadObserver::UploadDownloadItem(DownloadItem* download) {
DCHECK(download->IsComplete());
file_write_helper_->PrepareWritableFileAndRun(
GetDrivePath(download),
base::Bind(&MoveDownloadedFile, download->GetFullPath()));
base::Bind(&MoveDownloadedFile, download->GetTargetFilePath()));
}
} // namespace drive
......@@ -348,6 +348,7 @@ void DragDownload(const DownloadItem* download,
gfx::Image* icon,
gfx::NativeView view) {
DCHECK(download);
DCHECK(download->IsComplete());
// Set up our OLE machinery
ui::OSExchangeData data;
......@@ -357,7 +358,7 @@ void DragDownload(const DownloadItem* download,
download->GetFileNameToReportUser(), icon->ToImageSkia(), &data);
}
const FilePath full_path = download->GetFullPath();
const FilePath full_path = download->GetTargetFilePath();
data.SetFilename(full_path);
std::string mime_type = download->GetMimeType();
......
......@@ -196,7 +196,7 @@ class DownloadShelfContextMenuMac : public DownloadShelfContextMenu {
// Set correct popup menu. Also, set draggable download on completion.
if (downloadModel->download()->IsComplete()) {
[progressView_ setMenu:completeDownloadMenu_];
[progressView_ setDownload:downloadModel->download()->GetFullPath()];
[progressView_ setDownload:downloadModel->download()->GetTargetFilePath()];
} else {
[progressView_ setMenu:activeDownloadMenu_];
}
......
......@@ -6,6 +6,7 @@
#include "chrome/browser/ui/cocoa/download/download_util_mac.h"
#include "base/logging.h"
#include "base/sys_string_conversions.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
......@@ -28,8 +29,9 @@ void AddFileToPasteboard(NSPasteboard* pasteboard, const FilePath& path) {
void DragDownload(const DownloadItem* download,
gfx::Image* icon,
gfx::NativeView view) {
DCHECK(download->IsComplete());
NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
AddFileToPasteboard(pasteboard, download->GetFullPath());
AddFileToPasteboard(pasteboard, download->GetTargetFilePath());
// Synthesize a drag event, since we don't have access to the actual event
// that initiated a drag (possibly consumed by the Web UI, for example).
......
......@@ -89,8 +89,9 @@ class DownloadItemDrag::DragData {
};
DownloadItemDrag::DragData::DragData(const DownloadItem* item)
: url_(net::FilePathToFileURL(item->GetFullPath())),
: url_(net::FilePathToFileURL(item->GetTargetFilePath())),
display_name_(item->GetFileNameToReportUser().LossyDisplayName()) {
DCHECK(item->IsComplete());
}
void DownloadItemDrag::DragData::OnDragDataGet(GtkWidget* widget,
......
......@@ -459,7 +459,10 @@ void DownloadItemGtk::OnLoadSmallIconComplete(gfx::Image* image) {
void DownloadItemGtk::OnLoadLargeIconComplete(gfx::Image* image) {
icon_large_ = image;
DownloadItemDrag::SetSource(body_.get(), download(), icon_large_);
if (download()->IsComplete())
DownloadItemDrag::SetSource(body_.get(), download(), icon_large_);
// Else, the download will be made draggable once an OnDownloadUpdated()
// notification is received with download->IsComplete().
}
void DownloadItemGtk::LoadIcon() {
......
......@@ -338,10 +338,10 @@ void DownloadsDOMHandler::HandleDrag(const base::ListValue* args) {
content::DownloadItem* file = GetDownloadByValue(args);
content::WebContents* web_contents = GetWebUIWebContents();
// |web_contents| is only NULL in the test.
if (!file || !web_contents)
if (!file || !web_contents || !file->IsComplete())
return;
gfx::Image* icon = g_browser_process->icon_manager()->LookupIcon(
file->GetUserVerifiedFilePath(), IconLoader::NORMAL);
file->GetTargetFilePath(), IconLoader::NORMAL);
gfx::NativeView view = web_contents->GetNativeView();
{
// Enable nested tasks during DnD, while |DragDownload()| blocks.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment