Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / ui / base / dragdrop / os_exchange_data_provider_win.h
blob21304e58a5c0623fa2c47fa3ace6617dd9695cd6
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_
8 #include <objidl.h>
9 #include <shlobj.h>
10 #include <string>
11 #include <vector>
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
19 #endif
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/geometry/vector2d.h"
26 #include "ui/gfx/image/image_skia.h"
28 namespace ui {
30 class DataObjectImpl : public DownloadFileObserver,
31 public IDataObject,
32 public IDataObjectAsyncCapability {
33 public:
34 class Observer {
35 public:
36 virtual void OnWaitForData() = 0;
37 virtual void OnDataObjectDisposed() = 0;
38 protected:
39 virtual ~Observer() { }
42 DataObjectImpl();
44 // Accessors.
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 void OnDownloadCompleted(const base::FilePath& file_path) override;
53 void OnDownloadAborted() override;
55 // IDataObject implementation:
56 HRESULT __stdcall GetData(FORMATETC* format_etc, STGMEDIUM* medium) override;
57 HRESULT __stdcall GetDataHere(FORMATETC* format_etc,
58 STGMEDIUM* medium) override;
59 HRESULT __stdcall QueryGetData(FORMATETC* format_etc) override;
60 HRESULT __stdcall GetCanonicalFormatEtc(FORMATETC* format_etc,
61 FORMATETC* result) override;
62 HRESULT __stdcall SetData(FORMATETC* format_etc,
63 STGMEDIUM* medium,
64 BOOL should_release) override;
65 HRESULT __stdcall EnumFormatEtc(DWORD direction,
66 IEnumFORMATETC** enumerator) override;
67 HRESULT __stdcall DAdvise(FORMATETC* format_etc,
68 DWORD advf,
69 IAdviseSink* sink,
70 DWORD* connection) override;
71 HRESULT __stdcall DUnadvise(DWORD connection) override;
72 HRESULT __stdcall EnumDAdvise(IEnumSTATDATA** enumerator) override;
74 // IDataObjectAsyncCapability implementation:
75 HRESULT __stdcall EndOperation(HRESULT result,
76 IBindCtx* reserved,
77 DWORD effects) override;
78 HRESULT __stdcall GetAsyncMode(BOOL* is_op_async) override;
79 HRESULT __stdcall InOperation(BOOL* in_async_op) override;
80 HRESULT __stdcall SetAsyncMode(BOOL do_op_async) override;
81 HRESULT __stdcall StartOperation(IBindCtx* reserved) override;
83 // IUnknown implementation:
84 HRESULT __stdcall QueryInterface(const IID& iid, void** object) override;
85 ULONG __stdcall AddRef() override;
86 ULONG __stdcall Release() override;
88 private:
89 // FormatEtcEnumerator only likes us for our StoredDataMap typedef.
90 friend class FormatEtcEnumerator;
91 friend class OSExchangeDataProviderWin;
93 ~DataObjectImpl() override;
95 void StopDownloads();
97 // Removes from contents_ the first data that matches |format|.
98 void RemoveData(const FORMATETC& format);
100 // Our internal representation of stored data & type info.
101 struct StoredDataInfo {
102 FORMATETC format_etc;
103 STGMEDIUM* medium;
104 bool owns_medium;
105 scoped_refptr<DownloadFileProvider> downloader;
107 StoredDataInfo(const FORMATETC& format_etc, STGMEDIUM* medium);
108 ~StoredDataInfo();
111 typedef ScopedVector<StoredDataInfo> StoredData;
112 StoredData contents_;
114 base::win::ScopedComPtr<IDataObject> source_object_;
116 bool is_aborting_;
117 bool in_drag_loop_;
118 bool in_async_mode_;
119 bool async_operation_started_;
120 Observer* observer_;
123 class UI_BASE_EXPORT OSExchangeDataProviderWin
124 : public OSExchangeData::Provider {
125 public:
126 // Returns true if source has plain text that is a valid url.
127 static bool HasPlainTextURL(IDataObject* source);
129 // Returns true if source has plain text that is a valid URL and sets url to
130 // that url.
131 static bool GetPlainTextURL(IDataObject* source, GURL* url);
133 static DataObjectImpl* GetDataObjectImpl(const OSExchangeData& data);
134 static IDataObject* GetIDataObject(const OSExchangeData& data);
135 static IDataObjectAsyncCapability* GetIAsyncOperation(
136 const OSExchangeData& data);
138 explicit OSExchangeDataProviderWin(IDataObject* source);
139 OSExchangeDataProviderWin();
141 ~OSExchangeDataProviderWin() override;
143 IDataObject* data_object() const { return data_.get(); }
144 IDataObjectAsyncCapability* async_operation() const { return data_.get(); }
146 // OSExchangeData::Provider methods.
147 Provider* Clone() const override;
148 void MarkOriginatedFromRenderer() override;
149 bool DidOriginateFromRenderer() const override;
150 void SetString(const base::string16& data) override;
151 void SetURL(const GURL& url, const base::string16& title) override;
152 void SetFilename(const base::FilePath& path) override;
153 void SetFilenames(const std::vector<FileInfo>& filenames) override;
154 void SetPickledData(const OSExchangeData::CustomFormat& format,
155 const base::Pickle& data) override;
156 void SetFileContents(const base::FilePath& filename,
157 const std::string& file_contents) override;
158 void SetHtml(const base::string16& html, const GURL& base_url) override;
160 bool GetString(base::string16* data) const override;
161 bool GetURLAndTitle(OSExchangeData::FilenameToURLPolicy policy,
162 GURL* url,
163 base::string16* title) const override;
164 bool GetFilename(base::FilePath* path) const override;
165 bool GetFilenames(std::vector<FileInfo>* filenames) const override;
166 bool GetPickledData(const OSExchangeData::CustomFormat& format,
167 base::Pickle* data) const override;
168 bool GetFileContents(base::FilePath* filename,
169 std::string* file_contents) const override;
170 bool GetHtml(base::string16* html, GURL* base_url) const override;
171 bool HasString() const override;
172 bool HasURL(OSExchangeData::FilenameToURLPolicy policy) const override;
173 bool HasFile() const override;
174 bool HasFileContents() const override;
175 bool HasHtml() const override;
176 bool HasCustomFormat(
177 const OSExchangeData::CustomFormat& format) const override;
178 void SetDownloadFileInfo(
179 const OSExchangeData::DownloadFileInfo& download_info) override;
180 void SetDragImage(const gfx::ImageSkia& image,
181 const gfx::Vector2d& cursor_offset) override;
182 const gfx::ImageSkia& GetDragImage() const override;
183 const gfx::Vector2d& GetDragImageOffset() const override;
185 private:
186 scoped_refptr<DataObjectImpl> data_;
187 base::win::ScopedComPtr<IDataObject> source_object_;
189 // Drag image and offset data. Only used for Ash.
190 gfx::ImageSkia drag_image_;
191 gfx::Vector2d drag_image_offset_;
193 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderWin);
196 } // namespace ui
198 #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_