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
3 // found in the LICENSE file.
5 #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_
6 #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_
13 // Win8 SDK compatibility, see http://goo.gl/fufvl for more information.
14 // "Note: This interface has been renamed IDataObjectAsyncCapability."
15 // If we're building on pre-8 we define it to its old name. It's documented as
16 // being binary compatible.
17 #ifndef __IDataObjectAsyncCapability_FWD_DEFINED__
18 #define IDataObjectAsyncCapability IAsyncOperation
21 #include "base/memory/scoped_vector.h"
22 #include "base/win/scoped_comptr.h"
23 #include "ui/base/dragdrop/os_exchange_data.h"
24 #include "ui/base/ui_base_export.h"
25 #include "ui/gfx/image/image_skia.h"
26 #include "ui/gfx/vector2d.h"
30 class DataObjectImpl
: public DownloadFileObserver
,
32 public IDataObjectAsyncCapability
{
36 virtual void OnWaitForData() = 0;
37 virtual void OnDataObjectDisposed() = 0;
39 virtual ~Observer() { }
45 void set_observer(Observer
* observer
) { observer_
= observer
; }
46 void set_in_drag_loop(bool in_drag_loop
) { in_drag_loop_
= in_drag_loop
; }
48 // Number of known formats.
49 size_t size() const { return contents_
.size(); }
51 // DownloadFileObserver implementation:
52 virtual void OnDownloadCompleted(const base::FilePath
& file_path
);
53 virtual void OnDownloadAborted();
55 // IDataObject implementation:
56 HRESULT __stdcall
GetData(FORMATETC
* format_etc
, STGMEDIUM
* medium
);
57 HRESULT __stdcall
GetDataHere(FORMATETC
* format_etc
, STGMEDIUM
* medium
);
58 HRESULT __stdcall
QueryGetData(FORMATETC
* format_etc
);
59 HRESULT __stdcall
GetCanonicalFormatEtc(
60 FORMATETC
* format_etc
, FORMATETC
* result
);
61 HRESULT __stdcall
SetData(
62 FORMATETC
* format_etc
, STGMEDIUM
* medium
, BOOL should_release
);
63 HRESULT __stdcall
EnumFormatEtc(
64 DWORD direction
, IEnumFORMATETC
** enumerator
);
65 HRESULT __stdcall
DAdvise(FORMATETC
* format_etc
, DWORD advf
,
66 IAdviseSink
* sink
, DWORD
* connection
);
67 HRESULT __stdcall
DUnadvise(DWORD connection
);
68 HRESULT __stdcall
EnumDAdvise(IEnumSTATDATA
** enumerator
);
70 // IDataObjectAsyncCapability implementation:
71 HRESULT __stdcall
EndOperation(
72 HRESULT result
, IBindCtx
* reserved
, DWORD effects
);
73 HRESULT __stdcall
GetAsyncMode(BOOL
* is_op_async
);
74 HRESULT __stdcall
InOperation(BOOL
* in_async_op
);
75 HRESULT __stdcall
SetAsyncMode(BOOL do_op_async
);
76 HRESULT __stdcall
StartOperation(IBindCtx
* reserved
);
78 // IUnknown implementation:
79 HRESULT __stdcall
QueryInterface(const IID
& iid
, void** object
);
80 ULONG __stdcall
AddRef();
81 ULONG __stdcall
Release();
84 // FormatEtcEnumerator only likes us for our StoredDataMap typedef.
85 friend class FormatEtcEnumerator
;
86 friend class OSExchangeDataProviderWin
;
88 virtual ~DataObjectImpl();
92 // Removes from contents_ the first data that matches |format|.
93 void RemoveData(const FORMATETC
& format
);
95 // Our internal representation of stored data & type info.
96 struct StoredDataInfo
{
100 scoped_refptr
<DownloadFileProvider
> downloader
;
102 StoredDataInfo(const FORMATETC
& format_etc
, STGMEDIUM
* medium
)
103 : format_etc(format_etc
), medium(medium
), owns_medium(true) {}
107 ReleaseStgMedium(medium
);
110 if (downloader
.get())
115 typedef ScopedVector
<StoredDataInfo
> StoredData
;
116 StoredData contents_
;
118 base::win::ScopedComPtr
<IDataObject
> source_object_
;
123 bool async_operation_started_
;
127 class UI_BASE_EXPORT OSExchangeDataProviderWin
128 : public OSExchangeData::Provider
{
130 // Returns true if source has plain text that is a valid url.
131 static bool HasPlainTextURL(IDataObject
* source
);
133 // Returns true if source has plain text that is a valid URL and sets url to
135 static bool GetPlainTextURL(IDataObject
* source
, GURL
* url
);
137 static DataObjectImpl
* GetDataObjectImpl(const OSExchangeData
& data
);
138 static IDataObject
* GetIDataObject(const OSExchangeData
& data
);
139 static IDataObjectAsyncCapability
* GetIAsyncOperation(
140 const OSExchangeData
& data
);
142 explicit OSExchangeDataProviderWin(IDataObject
* source
);
143 OSExchangeDataProviderWin();
145 virtual ~OSExchangeDataProviderWin();
147 IDataObject
* data_object() const { return data_
.get(); }
148 IDataObjectAsyncCapability
* async_operation() const { return data_
.get(); }
150 // OSExchangeData::Provider methods.
151 virtual Provider
* Clone() const;
152 virtual void MarkOriginatedFromRenderer();
153 virtual bool DidOriginateFromRenderer() const;
154 virtual void SetString(const base::string16
& data
);
155 virtual void SetURL(const GURL
& url
, const base::string16
& title
);
156 virtual void SetFilename(const base::FilePath
& path
);
157 virtual void SetFilenames(const std::vector
<FileInfo
>& filenames
);
158 virtual void SetPickledData(const OSExchangeData::CustomFormat
& format
,
160 virtual void SetFileContents(const base::FilePath
& filename
,
161 const std::string
& file_contents
);
162 virtual void SetHtml(const base::string16
& html
, const GURL
& base_url
);
164 virtual bool GetString(base::string16
* data
) const;
165 virtual bool GetURLAndTitle(OSExchangeData::FilenameToURLPolicy policy
,
167 base::string16
* title
) const;
168 virtual bool GetFilename(base::FilePath
* path
) const;
169 virtual bool GetFilenames(std::vector
<FileInfo
>* filenames
) const;
170 virtual bool GetPickledData(const OSExchangeData::CustomFormat
& format
,
172 virtual bool GetFileContents(base::FilePath
* filename
,
173 std::string
* file_contents
) const;
174 virtual bool GetHtml(base::string16
* html
, GURL
* base_url
) const;
175 virtual bool HasString() const;
176 virtual bool HasURL(OSExchangeData::FilenameToURLPolicy policy
) const;
177 virtual bool HasFile() const;
178 virtual bool HasFileContents() const;
179 virtual bool HasHtml() const;
180 virtual bool HasCustomFormat(
181 const OSExchangeData::CustomFormat
& format
) const;
182 virtual void SetDownloadFileInfo(
183 const OSExchangeData::DownloadFileInfo
& download_info
);
184 virtual void SetDragImage(const gfx::ImageSkia
& image
,
185 const gfx::Vector2d
& cursor_offset
) OVERRIDE
;
186 virtual const gfx::ImageSkia
& GetDragImage() const OVERRIDE
;
187 virtual const gfx::Vector2d
& GetDragImageOffset() const OVERRIDE
;
190 scoped_refptr
<DataObjectImpl
> data_
;
191 base::win::ScopedComPtr
<IDataObject
> source_object_
;
193 // Drag image and offset data. Only used for Ash.
194 gfx::ImageSkia drag_image_
;
195 gfx::Vector2d drag_image_offset_
;
197 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderWin
);
202 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_