This source file includes following definitions.
- display_name_
 
- AttachToWidget
 
- OnDragDataGet
 
- OnDestroy
 
- SetSource
 
- drag_data_
 
- OnDragDataGet
 
- DragDownloadItem
 
#include "chrome/browser/ui/gtk/download/download_item_drag.h"
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/download/drag_download_item.h"
#include "content/public/browser/download_item.h"
#include "net/base/net_util.h"
#include "ui/base/dragdrop/gtk_dnd_util.h"
#include "ui/gfx/image/image.h"
#include "url/gurl.h"
using content::DownloadItem;
namespace {
const int kDownloadItemCodeMask = ui::TEXT_URI_LIST | ui::CHROME_NAMED_URL;
const GdkDragAction kDownloadItemDragAction = GDK_ACTION_COPY;
}  
class DownloadItemDrag::DragData {
 public:
  
  explicit DragData(const DownloadItem* item);
  
  
  
  
  static void AttachToWidget(scoped_ptr<DragData> drag_data,
                             GtkWidget* widget,
                             gfx::Image* icon);
  
  CHROMEGTK_CALLBACK_4(DragData, void, OnDragDataGet, GdkDragContext*,
                       GtkSelectionData*, guint, guint);
 private:
  
  
  static void OnDestroy(gpointer data, GClosure* closure);
  GURL url_;
  base::string16 display_name_;
};
DownloadItemDrag::DragData::DragData(const DownloadItem* item)
    : url_(net::FilePathToFileURL(item->GetTargetFilePath())),
      display_name_(item->GetFileNameToReportUser().LossyDisplayName()) {
  DCHECK_EQ(DownloadItem::COMPLETE, item->GetState());
}
void DownloadItemDrag::DragData::AttachToWidget(scoped_ptr<DragData> drag_data,
                                                GtkWidget* widget,
                                                gfx::Image* icon) {
  gtk_drag_source_set(
      widget, GDK_BUTTON1_MASK, NULL, 0, kDownloadItemDragAction);
  ui::SetSourceTargetListFromCodeMask(widget, kDownloadItemCodeMask);
  
  g_signal_handlers_disconnect_matched(
      widget,
      G_SIGNAL_MATCH_FUNC,
      0,
      0,
      NULL,
      reinterpret_cast<gpointer>(&OnDragDataGetThunk),
      NULL);
  
  g_signal_connect_data(widget,
                        "drag-data-get",
                        G_CALLBACK(&OnDragDataGetThunk),
                        reinterpret_cast<gpointer>(drag_data.release()),
                        &OnDestroy,
                        static_cast<GConnectFlags>(0));
  if (icon)
    gtk_drag_source_set_icon_pixbuf(widget, icon->ToGdkPixbuf());
}
void DownloadItemDrag::DragData::OnDragDataGet(GtkWidget* widget,
                                               GdkDragContext* context,
                                               GtkSelectionData* selection_data,
                                               guint target_type,
                                               guint time) {
  ui::WriteURLWithName(selection_data, url_, display_name_, target_type);
}
void DownloadItemDrag::DragData::OnDestroy(gpointer data, GClosure* closure) {
  DragData* drag_data = reinterpret_cast<DragData*>(data);
  delete drag_data;
}
void DownloadItemDrag::SetSource(GtkWidget* widget,
                                 const DownloadItem* item,
                                 gfx::Image* icon) {
  scoped_ptr<DragData> drag_data(new DragData(item));
  DragData::AttachToWidget(drag_data.Pass(), widget, icon);
}
DownloadItemDrag::DownloadItemDrag(const DownloadItem* item, gfx::Image* icon)
    : CustomDrag(icon, kDownloadItemCodeMask, kDownloadItemDragAction),
      drag_data_(new DragData(item)) {}
DownloadItemDrag::~DownloadItemDrag() {}
void DownloadItemDrag::OnDragDataGet(GtkWidget* widget,
                                     GdkDragContext* context,
                                     GtkSelectionData* selection_data,
                                     guint target_type,
                                     guint time) {
  drag_data_->OnDragDataGet(widget, context, selection_data, target_type, time);
}
void DragDownloadItem(const content::DownloadItem* download,
                      gfx::Image* icon,
                      gfx::NativeView view) {
  
  
  new DownloadItemDrag(download, icon);
}