| 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 // Download utility implementation | 5 // Download utility implementation |
| 6 | 6 |
| 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
| 8 | 8 |
| 9 #include "chrome/browser/download/download_util.h" | 9 #include "chrome/browser/download/download_util.h" |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 #include "chrome/browser/ui/gtk/unity_service.h" | 71 #include "chrome/browser/ui/gtk/unity_service.h" |
| 72 #endif // defined(TOOLKIT_GTK) | 72 #endif // defined(TOOLKIT_GTK) |
| 73 | 73 |
| 74 #if defined(OS_WIN) && !defined(USE_AURA) | 74 #if defined(OS_WIN) && !defined(USE_AURA) |
| 75 #include "base/win/scoped_comptr.h" | 75 #include "base/win/scoped_comptr.h" |
| 76 #include "chrome/browser/ui/browser_list.h" | 76 #include "chrome/browser/ui/browser_list.h" |
| 77 #include "ui/base/dragdrop/drag_source.h" | 77 #include "ui/base/dragdrop/drag_source.h" |
| 78 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 78 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 79 #endif | 79 #endif |
| 80 | 80 |
| 81 #if defined(USE_AURA) |
| 82 #include "ui/aura/client/drag_drop_client.h" |
| 83 #include "ui/aura/root_window.h" |
| 84 #include "ui/aura/window.h" |
| 85 #endif |
| 86 |
| 81 namespace { | 87 namespace { |
| 82 | 88 |
| 83 // Returns a string constant to be used as the |danger_type| value in | 89 // Returns a string constant to be used as the |danger_type| value in |
| 84 // CreateDownloadItemValue(). We only return strings for DANGEROUS_FILE, | 90 // CreateDownloadItemValue(). We only return strings for DANGEROUS_FILE, |
| 85 // DANGEROUS_URL, DANGEROUS_CONTENT, and UNCOMMON_CONTENT because the | 91 // DANGEROUS_URL, DANGEROUS_CONTENT, and UNCOMMON_CONTENT because the |
| 86 // |danger_type| value is only defined if the value of |state| is |DANGEROUS|. | 92 // |danger_type| value is only defined if the value of |state| is |DANGEROUS|. |
| 87 const char* GetDangerTypeString(content::DownloadDangerType danger_type) { | 93 const char* GetDangerTypeString(content::DownloadDangerType danger_type) { |
| 88 switch (danger_type) { | 94 switch (danger_type) { |
| 89 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: | 95 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE: |
| 90 return "DANGEROUS_FILE"; | 96 return "DANGEROUS_FILE"; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 net::GetMimeTypeFromFile(full_path, &mime_type); | 406 net::GetMimeTypeFromFile(full_path, &mime_type); |
| 401 | 407 |
| 402 // Add URL so that we can load supported files when dragged to WebContents. | 408 // Add URL so that we can load supported files when dragged to WebContents. |
| 403 if (net::IsSupportedMimeType(mime_type)) { | 409 if (net::IsSupportedMimeType(mime_type)) { |
| 404 data.SetURL(net::FilePathToFileURL(full_path), | 410 data.SetURL(net::FilePathToFileURL(full_path), |
| 405 download->GetFileNameToReportUser().LossyDisplayName()); | 411 download->GetFileNameToReportUser().LossyDisplayName()); |
| 406 } | 412 } |
| 407 | 413 |
| 408 #if !defined(TOOLKIT_GTK) | 414 #if !defined(TOOLKIT_GTK) |
| 409 #if defined(USE_AURA) | 415 #if defined(USE_AURA) |
| 410 views::Widget* widget = views::Widget::GetWidgetForNativeView(view); | 416 aura::RootWindow* root_window = view->GetRootWindow(); |
| 417 if (!root_window || !aura::client::GetDragDropClient(root_window)) |
| 418 return; |
| 419 |
| 411 gfx::Point location = gfx::Screen::GetCursorScreenPoint(); | 420 gfx::Point location = gfx::Screen::GetCursorScreenPoint(); |
| 412 // We do not care about notifying the DragItemView on completion of drag. So | 421 aura::client::GetDragDropClient(root_window)->StartDragAndDrop(data, location, |
| 413 // we pass NULL to RunShellDrag for the source view. | |
| 414 widget->RunShellDrag(NULL, data, location, | |
| 415 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK); | 422 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK); |
| 416 #else // We are on WIN without AURA | 423 #else // We are on WIN without AURA |
| 417 // We cannot use Widget::RunShellDrag on WIN since the |view| is backed by a | 424 // We cannot use Widget::RunShellDrag on WIN since the |view| is backed by a |
| 418 // TabContentsViewWin, not a NativeWidgetWin. | 425 // TabContentsViewWin, not a NativeWidgetWin. |
| 419 scoped_refptr<ui::DragSource> drag_source(new ui::DragSource); | 426 scoped_refptr<ui::DragSource> drag_source(new ui::DragSource); |
| 420 // Run the drag and drop loop | 427 // Run the drag and drop loop |
| 421 DWORD effects; | 428 DWORD effects; |
| 422 DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), | 429 DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), |
| 423 drag_source.get(), DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); | 430 drag_source.get(), DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); |
| 424 #endif | 431 #endif |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 UMA_HISTOGRAM_ENUMERATION( | 665 UMA_HISTOGRAM_ENUMERATION( |
| 659 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); | 666 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); |
| 660 } | 667 } |
| 661 | 668 |
| 662 void RecordDownloadSource(ChromeDownloadSource source) { | 669 void RecordDownloadSource(ChromeDownloadSource source) { |
| 663 UMA_HISTOGRAM_ENUMERATION( | 670 UMA_HISTOGRAM_ENUMERATION( |
| 664 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); | 671 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); |
| 665 } | 672 } |
| 666 | 673 |
| 667 } // namespace download_util | 674 } // namespace download_util |
| OLD | NEW |