OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
50 #include "grit/locale_settings.h" | 50 #include "grit/locale_settings.h" |
51 #include "grit/theme_resources.h" | 51 #include "grit/theme_resources.h" |
52 #include "net/base/mime_util.h" | 52 #include "net/base/mime_util.h" |
53 #include "net/base/net_util.h" | 53 #include "net/base/net_util.h" |
54 #include "skia/ext/image_operations.h" | 54 #include "skia/ext/image_operations.h" |
55 #include "third_party/skia/include/core/SkPath.h" | 55 #include "third_party/skia/include/core/SkPath.h" |
56 #include "third_party/skia/include/core/SkShader.h" | 56 #include "third_party/skia/include/core/SkShader.h" |
57 | 57 |
58 #if defined(TOOLKIT_VIEWS) | 58 #if defined(TOOLKIT_VIEWS) |
59 #include "app/os_exchange_data.h" | 59 #include "ui/base/dragdrop/os_exchange_data.h" |
60 #include "views/drag_utils.h" | 60 #include "views/drag_utils.h" |
61 #endif | 61 #endif |
62 | 62 |
63 #if defined(TOOLKIT_USES_GTK) | 63 #if defined(TOOLKIT_USES_GTK) |
64 #if defined(TOOLKIT_VIEWS) | 64 #if defined(TOOLKIT_VIEWS) |
65 #include "app/drag_drop_types.h" | 65 #include "app/drag_drop_types.h" |
66 #include "views/widget/widget_gtk.h" | 66 #include "views/widget/widget_gtk.h" |
67 #elif defined(TOOLKIT_GTK) | 67 #elif defined(TOOLKIT_GTK) |
68 #include "chrome/browser/gtk/custom_drag.h" | 68 #include "chrome/browser/gtk/custom_drag.h" |
69 #endif // defined(TOOLKIT_GTK) | 69 #endif // defined(TOOLKIT_GTK) |
70 #endif // defined(TOOLKIT_USES_GTK) | 70 #endif // defined(TOOLKIT_USES_GTK) |
71 | 71 |
72 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
73 #include "app/os_exchange_data_provider_win.h" | |
74 #include "app/win/drag_source.h" | 73 #include "app/win/drag_source.h" |
75 #include "app/win/win_util.h" | 74 #include "app/win/win_util.h" |
76 #include "base/win/scoped_comptr.h" | 75 #include "base/win/scoped_comptr.h" |
77 #include "chrome/browser/browser_list.h" | 76 #include "chrome/browser/browser_list.h" |
78 #include "chrome/browser/ui/views/frame/browser_view.h" | 77 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 78 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
79 #endif | 79 #endif |
80 | 80 |
81 namespace download_util { | 81 namespace download_util { |
82 | 82 |
83 // How many times to cycle the complete animation. This should be an odd number | 83 // How many times to cycle the complete animation. This should be an odd number |
84 // so that the animation ends faded out. | 84 // so that the animation ends faded out. |
85 static const int kCompleteAnimationCycles = 5; | 85 static const int kCompleteAnimationCycles = 5; |
86 | 86 |
87 // The maximum number of 'uniquified' files we will try to create. | 87 // The maximum number of 'uniquified' files we will try to create. |
88 // This is used when the filename we're trying to download is already in use, | 88 // This is used when the filename we're trying to download is already in use, |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } | 462 } |
463 | 463 |
464 #if defined(TOOLKIT_VIEWS) | 464 #if defined(TOOLKIT_VIEWS) |
465 // Download dragging | 465 // Download dragging |
466 void DragDownload(const DownloadItem* download, | 466 void DragDownload(const DownloadItem* download, |
467 SkBitmap* icon, | 467 SkBitmap* icon, |
468 gfx::NativeView view) { | 468 gfx::NativeView view) { |
469 DCHECK(download); | 469 DCHECK(download); |
470 | 470 |
471 // Set up our OLE machinery | 471 // Set up our OLE machinery |
472 OSExchangeData data; | 472 ui::OSExchangeData data; |
473 | 473 |
474 if (icon) { | 474 if (icon) { |
475 drag_utils::CreateDragImageForFile( | 475 drag_utils::CreateDragImageForFile( |
476 download->GetFileNameToReportUser(), icon, &data); | 476 download->GetFileNameToReportUser(), icon, &data); |
477 } | 477 } |
478 | 478 |
479 const FilePath full_path = download->full_path(); | 479 const FilePath full_path = download->full_path(); |
480 data.SetFilename(full_path.ToWStringHack()); | 480 data.SetFilename(full_path.ToWStringHack()); |
481 | 481 |
482 std::string mime_type = download->mime_type(); | 482 std::string mime_type = download->mime_type(); |
483 if (mime_type.empty()) | 483 if (mime_type.empty()) |
484 net::GetMimeTypeFromFile(full_path, &mime_type); | 484 net::GetMimeTypeFromFile(full_path, &mime_type); |
485 | 485 |
486 // Add URL so that we can load supported files when dragged to TabContents. | 486 // Add URL so that we can load supported files when dragged to TabContents. |
487 if (net::IsSupportedMimeType(mime_type)) { | 487 if (net::IsSupportedMimeType(mime_type)) { |
488 data.SetURL(GURL(WideToUTF8(full_path.ToWStringHack())), | 488 data.SetURL(GURL(WideToUTF8(full_path.ToWStringHack())), |
489 download->GetFileNameToReportUser().ToWStringHack()); | 489 download->GetFileNameToReportUser().ToWStringHack()); |
490 } | 490 } |
491 | 491 |
492 #if defined(OS_WIN) | 492 #if defined(OS_WIN) |
493 scoped_refptr<app::win::DragSource> drag_source(new app::win::DragSource); | 493 scoped_refptr<app::win::DragSource> drag_source(new app::win::DragSource); |
494 | 494 |
495 // Run the drag and drop loop | 495 // Run the drag and drop loop |
496 DWORD effects; | 496 DWORD effects; |
497 DoDragDrop(OSExchangeDataProviderWin::GetIDataObject(data), drag_source.get(), | 497 DoDragDrop(ui::OSExchangeDataProviderWin::GetIDataObject(data), |
498 DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); | 498 drag_source.get(), DROPEFFECT_COPY | DROPEFFECT_LINK, &effects); |
499 #elif defined(TOOLKIT_USES_GTK) | 499 #elif defined(TOOLKIT_USES_GTK) |
500 GtkWidget* root = gtk_widget_get_toplevel(view); | 500 GtkWidget* root = gtk_widget_get_toplevel(view); |
501 if (!root) | 501 if (!root) |
502 return; | 502 return; |
503 views::WidgetGtk* widget = views::WidgetGtk::GetViewForNative(root); | 503 views::WidgetGtk* widget = views::WidgetGtk::GetViewForNative(root); |
504 if (!widget) | 504 if (!widget) |
505 return; | 505 return; |
506 | 506 |
507 widget->DoDrag(data, DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK); | 507 widget->DoDrag(data, DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK); |
508 #endif // OS_WIN | 508 #endif // OS_WIN |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 771 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
772 // Extensions that are not from the gallery are considered dangerous. | 772 // Extensions that are not from the gallery are considered dangerous. |
773 return true; | 773 return true; |
774 } | 774 } |
775 } | 775 } |
776 | 776 |
777 return false; | 777 return false; |
778 } | 778 } |
779 | 779 |
780 } // namespace download_util | 780 } // namespace download_util |
OLD | NEW |