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