OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/download/drag_download_item.h" | 5 #include "chrome/browser/download/drag_download_item.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "content/public/browser/download_item.h" | 9 #include "content/public/browser/download_item.h" |
10 #include "net/base/mime_util.h" | 10 #include "net/base/mime_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 ui::OSExchangeData data; | 39 ui::OSExchangeData data; |
40 | 40 |
41 if (icon) { | 41 if (icon) { |
42 drag_utils::CreateDragImageForFile( | 42 drag_utils::CreateDragImageForFile( |
43 download->GetFileNameToReportUser(), icon->ToImageSkia(), &data); | 43 download->GetFileNameToReportUser(), icon->ToImageSkia(), &data); |
44 } | 44 } |
45 | 45 |
46 const base::FilePath full_path = download->GetTargetFilePath(); | 46 const base::FilePath full_path = download->GetTargetFilePath(); |
47 data.SetFilename(full_path); | 47 data.SetFilename(full_path); |
48 | 48 |
49 std::string mime_type = download->GetMimeType(); | |
50 if (mime_type.empty()) | |
51 net::GetMimeTypeFromFile(full_path, &mime_type); | |
52 | |
53 // Add URL so that we can load supported files when dragged to WebContents. | 49 // Add URL so that we can load supported files when dragged to WebContents. |
54 if (net::IsSupportedMimeType(mime_type)) { | 50 data.SetURL(net::FilePathToFileURL(full_path), |
55 data.SetURL(net::FilePathToFileURL(full_path), | 51 download->GetFileNameToReportUser().LossyDisplayName()); |
56 download->GetFileNameToReportUser().LossyDisplayName()); | |
57 } | |
58 | 52 |
59 #if !defined(TOOLKIT_GTK) | 53 #if !defined(TOOLKIT_GTK) |
60 #if defined(USE_AURA) | 54 #if defined(USE_AURA) |
61 aura::Window* root_window = view->GetRootWindow(); | 55 aura::Window* root_window = view->GetRootWindow(); |
62 if (!root_window || !aura::client::GetDragDropClient(root_window)) | 56 if (!root_window || !aura::client::GetDragDropClient(root_window)) |
63 return; | 57 return; |
64 | 58 |
65 gfx::Point location = gfx::Screen::GetScreenFor(view)->GetCursorScreenPoint(); | 59 gfx::Point location = gfx::Screen::GetScreenFor(view)->GetCursorScreenPoint(); |
66 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. | 60 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. |
67 aura::client::GetDragDropClient(root_window)->StartDragAndDrop( | 61 aura::client::GetDragDropClient(root_window)->StartDragAndDrop( |
(...skipping 22 matching lines...) Expand all Loading... |
90 | 84 |
91 views::NativeWidgetGtk* widget = static_cast<views::NativeWidgetGtk*>( | 85 views::NativeWidgetGtk* widget = static_cast<views::NativeWidgetGtk*>( |
92 views::Widget::GetWidgetForNativeView(root)->native_widget()); | 86 views::Widget::GetWidgetForNativeView(root)->native_widget()); |
93 if (!widget) | 87 if (!widget) |
94 return; | 88 return; |
95 | 89 |
96 widget->DoDrag(data, | 90 widget->DoDrag(data, |
97 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK); | 91 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK); |
98 #endif // TOOLKIT_GTK | 92 #endif // TOOLKIT_GTK |
99 } | 93 } |
OLD | NEW |