OLD | NEW |
| (Empty) |
1 // Copyright (c) 2009 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. | |
4 | |
5 #ifndef APP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_ | |
6 #define APP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_ | |
7 #pragma once | |
8 | |
9 #include <objidl.h> | |
10 #include <shlobj.h> | |
11 #include <string> | |
12 | |
13 #include "app/os_exchange_data.h" | |
14 #include "base/scoped_comptr_win.h" | |
15 | |
16 class DataObjectImpl : public DownloadFileObserver, | |
17 public IDataObject, | |
18 public IAsyncOperation { | |
19 public: | |
20 class Observer { | |
21 public: | |
22 virtual void OnWaitForData() = 0; | |
23 virtual void OnDataObjectDisposed() = 0; | |
24 protected: | |
25 virtual ~Observer() { } | |
26 }; | |
27 | |
28 DataObjectImpl(); | |
29 | |
30 // Accessors. | |
31 void set_observer(Observer* observer) { observer_ = observer; } | |
32 | |
33 // DownloadFileObserver implementation: | |
34 virtual void OnDownloadCompleted(const FilePath& file_path); | |
35 virtual void OnDownloadAborted(); | |
36 | |
37 // IDataObject implementation: | |
38 HRESULT __stdcall GetData(FORMATETC* format_etc, STGMEDIUM* medium); | |
39 HRESULT __stdcall GetDataHere(FORMATETC* format_etc, STGMEDIUM* medium); | |
40 HRESULT __stdcall QueryGetData(FORMATETC* format_etc); | |
41 HRESULT __stdcall GetCanonicalFormatEtc( | |
42 FORMATETC* format_etc, FORMATETC* result); | |
43 HRESULT __stdcall SetData( | |
44 FORMATETC* format_etc, STGMEDIUM* medium, BOOL should_release); | |
45 HRESULT __stdcall EnumFormatEtc( | |
46 DWORD direction, IEnumFORMATETC** enumerator); | |
47 HRESULT __stdcall DAdvise(FORMATETC* format_etc, DWORD advf, | |
48 IAdviseSink* sink, DWORD* connection); | |
49 HRESULT __stdcall DUnadvise(DWORD connection); | |
50 HRESULT __stdcall EnumDAdvise(IEnumSTATDATA** enumerator); | |
51 | |
52 // IAsyncOperation implementation: | |
53 HRESULT __stdcall EndOperation( | |
54 HRESULT result, IBindCtx* reserved, DWORD effects); | |
55 HRESULT __stdcall GetAsyncMode(BOOL* is_op_async); | |
56 HRESULT __stdcall InOperation(BOOL* in_async_op); | |
57 HRESULT __stdcall SetAsyncMode(BOOL do_op_async); | |
58 HRESULT __stdcall StartOperation(IBindCtx* reserved); | |
59 | |
60 // IUnknown implementation: | |
61 HRESULT __stdcall QueryInterface(const IID& iid, void** object); | |
62 ULONG __stdcall AddRef(); | |
63 ULONG __stdcall Release(); | |
64 | |
65 private: | |
66 // FormatEtcEnumerator only likes us for our StoredDataMap typedef. | |
67 friend class FormatEtcEnumerator; | |
68 friend class OSExchangeDataProviderWin; | |
69 | |
70 virtual ~DataObjectImpl(); | |
71 | |
72 void StopDownloads(); | |
73 | |
74 // Our internal representation of stored data & type info. | |
75 struct StoredDataInfo { | |
76 FORMATETC format_etc; | |
77 STGMEDIUM* medium; | |
78 bool owns_medium; | |
79 bool in_delay_rendering; | |
80 scoped_refptr<DownloadFileProvider> downloader; | |
81 | |
82 StoredDataInfo(CLIPFORMAT cf, STGMEDIUM* medium) | |
83 : medium(medium), | |
84 owns_medium(true), | |
85 in_delay_rendering(false) { | |
86 format_etc.cfFormat = cf; | |
87 format_etc.dwAspect = DVASPECT_CONTENT; | |
88 format_etc.lindex = -1; | |
89 format_etc.ptd = NULL; | |
90 format_etc.tymed = medium ? medium->tymed : TYMED_HGLOBAL; | |
91 } | |
92 | |
93 StoredDataInfo(FORMATETC* format_etc, STGMEDIUM* medium) | |
94 : format_etc(*format_etc), | |
95 medium(medium), | |
96 owns_medium(true), | |
97 in_delay_rendering(false) { | |
98 } | |
99 | |
100 ~StoredDataInfo() { | |
101 if (owns_medium) { | |
102 ReleaseStgMedium(medium); | |
103 delete medium; | |
104 } | |
105 if (downloader.get()) | |
106 downloader->Stop(); | |
107 } | |
108 }; | |
109 | |
110 typedef std::vector<StoredDataInfo*> StoredData; | |
111 StoredData contents_; | |
112 | |
113 ScopedComPtr<IDataObject> source_object_; | |
114 | |
115 bool is_aborting_; | |
116 bool in_async_mode_; | |
117 bool async_operation_started_; | |
118 Observer* observer_; | |
119 }; | |
120 | |
121 class OSExchangeDataProviderWin : public OSExchangeData::Provider { | |
122 public: | |
123 // Returns true if source has plain text that is a valid url. | |
124 static bool HasPlainTextURL(IDataObject* source); | |
125 | |
126 // Returns true if source has plain text that is a valid URL and sets url to | |
127 // that url. | |
128 static bool GetPlainTextURL(IDataObject* source, GURL* url); | |
129 | |
130 static DataObjectImpl* GetDataObjectImpl(const OSExchangeData& data); | |
131 static IDataObject* GetIDataObject(const OSExchangeData& data); | |
132 static IAsyncOperation* GetIAsyncOperation(const OSExchangeData& data); | |
133 | |
134 explicit OSExchangeDataProviderWin(IDataObject* source); | |
135 OSExchangeDataProviderWin(); | |
136 | |
137 virtual ~OSExchangeDataProviderWin(); | |
138 | |
139 IDataObject* data_object() const { return data_.get(); } | |
140 IAsyncOperation* async_operation() const { return data_.get(); } | |
141 | |
142 // OSExchangeData::Provider methods. | |
143 virtual void SetString(const std::wstring& data); | |
144 virtual void SetURL(const GURL& url, const std::wstring& title); | |
145 virtual void SetFilename(const std::wstring& full_path); | |
146 virtual void SetPickledData(OSExchangeData::CustomFormat format, | |
147 const Pickle& data); | |
148 virtual void SetFileContents(const std::wstring& filename, | |
149 const std::string& file_contents); | |
150 virtual void SetHtml(const std::wstring& html, const GURL& base_url); | |
151 | |
152 virtual bool GetString(std::wstring* data) const; | |
153 virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const; | |
154 virtual bool GetFilename(std::wstring* full_path) const; | |
155 virtual bool GetPickledData(OSExchangeData::CustomFormat format, | |
156 Pickle* data) const; | |
157 virtual bool GetFileContents(std::wstring* filename, | |
158 std::string* file_contents) const; | |
159 virtual bool GetHtml(std::wstring* html, GURL* base_url) const; | |
160 virtual bool HasString() const; | |
161 virtual bool HasURL() const; | |
162 virtual bool HasFile() const; | |
163 virtual bool HasFileContents() const; | |
164 virtual bool HasHtml() const; | |
165 virtual bool HasCustomFormat(OSExchangeData::CustomFormat format) const; | |
166 virtual void SetDownloadFileInfo( | |
167 const OSExchangeData::DownloadFileInfo& download_info); | |
168 | |
169 private: | |
170 scoped_refptr<DataObjectImpl> data_; | |
171 ScopedComPtr<IDataObject> source_object_; | |
172 | |
173 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderWin); | |
174 }; | |
175 | |
176 #endif // APP_OS_EXCHANGE_DATA_PROVIDER_WIN_H_ | |
OLD | NEW |