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 "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "content/public/browser/download_item.h" | 11 #include "content/public/browser/download_item.h" |
12 #include "net/base/mime_util.h" | 12 #include "net/base/mime_util.h" |
13 #include "ui/aura/client/drag_drop_client.h" | 13 #include "ui/aura/client/drag_drop_client.h" |
14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/base/dragdrop/drag_drop_types.h" | 16 #include "ui/base/dragdrop/drag_drop_types.h" |
17 #include "ui/base/dragdrop/drag_utils.h" | |
18 #include "ui/base/dragdrop/file_info.h" | 17 #include "ui/base/dragdrop/file_info.h" |
19 #include "ui/base/dragdrop/os_exchange_data.h" | 18 #include "ui/base/dragdrop/os_exchange_data.h" |
20 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
21 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" |
22 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
23 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
23 #include "ui/views/button_drag_utils.h" | |
24 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 | 26 |
27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
28 #include "chrome/browser/chromeos/drive/download_handler.h" | 28 #include "chrome/browser/chromeos/drive/download_handler.h" |
29 #endif | 29 #endif |
30 | 30 |
31 void DragDownloadItem(const content::DownloadItem* download, | 31 void DragDownloadItem(const content::DownloadItem* download, |
32 gfx::Image* icon, | 32 gfx::Image* icon, |
33 gfx::NativeView view) { | 33 gfx::NativeView view) { |
34 DCHECK(download); | 34 DCHECK(download); |
35 DCHECK_EQ(content::DownloadItem::COMPLETE, download->GetState()); | 35 DCHECK_EQ(content::DownloadItem::COMPLETE, download->GetState()); |
36 | 36 |
37 aura::Window* root_window = view->GetRootWindow(); | |
38 if (!root_window || !aura::client::GetDragDropClient(root_window)) | |
sky
2017/03/16 03:38:05
Under what circumstances would there be no root or
Evan Stade
2017/03/16 14:14:50
I have no idea, I just moved the check from below
| |
39 return; | |
40 | |
37 // Set up our OLE machinery | 41 // Set up our OLE machinery |
38 ui::OSExchangeData data; | 42 ui::OSExchangeData data; |
39 | 43 |
40 drag_utils::CreateDragImageForFile( | 44 button_drag_utils::SetDragImage( |
41 download->GetFileNameToReportUser(), | 45 GURL(), download->GetFileNameToReportUser().BaseName().LossyDisplayName(), |
42 icon ? icon->AsImageSkia() : gfx::ImageSkia(), | 46 icon ? icon->AsImageSkia() : gfx::ImageSkia(), nullptr, |
43 &data); | 47 *views::Widget::GetTopLevelWidgetForNativeView(view), &data); |
Evan Stade
2017/03/16 00:03:30
key to fixing the crash (which occurred for chrome
| |
44 | 48 |
45 base::FilePath full_path = download->GetTargetFilePath(); | 49 base::FilePath full_path = download->GetTargetFilePath(); |
46 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
47 // Overwrite |full_path| with drive cache file path when appropriate. | 51 // Overwrite |full_path| with drive cache file path when appropriate. |
48 Profile* profile = Profile::FromBrowserContext(download->GetBrowserContext()); | 52 Profile* profile = Profile::FromBrowserContext(download->GetBrowserContext()); |
49 drive::DownloadHandler* drive_download_handler = | 53 drive::DownloadHandler* drive_download_handler = |
50 drive::DownloadHandler::GetForProfile(profile); | 54 drive::DownloadHandler::GetForProfile(profile); |
51 if (drive_download_handler && | 55 if (drive_download_handler && |
52 drive_download_handler->IsDriveDownload(download)) | 56 drive_download_handler->IsDriveDownload(download)) |
53 full_path = drive_download_handler->GetCacheFilePath(download); | 57 full_path = drive_download_handler->GetCacheFilePath(download); |
54 #endif | 58 #endif |
55 std::vector<ui::FileInfo> file_infos; | 59 std::vector<ui::FileInfo> file_infos; |
56 file_infos.push_back( | 60 file_infos.push_back( |
57 ui::FileInfo(full_path, download->GetFileNameToReportUser())); | 61 ui::FileInfo(full_path, download->GetFileNameToReportUser())); |
58 data.SetFilenames(file_infos); | 62 data.SetFilenames(file_infos); |
59 | 63 |
60 aura::Window* root_window = view->GetRootWindow(); | |
61 if (!root_window || !aura::client::GetDragDropClient(root_window)) | |
62 return; | |
63 | |
64 gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint(); | 64 gfx::Point location = display::Screen::GetScreen()->GetCursorScreenPoint(); |
65 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. | 65 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. |
66 aura::client::GetDragDropClient(root_window)->StartDragAndDrop( | 66 aura::client::GetDragDropClient(root_window)->StartDragAndDrop( |
67 data, | 67 data, |
68 root_window, | 68 root_window, |
69 view, | 69 view, |
70 location, | 70 location, |
71 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK, | 71 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK, |
72 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); | 72 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); |
73 } | 73 } |
OLD | NEW |